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