diff --git a/tests/controls/textctrltest.cpp b/tests/controls/textctrltest.cpp index 1a8445c518..c65d91045f 100644 --- a/tests/controls/textctrltest.cpp +++ b/tests/controls/textctrltest.cpp @@ -94,6 +94,12 @@ private: CPPUNIT_TEST( PositionToCoordsRich2 ); CPPUNIT_TEST( PositionToXYMultiLine ); CPPUNIT_TEST( XYToPositionMultiLine ); +#if wxUSE_RICHEDIT + CPPUNIT_TEST( PositionToXYMultiLineRich ); + CPPUNIT_TEST( XYToPositionMultiLineRich ); + CPPUNIT_TEST( PositionToXYMultiLineRich2 ); + CPPUNIT_TEST( XYToPositionMultiLineRich2 ); +#endif // wxUSE_RICHEDIT CPPUNIT_TEST_SUITE_END(); void PseudoTestSwitchToMultiLineStyle() @@ -118,10 +124,18 @@ private: void PositionToCoordsRich2(); void PositionToXYMultiLine(); void XYToPositionMultiLine(); +#if wxUSE_RICHEDIT + void PositionToXYMultiLineRich(); + void XYToPositionMultiLineRich(); + void PositionToXYMultiLineRich2(); + void XYToPositionMultiLineRich2(); +#endif // wxUSE_RICHEDIT void PositionToXYSingleLine(); void XYToPositionSingleLine(); void DoPositionToCoordsTestWithStyle(long style); + void DoPositionToXYMultiLine(long style); + void DoXYToPositionMultiLine(long style); // Create the control with the following styles added to ms_style which may // (or not) already contain wxTE_MULTILINE. @@ -662,19 +676,40 @@ void TextCtrlTestCase::DoPositionToCoordsTestWithStyle(long style) void TextCtrlTestCase::PositionToXYMultiLine() { - delete m_text; - CreateText(wxTE_MULTILINE|wxTE_DONTWRAP); + DoPositionToXYMultiLine(0); +} +#if wxUSE_RICHEDIT +void TextCtrlTestCase::PositionToXYMultiLineRich() +{ + DoPositionToXYMultiLine(wxTE_RICH); +} + +void TextCtrlTestCase::PositionToXYMultiLineRich2() +{ + DoPositionToXYMultiLine(wxTE_RICH2); +} +#endif // wxUSE_RICHEDIT + +void TextCtrlTestCase::DoPositionToXYMultiLine(long style) +{ + delete m_text; + CreateText(style|wxTE_MULTILINE|wxTE_DONTWRAP); + + const bool isRichEdit = (style & (wxTE_RICH | wxTE_RICH2)) != 0; + + typedef struct { long x, y; } XYPos; bool ok; wxString text; - // empty field + // empty field m_text->Clear(); const long numChars_0 = 0; - CPPUNIT_ASSERT_EQUAL( numChars_0, m_text->GetLastPosition() ); - struct { long x, y; } coords_0[numChars_0+1] = + wxASSERT(numChars_0 == text.Length()); + XYPos coords_0[numChars_0+1] = { { 0, 0 } }; + CPPUNIT_ASSERT_EQUAL( numChars_0, m_text->GetLastPosition() ); for ( long i = 0; i < (long)WXSIZEOF(coords_0); i++ ) { long x, y; @@ -691,10 +726,10 @@ void TextCtrlTestCase::PositionToXYMultiLine() m_text->SetValue(text); const long numChars_1 = 4; wxASSERT( numChars_1 == text.Length() ); - CPPUNIT_ASSERT_EQUAL( numChars_1, m_text->GetLastPosition() ); - struct { long x, y; } coords_1[numChars_1+1] = + XYPos coords_1[numChars_1+1] = { { 0, 0 }, { 1, 0 }, { 2, 0}, { 3, 0 }, { 4, 0 } }; + CPPUNIT_ASSERT_EQUAL( numChars_1, m_text->GetLastPosition() ); for ( long i = 0; i < (long)WXSIZEOF(coords_1); i++ ) { long x, y; @@ -709,121 +744,179 @@ void TextCtrlTestCase::PositionToXYMultiLine() // few lines text = wxS("123\nab\nX"); m_text->SetValue(text); + #if defined(__WXMSW__) // Take into account that every new line mark occupies // two characters, not one. - const long numChars_2 = 8 + 2; -#else - const long numChars_2 = 8; -#endif // WXMSW/!WXMSW - CPPUNIT_ASSERT_EQUAL( numChars_2, m_text->GetLastPosition() ); -#if defined(__WXMSW__) + const long numChars_msw_2 = 8 + 2; // Note: Two new line characters refer to the same X-Y position. - struct { long x, y; } coords_2[numChars_2 + 1] = - { { 0, 0 }, { 1, 0 }, { 2, 0 }, { 3, 0 }, { 3, 0 }, - { 0, 1 }, { 1, 1 }, { 2, 1 }, { 2, 1 }, - { 0, 2 }, { 1, 2 } }; -#else - struct { long x, y; } coords_2[numChars_2 + 1] = - { { 0, 0 }, { 1, 0 }, { 2, 0 }, { 3, 0 }, - { 0, 1 }, { 1, 1 }, { 2, 1 }, - { 0, 2 }, { 1, 2 } }; -#endif // WXMSW/!WXMSW + XYPos coords_2_msw[numChars_msw_2 + 1] = + { { 0, 0 },{ 1, 0 },{ 2, 0 },{ 3, 0 },{ 3, 0 }, + { 0, 1 },{ 1, 1 },{ 2, 1 },{ 2, 1 }, + { 0, 2 },{ 1, 2 } }; +#endif // WXMSW - for ( long i = 0; i < (long)WXSIZEOF(coords_2); i++ ) + const long numChars_2 = 8; + wxASSERT(numChars_2 == text.Length()); + XYPos coords_2[numChars_2 + 1] = + { { 0, 0 }, { 1, 0 }, { 2, 0 }, { 3, 0 }, + { 0, 1 }, { 1, 1 }, { 2, 1 }, + { 0, 2 }, { 1, 2 } }; + + const long &ref_numChars_2 = +#if defined(__WXMSW__) + isRichEdit ? numChars_2 : numChars_msw_2; +#else + numChars_2; +#endif + + XYPos *ref_coords_2 = +#if defined(__WXMSW__) + isRichEdit ? coords_2 : coords_2_msw; +#else + coords_2; +#endif + + CPPUNIT_ASSERT_EQUAL( ref_numChars_2, m_text->GetLastPosition() ); + for ( long i = 0; i < ref_numChars_2+1; i++ ) { long x, y; ok = m_text->PositionToXY(i, &x, &y); CPPUNIT_ASSERT_EQUAL( true, ok ); - CPPUNIT_ASSERT_EQUAL( coords_2[i].x, x ); - CPPUNIT_ASSERT_EQUAL( coords_2[i].y, y ); + CPPUNIT_ASSERT_EQUAL( ref_coords_2[i].x, x ); + CPPUNIT_ASSERT_EQUAL( ref_coords_2[i].y, y ); } - ok = m_text->PositionToXY(WXSIZEOF(coords_2), NULL, NULL); + ok = m_text->PositionToXY(ref_numChars_2 + 1, NULL, NULL); CPPUNIT_ASSERT_EQUAL( false, ok ); // only empty lines text = wxS("\n\n\n"); m_text->SetValue(text); + #if defined(__WXMSW__) // Take into account that every new line mark occupies // two characters, not one. - const long numChars_3 = 3 + 3; -#else - const long numChars_3 = 3; -#endif // WXMSW/!WXMSW - CPPUNIT_ASSERT_EQUAL( numChars_3, m_text->GetLastPosition() ); -#if defined(__WXMSW__) + const long numChars_msw_3 = 3 + 3; // Note: Two new line characters refer to the same X-Y position. - struct { long x, y; } coords_3[numChars_3 + 1] = - { { 0, 0 }, { 0, 0 }, - { 0, 1 }, { 0, 1 }, - { 0, 2 }, { 0, 2 }, + XYPos coords_3_msw[numChars_msw_3 + 1] = + { { 0, 0 },{ 0, 0 }, + { 0, 1 },{ 0, 1 }, + { 0, 2 },{ 0, 2 }, { 0, 3 } }; -#else - struct { long x, y; } coords_3[numChars_3+1] = +#endif // WXMSW + + const long numChars_3 = 3; + wxASSERT(numChars_3 == text.Length()); + XYPos coords_3[numChars_3+1] = { { 0, 0 }, { 0, 1 }, { 0, 2 }, { 0, 3 } }; -#endif // WXMSW/!WXMSW - for ( long i = 0; i < (long)WXSIZEOF(coords_3); i++ ) + const long &ref_numChars_3 = +#if defined(__WXMSW__) + isRichEdit ? numChars_3 : numChars_msw_3; +#else + numChars_3; +#endif + + XYPos *ref_coords_3 = +#if defined(__WXMSW__) + isRichEdit ? coords_3 : coords_3_msw; +#else + coords_3; +#endif + + CPPUNIT_ASSERT_EQUAL( ref_numChars_3, m_text->GetLastPosition() ); + for ( long i = 0; i < ref_numChars_3+1; i++ ) { long x, y; ok = m_text->PositionToXY(i, &x, &y); CPPUNIT_ASSERT_EQUAL( true, ok ); - CPPUNIT_ASSERT_EQUAL( coords_3[i].x, x ); - CPPUNIT_ASSERT_EQUAL( coords_3[i].y, y ); + CPPUNIT_ASSERT_EQUAL( ref_coords_3[i].x, x ); + CPPUNIT_ASSERT_EQUAL( ref_coords_3[i].y, y ); } - ok = m_text->PositionToXY(WXSIZEOF(coords_3), NULL, NULL); + ok = m_text->PositionToXY(ref_numChars_3 + 1, NULL, NULL); CPPUNIT_ASSERT_EQUAL( false, ok ); // mixed empty/non-empty lines text = wxS("123\na\n\nX\n\n"); m_text->SetValue(text); + #if defined(__WXMSW__) // Take into account that every new line mark occupies // two characters, not one. - const long numChars_4 = 10 + 5; -#else - const long numChars_4 = 10; -#endif // WXMSW/!WXMSW - CPPUNIT_ASSERT_EQUAL( numChars_4, m_text->GetLastPosition() ); -#if defined(__WXMSW__) + const long numChars_msw_4 = 10 + 5; // Note: Two new line characters refer to the same X-Y position. - struct { long x, y; } coords_4[numChars_4 + 1] = - { { 0, 0 }, { 1, 0 }, { 2, 0 }, { 3, 0 }, { 3, 0 }, - { 0, 1 }, { 1, 1 }, { 1, 1 }, - { 0, 2 }, { 0, 2 }, - { 0, 3 }, { 1, 3 }, { 1, 3 }, - { 0, 4 }, { 0, 4 }, + XYPos coords_4_msw[numChars_msw_4 + 1] = + { { 0, 0 },{ 1, 0 },{ 2, 0 },{ 3, 0 },{ 3, 0 }, + { 0, 1 },{ 1, 1 },{ 1, 1 }, + { 0, 2 },{ 0, 2 }, + { 0, 3 },{ 1, 3 },{ 1, 3 }, + { 0, 4 },{ 0, 4 }, { 0, 5 } }; -#else - struct { long x, y; } coords_4[numChars_4+1] = +#endif // WXMSW + + const long numChars_4 = 10; + wxASSERT(numChars_4 == text.Length()); + XYPos coords_4[numChars_4+1] = { { 0, 0 }, { 1, 0 }, { 2, 0 }, { 3, 0 }, { 0, 1 }, { 1, 1 }, { 0, 2 }, { 0, 3 }, { 1, 3 }, { 0, 4 }, { 0, 5 } }; -#endif // WXMSW/!WXMSW - for ( long i = 0; i < (long)WXSIZEOF(coords_4); i++ ) + const long &ref_numChars_4 = +#if defined(__WXMSW__) + isRichEdit ? numChars_4 : numChars_msw_4; +#else + numChars_4; +#endif + + XYPos *ref_coords_4 = +#if defined(__WXMSW__) + isRichEdit ? coords_4 : coords_4_msw; +#else + coords_4; +#endif + + CPPUNIT_ASSERT_EQUAL( ref_numChars_4, m_text->GetLastPosition() ); + for ( long i = 0; i < ref_numChars_4+1; i++ ) { long x, y; ok = m_text->PositionToXY(i, &x, &y); CPPUNIT_ASSERT_EQUAL( true, ok ); - CPPUNIT_ASSERT_EQUAL( coords_4[i].x, x ); - CPPUNIT_ASSERT_EQUAL( coords_4[i].y, y ); + CPPUNIT_ASSERT_EQUAL( ref_coords_4[i].x, x ); + CPPUNIT_ASSERT_EQUAL( ref_coords_4[i].y, y ); } - ok = m_text->PositionToXY(WXSIZEOF(coords_4), NULL, NULL); + ok = m_text->PositionToXY(ref_numChars_4 + 1, NULL, NULL); CPPUNIT_ASSERT_EQUAL( false, ok ); } void TextCtrlTestCase::XYToPositionMultiLine() +{ + DoXYToPositionMultiLine(0); +} + +#if wxUSE_RICHEDIT +void TextCtrlTestCase::XYToPositionMultiLineRich() +{ + DoXYToPositionMultiLine(wxTE_RICH); +} + +void TextCtrlTestCase::XYToPositionMultiLineRich2() +{ + DoXYToPositionMultiLine(wxTE_RICH2); +} +#endif // wxUSE_RICHEDIT + +void TextCtrlTestCase::DoXYToPositionMultiLine(long style) { delete m_text; - CreateText(wxTE_MULTILINE|wxTE_DONTWRAP); + CreateText(style|wxTE_MULTILINE|wxTE_DONTWRAP); + + const bool isRichEdit = (style & (wxTE_RICH | wxTE_RICH2)) != 0; wxString text; // empty field @@ -865,24 +958,30 @@ void TextCtrlTestCase::XYToPositionMultiLine() CPPUNIT_ASSERT_EQUAL( numLines_2, m_text->GetNumberOfLines() ); #if defined(__WXMSW__) // Note: New lines are occupied by two characters. - long pos_2[numLines_2 + 1][maxLineLength_2 + 1] = + long pos_2_msw[numLines_2 + 1][maxLineLength_2 + 1] = { { 0, 1, 2, 3, -1 }, // New line occupies positions 3, 4 { 5, 6, 7, -1, -1 }, // New line occupies positions 7, 8 { 9, 10, -1, -1, -1 }, { -1, -1, -1, -1, -1 } }; -#else +#endif // WXMSW long pos_2[numLines_2+1][maxLineLength_2+1] = { { 0, 1, 2, 3, -1 }, { 4, 5, 6, -1, -1 }, { 7, 8, -1, -1, -1 }, { -1, -1, -1, -1, -1 } }; -#endif // WXMSW/!WXMSW + + long (&ref_pos_2)[numLines_2 + 1][maxLineLength_2 + 1] = +#if defined(__WXMSW__) + isRichEdit ? pos_2 : pos_2_msw; +#else + pos_2; +#endif for ( long y = 0; y < numLines_2+1; y++ ) for( long x = 0; x < maxLineLength_2+1; x++ ) { long p = m_text->XYToPosition(x, y); - CPPUNIT_ASSERT_EQUAL( pos_2[y][x], p ); + CPPUNIT_ASSERT_EQUAL( ref_pos_2[y][x], p ); } // only empty lines @@ -893,26 +992,32 @@ void TextCtrlTestCase::XYToPositionMultiLine() CPPUNIT_ASSERT_EQUAL( numLines_3, m_text->GetNumberOfLines() ); #if defined(__WXMSW__) // Note: New lines are occupied by two characters. - long pos_3[numLines_3 + 1][maxLineLength_3 + 1] = + long pos_3_msw[numLines_3 + 1][maxLineLength_3 + 1] = { { 0, -1 }, // New line occupies positions 0, 1 { 2, -1 }, // New line occupies positions 2, 3 { 4, -1 }, // New line occupies positions 4, 5 { 6, -1 }, { -1, -1 } }; -#else +#endif // WXMSW long pos_3[numLines_3+1][maxLineLength_3+1] = { { 0, -1 }, { 1, -1 }, { 2, -1 }, { 3, -1 }, { -1, -1 } }; -#endif // WXMSW/!WXMSW + + long (&ref_pos_3)[numLines_3 + 1][maxLineLength_3 + 1] = +#if defined(__WXMSW__) + isRichEdit ? pos_3 : pos_3_msw; +#else + pos_3; +#endif for ( long y = 0; y < numLines_3+1; y++ ) for( long x = 0; x < maxLineLength_3+1; x++ ) { long p = m_text->XYToPosition(x, y); - CPPUNIT_ASSERT_EQUAL( pos_3[y][x], p ); + CPPUNIT_ASSERT_EQUAL( ref_pos_3[y][x], p ); } // mixed empty/non-empty lines @@ -923,7 +1028,7 @@ void TextCtrlTestCase::XYToPositionMultiLine() CPPUNIT_ASSERT_EQUAL( numLines_4, m_text->GetNumberOfLines() ); #if defined(__WXMSW__) // Note: New lines are occupied by two characters. - long pos_4[numLines_4 + 1][maxLineLength_4 + 1] = + long pos_4_msw[numLines_4 + 1][maxLineLength_4 + 1] = { { 0, 1, 2, 3, -1 }, // New line occupies positions 3, 4 { 5, 6, -1, -1, -1 }, // New line occupies positions 6, 7 { 8, -1, -1, -1, -1 }, // New line occupies positions 8, 9 @@ -931,7 +1036,7 @@ void TextCtrlTestCase::XYToPositionMultiLine() { 13, -1, -1, -1, -1 }, // New line occupies positions 13, 14 { 15, -1, -1, -1, -1 }, { -1, -1, -1, -1, -1 } }; -#else +#endif // WXMSW long pos_4[numLines_4+1][maxLineLength_4+1] = { { 0, 1, 2, 3, -1 }, { 4, 5, -1, -1, -1 }, @@ -940,13 +1045,19 @@ void TextCtrlTestCase::XYToPositionMultiLine() { 9, -1, -1, -1, -1 }, { 10, -1, -1, -1, -1 }, { -1, -1, -1, -1, -1 } }; -#endif // WXMSW/!WXMSW + + long (&ref_pos_4)[numLines_4 + 1][maxLineLength_4 + 1] = +#if defined(__WXMSW__) + isRichEdit ? pos_4 : pos_4_msw; +#else + pos_4; +#endif for ( long y = 0; y < numLines_4+1; y++ ) for( long x = 0; x < maxLineLength_4+1; x++ ) { long p = m_text->XYToPosition(x, y); - CPPUNIT_ASSERT_EQUAL( pos_4[y][x], p ); + CPPUNIT_ASSERT_EQUAL( ref_pos_4[y][x], p ); } }