X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/bd42a07c7a528c607e7327dcd194b739fb242da2..3942aa77f5f737e668137a09ee197c7099c45a9e:/tests/strings/strings.cpp diff --git a/tests/strings/strings.cpp b/tests/strings/strings.cpp index 879fab7907..a0485c9007 100644 --- a/tests/strings/strings.cpp +++ b/tests/strings/strings.cpp @@ -35,6 +35,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 +69,7 @@ private: void String(); void PChar(); void Format(); + void FormatUnicode(); void Constructors(); void StaticConstructors(); void Extraction(); @@ -174,6 +176,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) ); @@ -192,6 +208,18 @@ void StringTestCase::Constructors() CPPUNIT_ASSERT_EQUAL( 0, wxString(wxString(), 17).length() ); +#if wxUSE_UNICODE_UTF8 + // This string has 3 characters (, and ), not 4 when using UTF-8 + // locale! + if ( wxConvLibc.IsUTF8() ) + { + wxString s3("h\xc3\xa9llo", 4); + CPPUNIT_ASSERT_EQUAL( 3, s3.length() ); + CPPUNIT_ASSERT_EQUAL( 'l', (char)s3[2] ); + } +#endif // wxUSE_UNICODE_UTF8 + + static const char *s = "?really!"; const char *start = wxStrchr(s, 'r'); const char *end = wxStrchr(s, '!'); @@ -219,6 +247,9 @@ void StringTestCase::StaticConstructors() CPPUNIT_ASSERT_EQUAL( "Hello", wxString::FromUTF8("Hello", 5) ); CPPUNIT_ASSERT_EQUAL( "Hello", wxString::FromUTF8("Hello") ); + CPPUNIT_ASSERT_EQUAL( 2, wxString::FromUTF8("h\xc3\xa9llo", 3).length() ); + + //CPPUNIT_ASSERT_EQUAL( 1, wxString::FromUTF8("", 1).length() ); } @@ -568,6 +599,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; } @@ -598,6 +630,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() @@ -613,11 +661,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 ); } @@ -647,11 +697,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 ); } @@ -669,7 +721,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 ); } @@ -685,7 +738,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 ); }