]> git.saurik.com Git - wxWidgets.git/blobdiff - tests/strings/strings.cpp
fix building with WXWIN_COMPATIBILITY_2_8 == 0
[wxWidgets.git] / tests / strings / strings.cpp
index 98e6619a80b283fff64fe6f35568fb31b1bdffd7..b016294724d2f66ce14476d54e5d51484de9aa94 100644 (file)
@@ -3,7 +3,6 @@
 // Purpose:     wxString unit test
 // Author:      Vadim Zeitlin, Wlodzimierz ABX Skiba
 // Created:     2004-04-19
-// RCS-ID:      $Id$
 // Copyright:   (c) 2004 Vadim Zeitlin, Wlodzimierz Skiba
 ///////////////////////////////////////////////////////////////////////////////
 
@@ -35,6 +34,7 @@ private:
         CPPUNIT_TEST( String );
         CPPUNIT_TEST( PChar );
         CPPUNIT_TEST( Format );
+        CPPUNIT_TEST( FormatUnicode );
         CPPUNIT_TEST( Constructors );
         CPPUNIT_TEST( StaticConstructors );
         CPPUNIT_TEST( Extraction );
@@ -68,6 +68,7 @@ private:
     void String();
     void PChar();
     void Format();
+    void FormatUnicode();
     void Constructors();
     void StaticConstructors();
     void Extraction();
@@ -174,6 +175,20 @@ void StringTestCase::Format()
     );
 }
 
+void StringTestCase::FormatUnicode()
+{
+#if wxUSE_UNICODE
+    const char *UNICODE_STR = "Iestat\xC4\xAB %i%i";
+    //const char *UNICODE_STR = "Iestat\xCC\x84 %i%i";
+
+    wxString fmt = wxString::FromUTF8(UNICODE_STR);
+    wxString s = wxString::Format(fmt, 1, 1);
+    wxString expected(fmt);
+    expected.Replace("%i", "1");
+    CPPUNIT_ASSERT_EQUAL( expected, s );
+#endif // wxUSE_UNICODE
+}
+
 void StringTestCase::Constructors()
 {
     CPPUNIT_ASSERT_EQUAL( "", wxString('Z', 0) );
@@ -381,17 +396,17 @@ void StringTestCase::Match()
     #define TEST_MATCH( s1 , s2 , result ) \
         CPPUNIT_ASSERT( wxString(s1).Matches(s2) == result )
 
-    TEST_MATCH( wxT("foobar"),    wxT("foo*"),   true  );
-    TEST_MATCH( wxT("foobar"),    wxT("*oo*"),   true  );
-    TEST_MATCH( wxT("foobar"),    wxT("*bar"),   true  );
-    TEST_MATCH( wxT("foobar"),    wxT("??????"), true  );
-    TEST_MATCH( wxT("foobar"),    wxT("f??b*"),  true  );
-    TEST_MATCH( wxT("foobar"),    wxT("f?b*"),   false );
-    TEST_MATCH( wxT("foobar"),    wxT("*goo*"),  false );
-    TEST_MATCH( wxT("foobar"),    wxT("*foo"),   false );
-    TEST_MATCH( wxT("foobarfoo"), wxT("*foo"),   true  );
-    TEST_MATCH( wxT(""),          wxT("*"),      true  );
-    TEST_MATCH( wxT(""),          wxT("?"),      false );
+    TEST_MATCH( "foobar",       "foo*",        true  );
+    TEST_MATCH( "foobar",       "*oo*",        true  );
+    TEST_MATCH( "foobar",       "*bar",        true  );
+    TEST_MATCH( "foobar",       "??????",      true  );
+    TEST_MATCH( "foobar",       "f??b*",       true  );
+    TEST_MATCH( "foobar",       "f?b*",        false );
+    TEST_MATCH( "foobar",       "*goo*",       false );
+    TEST_MATCH( "foobar",       "*foo",        false );
+    TEST_MATCH( "foobarfoo",    "*foo",        true  );
+    TEST_MATCH( "",             "*",           true  );
+    TEST_MATCH( "",             "?",           false );
 
     #undef TEST_MATCH
 }
@@ -583,6 +598,7 @@ static const struct ToLongData
     long value;
 #endif // wxLongLong_t
     int flags;
+    int base;
 
     long LValue() const { return value; }
     unsigned long ULValue() const { return value; }
@@ -613,6 +629,22 @@ static const struct ToLongData
     { wxT("9223372036854775808"), wxULL(9223372036854775808), Number_LongLong |
                                                              Number_Unsigned },
 #endif // wxLongLong_t
+
+    // Base tests.
+    { wxT("010"),  10, Number_Ok, 10 },
+    { wxT("010"),   8, Number_Ok,  0 },
+    { wxT("010"),   8, Number_Ok,  8 },
+    { wxT("010"),  16, Number_Ok, 16 },
+
+    { wxT("0010"), 10, Number_Ok, 10 },
+    { wxT("0010"),  8, Number_Ok,  0 },
+    { wxT("0010"),  8, Number_Ok,  8 },
+    { wxT("0010"), 16, Number_Ok, 16 },
+
+    { wxT("0x11"),  0, Number_Invalid, 10 },
+    { wxT("0x11"), 17, Number_Ok,       0 },
+    { wxT("0x11"),  0, Number_Invalid,  8 },
+    { wxT("0x11"), 17, Number_Ok,      16 },
 };
 
 void StringTestCase::ToLong()
@@ -628,11 +660,13 @@ void StringTestCase::ToLong()
         // NOTE: unless you're using some exotic locale, ToCLong and ToLong
         //       should behave the same for our test data set:
 
-        CPPUNIT_ASSERT_EQUAL( ld.IsOk(), wxString(ld.str).ToCLong(&l) );
+        CPPUNIT_ASSERT_EQUAL( ld.IsOk(),
+                              wxString(ld.str).ToCLong(&l, ld.base) );
         if ( ld.IsOk() )
             CPPUNIT_ASSERT_EQUAL( ld.LValue(), l );
 
-        CPPUNIT_ASSERT_EQUAL( ld.IsOk(), wxString(ld.str).ToLong(&l) );
+        CPPUNIT_ASSERT_EQUAL( ld.IsOk(),
+                              wxString(ld.str).ToLong(&l, ld.base) );
         if ( ld.IsOk() )
             CPPUNIT_ASSERT_EQUAL( ld.LValue(), l );
     }
@@ -662,11 +696,13 @@ void StringTestCase::ToULong()
         // NOTE: unless you're using some exotic locale, ToCLong and ToLong
         //       should behave the same for our test data set:
 
-        CPPUNIT_ASSERT_EQUAL( ld.IsOk(), wxString(ld.str).ToCULong(&ul) );
+        CPPUNIT_ASSERT_EQUAL( ld.IsOk(),
+                              wxString(ld.str).ToCULong(&ul, ld.base) );
         if ( ld.IsOk() )
             CPPUNIT_ASSERT_EQUAL( ld.ULValue(), ul );
 
-        CPPUNIT_ASSERT_EQUAL( ld.IsOk(), wxString(ld.str).ToULong(&ul) );
+        CPPUNIT_ASSERT_EQUAL( ld.IsOk(),
+                              wxString(ld.str).ToULong(&ul, ld.base) );
         if ( ld.IsOk() )
             CPPUNIT_ASSERT_EQUAL( ld.ULValue(), ul );
     }
@@ -684,7 +720,8 @@ void StringTestCase::ToLongLong()
         if ( ld.flags & (Number_Long | Number_Unsigned) )
             continue;
 
-        CPPUNIT_ASSERT_EQUAL( ld.IsOk(), wxString(ld.str).ToLongLong(&l) );
+        CPPUNIT_ASSERT_EQUAL( ld.IsOk(),
+                              wxString(ld.str).ToLongLong(&l, ld.base) );
         if ( ld.IsOk() )
             CPPUNIT_ASSERT_EQUAL( ld.LLValue(), l );
     }
@@ -700,7 +737,8 @@ void StringTestCase::ToULongLong()
         if ( ld.flags & (Number_Long | Number_Signed) )
             continue;
 
-        CPPUNIT_ASSERT_EQUAL( ld.IsOk(), wxString(ld.str).ToULongLong(&ul) );
+        CPPUNIT_ASSERT_EQUAL( ld.IsOk(),
+                              wxString(ld.str).ToULongLong(&ul, ld.base) );
         if ( ld.IsOk() )
             CPPUNIT_ASSERT_EQUAL( ld.ULLValue(), ul );
     }