CPPUNIT_TEST( Latin1Tests );
CPPUNIT_TEST( FontmapTests );
CPPUNIT_TEST( BufSize );
+ CPPUNIT_TEST( FromWCharTests );
#ifdef HAVE_WCHAR_H
CPPUNIT_TEST( UTF8_41 );
CPPUNIT_TEST( UTF8_7f );
void LibcTests();
void FontmapTests();
void BufSize();
+ void FromWCharTests();
void IconvTests();
void Latin1Tests();
// register in the unnamed registry so that these tests are run by default
CPPUNIT_TEST_SUITE_REGISTRATION( MBConvTestCase );
-// also include in it's own registry so that these tests can be run alone
+// also include in its own registry so that these tests can be run alone
CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( MBConvTestCase, "MBConvTestCase" );
CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( MBConvTestCase, "MBConv" );
// so we should store the wide character version as UTF-8 and depend on
// the UTF-8 converter's ability to decode it to platform specific wide characters
// this test is invalid if the UTF-8 converter can't decode
- wxWCharBuffer wideBuffer((size_t)0);
- wideBuffer = DecodeUTF8( utf8Buffer, utf8Bytes );
- size_t wideChars = wxWcslen( wideBuffer.data() );
+ const wxWCharBuffer wideBuffer(DecodeUTF8(utf8Buffer, utf8Bytes));
+ const size_t wideChars = wxWcslen(wideBuffer);
TestDecoder
(
wideBuffer.data(),
wideChars,
- (const char*)multiBuffer,
+ multiBuffer,
multiBytes,
converter,
sizeofNull
(
wideBuffer.data(),
wideChars,
- (const char*)multiBuffer,
+ multiBuffer,
multiBytes,
converter,
sizeofNull
CPPUNIT_ASSERT_EQUAL( '?', buf[lenMB + 2] );
}
+void MBConvTestCase::FromWCharTests()
+{
+ wxCSConv conv950("CP950");
+ char mbuf[10];
+ // U+4e00 is 2 bytes (0xa4 0x40) in cp950
+ wchar_t wbuf[] = { 0x4e00, 0, 0x4e00, 0 };
+
+ // test simple ASCII text
+ memset(mbuf, '!', sizeof(mbuf));
+ CPPUNIT_ASSERT_EQUAL( wxCONV_FAILED, conv950.FromWChar(mbuf, 0, L"a", 1));
+ CPPUNIT_ASSERT_EQUAL( '!', mbuf[0]);
+
+ memset(mbuf, '!', sizeof(mbuf));
+ CPPUNIT_ASSERT_EQUAL( 1, conv950.FromWChar(mbuf, 1, L"a", 1));
+ CPPUNIT_ASSERT_EQUAL( 'a', mbuf[0]);
+ CPPUNIT_ASSERT_EQUAL( '!', mbuf[1]);
+
+ memset(mbuf, '!', sizeof(mbuf));
+ CPPUNIT_ASSERT_EQUAL( wxCONV_FAILED, conv950.FromWChar(mbuf, 1, L"a", 2));
+
+ memset(mbuf, '!', sizeof(mbuf));
+ CPPUNIT_ASSERT_EQUAL( 2, conv950.FromWChar(mbuf, 2, L"a", 2));
+ CPPUNIT_ASSERT_EQUAL( 'a', mbuf[0]);
+ CPPUNIT_ASSERT_EQUAL( '\0', mbuf[1]);
+ CPPUNIT_ASSERT_EQUAL( '!', mbuf[2]);
+
+ // test non-ASCII text, 1 wchar -> 2 char
+ memset(mbuf, '!', sizeof(mbuf));
+ CPPUNIT_ASSERT_EQUAL( wxCONV_FAILED, conv950.FromWChar(mbuf, 0, wbuf, 1));
+
+ memset(mbuf, '!', sizeof(mbuf));
+ CPPUNIT_ASSERT_EQUAL( wxCONV_FAILED, conv950.FromWChar(mbuf, 1, wbuf, 1));
+
+ memset(mbuf, '!', sizeof(mbuf));
+ CPPUNIT_ASSERT_EQUAL( 2, conv950.FromWChar(mbuf, 2, wbuf, 1));
+ CPPUNIT_ASSERT_EQUAL( '!', mbuf[2]);
+
+ memset(mbuf, '!', sizeof(mbuf));
+ CPPUNIT_ASSERT_EQUAL( wxCONV_FAILED, conv950.FromWChar(mbuf, 2, wbuf, 2));
+
+ memset(mbuf, '!', sizeof(mbuf));
+ CPPUNIT_ASSERT_EQUAL( 3, conv950.FromWChar(mbuf, 3, wbuf, 2));
+ CPPUNIT_ASSERT_EQUAL( '\0', mbuf[2]);
+ CPPUNIT_ASSERT_EQUAL( '!', mbuf[3]);
+
+ // test text with embedded NUL-character and srcLen specified
+ memset(mbuf, '!', sizeof(mbuf));
+ CPPUNIT_ASSERT_EQUAL( wxCONV_FAILED, conv950.FromWChar(mbuf, 3, wbuf, 3));
+
+ memset(mbuf, '!', sizeof(mbuf));
+ CPPUNIT_ASSERT_EQUAL( wxCONV_FAILED, conv950.FromWChar(mbuf, 4, wbuf, 3));
+ CPPUNIT_ASSERT_EQUAL( 5, conv950.FromWChar(mbuf, 5, wbuf, 3));
+ CPPUNIT_ASSERT_EQUAL( '\0', mbuf[2]);
+ CPPUNIT_ASSERT_EQUAL( '!', mbuf[5]);
+
+ memset(mbuf, '!', sizeof(mbuf));
+ CPPUNIT_ASSERT_EQUAL( wxCONV_FAILED, conv950.FromWChar(mbuf, 5, wbuf, 4));
+
+ memset(mbuf, '!', sizeof(mbuf));
+ CPPUNIT_ASSERT_EQUAL( 6, conv950.FromWChar(mbuf, 6, wbuf, 4));
+ CPPUNIT_ASSERT_EQUAL( '\0', mbuf[2]);
+ CPPUNIT_ASSERT_EQUAL( '\0', mbuf[5]);
+ CPPUNIT_ASSERT_EQUAL( '!', mbuf[6]);
+}
WXDLLIMPEXP_BASE wxMBConv* new_wxMBConv_iconv( const char* name );
void MBConvTestCase::LibcTests()
{
- // There isn't a locale that all systems support (except "C"), so leave
- // this one disabled for non-Windows systems for the moment, until
- // a solution can be found.
-#ifdef __WXMSW__
-
-#ifdef __WXMSW__
- setlocale( LC_ALL, "English_United States.1252" );
- const unsigned char* systemMB = CP1252;
- size_t systemMB_size = sizeof(CP1252);
- const unsigned char* systemMB_utf8 = CP1252_utf8;
- size_t systemMB_utf8_size = sizeof(CP1252_utf8);
-#else
- setlocale( LC_ALL, "en_US.iso8859-1" );
- const unsigned char* systemMB = iso8859_1;
- size_t systemMB_size = sizeof(iso8859_1);
- const unsigned char* systemMB_utf8 = iso8859_1_utf8;
- size_t systemMB_utf8_size = sizeof(iso8859_1_utf8);
-#endif
+ // The locale name are OS-dependent so this test is done only under Windows
+ // when using MSVC (surprisingly it fails with MinGW, even though it's
+ // supposed to use the same CRT -- no idea why and unfortunately gdb is too
+ // flaky to debug it)
+#ifdef __VISUALC__
+ LocaleSetter loc("English_United States.1252");
+
wxMBConvLibc convLibc;
TestCoder(
- (const char*)systemMB,
- systemMB_size,
- (const char*)systemMB_utf8,
- systemMB_utf8_size,
+ (const char*)CP1252,
+ sizeof(CP1252),
+ (const char*)CP1252_utf8,
+ sizeof(CP1252_utf8),
convLibc,
1
);
-
-#endif // __WXMSW__
+#endif // __VISUALC__
}
// verifies that the specified mb sequences decode to the specified wc sequence
0
);
// make sure the correct output length was calculated
- CPPUNIT_ASSERT_EQUAL( wideChars, outputWritten );
+ WX_ASSERT_EQUAL_MESSAGE
+ (
+ ("while converting \"%s\"", multiBuffer),
+ wideChars,
+ outputWritten
+ );
// convert the string
size_t guardChars = 8; // to make sure we're not overrunning the output buffer