1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: tests/mbconv/main.cpp
3 // Purpose: wxMBConv unit test
4 // Author: Vadim Zeitlin, Mike Wetherell, Vince Harron
7 // Copyright: (c) 2003 TT-Solutions, (c) 2005 Mike Wetherell, Vince Harron
8 ///////////////////////////////////////////////////////////////////////////////
10 // ----------------------------------------------------------------------------
12 // ----------------------------------------------------------------------------
24 #include "wx/strconv.h"
25 #include "wx/string.h"
26 #include "wx/txtstrm.h"
27 #include "wx/mstream.h"
29 #if defined wxHAVE_TCHAR_SUPPORT && !defined HAVE_WCHAR_H
33 // ----------------------------------------------------------------------------
34 // Some wide character constants. "\uXXXX" escapes aren't supported by old
35 // compilers such as VC++ 5 and g++ 2.95.
36 // ----------------------------------------------------------------------------
38 wchar_t u41
[] = { 0x41, 0 };
39 wchar_t u7f
[] = { 0x7f, 0 };
41 wchar_t u80
[] = { 0x80, 0 };
42 wchar_t u391
[] = { 0x391, 0 };
43 wchar_t u7ff
[] = { 0x7ff, 0 };
45 wchar_t u800
[] = { 0x800, 0 };
46 wchar_t u2620
[] = { 0x2620, 0 };
47 wchar_t ufffd
[] = { 0xfffd, 0 };
49 #if SIZEOF_WCHAR_T == 4
50 wchar_t u10000
[] = { 0x10000, 0 };
51 wchar_t u1000a5
[] = { 0x1000a5, 0 };
52 wchar_t u10fffd
[] = { 0x10fffd, 0 };
54 wchar_t u10000
[] = { 0xd800, 0xdc00, 0 };
55 wchar_t u1000a5
[] = { 0xdbc0, 0xdca5, 0 };
56 wchar_t u10fffd
[] = { 0xdbff, 0xdffd, 0 };
59 // ----------------------------------------------------------------------------
61 // ----------------------------------------------------------------------------
63 class MBConvTestCase
: public CppUnit::TestCase
69 CPPUNIT_TEST_SUITE( MBConvTestCase
);
70 CPPUNIT_TEST( UTF32LETests
);
71 CPPUNIT_TEST( UTF32BETests
);
72 CPPUNIT_TEST( WC2CP1250
);
73 CPPUNIT_TEST( UTF7Tests
);
74 CPPUNIT_TEST( UTF8Tests
);
75 CPPUNIT_TEST( UTF16LETests
);
76 CPPUNIT_TEST( UTF16BETests
);
77 CPPUNIT_TEST( CP932Tests
);
78 CPPUNIT_TEST( CP1252Tests
); // depends on UTF8 Decoder functioning correctly
79 CPPUNIT_TEST( LibcTests
);
80 CPPUNIT_TEST( IconvTests
);
81 CPPUNIT_TEST( FontmapTests
);
83 CPPUNIT_TEST( UTF8_41
);
84 CPPUNIT_TEST( UTF8_7f
);
85 CPPUNIT_TEST( UTF8_80
);
86 CPPUNIT_TEST( UTF8_c2_7f
);
87 CPPUNIT_TEST( UTF8_c2_80
);
88 CPPUNIT_TEST( UTF8_ce_91
);
89 CPPUNIT_TEST( UTF8_df_bf
);
90 CPPUNIT_TEST( UTF8_df_c0
);
91 CPPUNIT_TEST( UTF8_e0_a0_7f
);
92 CPPUNIT_TEST( UTF8_e0_a0_80
);
93 CPPUNIT_TEST( UTF8_e2_98_a0
);
94 CPPUNIT_TEST( UTF8_ef_bf_bd
);
95 CPPUNIT_TEST( UTF8_ef_bf_c0
);
96 CPPUNIT_TEST( UTF8_f0_90_80_7f
);
97 CPPUNIT_TEST( UTF8_f0_90_80_80
);
98 CPPUNIT_TEST( UTF8_f4_8f_bf_bd
);
99 CPPUNIT_TEST( UTF8PUA_f4_80_82_a5
);
100 CPPUNIT_TEST( UTF8Octal_backslash245
);
101 #endif // HAVE_WCHAR_H
102 CPPUNIT_TEST_SUITE_END();
117 // verifies that the specified multibyte sequence decodes to the specified wchar_t sequence
119 const wchar_t* wideBuffer
, // the same character sequence as multiBuffer, encoded as wchar_t
120 size_t wideChars
, // the number of wide characters at wideBuffer
121 const char* multiBuffer
, // a multibyte encoded character sequence that can be decoded by "converter"
122 size_t multiBytes
, // the byte length of the multibyte character sequence that can be decoded by "converter"
123 wxMBConv
* converter
, // the wxMBConv object that can decode multiBuffer into a wide character sequence
124 int sizeofNull
// number of bytes occupied by terminating null in this encoding
127 // verifies that the specified wchar_t sequence encodes to the specified multibyte sequence
129 const wchar_t* wideBuffer
, // the same character sequence as multiBuffer, encoded as wchar_t
130 size_t wideChars
, // the number of wide characters at wideBuffer
131 const char* multiBuffer
, // a multibyte encoded character sequence that can be decoded by "converter"
132 size_t multiBytes
, // the byte length of the multibyte character sequence that can be decoded by "converter"
133 wxMBConv
* converter
, // the wxMBConv object that can decode multiBuffer into a wide character sequence
134 int sizeofNull
// number of bytes occupied by terminating null in this encoding
137 #if wxUSE_UNICODE && wxUSE_STREAMS
138 // use wxTextInputStream to exercise wxMBConv interface
139 // (this reveals some bugs in certain wxMBConv subclasses)
140 void TestStreamDecoder(
141 const wchar_t* wideBuffer
, // the same character sequence as multiBuffer, encoded as wchar_t
142 size_t wideChars
, // the number of wide characters at wideBuffer
143 const char* multiBuffer
, // a multibyte encoded character sequence that can be decoded by "converter"
144 size_t multiBytes
, // the byte length of the multibyte character sequence that can be decoded by "converter"
145 wxMBConv
* converter
// the wxMBConv object that can decode multiBuffer into a wide character sequence
148 // use wxTextOutputStream to exercise wxMBConv interface
149 // (this reveals some bugs in certain wxMBConv subclasses)
150 void TestStreamEncoder(
151 const wchar_t* wideBuffer
, // the same character sequence as multiBuffer, encoded as wchar_t
152 size_t wideChars
, // the number of wide characters at wideBuffer
153 const char* multiBuffer
, // a multibyte encoded character sequence that can be decoded by "converter"
154 size_t multiBytes
, // the byte length of the multibyte character sequence that can be decoded by "converter"
155 wxMBConv
* converter
// the wxMBConv object that can decode multiBuffer into a wide character sequence
159 // tests the encoding and decoding capability of an wxMBConv object
161 // decodes the utf-8 bytes into wide characters
162 // encodes the wide characters to compare against input multiBuffer
163 // decodes the multiBuffer to compare against wide characters
164 // decodes the multiBuffer into wide characters
166 const char* multiBuffer
, // a multibyte encoded character sequence that can be decoded by "converter"
167 size_t multiBytes
, // the byte length of the multibyte character sequence that can be decoded by "converter"
168 const char* utf8Buffer
, // the same character sequence as multiBuffer, encoded as UTF-8
169 size_t utf8Bytes
, // the byte length of the UTF-8 encoded character sequence
170 wxMBConv
* converter
, // the wxMBConv object that can decode multiBuffer into a wide character sequence
171 int sizeofNull
// the number of bytes occupied by a terminating null in the converter's encoding
175 // UTF-8 tests. Test the first, last and one in the middle for sequences
177 void UTF8_41() { UTF8("\x41", u41
); }
178 void UTF8_7f() { UTF8("\x7f", u7f
); }
179 void UTF8_80() { UTF8("\x80", NULL
); }
181 void UTF8_c2_7f() { UTF8("\xc2\x7f", NULL
); }
182 void UTF8_c2_80() { UTF8("\xc2\x80", u80
); }
183 void UTF8_ce_91() { UTF8("\xce\x91", u391
); }
184 void UTF8_df_bf() { UTF8("\xdf\xbf", u7ff
); }
185 void UTF8_df_c0() { UTF8("\xdf\xc0", NULL
); }
187 void UTF8_e0_a0_7f() { UTF8("\xe0\xa0\x7f", NULL
); }
188 void UTF8_e0_a0_80() { UTF8("\xe0\xa0\x80", u800
); }
189 void UTF8_e2_98_a0() { UTF8("\xe2\x98\xa0", u2620
); }
190 void UTF8_ef_bf_bd() { UTF8("\xef\xbf\xbd", ufffd
); }
191 void UTF8_ef_bf_c0() { UTF8("\xef\xbf\xc0", NULL
); }
193 void UTF8_f0_90_80_7f() { UTF8("\xf0\x90\x80\x7f", NULL
); }
194 void UTF8_f0_90_80_80() { UTF8("\xf0\x90\x80\x80", u10000
); }
195 void UTF8_f4_8f_bf_bd() { UTF8("\xf4\x8f\xbf\xbd", u10fffd
); }
197 // test 'escaping the escape characters' for the two escaping schemes
198 void UTF8PUA_f4_80_82_a5() { UTF8PUA("\xf4\x80\x82\xa5", u1000a5
); }
199 void UTF8Octal_backslash245() { UTF8Octal("\\245", L
"\\245"); }
201 // implementation for the utf-8 tests (see comments below)
202 void UTF8(const char *charSequence
, const wchar_t *wideSequence
);
203 void UTF8PUA(const char *charSequence
, const wchar_t *wideSequence
);
204 void UTF8Octal(const char *charSequence
, const wchar_t *wideSequence
);
205 void UTF8(const char *charSequence
, const wchar_t *wideSequence
, int option
);
206 #endif // HAVE_WCHAR_H
208 DECLARE_NO_COPY_CLASS(MBConvTestCase
)
211 // register in the unnamed registry so that these tests are run by default
212 CPPUNIT_TEST_SUITE_REGISTRATION( MBConvTestCase
);
214 // also include in it's own registry so that these tests can be run alone
215 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( MBConvTestCase
, "MBConv" );
217 void MBConvTestCase::WC2CP1250()
219 static const struct Data
225 { L
"hello", "hello" }, // test that it works in simplest case
226 { L
"\xBD of \xBD is \xBC", NULL
}, // this should fail as cp1250 doesn't have 1/2
229 wxCSConv
cs1250(wxFONTENCODING_CP1250
);
230 for ( size_t n
= 0; n
< WXSIZEOF(data
); n
++ )
232 const Data
& d
= data
[n
];
235 CPPUNIT_ASSERT( strcmp(cs1250
.cWC2MB(d
.wc
), d
.cp1250
) == 0 );
239 CPPUNIT_ASSERT( (const char*)cs1250
.cWC2MB(d
.wc
) == NULL
);
244 // Print an unsigned character array as a C unsigned character array.
245 // NB: Please don't remove this function even though it's not used anywhere,
246 // it's very useful when debugging a failed test.
247 wxString
CByteArrayFormat( const void* data
, size_t len
, const wxChar
* name
)
249 const unsigned char* bytes
= (unsigned char*)data
;
252 result
.Printf( _T("const static unsigned char %s[%i] = \n{"), name
, (int)len
);
254 for ( size_t i
= 0; i
< len
; i
++ )
258 result
.append( _T(",") );
262 result
.append( _T("\n ") );
264 wxString byte
= wxString::Format( _T("0x%02x"), bytes
[i
] );
267 result
.append( _T("\n};\n") );
271 // The following bytes represent the same string, containing Japanese and English
272 // characters, encoded in several different formats.
275 const static unsigned char welcome_utf7_iconv
[84] =
277 0x57,0x65,0x6c,0x63,0x6f,0x6d,0x65,0x20,0x74,0x6f,0x20,0x6f,0x75,0x72,0x20,0x63,
278 0x79,0x62,0x65,0x72,0x20,0x73,0x70,0x61,0x63,0x65,0x20,0x66,0x6f,0x72,0x63,0x65,
279 0x2e,0x20,0x20,0x2b,0x4d,0x46,0x6b,0x77,0x55,0x49,0x74,0x6d,0x57,0x39,0x38,0x77,
280 0x61,0x35,0x62,0x37,0x69,0x6e,0x45,0x77,0x6b,0x6a,0x42,0x5a,0x4d,0x49,0x73,0x77,
281 0x65,0x7a,0x42,0x47,0x4d,0x45,0x77,0x77,0x52,0x44,0x42,0x45,0x4d,0x47,0x63,0x77,
284 // encoded by wxWindows (iconv can decode this successfully)
285 const static unsigned char welcome_utf7_wx
[109] =
287 0x57,0x65,0x6c,0x63,0x6f,0x6d,0x65,0x2b,0x41,0x43,0x41,0x2d,0x74,0x6f,0x2b,0x41,
288 0x43,0x41,0x2d,0x6f,0x75,0x72,0x2b,0x41,0x43,0x41,0x2d,0x63,0x79,0x62,0x65,0x72,
289 0x2b,0x41,0x43,0x41,0x2d,0x73,0x70,0x61,0x63,0x65,0x2b,0x41,0x43,0x41,0x2d,0x66,
290 0x6f,0x72,0x63,0x65,0x2e,0x2b,0x41,0x43,0x41,0x41,0x49,0x44,0x42,0x5a,0x4d,0x46,
291 0x43,0x4c,0x5a,0x6c,0x76,0x66,0x4d,0x47,0x75,0x57,0x2b,0x34,0x70,0x78,0x4d,0x4a,
292 0x49,0x77,0x57,0x54,0x43,0x4c,0x4d,0x48,0x73,0x77,0x52,0x6a,0x42,0x4d,0x4d,0x45,
293 0x51,0x77,0x52,0x44,0x42,0x6e,0x4d,0x46,0x6b,0x77,0x41,0x67,0x2d
296 const static unsigned char welcome_utf8
[89] =
298 0x57,0x65,0x6c,0x63,0x6f,0x6d,0x65,0x20,0x74,0x6f,0x20,0x6f,0x75,0x72,0x20,0x63,
299 0x79,0x62,0x65,0x72,0x20,0x73,0x70,0x61,0x63,0x65,0x20,0x66,0x6f,0x72,0x63,0x65,
300 0x2e,0x20,0x20,0xe3,0x81,0x99,0xe3,0x81,0x90,0xe8,0xad,0xa6,0xe5,0xaf,0x9f,0xe3,
301 0x81,0xab,0xe9,0x9b,0xbb,0xe8,0xa9,0xb1,0xe3,0x82,0x92,0xe3,0x81,0x99,0xe3,0x82,
302 0x8b,0xe3,0x81,0xbb,0xe3,0x81,0x86,0xe3,0x81,0x8c,0xe3,0x81,0x84,0xe3,0x81,0x84,
303 0xe3,0x81,0xa7,0xe3,0x81,0x99,0xe3,0x80,0x82
306 const static unsigned char welcome_utf16le
[106] =
308 0x57,0x00,0x65,0x00,0x6c,0x00,0x63,0x00,0x6f,0x00,0x6d,0x00,0x65,0x00,0x20,0x00,
309 0x74,0x00,0x6f,0x00,0x20,0x00,0x6f,0x00,0x75,0x00,0x72,0x00,0x20,0x00,0x63,0x00,
310 0x79,0x00,0x62,0x00,0x65,0x00,0x72,0x00,0x20,0x00,0x73,0x00,0x70,0x00,0x61,0x00,
311 0x63,0x00,0x65,0x00,0x20,0x00,0x66,0x00,0x6f,0x00,0x72,0x00,0x63,0x00,0x65,0x00,
312 0x2e,0x00,0x20,0x00,0x20,0x00,0x59,0x30,0x50,0x30,0x66,0x8b,0xdf,0x5b,0x6b,0x30,
313 0xfb,0x96,0x71,0x8a,0x92,0x30,0x59,0x30,0x8b,0x30,0x7b,0x30,0x46,0x30,0x4c,0x30,
314 0x44,0x30,0x44,0x30,0x67,0x30,0x59,0x30,0x02,0x30
317 const static unsigned char welcome_utf16be
[106] =
319 0x00,0x57,0x00,0x65,0x00,0x6c,0x00,0x63,0x00,0x6f,0x00,0x6d,0x00,0x65,0x00,0x20,
320 0x00,0x74,0x00,0x6f,0x00,0x20,0x00,0x6f,0x00,0x75,0x00,0x72,0x00,0x20,0x00,0x63,
321 0x00,0x79,0x00,0x62,0x00,0x65,0x00,0x72,0x00,0x20,0x00,0x73,0x00,0x70,0x00,0x61,
322 0x00,0x63,0x00,0x65,0x00,0x20,0x00,0x66,0x00,0x6f,0x00,0x72,0x00,0x63,0x00,0x65,
323 0x00,0x2e,0x00,0x20,0x00,0x20,0x30,0x59,0x30,0x50,0x8b,0x66,0x5b,0xdf,0x30,0x6b,
324 0x96,0xfb,0x8a,0x71,0x30,0x92,0x30,0x59,0x30,0x8b,0x30,0x7b,0x30,0x46,0x30,0x4c,
325 0x30,0x44,0x30,0x44,0x30,0x67,0x30,0x59,0x30,0x02
328 const static unsigned char welcome_utf32le
[212] =
330 0x57,0x00,0x00,0x00,0x65,0x00,0x00,0x00,0x6c,0x00,0x00,0x00,0x63,0x00,0x00,0x00,
331 0x6f,0x00,0x00,0x00,0x6d,0x00,0x00,0x00,0x65,0x00,0x00,0x00,0x20,0x00,0x00,0x00,
332 0x74,0x00,0x00,0x00,0x6f,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x6f,0x00,0x00,0x00,
333 0x75,0x00,0x00,0x00,0x72,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x63,0x00,0x00,0x00,
334 0x79,0x00,0x00,0x00,0x62,0x00,0x00,0x00,0x65,0x00,0x00,0x00,0x72,0x00,0x00,0x00,
335 0x20,0x00,0x00,0x00,0x73,0x00,0x00,0x00,0x70,0x00,0x00,0x00,0x61,0x00,0x00,0x00,
336 0x63,0x00,0x00,0x00,0x65,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x66,0x00,0x00,0x00,
337 0x6f,0x00,0x00,0x00,0x72,0x00,0x00,0x00,0x63,0x00,0x00,0x00,0x65,0x00,0x00,0x00,
338 0x2e,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x59,0x30,0x00,0x00,
339 0x50,0x30,0x00,0x00,0x66,0x8b,0x00,0x00,0xdf,0x5b,0x00,0x00,0x6b,0x30,0x00,0x00,
340 0xfb,0x96,0x00,0x00,0x71,0x8a,0x00,0x00,0x92,0x30,0x00,0x00,0x59,0x30,0x00,0x00,
341 0x8b,0x30,0x00,0x00,0x7b,0x30,0x00,0x00,0x46,0x30,0x00,0x00,0x4c,0x30,0x00,0x00,
342 0x44,0x30,0x00,0x00,0x44,0x30,0x00,0x00,0x67,0x30,0x00,0x00,0x59,0x30,0x00,0x00,
346 const static unsigned char welcome_utf32be
[212] =
348 0x00,0x00,0x00,0x57,0x00,0x00,0x00,0x65,0x00,0x00,0x00,0x6c,0x00,0x00,0x00,0x63,
349 0x00,0x00,0x00,0x6f,0x00,0x00,0x00,0x6d,0x00,0x00,0x00,0x65,0x00,0x00,0x00,0x20,
350 0x00,0x00,0x00,0x74,0x00,0x00,0x00,0x6f,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x6f,
351 0x00,0x00,0x00,0x75,0x00,0x00,0x00,0x72,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x63,
352 0x00,0x00,0x00,0x79,0x00,0x00,0x00,0x62,0x00,0x00,0x00,0x65,0x00,0x00,0x00,0x72,
353 0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x73,0x00,0x00,0x00,0x70,0x00,0x00,0x00,0x61,
354 0x00,0x00,0x00,0x63,0x00,0x00,0x00,0x65,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x66,
355 0x00,0x00,0x00,0x6f,0x00,0x00,0x00,0x72,0x00,0x00,0x00,0x63,0x00,0x00,0x00,0x65,
356 0x00,0x00,0x00,0x2e,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x20,0x00,0x00,0x30,0x59,
357 0x00,0x00,0x30,0x50,0x00,0x00,0x8b,0x66,0x00,0x00,0x5b,0xdf,0x00,0x00,0x30,0x6b,
358 0x00,0x00,0x96,0xfb,0x00,0x00,0x8a,0x71,0x00,0x00,0x30,0x92,0x00,0x00,0x30,0x59,
359 0x00,0x00,0x30,0x8b,0x00,0x00,0x30,0x7b,0x00,0x00,0x30,0x46,0x00,0x00,0x30,0x4c,
360 0x00,0x00,0x30,0x44,0x00,0x00,0x30,0x44,0x00,0x00,0x30,0x67,0x00,0x00,0x30,0x59,
364 const static unsigned char welcome_cp932
[71] =
366 0x57,0x65,0x6c,0x63,0x6f,0x6d,0x65,0x20,0x74,0x6f,0x20,0x6f,0x75,0x72,0x20,0x63,
367 0x79,0x62,0x65,0x72,0x20,0x73,0x70,0x61,0x63,0x65,0x20,0x66,0x6f,0x72,0x63,0x65,
368 0x2e,0x20,0x20,0x82,0xb7,0x82,0xae,0x8c,0x78,0x8e,0x40,0x82,0xc9,0x93,0x64,0x98,
369 0x62,0x82,0xf0,0x82,0xb7,0x82,0xe9,0x82,0xd9,0x82,0xa4,0x82,0xaa,0x82,0xa2,0x82,
370 0xa2,0x82,0xc5,0x82,0xb7,0x81,0x42
373 #if wxBYTE_ORDER == wxBIG_ENDIAN
374 #if SIZEOF_WCHAR_T == 2
375 #define welcome_wchar_t welcome_utf16be
376 #elif SIZEOF_WCHAR_T == 4
377 #define welcome_wchar_t welcome_utf32be
379 #elif wxBYTE_ORDER == wxLITTLE_ENDIAN
380 #if SIZEOF_WCHAR_T == 2
381 #define welcome_wchar_t welcome_utf16le
382 #elif SIZEOF_WCHAR_T == 4
383 #define welcome_wchar_t welcome_utf32le
387 void MBConvTestCase::UTF7Tests()
391 (const wchar_t*)welcome_wchar_t
,
392 sizeof(welcome_wchar_t
)/sizeof(wchar_t),
393 (const char*)welcome_utf7_iconv
,
394 sizeof(welcome_utf7_iconv
),
400 (const wchar_t*)welcome_wchar_t
,
401 sizeof(welcome_wchar_t
)/sizeof(wchar_t),
402 (const char*)welcome_utf7_wx
,
403 sizeof(welcome_utf7_wx
),
408 // wxWidget's UTF-7 encoder generates different byte sequences than iconv's.
409 // but both seem to be equally legal.
410 // This test won't work and that's okay.
413 (const wchar_t*)welcome_wchar_t
,
414 sizeof(welcome_wchar_t
)/sizeof(wchar_t),
415 (const char*)welcome_utf7_iconv
,
416 sizeof(welcome_utf7_iconv
),
423 (const wchar_t*)welcome_wchar_t
,
424 sizeof(welcome_wchar_t
)/sizeof(wchar_t),
425 (const char*)welcome_utf7_wx
,
426 sizeof(welcome_utf7_wx
),
432 void MBConvTestCase::UTF8Tests()
436 (const wchar_t*)welcome_wchar_t
,
437 sizeof(welcome_wchar_t
)/sizeof(wchar_t),
438 (const char*)welcome_utf8
,
439 sizeof(welcome_utf8
),
445 (const wchar_t*)welcome_wchar_t
,
446 sizeof(welcome_wchar_t
)/sizeof(wchar_t),
447 (const char*)welcome_utf8
,
448 sizeof(welcome_utf8
),
454 void MBConvTestCase::UTF16LETests()
456 wxMBConvUTF16LE convUTF16LE
;
459 (const wchar_t*)welcome_wchar_t
,
460 sizeof(welcome_wchar_t
)/sizeof(wchar_t),
461 (const char*)welcome_utf16le
,
462 sizeof(welcome_utf16le
),
468 (const wchar_t*)welcome_wchar_t
,
469 sizeof(welcome_wchar_t
)/sizeof(wchar_t),
470 (const char*)welcome_utf16le
,
471 sizeof(welcome_utf16le
),
477 void MBConvTestCase::UTF16BETests()
479 wxMBConvUTF16BE convUTF16BE
;
482 (const wchar_t*)welcome_wchar_t
,
483 sizeof(welcome_wchar_t
)/sizeof(wchar_t),
484 (const char*)welcome_utf16be
,
485 sizeof(welcome_utf16be
),
491 (const wchar_t*)welcome_wchar_t
,
492 sizeof(welcome_wchar_t
)/sizeof(wchar_t),
493 (const char*)welcome_utf16be
,
494 sizeof(welcome_utf16be
),
500 void MBConvTestCase::UTF32LETests()
502 wxMBConvUTF32LE convUTF32LE
;
505 (const wchar_t*)welcome_wchar_t
,
506 sizeof(welcome_wchar_t
)/sizeof(wchar_t),
507 (const char*)welcome_utf32le
,
508 sizeof(welcome_utf32le
),
514 (const wchar_t*)welcome_wchar_t
,
515 sizeof(welcome_wchar_t
)/sizeof(wchar_t),
516 (const char*)welcome_utf32le
,
517 sizeof(welcome_utf32le
),
523 void MBConvTestCase::UTF32BETests()
525 wxMBConvUTF32BE convUTF32BE
;
528 (const wchar_t*)welcome_wchar_t
,
529 sizeof(welcome_wchar_t
)/sizeof(wchar_t),
530 (const char*)welcome_utf32be
,
531 sizeof(welcome_utf32be
),
537 (const wchar_t*)welcome_wchar_t
,
538 sizeof(welcome_wchar_t
)/sizeof(wchar_t),
539 (const char*)welcome_utf32be
,
540 sizeof(welcome_utf32be
),
546 void MBConvTestCase::CP932Tests()
548 wxCSConv
convCP932( wxFONTENCODING_CP932
);
551 (const wchar_t*)welcome_wchar_t
,
552 sizeof(welcome_wchar_t
)/sizeof(wchar_t),
553 (const char*)welcome_cp932
,
554 sizeof(welcome_cp932
),
560 (const wchar_t*)welcome_wchar_t
,
561 sizeof(welcome_wchar_t
)/sizeof(wchar_t),
562 (const char*)welcome_cp932
,
563 sizeof(welcome_cp932
),
569 // a character sequence encoded as iso8859-1 (iconv)
570 static const unsigned char iso8859_1
[251] =
572 0x05,0x06,0x07,0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f,0x10,0x11,0x12,0x13,0x14,
573 0x15,0x16,0x17,0x18,0x19,0x1a,0x1b,0x1c,0x1d,0x1e,0x1f,0x20,0x21,0x22,0x23,0x24,
574 0x25,0x26,0x27,0x28,0x29,0x2a,0x2b,0x2c,0x2d,0x2e,0x2f,0x30,0x31,0x32,0x33,0x34,
575 0x35,0x36,0x37,0x38,0x39,0x3a,0x3b,0x3c,0x3d,0x3e,0x3f,0x40,0x41,0x42,0x43,0x44,
576 0x45,0x46,0x47,0x48,0x49,0x4a,0x4b,0x4c,0x4d,0x4e,0x4f,0x50,0x51,0x52,0x53,0x54,
577 0x55,0x56,0x57,0x58,0x59,0x5a,0x5b,0x5c,0x5d,0x5e,0x5f,0x60,0x61,0x62,0x63,0x64,
578 0x65,0x66,0x67,0x68,0x69,0x6a,0x6b,0x6c,0x6d,0x6e,0x6f,0x70,0x71,0x72,0x73,0x74,
579 0x75,0x76,0x77,0x78,0x79,0x7a,0x7b,0x7c,0x7d,0x7e,0x7f,0x80,0x81,0x82,0x83,0x84,
580 0x85,0x86,0x87,0x88,0x89,0x8a,0x8b,0x8c,0x8d,0x8e,0x8f,0x90,0x91,0x92,0x93,0x94,
581 0x95,0x96,0x97,0x98,0x99,0x9a,0x9b,0x9c,0x9d,0x9e,0x9f,0xa0,0xa1,0xa2,0xa3,0xa4,
582 0xa5,0xa6,0xa7,0xa8,0xa9,0xaa,0xab,0xac,0xad,0xae,0xaf,0xb0,0xb1,0xb2,0xb3,0xb4,
583 0xb5,0xb6,0xb7,0xb8,0xb9,0xba,0xbb,0xbc,0xbd,0xbe,0xbf,0xc0,0xc1,0xc2,0xc3,0xc4,
584 0xc5,0xc6,0xc7,0xc8,0xc9,0xca,0xcb,0xcc,0xcd,0xce,0xcf,0xd0,0xd1,0xd2,0xd3,0xd4,
585 0xd5,0xd6,0xd7,0xd8,0xd9,0xda,0xdb,0xdc,0xdd,0xde,0xdf,0xe0,0xe1,0xe2,0xe3,0xe4,
586 0xe5,0xe6,0xe7,0xe8,0xe9,0xea,0xeb,0xec,0xed,0xee,0xef,0xf0,0xf1,0xf2,0xf3,0xf4,
587 0xf5,0xf6,0xf7,0xf8,0xf9,0xfa,0xfb,0xfc,0xfd,0xfe,0xff
589 // the above character sequence encoded as UTF-8 (iconv)
590 static const unsigned char iso8859_1_utf8
[379] =
592 0x05,0x06,0x07,0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f,0x10,0x11,0x12,0x13,0x14,
593 0x15,0x16,0x17,0x18,0x19,0x1a,0x1b,0x1c,0x1d,0x1e,0x1f,0x20,0x21,0x22,0x23,0x24,
594 0x25,0x26,0x27,0x28,0x29,0x2a,0x2b,0x2c,0x2d,0x2e,0x2f,0x30,0x31,0x32,0x33,0x34,
595 0x35,0x36,0x37,0x38,0x39,0x3a,0x3b,0x3c,0x3d,0x3e,0x3f,0x40,0x41,0x42,0x43,0x44,
596 0x45,0x46,0x47,0x48,0x49,0x4a,0x4b,0x4c,0x4d,0x4e,0x4f,0x50,0x51,0x52,0x53,0x54,
597 0x55,0x56,0x57,0x58,0x59,0x5a,0x5b,0x5c,0x5d,0x5e,0x5f,0x60,0x61,0x62,0x63,0x64,
598 0x65,0x66,0x67,0x68,0x69,0x6a,0x6b,0x6c,0x6d,0x6e,0x6f,0x70,0x71,0x72,0x73,0x74,
599 0x75,0x76,0x77,0x78,0x79,0x7a,0x7b,0x7c,0x7d,0x7e,0x7f,0xc2,0x80,0xc2,0x81,0xc2,
600 0x82,0xc2,0x83,0xc2,0x84,0xc2,0x85,0xc2,0x86,0xc2,0x87,0xc2,0x88,0xc2,0x89,0xc2,
601 0x8a,0xc2,0x8b,0xc2,0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0xc3,0xb3,0xc3,0xb4,0xc3,0xb5,0xc3,0xb6,0xc3,0xb7,0xc3,0xb8,0xc3,0xb9,0xc3,
615 0xba,0xc3,0xbb,0xc3,0xbc,0xc3,0xbd,0xc3,0xbe,0xc3,0xbf
618 // a character sequence encoded as CP1252 (iconv)
619 static const unsigned char CP1252
[246] =
621 0x05,0x06,0x07,0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f,0x10,0x11,0x12,0x13,0x14,
622 0x15,0x16,0x17,0x18,0x19,0x1a,0x1b,0x1c,0x1d,0x1e,0x1f,0x20,0x21,0x22,0x23,0x24,
623 0x25,0x26,0x27,0x28,0x29,0x2a,0x2b,0x2c,0x2d,0x2e,0x2f,0x30,0x31,0x32,0x33,0x34,
624 0x35,0x36,0x37,0x38,0x39,0x3a,0x3b,0x3c,0x3d,0x3e,0x3f,0x40,0x41,0x42,0x43,0x44,
625 0x45,0x46,0x47,0x48,0x49,0x4a,0x4b,0x4c,0x4d,0x4e,0x4f,0x50,0x51,0x52,0x53,0x54,
626 0x55,0x56,0x57,0x58,0x59,0x5a,0x5b,0x5c,0x5d,0x5e,0x5f,0x60,0x61,0x62,0x63,0x64,
627 0x65,0x66,0x67,0x68,0x69,0x6a,0x6b,0x6c,0x6d,0x6e,0x6f,0x70,0x71,0x72,0x73,0x74,
628 0x75,0x76,0x77,0x78,0x79,0x7a,0x7b,0x7c,0x7d,0x7e,0x7f,0xa0,0xa1,0xa2,0xa3,0xa4,
629 0xa5,0xa6,0xa7,0xa8,0xa9,0xaa,0xab,0xac,0xad,0xae,0xaf,0xb0,0xb1,0xb2,0xb3,0xb4,
630 0xb5,0xb6,0xb7,0xb8,0xb9,0xba,0xbb,0xbc,0xbd,0xbe,0xbf,0xc0,0xc1,0xc2,0xc3,0xc4,
631 0xc5,0xc6,0xc7,0xc8,0xc9,0xca,0xcb,0xcc,0xcd,0xce,0xcf,0xd0,0xd1,0xd2,0xd3,0xd4,
632 0xd5,0xd6,0xd7,0xd8,0xd9,0xda,0xdb,0xdc,0xdd,0xde,0xdf,0xe0,0xe1,0xe2,0xe3,0xe4,
633 0xe5,0xe6,0xe7,0xe8,0xe9,0xea,0xeb,0xec,0xed,0xee,0xef,0xf0,0xf1,0xf2,0xf3,0xf4,
634 0xf5,0xf6,0xf7,0xf8,0xf9,0xfa,0xfb,0xfc,0xfd,0xfe,0xff,0x8c,0x9c,0x8a,0x9a,0x9f,
635 0x8e,0x9e,0x83,0x88,0x98,0x96,0x97,0x91,0x92,0x82,0x93,0x94,0x84,0x86,0x87,0x95,
636 0x85,0x89,0x8b,0x9b,0x80,0x99
638 // the above character sequence encoded as UTF-8 (iconv)
639 static const unsigned char CP1252_utf8
[386] =
641 0x05,0x06,0x07,0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f,0x10,0x11,0x12,0x13,0x14,
642 0x15,0x16,0x17,0x18,0x19,0x1a,0x1b,0x1c,0x1d,0x1e,0x1f,0x20,0x21,0x22,0x23,0x24,
643 0x25,0x26,0x27,0x28,0x29,0x2a,0x2b,0x2c,0x2d,0x2e,0x2f,0x30,0x31,0x32,0x33,0x34,
644 0x35,0x36,0x37,0x38,0x39,0x3a,0x3b,0x3c,0x3d,0x3e,0x3f,0x40,0x41,0x42,0x43,0x44,
645 0x45,0x46,0x47,0x48,0x49,0x4a,0x4b,0x4c,0x4d,0x4e,0x4f,0x50,0x51,0x52,0x53,0x54,
646 0x55,0x56,0x57,0x58,0x59,0x5a,0x5b,0x5c,0x5d,0x5e,0x5f,0x60,0x61,0x62,0x63,0x64,
647 0x65,0x66,0x67,0x68,0x69,0x6a,0x6b,0x6c,0x6d,0x6e,0x6f,0x70,0x71,0x72,0x73,0x74,
648 0x75,0x76,0x77,0x78,0x79,0x7a,0x7b,0x7c,0x7d,0x7e,0x7f,0xc2,0xa0,0xc2,0xa1,0xc2,
649 0xa2,0xc2,0xa3,0xc2,0xa4,0xc2,0xa5,0xc2,0xa6,0xc2,0xa7,0xc2,0xa8,0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99,0xe2,0x80,0x9a,0xe2,0x80,
663 0x9c,0xe2,0x80,0x9d,0xe2,0x80,0x9e,0xe2,0x80,0xa0,0xe2,0x80,0xa1,0xe2,0x80,0xa2,
664 0xe2,0x80,0xa6,0xe2,0x80,0xb0,0xe2,0x80,0xb9,0xe2,0x80,0xba,0xe2,0x82,0xac,0xe2,
668 // a character sequence encoded as iso8859-5 (iconv)
669 static const unsigned char iso8859_5
[251] =
671 0x05,0x06,0x07,0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f,0x10,0x11,0x12,0x13,0x14,
672 0x15,0x16,0x17,0x18,0x19,0x1a,0x1b,0x1c,0x1d,0x1e,0x1f,0x20,0x21,0x22,0x23,0x24,
673 0x25,0x26,0x27,0x28,0x29,0x2a,0x2b,0x2c,0x2d,0x2e,0x2f,0x30,0x31,0x32,0x33,0x34,
674 0x35,0x36,0x37,0x38,0x39,0x3a,0x3b,0x3c,0x3d,0x3e,0x3f,0x40,0x41,0x42,0x43,0x44,
675 0x45,0x46,0x47,0x48,0x49,0x4a,0x4b,0x4c,0x4d,0x4e,0x4f,0x50,0x51,0x52,0x53,0x54,
676 0x55,0x56,0x57,0x58,0x59,0x5a,0x5b,0x5c,0x5d,0x5e,0x5f,0x60,0x61,0x62,0x63,0x64,
677 0x65,0x66,0x67,0x68,0x69,0x6a,0x6b,0x6c,0x6d,0x6e,0x6f,0x70,0x71,0x72,0x73,0x74,
678 0x75,0x76,0x77,0x78,0x79,0x7a,0x7b,0x7c,0x7d,0x7e,0x7f,0x80,0x81,0x82,0x83,0x84,
679 0x85,0x86,0x87,0x88,0x89,0x8a,0x8b,0x8c,0x8d,0x8e,0x8f,0x90,0x91,0x92,0x93,0x94,
680 0x95,0x96,0x97,0x98,0x99,0x9a,0x9b,0x9c,0x9d,0x9e,0x9f,0xa0,0xfd,0xad,0xa1,0xa2,
681 0xa3,0xa4,0xa5,0xa6,0xa7,0xa8,0xa9,0xaa,0xab,0xac,0xae,0xaf,0xb0,0xb1,0xb2,0xb3,
682 0xb4,0xb5,0xb6,0xb7,0xb8,0xb9,0xba,0xbb,0xbc,0xbd,0xbe,0xbf,0xc0,0xc1,0xc2,0xc3,
683 0xc4,0xc5,0xc6,0xc7,0xc8,0xc9,0xca,0xcb,0xcc,0xcd,0xce,0xcf,0xd0,0xd1,0xd2,0xd3,
684 0xd4,0xd5,0xd6,0xd7,0xd8,0xd9,0xda,0xdb,0xdc,0xdd,0xde,0xdf,0xe0,0xe1,0xe2,0xe3,
685 0xe4,0xe5,0xe6,0xe7,0xe8,0xe9,0xea,0xeb,0xec,0xed,0xee,0xef,0xf1,0xf2,0xf3,0xf4,
686 0xf5,0xf6,0xf7,0xf8,0xf9,0xfa,0xfb,0xfc,0xfe,0xff,0xf0
688 // the above character sequence encoded as UTF-8 (iconv)
689 static const unsigned char iso8859_5_utf8
[380] =
691 0x05,0x06,0x07,0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f,0x10,0x11,0x12,0x13,0x14,
692 0x15,0x16,0x17,0x18,0x19,0x1a,0x1b,0x1c,0x1d,0x1e,0x1f,0x20,0x21,0x22,0x23,0x24,
693 0x25,0x26,0x27,0x28,0x29,0x2a,0x2b,0x2c,0x2d,0x2e,0x2f,0x30,0x31,0x32,0x33,0x34,
694 0x35,0x36,0x37,0x38,0x39,0x3a,0x3b,0x3c,0x3d,0x3e,0x3f,0x40,0x41,0x42,0x43,0x44,
695 0x45,0x46,0x47,0x48,0x49,0x4a,0x4b,0x4c,0x4d,0x4e,0x4f,0x50,0x51,0x52,0x53,0x54,
696 0x55,0x56,0x57,0x58,0x59,0x5a,0x5b,0x5c,0x5d,0x5e,0x5f,0x60,0x61,0x62,0x63,0x64,
697 0x65,0x66,0x67,0x68,0x69,0x6a,0x6b,0x6c,0x6d,0x6e,0x6f,0x70,0x71,0x72,0x73,0x74,
698 0x75,0x76,0x77,0x78,0x79,0x7a,0x7b,0x7c,0x7d,0x7e,0x7f,0xc2,0x80,0xc2,0x81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0x88,0xd1,
712 0x89,0xd1,0x8a,0xd1,0x8b,0xd1,0x8c,0xd1,0x8d,0xd1,0x8e,0xd1,0x8f,0xd1,0x91,0xd1,
713 0x92,0xd1,0x93,0xd1,0x94,0xd1,0x95,0xd1,0x96,0xd1,0x97,0xd1,0x98,0xd1,0x99,0xd1,
714 0x9a,0xd1,0x9b,0xd1,0x9c,0xd1,0x9e,0xd1,0x9f,0xe2,0x84,0x96
718 // decodes the specified *unterminated* UTF-8 byte array
719 wxWCharBuffer
DecodeUTF8(
720 const void* data
, // an unterminated UTF-8 encoded byte array
721 size_t size
// the byte length of data
724 // the decoder requires a null terminated buffer.
725 // the input data is not null terminated.
726 // copy to null terminated buffer
728 wxCharBuffer
nullTerminated( size
+1 );
729 memcpy( nullTerminated
.data(), data
, size
);
730 nullTerminated
.data()[size
] = 0;
731 return wxConvUTF8
.cMB2WC(nullTerminated
.data());
734 // tests the encoding and decoding capability of an wxMBConv object
736 // decodes the utf-8 bytes into wide characters
737 // encodes the wide characters to compare against input multiBuffer
738 // decodes the multiBuffer to compare against wide characters
739 // decodes the multiBuffer into wide characters
740 void MBConvTestCase::TestCoder(
741 const char* multiBuffer
, // a multibyte encoded character sequence that can be decoded by "converter"
742 size_t multiBytes
, // the byte length of the multibyte character sequence that can be decoded by "converter"
743 const char* utf8Buffer
, // the same character sequence as multiBuffer, encoded as UTF-8
744 size_t utf8Bytes
, // the byte length of the UTF-8 encoded character sequence
745 wxMBConv
* converter
, // the wxMBConv object thta can decode multiBuffer into a wide character sequence
746 int sizeofNull
// the number of bytes occupied by a terminating null in the converter's encoding
749 // wide character size and endian-ess varies from platform to platform
750 // compiler support for wide character literals varies from compiler to compiler
751 // so we should store the wide character version as UTF-8 and depend on
752 // the UTF-8 converter's ability to decode it to platform specific wide characters
753 // this test is invalid if the UTF-8 converter can't decode
754 wxWCharBuffer
wideBuffer((size_t)0);
755 wideBuffer
= DecodeUTF8( utf8Buffer
, utf8Bytes
);
756 size_t wideChars
= wxWcslen( wideBuffer
.data() );
762 (const char*)multiBuffer
,
771 (const char*)multiBuffer
,
779 WXDLLIMPEXP_BASE wxMBConv
* new_wxMBConv_wxwin( const wxChar
* name
);
781 void MBConvTestCase::FontmapTests()
784 wxMBConv
* converter
= new_wxMBConv_wxwin( _T("CP1252") );
792 (const char*)CP1252_utf8
,
802 WXDLLIMPEXP_BASE wxMBConv
* new_wxMBConv_iconv( const wxChar
* name
);
804 void MBConvTestCase::IconvTests()
807 wxMBConv
* converter
= new_wxMBConv_iconv( _T("CP932") );
813 (const char*)welcome_cp932
,
814 sizeof(welcome_cp932
),
815 (const char*)welcome_utf8
,
816 sizeof(welcome_utf8
),
824 void MBConvTestCase::CP1252Tests()
826 wxCSConv
convCP1252( wxFONTENCODING_CP1252
);
830 (const char*)CP1252_utf8
,
837 void MBConvTestCase::LibcTests()
839 // There isn't a locale that all systems support (except "C"), so leave
840 // this one disabled for non-Windows systems for the moment, until
841 // a solution can be found.
845 setlocale( LC_ALL
, "English_United States.1252" );
846 const unsigned char* systemMB
= CP1252
;
847 size_t systemMB_size
= sizeof(CP1252
);
848 const unsigned char* systemMB_utf8
= CP1252_utf8
;
849 size_t systemMB_utf8_size
= sizeof(CP1252_utf8
);
851 setlocale( LC_ALL
, "en_US.iso8859-1" );
852 const unsigned char* systemMB
= iso8859_1
;
853 size_t systemMB_size
= sizeof(iso8859_1
);
854 const unsigned char* systemMB_utf8
= iso8859_1_utf8
;
855 size_t systemMB_utf8_size
= sizeof(iso8859_1_utf8
);
857 wxMBConvLibc convLibc
;
859 (const char*)systemMB
,
861 (const char*)systemMB_utf8
,
870 // verifies that the specified mb sequences decode to the specified wc sequence
871 void MBConvTestCase::TestDecoder(
872 const wchar_t* wideBuffer
, // the same character sequence as multiBuffer, encoded as wchar_t
873 size_t wideChars
, // the number of wide characters at wideBuffer
874 const char* multiBuffer
, // a multibyte encoded character sequence that can be decoded by "converter"
875 size_t multiBytes
, // the byte length of the multibyte character sequence that can be decoded by "converter"
876 wxMBConv
* converter
, // the wxMBConv object that can decode multiBuffer into a wide character sequence
877 int sizeofNull
// number of bytes occupied by terminating null in this encoding
880 const unsigned UNINITIALIZED
= 0xcd;
882 // copy the input bytes into a null terminated buffer
883 wxCharBuffer
inputCopy( multiBytes
+sizeofNull
);
884 memcpy( inputCopy
.data(), multiBuffer
, multiBytes
);
885 memset( &inputCopy
.data()[multiBytes
], 0, sizeofNull
);
887 // calculate the output size
888 size_t outputWritten
= converter
->MB2WC
891 (const char*)inputCopy
.data(),
894 // make sure the correct output length was calculated
895 CPPUNIT_ASSERT( outputWritten
== wideChars
);
897 // convert the string
898 size_t guardChars
= 8; // to make sure we're not overrunning the output buffer
899 size_t nullCharacters
= 1;
900 size_t outputBufferChars
= outputWritten
+ nullCharacters
+ guardChars
;
901 wxWCharBuffer
outputBuffer(outputBufferChars
);
902 memset( outputBuffer
.data(), UNINITIALIZED
, outputBufferChars
*sizeof(wchar_t) );
904 outputWritten
= converter
->MB2WC
907 (const char*)inputCopy
.data(),
910 // make sure the correct number of characters were outputs
911 CPPUNIT_ASSERT( outputWritten
== wideChars
);
913 // make sure the characters generated are correct
914 CPPUNIT_ASSERT( 0 == memcmp( outputBuffer
, wideBuffer
, wideChars
*sizeof(wchar_t) ) );
916 // the output buffer should be null terminated
917 CPPUNIT_ASSERT( outputBuffer
[outputWritten
] == 0 );
919 // make sure the rest of the output buffer is untouched
920 for ( size_t i
= (wideChars
+1)*sizeof(wchar_t); i
< (outputBufferChars
*sizeof(wchar_t)); i
++ )
922 CPPUNIT_ASSERT( ((unsigned char*)outputBuffer
.data())[i
] == UNINITIALIZED
);
925 #if wxUSE_UNICODE && wxUSE_STREAMS
926 TestStreamDecoder( wideBuffer
, wideChars
, multiBuffer
, multiBytes
, converter
);
930 // verifies that the specified wc sequences encodes to the specified mb sequence
931 void MBConvTestCase::TestEncoder(
932 const wchar_t* wideBuffer
, // the same character sequence as multiBuffer, encoded as wchar_t
933 size_t wideChars
, // the number of wide characters at wideBuffer
934 const char* multiBuffer
, // a multibyte encoded character sequence that can be decoded by "converter"
935 size_t multiBytes
, // the byte length of the multibyte character sequence that can be decoded by "converter"
936 wxMBConv
* converter
, // the wxMBConv object that can decode multiBuffer into a wide character sequence
937 int sizeofNull
// number of bytes occupied by terminating null in this encoding
940 const unsigned UNINITIALIZED
= 0xcd;
942 // copy the input bytes into a null terminated buffer
943 wxWCharBuffer
inputCopy( wideChars
+ 1 );
944 memcpy( inputCopy
.data(), wideBuffer
, (wideChars
*sizeof(wchar_t)) );
945 inputCopy
.data()[wideChars
] = 0;
947 // calculate the output size
948 size_t outputWritten
= converter
->WC2MB
951 (const wchar_t*)inputCopy
.data(),
954 // make sure the correct output length was calculated
955 CPPUNIT_ASSERT( outputWritten
== multiBytes
);
957 // convert the string
958 size_t guardBytes
= 8; // to make sure we're not overrunning the output buffer
959 size_t outputBufferSize
= outputWritten
+ sizeofNull
+ guardBytes
;
960 wxCharBuffer
outputBuffer(outputBufferSize
);
961 memset( outputBuffer
.data(), UNINITIALIZED
, outputBufferSize
);
963 outputWritten
= converter
->WC2MB
966 (const wchar_t*)inputCopy
.data(),
970 // make sure the correct number of characters were output
971 CPPUNIT_ASSERT( outputWritten
== multiBytes
);
973 // make sure the characters generated are correct
974 CPPUNIT_ASSERT( 0 == memcmp( outputBuffer
, multiBuffer
, multiBytes
) );
978 // the output buffer should be null terminated
979 for ( i
= multiBytes
; i
< multiBytes
+ sizeofNull
; i
++ )
981 CPPUNIT_ASSERT( ((unsigned char*)outputBuffer
.data())[i
] == 0 );
984 // make sure the rest of the output buffer is untouched
985 for ( i
= multiBytes
+ sizeofNull
; i
< outputBufferSize
; i
++ )
987 CPPUNIT_ASSERT( ((unsigned char*)outputBuffer
.data())[i
] == UNINITIALIZED
);
990 #if wxUSE_UNICODE && wxUSE_STREAMS
991 TestStreamEncoder( wideBuffer
, wideChars
, multiBuffer
, multiBytes
, converter
);
995 #if wxUSE_UNICODE && wxUSE_STREAMS
996 // use wxTextInputStream to exercise wxMBConv interface
997 // (this reveals some bugs in certain wxMBConv subclasses)
998 void MBConvTestCase::TestStreamDecoder(
999 const wchar_t* wideBuffer
, // the same character sequence as multiBuffer, encoded as wchar_t
1000 size_t wideChars
, // the number of wide characters at wideBuffer
1001 const char* multiBuffer
, // a multibyte encoded character sequence that can be decoded by "converter"
1002 size_t multiBytes
, // the byte length of the multibyte character sequence that can be decoded by "converter"
1003 wxMBConv
* converter
// the wxMBConv object that can decode multiBuffer into a wide character sequence
1006 // this isn't meant to test wxMemoryInputStream or wxTextInputStream
1007 // it's meant to test the way wxTextInputStream uses wxMBConv
1008 // (which has exposed some problems with wxMBConv)
1009 wxMemoryInputStream
memoryInputStream( multiBuffer
, multiBytes
);
1010 wxTextInputStream
textInputStream( memoryInputStream
, wxT(""), *converter
);
1011 for ( size_t i
= 0; i
< wideChars
; i
++ )
1013 wxChar wc
= textInputStream
.GetChar();
1014 CPPUNIT_ASSERT( wc
== wideBuffer
[i
] );
1016 CPPUNIT_ASSERT( 0 == textInputStream
.GetChar() );
1017 CPPUNIT_ASSERT( memoryInputStream
.Eof() );
1021 #if wxUSE_UNICODE && wxUSE_STREAMS
1022 // use wxTextInputStream to exercise wxMBConv interface
1023 // (this reveals some bugs in certain wxMBConv subclasses)
1024 void MBConvTestCase::TestStreamEncoder(
1025 const wchar_t* wideBuffer
, // the same character sequence as multiBuffer, encoded as wchar_t
1026 size_t wideChars
, // the number of wide characters at wideBuffer
1027 const char* multiBuffer
, // a multibyte encoded character sequence that can be decoded by "converter"
1028 size_t multiBytes
, // the byte length of the multibyte character sequence that can be decoded by "converter"
1029 wxMBConv
* converter
// the wxMBConv object that can decode multiBuffer into a wide character sequence
1032 // this isn't meant to test wxMemoryOutputStream or wxTextOutputStream
1033 // it's meant to test the way wxTextOutputStream uses wxMBConv
1034 // (which has exposed some problems with wxMBConv)
1035 wxMemoryOutputStream memoryOutputStream
;
1036 // wxEOL_UNIX will pass \n \r unchanged
1037 wxTextOutputStream
textOutputStream( memoryOutputStream
, wxEOL_UNIX
, *converter
);
1038 for ( size_t i
= 0; i
< wideChars
; i
++ )
1040 textOutputStream
.PutChar( wideBuffer
[i
] );
1042 CPPUNIT_ASSERT_EQUAL( (wxFileOffset
)multiBytes
, memoryOutputStream
.TellO() );
1043 wxCharBuffer
copy( memoryOutputStream
.TellO() );
1044 memoryOutputStream
.CopyTo( copy
.data(), memoryOutputStream
.TellO());
1045 CPPUNIT_ASSERT_EQUAL( 0, memcmp( copy
.data(), multiBuffer
, multiBytes
) );
1050 // ----------------------------------------------------------------------------
1052 // ----------------------------------------------------------------------------
1056 // Check that 'charSequence' translates to 'wideSequence' and back.
1057 // Invalid sequences can be tested by giving NULL for 'wideSequence'. Even
1058 // invalid sequences should roundtrip when an option is given and this is
1061 void MBConvTestCase::UTF8(const char *charSequence
,
1062 const wchar_t *wideSequence
)
1064 UTF8(charSequence
, wideSequence
, wxMBConvUTF8::MAP_INVALID_UTF8_NOT
);
1065 UTF8(charSequence
, wideSequence
, wxMBConvUTF8::MAP_INVALID_UTF8_TO_PUA
);
1066 UTF8(charSequence
, wideSequence
, wxMBConvUTF8::MAP_INVALID_UTF8_TO_OCTAL
);
1069 // Use this alternative when 'charSequence' contains a PUA character. Such
1070 // sequences should still roundtrip ok, and this is checked.
1072 void MBConvTestCase::UTF8PUA(const char *charSequence
,
1073 const wchar_t *wideSequence
)
1075 UTF8(charSequence
, wideSequence
, wxMBConvUTF8::MAP_INVALID_UTF8_NOT
);
1076 UTF8(charSequence
, NULL
, wxMBConvUTF8::MAP_INVALID_UTF8_TO_PUA
);
1077 UTF8(charSequence
, wideSequence
, wxMBConvUTF8::MAP_INVALID_UTF8_TO_OCTAL
);
1080 // Use this alternative when 'charSequence' contains an octal escape sequence.
1081 // Such sequences should still roundtrip ok, and this is checked.
1083 void MBConvTestCase::UTF8Octal(const char *charSequence
,
1084 const wchar_t *wideSequence
)
1086 UTF8(charSequence
, wideSequence
, wxMBConvUTF8::MAP_INVALID_UTF8_NOT
);
1087 UTF8(charSequence
, wideSequence
, wxMBConvUTF8::MAP_INVALID_UTF8_TO_PUA
);
1088 UTF8(charSequence
, NULL
, wxMBConvUTF8::MAP_INVALID_UTF8_TO_OCTAL
);
1091 // in case wcscpy is missing
1093 static wchar_t *wx_wcscpy(wchar_t *dest
, const wchar_t *src
)
1096 while ((*d
++ = *src
++) != 0)
1101 // in case wcscat is missing
1103 static wchar_t *wx_wcscat(wchar_t *dest
, const wchar_t *src
)
1108 while ((*d
++ = *src
++) != 0)
1113 // in case wcscmp is missing
1115 static int wx_wcscmp(const wchar_t *s1
, const wchar_t *s2
)
1117 while (*s1
== *s2
&& *s1
!= 0)
1125 // in case wcslen is missing
1127 static size_t wx_wcslen(const wchar_t *s
)
1129 const wchar_t *t
= s
;
1135 // include the option in the error messages so it's possible to see which
1137 #define UTF8ASSERT(expr) CPPUNIT_ASSERT_MESSAGE(#expr + errmsg, expr)
1139 // The test implementation
1141 void MBConvTestCase::UTF8(const char *charSequence
,
1142 const wchar_t *wideSequence
,
1145 const size_t BUFSIZE
= 128;
1146 wxASSERT(strlen(charSequence
) * 3 + 10 < BUFSIZE
);
1147 char bytes
[BUFSIZE
];
1149 // include the option in the error messages so it's possible to see
1150 // which test failed
1151 sprintf(bytes
, " (with option == %d)", option
);
1152 std::string
errmsg(bytes
);
1154 // put the charSequence at the start, middle and end of a string
1155 strcpy(bytes
, charSequence
);
1156 strcat(bytes
, "ABC");
1157 strcat(bytes
, charSequence
);
1158 strcat(bytes
, "XYZ");
1159 strcat(bytes
, charSequence
);
1161 // translate it into wide characters
1162 wxMBConvUTF8
utf8(option
);
1163 wchar_t widechars
[BUFSIZE
];
1164 size_t lenResult
= utf8
.MB2WC(NULL
, bytes
, 0);
1165 size_t result
= utf8
.MB2WC(widechars
, bytes
, BUFSIZE
);
1166 UTF8ASSERT(result
== lenResult
);
1168 // check we got the expected result
1170 UTF8ASSERT(result
!= (size_t)-1);
1171 wxASSERT(result
< BUFSIZE
);
1173 wchar_t expected
[BUFSIZE
];
1174 wx_wcscpy(expected
, wideSequence
);
1175 wx_wcscat(expected
, L
"ABC");
1176 wx_wcscat(expected
, wideSequence
);
1177 wx_wcscat(expected
, L
"XYZ");
1178 wx_wcscat(expected
, wideSequence
);
1180 UTF8ASSERT(wx_wcscmp(widechars
, expected
) == 0);
1181 UTF8ASSERT(wx_wcslen(widechars
) == result
);
1184 // If 'wideSequence' is NULL, then the result is expected to be
1185 // invalid. Normally that is as far as we can go, but if there is an
1186 // option then the conversion should succeed anyway, and it should be
1187 // possible to translate back to the original
1189 UTF8ASSERT(result
== (size_t)-1);
1193 UTF8ASSERT(result
!= (size_t)-1);
1197 // translate it back and check we get the original
1198 char bytesAgain
[BUFSIZE
];
1199 size_t lenResultAgain
= utf8
.WC2MB(NULL
, widechars
, 0);
1200 size_t resultAgain
= utf8
.WC2MB(bytesAgain
, widechars
, BUFSIZE
);
1201 UTF8ASSERT(resultAgain
== lenResultAgain
);
1202 UTF8ASSERT(resultAgain
!= (size_t)-1);
1203 wxASSERT(resultAgain
< BUFSIZE
);
1205 UTF8ASSERT(strcmp(bytes
, bytesAgain
) == 0);
1206 UTF8ASSERT(strlen(bytesAgain
) == resultAgain
);
1209 #endif // HAVE_WCHAR_H