]>
Commit | Line | Data |
---|---|---|
c9f78968 VS |
1 | /////////////////////////////////////////////////////////////////////////////// |
2 | // Name: tests/strings/unichar.cpp | |
3 | // Purpose: Test for wxUniChar class | |
4 | // Author: Vaclav Slavik | |
5 | // Created: 2007-03-11 | |
6 | // RCS-ID: $Id$ | |
7 | // Copyright: (c) 2007 REA Elektronik GmbH | |
8 | // Licence: wxWindows licence | |
9 | /////////////////////////////////////////////////////////////////////////////// | |
10 | ||
11 | // ---------------------------------------------------------------------------- | |
12 | // headers | |
13 | // ---------------------------------------------------------------------------- | |
14 | ||
15 | #include "testprec.h" | |
16 | ||
17 | #ifdef __BORLANDC__ | |
18 | #pragma hdrstop | |
19 | #endif | |
20 | ||
21 | #ifndef WX_PRECOMP | |
22 | #include "wx/wx.h" | |
23 | #endif // WX_PRECOMP | |
24 | ||
25 | #include "wx/string.h" | |
26 | ||
27 | // ---------------------------------------------------------------------------- | |
28 | // test class | |
29 | // ---------------------------------------------------------------------------- | |
30 | ||
31 | class UniCharTestCase : public CppUnit::TestCase | |
32 | { | |
33 | public: | |
34 | UniCharTestCase() {} | |
35 | ||
36 | private: | |
37 | CPPUNIT_TEST_SUITE( UniCharTestCase ); | |
38 | CPPUNIT_TEST( CharCompare ); | |
39 | CPPUNIT_TEST( CharCompareIntl ); | |
40 | CPPUNIT_TEST( StringCompare ); | |
41 | CPPUNIT_TEST( StringCompareIntl ); | |
42 | CPPUNIT_TEST_SUITE_END(); | |
43 | ||
44 | void CharCompare(); | |
45 | void CharCompareIntl(); | |
46 | void StringCompare(); | |
47 | void StringCompareIntl(); | |
48 | ||
49 | DECLARE_NO_COPY_CLASS(UniCharTestCase) | |
50 | }; | |
51 | ||
52 | // register in the unnamed registry so that these tests are run by default | |
53 | CPPUNIT_TEST_SUITE_REGISTRATION( UniCharTestCase ); | |
54 | ||
55 | // also include in it's own registry so that these tests can be run alone | |
56 | CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( UniCharTestCase, "UniCharTestCase" ); | |
57 | ||
58 | void UniCharTestCase::CharCompare() | |
59 | { | |
60 | wxUniChar a('a'); | |
61 | wxUniChar b('b'); | |
62 | ||
63 | CPPUNIT_ASSERT( a == a ); | |
64 | CPPUNIT_ASSERT( a == 'a' ); | |
9a83f860 | 65 | CPPUNIT_ASSERT( a == wxT('a') ); |
c9f78968 | 66 | CPPUNIT_ASSERT( a == wxUniChar('a') ); |
9a83f860 | 67 | CPPUNIT_ASSERT( a == wxUniChar(wxT('a')) ); |
c9f78968 VS |
68 | |
69 | CPPUNIT_ASSERT( a != b ); | |
70 | CPPUNIT_ASSERT( a != 'b' ); | |
9a83f860 | 71 | CPPUNIT_ASSERT( a != wxT('b') ); |
c9f78968 | 72 | CPPUNIT_ASSERT( a != wxUniChar('b') ); |
9a83f860 | 73 | CPPUNIT_ASSERT( a != wxUniChar(wxT('b')) ); |
c9f78968 VS |
74 | |
75 | CPPUNIT_ASSERT( a < b ); | |
76 | CPPUNIT_ASSERT( a < 'b' ); | |
9a83f860 | 77 | CPPUNIT_ASSERT( a < wxT('b') ); |
c9f78968 | 78 | CPPUNIT_ASSERT( a < wxUniChar('b') ); |
9a83f860 | 79 | CPPUNIT_ASSERT( a < wxUniChar(wxT('b')) ); |
c9f78968 VS |
80 | |
81 | CPPUNIT_ASSERT( a <= b ); | |
82 | CPPUNIT_ASSERT( a <= 'b' ); | |
9a83f860 | 83 | CPPUNIT_ASSERT( a <= wxT('b') ); |
c9f78968 | 84 | CPPUNIT_ASSERT( a <= wxUniChar('b') ); |
9a83f860 | 85 | CPPUNIT_ASSERT( a <= wxUniChar(wxT('b')) ); |
c9f78968 VS |
86 | |
87 | CPPUNIT_ASSERT( a <= a ); | |
88 | CPPUNIT_ASSERT( a <= 'a' ); | |
9a83f860 | 89 | CPPUNIT_ASSERT( a <= wxT('a') ); |
c9f78968 | 90 | CPPUNIT_ASSERT( a <= wxUniChar('a') ); |
9a83f860 | 91 | CPPUNIT_ASSERT( a <= wxUniChar(wxT('a')) ); |
c9f78968 VS |
92 | |
93 | CPPUNIT_ASSERT( b > a ); | |
94 | CPPUNIT_ASSERT( b > 'a' ); | |
9a83f860 | 95 | CPPUNIT_ASSERT( b > wxT('a') ); |
c9f78968 | 96 | CPPUNIT_ASSERT( b > wxUniChar('a') ); |
9a83f860 | 97 | CPPUNIT_ASSERT( b > wxUniChar(wxT('a')) ); |
c9f78968 VS |
98 | |
99 | CPPUNIT_ASSERT( b >= a ); | |
100 | CPPUNIT_ASSERT( b >= 'a' ); | |
9a83f860 | 101 | CPPUNIT_ASSERT( b >= wxT('a') ); |
c9f78968 | 102 | CPPUNIT_ASSERT( b >= wxUniChar('a') ); |
9a83f860 | 103 | CPPUNIT_ASSERT( b >= wxUniChar(wxT('a')) ); |
c9f78968 VS |
104 | |
105 | CPPUNIT_ASSERT( b >= b ); | |
106 | CPPUNIT_ASSERT( b >= 'b' ); | |
9a83f860 | 107 | CPPUNIT_ASSERT( b >= wxT('b') ); |
c9f78968 | 108 | CPPUNIT_ASSERT( b >= wxUniChar('b') ); |
9a83f860 | 109 | CPPUNIT_ASSERT( b >= wxUniChar(wxT('b')) ); |
c9f78968 VS |
110 | |
111 | CPPUNIT_ASSERT( b - a == 1 ); | |
112 | CPPUNIT_ASSERT( a - b == -1 ); | |
113 | } | |
114 | ||
115 | ||
116 | #define CYRILLIC_SMALL_LETTER_YU ((wchar_t)0x044E) | |
117 | #define ARABIC_LETTER_NOON ((wchar_t)0x0646) | |
118 | ||
119 | void UniCharTestCase::CharCompareIntl() | |
120 | { | |
121 | wxUniChar a(CYRILLIC_SMALL_LETTER_YU); | |
122 | wxUniChar b(ARABIC_LETTER_NOON); | |
123 | ||
124 | CPPUNIT_ASSERT( a == a ); | |
125 | CPPUNIT_ASSERT( a == CYRILLIC_SMALL_LETTER_YU ); | |
126 | CPPUNIT_ASSERT( a == wxUniChar(CYRILLIC_SMALL_LETTER_YU) ); | |
127 | ||
128 | CPPUNIT_ASSERT( a != b ); | |
129 | CPPUNIT_ASSERT( a != ARABIC_LETTER_NOON ); | |
130 | CPPUNIT_ASSERT( a != wxUniChar(ARABIC_LETTER_NOON) ); | |
131 | ||
132 | CPPUNIT_ASSERT( a < b ); | |
133 | CPPUNIT_ASSERT( a < ARABIC_LETTER_NOON ); | |
134 | CPPUNIT_ASSERT( a < wxUniChar(ARABIC_LETTER_NOON) ); | |
135 | ||
136 | CPPUNIT_ASSERT( a <= b ); | |
137 | CPPUNIT_ASSERT( a <= ARABIC_LETTER_NOON ); | |
138 | CPPUNIT_ASSERT( a <= wxUniChar(ARABIC_LETTER_NOON) ); | |
139 | ||
140 | CPPUNIT_ASSERT( a <= a ); | |
141 | CPPUNIT_ASSERT( a <= CYRILLIC_SMALL_LETTER_YU ); | |
142 | CPPUNIT_ASSERT( a <= wxUniChar(CYRILLIC_SMALL_LETTER_YU) ); | |
143 | ||
144 | CPPUNIT_ASSERT( b > a ); | |
145 | CPPUNIT_ASSERT( b > CYRILLIC_SMALL_LETTER_YU ); | |
146 | CPPUNIT_ASSERT( b > wxUniChar(CYRILLIC_SMALL_LETTER_YU) ); | |
147 | ||
148 | CPPUNIT_ASSERT( b >= a ); | |
149 | CPPUNIT_ASSERT( b >= CYRILLIC_SMALL_LETTER_YU ); | |
150 | CPPUNIT_ASSERT( b >= wxUniChar(CYRILLIC_SMALL_LETTER_YU) ); | |
151 | ||
152 | CPPUNIT_ASSERT( b >= b ); | |
153 | CPPUNIT_ASSERT( b >= ARABIC_LETTER_NOON ); | |
154 | CPPUNIT_ASSERT( b >= wxUniChar(ARABIC_LETTER_NOON) ); | |
155 | ||
156 | CPPUNIT_ASSERT( b - a == 504 ); | |
157 | CPPUNIT_ASSERT( a - b == -504 ); | |
158 | } | |
159 | ||
160 | void UniCharTestCase::StringCompare() | |
161 | { | |
162 | // test string comparison with chars | |
163 | wxString sa = "a"; | |
164 | const wxString sb = "b"; | |
165 | char c1 = 'a'; | |
9a83f860 | 166 | wchar_t c2 = wxT('a'); |
c9f78968 VS |
167 | wxUniChar c3 = 'a'; |
168 | ||
169 | CPPUNIT_ASSERT( sa == 'a'); | |
170 | CPPUNIT_ASSERT( 'a' == sa); | |
171 | CPPUNIT_ASSERT( sb != 'a'); | |
172 | CPPUNIT_ASSERT( 'a' != sb); | |
173 | ||
174 | CPPUNIT_ASSERT( sa == c1); | |
175 | CPPUNIT_ASSERT( c1 == sa); | |
176 | CPPUNIT_ASSERT( sb != c1); | |
177 | CPPUNIT_ASSERT( c1 != sb); | |
178 | ||
179 | CPPUNIT_ASSERT( sa == c2); | |
180 | CPPUNIT_ASSERT( c2 == sa); | |
181 | CPPUNIT_ASSERT( sb != c2); | |
182 | CPPUNIT_ASSERT( c2 != sb); | |
183 | ||
184 | CPPUNIT_ASSERT( sa == c3); | |
185 | CPPUNIT_ASSERT( c3 == sa); | |
186 | CPPUNIT_ASSERT( sb != c3); | |
187 | CPPUNIT_ASSERT( c3 != sb); | |
188 | ||
189 | // test wxUniCharRef: | |
190 | CPPUNIT_ASSERT( sa == sa[0]); | |
191 | CPPUNIT_ASSERT( sa[0] == sa); | |
192 | CPPUNIT_ASSERT( sb != sa[0]); | |
193 | CPPUNIT_ASSERT( sa[0] != sb); | |
194 | ||
195 | // test const version of operator[] (returns wxUniChar, not wxUniCharRef): | |
196 | CPPUNIT_ASSERT( sb == sb[0]); | |
197 | CPPUNIT_ASSERT( sb[0] == sb); | |
198 | CPPUNIT_ASSERT( sa != sb[0]); | |
199 | CPPUNIT_ASSERT( sb[0] != sa); | |
200 | } | |
201 | ||
202 | void UniCharTestCase::StringCompareIntl() | |
203 | { | |
204 | // test string comparison with chars | |
205 | wxString sa = CYRILLIC_SMALL_LETTER_YU; | |
206 | const wxString sb = ARABIC_LETTER_NOON; | |
207 | wchar_t c2 = CYRILLIC_SMALL_LETTER_YU; | |
208 | wxUniChar c3 = CYRILLIC_SMALL_LETTER_YU; | |
209 | ||
210 | CPPUNIT_ASSERT( sa == CYRILLIC_SMALL_LETTER_YU); | |
211 | CPPUNIT_ASSERT( CYRILLIC_SMALL_LETTER_YU == sa); | |
212 | CPPUNIT_ASSERT( sb != CYRILLIC_SMALL_LETTER_YU); | |
213 | CPPUNIT_ASSERT( CYRILLIC_SMALL_LETTER_YU != sb); | |
214 | ||
215 | CPPUNIT_ASSERT( sa == c2); | |
216 | CPPUNIT_ASSERT( c2 == sa); | |
217 | CPPUNIT_ASSERT( sb != c2); | |
218 | CPPUNIT_ASSERT( c2 != sb); | |
219 | ||
220 | CPPUNIT_ASSERT( sa == c3); | |
221 | CPPUNIT_ASSERT( c3 == sa); | |
222 | CPPUNIT_ASSERT( sb != c3); | |
223 | CPPUNIT_ASSERT( c3 != sb); | |
224 | ||
225 | // test wxUniCharRef: | |
226 | CPPUNIT_ASSERT( sa == sa[0]); | |
227 | CPPUNIT_ASSERT( sa[0] == sa); | |
228 | CPPUNIT_ASSERT( sb != sa[0]); | |
229 | CPPUNIT_ASSERT( sa[0] != sb); | |
230 | ||
231 | // test const version of operator[] (returns wxUniChar, not wxUniCharRef): | |
232 | CPPUNIT_ASSERT( sb == sb[0]); | |
233 | CPPUNIT_ASSERT( sb[0] == sb); | |
234 | CPPUNIT_ASSERT( sa != sb[0]); | |
235 | CPPUNIT_ASSERT( sb[0] != sa); | |
236 | } |