From: Vadim Zeitlin Date: Mon, 31 Jan 2005 00:31:47 +0000 (+0000) Subject: added small UTF 8 conversion test case X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/ec54fe9e186fd7d8f49180690ddf064201438893 added small UTF 8 conversion test case git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@31665 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/tests/strings/strings.cpp b/tests/strings/strings.cpp index 858bcab7d4..bc1c4c00bb 100644 --- a/tests/strings/strings.cpp +++ b/tests/strings/strings.cpp @@ -42,7 +42,8 @@ private: CPPUNIT_TEST( ConstructorsWithConversion ); CPPUNIT_TEST( Conversion ); CPPUNIT_TEST( ConversionUTF7 ); -#endif + CPPUNIT_TEST( ConversionUTF8 ); +#endif // wxUSE_WCHAR_T CPPUNIT_TEST( Extraction ); CPPUNIT_TEST( Find ); CPPUNIT_TEST( Tokenizer ); @@ -62,7 +63,8 @@ private: void ConstructorsWithConversion(); void Conversion(); void ConversionUTF7(); -#endif + void ConversionUTF8(); +#endif // wxUSE_WCHAR_T void Extraction(); void Find(); void SingleTokenizerTest( wxChar *str, wxChar *delims, size_t count , wxStringTokenizerMode mode ); @@ -248,6 +250,24 @@ void StringTestCase::ConversionUTF7() #endif // wxUSE_UNICODE } +void StringTestCase::ConversionUTF8() +{ + const wchar_t wcs[] = { 0x00A3, 0x00A3, 0x00A3, 0x00A3, 0 }; // pound signs + const char *utf8 = "\xc2\xa3\xc2\xa3\xc2\xa3\xc2\xa3"; + + wxCSConv conv(_T("utf-8")); + +#if wxUSE_UNICODE + wxCharBuffer buf(wxString(wcs).mb_str(conv)); + + CPPUNIT_ASSERT( strcmp(buf, utf8) == 0 ); +#else // !wxUSE_UNICODE + wxWCharBuffer wbuf(wxString(utf8).wc_str(conv)); + + CPPUNIT_ASSERT( wcscmp(wbuf, wcs) == 0 ); +#endif // wxUSE_UNICODE/!wxUSE_UNICODE +} + #endif // wxUSE_WCHAR_T