void StopWatchTestCase::Misc() { // Buildbot machines are quite slow and sleep doesn't work reliably there, // i.e. it can sleep for much longer than requested. This is not really an // error, so just don't run this test there -- and if you get failures in // this test when running it interactively, this might also be normal if // the machine is under heavy load. if ( IsAutomaticTest() ) return; wxStopWatch sw; long t; wxLongLong usec; sw.Pause(); // pause it immediately // verify that almost no time elapsed usec = sw.TimeInMicro(); WX_ASSERT_MESSAGE ( ("Elapsed time was %" wxLongLongFmtSpec "dus", usec), usec < tolerance*1000 ); wxSleep(1); t = sw.Time(); // check that the stop watch doesn't advance while paused WX_ASSERT_MESSAGE ( ("Actual time value is %ld", t), t >= 0 && t < tolerance ); sw.Resume(); wxMilliSleep(sleepTime); t = sw.Time(); // check that it did advance now by ~1.5s WX_ASSERT_MESSAGE ( ("Actual time value is %ld", t), t > sleepTime - tolerance && t < 2*sleepTime ); sw.Pause(); // check that this sleep won't be taken into account below wxMilliSleep(sleepTime); sw.Resume(); wxMilliSleep(sleepTime); t = sw.Time(); // and it should advance again WX_ASSERT_MESSAGE ( ("Actual time value is %ld", t), t > 2*sleepTime - tolerance && t < 3*sleepTime ); }
void StopWatchTestCase::RestartBug() { wxStopWatch sw; sw.Pause(); // Calling Start() should resume the stopwatch if it was paused. static const int offset = 5000; sw.Start(offset); wxMilliSleep(sleepTime); long t = sw.Time(); WX_ASSERT_MESSAGE ( ("Actual time value is %ld", t), t >= offset + sleepTime - tolerance ); // As above, this is not actually due to the fact of the test being // automatic but just because buildot machines are usually pretty slow, so // this test often fails there simply because of the high load on them. if ( !IsAutomaticTest() ) { WX_ASSERT_MESSAGE ( ("Actual time value is %ld", t), t < offset + sleepTime + tolerance ); } }
void TextEntryTestCase::Editable() { #if wxUSE_UIACTIONSIMULATOR #ifdef __WXGTK__ // FIXME: For some reason this test regularly (although not always) fails // in wxGTK build bot builds when testing wxBitmapComboBox, but I // can't reproduce the failure locally. For now, disable this check // to let the entire test suite pass in automatic tests instead of // failing sporadically. if ( wxStrcmp(GetTestWindow()->GetClassInfo()->GetClassName(), "wxBitmapComboBox") == 0 && IsAutomaticTest() ) { return; } #endif // __WGTK__ wxTextEntry * const entry = GetTestEntry(); wxWindow * const window = GetTestWindow(); EventCounter updated(window, wxEVT_TEXT); window->SetFocus(); wxYield(); wxUIActionSimulator sim; sim.Text("abcdef"); wxYield(); CPPUNIT_ASSERT_EQUAL("abcdef", entry->GetValue()); CPPUNIT_ASSERT_EQUAL(6, updated.GetCount()); updated.Clear(); entry->SetEditable(false); sim.Text("gh"); wxYield(); CPPUNIT_ASSERT_EQUAL("abcdef", entry->GetValue()); CPPUNIT_ASSERT_EQUAL(0, updated.GetCount()); #endif }
void ListBaseTestCase::ItemClick() { #if wxUSE_UIACTIONSIMULATOR #ifdef __WXMSW__ // FIXME: This test fails on MSW buildbot slaves although works fine on // development machine, no idea why. It seems to be a problem with // wxUIActionSimulator rather the wxListCtrl control itself however. if ( IsAutomaticTest() ) return; #endif // __WXMSW__ wxListCtrl* const list = GetList(); list->InsertColumn(0, "Column 0", wxLIST_FORMAT_LEFT, 60); list->InsertColumn(1, "Column 1", wxLIST_FORMAT_LEFT, 50); list->InsertColumn(2, "Column 2", wxLIST_FORMAT_LEFT, 40); list->InsertItem(0, "Item 0"); list->SetItem(0, 1, "first column"); list->SetItem(0, 2, "second column"); EventCounter selected(list, wxEVT_LIST_ITEM_SELECTED); EventCounter focused(list, wxEVT_LIST_ITEM_FOCUSED); EventCounter activated(list, wxEVT_LIST_ITEM_ACTIVATED); EventCounter rclick(list, wxEVT_LIST_ITEM_RIGHT_CLICK); wxUIActionSimulator sim; wxRect pos; list->GetItemRect(0, pos); //We move in slightly so we are not on the edge wxPoint point = list->ClientToScreen(pos.GetPosition()) + wxPoint(10, 5); sim.MouseMove(point); wxYield(); sim.MouseClick(); wxYield(); sim.MouseDblClick(); wxYield(); sim.MouseClick(wxMOUSE_BTN_RIGHT); wxYield(); // when the first item was selected the focus changes to it, but not // on subsequent clicks // FIXME: This test fail under wxGTK & wxOSX because we get 3 FOCUSED events and // 2 SELECTED ones instead of the one of each we expect for some // reason, this needs to be debugged as it may indicate a bug in the // generic wxListCtrl implementation. #ifndef _WX_GENERIC_LISTCTRL_H_ CPPUNIT_ASSERT_EQUAL(1, focused.GetCount()); CPPUNIT_ASSERT_EQUAL(1, selected.GetCount()); #endif CPPUNIT_ASSERT_EQUAL(1, activated.GetCount()); CPPUNIT_ASSERT_EQUAL(1, rclick.GetCount()); //tidy up when we are finished list->ClearAll(); #endif // wxUSE_UIACTIONSIMULATOR }
void MenuTestCase::Events() { #ifdef __WXGTK__ // FIXME: For some reason, we sporadically fail to get the event in // buildbot slave builds even though the test always passes locally. // There is undoubtedly something wrong here but without being able // to debug it, I have no idea what is it, so let's just disable // this test when running under buildbot to let the entire test // suite pass. if ( IsAutomaticTest() ) return; #endif // __WXGTK__ #if wxUSE_UIACTIONSIMULATOR class MenuEventHandler : public wxEvtHandler { public: MenuEventHandler(wxWindow* win) : m_win(win) { m_win->Connect(wxEVT_MENU, wxCommandEventHandler(MenuEventHandler::OnMenu), NULL, this); m_gotEvent = false; m_event = NULL; } virtual ~MenuEventHandler() { m_win->Disconnect(wxEVT_MENU, wxCommandEventHandler(MenuEventHandler::OnMenu), NULL, this); delete m_event; } const wxCommandEvent& GetEvent() { CPPUNIT_ASSERT( m_gotEvent ); m_gotEvent = false; return *m_event; } private: void OnMenu(wxCommandEvent& event) { CPPUNIT_ASSERT( !m_gotEvent ); delete m_event; m_event = static_cast<wxCommandEvent*>(event.Clone()); m_gotEvent = true; } wxWindow* const m_win; wxCommandEvent* m_event; bool m_gotEvent; }; MenuEventHandler handler(m_frame); // Invoke the accelerator. m_frame->Show(); m_frame->SetFocus(); wxYield(); wxUIActionSimulator sim; sim.KeyDown(WXK_F1); sim.KeyUp(WXK_F1); wxYield(); const wxCommandEvent& ev = handler.GetEvent(); CPPUNIT_ASSERT_EQUAL( static_cast<int>(MenuTestCase_Bar), ev.GetId() ); wxObject* const src = ev.GetEventObject(); CPPUNIT_ASSERT( src ); CPPUNIT_ASSERT_EQUAL( "wxMenu", wxString(src->GetClassInfo()->GetClassName()) ); CPPUNIT_ASSERT_EQUAL( static_cast<wxObject*>(m_menuWithBar), src ); #endif // wxUSE_UIACTIONSIMULATOR }
void TextEntryTestCase::Editable() { #ifdef __WXGTK__ // FIXME: For some reason this test regularly (although not always) fails // in wxGTK build bot builds when testing wxBitmapComboBox, but I // can't reproduce the failure locally. For now, disable this check // to let the entire test suite pass in automatic tests instead of // failing sporadically. if ( wxStrcmp(GetTestWindow()->GetClassInfo()->GetClassName(), "wxBitmapComboBox") == 0 && IsAutomaticTest() ) { return; } #endif // __WGTK__ wxTextEntry * const entry = GetTestEntry(); wxWindow * const window = GetTestWindow(); EventCounter updated(window, wxEVT_TEXT); window->SetFocus(); wxYield(); // Check that we get the expected number of events. wxUIActionSimulator sim; sim.Text("abcdef"); wxYield(); CPPUNIT_ASSERT_EQUAL("abcdef", entry->GetValue()); CPPUNIT_ASSERT_EQUAL(6, updated.GetCount()); // And that the event carries the right value. TextEventHandler handler(window); sim.Text("g"); wxYield(); CPPUNIT_ASSERT_EQUAL("abcdefg", handler.GetLastString()); // ... even if we generate the event programmatically and whether it uses // the same value as the control has right now entry->SetValue("abcdefg"); CPPUNIT_ASSERT_EQUAL("abcdefg", handler.GetLastString()); // ... or not entry->SetValue("abcdef"); CPPUNIT_ASSERT_EQUAL("abcdef", handler.GetLastString()); // Check that making the control not editable does indeed prevent it from // being edited. updated.Clear(); entry->SetEditable(false); sim.Text("gh"); wxYield(); CPPUNIT_ASSERT_EQUAL("abcdef", entry->GetValue()); CPPUNIT_ASSERT_EQUAL(0, updated.GetCount()); }