X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/6bd4f2812dca25f2c693ba27e5c117deee71fb3e..ec592d7f3ebad36e669525592005b9a3da5893f4:/tests/strings/strings.cpp diff --git a/tests/strings/strings.cpp b/tests/strings/strings.cpp index a3fec56598..7fcc223c9c 100644 --- a/tests/strings/strings.cpp +++ b/tests/strings/strings.cpp @@ -60,6 +60,7 @@ private: CPPUNIT_TEST( CStrDataImplicitConversion ); CPPUNIT_TEST( ExplicitConversion ); CPPUNIT_TEST( IndexedAccess ); + CPPUNIT_TEST( BeforeAndAfter ); CPPUNIT_TEST_SUITE_END(); void String(); @@ -91,6 +92,7 @@ private: void CStrDataImplicitConversion(); void ExplicitConversion(); void IndexedAccess(); + void BeforeAndAfter(); DECLARE_NO_COPY_CLASS(StringTestCase) }; @@ -316,7 +318,7 @@ void StringTestCase::Replace() { \ wxString s(o,olen); \ s.replace( pos , len , replacement ); \ - CPPUNIT_ASSERT( s == wxString(r,rlen) ); \ + CPPUNIT_ASSERT_EQUAL( wxString(r,rlen), s ); \ } TEST_NULLCHARREPLACE( _T("null\0char"), 9, 5, 1, _T("d"), @@ -326,7 +328,7 @@ void StringTestCase::Replace() { \ wxString s(o,olen); \ s.Replace( olds, news, all ); \ - CPPUNIT_ASSERT( s == wxString(r,rlen) ); \ + CPPUNIT_ASSERT_EQUAL( wxString(r,rlen), s ); \ } TEST_WXREPLACE( _T("null\0char"), 9, _T("c"), _T("de"), true, @@ -336,6 +338,10 @@ void StringTestCase::Replace() _T("null\0char"), 9 ); TEST_WXREPLACE( "life", 4, "f", "", false, "lie", 3 ); + TEST_WXREPLACE( "life", 4, "f", "", true, "lie", 3 ); + TEST_WXREPLACE( "life", 4, "fe", "ve", true, "live", 4 ); + TEST_WXREPLACE( "xx", 2, "x", "yy", true, "yyyy", 4 ); + TEST_WXREPLACE( "xxx", 3, "xx", "z", true, "zx", 2 ); #undef TEST_WXREPLACE #undef TEST_NULLCHARREPLACE @@ -529,7 +535,7 @@ enum Number_Unsigned = 2, // if not specified, works for signed conversion Number_Signed = 4, // if not specified, works for unsigned Number_LongLong = 8, // only for long long tests - Number_Long = 16, // only for long tests + Number_Long = 16 // only for long tests }; static const struct ToLongData @@ -832,12 +838,33 @@ void StringTestCase::ExplicitConversion() void StringTestCase::IndexedAccess() { wxString s("bar"); - CPPUNIT_ASSERT_EQUAL( 'r', s[2] ); + CPPUNIT_ASSERT_EQUAL( 'r', (char)s[2] ); // this tests for a possible bug in UTF-8 based wxString implementation: // the 3rd character of the underlying byte string is going to change, but // the 3rd character of wxString should remain the same - s[0] = L'\u00e9'; - CPPUNIT_ASSERT_EQUAL( 'r', s[2] ); + s[0] = L'\xe9'; + CPPUNIT_ASSERT_EQUAL( 'r', (char)s[2] ); +} + +void StringTestCase::BeforeAndAfter() +{ + const wxString s(L"letter=\xe9;\xe7a=l\xe0"); + + CPPUNIT_ASSERT_EQUAL( "letter", s.BeforeFirst('=') ); + CPPUNIT_ASSERT_EQUAL( s, s.BeforeFirst('!') ); + CPPUNIT_ASSERT_EQUAL( L"letter=\xe9", s.BeforeFirst(';') ); + + CPPUNIT_ASSERT_EQUAL( L"letter=\xe9;\xe7a", s.BeforeLast('=') ); + CPPUNIT_ASSERT_EQUAL( "", s.BeforeLast('!') ); + CPPUNIT_ASSERT_EQUAL( L"letter=\xe9", s.BeforeLast(';') ); + + CPPUNIT_ASSERT_EQUAL( L"\xe9;\xe7a=l\xe0", s.AfterFirst('=') ); + CPPUNIT_ASSERT_EQUAL( "", s.AfterFirst('!') ); + CPPUNIT_ASSERT_EQUAL( L"\xe7a=l\xe0", s.AfterFirst(';') ); + + CPPUNIT_ASSERT_EQUAL( L"l\xe0", s.AfterLast('=') ); + CPPUNIT_ASSERT_EQUAL( s, s.AfterLast('!') ); + CPPUNIT_ASSERT_EQUAL( L"\xe7a=l\xe0", s.AfterLast(';') ); }