]>
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
);
41 CPPUNIT_TEST( StringCompareIntl
);
42 CPPUNIT_TEST_SUITE_END();
45 void CharCompareIntl();
47 void StringCompareIntl();
49 DECLARE_NO_COPY_CLASS(UniCharTestCase
)
52 // register in the unnamed registry so that these tests are run by default
53 CPPUNIT_TEST_SUITE_REGISTRATION( UniCharTestCase
);
55 // also include in it's own registry so that these tests can be run alone
56 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( UniCharTestCase
, "UniCharTestCase" );
58 void UniCharTestCase::CharCompare()
63 CPPUNIT_ASSERT( a
== a
);
64 CPPUNIT_ASSERT( a
== 'a' );
65 CPPUNIT_ASSERT( a
== wxT('a') );
66 CPPUNIT_ASSERT( a
== wxUniChar('a') );
67 CPPUNIT_ASSERT( a
== wxUniChar(wxT('a')) );
69 CPPUNIT_ASSERT( a
!= b
);
70 CPPUNIT_ASSERT( a
!= 'b' );
71 CPPUNIT_ASSERT( a
!= wxT('b') );
72 CPPUNIT_ASSERT( a
!= wxUniChar('b') );
73 CPPUNIT_ASSERT( a
!= wxUniChar(wxT('b')) );
75 CPPUNIT_ASSERT( a
< b
);
76 CPPUNIT_ASSERT( a
< 'b' );
77 CPPUNIT_ASSERT( a
< wxT('b') );
78 CPPUNIT_ASSERT( a
< wxUniChar('b') );
79 CPPUNIT_ASSERT( a
< wxUniChar(wxT('b')) );
81 CPPUNIT_ASSERT( a
<= b
);
82 CPPUNIT_ASSERT( a
<= 'b' );
83 CPPUNIT_ASSERT( a
<= wxT('b') );
84 CPPUNIT_ASSERT( a
<= wxUniChar('b') );
85 CPPUNIT_ASSERT( a
<= wxUniChar(wxT('b')) );
87 CPPUNIT_ASSERT( a
<= a
);
88 CPPUNIT_ASSERT( a
<= 'a' );
89 CPPUNIT_ASSERT( a
<= wxT('a') );
90 CPPUNIT_ASSERT( a
<= wxUniChar('a') );
91 CPPUNIT_ASSERT( a
<= wxUniChar(wxT('a')) );
93 CPPUNIT_ASSERT( b
> a
);
94 CPPUNIT_ASSERT( b
> 'a' );
95 CPPUNIT_ASSERT( b
> wxT('a') );
96 CPPUNIT_ASSERT( b
> wxUniChar('a') );
97 CPPUNIT_ASSERT( b
> wxUniChar(wxT('a')) );
99 CPPUNIT_ASSERT( b
>= a
);
100 CPPUNIT_ASSERT( b
>= 'a' );
101 CPPUNIT_ASSERT( b
>= wxT('a') );
102 CPPUNIT_ASSERT( b
>= wxUniChar('a') );
103 CPPUNIT_ASSERT( b
>= wxUniChar(wxT('a')) );
105 CPPUNIT_ASSERT( b
>= b
);
106 CPPUNIT_ASSERT( b
>= 'b' );
107 CPPUNIT_ASSERT( b
>= wxT('b') );
108 CPPUNIT_ASSERT( b
>= wxUniChar('b') );
109 CPPUNIT_ASSERT( b
>= wxUniChar(wxT('b')) );
111 CPPUNIT_ASSERT( b
- a
== 1 );
112 CPPUNIT_ASSERT( a
- b
== -1 );
116 #define CYRILLIC_SMALL_LETTER_YU ((wchar_t)0x044E)
117 #define ARABIC_LETTER_NOON ((wchar_t)0x0646)
119 void UniCharTestCase::CharCompareIntl()
121 wxUniChar
a(CYRILLIC_SMALL_LETTER_YU
);
122 wxUniChar
b(ARABIC_LETTER_NOON
);
124 CPPUNIT_ASSERT( a
== a
);
125 CPPUNIT_ASSERT( a
== CYRILLIC_SMALL_LETTER_YU
);
126 CPPUNIT_ASSERT( a
== wxUniChar(CYRILLIC_SMALL_LETTER_YU
) );
128 CPPUNIT_ASSERT( a
!= b
);
129 CPPUNIT_ASSERT( a
!= ARABIC_LETTER_NOON
);
130 CPPUNIT_ASSERT( a
!= wxUniChar(ARABIC_LETTER_NOON
) );
132 CPPUNIT_ASSERT( a
< b
);
133 CPPUNIT_ASSERT( a
< ARABIC_LETTER_NOON
);
134 CPPUNIT_ASSERT( a
< wxUniChar(ARABIC_LETTER_NOON
) );
136 CPPUNIT_ASSERT( a
<= b
);
137 CPPUNIT_ASSERT( a
<= ARABIC_LETTER_NOON
);
138 CPPUNIT_ASSERT( a
<= wxUniChar(ARABIC_LETTER_NOON
) );
140 CPPUNIT_ASSERT( a
<= a
);
141 CPPUNIT_ASSERT( a
<= CYRILLIC_SMALL_LETTER_YU
);
142 CPPUNIT_ASSERT( a
<= wxUniChar(CYRILLIC_SMALL_LETTER_YU
) );
144 CPPUNIT_ASSERT( b
> a
);
145 CPPUNIT_ASSERT( b
> CYRILLIC_SMALL_LETTER_YU
);
146 CPPUNIT_ASSERT( b
> wxUniChar(CYRILLIC_SMALL_LETTER_YU
) );
148 CPPUNIT_ASSERT( b
>= a
);
149 CPPUNIT_ASSERT( b
>= CYRILLIC_SMALL_LETTER_YU
);
150 CPPUNIT_ASSERT( b
>= wxUniChar(CYRILLIC_SMALL_LETTER_YU
) );
152 CPPUNIT_ASSERT( b
>= b
);
153 CPPUNIT_ASSERT( b
>= ARABIC_LETTER_NOON
);
154 CPPUNIT_ASSERT( b
>= wxUniChar(ARABIC_LETTER_NOON
) );
156 CPPUNIT_ASSERT( b
- a
== 504 );
157 CPPUNIT_ASSERT( a
- b
== -504 );
160 void UniCharTestCase::StringCompare()
162 // test string comparison with chars
164 const wxString sb
= "b";
166 wchar_t c2
= wxT('a');
169 CPPUNIT_ASSERT( sa
== 'a');
170 CPPUNIT_ASSERT( 'a' == sa
);
171 CPPUNIT_ASSERT( sb
!= 'a');
172 CPPUNIT_ASSERT( 'a' != sb
);
174 CPPUNIT_ASSERT( sa
== c1
);
175 CPPUNIT_ASSERT( c1
== sa
);
176 CPPUNIT_ASSERT( sb
!= c1
);
177 CPPUNIT_ASSERT( c1
!= sb
);
179 CPPUNIT_ASSERT( sa
== c2
);
180 CPPUNIT_ASSERT( c2
== sa
);
181 CPPUNIT_ASSERT( sb
!= c2
);
182 CPPUNIT_ASSERT( c2
!= sb
);
184 CPPUNIT_ASSERT( sa
== c3
);
185 CPPUNIT_ASSERT( c3
== sa
);
186 CPPUNIT_ASSERT( sb
!= c3
);
187 CPPUNIT_ASSERT( c3
!= sb
);
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
);
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
);
202 void UniCharTestCase::StringCompareIntl()
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
;
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
);
215 CPPUNIT_ASSERT( sa
== c2
);
216 CPPUNIT_ASSERT( c2
== sa
);
217 CPPUNIT_ASSERT( sb
!= c2
);
218 CPPUNIT_ASSERT( c2
!= sb
);
220 CPPUNIT_ASSERT( sa
== c3
);
221 CPPUNIT_ASSERT( c3
== sa
);
222 CPPUNIT_ASSERT( sb
!= c3
);
223 CPPUNIT_ASSERT( c3
!= sb
);
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
);
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
);