]> git.saurik.com Git - wxWidgets.git/blobdiff - tests/strings/strings.cpp
wxMOTIF ?: wxcursor:wxcursor overload fix
[wxWidgets.git] / tests / strings / strings.cpp
index 09e0dca52c890cff5a8809f7ccdcdf738a344068..3542704e49cea77d7aca63941bbfc617fd94bae2 100644 (file)
@@ -59,6 +59,8 @@ private:
         CPPUNIT_TEST( CStrDataOperators );
         CPPUNIT_TEST( CStrDataImplicitConversion );
         CPPUNIT_TEST( ExplicitConversion );
+        CPPUNIT_TEST( IndexedAccess );
+        CPPUNIT_TEST( BeforeAndAfter );
     CPPUNIT_TEST_SUITE_END();
 
     void String();
@@ -89,6 +91,8 @@ private:
     void CStrDataOperators();
     void CStrDataImplicitConversion();
     void ExplicitConversion();
+    void IndexedAccess();
+    void BeforeAndAfter();
 
     DECLARE_NO_COPY_CLASS(StringTestCase)
 };
@@ -333,6 +337,8 @@ void StringTestCase::Replace()
     TEST_WXREPLACE( _T("null\0dehar"), 10, _T("de"), _T("c"), true,
                           _T("null\0char"), 9 );
 
+    TEST_WXREPLACE( "life", 4, "f", "", false, "lie", 3 );
+
     #undef TEST_WXREPLACE
     #undef TEST_NULLCHARREPLACE
     #undef TEST_REPLACE
@@ -824,3 +830,37 @@ void StringTestCase::ExplicitConversion()
     CPPUNIT_ASSERT( CheckStrConstWChar(s, s.wc_str()) );
     CPPUNIT_ASSERT( CheckStrWChar(s, s.wchar_str()) );
 }
+
+void StringTestCase::IndexedAccess()
+{
+    wxString s("bar");
+    CPPUNIT_ASSERT_EQUAL( 'r', 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] );
+}
+
+void StringTestCase::BeforeAndAfter()
+{
+    const wxString s(L"letter=\u00e9;\u00e7a=l\u00e0");
+
+    CPPUNIT_ASSERT_EQUAL( "letter", s.BeforeFirst('=') );
+    CPPUNIT_ASSERT_EQUAL( s, s.BeforeFirst('!') );
+    CPPUNIT_ASSERT_EQUAL( L"letter=\u00e9", s.BeforeFirst(';') );
+
+    CPPUNIT_ASSERT_EQUAL( L"letter=\u00e9;\u00e7a", s.BeforeLast('=') );
+    CPPUNIT_ASSERT_EQUAL( "", s.BeforeLast('!') );
+    CPPUNIT_ASSERT_EQUAL( L"letter=\u00e9", s.BeforeLast(';') );
+
+    CPPUNIT_ASSERT_EQUAL( L"\u00e9;\u00e7a=l\u00e0", s.AfterFirst('=') );
+    CPPUNIT_ASSERT_EQUAL( "", s.AfterFirst('!') );
+    CPPUNIT_ASSERT_EQUAL( L"\u00e7a=l\u00e0", s.AfterFirst(';') );
+
+    CPPUNIT_ASSERT_EQUAL( L"l\u00e0", s.AfterLast('=') );
+    CPPUNIT_ASSERT_EQUAL( s, s.AfterLast('!') );
+    CPPUNIT_ASSERT_EQUAL( L"\u00e7a=l\u00e0", s.AfterLast(';') );
+}
+