X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/c0d9b217a7dcec3b322390efcbc5c98615cd3f16..468432091bfe8fc23aa17b3c574eb635a4be0a65:/tests/controls/textctrltest.cpp?ds=sidebyside diff --git a/tests/controls/textctrltest.cpp b/tests/controls/textctrltest.cpp index 4c4234be44..afc923afa7 100644 --- a/tests/controls/textctrltest.cpp +++ b/tests/controls/textctrltest.cpp @@ -1,5 +1,5 @@ /////////////////////////////////////////////////////////////////////////////// -// Name: tests/textctrl/textctrltest.cpp +// Name: tests/controls/textctrltest.cpp // Purpose: wxTextCtrl unit test // Author: Vadim Zeitlin // Created: 2007-09-25 @@ -22,11 +22,13 @@ #include "wx/textctrl.h" #endif // WX_PRECOMP +#include "textentrytest.h" + // ---------------------------------------------------------------------------- // test class // ---------------------------------------------------------------------------- -class TextCtrlTestCase : public CppUnit::TestCase +class TextCtrlTestCase : public TextEntryTestCase { public: TextCtrlTestCase() { } @@ -35,16 +37,14 @@ public: virtual void tearDown(); private: + virtual wxTextEntry *GetTestEntry() const { return m_text; } + virtual wxWindow *GetTestWindow() const { return m_text; } + CPPUNIT_TEST_SUITE( TextCtrlTestCase ); - CPPUNIT_TEST( SetValue ); - CPPUNIT_TEST( TextChangeEvents ); + wxTEXT_ENTRY_TESTS(); CPPUNIT_TEST_SUITE_END(); - void SetValue(); - void TextChangeEvents(); - wxTextCtrl *m_text; - wxFrame *m_frame; DECLARE_NO_COPY_CLASS(TextCtrlTestCase) }; @@ -74,75 +74,3 @@ void TextCtrlTestCase::tearDown() // tests themselves // ---------------------------------------------------------------------------- -void TextCtrlTestCase::SetValue() -{ - CPPUNIT_ASSERT( m_text->IsEmpty() ); - - m_text->SetValue("foo"); - WX_ASSERT_STR_EQUAL( "foo", m_text->GetValue() ); - - m_text->SetValue(""); - CPPUNIT_ASSERT( m_text->IsEmpty() ); - - m_text->SetValue("hi"); - WX_ASSERT_STR_EQUAL( "hi", m_text->GetValue() ); - - m_text->SetValue("bye"); - WX_ASSERT_STR_EQUAL( "bye", m_text->GetValue() ); -} - -void TextCtrlTestCase::TextChangeEvents() -{ - class TextTestEventHandler : public wxEvtHandler - { - public: - TextTestEventHandler() { m_events = 0; } - - // calling this automatically resets the events counter - int GetEvents() - { - const int events = m_events; - m_events = 0; - return events; - } - - void OnText(wxCommandEvent& WXUNUSED(event)) { m_events++; } - - private: - int m_events; - } handler; - - m_text->Connect(wxEVT_COMMAND_TEXT_UPDATED, - wxCommandEventHandler(TextTestEventHandler::OnText), - NULL, - &handler); - - // notice that SetValue() generates an event even if the text didn't change - m_text->SetValue(""); - CPPUNIT_ASSERT_EQUAL( 1, handler.GetEvents() ); - - m_text->SetValue("foo"); - CPPUNIT_ASSERT_EQUAL( 1, handler.GetEvents() ); - - m_text->SetValue("foo"); - CPPUNIT_ASSERT_EQUAL( 1, handler.GetEvents() ); - - m_text->ChangeValue("bar"); - CPPUNIT_ASSERT_EQUAL( 0, handler.GetEvents() ); - - m_text->AppendText("bar"); - CPPUNIT_ASSERT_EQUAL( 1, handler.GetEvents() ); - - m_text->Replace(3, 6, "baz"); - CPPUNIT_ASSERT_EQUAL( 1, handler.GetEvents() ); - - m_text->Remove(0, 3); - CPPUNIT_ASSERT_EQUAL( 1, handler.GetEvents() ); - - m_text->WriteText("foo"); - CPPUNIT_ASSERT_EQUAL( 1, handler.GetEvents() ); - - m_text->Clear(); - CPPUNIT_ASSERT_EQUAL( 1, handler.GetEvents() ); -} -