]>
git.saurik.com Git - wxWidgets.git/blob - tests/strings/unichar.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: tests/strings/unichar.cpp
3 // Purpose: Test for wxUniChar class
4 // Author: Vaclav Slavik
7 // Copyright: (c) 2007 REA Elektronik GmbH
8 // Licence: wxWindows licence
9 ///////////////////////////////////////////////////////////////////////////////
11 // ----------------------------------------------------------------------------
13 // ----------------------------------------------------------------------------
25 #include "wx/string.h"
27 // ----------------------------------------------------------------------------
29 // ----------------------------------------------------------------------------
31 class UniCharTestCase
: public CppUnit::TestCase
37 CPPUNIT_TEST_SUITE( UniCharTestCase
);
38 CPPUNIT_TEST( CharCompare
);
39 CPPUNIT_TEST( CharCompareIntl
);
40 CPPUNIT_TEST( StringCompare
);
42 CPPUNIT_TEST( StringCompareIntl
);
43 #endif // wxUSE_UNICODE
44 CPPUNIT_TEST_SUITE_END();
47 void CharCompareIntl();
49 void StringCompareIntl();
51 DECLARE_NO_COPY_CLASS(UniCharTestCase
)
54 // register in the unnamed registry so that these tests are run by default
55 CPPUNIT_TEST_SUITE_REGISTRATION( UniCharTestCase
);
57 // also include in its own registry so that these tests can be run alone
58 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( UniCharTestCase
, "UniCharTestCase" );
60 void UniCharTestCase::CharCompare()
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')) );
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
);
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')) );
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
);
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')) );
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
);
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')) );
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
);
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')) );
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
);
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')) );
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
);
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')) );
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
);
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')) );
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
);
161 CPPUNIT_ASSERT( b
- a
== 1 );
162 CPPUNIT_ASSERT( a
- b
== -1 );
166 #define CYRILLIC_SMALL_LETTER_YU ((wchar_t)0x044E)
167 #define ARABIC_LETTER_NOON ((wchar_t)0x0646)
169 void UniCharTestCase::CharCompareIntl()
171 wxUniChar
a(CYRILLIC_SMALL_LETTER_YU
);
172 wxUniChar
b(ARABIC_LETTER_NOON
);
174 CPPUNIT_ASSERT( a
== a
);
175 CPPUNIT_ASSERT( a
== CYRILLIC_SMALL_LETTER_YU
);
176 CPPUNIT_ASSERT( a
== wxUniChar(CYRILLIC_SMALL_LETTER_YU
) );
178 CPPUNIT_ASSERT( a
!= b
);
179 CPPUNIT_ASSERT( a
!= ARABIC_LETTER_NOON
);
180 CPPUNIT_ASSERT( a
!= wxUniChar(ARABIC_LETTER_NOON
) );
182 CPPUNIT_ASSERT( a
< b
);
183 CPPUNIT_ASSERT( a
< ARABIC_LETTER_NOON
);
184 CPPUNIT_ASSERT( a
< wxUniChar(ARABIC_LETTER_NOON
) );
186 CPPUNIT_ASSERT( a
<= b
);
187 CPPUNIT_ASSERT( a
<= ARABIC_LETTER_NOON
);
188 CPPUNIT_ASSERT( a
<= wxUniChar(ARABIC_LETTER_NOON
) );
190 CPPUNIT_ASSERT( a
<= a
);
191 CPPUNIT_ASSERT( a
<= CYRILLIC_SMALL_LETTER_YU
);
192 CPPUNIT_ASSERT( a
<= wxUniChar(CYRILLIC_SMALL_LETTER_YU
) );
194 CPPUNIT_ASSERT( b
> a
);
195 CPPUNIT_ASSERT( b
> CYRILLIC_SMALL_LETTER_YU
);
196 CPPUNIT_ASSERT( b
> wxUniChar(CYRILLIC_SMALL_LETTER_YU
) );
198 CPPUNIT_ASSERT( b
>= a
);
199 CPPUNIT_ASSERT( b
>= CYRILLIC_SMALL_LETTER_YU
);
200 CPPUNIT_ASSERT( b
>= wxUniChar(CYRILLIC_SMALL_LETTER_YU
) );
202 CPPUNIT_ASSERT( b
>= b
);
203 CPPUNIT_ASSERT( b
>= ARABIC_LETTER_NOON
);
204 CPPUNIT_ASSERT( b
>= wxUniChar(ARABIC_LETTER_NOON
) );
206 CPPUNIT_ASSERT( b
- a
== 504 );
207 CPPUNIT_ASSERT( a
- b
== -504 );
210 void UniCharTestCase::StringCompare()
212 // test string comparison with chars
214 const wxString sb
= "b";
216 wchar_t c2
= wxT('a');
219 CPPUNIT_ASSERT( sa
== 'a');
220 CPPUNIT_ASSERT( 'a' == sa
);
221 CPPUNIT_ASSERT( sb
!= 'a');
222 CPPUNIT_ASSERT( 'a' != sb
);
224 CPPUNIT_ASSERT( sa
== c1
);
225 CPPUNIT_ASSERT( c1
== sa
);
226 CPPUNIT_ASSERT( sb
!= c1
);
227 CPPUNIT_ASSERT( c1
!= sb
);
229 CPPUNIT_ASSERT( sa
== c2
);
230 CPPUNIT_ASSERT( c2
== sa
);
231 CPPUNIT_ASSERT( sb
!= c2
);
232 CPPUNIT_ASSERT( c2
!= sb
);
234 CPPUNIT_ASSERT( sa
== c3
);
235 CPPUNIT_ASSERT( c3
== sa
);
236 CPPUNIT_ASSERT( sb
!= c3
);
237 CPPUNIT_ASSERT( c3
!= sb
);
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
);
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
);
253 void UniCharTestCase::StringCompareIntl()
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
;
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
);
266 CPPUNIT_ASSERT( sa
== c2
);
267 CPPUNIT_ASSERT( c2
== sa
);
268 CPPUNIT_ASSERT( sb
!= c2
);
269 CPPUNIT_ASSERT( c2
!= sb
);
271 CPPUNIT_ASSERT( sa
== c3
);
272 CPPUNIT_ASSERT( c3
== sa
);
273 CPPUNIT_ASSERT( sb
!= c3
);
274 CPPUNIT_ASSERT( c3
!= sb
);
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
);
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
);
288 #endif // wxUSE_UNICODE