Move getting the unit test event count from wxTestableFrame to the EventCounter class. This reduces the need to have wxTestableFrame pointers all over the unit testing code and should reduce bugs caused by counting the wrong events.
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@70871 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -41,40 +41,45 @@ void TextEntryTestCase::SetValue()
|
||||
|
||||
void TextEntryTestCase::TextChangeEvents()
|
||||
{
|
||||
wxTestableFrame* frame = wxStaticCast(wxTheApp->GetTopWindow(),
|
||||
wxTestableFrame);
|
||||
|
||||
EventCounter count(GetTestWindow(), wxEVT_COMMAND_TEXT_UPDATED);
|
||||
EventCounter updated(GetTestWindow(), wxEVT_COMMAND_TEXT_UPDATED);
|
||||
|
||||
wxTextEntry * const entry = GetTestEntry();
|
||||
|
||||
// notice that SetValue() generates an event even if the text didn't change
|
||||
entry->SetValue("");
|
||||
CPPUNIT_ASSERT_EQUAL( 1, frame->GetEventCount() );
|
||||
CPPUNIT_ASSERT_EQUAL( 1, updated.GetCount() );
|
||||
updated.Clear();
|
||||
|
||||
entry->SetValue("foo");
|
||||
CPPUNIT_ASSERT_EQUAL( 1, frame->GetEventCount() );
|
||||
CPPUNIT_ASSERT_EQUAL( 1, updated.GetCount() );
|
||||
updated.Clear();
|
||||
|
||||
entry->SetValue("foo");
|
||||
CPPUNIT_ASSERT_EQUAL( 1, frame->GetEventCount() );
|
||||
CPPUNIT_ASSERT_EQUAL( 1, updated.GetCount() );
|
||||
updated.Clear();
|
||||
|
||||
entry->ChangeValue("bar");
|
||||
CPPUNIT_ASSERT_EQUAL( 0, frame->GetEventCount() );
|
||||
CPPUNIT_ASSERT_EQUAL( 0, updated.GetCount() );
|
||||
|
||||
entry->AppendText("bar");
|
||||
CPPUNIT_ASSERT_EQUAL( 1, frame->GetEventCount() );
|
||||
CPPUNIT_ASSERT_EQUAL( 1, updated.GetCount() );
|
||||
updated.Clear();
|
||||
|
||||
entry->Replace(3, 6, "baz");
|
||||
CPPUNIT_ASSERT_EQUAL( 1, frame->GetEventCount() );
|
||||
CPPUNIT_ASSERT_EQUAL( 1, updated.GetCount() );
|
||||
updated.Clear();
|
||||
|
||||
entry->Remove(0, 3);
|
||||
CPPUNIT_ASSERT_EQUAL( 1, frame->GetEventCount() );
|
||||
CPPUNIT_ASSERT_EQUAL( 1, updated.GetCount() );
|
||||
updated.Clear();
|
||||
|
||||
entry->WriteText("foo");
|
||||
CPPUNIT_ASSERT_EQUAL( 1, frame->GetEventCount() );
|
||||
CPPUNIT_ASSERT_EQUAL( 1, updated.GetCount() );
|
||||
updated.Clear();
|
||||
|
||||
entry->Clear();
|
||||
CPPUNIT_ASSERT_EQUAL( 1, frame->GetEventCount() );
|
||||
CPPUNIT_ASSERT_EQUAL( 1, updated.GetCount() );
|
||||
updated.Clear();
|
||||
}
|
||||
|
||||
void TextEntryTestCase::CheckStringSelection(const char *sel)
|
||||
@@ -176,13 +181,10 @@ void TextEntryTestCase::Replace()
|
||||
void TextEntryTestCase::Editable()
|
||||
{
|
||||
#if wxUSE_UIACTIONSIMULATOR
|
||||
wxTestableFrame* frame = wxStaticCast(wxTheApp->GetTopWindow(),
|
||||
wxTestableFrame);
|
||||
|
||||
wxTextEntry * const entry = GetTestEntry();
|
||||
wxWindow * const window = GetTestWindow();
|
||||
|
||||
EventCounter count(window, wxEVT_COMMAND_TEXT_UPDATED);
|
||||
EventCounter updated(window, wxEVT_COMMAND_TEXT_UPDATED);
|
||||
|
||||
window->SetFocus();
|
||||
wxYield();
|
||||
@@ -192,14 +194,16 @@ void TextEntryTestCase::Editable()
|
||||
wxYield();
|
||||
|
||||
CPPUNIT_ASSERT_EQUAL("abcdef", entry->GetValue());
|
||||
CPPUNIT_ASSERT_EQUAL(6, frame->GetEventCount());
|
||||
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, frame->GetEventCount());
|
||||
CPPUNIT_ASSERT_EQUAL(0, updated.GetCount());
|
||||
#endif
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user