]>
Commit | Line | Data |
---|---|---|
2cc07181 VZ |
1 | /////////////////////////////////////////////////////////////////////////////// |
2 | // Name: tests/mbconv/main.cpp | |
3 | // Purpose: wxMBConv unit test | |
8f115891 | 4 | // Author: Vadim Zeitlin, Mike Wetherell, Vince Harron |
2cc07181 VZ |
5 | // Created: 14.02.04 |
6 | // RCS-ID: $Id$ | |
8f115891 | 7 | // Copyright: (c) 2003 TT-Solutions, (c) 2005 Mike Wetherell, Vince Harron |
2cc07181 VZ |
8 | /////////////////////////////////////////////////////////////////////////////// |
9 | ||
10 | // ---------------------------------------------------------------------------- | |
11 | // headers | |
12 | // ---------------------------------------------------------------------------- | |
13 | ||
8899b155 | 14 | #include "testprec.h" |
20f46e8d VS |
15 | |
16 | #ifdef __BORLANDC__ | |
17 | #pragma hdrstop | |
18 | #endif | |
19 | ||
20 | #ifndef WX_PRECOMP | |
21 | #include "wx/wx.h" | |
22 | #endif // WX_PRECOMP | |
23 | ||
2cc07181 VZ |
24 | #include "wx/strconv.h" |
25 | #include "wx/string.h" | |
8f115891 MW |
26 | #include "wx/txtstrm.h" |
27 | #include "wx/mstream.h" | |
2cc07181 | 28 | |
726c8204 MW |
29 | #if defined wxHAVE_TCHAR_SUPPORT && !defined HAVE_WCHAR_H |
30 | #define HAVE_WCHAR_H | |
31 | #endif | |
32 | ||
33 | // ---------------------------------------------------------------------------- | |
34 | // Some wide character constants. "\uXXXX" escapes aren't supported by old | |
35 | // compilers such as VC++ 5 and g++ 2.95. | |
36 | // ---------------------------------------------------------------------------- | |
37 | ||
38 | wchar_t u41[] = { 0x41, 0 }; | |
39 | wchar_t u7f[] = { 0x7f, 0 }; | |
40 | ||
41 | wchar_t u80[] = { 0x80, 0 }; | |
42 | wchar_t u391[] = { 0x391, 0 }; | |
43 | wchar_t u7ff[] = { 0x7ff, 0 }; | |
44 | ||
45 | wchar_t u800[] = { 0x800, 0 }; | |
46 | wchar_t u2620[] = { 0x2620, 0 }; | |
47 | wchar_t ufffd[] = { 0xfffd, 0 }; | |
48 | ||
49 | #if SIZEOF_WCHAR_T == 4 | |
50 | wchar_t u10000[] = { 0x10000, 0 }; | |
51 | wchar_t u1000a5[] = { 0x1000a5, 0 }; | |
52 | wchar_t u10fffd[] = { 0x10fffd, 0 }; | |
53 | #else | |
54 | wchar_t u10000[] = { 0xd800, 0xdc00, 0 }; | |
55 | wchar_t u1000a5[] = { 0xdbc0, 0xdca5, 0 }; | |
56 | wchar_t u10fffd[] = { 0xdbff, 0xdffd, 0 }; | |
57 | #endif | |
58 | ||
2cc07181 VZ |
59 | // ---------------------------------------------------------------------------- |
60 | // test class | |
61 | // ---------------------------------------------------------------------------- | |
62 | ||
63 | class MBConvTestCase : public CppUnit::TestCase | |
64 | { | |
65 | public: | |
66 | MBConvTestCase() { } | |
67 | ||
68 | private: | |
69 | CPPUNIT_TEST_SUITE( MBConvTestCase ); | |
8f115891 MW |
70 | CPPUNIT_TEST( UTF32LETests ); |
71 | CPPUNIT_TEST( UTF32BETests ); | |
2cc07181 | 72 | CPPUNIT_TEST( WC2CP1250 ); |
8f115891 MW |
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 ); | |
fec42c21 | 81 | CPPUNIT_TEST( Latin1Tests ); |
8f115891 | 82 | CPPUNIT_TEST( FontmapTests ); |
8a493b67 | 83 | CPPUNIT_TEST( BufSize ); |
726c8204 MW |
84 | #ifdef HAVE_WCHAR_H |
85 | CPPUNIT_TEST( UTF8_41 ); | |
86 | CPPUNIT_TEST( UTF8_7f ); | |
87 | CPPUNIT_TEST( UTF8_80 ); | |
88 | CPPUNIT_TEST( UTF8_c2_7f ); | |
89 | CPPUNIT_TEST( UTF8_c2_80 ); | |
90 | CPPUNIT_TEST( UTF8_ce_91 ); | |
91 | CPPUNIT_TEST( UTF8_df_bf ); | |
92 | CPPUNIT_TEST( UTF8_df_c0 ); | |
93 | CPPUNIT_TEST( UTF8_e0_a0_7f ); | |
94 | CPPUNIT_TEST( UTF8_e0_a0_80 ); | |
95 | CPPUNIT_TEST( UTF8_e2_98_a0 ); | |
96 | CPPUNIT_TEST( UTF8_ef_bf_bd ); | |
97 | CPPUNIT_TEST( UTF8_ef_bf_c0 ); | |
98 | CPPUNIT_TEST( UTF8_f0_90_80_7f ); | |
99 | CPPUNIT_TEST( UTF8_f0_90_80_80 ); | |
100 | CPPUNIT_TEST( UTF8_f4_8f_bf_bd ); | |
101 | CPPUNIT_TEST( UTF8PUA_f4_80_82_a5 ); | |
102 | CPPUNIT_TEST( UTF8Octal_backslash245 ); | |
103 | #endif // HAVE_WCHAR_H | |
2cc07181 VZ |
104 | CPPUNIT_TEST_SUITE_END(); |
105 | ||
106 | void WC2CP1250(); | |
8f115891 MW |
107 | void UTF7Tests(); |
108 | void UTF8Tests(); | |
109 | void UTF16LETests(); | |
110 | void UTF16BETests(); | |
111 | void UTF32LETests(); | |
112 | void UTF32BETests(); | |
113 | void CP932Tests(); | |
114 | void CP1252Tests(); | |
115 | void LibcTests(); | |
116 | void FontmapTests(); | |
8a493b67 | 117 | void BufSize(); |
8f115891 | 118 | void IconvTests(); |
fec42c21 | 119 | void Latin1Tests(); |
8f115891 MW |
120 | |
121 | // verifies that the specified multibyte sequence decodes to the specified wchar_t sequence | |
122 | void TestDecoder( | |
123 | const wchar_t* wideBuffer, // the same character sequence as multiBuffer, encoded as wchar_t | |
124 | size_t wideChars, // the number of wide characters at wideBuffer | |
125 | const char* multiBuffer, // a multibyte encoded character sequence that can be decoded by "converter" | |
126 | size_t multiBytes, // the byte length of the multibyte character sequence that can be decoded by "converter" | |
86501081 | 127 | wxMBConv& converter, // the wxMBConv object that can decode multiBuffer into a wide character sequence |
8f115891 MW |
128 | int sizeofNull // number of bytes occupied by terminating null in this encoding |
129 | ); | |
130 | ||
131 | // verifies that the specified wchar_t sequence encodes to the specified multibyte sequence | |
132 | void TestEncoder( | |
133 | const wchar_t* wideBuffer, // the same character sequence as multiBuffer, encoded as wchar_t | |
134 | size_t wideChars, // the number of wide characters at wideBuffer | |
135 | const char* multiBuffer, // a multibyte encoded character sequence that can be decoded by "converter" | |
136 | size_t multiBytes, // the byte length of the multibyte character sequence that can be decoded by "converter" | |
86501081 | 137 | wxMBConv& converter, // the wxMBConv object that can decode multiBuffer into a wide character sequence |
8f115891 MW |
138 | int sizeofNull // number of bytes occupied by terminating null in this encoding |
139 | ); | |
140 | ||
141 | #if wxUSE_UNICODE && wxUSE_STREAMS | |
142 | // use wxTextInputStream to exercise wxMBConv interface | |
143 | // (this reveals some bugs in certain wxMBConv subclasses) | |
144 | void TestStreamDecoder( | |
145 | const wchar_t* wideBuffer, // the same character sequence as multiBuffer, encoded as wchar_t | |
146 | size_t wideChars, // the number of wide characters at wideBuffer | |
147 | const char* multiBuffer, // a multibyte encoded character sequence that can be decoded by "converter" | |
148 | size_t multiBytes, // the byte length of the multibyte character sequence that can be decoded by "converter" | |
86501081 | 149 | wxMBConv& converter // the wxMBConv object that can decode multiBuffer into a wide character sequence |
8f115891 MW |
150 | ); |
151 | ||
152 | // use wxTextOutputStream to exercise wxMBConv interface | |
153 | // (this reveals some bugs in certain wxMBConv subclasses) | |
154 | void TestStreamEncoder( | |
155 | const wchar_t* wideBuffer, // the same character sequence as multiBuffer, encoded as wchar_t | |
156 | size_t wideChars, // the number of wide characters at wideBuffer | |
157 | const char* multiBuffer, // a multibyte encoded character sequence that can be decoded by "converter" | |
158 | size_t multiBytes, // the byte length of the multibyte character sequence that can be decoded by "converter" | |
86501081 | 159 | wxMBConv& converter // the wxMBConv object that can decode multiBuffer into a wide character sequence |
8f115891 MW |
160 | ); |
161 | #endif | |
162 | ||
163 | // tests the encoding and decoding capability of an wxMBConv object | |
164 | // | |
165 | // decodes the utf-8 bytes into wide characters | |
166 | // encodes the wide characters to compare against input multiBuffer | |
167 | // decodes the multiBuffer to compare against wide characters | |
168 | // decodes the multiBuffer into wide characters | |
169 | void TestCoder( | |
170 | const char* multiBuffer, // a multibyte encoded character sequence that can be decoded by "converter" | |
171 | size_t multiBytes, // the byte length of the multibyte character sequence that can be decoded by "converter" | |
172 | const char* utf8Buffer, // the same character sequence as multiBuffer, encoded as UTF-8 | |
173 | size_t utf8Bytes, // the byte length of the UTF-8 encoded character sequence | |
86501081 | 174 | wxMBConv& converter, // the wxMBConv object that can decode multiBuffer into a wide character sequence |
8f115891 MW |
175 | int sizeofNull // the number of bytes occupied by a terminating null in the converter's encoding |
176 | ); | |
2cc07181 | 177 | |
726c8204 MW |
178 | #ifdef HAVE_WCHAR_H |
179 | // UTF-8 tests. Test the first, last and one in the middle for sequences | |
180 | // of each length | |
181 | void UTF8_41() { UTF8("\x41", u41); } | |
182 | void UTF8_7f() { UTF8("\x7f", u7f); } | |
183 | void UTF8_80() { UTF8("\x80", NULL); } | |
184 | ||
185 | void UTF8_c2_7f() { UTF8("\xc2\x7f", NULL); } | |
186 | void UTF8_c2_80() { UTF8("\xc2\x80", u80); } | |
187 | void UTF8_ce_91() { UTF8("\xce\x91", u391); } | |
188 | void UTF8_df_bf() { UTF8("\xdf\xbf", u7ff); } | |
189 | void UTF8_df_c0() { UTF8("\xdf\xc0", NULL); } | |
190 | ||
191 | void UTF8_e0_a0_7f() { UTF8("\xe0\xa0\x7f", NULL); } | |
192 | void UTF8_e0_a0_80() { UTF8("\xe0\xa0\x80", u800); } | |
193 | void UTF8_e2_98_a0() { UTF8("\xe2\x98\xa0", u2620); } | |
194 | void UTF8_ef_bf_bd() { UTF8("\xef\xbf\xbd", ufffd); } | |
195 | void UTF8_ef_bf_c0() { UTF8("\xef\xbf\xc0", NULL); } | |
196 | ||
197 | void UTF8_f0_90_80_7f() { UTF8("\xf0\x90\x80\x7f", NULL); } | |
198 | void UTF8_f0_90_80_80() { UTF8("\xf0\x90\x80\x80", u10000); } | |
199 | void UTF8_f4_8f_bf_bd() { UTF8("\xf4\x8f\xbf\xbd", u10fffd); } | |
200 | ||
201 | // test 'escaping the escape characters' for the two escaping schemes | |
202 | void UTF8PUA_f4_80_82_a5() { UTF8PUA("\xf4\x80\x82\xa5", u1000a5); } | |
203 | void UTF8Octal_backslash245() { UTF8Octal("\\245", L"\\245"); } | |
204 | ||
205 | // implementation for the utf-8 tests (see comments below) | |
206 | void UTF8(const char *charSequence, const wchar_t *wideSequence); | |
207 | void UTF8PUA(const char *charSequence, const wchar_t *wideSequence); | |
208 | void UTF8Octal(const char *charSequence, const wchar_t *wideSequence); | |
209 | void UTF8(const char *charSequence, const wchar_t *wideSequence, int option); | |
210 | #endif // HAVE_WCHAR_H | |
211 | ||
20f46e8d | 212 | DECLARE_NO_COPY_CLASS(MBConvTestCase) |
2cc07181 VZ |
213 | }; |
214 | ||
98eae466 VS |
215 | // register in the unnamed registry so that these tests are run by default |
216 | CPPUNIT_TEST_SUITE_REGISTRATION( MBConvTestCase ); | |
217 | ||
218 | // also include in it's own registry so that these tests can be run alone | |
1002abaa | 219 | CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( MBConvTestCase, "MBConvTestCase" ); |
e6a87338 | 220 | CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( MBConvTestCase, "MBConv" ); |
2cc07181 VZ |
221 | |
222 | void MBConvTestCase::WC2CP1250() | |
223 | { | |
224 | static const struct Data | |
225 | { | |
226 | const wchar_t *wc; | |
227 | const char *cp1250; | |
228 | } data[] = | |
229 | { | |
230 | { L"hello", "hello" }, // test that it works in simplest case | |
a430a60f | 231 | { L"\xBD of \xBD is \xBC", NULL }, // this should fail as cp1250 doesn't have 1/2 |
2cc07181 VZ |
232 | }; |
233 | ||
234 | wxCSConv cs1250(wxFONTENCODING_CP1250); | |
235 | for ( size_t n = 0; n < WXSIZEOF(data); n++ ) | |
236 | { | |
237 | const Data& d = data[n]; | |
98eae466 VS |
238 | if (d.cp1250) |
239 | { | |
240 | CPPUNIT_ASSERT( strcmp(cs1250.cWC2MB(d.wc), d.cp1250) == 0 ); | |
241 | } | |
242 | else | |
243 | { | |
0f216992 | 244 | CPPUNIT_ASSERT( (const char*)cs1250.cWC2MB(d.wc) == NULL ); |
98eae466 | 245 | } |
2cc07181 VZ |
246 | } |
247 | } | |
726c8204 | 248 | |
75b16a30 VS |
249 | // Print an unsigned character array as a C unsigned character array. |
250 | // NB: Please don't remove this function even though it's not used anywhere, | |
251 | // it's very useful when debugging a failed test. | |
252 | wxString CByteArrayFormat( const void* data, size_t len, const wxChar* name ) | |
253 | { | |
254 | const unsigned char* bytes = (unsigned char*)data; | |
255 | wxString result; | |
256 | ||
257 | result.Printf( _T("const static unsigned char %s[%i] = \n{"), name, (int)len ); | |
258 | ||
259 | for ( size_t i = 0; i < len; i++ ) | |
260 | { | |
261 | if ( i != 0 ) | |
262 | { | |
263 | result.append( _T(",") ); | |
264 | } | |
265 | if ((i%16)==0) | |
266 | { | |
267 | result.append( _T("\n ") ); | |
268 | } | |
269 | wxString byte = wxString::Format( _T("0x%02x"), bytes[i] ); | |
270 | result.append(byte); | |
271 | } | |
272 | result.append( _T("\n};\n") ); | |
273 | return result; | |
274 | } | |
275 | ||
78648f60 | 276 | // The following bytes represent the same string, containing Japanese and English |
8f115891 MW |
277 | // characters, encoded in several different formats. |
278 | ||
279 | // encoded by iconv | |
78648f60 | 280 | const static unsigned char welcome_utf7_iconv[84] = |
8f115891 MW |
281 | { |
282 | 0x57,0x65,0x6c,0x63,0x6f,0x6d,0x65,0x20,0x74,0x6f,0x20,0x6f,0x75,0x72,0x20,0x63, | |
283 | 0x79,0x62,0x65,0x72,0x20,0x73,0x70,0x61,0x63,0x65,0x20,0x66,0x6f,0x72,0x63,0x65, | |
284 | 0x2e,0x20,0x20,0x2b,0x4d,0x46,0x6b,0x77,0x55,0x49,0x74,0x6d,0x57,0x39,0x38,0x77, | |
285 | 0x61,0x35,0x62,0x37,0x69,0x6e,0x45,0x77,0x6b,0x6a,0x42,0x5a,0x4d,0x49,0x73,0x77, | |
286 | 0x65,0x7a,0x42,0x47,0x4d,0x45,0x77,0x77,0x52,0x44,0x42,0x45,0x4d,0x47,0x63,0x77, | |
287 | 0x57,0x54,0x41,0x43 | |
288 | }; | |
289 | // encoded by wxWindows (iconv can decode this successfully) | |
78648f60 | 290 | const static unsigned char welcome_utf7_wx[109] = |
8f115891 MW |
291 | { |
292 | 0x57,0x65,0x6c,0x63,0x6f,0x6d,0x65,0x2b,0x41,0x43,0x41,0x2d,0x74,0x6f,0x2b,0x41, | |
293 | 0x43,0x41,0x2d,0x6f,0x75,0x72,0x2b,0x41,0x43,0x41,0x2d,0x63,0x79,0x62,0x65,0x72, | |
294 | 0x2b,0x41,0x43,0x41,0x2d,0x73,0x70,0x61,0x63,0x65,0x2b,0x41,0x43,0x41,0x2d,0x66, | |
295 | 0x6f,0x72,0x63,0x65,0x2e,0x2b,0x41,0x43,0x41,0x41,0x49,0x44,0x42,0x5a,0x4d,0x46, | |
296 | 0x43,0x4c,0x5a,0x6c,0x76,0x66,0x4d,0x47,0x75,0x57,0x2b,0x34,0x70,0x78,0x4d,0x4a, | |
297 | 0x49,0x77,0x57,0x54,0x43,0x4c,0x4d,0x48,0x73,0x77,0x52,0x6a,0x42,0x4d,0x4d,0x45, | |
298 | 0x51,0x77,0x52,0x44,0x42,0x6e,0x4d,0x46,0x6b,0x77,0x41,0x67,0x2d | |
299 | }; | |
300 | // encoded by iconv | |
78648f60 | 301 | const static unsigned char welcome_utf8[89] = |
8f115891 MW |
302 | { |
303 | 0x57,0x65,0x6c,0x63,0x6f,0x6d,0x65,0x20,0x74,0x6f,0x20,0x6f,0x75,0x72,0x20,0x63, | |
304 | 0x79,0x62,0x65,0x72,0x20,0x73,0x70,0x61,0x63,0x65,0x20,0x66,0x6f,0x72,0x63,0x65, | |
305 | 0x2e,0x20,0x20,0xe3,0x81,0x99,0xe3,0x81,0x90,0xe8,0xad,0xa6,0xe5,0xaf,0x9f,0xe3, | |
306 | 0x81,0xab,0xe9,0x9b,0xbb,0xe8,0xa9,0xb1,0xe3,0x82,0x92,0xe3,0x81,0x99,0xe3,0x82, | |
307 | 0x8b,0xe3,0x81,0xbb,0xe3,0x81,0x86,0xe3,0x81,0x8c,0xe3,0x81,0x84,0xe3,0x81,0x84, | |
308 | 0xe3,0x81,0xa7,0xe3,0x81,0x99,0xe3,0x80,0x82 | |
309 | }; | |
310 | // encoded by iconv | |
78648f60 | 311 | const static unsigned char welcome_utf16le[106] = |
8f115891 MW |
312 | { |
313 | 0x57,0x00,0x65,0x00,0x6c,0x00,0x63,0x00,0x6f,0x00,0x6d,0x00,0x65,0x00,0x20,0x00, | |
314 | 0x74,0x00,0x6f,0x00,0x20,0x00,0x6f,0x00,0x75,0x00,0x72,0x00,0x20,0x00,0x63,0x00, | |
315 | 0x79,0x00,0x62,0x00,0x65,0x00,0x72,0x00,0x20,0x00,0x73,0x00,0x70,0x00,0x61,0x00, | |
316 | 0x63,0x00,0x65,0x00,0x20,0x00,0x66,0x00,0x6f,0x00,0x72,0x00,0x63,0x00,0x65,0x00, | |
317 | 0x2e,0x00,0x20,0x00,0x20,0x00,0x59,0x30,0x50,0x30,0x66,0x8b,0xdf,0x5b,0x6b,0x30, | |
318 | 0xfb,0x96,0x71,0x8a,0x92,0x30,0x59,0x30,0x8b,0x30,0x7b,0x30,0x46,0x30,0x4c,0x30, | |
319 | 0x44,0x30,0x44,0x30,0x67,0x30,0x59,0x30,0x02,0x30 | |
320 | }; | |
321 | // encoded by iconv | |
78648f60 | 322 | const static unsigned char welcome_utf16be[106] = |
8f115891 MW |
323 | { |
324 | 0x00,0x57,0x00,0x65,0x00,0x6c,0x00,0x63,0x00,0x6f,0x00,0x6d,0x00,0x65,0x00,0x20, | |
325 | 0x00,0x74,0x00,0x6f,0x00,0x20,0x00,0x6f,0x00,0x75,0x00,0x72,0x00,0x20,0x00,0x63, | |
326 | 0x00,0x79,0x00,0x62,0x00,0x65,0x00,0x72,0x00,0x20,0x00,0x73,0x00,0x70,0x00,0x61, | |
327 | 0x00,0x63,0x00,0x65,0x00,0x20,0x00,0x66,0x00,0x6f,0x00,0x72,0x00,0x63,0x00,0x65, | |
328 | 0x00,0x2e,0x00,0x20,0x00,0x20,0x30,0x59,0x30,0x50,0x8b,0x66,0x5b,0xdf,0x30,0x6b, | |
329 | 0x96,0xfb,0x8a,0x71,0x30,0x92,0x30,0x59,0x30,0x8b,0x30,0x7b,0x30,0x46,0x30,0x4c, | |
330 | 0x30,0x44,0x30,0x44,0x30,0x67,0x30,0x59,0x30,0x02 | |
331 | }; | |
332 | // encoded by iconv | |
78648f60 | 333 | const static unsigned char welcome_utf32le[212] = |
8f115891 MW |
334 | { |
335 | 0x57,0x00,0x00,0x00,0x65,0x00,0x00,0x00,0x6c,0x00,0x00,0x00,0x63,0x00,0x00,0x00, | |
336 | 0x6f,0x00,0x00,0x00,0x6d,0x00,0x00,0x00,0x65,0x00,0x00,0x00,0x20,0x00,0x00,0x00, | |
337 | 0x74,0x00,0x00,0x00,0x6f,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x6f,0x00,0x00,0x00, | |
338 | 0x75,0x00,0x00,0x00,0x72,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x63,0x00,0x00,0x00, | |
339 | 0x79,0x00,0x00,0x00,0x62,0x00,0x00,0x00,0x65,0x00,0x00,0x00,0x72,0x00,0x00,0x00, | |
340 | 0x20,0x00,0x00,0x00,0x73,0x00,0x00,0x00,0x70,0x00,0x00,0x00,0x61,0x00,0x00,0x00, | |
341 | 0x63,0x00,0x00,0x00,0x65,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x66,0x00,0x00,0x00, | |
342 | 0x6f,0x00,0x00,0x00,0x72,0x00,0x00,0x00,0x63,0x00,0x00,0x00,0x65,0x00,0x00,0x00, | |
343 | 0x2e,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x59,0x30,0x00,0x00, | |
344 | 0x50,0x30,0x00,0x00,0x66,0x8b,0x00,0x00,0xdf,0x5b,0x00,0x00,0x6b,0x30,0x00,0x00, | |
345 | 0xfb,0x96,0x00,0x00,0x71,0x8a,0x00,0x00,0x92,0x30,0x00,0x00,0x59,0x30,0x00,0x00, | |
346 | 0x8b,0x30,0x00,0x00,0x7b,0x30,0x00,0x00,0x46,0x30,0x00,0x00,0x4c,0x30,0x00,0x00, | |
347 | 0x44,0x30,0x00,0x00,0x44,0x30,0x00,0x00,0x67,0x30,0x00,0x00,0x59,0x30,0x00,0x00, | |
348 | 0x02,0x30,0x00,0x00 | |
349 | }; | |
350 | // encoded by iconv | |
78648f60 | 351 | const static unsigned char welcome_utf32be[212] = |
8f115891 MW |
352 | { |
353 | 0x00,0x00,0x00,0x57,0x00,0x00,0x00,0x65,0x00,0x00,0x00,0x6c,0x00,0x00,0x00,0x63, | |
354 | 0x00,0x00,0x00,0x6f,0x00,0x00,0x00,0x6d,0x00,0x00,0x00,0x65,0x00,0x00,0x00,0x20, | |
355 | 0x00,0x00,0x00,0x74,0x00,0x00,0x00,0x6f,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x6f, | |
356 | 0x00,0x00,0x00,0x75,0x00,0x00,0x00,0x72,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x63, | |
357 | 0x00,0x00,0x00,0x79,0x00,0x00,0x00,0x62,0x00,0x00,0x00,0x65,0x00,0x00,0x00,0x72, | |
358 | 0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x73,0x00,0x00,0x00,0x70,0x00,0x00,0x00,0x61, | |
359 | 0x00,0x00,0x00,0x63,0x00,0x00,0x00,0x65,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x66, | |
360 | 0x00,0x00,0x00,0x6f,0x00,0x00,0x00,0x72,0x00,0x00,0x00,0x63,0x00,0x00,0x00,0x65, | |
361 | 0x00,0x00,0x00,0x2e,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x20,0x00,0x00,0x30,0x59, | |
362 | 0x00,0x00,0x30,0x50,0x00,0x00,0x8b,0x66,0x00,0x00,0x5b,0xdf,0x00,0x00,0x30,0x6b, | |
363 | 0x00,0x00,0x96,0xfb,0x00,0x00,0x8a,0x71,0x00,0x00,0x30,0x92,0x00,0x00,0x30,0x59, | |
364 | 0x00,0x00,0x30,0x8b,0x00,0x00,0x30,0x7b,0x00,0x00,0x30,0x46,0x00,0x00,0x30,0x4c, | |
365 | 0x00,0x00,0x30,0x44,0x00,0x00,0x30,0x44,0x00,0x00,0x30,0x67,0x00,0x00,0x30,0x59, | |
366 | 0x00,0x00,0x30,0x02 | |
367 | }; | |
368 | // encoded by iconv | |
78648f60 | 369 | const static unsigned char welcome_cp932[71] = |
8f115891 MW |
370 | { |
371 | 0x57,0x65,0x6c,0x63,0x6f,0x6d,0x65,0x20,0x74,0x6f,0x20,0x6f,0x75,0x72,0x20,0x63, | |
372 | 0x79,0x62,0x65,0x72,0x20,0x73,0x70,0x61,0x63,0x65,0x20,0x66,0x6f,0x72,0x63,0x65, | |
373 | 0x2e,0x20,0x20,0x82,0xb7,0x82,0xae,0x8c,0x78,0x8e,0x40,0x82,0xc9,0x93,0x64,0x98, | |
374 | 0x62,0x82,0xf0,0x82,0xb7,0x82,0xe9,0x82,0xd9,0x82,0xa4,0x82,0xaa,0x82,0xa2,0x82, | |
375 | 0xa2,0x82,0xc5,0x82,0xb7,0x81,0x42 | |
376 | }; | |
377 | ||
378 | #if wxBYTE_ORDER == wxBIG_ENDIAN | |
379 | #if SIZEOF_WCHAR_T == 2 | |
380 | #define welcome_wchar_t welcome_utf16be | |
381 | #elif SIZEOF_WCHAR_T == 4 | |
382 | #define welcome_wchar_t welcome_utf32be | |
383 | #endif | |
384 | #elif wxBYTE_ORDER == wxLITTLE_ENDIAN | |
385 | #if SIZEOF_WCHAR_T == 2 | |
386 | #define welcome_wchar_t welcome_utf16le | |
387 | #elif SIZEOF_WCHAR_T == 4 | |
388 | #define welcome_wchar_t welcome_utf32le | |
389 | #endif | |
390 | #endif | |
391 | ||
392 | void MBConvTestCase::UTF7Tests() | |
393 | { | |
78648f60 VZ |
394 | #if 0 |
395 | wxCSConv convUTF7(wxFONTENCODING_UTF7); | |
396 | #else | |
397 | wxMBConvUTF7 convUTF7; | |
398 | #endif | |
399 | ||
8f115891 | 400 | TestDecoder |
78648f60 VZ |
401 | ( |
402 | (const wchar_t*)welcome_wchar_t, | |
8f115891 | 403 | sizeof(welcome_wchar_t)/sizeof(wchar_t), |
78648f60 VZ |
404 | (const char*)welcome_utf7_iconv, |
405 | sizeof(welcome_utf7_iconv), | |
406 | convUTF7, | |
8f115891 MW |
407 | 1 |
408 | ); | |
409 | TestDecoder | |
78648f60 VZ |
410 | ( |
411 | (const wchar_t*)welcome_wchar_t, | |
8f115891 | 412 | sizeof(welcome_wchar_t)/sizeof(wchar_t), |
78648f60 VZ |
413 | (const char*)welcome_utf7_wx, |
414 | sizeof(welcome_utf7_wx), | |
415 | convUTF7, | |
8f115891 MW |
416 | 1 |
417 | ); | |
78648f60 VZ |
418 | #if 0 |
419 | // wxWidget's UTF-7 encoder generates different byte sequences than iconv's. | |
8f115891 MW |
420 | // but both seem to be equally legal. |
421 | // This test won't work and that's okay. | |
422 | TestEncoder | |
78648f60 VZ |
423 | ( |
424 | (const wchar_t*)welcome_wchar_t, | |
8f115891 | 425 | sizeof(welcome_wchar_t)/sizeof(wchar_t), |
78648f60 VZ |
426 | (const char*)welcome_utf7_iconv, |
427 | sizeof(welcome_utf7_iconv), | |
428 | convUTF7, | |
8f115891 MW |
429 | 1 |
430 | ); | |
431 | #endif | |
432 | TestEncoder | |
78648f60 VZ |
433 | ( |
434 | (const wchar_t*)welcome_wchar_t, | |
8f115891 | 435 | sizeof(welcome_wchar_t)/sizeof(wchar_t), |
78648f60 VZ |
436 | (const char*)welcome_utf7_wx, |
437 | sizeof(welcome_utf7_wx), | |
438 | convUTF7, | |
8f115891 MW |
439 | 1 |
440 | ); | |
441 | } | |
442 | ||
443 | void MBConvTestCase::UTF8Tests() | |
444 | { | |
445 | TestDecoder | |
78648f60 VZ |
446 | ( |
447 | (const wchar_t*)welcome_wchar_t, | |
8f115891 | 448 | sizeof(welcome_wchar_t)/sizeof(wchar_t), |
78648f60 VZ |
449 | (const char*)welcome_utf8, |
450 | sizeof(welcome_utf8), | |
86501081 | 451 | wxConvUTF8, |
8f115891 MW |
452 | 1 |
453 | ); | |
454 | TestEncoder | |
78648f60 VZ |
455 | ( |
456 | (const wchar_t*)welcome_wchar_t, | |
8f115891 | 457 | sizeof(welcome_wchar_t)/sizeof(wchar_t), |
78648f60 VZ |
458 | (const char*)welcome_utf8, |
459 | sizeof(welcome_utf8), | |
86501081 | 460 | wxConvUTF8, |
8f115891 MW |
461 | 1 |
462 | ); | |
463 | } | |
464 | ||
465 | void MBConvTestCase::UTF16LETests() | |
466 | { | |
467 | wxMBConvUTF16LE convUTF16LE; | |
468 | TestDecoder | |
78648f60 VZ |
469 | ( |
470 | (const wchar_t*)welcome_wchar_t, | |
8f115891 | 471 | sizeof(welcome_wchar_t)/sizeof(wchar_t), |
78648f60 VZ |
472 | (const char*)welcome_utf16le, |
473 | sizeof(welcome_utf16le), | |
86501081 | 474 | convUTF16LE, |
8f115891 MW |
475 | 2 |
476 | ); | |
477 | TestEncoder | |
78648f60 VZ |
478 | ( |
479 | (const wchar_t*)welcome_wchar_t, | |
8f115891 | 480 | sizeof(welcome_wchar_t)/sizeof(wchar_t), |
78648f60 VZ |
481 | (const char*)welcome_utf16le, |
482 | sizeof(welcome_utf16le), | |
86501081 | 483 | convUTF16LE, |
8f115891 MW |
484 | 2 |
485 | ); | |
486 | } | |
487 | ||
488 | void MBConvTestCase::UTF16BETests() | |
489 | { | |
490 | wxMBConvUTF16BE convUTF16BE; | |
491 | TestDecoder | |
78648f60 VZ |
492 | ( |
493 | (const wchar_t*)welcome_wchar_t, | |
8f115891 | 494 | sizeof(welcome_wchar_t)/sizeof(wchar_t), |
78648f60 VZ |
495 | (const char*)welcome_utf16be, |
496 | sizeof(welcome_utf16be), | |
86501081 | 497 | convUTF16BE, |
8f115891 MW |
498 | 2 |
499 | ); | |
500 | TestEncoder | |
78648f60 VZ |
501 | ( |
502 | (const wchar_t*)welcome_wchar_t, | |
8f115891 | 503 | sizeof(welcome_wchar_t)/sizeof(wchar_t), |
78648f60 VZ |
504 | (const char*)welcome_utf16be, |
505 | sizeof(welcome_utf16be), | |
86501081 | 506 | convUTF16BE, |
8f115891 MW |
507 | 2 |
508 | ); | |
509 | } | |
510 | ||
511 | void MBConvTestCase::UTF32LETests() | |
512 | { | |
513 | wxMBConvUTF32LE convUTF32LE; | |
514 | TestDecoder | |
78648f60 VZ |
515 | ( |
516 | (const wchar_t*)welcome_wchar_t, | |
8f115891 | 517 | sizeof(welcome_wchar_t)/sizeof(wchar_t), |
78648f60 VZ |
518 | (const char*)welcome_utf32le, |
519 | sizeof(welcome_utf32le), | |
86501081 | 520 | convUTF32LE, |
8f115891 MW |
521 | 4 |
522 | ); | |
523 | TestEncoder | |
78648f60 VZ |
524 | ( |
525 | (const wchar_t*)welcome_wchar_t, | |
8f115891 | 526 | sizeof(welcome_wchar_t)/sizeof(wchar_t), |
78648f60 VZ |
527 | (const char*)welcome_utf32le, |
528 | sizeof(welcome_utf32le), | |
86501081 | 529 | convUTF32LE, |
8f115891 MW |
530 | 4 |
531 | ); | |
532 | } | |
533 | ||
534 | void MBConvTestCase::UTF32BETests() | |
535 | { | |
536 | wxMBConvUTF32BE convUTF32BE; | |
537 | TestDecoder | |
78648f60 VZ |
538 | ( |
539 | (const wchar_t*)welcome_wchar_t, | |
8f115891 | 540 | sizeof(welcome_wchar_t)/sizeof(wchar_t), |
78648f60 VZ |
541 | (const char*)welcome_utf32be, |
542 | sizeof(welcome_utf32be), | |
86501081 | 543 | convUTF32BE, |
8f115891 MW |
544 | 4 |
545 | ); | |
546 | TestEncoder | |
78648f60 VZ |
547 | ( |
548 | (const wchar_t*)welcome_wchar_t, | |
8f115891 | 549 | sizeof(welcome_wchar_t)/sizeof(wchar_t), |
78648f60 VZ |
550 | (const char*)welcome_utf32be, |
551 | sizeof(welcome_utf32be), | |
86501081 | 552 | convUTF32BE, |
8f115891 MW |
553 | 4 |
554 | ); | |
555 | } | |
556 | ||
557 | void MBConvTestCase::CP932Tests() | |
558 | { | |
559 | wxCSConv convCP932( wxFONTENCODING_CP932 ); | |
560 | TestDecoder | |
78648f60 VZ |
561 | ( |
562 | (const wchar_t*)welcome_wchar_t, | |
8f115891 | 563 | sizeof(welcome_wchar_t)/sizeof(wchar_t), |
78648f60 VZ |
564 | (const char*)welcome_cp932, |
565 | sizeof(welcome_cp932), | |
86501081 | 566 | convCP932, |
8f115891 MW |
567 | 1 |
568 | ); | |
569 | TestEncoder | |
78648f60 VZ |
570 | ( |
571 | (const wchar_t*)welcome_wchar_t, | |
8f115891 | 572 | sizeof(welcome_wchar_t)/sizeof(wchar_t), |
78648f60 VZ |
573 | (const char*)welcome_cp932, |
574 | sizeof(welcome_cp932), | |
86501081 | 575 | convCP932, |
8f115891 MW |
576 | 1 |
577 | ); | |
578 | } | |
579 | ||
580 | // a character sequence encoded as iso8859-1 (iconv) | |
78648f60 | 581 | static const unsigned char iso8859_1[251] = |
8f115891 MW |
582 | { |
583 | 0x05,0x06,0x07,0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f,0x10,0x11,0x12,0x13,0x14, | |
584 | 0x15,0x16,0x17,0x18,0x19,0x1a,0x1b,0x1c,0x1d,0x1e,0x1f,0x20,0x21,0x22,0x23,0x24, | |
585 | 0x25,0x26,0x27,0x28,0x29,0x2a,0x2b,0x2c,0x2d,0x2e,0x2f,0x30,0x31,0x32,0x33,0x34, | |
586 | 0x35,0x36,0x37,0x38,0x39,0x3a,0x3b,0x3c,0x3d,0x3e,0x3f,0x40,0x41,0x42,0x43,0x44, | |
587 | 0x45,0x46,0x47,0x48,0x49,0x4a,0x4b,0x4c,0x4d,0x4e,0x4f,0x50,0x51,0x52,0x53,0x54, | |
588 | 0x55,0x56,0x57,0x58,0x59,0x5a,0x5b,0x5c,0x5d,0x5e,0x5f,0x60,0x61,0x62,0x63,0x64, | |
589 | 0x65,0x66,0x67,0x68,0x69,0x6a,0x6b,0x6c,0x6d,0x6e,0x6f,0x70,0x71,0x72,0x73,0x74, | |
590 | 0x75,0x76,0x77,0x78,0x79,0x7a,0x7b,0x7c,0x7d,0x7e,0x7f,0x80,0x81,0x82,0x83,0x84, | |
591 | 0x85,0x86,0x87,0x88,0x89,0x8a,0x8b,0x8c,0x8d,0x8e,0x8f,0x90,0x91,0x92,0x93,0x94, | |
592 | 0x95,0x96,0x97,0x98,0x99,0x9a,0x9b,0x9c,0x9d,0x9e,0x9f,0xa0,0xa1,0xa2,0xa3,0xa4, | |
593 | 0xa5,0xa6,0xa7,0xa8,0xa9,0xaa,0xab,0xac,0xad,0xae,0xaf,0xb0,0xb1,0xb2,0xb3,0xb4, | |
594 | 0xb5,0xb6,0xb7,0xb8,0xb9,0xba,0xbb,0xbc,0xbd,0xbe,0xbf,0xc0,0xc1,0xc2,0xc3,0xc4, | |
595 | 0xc5,0xc6,0xc7,0xc8,0xc9,0xca,0xcb,0xcc,0xcd,0xce,0xcf,0xd0,0xd1,0xd2,0xd3,0xd4, | |
596 | 0xd5,0xd6,0xd7,0xd8,0xd9,0xda,0xdb,0xdc,0xdd,0xde,0xdf,0xe0,0xe1,0xe2,0xe3,0xe4, | |
597 | 0xe5,0xe6,0xe7,0xe8,0xe9,0xea,0xeb,0xec,0xed,0xee,0xef,0xf0,0xf1,0xf2,0xf3,0xf4, | |
598 | 0xf5,0xf6,0xf7,0xf8,0xf9,0xfa,0xfb,0xfc,0xfd,0xfe,0xff | |
599 | }; | |
600 | // the above character sequence encoded as UTF-8 (iconv) | |
78648f60 | 601 | static const unsigned char iso8859_1_utf8[379] = |
8f115891 MW |
602 | { |
603 | 0x05,0x06,0x07,0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f,0x10,0x11,0x12,0x13,0x14, | |
604 | 0x15,0x16,0x17,0x18,0x19,0x1a,0x1b,0x1c,0x1d,0x1e,0x1f,0x20,0x21,0x22,0x23,0x24, | |
605 | 0x25,0x26,0x27,0x28,0x29,0x2a,0x2b,0x2c,0x2d,0x2e,0x2f,0x30,0x31,0x32,0x33,0x34, | |
606 | 0x35,0x36,0x37,0x38,0x39,0x3a,0x3b,0x3c,0x3d,0x3e,0x3f,0x40,0x41,0x42,0x43,0x44, | |
607 | 0x45,0x46,0x47,0x48,0x49,0x4a,0x4b,0x4c,0x4d,0x4e,0x4f,0x50,0x51,0x52,0x53,0x54, | |
608 | 0x55,0x56,0x57,0x58,0x59,0x5a,0x5b,0x5c,0x5d,0x5e,0x5f,0x60,0x61,0x62,0x63,0x64, | |
609 | 0x65,0x66,0x67,0x68,0x69,0x6a,0x6b,0x6c,0x6d,0x6e,0x6f,0x70,0x71,0x72,0x73,0x74, | |
610 | 0x75,0x76,0x77,0x78,0x79,0x7a,0x7b,0x7c,0x7d,0x7e,0x7f,0xc2,0x80,0xc2,0x81,0xc2, | |
611 | 0x82,0xc2,0x83,0xc2,0x84,0xc2,0x85,0xc2,0x86,0xc2,0x87,0xc2,0x88,0xc2,0x89,0xc2, | |
612 | 0x8a,0xc2,0x8b,0xc2,0x8c,0xc2,0x8d,0xc2,0x8e,0xc2,0x8f,0xc2,0x90,0xc2,0x91,0xc2, | |
613 | 0x92,0xc2,0x93,0xc2,0x94,0xc2,0x95,0xc2,0x96,0xc2,0x97,0xc2,0x98,0xc2,0x99,0xc2, | |
614 | 0x9a,0xc2,0x9b,0xc2,0x9c,0xc2,0x9d,0xc2,0x9e,0xc2,0x9f,0xc2,0xa0,0xc2,0xa1,0xc2, | |
615 | 0xa2,0xc2,0xa3,0xc2,0xa4,0xc2,0xa5,0xc2,0xa6,0xc2,0xa7,0xc2,0xa8,0xc2,0xa9,0xc2, | |
616 | 0xaa,0xc2,0xab,0xc2,0xac,0xc2,0xad,0xc2,0xae,0xc2,0xaf,0xc2,0xb0,0xc2,0xb1,0xc2, | |
617 | 0xb2,0xc2,0xb3,0xc2,0xb4,0xc2,0xb5,0xc2,0xb6,0xc2,0xb7,0xc2,0xb8,0xc2,0xb9,0xc2, | |
618 | 0xba,0xc2,0xbb,0xc2,0xbc,0xc2,0xbd,0xc2,0xbe,0xc2,0xbf,0xc3,0x80,0xc3,0x81,0xc3, | |
619 | 0x82,0xc3,0x83,0xc3,0x84,0xc3,0x85,0xc3,0x86,0xc3,0x87,0xc3,0x88,0xc3,0x89,0xc3, | |
620 | 0x8a,0xc3,0x8b,0xc3,0x8c,0xc3,0x8d,0xc3,0x8e,0xc3,0x8f,0xc3,0x90,0xc3,0x91,0xc3, | |
621 | 0x92,0xc3,0x93,0xc3,0x94,0xc3,0x95,0xc3,0x96,0xc3,0x97,0xc3,0x98,0xc3,0x99,0xc3, | |
622 | 0x9a,0xc3,0x9b,0xc3,0x9c,0xc3,0x9d,0xc3,0x9e,0xc3,0x9f,0xc3,0xa0,0xc3,0xa1,0xc3, | |
623 | 0xa2,0xc3,0xa3,0xc3,0xa4,0xc3,0xa5,0xc3,0xa6,0xc3,0xa7,0xc3,0xa8,0xc3,0xa9,0xc3, | |
624 | 0xaa,0xc3,0xab,0xc3,0xac,0xc3,0xad,0xc3,0xae,0xc3,0xaf,0xc3,0xb0,0xc3,0xb1,0xc3, | |
625 | 0xb2,0xc3,0xb3,0xc3,0xb4,0xc3,0xb5,0xc3,0xb6,0xc3,0xb7,0xc3,0xb8,0xc3,0xb9,0xc3, | |
626 | 0xba,0xc3,0xbb,0xc3,0xbc,0xc3,0xbd,0xc3,0xbe,0xc3,0xbf | |
627 | }; | |
628 | ||
629 | // a character sequence encoded as CP1252 (iconv) | |
78648f60 | 630 | static const unsigned char CP1252[246] = |
8f115891 MW |
631 | { |
632 | 0x05,0x06,0x07,0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f,0x10,0x11,0x12,0x13,0x14, | |
633 | 0x15,0x16,0x17,0x18,0x19,0x1a,0x1b,0x1c,0x1d,0x1e,0x1f,0x20,0x21,0x22,0x23,0x24, | |
634 | 0x25,0x26,0x27,0x28,0x29,0x2a,0x2b,0x2c,0x2d,0x2e,0x2f,0x30,0x31,0x32,0x33,0x34, | |
635 | 0x35,0x36,0x37,0x38,0x39,0x3a,0x3b,0x3c,0x3d,0x3e,0x3f,0x40,0x41,0x42,0x43,0x44, | |
636 | 0x45,0x46,0x47,0x48,0x49,0x4a,0x4b,0x4c,0x4d,0x4e,0x4f,0x50,0x51,0x52,0x53,0x54, | |
637 | 0x55,0x56,0x57,0x58,0x59,0x5a,0x5b,0x5c,0x5d,0x5e,0x5f,0x60,0x61,0x62,0x63,0x64, | |
638 | 0x65,0x66,0x67,0x68,0x69,0x6a,0x6b,0x6c,0x6d,0x6e,0x6f,0x70,0x71,0x72,0x73,0x74, | |
639 | 0x75,0x76,0x77,0x78,0x79,0x7a,0x7b,0x7c,0x7d,0x7e,0x7f,0xa0,0xa1,0xa2,0xa3,0xa4, | |
640 | 0xa5,0xa6,0xa7,0xa8,0xa9,0xaa,0xab,0xac,0xad,0xae,0xaf,0xb0,0xb1,0xb2,0xb3,0xb4, | |
641 | 0xb5,0xb6,0xb7,0xb8,0xb9,0xba,0xbb,0xbc,0xbd,0xbe,0xbf,0xc0,0xc1,0xc2,0xc3,0xc4, | |
642 | 0xc5,0xc6,0xc7,0xc8,0xc9,0xca,0xcb,0xcc,0xcd,0xce,0xcf,0xd0,0xd1,0xd2,0xd3,0xd4, | |
643 | 0xd5,0xd6,0xd7,0xd8,0xd9,0xda,0xdb,0xdc,0xdd,0xde,0xdf,0xe0,0xe1,0xe2,0xe3,0xe4, | |
644 | 0xe5,0xe6,0xe7,0xe8,0xe9,0xea,0xeb,0xec,0xed,0xee,0xef,0xf0,0xf1,0xf2,0xf3,0xf4, | |
645 | 0xf5,0xf6,0xf7,0xf8,0xf9,0xfa,0xfb,0xfc,0xfd,0xfe,0xff,0x8c,0x9c,0x8a,0x9a,0x9f, | |
646 | 0x8e,0x9e,0x83,0x88,0x98,0x96,0x97,0x91,0x92,0x82,0x93,0x94,0x84,0x86,0x87,0x95, | |
647 | 0x85,0x89,0x8b,0x9b,0x80,0x99 | |
648 | }; | |
649 | // the above character sequence encoded as UTF-8 (iconv) | |
78648f60 | 650 | static const unsigned char CP1252_utf8[386] = |
8f115891 MW |
651 | { |
652 | 0x05,0x06,0x07,0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f,0x10,0x11,0x12,0x13,0x14, | |
653 | 0x15,0x16,0x17,0x18,0x19,0x1a,0x1b,0x1c,0x1d,0x1e,0x1f,0x20,0x21,0x22,0x23,0x24, | |
654 | 0x25,0x26,0x27,0x28,0x29,0x2a,0x2b,0x2c,0x2d,0x2e,0x2f,0x30,0x31,0x32,0x33,0x34, | |
655 | 0x35,0x36,0x37,0x38,0x39,0x3a,0x3b,0x3c,0x3d,0x3e,0x3f,0x40,0x41,0x42,0x43,0x44, | |
656 | 0x45,0x46,0x47,0x48,0x49,0x4a,0x4b,0x4c,0x4d,0x4e,0x4f,0x50,0x51,0x52,0x53,0x54, | |
657 | 0x55,0x56,0x57,0x58,0x59,0x5a,0x5b,0x5c,0x5d,0x5e,0x5f,0x60,0x61,0x62,0x63,0x64, | |
658 | 0x65,0x66,0x67,0x68,0x69,0x6a,0x6b,0x6c,0x6d,0x6e,0x6f,0x70,0x71,0x72,0x73,0x74, | |
659 | 0x75,0x76,0x77,0x78,0x79,0x7a,0x7b,0x7c,0x7d,0x7e,0x7f,0xc2,0xa0,0xc2,0xa1,0xc2, | |
660 | 0xa2,0xc2,0xa3,0xc2,0xa4,0xc2,0xa5,0xc2,0xa6,0xc2,0xa7,0xc2,0xa8,0xc2,0xa9,0xc2, | |
661 | 0xaa,0xc2,0xab,0xc2,0xac,0xc2,0xad,0xc2,0xae,0xc2,0xaf,0xc2,0xb0,0xc2,0xb1,0xc2, | |
662 | 0xb2,0xc2,0xb3,0xc2,0xb4,0xc2,0xb5,0xc2,0xb6,0xc2,0xb7,0xc2,0xb8,0xc2,0xb9,0xc2, | |
663 | 0xba,0xc2,0xbb,0xc2,0xbc,0xc2,0xbd,0xc2,0xbe,0xc2,0xbf,0xc3,0x80,0xc3,0x81,0xc3, | |
664 | 0x82,0xc3,0x83,0xc3,0x84,0xc3,0x85,0xc3,0x86,0xc3,0x87,0xc3,0x88,0xc3,0x89,0xc3, | |
665 | 0x8a,0xc3,0x8b,0xc3,0x8c,0xc3,0x8d,0xc3,0x8e,0xc3,0x8f,0xc3,0x90,0xc3,0x91,0xc3, | |
666 | 0x92,0xc3,0x93,0xc3,0x94,0xc3,0x95,0xc3,0x96,0xc3,0x97,0xc3,0x98,0xc3,0x99,0xc3, | |
667 | 0x9a,0xc3,0x9b,0xc3,0x9c,0xc3,0x9d,0xc3,0x9e,0xc3,0x9f,0xc3,0xa0,0xc3,0xa1,0xc3, | |
668 | 0xa2,0xc3,0xa3,0xc3,0xa4,0xc3,0xa5,0xc3,0xa6,0xc3,0xa7,0xc3,0xa8,0xc3,0xa9,0xc3, | |
669 | 0xaa,0xc3,0xab,0xc3,0xac,0xc3,0xad,0xc3,0xae,0xc3,0xaf,0xc3,0xb0,0xc3,0xb1,0xc3, | |
670 | 0xb2,0xc3,0xb3,0xc3,0xb4,0xc3,0xb5,0xc3,0xb6,0xc3,0xb7,0xc3,0xb8,0xc3,0xb9,0xc3, | |
671 | 0xba,0xc3,0xbb,0xc3,0xbc,0xc3,0xbd,0xc3,0xbe,0xc3,0xbf,0xc5,0x92,0xc5,0x93,0xc5, | |
672 | 0xa0,0xc5,0xa1,0xc5,0xb8,0xc5,0xbd,0xc5,0xbe,0xc6,0x92,0xcb,0x86,0xcb,0x9c,0xe2, | |
673 | 0x80,0x93,0xe2,0x80,0x94,0xe2,0x80,0x98,0xe2,0x80,0x99,0xe2,0x80,0x9a,0xe2,0x80, | |
674 | 0x9c,0xe2,0x80,0x9d,0xe2,0x80,0x9e,0xe2,0x80,0xa0,0xe2,0x80,0xa1,0xe2,0x80,0xa2, | |
675 | 0xe2,0x80,0xa6,0xe2,0x80,0xb0,0xe2,0x80,0xb9,0xe2,0x80,0xba,0xe2,0x82,0xac,0xe2, | |
676 | 0x84,0xa2 | |
677 | }; | |
678 | ||
679 | // a character sequence encoded as iso8859-5 (iconv) | |
78648f60 | 680 | static const unsigned char iso8859_5[251] = |
8f115891 MW |
681 | { |
682 | 0x05,0x06,0x07,0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f,0x10,0x11,0x12,0x13,0x14, | |
683 | 0x15,0x16,0x17,0x18,0x19,0x1a,0x1b,0x1c,0x1d,0x1e,0x1f,0x20,0x21,0x22,0x23,0x24, | |
684 | 0x25,0x26,0x27,0x28,0x29,0x2a,0x2b,0x2c,0x2d,0x2e,0x2f,0x30,0x31,0x32,0x33,0x34, | |
685 | 0x35,0x36,0x37,0x38,0x39,0x3a,0x3b,0x3c,0x3d,0x3e,0x3f,0x40,0x41,0x42,0x43,0x44, | |
686 | 0x45,0x46,0x47,0x48,0x49,0x4a,0x4b,0x4c,0x4d,0x4e,0x4f,0x50,0x51,0x52,0x53,0x54, | |
687 | 0x55,0x56,0x57,0x58,0x59,0x5a,0x5b,0x5c,0x5d,0x5e,0x5f,0x60,0x61,0x62,0x63,0x64, | |
688 | 0x65,0x66,0x67,0x68,0x69,0x6a,0x6b,0x6c,0x6d,0x6e,0x6f,0x70,0x71,0x72,0x73,0x74, | |
689 | 0x75,0x76,0x77,0x78,0x79,0x7a,0x7b,0x7c,0x7d,0x7e,0x7f,0x80,0x81,0x82,0x83,0x84, | |
690 | 0x85,0x86,0x87,0x88,0x89,0x8a,0x8b,0x8c,0x8d,0x8e,0x8f,0x90,0x91,0x92,0x93,0x94, | |
691 | 0x95,0x96,0x97,0x98,0x99,0x9a,0x9b,0x9c,0x9d,0x9e,0x9f,0xa0,0xfd,0xad,0xa1,0xa2, | |
692 | 0xa3,0xa4,0xa5,0xa6,0xa7,0xa8,0xa9,0xaa,0xab,0xac,0xae,0xaf,0xb0,0xb1,0xb2,0xb3, | |
693 | 0xb4,0xb5,0xb6,0xb7,0xb8,0xb9,0xba,0xbb,0xbc,0xbd,0xbe,0xbf,0xc0,0xc1,0xc2,0xc3, | |
694 | 0xc4,0xc5,0xc6,0xc7,0xc8,0xc9,0xca,0xcb,0xcc,0xcd,0xce,0xcf,0xd0,0xd1,0xd2,0xd3, | |
695 | 0xd4,0xd5,0xd6,0xd7,0xd8,0xd9,0xda,0xdb,0xdc,0xdd,0xde,0xdf,0xe0,0xe1,0xe2,0xe3, | |
696 | 0xe4,0xe5,0xe6,0xe7,0xe8,0xe9,0xea,0xeb,0xec,0xed,0xee,0xef,0xf1,0xf2,0xf3,0xf4, | |
697 | 0xf5,0xf6,0xf7,0xf8,0xf9,0xfa,0xfb,0xfc,0xfe,0xff,0xf0 | |
698 | }; | |
699 | // the above character sequence encoded as UTF-8 (iconv) | |
78648f60 | 700 | static const unsigned char iso8859_5_utf8[380] = |
8f115891 MW |
701 | { |
702 | 0x05,0x06,0x07,0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f,0x10,0x11,0x12,0x13,0x14, | |
703 | 0x15,0x16,0x17,0x18,0x19,0x1a,0x1b,0x1c,0x1d,0x1e,0x1f,0x20,0x21,0x22,0x23,0x24, | |
704 | 0x25,0x26,0x27,0x28,0x29,0x2a,0x2b,0x2c,0x2d,0x2e,0x2f,0x30,0x31,0x32,0x33,0x34, | |
705 | 0x35,0x36,0x37,0x38,0x39,0x3a,0x3b,0x3c,0x3d,0x3e,0x3f,0x40,0x41,0x42,0x43,0x44, | |
706 | 0x45,0x46,0x47,0x48,0x49,0x4a,0x4b,0x4c,0x4d,0x4e,0x4f,0x50,0x51,0x52,0x53,0x54, | |
707 | 0x55,0x56,0x57,0x58,0x59,0x5a,0x5b,0x5c,0x5d,0x5e,0x5f,0x60,0x61,0x62,0x63,0x64, | |
708 | 0x65,0x66,0x67,0x68,0x69,0x6a,0x6b,0x6c,0x6d,0x6e,0x6f,0x70,0x71,0x72,0x73,0x74, | |
709 | 0x75,0x76,0x77,0x78,0x79,0x7a,0x7b,0x7c,0x7d,0x7e,0x7f,0xc2,0x80,0xc2,0x81,0xc2, | |
710 | 0x82,0xc2,0x83,0xc2,0x84,0xc2,0x85,0xc2,0x86,0xc2,0x87,0xc2,0x88,0xc2,0x89,0xc2, | |
711 | 0x8a,0xc2,0x8b,0xc2,0x8c,0xc2,0x8d,0xc2,0x8e,0xc2,0x8f,0xc2,0x90,0xc2,0x91,0xc2, | |
712 | 0x92,0xc2,0x93,0xc2,0x94,0xc2,0x95,0xc2,0x96,0xc2,0x97,0xc2,0x98,0xc2,0x99,0xc2, | |
713 | 0x9a,0xc2,0x9b,0xc2,0x9c,0xc2,0x9d,0xc2,0x9e,0xc2,0x9f,0xc2,0xa0,0xc2,0xa7,0xc2, | |
714 | 0xad,0xd0,0x81,0xd0,0x82,0xd0,0x83,0xd0,0x84,0xd0,0x85,0xd0,0x86,0xd0,0x87,0xd0, | |
715 | 0x88,0xd0,0x89,0xd0,0x8a,0xd0,0x8b,0xd0,0x8c,0xd0,0x8e,0xd0,0x8f,0xd0,0x90,0xd0, | |
716 | 0x91,0xd0,0x92,0xd0,0x93,0xd0,0x94,0xd0,0x95,0xd0,0x96,0xd0,0x97,0xd0,0x98,0xd0, | |
717 | 0x99,0xd0,0x9a,0xd0,0x9b,0xd0,0x9c,0xd0,0x9d,0xd0,0x9e,0xd0,0x9f,0xd0,0xa0,0xd0, | |
718 | 0xa1,0xd0,0xa2,0xd0,0xa3,0xd0,0xa4,0xd0,0xa5,0xd0,0xa6,0xd0,0xa7,0xd0,0xa8,0xd0, | |
719 | 0xa9,0xd0,0xaa,0xd0,0xab,0xd0,0xac,0xd0,0xad,0xd0,0xae,0xd0,0xaf,0xd0,0xb0,0xd0, | |
720 | 0xb1,0xd0,0xb2,0xd0,0xb3,0xd0,0xb4,0xd0,0xb5,0xd0,0xb6,0xd0,0xb7,0xd0,0xb8,0xd0, | |
721 | 0xb9,0xd0,0xba,0xd0,0xbb,0xd0,0xbc,0xd0,0xbd,0xd0,0xbe,0xd0,0xbf,0xd1,0x80,0xd1, | |
722 | 0x81,0xd1,0x82,0xd1,0x83,0xd1,0x84,0xd1,0x85,0xd1,0x86,0xd1,0x87,0xd1,0x88,0xd1, | |
723 | 0x89,0xd1,0x8a,0xd1,0x8b,0xd1,0x8c,0xd1,0x8d,0xd1,0x8e,0xd1,0x8f,0xd1,0x91,0xd1, | |
724 | 0x92,0xd1,0x93,0xd1,0x94,0xd1,0x95,0xd1,0x96,0xd1,0x97,0xd1,0x98,0xd1,0x99,0xd1, | |
725 | 0x9a,0xd1,0x9b,0xd1,0x9c,0xd1,0x9e,0xd1,0x9f,0xe2,0x84,0x96 | |
726 | }; | |
727 | ||
728 | // DecodeUTF8 | |
729 | // decodes the specified *unterminated* UTF-8 byte array | |
730 | wxWCharBuffer DecodeUTF8( | |
731 | const void* data, // an unterminated UTF-8 encoded byte array | |
732 | size_t size // the byte length of data | |
733 | ) | |
734 | { | |
735 | // the decoder requires a null terminated buffer. | |
736 | // the input data is not null terminated. | |
737 | // copy to null terminated buffer | |
738 | ||
739 | wxCharBuffer nullTerminated( size+1 ); | |
740 | memcpy( nullTerminated.data(), data, size ); | |
741 | nullTerminated.data()[size] = 0; | |
742 | return wxConvUTF8.cMB2WC(nullTerminated.data()); | |
743 | } | |
744 | ||
745 | // tests the encoding and decoding capability of an wxMBConv object | |
746 | // | |
747 | // decodes the utf-8 bytes into wide characters | |
748 | // encodes the wide characters to compare against input multiBuffer | |
749 | // decodes the multiBuffer to compare against wide characters | |
750 | // decodes the multiBuffer into wide characters | |
751 | void MBConvTestCase::TestCoder( | |
752 | const char* multiBuffer, // a multibyte encoded character sequence that can be decoded by "converter" | |
753 | size_t multiBytes, // the byte length of the multibyte character sequence that can be decoded by "converter" | |
754 | const char* utf8Buffer, // the same character sequence as multiBuffer, encoded as UTF-8 | |
755 | size_t utf8Bytes, // the byte length of the UTF-8 encoded character sequence | |
86501081 | 756 | wxMBConv& converter, // the wxMBConv object thta can decode multiBuffer into a wide character sequence |
8f115891 MW |
757 | int sizeofNull // the number of bytes occupied by a terminating null in the converter's encoding |
758 | ) | |
759 | { | |
760 | // wide character size and endian-ess varies from platform to platform | |
761 | // compiler support for wide character literals varies from compiler to compiler | |
762 | // so we should store the wide character version as UTF-8 and depend on | |
763 | // the UTF-8 converter's ability to decode it to platform specific wide characters | |
764 | // this test is invalid if the UTF-8 converter can't decode | |
765 | wxWCharBuffer wideBuffer((size_t)0); | |
766 | wideBuffer = DecodeUTF8( utf8Buffer, utf8Bytes ); | |
767 | size_t wideChars = wxWcslen( wideBuffer.data() ); | |
768 | ||
769 | TestDecoder | |
78648f60 VZ |
770 | ( |
771 | wideBuffer.data(), | |
8f115891 | 772 | wideChars, |
78648f60 | 773 | (const char*)multiBuffer, |
8f115891 MW |
774 | multiBytes, |
775 | converter, | |
776 | sizeofNull | |
777 | ); | |
778 | TestEncoder | |
78648f60 VZ |
779 | ( |
780 | wideBuffer.data(), | |
8f115891 | 781 | wideChars, |
78648f60 | 782 | (const char*)multiBuffer, |
8f115891 MW |
783 | multiBytes, |
784 | converter, | |
785 | sizeofNull | |
786 | ); | |
787 | } | |
788 | ||
789 | ||
86501081 | 790 | WXDLLIMPEXP_BASE wxMBConv* new_wxMBConv_wxwin( const char* name ); |
8f115891 MW |
791 | |
792 | void MBConvTestCase::FontmapTests() | |
793 | { | |
794 | #ifdef wxUSE_FONTMAP | |
86501081 | 795 | wxMBConv* converter = new_wxMBConv_wxwin("CP1252"); |
8f115891 MW |
796 | if ( !converter ) |
797 | { | |
798 | return; | |
799 | } | |
800 | TestCoder( | |
801 | (const char*)CP1252, | |
802 | sizeof(CP1252), | |
803 | (const char*)CP1252_utf8, | |
804 | sizeof(CP1252_utf8), | |
86501081 | 805 | *converter, |
8f115891 MW |
806 | 1 |
807 | ); | |
808 | delete converter; | |
809 | #endif | |
810 | } | |
811 | ||
8a493b67 VZ |
812 | void MBConvTestCase::BufSize() |
813 | { | |
814 | wxCSConv conv1251(_T("CP1251")); | |
815 | CPPUNIT_ASSERT( conv1251.IsOk() ); | |
816 | const char *cp1251text = | |
817 | "\313\301\326\305\324\323\321 \325\304\301\336\316\331\315"; | |
8a493b67 | 818 | |
51725fc0 VZ |
819 | const size_t lenW = conv1251.MB2WC(NULL, cp1251text, 0); |
820 | CPPUNIT_ASSERT_EQUAL( strlen(cp1251text), lenW ); | |
821 | wxWCharBuffer wbuf(lenW + 1); // allocates lenW + 2 characters | |
822 | wbuf.data()[lenW + 1] = L'!'; | |
8a493b67 | 823 | |
51725fc0 | 824 | // lenW is not enough because it's the length and we need the size |
8a493b67 | 825 | CPPUNIT_ASSERT_EQUAL( |
51725fc0 | 826 | wxCONV_FAILED, conv1251.MB2WC(wbuf.data(), cp1251text, lenW) ); |
8a493b67 | 827 | |
51725fc0 | 828 | // lenW+1 is just fine |
8a493b67 | 829 | CPPUNIT_ASSERT( |
51725fc0 | 830 | conv1251.MB2WC(wbuf.data(), cp1251text, lenW + 1) != wxCONV_FAILED ); |
8a493b67 VZ |
831 | |
832 | // of course, greater values work too | |
833 | CPPUNIT_ASSERT( | |
51725fc0 VZ |
834 | conv1251.MB2WC(wbuf.data(), cp1251text, lenW + 2) != wxCONV_FAILED ); |
835 | ||
836 | // but they shouldn't write more stuff to the buffer | |
837 | CPPUNIT_ASSERT_EQUAL( L'!', wbuf[lenW + 1] ); | |
8a493b67 VZ |
838 | |
839 | ||
840 | // test in the other direction too, using an encoding with multibyte NUL | |
51725fc0 | 841 | wxCSConv convUTF16(_T("UTF-16LE")); |
8a493b67 VZ |
842 | CPPUNIT_ASSERT( convUTF16.IsOk() ); |
843 | const wchar_t *utf16text = L"Hello"; | |
8a493b67 | 844 | |
51725fc0 VZ |
845 | const size_t lenMB = convUTF16.WC2MB(NULL, utf16text, 0); |
846 | CPPUNIT_ASSERT_EQUAL( wcslen(utf16text)*2, lenMB ); | |
847 | wxCharBuffer buf(lenMB + 2); // it only adds 1 for NUL on its own, we need 2 | |
848 | // for NUL and an extra one for the guard byte | |
849 | buf.data()[lenMB + 2] = '?'; | |
8a493b67 VZ |
850 | |
851 | CPPUNIT_ASSERT_EQUAL( | |
51725fc0 VZ |
852 | wxCONV_FAILED, convUTF16.WC2MB(buf.data(), utf16text, lenMB) ); |
853 | CPPUNIT_ASSERT_EQUAL( | |
854 | wxCONV_FAILED, convUTF16.WC2MB(buf.data(), utf16text, lenMB + 1) ); | |
8a493b67 | 855 | CPPUNIT_ASSERT( |
51725fc0 | 856 | convUTF16.WC2MB(buf.data(), utf16text, lenMB + 2) != wxCONV_FAILED ); |
8a493b67 | 857 | CPPUNIT_ASSERT( |
51725fc0 VZ |
858 | convUTF16.WC2MB(buf.data(), utf16text, lenMB + 3) != wxCONV_FAILED ); |
859 | CPPUNIT_ASSERT_EQUAL( '?', buf[lenMB + 2] ); | |
8a493b67 VZ |
860 | } |
861 | ||
8f115891 | 862 | |
86501081 | 863 | WXDLLIMPEXP_BASE wxMBConv* new_wxMBConv_iconv( const char* name ); |
8f115891 MW |
864 | |
865 | void MBConvTestCase::IconvTests() | |
866 | { | |
867 | #ifdef HAVE_ICONV | |
86501081 | 868 | wxMBConv* converter = new_wxMBConv_iconv("CP932"); |
8f115891 MW |
869 | if ( !converter ) |
870 | { | |
871 | return; | |
872 | } | |
873 | TestCoder( | |
874 | (const char*)welcome_cp932, | |
875 | sizeof(welcome_cp932), | |
876 | (const char*)welcome_utf8, | |
877 | sizeof(welcome_utf8), | |
86501081 | 878 | *converter, |
8f115891 MW |
879 | 1 |
880 | ); | |
881 | delete converter; | |
882 | #endif | |
883 | } | |
884 | ||
fec42c21 VZ |
885 | void MBConvTestCase::Latin1Tests() |
886 | { | |
887 | TestCoder( | |
888 | (const char*)iso8859_1, | |
889 | sizeof(iso8859_1), | |
890 | (const char*)iso8859_1_utf8, | |
891 | sizeof(iso8859_1_utf8), | |
892 | wxConvISO8859_1, | |
893 | 1 | |
894 | ); | |
895 | ||
896 | static const char nulstr[] = "foo\0bar\0"; | |
897 | static const size_t mbLen = WXSIZEOF(nulstr) - 1; | |
898 | size_t wcLen; | |
899 | wxWCharBuffer wbuf(wxConvISO8859_1.cMB2WC(nulstr, mbLen, &wcLen)); | |
900 | CPPUNIT_ASSERT_EQUAL( mbLen, wcLen ); | |
901 | } | |
902 | ||
8f115891 MW |
903 | void MBConvTestCase::CP1252Tests() |
904 | { | |
905 | wxCSConv convCP1252( wxFONTENCODING_CP1252 ); | |
906 | TestCoder( | |
907 | (const char*)CP1252, | |
908 | sizeof(CP1252), | |
909 | (const char*)CP1252_utf8, | |
910 | sizeof(CP1252_utf8), | |
86501081 | 911 | convCP1252, |
8f115891 MW |
912 | 1 |
913 | ); | |
914 | } | |
915 | ||
916 | void MBConvTestCase::LibcTests() | |
917 | { | |
918 | // There isn't a locale that all systems support (except "C"), so leave | |
919 | // this one disabled for non-Windows systems for the moment, until | |
920 | // a solution can be found. | |
921 | #ifdef __WXMSW__ | |
922 | ||
923 | #ifdef __WXMSW__ | |
924 | setlocale( LC_ALL, "English_United States.1252" ); | |
925 | const unsigned char* systemMB = CP1252; | |
926 | size_t systemMB_size = sizeof(CP1252); | |
927 | const unsigned char* systemMB_utf8 = CP1252_utf8; | |
928 | size_t systemMB_utf8_size = sizeof(CP1252_utf8); | |
929 | #else | |
930 | setlocale( LC_ALL, "en_US.iso8859-1" ); | |
931 | const unsigned char* systemMB = iso8859_1; | |
932 | size_t systemMB_size = sizeof(iso8859_1); | |
933 | const unsigned char* systemMB_utf8 = iso8859_1_utf8; | |
934 | size_t systemMB_utf8_size = sizeof(iso8859_1_utf8); | |
935 | #endif | |
936 | wxMBConvLibc convLibc; | |
937 | TestCoder( | |
78648f60 | 938 | (const char*)systemMB, |
8f115891 | 939 | systemMB_size, |
78648f60 | 940 | (const char*)systemMB_utf8, |
8f115891 | 941 | systemMB_utf8_size, |
3af0741c | 942 | convLibc, |
8f115891 MW |
943 | 1 |
944 | ); | |
945 | ||
946 | #endif // __WXMSW__ | |
947 | } | |
948 | ||
949 | // verifies that the specified mb sequences decode to the specified wc sequence | |
950 | void MBConvTestCase::TestDecoder( | |
951 | const wchar_t* wideBuffer, // the same character sequence as multiBuffer, encoded as wchar_t | |
952 | size_t wideChars, // the number of wide characters at wideBuffer | |
953 | const char* multiBuffer, // a multibyte encoded character sequence that can be decoded by "converter" | |
954 | size_t multiBytes, // the byte length of the multibyte character sequence that can be decoded by "converter" | |
86501081 | 955 | wxMBConv& converter, // the wxMBConv object that can decode multiBuffer into a wide character sequence |
8f115891 MW |
956 | int sizeofNull // number of bytes occupied by terminating null in this encoding |
957 | ) | |
958 | { | |
959 | const unsigned UNINITIALIZED = 0xcd; | |
960 | ||
961 | // copy the input bytes into a null terminated buffer | |
962 | wxCharBuffer inputCopy( multiBytes+sizeofNull ); | |
963 | memcpy( inputCopy.data(), multiBuffer, multiBytes ); | |
964 | memset( &inputCopy.data()[multiBytes], 0, sizeofNull ); | |
965 | ||
966 | // calculate the output size | |
86501081 | 967 | size_t outputWritten = converter.MB2WC |
78648f60 VZ |
968 | ( |
969 | 0, | |
970 | (const char*)inputCopy.data(), | |
8f115891 MW |
971 | 0 |
972 | ); | |
973 | // make sure the correct output length was calculated | |
78648f60 | 974 | CPPUNIT_ASSERT_EQUAL( wideChars, outputWritten ); |
8f115891 MW |
975 | |
976 | // convert the string | |
977 | size_t guardChars = 8; // to make sure we're not overrunning the output buffer | |
978 | size_t nullCharacters = 1; | |
979 | size_t outputBufferChars = outputWritten + nullCharacters + guardChars; | |
980 | wxWCharBuffer outputBuffer(outputBufferChars); | |
981 | memset( outputBuffer.data(), UNINITIALIZED, outputBufferChars*sizeof(wchar_t) ); | |
982 | ||
86501081 | 983 | outputWritten = converter.MB2WC |
78648f60 VZ |
984 | ( |
985 | outputBuffer.data(), | |
986 | (const char*)inputCopy.data(), | |
8f115891 MW |
987 | outputBufferChars |
988 | ); | |
989 | // make sure the correct number of characters were outputs | |
78648f60 | 990 | CPPUNIT_ASSERT_EQUAL( wideChars, outputWritten ); |
8f115891 MW |
991 | |
992 | // make sure the characters generated are correct | |
993 | CPPUNIT_ASSERT( 0 == memcmp( outputBuffer, wideBuffer, wideChars*sizeof(wchar_t) ) ); | |
994 | ||
995 | // the output buffer should be null terminated | |
996 | CPPUNIT_ASSERT( outputBuffer[outputWritten] == 0 ); | |
997 | ||
998 | // make sure the rest of the output buffer is untouched | |
999 | for ( size_t i = (wideChars+1)*sizeof(wchar_t); i < (outputBufferChars*sizeof(wchar_t)); i++ ) | |
1000 | { | |
1001 | CPPUNIT_ASSERT( ((unsigned char*)outputBuffer.data())[i] == UNINITIALIZED ); | |
1002 | } | |
1003 | ||
1004 | #if wxUSE_UNICODE && wxUSE_STREAMS | |
1005 | TestStreamDecoder( wideBuffer, wideChars, multiBuffer, multiBytes, converter ); | |
1006 | #endif | |
1007 | } | |
1008 | ||
1009 | // verifies that the specified wc sequences encodes to the specified mb sequence | |
1010 | void MBConvTestCase::TestEncoder( | |
1011 | const wchar_t* wideBuffer, // the same character sequence as multiBuffer, encoded as wchar_t | |
1012 | size_t wideChars, // the number of wide characters at wideBuffer | |
1013 | const char* multiBuffer, // a multibyte encoded character sequence that can be decoded by "converter" | |
1014 | size_t multiBytes, // the byte length of the multibyte character sequence that can be decoded by "converter" | |
86501081 | 1015 | wxMBConv& converter, // the wxMBConv object that can decode multiBuffer into a wide character sequence |
8f115891 MW |
1016 | int sizeofNull // number of bytes occupied by terminating null in this encoding |
1017 | ) | |
1018 | { | |
1019 | const unsigned UNINITIALIZED = 0xcd; | |
1020 | ||
1021 | // copy the input bytes into a null terminated buffer | |
1022 | wxWCharBuffer inputCopy( wideChars + 1 ); | |
1023 | memcpy( inputCopy.data(), wideBuffer, (wideChars*sizeof(wchar_t)) ); | |
1024 | inputCopy.data()[wideChars] = 0; | |
1025 | ||
1026 | // calculate the output size | |
86501081 | 1027 | size_t outputWritten = converter.WC2MB |
78648f60 VZ |
1028 | ( |
1029 | 0, | |
1030 | (const wchar_t*)inputCopy.data(), | |
8f115891 MW |
1031 | 0 |
1032 | ); | |
1033 | // make sure the correct output length was calculated | |
78648f60 | 1034 | CPPUNIT_ASSERT_EQUAL( multiBytes, outputWritten ); |
8f115891 MW |
1035 | |
1036 | // convert the string | |
1037 | size_t guardBytes = 8; // to make sure we're not overrunning the output buffer | |
1038 | size_t outputBufferSize = outputWritten + sizeofNull + guardBytes; | |
1039 | wxCharBuffer outputBuffer(outputBufferSize); | |
1040 | memset( outputBuffer.data(), UNINITIALIZED, outputBufferSize ); | |
1041 | ||
86501081 | 1042 | outputWritten = converter.WC2MB |
78648f60 VZ |
1043 | ( |
1044 | outputBuffer.data(), | |
1045 | (const wchar_t*)inputCopy.data(), | |
1046 | outputBufferSize | |
8f115891 MW |
1047 | ); |
1048 | ||
1049 | // make sure the correct number of characters were output | |
78648f60 | 1050 | CPPUNIT_ASSERT_EQUAL( multiBytes, outputWritten ); |
8f115891 MW |
1051 | |
1052 | // make sure the characters generated are correct | |
1053 | CPPUNIT_ASSERT( 0 == memcmp( outputBuffer, multiBuffer, multiBytes ) ); | |
1054 | ||
6565d564 MW |
1055 | size_t i; |
1056 | ||
8f115891 | 1057 | // the output buffer should be null terminated |
6565d564 | 1058 | for ( i = multiBytes; i < multiBytes + sizeofNull; i++ ) |
8f115891 MW |
1059 | { |
1060 | CPPUNIT_ASSERT( ((unsigned char*)outputBuffer.data())[i] == 0 ); | |
1061 | } | |
1062 | ||
1063 | // make sure the rest of the output buffer is untouched | |
6565d564 | 1064 | for ( i = multiBytes + sizeofNull; i < outputBufferSize; i++ ) |
8f115891 MW |
1065 | { |
1066 | CPPUNIT_ASSERT( ((unsigned char*)outputBuffer.data())[i] == UNINITIALIZED ); | |
1067 | } | |
1068 | ||
1069 | #if wxUSE_UNICODE && wxUSE_STREAMS | |
1070 | TestStreamEncoder( wideBuffer, wideChars, multiBuffer, multiBytes, converter ); | |
1071 | #endif | |
1072 | } | |
1073 | ||
1074 | #if wxUSE_UNICODE && wxUSE_STREAMS | |
1075 | // use wxTextInputStream to exercise wxMBConv interface | |
1076 | // (this reveals some bugs in certain wxMBConv subclasses) | |
1077 | void MBConvTestCase::TestStreamDecoder( | |
1078 | const wchar_t* wideBuffer, // the same character sequence as multiBuffer, encoded as wchar_t | |
1079 | size_t wideChars, // the number of wide characters at wideBuffer | |
1080 | const char* multiBuffer, // a multibyte encoded character sequence that can be decoded by "converter" | |
1081 | size_t multiBytes, // the byte length of the multibyte character sequence that can be decoded by "converter" | |
86501081 | 1082 | wxMBConv& converter // the wxMBConv object that can decode multiBuffer into a wide character sequence |
8f115891 MW |
1083 | ) |
1084 | { | |
1085 | // this isn't meant to test wxMemoryInputStream or wxTextInputStream | |
1086 | // it's meant to test the way wxTextInputStream uses wxMBConv | |
1087 | // (which has exposed some problems with wxMBConv) | |
1088 | wxMemoryInputStream memoryInputStream( multiBuffer, multiBytes ); | |
86501081 | 1089 | wxTextInputStream textInputStream( memoryInputStream, wxT(""), converter ); |
8f115891 MW |
1090 | for ( size_t i = 0; i < wideChars; i++ ) |
1091 | { | |
1092 | wxChar wc = textInputStream.GetChar(); | |
04080f20 VZ |
1093 | CPPUNIT_ASSERT_EQUAL_MESSAGE( |
1094 | std::string(wxString::Format("At position %lu", (unsigned long)i)), | |
1095 | wideBuffer[i], | |
1096 | wc | |
1097 | ); | |
8f115891 MW |
1098 | } |
1099 | CPPUNIT_ASSERT( 0 == textInputStream.GetChar() ); | |
1100 | CPPUNIT_ASSERT( memoryInputStream.Eof() ); | |
1101 | } | |
1102 | #endif | |
1103 | ||
1104 | #if wxUSE_UNICODE && wxUSE_STREAMS | |
1105 | // use wxTextInputStream to exercise wxMBConv interface | |
1106 | // (this reveals some bugs in certain wxMBConv subclasses) | |
1107 | void MBConvTestCase::TestStreamEncoder( | |
1108 | const wchar_t* wideBuffer, // the same character sequence as multiBuffer, encoded as wchar_t | |
1109 | size_t wideChars, // the number of wide characters at wideBuffer | |
1110 | const char* multiBuffer, // a multibyte encoded character sequence that can be decoded by "converter" | |
1111 | size_t multiBytes, // the byte length of the multibyte character sequence that can be decoded by "converter" | |
86501081 | 1112 | wxMBConv& converter // the wxMBConv object that can decode multiBuffer into a wide character sequence |
8f115891 MW |
1113 | ) |
1114 | { | |
1115 | // this isn't meant to test wxMemoryOutputStream or wxTextOutputStream | |
1116 | // it's meant to test the way wxTextOutputStream uses wxMBConv | |
1117 | // (which has exposed some problems with wxMBConv) | |
1118 | wxMemoryOutputStream memoryOutputStream; | |
1119 | // wxEOL_UNIX will pass \n \r unchanged | |
86501081 | 1120 | wxTextOutputStream textOutputStream( memoryOutputStream, wxEOL_UNIX, converter ); |
8f115891 MW |
1121 | for ( size_t i = 0; i < wideChars; i++ ) |
1122 | { | |
1123 | textOutputStream.PutChar( wideBuffer[i] ); | |
1124 | } | |
ca8cf4ff VZ |
1125 | |
1126 | textOutputStream.Flush(); | |
1127 | ||
097a92e2 | 1128 | CPPUNIT_ASSERT_EQUAL( multiBytes, size_t(memoryOutputStream.TellO()) ); |
8f115891 MW |
1129 | wxCharBuffer copy( memoryOutputStream.TellO() ); |
1130 | memoryOutputStream.CopyTo( copy.data(), memoryOutputStream.TellO()); | |
4a9eae36 | 1131 | CPPUNIT_ASSERT_EQUAL( 0, memcmp( copy.data(), multiBuffer, multiBytes ) ); |
8f115891 MW |
1132 | } |
1133 | #endif | |
1134 | ||
1135 | ||
726c8204 MW |
1136 | // ---------------------------------------------------------------------------- |
1137 | // UTF-8 tests | |
1138 | // ---------------------------------------------------------------------------- | |
1139 | ||
1140 | #ifdef HAVE_WCHAR_H | |
1141 | ||
1142 | // Check that 'charSequence' translates to 'wideSequence' and back. | |
98cfeab3 | 1143 | // Invalid sequences can be tested by giving NULL for 'wideSequence'. Even |
726c8204 MW |
1144 | // invalid sequences should roundtrip when an option is given and this is |
1145 | // checked. | |
1146 | // | |
1147 | void MBConvTestCase::UTF8(const char *charSequence, | |
1148 | const wchar_t *wideSequence) | |
1149 | { | |
1150 | UTF8(charSequence, wideSequence, wxMBConvUTF8::MAP_INVALID_UTF8_NOT); | |
1151 | UTF8(charSequence, wideSequence, wxMBConvUTF8::MAP_INVALID_UTF8_TO_PUA); | |
1152 | UTF8(charSequence, wideSequence, wxMBConvUTF8::MAP_INVALID_UTF8_TO_OCTAL); | |
1153 | } | |
1154 | ||
1155 | // Use this alternative when 'charSequence' contains a PUA character. Such | |
1156 | // sequences should still roundtrip ok, and this is checked. | |
1157 | // | |
1158 | void MBConvTestCase::UTF8PUA(const char *charSequence, | |
1159 | const wchar_t *wideSequence) | |
1160 | { | |
1161 | UTF8(charSequence, wideSequence, wxMBConvUTF8::MAP_INVALID_UTF8_NOT); | |
1162 | UTF8(charSequence, NULL, wxMBConvUTF8::MAP_INVALID_UTF8_TO_PUA); | |
1163 | UTF8(charSequence, wideSequence, wxMBConvUTF8::MAP_INVALID_UTF8_TO_OCTAL); | |
1164 | } | |
1165 | ||
1166 | // Use this alternative when 'charSequence' contains an octal escape sequence. | |
1167 | // Such sequences should still roundtrip ok, and this is checked. | |
1168 | // | |
1169 | void MBConvTestCase::UTF8Octal(const char *charSequence, | |
1170 | const wchar_t *wideSequence) | |
1171 | { | |
1172 | UTF8(charSequence, wideSequence, wxMBConvUTF8::MAP_INVALID_UTF8_NOT); | |
1173 | UTF8(charSequence, wideSequence, wxMBConvUTF8::MAP_INVALID_UTF8_TO_PUA); | |
1174 | UTF8(charSequence, NULL, wxMBConvUTF8::MAP_INVALID_UTF8_TO_OCTAL); | |
1175 | } | |
1176 | ||
394579cf MW |
1177 | // in case wcscpy is missing |
1178 | // | |
1179 | static wchar_t *wx_wcscpy(wchar_t *dest, const wchar_t *src) | |
1180 | { | |
78648f60 | 1181 | wchar_t *d = dest; |
394579cf MW |
1182 | while ((*d++ = *src++) != 0) |
1183 | ; | |
1184 | return dest; | |
1185 | } | |
1186 | ||
1187 | // in case wcscat is missing | |
1188 | // | |
1189 | static wchar_t *wx_wcscat(wchar_t *dest, const wchar_t *src) | |
1190 | { | |
78648f60 | 1191 | wchar_t *d = dest; |
394579cf MW |
1192 | while (*d) |
1193 | d++; | |
1194 | while ((*d++ = *src++) != 0) | |
1195 | ; | |
1196 | return dest; | |
1197 | } | |
1198 | ||
c1ce4db1 MW |
1199 | // in case wcscmp is missing |
1200 | // | |
1201 | static int wx_wcscmp(const wchar_t *s1, const wchar_t *s2) | |
1202 | { | |
1203 | while (*s1 == *s2 && *s1 != 0) | |
1204 | { | |
1205 | s1++; | |
1206 | s2++; | |
1207 | } | |
1208 | return *s1 - *s2; | |
1209 | } | |
1210 | ||
1211 | // in case wcslen is missing | |
1212 | // | |
1213 | static size_t wx_wcslen(const wchar_t *s) | |
1214 | { | |
1215 | const wchar_t *t = s; | |
1216 | while (*t != 0) | |
1217 | t++; | |
1218 | return t - s; | |
1219 | } | |
1220 | ||
726c8204 MW |
1221 | // include the option in the error messages so it's possible to see which |
1222 | // test failed | |
1223 | #define UTF8ASSERT(expr) CPPUNIT_ASSERT_MESSAGE(#expr + errmsg, expr) | |
1224 | ||
1225 | // The test implementation | |
1226 | // | |
1227 | void MBConvTestCase::UTF8(const char *charSequence, | |
1228 | const wchar_t *wideSequence, | |
1229 | int option) | |
1230 | { | |
1231 | const size_t BUFSIZE = 128; | |
1232 | wxASSERT(strlen(charSequence) * 3 + 10 < BUFSIZE); | |
1233 | char bytes[BUFSIZE]; | |
78648f60 | 1234 | |
726c8204 MW |
1235 | // include the option in the error messages so it's possible to see |
1236 | // which test failed | |
1237 | sprintf(bytes, " (with option == %d)", option); | |
1238 | std::string errmsg(bytes); | |
78648f60 | 1239 | |
726c8204 MW |
1240 | // put the charSequence at the start, middle and end of a string |
1241 | strcpy(bytes, charSequence); | |
1242 | strcat(bytes, "ABC"); | |
1243 | strcat(bytes, charSequence); | |
1244 | strcat(bytes, "XYZ"); | |
1245 | strcat(bytes, charSequence); | |
1246 | ||
1247 | // translate it into wide characters | |
1248 | wxMBConvUTF8 utf8(option); | |
1249 | wchar_t widechars[BUFSIZE]; | |
98cfeab3 | 1250 | size_t lenResult = utf8.MB2WC(NULL, bytes, 0); |
726c8204 | 1251 | size_t result = utf8.MB2WC(widechars, bytes, BUFSIZE); |
98cfeab3 | 1252 | UTF8ASSERT(result == lenResult); |
726c8204 MW |
1253 | |
1254 | // check we got the expected result | |
1255 | if (wideSequence) { | |
1256 | UTF8ASSERT(result != (size_t)-1); | |
1257 | wxASSERT(result < BUFSIZE); | |
1258 | ||
1259 | wchar_t expected[BUFSIZE]; | |
394579cf MW |
1260 | wx_wcscpy(expected, wideSequence); |
1261 | wx_wcscat(expected, L"ABC"); | |
1262 | wx_wcscat(expected, wideSequence); | |
1263 | wx_wcscat(expected, L"XYZ"); | |
1264 | wx_wcscat(expected, wideSequence); | |
726c8204 | 1265 | |
c1ce4db1 MW |
1266 | UTF8ASSERT(wx_wcscmp(widechars, expected) == 0); |
1267 | UTF8ASSERT(wx_wcslen(widechars) == result); | |
726c8204 MW |
1268 | } |
1269 | else { | |
1270 | // If 'wideSequence' is NULL, then the result is expected to be | |
1271 | // invalid. Normally that is as far as we can go, but if there is an | |
1272 | // option then the conversion should succeed anyway, and it should be | |
1273 | // possible to translate back to the original | |
1274 | if (!option) { | |
1275 | UTF8ASSERT(result == (size_t)-1); | |
1276 | return; | |
1277 | } | |
1278 | else { | |
1279 | UTF8ASSERT(result != (size_t)-1); | |
1280 | } | |
1281 | } | |
1282 | ||
1283 | // translate it back and check we get the original | |
1284 | char bytesAgain[BUFSIZE]; | |
98cfeab3 | 1285 | size_t lenResultAgain = utf8.WC2MB(NULL, widechars, 0); |
726c8204 | 1286 | size_t resultAgain = utf8.WC2MB(bytesAgain, widechars, BUFSIZE); |
98cfeab3 | 1287 | UTF8ASSERT(resultAgain == lenResultAgain); |
726c8204 MW |
1288 | UTF8ASSERT(resultAgain != (size_t)-1); |
1289 | wxASSERT(resultAgain < BUFSIZE); | |
1290 | ||
1291 | UTF8ASSERT(strcmp(bytes, bytesAgain) == 0); | |
98cfeab3 | 1292 | UTF8ASSERT(strlen(bytesAgain) == resultAgain); |
726c8204 MW |
1293 | } |
1294 | ||
1295 | #endif // HAVE_WCHAR_H |