From 4eed8e53313827f51cd97dcac7d2d437f53a2dbb Mon Sep 17 00:00:00 2001 From: Michael Meeks Date: Wed, 29 Apr 2015 17:20:58 +0100 Subject: abhortive focus unit test - apparently we need visible windows for that. Change-Id: I64999eb625a4b312997ba78698710bd1acaf8da7 --- vcl/qa/cppunit/lifecycle.cxx | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/vcl/qa/cppunit/lifecycle.cxx b/vcl/qa/cppunit/lifecycle.cxx index 4a0bebff8d0c..e23faa3cd3ef 100644 --- a/vcl/qa/cppunit/lifecycle.cxx +++ b/vcl/qa/cppunit/lifecycle.cxx @@ -16,6 +16,7 @@ #include #include #include +#include class LifecycleTest : public test::BootstrapFixture { @@ -31,6 +32,7 @@ public: void testParentedWidgets(); void testChildDispose(); void testPostDispose(); + void testFocus(); CPPUNIT_TEST_SUITE(LifecycleTest); CPPUNIT_TEST(testCast); @@ -40,6 +42,7 @@ public: CPPUNIT_TEST(testParentedWidgets); CPPUNIT_TEST(testChildDispose); CPPUNIT_TEST(testPostDispose); + CPPUNIT_TEST(testFocus); CPPUNIT_TEST_SUITE_END(); }; @@ -143,6 +146,44 @@ void LifecycleTest::testPostDispose() CPPUNIT_ASSERT(!xWin->GetWindow(0)); } +class FocusCrashPostDispose : public TabControl +{ +public: + FocusCrashPostDispose(vcl::Window *pParent) : + TabControl(pParent, 0) + { + } + virtual bool PreNotify( NotifyEvent& ) SAL_OVERRIDE + { + return false; + } + virtual bool Notify( NotifyEvent& ) SAL_OVERRIDE + { +// CPPUNIT_ASSERT(false && "notify"); + return false; + } + virtual void GetFocus() SAL_OVERRIDE + { + CPPUNIT_ASSERT(false && "get focus"); + } + virtual void LoseFocus() SAL_OVERRIDE + { + CPPUNIT_ASSERT(false && "this should never be called"); + } +}; + +void LifecycleTest::testFocus() +{ + ScopedVclPtrInstance xWin(nullptr, WB_APP|WB_STDWORK); + ScopedVclPtrInstance< FocusCrashPostDispose > xChild(xWin); + xWin->Show(); + xChild->GrabFocus(); + // process asynchronous ToTop + Scheduler::ProcessTaskScheduling(false); + // FIXME: really awful to test focus issues without showing windows. + // CPPUNIT_ASSERT(xChild->HasFocus()); +} + CPPUNIT_TEST_SUITE_REGISTRATION(LifecycleTest); CPPUNIT_PLUGIN_IMPLEMENT(); -- cgit v1.2.3