]> git.saurik.com Git - wxWidgets.git/blame - tests/strings/unichar.cpp
Implement GetSizeFromTextSize() for wxSpinCtrl.
[wxWidgets.git] / tests / strings / unichar.cpp
CommitLineData
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
31class UniCharTestCase : public CppUnit::TestCase
32{
33public:
34 UniCharTestCase() {}
35
36private:
37 CPPUNIT_TEST_SUITE( UniCharTestCase );
38 CPPUNIT_TEST( CharCompare );
39 CPPUNIT_TEST( CharCompareIntl );
40 CPPUNIT_TEST( StringCompare );
87f528f1 41#if wxUSE_UNICODE
c9f78968 42 CPPUNIT_TEST( StringCompareIntl );
87f528f1 43#endif // wxUSE_UNICODE
c9f78968
VS
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
55CPPUNIT_TEST_SUITE_REGISTRATION( UniCharTestCase );
56
e3778b4d 57// also include in its own registry so that these tests can be run alone
c9f78968
VS
58CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( UniCharTestCase, "UniCharTestCase" );
59
60void UniCharTestCase::CharCompare()
61{
62 wxUniChar a('a');
63 wxUniChar b('b');
64
65 CPPUNIT_ASSERT( a == a );
66 CPPUNIT_ASSERT( a == 'a' );
9a83f860 67 CPPUNIT_ASSERT( a == wxT('a') );
c9f78968 68 CPPUNIT_ASSERT( a == wxUniChar('a') );
9a83f860 69 CPPUNIT_ASSERT( a == wxUniChar(wxT('a')) );
c9f78968 70
6d93e28a
VZ
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
c9f78968
VS
77 CPPUNIT_ASSERT( a != b );
78 CPPUNIT_ASSERT( a != 'b' );
9a83f860 79 CPPUNIT_ASSERT( a != wxT('b') );
c9f78968 80 CPPUNIT_ASSERT( a != wxUniChar('b') );
9a83f860 81 CPPUNIT_ASSERT( a != wxUniChar(wxT('b')) );
c9f78968 82
6d93e28a
VZ
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
c9f78968
VS
89 CPPUNIT_ASSERT( a < b );
90 CPPUNIT_ASSERT( a < 'b' );
9a83f860 91 CPPUNIT_ASSERT( a < wxT('b') );
c9f78968 92 CPPUNIT_ASSERT( a < wxUniChar('b') );
9a83f860 93 CPPUNIT_ASSERT( a < wxUniChar(wxT('b')) );
c9f78968 94
6d93e28a
VZ
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
c9f78968
VS
101 CPPUNIT_ASSERT( a <= b );
102 CPPUNIT_ASSERT( a <= 'b' );
9a83f860 103 CPPUNIT_ASSERT( a <= wxT('b') );
c9f78968 104 CPPUNIT_ASSERT( a <= wxUniChar('b') );
9a83f860 105 CPPUNIT_ASSERT( a <= wxUniChar(wxT('b')) );
c9f78968 106
6d93e28a
VZ
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
c9f78968
VS
113 CPPUNIT_ASSERT( a <= a );
114 CPPUNIT_ASSERT( a <= 'a' );
9a83f860 115 CPPUNIT_ASSERT( a <= wxT('a') );
c9f78968 116 CPPUNIT_ASSERT( a <= wxUniChar('a') );
9a83f860 117 CPPUNIT_ASSERT( a <= wxUniChar(wxT('a')) );
c9f78968 118
6d93e28a
VZ
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
c9f78968
VS
125 CPPUNIT_ASSERT( b > a );
126 CPPUNIT_ASSERT( b > 'a' );
9a83f860 127 CPPUNIT_ASSERT( b > wxT('a') );
c9f78968 128 CPPUNIT_ASSERT( b > wxUniChar('a') );
9a83f860 129 CPPUNIT_ASSERT( b > wxUniChar(wxT('a')) );
c9f78968 130
6d93e28a
VZ
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
c9f78968
VS
137 CPPUNIT_ASSERT( b >= a );
138 CPPUNIT_ASSERT( b >= 'a' );
9a83f860 139 CPPUNIT_ASSERT( b >= wxT('a') );
c9f78968 140 CPPUNIT_ASSERT( b >= wxUniChar('a') );
9a83f860 141 CPPUNIT_ASSERT( b >= wxUniChar(wxT('a')) );
c9f78968 142
6d93e28a
VZ
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
c9f78968
VS
149 CPPUNIT_ASSERT( b >= b );
150 CPPUNIT_ASSERT( b >= 'b' );
9a83f860 151 CPPUNIT_ASSERT( b >= wxT('b') );
c9f78968 152 CPPUNIT_ASSERT( b >= wxUniChar('b') );
9a83f860 153 CPPUNIT_ASSERT( b >= wxUniChar(wxT('b')) );
c9f78968 154
6d93e28a
VZ
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
c9f78968
VS
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
169void 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
210void UniCharTestCase::StringCompare()
211{
212 // test string comparison with chars
213 wxString sa = "a";
214 const wxString sb = "b";
215 char c1 = 'a';
9a83f860 216 wchar_t c2 = wxT('a');
c9f78968
VS
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
87f528f1 252#if wxUSE_UNICODE
c9f78968
VS
253void 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}
87f528f1 288#endif // wxUSE_UNICODE