]>
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 |
387f829e VS |
64 | CPPUNIT_TEST_SUITE_END(); |
65 | ||
66 | void ToFromAscii(); | |
a65ca3e6 VZ |
67 | #if wxUSE_WCHAR_T |
68 | void ConstructorsWithConversion(); | |
85d3e5a9 | 69 | void ConversionEmpty(); |
5975f198 | 70 | void ConversionWithNULs(); |
a65ca3e6 VZ |
71 | void ConversionUTF7(); |
72 | void ConversionUTF8(); | |
5975f198 | 73 | void ConversionUTF16(); |
a7823b26 | 74 | void ConversionUTF32(); |
0f0298b1 | 75 | void IsConvOk(); |
a65ca3e6 VZ |
76 | |
77 | // test if converting s using the given encoding gives ws and vice versa | |
78 | // | |
79 | // if either of the first 2 arguments is NULL, the conversion is supposed | |
80 | // to fail | |
b0441359 | 81 | void DoTestConversion(const char *s, const wchar_t *w, wxMBConv& conv); |
a65ca3e6 VZ |
82 | #endif // wxUSE_WCHAR_T |
83 | ||
387f829e VS |
84 | |
85 | DECLARE_NO_COPY_CLASS(UnicodeTestCase) | |
86 | }; | |
87 | ||
88 | // register in the unnamed registry so that these tests are run by default | |
89 | CPPUNIT_TEST_SUITE_REGISTRATION( UnicodeTestCase ); | |
90 | ||
91 | // also include in it's own registry so that these tests can be run alone | |
1fc9e0d3 | 92 | CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( UnicodeTestCase, "Unicode" ); |
387f829e VS |
93 | |
94 | UnicodeTestCase::UnicodeTestCase() | |
95 | { | |
96 | } | |
97 | ||
98 | void UnicodeTestCase::ToFromAscii() | |
99 | { | |
100 | ||
101 | #define TEST_TO_FROM_ASCII(txt) \ | |
102 | { \ | |
103 | static const char *msg = txt; \ | |
104 | wxString s = wxString::FromAscii(msg); \ | |
105 | CPPUNIT_ASSERT( strcmp( s.ToAscii() , msg ) == 0 ); \ | |
106 | } | |
107 | ||
108 | TEST_TO_FROM_ASCII( "Hello, world!" ); | |
109 | TEST_TO_FROM_ASCII( "additional \" special \t test \\ component \n :-)" ); | |
110 | } | |
111 | ||
a65ca3e6 VZ |
112 | #if wxUSE_WCHAR_T |
113 | void UnicodeTestCase::ConstructorsWithConversion() | |
114 | { | |
115 |