]> git.saurik.com Git - wxWidgets.git/blob - tests/strings/unichar.cpp
Really fix hit testing in the generic wxDataViewToggleRenderer.
[wxWidgets.git] / tests / strings / unichar.cpp
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 #if wxUSE_UNICODE
42 CPPUNIT_TEST( StringCompareIntl );
43 #endif // wxUSE_UNICODE
44 CPPUNIT_TEST_SUITE_END();
45
46 void CharCompare();
47 void CharCompareIntl();
48 void StringCompare();
49 void StringCompareIntl();
50
51 DECLARE_NO_COPY_CLASS(UniCharTestCase)
52 };
53
54 // register in the unnamed registry so that these tests are run by default
55 CPPUNIT_TEST_SUITE_REGISTRATION( UniCharTestCase );
56
57 // also include in its own registry so that these tests can be run alone
58 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( UniCharTestCase, "UniCharTestCase" );
59
60 void UniCharTestCase::CharCompare()
61 {
62 wxUniChar a('a');
63 wxUniChar b('b');
64
65 CPPUNIT_ASSERT( a == a );
66 CPPUNIT_ASSERT( a == 'a' );
67 CPPUNIT_ASSERT( a == wxT('a') );
68 CPPUNIT_ASSERT( a == wxUniChar('a') );
69 CPPUNIT_ASSERT( a == wxUniChar(wxT('a')) );
70
71 CPPUNIT_ASSERT( a == a );
72 CPPUNIT_ASSERT( 'a' == a );
73 CPPUNIT_ASSERT( wxT('a') == a );
74 CPPUNIT_ASSERT( wxUniChar('a') == a );
75 CPPUNIT_ASSERT( wxUniChar(wxT('a')) == a );
76
77 CPPUNIT_ASSERT( a != b );
78 CPPUNIT_ASSERT( a != 'b' );
79 CPPUNIT_ASSERT( a != wxT('b') );
80 CPPUNIT_ASSERT( a != wxUniChar('b') );
81 CPPUNIT_ASSERT( a != wxUniChar(wxT('b')) );
82
83 CPPUNIT_ASSERT( b != a );
84 CPPUNIT_ASSERT( 'b' != a );
85 CPPUNIT_ASSERT( wxT('b') != a );
86 CPPUNIT_ASSERT( wxUniChar('b') != a );
87 CPPUNIT_ASSERT( wxUniChar(wxT('b')) != a );
88
89 CPPUNIT_ASSERT( a < b );
90 CPPUNIT_ASSERT( a < 'b' );
91 CPPUNIT_ASSERT( a < wxT('b') );
92 CPPUNIT_ASSERT( a < wxUniChar('b') );
93 CPPUNIT_ASSERT( a < wxUniChar(wxT('b')) );
94
95 CPPUNIT_ASSERT( b > a );
96 CPPUNIT_ASSERT( 'b' > a );
97 CPPUNIT_ASSERT( wxT('b') > a );
98 CPPUNIT_ASSERT( wxUniChar('b') > a );
99 CPPUNIT_ASSERT( wxUniChar(wxT('b')) > a );
100
101 CPPUNIT_ASSERT( a <= b );
102 CPPUNIT_ASSERT( a <= 'b' );
103 CPPUNIT_ASSERT( a <= wxT('b') );
104 CPPUNIT_ASSERT( a <= wxUniChar('b') );
105 CPPUNIT_ASSERT( a <= wxUniChar(wxT('b')) );
106
107 CPPUNIT_ASSERT( b >= a );
108 CPPUNIT_ASSERT( 'b' >= a );
109 CPPUNIT_ASSERT( wxT('b') >= a );
110 CPPUNIT_ASSERT( wxUniChar('b') >= a );
111 CPPUNIT_ASSERT( wxUniChar(wxT('b')) >= a );
112
113 CPPUNIT_ASSERT( a <= a );
114 CPPUNIT_ASSERT( a <= 'a' );
115 CPPUNIT_ASSERT( a <= wxT('a') );
116 CPPUNIT_ASSERT( a <= wxUniChar('a') );
117 CPPUNIT_ASSERT( a <= wxUniChar(wxT('a')) );
118
119 CPPUNIT_ASSERT( a >= a );
120 CPPUNIT_ASSERT( 'a' >= a );
121 CPPUNIT_ASSERT( wxT('a') >= a );
122 CPPUNIT_ASSERT( wxUniChar('a') >= a );
123 CPPUNIT_ASSERT( wxUniChar(wxT('a')) >= a );
124
125 CPPUNIT_ASSERT( b > a );
126 CPPUNIT_ASSERT( b > 'a' );
127 CPPUNIT_ASSERT( b > wxT('a') );
128 CPPUNIT_ASSERT( b > wxUniChar('a') );
129 CPPUNIT_ASSERT( b > wxUniChar(wxT('a')) );
130
131 CPPUNIT_ASSERT( a < b );
132 CPPUNIT_ASSERT( 'a' < b );
133 CPPUNIT_ASSERT( wxT('a') < b );
134 CPPUNIT_ASSERT( wxUniChar('a') < b );
135 CPPUNIT_ASSERT( wxUniChar(wxT('a')) < b );
136
137 CPPUNIT_ASSERT( b >= a );
138 CPPUNIT_ASSERT( b >= 'a' );
139 CPPUNIT_ASSERT( b >= wxT('a') );
140 CPPUNIT_ASSERT( b >= wxUniChar('a') );
141 CPPUNIT_ASSERT( b >= wxUniChar(wxT('a')) );
142
143 CPPUNIT_ASSERT( a <= b );
144 CPPUNIT_ASSERT( 'a' <= b );
145 CPPUNIT_ASSERT( wxT('a') <= b );
146 CPPUNIT_ASSERT( wxUniChar('a') <= b );
147 CPPUNIT_ASSERT( wxUniChar(wxT('a')) <= b );
148
149 CPPUNIT_ASSERT( b >= b );
150 CPPUNIT_ASSERT( b >= 'b' );
151 CPPUNIT_ASSERT( b >= wxT('b') );
152 CPPUNIT_ASSERT( b >= wxUniChar('b') );
153 CPPUNIT_ASSERT( b >= wxUniChar(wxT('b')) );
154
155 CPPUNIT_ASSERT( b <= b );
156 CPPUNIT_ASSERT( 'b' <= b );
157 CPPUNIT_ASSERT( wxT('b') <= b );
158 CPPUNIT_ASSERT( wxUniChar('b') <= b );
159 CPPUNIT_ASSERT( wxUniChar(wxT('b')) <= b );
160
161 CPPUNIT_ASSERT( b - a == 1 );
162 CPPUNIT_ASSERT( a - b == -1 );
163 }
164
165
166 #define CYRILLIC_SMALL_LETTER_YU ((wchar_t)0x044E)
167 #define ARABIC_LETTER_NOON ((wchar_t)0x0646)
168
169 void UniCharTestCase::CharCompareIntl()
170 {
171 wxUniChar a(CYRILLIC_SMALL_LETTER_YU);
172 wxUniChar b(ARABIC_LETTER_NOON);
173
174 CPPUNIT_ASSERT( a == a );
175 CPPUNIT_ASSERT( a == CYRILLIC_SMALL_LETTER_YU );
176 CPPUNIT_ASSERT( a == wxUniChar(CYRILLIC_SMALL_LETTER_YU) );
177
178 CPPUNIT_ASSERT( a != b );
179 CPPUNIT_ASSERT( a != ARABIC_LETTER_NOON );
180 CPPUNIT_ASSERT( a != wxUniChar(ARABIC_LETTER_NOON) );
181
182 CPPUNIT_ASSERT( a < b );
183 CPPUNIT_ASSERT( a < ARABIC_LETTER_NOON );
184 CPPUNIT_ASSERT( a < wxUniChar(ARABIC_LETTER_NOON) );
185
186 CPPUNIT_ASSERT( a <= b );
187 CPPUNIT_ASSERT( a <= ARABIC_LETTER_NOON );
188 CPPUNIT_ASSERT( a <= wxUniChar(ARABIC_LETTER_NOON) );
189
190 CPPUNIT_ASSERT( a <= a );
191 CPPUNIT_ASSERT( a <= CYRILLIC_SMALL_LETTER_YU );
192 CPPUNIT_ASSERT( a <= wxUniChar(CYRILLIC_SMALL_LETTER_YU) );
193
194 CPPUNIT_ASSERT( b > a );
195 CPPUNIT_ASSERT( b > CYRILLIC_SMALL_LETTER_YU );
196 CPPUNIT_ASSERT( b > wxUniChar(CYRILLIC_SMALL_LETTER_YU) );
197
198 CPPUNIT_ASSERT( b >= a );
199 CPPUNIT_ASSERT( b >= CYRILLIC_SMALL_LETTER_YU );
200 CPPUNIT_ASSERT( b >= wxUniChar(CYRILLIC_SMALL_LETTER_YU) );
201
202 CPPUNIT_ASSERT( b >= b );
203 CPPUNIT_ASSERT( b >= ARABIC_LETTER_NOON );
204 CPPUNIT_ASSERT( b >= wxUniChar(ARABIC_LETTER_NOON) );
205
206 CPPUNIT_ASSERT( b - a == 504 );
207 CPPUNIT_ASSERT( a - b == -504 );
208 }
209
210 void UniCharTestCase::StringCompare()
211 {
212 // test string comparison with chars
213 wxString sa = "a";
214 const wxString sb = "b";
215 char c1 = 'a';
216 wchar_t c2 = wxT('a');
217 wxUniChar c3 = 'a';
218
219 CPPUNIT_ASSERT( sa == 'a');
220 CPPUNIT_ASSERT( 'a' == sa);
221 CPPUNIT_ASSERT( sb != 'a');
222 CPPUNIT_ASSERT( 'a' != sb);
223
224 CPPUNIT_ASSERT( sa == c1);
225 CPPUNIT_ASSERT( c1 == sa);
226 CPPUNIT_ASSERT( sb != c1);
227 CPPUNIT_ASSERT( c1 != sb);
228
229 CPPUNIT_ASSERT( sa == c2);
230 CPPUNIT_ASSERT( c2 == sa);
231 CPPUNIT_ASSERT( sb != c2);
232 CPPUNIT_ASSERT( c2 != sb);
233
234 CPPUNIT_ASSERT( sa == c3);
235 CPPUNIT_ASSERT( c3 == sa);
236 CPPUNIT_ASSERT( sb != c3);
237 CPPUNIT_ASSERT( c3 != sb);
238
239 // test wxUniCharRef:
240 CPPUNIT_ASSERT( sa == sa[0]);
241 CPPUNIT_ASSERT( sa[0] == sa);
242 CPPUNIT_ASSERT( sb != sa[0]);
243 CPPUNIT_ASSERT( sa[0] != sb);
244
245 // test const version of operator[] (returns wxUniChar, not wxUniCharRef):
246 CPPUNIT_ASSERT( sb == sb[0]);
247 CPPUNIT_ASSERT( sb[0] == sb);
248 CPPUNIT_ASSERT( sa != sb[0]);
249 CPPUNIT_ASSERT( sb[0] != sa);
250 }
251
252 #if wxUSE_UNICODE
253 void UniCharTestCase::StringCompareIntl()
254 {
255 // test string comparison with chars
256 wxString sa = CYRILLIC_SMALL_LETTER_YU;
257 const wxString sb = ARABIC_LETTER_NOON;
258 wchar_t c2 = CYRILLIC_SMALL_LETTER_YU;
259 wxUniChar c3 = CYRILLIC_SMALL_LETTER_YU;
260
261 CPPUNIT_ASSERT( sa == CYRILLIC_SMALL_LETTER_YU);
262 CPPUNIT_ASSERT( CYRILLIC_SMALL_LETTER_YU == sa);
263 CPPUNIT_ASSERT( sb != CYRILLIC_SMALL_LETTER_YU);
264 CPPUNIT_ASSERT( CYRILLIC_SMALL_LETTER_YU != sb);
265
266 CPPUNIT_ASSERT( sa == c2);
267 CPPUNIT_ASSERT( c2 == sa);
268 CPPUNIT_ASSERT( sb != c2);
269 CPPUNIT_ASSERT( c2 != sb);
270
271 CPPUNIT_ASSERT( sa == c3);
272 CPPUNIT_ASSERT( c3 == sa);
273 CPPUNIT_ASSERT( sb != c3);
274 CPPUNIT_ASSERT( c3 != sb);
275
276 // test wxUniCharRef:
277 CPPUNIT_ASSERT( sa == sa[0]);
278 CPPUNIT_ASSERT( sa[0] == sa);
279 CPPUNIT_ASSERT( sb != sa[0]);
280 CPPUNIT_ASSERT( sa[0] != sb);
281
282 // test const version of operator[] (returns wxUniChar, not wxUniCharRef):
283 CPPUNIT_ASSERT( sb == sb[0]);
284 CPPUNIT_ASSERT( sb[0] == sb);
285 CPPUNIT_ASSERT( sa != sb[0]);
286 CPPUNIT_ASSERT( sb[0] != sa);
287 }
288 #endif // wxUSE_UNICODE