Add a unit test for wxDatePickerCtrl focus events
Unfortunately it doesn't work with wxGTK, as usual, due to wxUIActionSimulator not working correctly there.
This commit is contained in:
		| @@ -16,9 +16,11 @@ | ||||
|  | ||||
| #ifndef WX_PRECOMP | ||||
|     #include "wx/app.h" | ||||
|     #include "wx/button.h" | ||||
| #endif // WX_PRECOMP | ||||
|  | ||||
| #include "wx/datectrl.h" | ||||
| #include "wx/uiaction.h" | ||||
|  | ||||
| #include "testableframe.h" | ||||
| #include "testdate.h" | ||||
| @@ -35,12 +37,15 @@ private: | ||||
|     CPPUNIT_TEST_SUITE( DatePickerCtrlTestCase ); | ||||
|         CPPUNIT_TEST( Value ); | ||||
|         CPPUNIT_TEST( Range ); | ||||
|         WXUISIM_TEST( Focus ); | ||||
|     CPPUNIT_TEST_SUITE_END(); | ||||
|  | ||||
|     void Value(); | ||||
|     void Range(); | ||||
|     void Focus(); | ||||
|  | ||||
|     wxDatePickerCtrl* m_datepicker; | ||||
|     wxButton* m_button; | ||||
|  | ||||
|     wxDECLARE_NO_COPY_CLASS(DatePickerCtrlTestCase); | ||||
| }; | ||||
| @@ -54,10 +59,12 @@ CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( DatePickerCtrlTestCase, "DatePickerCtrlTe | ||||
| void DatePickerCtrlTestCase::setUp() | ||||
| { | ||||
|     m_datepicker = new wxDatePickerCtrl(wxTheApp->GetTopWindow(), wxID_ANY); | ||||
|     m_button = NULL; | ||||
| } | ||||
|  | ||||
| void DatePickerCtrlTestCase::tearDown() | ||||
| { | ||||
|     delete m_button; | ||||
|     delete m_datepicker; | ||||
| } | ||||
|  | ||||
| @@ -115,4 +122,45 @@ void DatePickerCtrlTestCase::Range() | ||||
|     CPPUNIT_ASSERT_EQUAL( dtBeforeEnd, m_datepicker->GetValue() ); | ||||
| } | ||||
|  | ||||
| #if wxUSE_UIACTIONSIMULATOR | ||||
|  | ||||
| static wxPoint GetRectCenter(const wxRect& r) | ||||
| { | ||||
|     return (r.GetTopRight() + r.GetBottomLeft()) / 2; | ||||
| } | ||||
|  | ||||
| void DatePickerCtrlTestCase::Focus() | ||||
| { | ||||
|     // Create another control just to give focus to it initially. | ||||
|     m_button = new wxButton(wxTheApp->GetTopWindow(), wxID_OK); | ||||
|     m_button->Move(0, m_datepicker->GetSize().y * 3); | ||||
|     m_button->SetFocus(); | ||||
|     wxYield(); | ||||
|  | ||||
|     CHECK( !m_datepicker->HasFocus() ); | ||||
|  | ||||
|     EventCounter setFocus(m_datepicker, wxEVT_SET_FOCUS); | ||||
|     EventCounter killFocus(m_datepicker, wxEVT_KILL_FOCUS); | ||||
|  | ||||
|     wxUIActionSimulator sim; | ||||
|  | ||||
|     sim.MouseMove(GetRectCenter(m_datepicker->GetScreenRect())); | ||||
|     sim.MouseClick(); | ||||
|     wxYield(); | ||||
|  | ||||
|     REQUIRE( m_datepicker->HasFocus() ); | ||||
|     CHECK( setFocus.GetCount() == 1 ); | ||||
|     CHECK( killFocus.GetCount() == 0 ); | ||||
|  | ||||
|     sim.MouseMove(GetRectCenter(m_button->GetScreenRect())); | ||||
|     sim.MouseClick(); | ||||
|     wxYield(); | ||||
|  | ||||
|     CHECK( !m_datepicker->HasFocus() ); | ||||
|     CHECK( setFocus.GetCount() == 1 ); | ||||
|     CHECK( killFocus.GetCount() == 1 ); | ||||
| } | ||||
|  | ||||
| #endif // wxUSE_UIACTIONSIMULATOR | ||||
|  | ||||
| #endif // wxUSE_DATEPICKCTRL | ||||
|   | ||||
		Reference in New Issue
	
	Block a user