]>
Commit | Line | Data |
---|---|---|
387f829e VS |
1 | /////////////////////////////////////////////////////////////////////////////// |
2 | // Name: tests/strings/unicode.cpp | |
3 | // Purpose: Unicode unit test | |
4 | // Author: Vadim Zeitlin, Wlodzimierz ABX Skiba | |
5 | // Created: 2004-04-28 | |
6 | // RCS-ID: $Id$ | |
7 | // Copyright: (c) 2004 Vadim Zeitlin, Wlodzimierz Skiba | |
8 | /////////////////////////////////////////////////////////////////////////////// | |
9 | ||
10 | // ---------------------------------------------------------------------------- | |
11 | // headers | |
12 | // ---------------------------------------------------------------------------- | |
13 | ||
8899b155 | 14 | #include "testprec.h" |
387f829e VS |
15 | |
16 | #ifdef __BORLANDC__ | |
17 | #pragma hdrstop | |
18 | #endif | |
19 | ||
20 | #ifndef WX_PRECOMP | |
387f829e VS |
21 | #endif // WX_PRECOMP |
22 | ||
8da7a00a VZ |
23 | // ---------------------------------------------------------------------------- |
24 | // local functions | |
25 | // ---------------------------------------------------------------------------- | |
26 | ||
27 | #if wxUSE_WCHAR_T && !wxUSE_UNICODE | |
28 | ||
29 | // in case wcscmp is missing | |
30 | static int wx_wcscmp(const wchar_t *s1, const wchar_t *s2) | |
31 | { | |
32 | while (*s1 == *s2 && *s1 != 0) | |
33 | { | |
34 | s1++; | |
35 | s2++; | |
36 | } | |
37 | return *s1 - *s2; | |
38 | } | |
39 | ||
40 | #endif // wxUSE_WCHAR_T && !wxUSE_UNICODE | |
41 | ||
387f829e VS |
42 | // ---------------------------------------------------------------------------- |
43 | // test class | |
44 | // ---------------------------------------------------------------------------- | |
45 | ||
46 | class UnicodeTestCase : public CppUnit::TestCase | |
47 | { | |
48 | public: | |
49 | UnicodeTestCase(); | |
50 | ||
51 | private: | |
52 | CPPUNIT_TEST_SUITE( UnicodeTestCase ); | |
53 | CPPUNIT_TEST( ToFromAscii ); | |
a65ca3e6 VZ |
54 | #if wxUSE_WCHAR_T |
55 | CPPUNIT_TEST( ConstructorsWithConversion ); | |
85d3e5a9 | 56 | CPPUNIT_TEST( ConversionEmpty ); |
5975f198 | 57 | CPPUNIT_TEST( ConversionWithNULs ); |
a65ca3e6 VZ |
58 | CPPUNIT_TEST( ConversionUTF7 ); |
59 | CPPUNIT_TEST( ConversionUTF8 ); | |
5975f198 | 60 | CPPUNIT_TEST( ConversionUTF16 ); |
a7823b26 | 61 | CPPUNIT_TEST( ConversionUTF32 ); |
0f0298b1 | 62 | CPPUNIT_TEST( IsConvOk ); |
a65ca3e6 | 63 | #endif // wxUSE_WCHAR_T |
b0c4d5d7 VS |
64 | #if wxUSE_UNICODE |
65 | CPPUNIT_TEST( Iteration ); | |
66 | #endif | |
387f829e VS |
67 | CPPUNIT_TEST_SUITE_END(); |
68 | ||
69 | void ToFromAscii(); | |
a65ca3e6 VZ |
70 | #if wxUSE_WCHAR_T |
71 | void ConstructorsWithConversion(); | |
85d3e5a9 | 72 | void ConversionEmpty(); |
5975f198 | 73 | void ConversionWithNULs(); |
a65ca3e6 VZ |
74 | void ConversionUTF7(); |
75 | void ConversionUTF8(); | |
5975f198 | 76 | void ConversionUTF16(); |
a7823b26 | 77 | void ConversionUTF32(); |
0f0298b1 | 78 | void IsConvOk(); |
b0c4d5d7 VS |
79 | #if wxUSE_UNICODE |
80 | void Iteration(); | |
81 | #endif | |
a65ca3e6 VZ |
82 | |
83 | // test if converting s using the given encoding gives ws and vice versa | |
84 | // | |
85 | // if either of the first 2 arguments is NULL, the conversion is supposed | |
86 | // to fail | |
b0441359 | 87 | void DoTestConversion(const char *s, const wchar_t *w, wxMBConv& conv); |
a65ca3e6 VZ |
88 | #endif // wxUSE_WCHAR_T |
89 | ||
387f829e VS |
90 | |
91 | DECLARE_NO_COPY_CLASS(UnicodeTestCase) | |
92 | }; | |
93 | ||
94 | // register in the unnamed registry so that these tests are run by default | |
95 | CPPUNIT_TEST_SUITE_REGISTRATION( UnicodeTestCase ); | |
96 | ||
97 | // also include in it's own registry so that these tests can be run alone | |
81e9dec6 | 98 | CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( UnicodeTestCase, "UnicodeTestCase" ); |
387f829e VS |
99 | |
100 | UnicodeTestCase::UnicodeTestCase() | |
101 | { | |
102 | } | |
103 | ||
104 | void UnicodeTestCase::ToFromAscii() | |
105 | { | |
106 | ||
107 | #define TEST_TO_FROM_ASCII(txt) \ | |
108 | { \ | |
109 | static const char *msg = txt; \ | |
110 | wxString s = wxString::FromAscii(msg); \ | |
111 | CPPUNIT_ASSERT( strcmp( s.ToAscii() , msg ) == 0 ); \ | |
112 | } | |
113 | ||
114 | TEST_TO_FROM_ASCII( "Hello, world!" ); | |
115 | TEST_TO_FROM_ASCII( "additional \" special \t test \\ component \n :-)" ); | |
116 | } | |
117 | ||
a65ca3e6 VZ |
118 | #if wxUSE_WCHAR_T |
119 | void UnicodeTestCase::ConstructorsWithConversion() | |
120 | { | |
121 |