]> git.saurik.com Git - wxWidgets.git/blobdiff - tests/strings/strings.cpp
started wxFileConfig unit test
[wxWidgets.git] / tests / strings / strings.cpp
index 1784339aa3cf41c061a89e60365689b5f2dd92fa..d8dc4fa3c2cccb6402c22d702acd9915c80fabee 100644 (file)
@@ -40,6 +40,9 @@ private:
         CPPUNIT_TEST( PChar );
         CPPUNIT_TEST( Format );
         CPPUNIT_TEST( Constructors );
+#if wxUSE_WCHAR_T
+        CPPUNIT_TEST( ConstructorsWithConversion );
+#endif
         CPPUNIT_TEST( Extraction );
         CPPUNIT_TEST( Find );
         CPPUNIT_TEST( Tokenizer );
@@ -52,6 +55,9 @@ private:
     void PChar();
     void Format();
     void Constructors();
+#if wxUSE_WCHAR_T
+    void ConstructorsWithConversion();
+#endif
     void Extraction();
     void Find();
     void SingleTokenizerTest( wxChar *str, wxChar *delims, size_t count , wxStringTokenizerMode mode );
@@ -138,6 +144,34 @@ void StringTestCase::Constructors()
     TEST_CTOR((start, end), _T("really"));
 }
 
+#if wxUSE_WCHAR_T
+void StringTestCase::ConstructorsWithConversion()
+{
+    // Déj`a in UTF-8 and wchar_t:
+    const char utf8[] = {0x44,0xC3,0xA9,0x6A,0xC3,0xA0,0};
+    const wchar_t wchar[] = {0x44,0xE9,0x6A,0xE0,0};
+    const char utf8sub[] = {0x44,0xC3,0xA9,0x6A,0}; // "Dej"
+    
+    wxString s1(utf8, wxConvUTF8);
+    wxString s2(wchar, wxConvUTF8);
+
+#if wxUSE_UNICODE
+    CPPUNIT_ASSERT( s1 == wchar );
+    CPPUNIT_ASSERT( s2 == wchar );
+#else
+    CPPUNIT_ASSERT( s1 == utf8 );
+    CPPUNIT_ASSERT( s2 == utf8 );
+#endif
+
+    wxString sub(utf8sub, wxConvUTF8); // "Dej" substring
+    wxString s3(utf8, wxConvUTF8, 4);
+    wxString s4(wchar, wxConvUTF8, 3);
+
+    CPPUNIT_ASSERT( s3 == sub );
+    CPPUNIT_ASSERT( s4 == sub );    
+}
+#endif
+
 void StringTestCase::Extraction()
 {
     wxString s(_T("Hello, world!"));
@@ -289,4 +323,17 @@ 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
+        wxString sUpper("\xdf"),
+                 sLower("\xff");
+
+        CPPUNIT_ASSERT( sUpper.Lower() == sLower );
+        CPPUNIT_ASSERT( sLower.Upper() == sUpper );
+    }
+#endif // !wxUSE_UNICODE
 }