]> git.saurik.com Git - wxWidgets.git/blobdiff - tests/controls/textctrltest.cpp
Added wxAutoOleInterface<T> template.
[wxWidgets.git] / tests / controls / textctrltest.cpp
index 04e5939a5ea53fe6346fa015e5e9e3e9330dcb67..5f2cc77f4e6a6bbb955aea5a2bb6fbefa813558c 100644 (file)
@@ -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
     #include "wx/textctrl.h"
 #endif // WX_PRECOMP
 
+#include "textentrytest.h"
+
 // ----------------------------------------------------------------------------
 // test class
 // ----------------------------------------------------------------------------
 
-class TextCtrlTestCase : public CppUnit::TestCase
+class TextCtrlTestCase : public TextEntryTestCase
 {
 public:
     TextCtrlTestCase() { }
@@ -35,22 +37,17 @@ 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 );
-        CPPUNIT_TEST( Selection );
+        wxTEXT_ENTRY_TESTS();
+        CPPUNIT_TEST( MultiLineReplace );
     CPPUNIT_TEST_SUITE_END();
 
-    void SetValue();
-    void TextChangeEvents();
-    void Selection();
-
-    // Selection() test helper: verify that selection is as described by the
-    // function parameters
-    void AssertSelection(int from, int to, const char *sel);
+    void MultiLineReplace();
 
     wxTextCtrl *m_text;
-    wxFrame *m_frame;
 
     DECLARE_NO_COPY_CLASS(TextCtrlTestCase)
 };
@@ -80,105 +77,27 @@ void TextCtrlTestCase::tearDown()
 // tests themselves
 // ----------------------------------------------------------------------------
 
-void TextCtrlTestCase::SetValue()
-{
-    CPPUNIT_ASSERT( m_text->IsEmpty() );
-
-    m_text->SetValue("foo");
-    CPPUNIT_ASSERT_EQUAL( "foo", m_text->GetValue() );
-
-    m_text->SetValue("");
-    CPPUNIT_ASSERT( m_text->IsEmpty() );
-
-    m_text->SetValue("hi");
-    CPPUNIT_ASSERT_EQUAL( "hi", m_text->GetValue() );
-
-    m_text->SetValue("bye");
-    CPPUNIT_ASSERT_EQUAL( "bye", m_text->GetValue() );
-}
-
-void TextCtrlTestCase::TextChangeEvents()
+void TextCtrlTestCase::MultiLineReplace()
 {
-    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() );
+    // we need a multiline control for this test so recreate it
+    delete m_text;
+    m_text = new wxTextCtrl(wxTheApp->GetTopWindow(), wxID_ANY, "",
+                            wxDefaultPosition, wxDefaultSize,
+                            wxTE_MULTILINE);
 
-    m_text->Replace(3, 6, "baz");
-    CPPUNIT_ASSERT_EQUAL( 1, handler.GetEvents() );
+    m_text->SetValue("Hello replace\n"
+                    "0123456789012");
+    m_text->SetInsertionPoint(0);
 
-    m_text->Remove(0, 3);
-    CPPUNIT_ASSERT_EQUAL( 1, handler.GetEvents() );
+    m_text->Replace(6, 13, "changed");
 
-    m_text->WriteText("foo");
-    CPPUNIT_ASSERT_EQUAL( 1, handler.GetEvents() );
+    CPPUNIT_ASSERT_EQUAL("Hello changed\n"
+                         "0123456789012",
+                         m_text->GetValue());
+    CPPUNIT_ASSERT_EQUAL(13, m_text->GetInsertionPoint());
 
-    m_text->Clear();
-    CPPUNIT_ASSERT_EQUAL( 1, handler.GetEvents() );
+    m_text->Replace(13, -1, "");
+    CPPUNIT_ASSERT_EQUAL("Hello changed", m_text->GetValue());
+    CPPUNIT_ASSERT_EQUAL(13, m_text->GetInsertionPoint());
 }
 
-void TextCtrlTestCase::AssertSelection(int from, int to, const char *sel)
-{
-    CPPUNIT_ASSERT( m_text->HasSelection() );
-
-    long fromReal,
-         toReal;
-    m_text->GetSelection(&fromReal, &toReal);
-    CPPUNIT_ASSERT_EQUAL( from, fromReal );
-    CPPUNIT_ASSERT_EQUAL( to, toReal );
-    CPPUNIT_ASSERT_EQUAL( sel, m_text->GetStringSelection() );
-
-    CPPUNIT_ASSERT_EQUAL( from, m_text->GetInsertionPoint() );
-}
-
-void TextCtrlTestCase::Selection()
-{
-    m_text->SetValue("0123456789");
-
-    m_text->SetSelection(2, 4);
-    AssertSelection(2, 4, "23"); // not "234"!
-
-    m_text->SetSelection(3, -1);
-    AssertSelection(3, 10, "3456789");
-
-    m_text->SelectAll();
-    AssertSelection(0, 10, "0123456789");
-
-    m_text->SetSelection(0, 0);
-    CPPUNIT_ASSERT( !m_text->HasSelection() );
-}