]> git.saurik.com Git - wxWidgets.git/blobdiff - tests/strings/strings.cpp
Compilo.
[wxWidgets.git] / tests / strings / strings.cpp
index 7198b0cb7cd005384bcc4dcb877014a7ad958e9e..e66615565bb6c11b971928f8ce8b7d0942758d99 100644 (file)
@@ -54,6 +54,7 @@ private:
         CPPUNIT_TEST( ToDouble );
         CPPUNIT_TEST( WriteBuf );
         CPPUNIT_TEST( CStrDataTernaryOperator );
+        CPPUNIT_TEST( CStrDataOperators );
         CPPUNIT_TEST( CStrDataImplicitConversion );
         CPPUNIT_TEST( ExplicitConversion );
     CPPUNIT_TEST_SUITE_END();
@@ -81,6 +82,7 @@ private:
     void WriteBuf();
     void CStrDataTernaryOperator();
     void DoCStrDataTernaryOperator(bool cond);
+    void CStrDataOperators();
     void CStrDataImplicitConversion();
     void ExplicitConversion();
 
@@ -678,22 +680,35 @@ void StringTestCase::DoCStrDataTernaryOperator(bool cond)
     // are not very important, we're testing if the code compiles at all):
 
     wxString s("foo");
-    const char *mbStr = "foo";
-    const wchar_t *wcStr = L"foo";
 
-    // FIXME-UTF8: when wxCStrData can handle both conversions, this should
-    //             be changed to always test all versions, both MB and WC
-#if wxUSE_UNICODE
+    const wchar_t *wcStr = L"foo";
     CPPUNIT_ASSERT( CheckStr(s, (cond ? s.c_str() : wcStr)) );
-    CPPUNIT_ASSERT( CheckStr(s, (cond ? s.c_str() : L"bar")) );
+    CPPUNIT_ASSERT( CheckStr(s, (cond ? s.c_str() : L"foo")) );
     CPPUNIT_ASSERT( CheckStr(s, (cond ? wcStr : s.c_str())) );
-    CPPUNIT_ASSERT( CheckStr(s, (cond ? L"bar" : s.c_str())) );
-#else
+    CPPUNIT_ASSERT( CheckStr(s, (cond ? L"foo" : s.c_str())) );
+
+    const char *mbStr = "foo";
     CPPUNIT_ASSERT( CheckStr(s, (cond ? s.c_str() : mbStr)) );
     CPPUNIT_ASSERT( CheckStr(s, (cond ? s.c_str() : "foo")) );
     CPPUNIT_ASSERT( CheckStr(s, (cond ? mbStr : s.c_str())) );
     CPPUNIT_ASSERT( CheckStr(s, (cond ? "foo" : s.c_str())) );
-#endif
+
+    wxString empty("");
+    CPPUNIT_ASSERT( CheckStr(empty, (cond ? empty.c_str() : wxEmptyString)) );
+    CPPUNIT_ASSERT( CheckStr(empty, (cond ? wxEmptyString : empty.c_str())) );
+}
+
+void StringTestCase::CStrDataOperators()
+{
+    wxString s("hello");
+
+    CPPUNIT_ASSERT( s.c_str()[0] == 'h' );
+    CPPUNIT_ASSERT( s.c_str()[1] == 'e' );
+    CPPUNIT_ASSERT( s.c_str()[5] == '\0' );
+
+    CPPUNIT_ASSERT( *s.c_str() == 'h' );
+    CPPUNIT_ASSERT( *(s.c_str() + 2) == 'l' );
+    CPPUNIT_ASSERT( *(s.c_str() + 5) == '\0' );
 }
 
 bool CheckStrChar(const wxString& expected, char *s)
@@ -709,15 +724,11 @@ void StringTestCase::CStrDataImplicitConversion()
 {
     wxString s("foo");
 
-    // FIXME-UTF8: when wxCStrData can handle both conversions, this should
-    //             be changed to always test all versions, both MB and WC
-#if wxUSE_UNICODE
     CPPUNIT_ASSERT( CheckStrConstWChar(s, s.c_str()) );
     CPPUNIT_ASSERT( CheckStrConstWChar(s, s) );
-#else
+
     CPPUNIT_ASSERT( CheckStrConstChar(s, s.c_str()) );
     CPPUNIT_ASSERT( CheckStrConstChar(s, s) );
-#endif
 }
 
 void StringTestCase::ExplicitConversion()