]> git.saurik.com Git - wxWidgets.git/blobdiff - tests/strings/strings.cpp
don't use WPARAM in the header (build fix after r59336)
[wxWidgets.git] / tests / strings / strings.cpp
index faa4548375b158fe24f6a0f816a2952e40e1786b..09686b11da5b493e6d854e7f2ec6cc4023a5d5a2 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
@@ -366,14 +372,26 @@ void StringTestCase::CaseChanges()
     wxString s1l(s1);
     s1u.MakeUpper();
     s1l.MakeLower();
+
+    CPPUNIT_ASSERT_EQUAL( _T("HELLO!"), s1u );
+    CPPUNIT_ASSERT_EQUAL( _T("hello!"), s1l );
+
     wxString s2u, s2l;
     s2u.MakeUpper();
     s2l.MakeLower();
 
-    CPPUNIT_ASSERT( s1u == _T("HELLO!") );
-    CPPUNIT_ASSERT( s1l == _T("hello!") );
-    CPPUNIT_ASSERT( s2u == wxEmptyString );
-    CPPUNIT_ASSERT( s2l == wxEmptyString );
+    CPPUNIT_ASSERT_EQUAL( "", s2u );
+    CPPUNIT_ASSERT_EQUAL( "", s2l );
+
+
+    wxString s3("good bye");
+    CPPUNIT_ASSERT_EQUAL( "Good bye", s3.Capitalize() );
+    s3.MakeCapitalized();
+    CPPUNIT_ASSERT_EQUAL( "Good bye", s3 );
+
+    CPPUNIT_ASSERT_EQUAL( "Abc", wxString("ABC").Capitalize() );
+
+    CPPUNIT_ASSERT_EQUAL( "", wxString().Capitalize() );
 }
 
 void StringTestCase::Compare()
@@ -513,7 +531,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
@@ -812,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', (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'\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(';') );
+}
+