]> git.saurik.com Git - wxWidgets.git/commitdiff
test wxString's char<->wchar_t ctors
authorVáclav Slavík <vslavik@fastmail.fm>
Tue, 8 Jun 2004 20:11:31 +0000 (20:11 +0000)
committerVáclav Slavík <vslavik@fastmail.fm>
Tue, 8 Jun 2004 20:11:31 +0000 (20:11 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@27696 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

tests/strings/strings.cpp

index 1784339aa3cf41c061a89e60365689b5f2dd92fa..fa633e6861a57f707b6b23d12a76582648be4f30 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!"));