X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/c0d9b217a7dcec3b322390efcbc5c98615cd3f16..778ce4329a0016255b249850c862335719543996:/tests/controls/textctrltest.cpp diff --git a/tests/controls/textctrltest.cpp b/tests/controls/textctrltest.cpp index 4c4234be44..02c600d559 100644 --- a/tests/controls/textctrltest.cpp +++ b/tests/controls/textctrltest.cpp @@ -38,10 +38,18 @@ private: CPPUNIT_TEST_SUITE( TextCtrlTestCase ); CPPUNIT_TEST( SetValue ); CPPUNIT_TEST( TextChangeEvents ); + CPPUNIT_TEST( Selection ); + CPPUNIT_TEST( InsertionPoint ); CPPUNIT_TEST_SUITE_END(); void SetValue(); void TextChangeEvents(); + void Selection(); + void InsertionPoint(); + + // 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; @@ -79,16 +87,16 @@ void TextCtrlTestCase::SetValue() CPPUNIT_ASSERT( m_text->IsEmpty() ); m_text->SetValue("foo"); - WX_ASSERT_STR_EQUAL( "foo", m_text->GetValue() ); + CPPUNIT_ASSERT_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() ); + CPPUNIT_ASSERT_EQUAL( "hi", m_text->GetValue() ); m_text->SetValue("bye"); - WX_ASSERT_STR_EQUAL( "bye", m_text->GetValue() ); + CPPUNIT_ASSERT_EQUAL( "bye", m_text->GetValue() ); } void TextCtrlTestCase::TextChangeEvents() @@ -146,3 +154,60 @@ 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() ); +} + +void TextCtrlTestCase::InsertionPoint() +{ + CPPUNIT_ASSERT_EQUAL( 0, m_text->GetLastPosition() ); + CPPUNIT_ASSERT_EQUAL( 0, m_text->GetInsertionPoint() ); + + m_text->SetValue("0"); // should put the insertion point in front + CPPUNIT_ASSERT_EQUAL( 1, m_text->GetLastPosition() ); + CPPUNIT_ASSERT_EQUAL( 0, m_text->GetInsertionPoint() ); + + m_text->AppendText("12"); // should update the insertion point position + CPPUNIT_ASSERT_EQUAL( 3, m_text->GetLastPosition() ); + CPPUNIT_ASSERT_EQUAL( 3, m_text->GetInsertionPoint() ); + + m_text->SetInsertionPoint(1); + CPPUNIT_ASSERT_EQUAL( 3, m_text->GetLastPosition() ); + CPPUNIT_ASSERT_EQUAL( 1, m_text->GetInsertionPoint() ); + + m_text->SetInsertionPointEnd(); + CPPUNIT_ASSERT_EQUAL( 3, m_text->GetInsertionPoint() ); + + m_text->SetInsertionPoint(0); + m_text->WriteText("-"); // should move it after the written text + CPPUNIT_ASSERT_EQUAL( 4, m_text->GetLastPosition() ); + CPPUNIT_ASSERT_EQUAL( 1, m_text->GetInsertionPoint() ); +} +