]> git.saurik.com Git - wxWidgets.git/blobdiff - tests/strings/strings.cpp
mention that Check() doesn't work before the item is attached to a menu
[wxWidgets.git] / tests / strings / strings.cpp
index 636ee7e99385f18e5ecc298f3d26fb4b00844d0e..d8dc4fa3c2cccb6402c22d702acd9915c80fabee 100644 (file)
@@ -40,23 +40,31 @@ 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 );
         CPPUNIT_TEST( Replace );
         CPPUNIT_TEST( Match );
+        CPPUNIT_TEST( CaseChanges );
     CPPUNIT_TEST_SUITE_END();
 
     void String();
     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 );
     void Tokenizer();
     void Replace();
     void Match();
+    void CaseChanges();
 
     DECLARE_NO_COPY_CLASS(StringTestCase)
 };
@@ -136,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!"));
@@ -271,3 +307,33 @@ void StringTestCase::Match()
     #undef TEST_MATCH
 }
 
+
+void StringTestCase::CaseChanges()
+{
+    wxString s1(_T("Hello!"));
+    wxString s1u(s1);
+    wxString s1l(s1);
+    s1u.MakeUpper();
+    s1l.MakeLower();
+    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 );
+
+#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
+}