]> git.saurik.com Git - wxWidgets.git/commitdiff
add unit test for wxTextCtrl::SetSelection()
authorVadim Zeitlin <vadim@wxwidgets.org>
Wed, 23 Jul 2008 23:34:25 +0000 (23:34 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Wed, 23 Jul 2008 23:34:25 +0000 (23:34 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@54775 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

tests/controls/textctrltest.cpp

index e75252f308d3aa8c6506a80bcdf54099ccb8d2d7..04e5939a5ea53fe6346fa015e5e9e3e9330dcb67 100644 (file)
@@ -38,10 +38,16 @@ private:
     CPPUNIT_TEST_SUITE( TextCtrlTestCase );
         CPPUNIT_TEST( SetValue );
         CPPUNIT_TEST( TextChangeEvents );
+        CPPUNIT_TEST( Selection );
     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);
 
     wxTextCtrl *m_text;
     wxFrame *m_frame;
@@ -146,3 +152,33 @@ void TextCtrlTestCase::TextChangeEvents()
     CPPUNIT_ASSERT_EQUAL( 1, handler.GetEvents() );
 }
 
+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() );
+}