]> git.saurik.com Git - wxWidgets.git/blob - tests/strings/unichar.cpp
Fix warnings in the MSW IE backend.
[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 != b );
72 CPPUNIT_ASSERT( a != 'b' );
73 CPPUNIT_ASSERT( a != wxT('b') );
74 CPPUNIT_ASSERT( a != wxUniChar('b') );
75 CPPUNIT_ASSERT( a != wxUniChar(wxT('b')) );
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( a <= b );
84 CPPUNIT_ASSERT( a <= 'b' );
85 CPPUNIT_ASSERT( a <= wxT('b') );
86 CPPUNIT_ASSERT( a <= wxUniChar('b') );
87 CPPUNIT_ASSERT( a <= wxUniChar(wxT('b')) );
88
89 CPPUNIT_ASSERT( a <= a );
90 CPPUNIT_ASSERT( a <= 'a' );
91 CPPUNIT_ASSERT( a <= wxT('a') );
92 CPPUNIT_ASSERT( a <= wxUniChar('a') );
93 CPPUNIT_ASSERT( a <= wxUniChar(wxT('a')) );
94
95 CPPUNIT_ASSERT( b > a );
96 CPPUNIT_ASSERT( b > 'a' );
97 CPPUNIT_ASSERT( b > wxT('a') );
98 CPPUNIT_ASSERT( b > wxUniChar('a') );
99 CPPUNIT_ASSERT( b > wxUniChar(wxT('a')) );
100
101 CPPUNIT_ASSERT( b >= a );
102 CPPUNIT_ASSERT( b >= 'a' );
103 CPPUNIT_ASSERT( b >= wxT('a') );
104 CPPUNIT_ASSERT( b >= wxUniChar('a') );
105 CPPUNIT_ASSERT( b >= wxUniChar(wxT('a')) );
106
107 CPPUNIT_ASSERT( b >= b );
108 CPPUNIT_ASSERT( b >= 'b' );
109 CPPUNIT_ASSERT( b >= wxT('b') );
110 CPPUNIT_ASSERT( b >= wxUniChar('b') );
111 CPPUNIT_ASSERT( b >= wxUniChar(wxT('b')) );
112
113 CPPUNIT_ASSERT( b - a == 1 );
114 CPPUNIT_ASSERT( a - b == -1 );
115 }
116
117
118 #define CYRILLIC_SMALL_LETTER_YU ((wchar_t)0x044E)
119 #define ARABIC_LETTER_NOON ((wchar_t)0x0646)
120
121 void UniCharTestCase::CharCompareIntl()
122 {
123 wxUniChar a(CYRILLIC_SMALL_LETTER_YU);
124 wxUniChar b(ARABIC_LETTER_NOON);
125
126 CPPUNIT_ASSERT( a == a );
127 CPPUNIT_ASSERT( a == CYRILLIC_SMALL_LETTER_YU );
128 CPPUNIT_ASSERT( a == wxUniChar(CYRILLIC_SMALL_LETTER_YU) );
129
130 CPPUNIT_ASSERT( a != b );
131 CPPUNIT_ASSERT( a != ARABIC_LETTER_NOON );
132 CPPUNIT_ASSERT( a != wxUniChar(ARABIC_LETTER_NOON) );
133
134 CPPUNIT_ASSERT( a < b );
135 CPPUNIT_ASSERT( a < ARABIC_LETTER_NOON );
136 CPPUNIT_ASSERT( a < wxUniChar(ARABIC_LETTER_NOON) );
137
138 CPPUNIT_ASSERT( a <= b );
139 CPPUNIT_ASSERT( a <= ARABIC_LETTER_NOON );
140 CPPUNIT_ASSERT( a <= wxUniChar(ARABIC_LETTER_NOON) );
141
142 CPPUNIT_ASSERT( a <= a );
143 CPPUNIT_ASSERT( a <= CYRILLIC_SMALL_LETTER_YU );
144 CPPUNIT_ASSERT( a <= wxUniChar(CYRILLIC_SMALL_LETTER_YU) );
145
146 CPPUNIT_ASSERT( b > a );
147 CPPUNIT_ASSERT( b > CYRILLIC_SMALL_LETTER_YU );
148 CPPUNIT_ASSERT( b > wxUniChar(CYRILLIC_SMALL_LETTER_YU) );
149
150 CPPUNIT_ASSERT( b >= a );
151 CPPUNIT_ASSERT( b >= CYRILLIC_SMALL_LETTER_YU );
152 CPPUNIT_ASSERT( b >= wxUniChar(CYRILLIC_SMALL_LETTER_YU) );
153
154 CPPUNIT_ASSERT( b >= b );
155 CPPUNIT_ASSERT( b >= ARABIC_LETTER_NOON );
156 CPPUNIT_ASSERT( b >= wxUniChar(ARABIC_LETTER_NOON) );
157
158 CPPUNIT_ASSERT( b - a == 504 );
159 CPPUNIT_ASSERT( a - b == -504 );
160 }
161
162 void UniCharTestCase::StringCompare()
163 {
164 // test string comparison with chars
165 wxString sa = "a";
166 const wxString sb = "b";
167 char c1 = 'a';
168 wchar_t c2 = wxT('a');
169 wxUniChar c3 = 'a';
170
171 CPPUNIT_ASSERT( sa == 'a');
172 CPPUNIT_ASSERT( 'a' == sa);
173 CPPUNIT_ASSERT( sb != 'a');
174 CPPUNIT_ASSERT( 'a' != sb);
175
176 CPPUNIT_ASSERT( sa == c1);
177 CPPUNIT_ASSERT( c1 == sa);
178 CPPUNIT_ASSERT( sb != c1);
179 CPPUNIT_ASSERT( c1 != sb);
180
181 CPPUNIT_ASSERT( sa == c2);
182 CPPUNIT_ASSERT( c2 == sa);
183 CPPUNIT_ASSERT( sb != c2);
184 CPPUNIT_ASSERT( c2 != sb);
185
186 CPPUNIT_ASSERT( sa == c3);
187 CPPUNIT_ASSERT( c3 == sa);
188 CPPUNIT_ASSERT( sb != c3);
189 CPPUNIT_ASSERT( c3 != sb);
190
191 // test wxUniCharRef:
192 CPPUNIT_ASSERT( sa == sa[0]);
193 CPPUNIT_ASSERT( sa[0] == sa);
194 CPPUNIT_ASSERT( sb != sa[0]);
195 CPPUNIT_ASSERT( sa[0] != sb);
196
197 // test const version of operator[] (returns wxUniChar, not wxUniCharRef):
198 CPPUNIT_ASSERT( sb == sb[0]);
199 CPPUNIT_ASSERT( sb[0] == sb);
200 CPPUNIT_ASSERT( sa != sb[0]);
201 CPPUNIT_ASSERT( sb[0] != sa);
202 }
203
204 #if wxUSE_UNICODE
205 void UniCharTestCase::StringCompareIntl()
206 {
207 // test string comparison with chars
208 wxString sa = CYRILLIC_SMALL_LETTER_YU;
209 const wxString sb = ARABIC_LETTER_NOON;
210 wchar_t c2 = CYRILLIC_SMALL_LETTER_YU;
211 wxUniChar c3 = CYRILLIC_SMALL_LETTER_YU;
212
213 CPPUNIT_ASSERT( sa == CYRILLIC_SMALL_LETTER_YU);
214 CPPUNIT_ASSERT( CYRILLIC_SMALL_LETTER_YU == sa);
215 CPPUNIT_ASSERT( sb != CYRILLIC_SMALL_LETTER_YU);
216 CPPUNIT_ASSERT( CYRILLIC_SMALL_LETTER_YU != sb);
217
218 CPPUNIT_ASSERT( sa == c2);
219 CPPUNIT_ASSERT( c2 == sa);
220 CPPUNIT_ASSERT( sb != c2);
221 CPPUNIT_ASSERT( c2 != sb);
222
223 CPPUNIT_ASSERT( sa == c3);
224 CPPUNIT_ASSERT( c3 == sa);
225 CPPUNIT_ASSERT( sb != c3);
226 CPPUNIT_ASSERT( c3 != sb);
227
228 // test wxUniCharRef:
229 CPPUNIT_ASSERT( sa == sa[0]);
230 CPPUNIT_ASSERT( sa[0] == sa);
231 CPPUNIT_ASSERT( sb != sa[0]);
232 CPPUNIT_ASSERT( sa[0] != sb);
233
234 // test const version of operator[] (returns wxUniChar, not wxUniCharRef):
235 CPPUNIT_ASSERT( sb == sb[0]);
236 CPPUNIT_ASSERT( sb[0] == sb);
237 CPPUNIT_ASSERT( sa != sb[0]);
238 CPPUNIT_ASSERT( sb[0] != sa);
239 }
240 #endif // wxUSE_UNICODE