]> git.saurik.com Git - wxWidgets.git/blobdiff - tests/strings/strings.cpp
fix some wrong declarations which upset mingw32
[wxWidgets.git] / tests / strings / strings.cpp
index e56d7e9a25a7c54e93232616a9bc560ba630de9d..268197281f6bc13382c6cdf8c6429938c30659c5 100644 (file)
@@ -53,7 +53,7 @@ private:
         CPPUNIT_TEST( ToULongLong );
 #endif // wxLongLong_t
         CPPUNIT_TEST( ToDouble );
-        CPPUNIT_TEST( WriteBuf );
+        CPPUNIT_TEST( StringBuf );
         CPPUNIT_TEST( UTF8Buf );
         CPPUNIT_TEST( CStrDataTernaryOperator );
         CPPUNIT_TEST( CStrDataOperators );
@@ -82,7 +82,7 @@ private:
     void ToULongLong();
 #endif // wxLongLong_t
     void ToDouble();
-    void WriteBuf();
+    void StringBuf();
     void UTF8Buf();
     void CStrDataTernaryOperator();
     void DoCStrDataTernaryOperator(bool cond);
@@ -374,22 +374,6 @@ void StringTestCase::CaseChanges()
     CPPUNIT_ASSERT( s1l == _T("hello!") );
     CPPUNIT_ASSERT( s2u == wxEmptyString );
     CPPUNIT_ASSERT( s2l == wxEmptyString );
-
-#if !wxUSE_UNICODE
-    wxLocale locRu(wxLANGUAGE_RUSSIAN, 0 /* flags */);
-    if ( locRu.IsOk() )
-    {
-        // try upper casing 8bit strings
-        const wchar_t capital_ya[] = { 0x42f, 0 },
-                      small_ya[]   = { 0x44f, 0 };
-
-        wxString sUpper(wxConvLibc.cWC2MB(capital_ya)),
-                 sLower(wxConvLibc.cWC2MB(small_ya));
-
-        CPPUNIT_ASSERT( sUpper.Lower() == sLower );
-        CPPUNIT_ASSERT( sLower.Upper() == sUpper );
-    }
-#endif // !wxUSE_UNICODE
 }
 
 void StringTestCase::Compare()
@@ -677,31 +661,50 @@ void StringTestCase::ToDouble()
     }
 }
 
-void StringTestCase::WriteBuf()
+void StringTestCase::StringBuf()
 {
+    // check that buffer can be used to write into the string
     wxString s;
     wxStrcpy(wxStringBuffer(s, 10), _T("foo"));
 
-    CPPUNIT_ASSERT(s[0u] == _T('f') );
+    WX_ASSERT_SIZET_EQUAL(3, s.length());
     CPPUNIT_ASSERT(_T('f') == s[0u]);
     CPPUNIT_ASSERT(_T('o') == s[1]);
     CPPUNIT_ASSERT(_T('o') == s[2]);
-    WX_ASSERT_SIZET_EQUAL(3, s.length());
 
+    {
+        // also check that the buffer initially contains the original string
+        // contents
+        wxStringBuffer buf(s, 10);
+        CPPUNIT_ASSERT_EQUAL( _T('f'), buf[0] );
+        CPPUNIT_ASSERT_EQUAL( _T('o'), buf[1] );
+        CPPUNIT_ASSERT_EQUAL( _T('o'), buf[2] );
+        CPPUNIT_ASSERT_EQUAL( _T('\0'), buf[3] );
+    }
 
     {
         wxStringBufferLength buf(s, 10);
+        CPPUNIT_ASSERT_EQUAL( _T('f'), buf[0] );
+        CPPUNIT_ASSERT_EQUAL( _T('o'), buf[1] );
+        CPPUNIT_ASSERT_EQUAL( _T('o'), buf[2] );
+        CPPUNIT_ASSERT_EQUAL( _T('\0'), buf[3] );
+
+        // and check that it can be used to write only the specified number of
+        // characters to the string
         wxStrcpy(buf, _T("barrbaz"));
         buf.SetLength(4);
     }
 
+    WX_ASSERT_SIZET_EQUAL(4, s.length());
     CPPUNIT_ASSERT(_T('b') == s[0u]);
     CPPUNIT_ASSERT(_T('a') == s[1]);
     CPPUNIT_ASSERT(_T('r') == s[2]);
     CPPUNIT_ASSERT(_T('r') == s[3]);
-    WX_ASSERT_SIZET_EQUAL(4, s.length());
 
-    CPPUNIT_ASSERT_EQUAL( 0, wxStrcmp(_T("barr"), s) );
+    // check that creating buffer of length smaller than string works, i.e. at
+    // least doesn't crash (it would if we naively copied the entire original
+    // string contents in the buffer)
+    *wxStringBuffer(s, 1) = '!';
 }
 
 void StringTestCase::UTF8Buf()