]>
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 it's 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
!= 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')) );
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( 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')) );
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')) );
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')) );
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')) );
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')) );
113 CPPUNIT_ASSERT( b
- a
== 1 );
114 CPPUNIT_ASSERT( a
- b
== -1 );
118 #define CYRILLIC_SMALL_LETTER_YU ((wchar_t)0x044E)
119 #define ARABIC_LETTER_NOON ((wchar_t)0x0646)
121 void UniCharTestCase::CharCompareIntl()
123 wxUniChar
a(CYRILLIC_SMALL_LETTER_YU
);
124 wxUniChar
b(ARABIC_LETTER_NOON
);
126 CPPUNIT_ASSERT( a
== a
);
127 CPPUNIT_ASSERT( a
== CYRILLIC_SMALL_LETTER_YU
);
128 CPPUNIT_ASSERT( a
== wxUniChar(CYRILLIC_SMALL_LETTER_YU
) );
130 CPPUNIT_ASSERT( a
!= b
);
131 CPPUNIT_ASSERT( a
!= ARABIC_LETTER_NOON
);
132 CPPUNIT_ASSERT( a
!= wxUniChar(ARABIC_LETTER_NOON
) );
134 CPPUNIT_ASSERT( a
< b
);
135 CPPUNIT_ASSERT( a
< ARABIC_LETTER_NOON
);
136 CPPUNIT_ASSERT( a
< wxUniChar(ARABIC_LETTER_NOON
) );
138 CPPUNIT_ASSERT( a
<= b
);
139 CPPUNIT_ASSERT( a
<= ARABIC_LETTER_NOON
);
140 CPPUNIT_ASSERT( a
<= wxUniChar(ARABIC_LETTER_NOON
) );
142 CPPUNIT_ASSERT( a
<= a
);
143 CPPUNIT_ASSERT( a
<= CYRILLIC_SMALL_LETTER_YU
);
144 CPPUNIT_ASSERT( a
<= wxUniChar(CYRILLIC_SMALL_LETTER_YU
) );
146 CPPUNIT_ASSERT( b
> a
);
147 CPPUNIT_ASSERT( b
> CYRILLIC_SMALL_LETTER_YU
);
148 CPPUNIT_ASSERT( b
> wxUniChar(CYRILLIC_SMALL_LETTER_YU
) );
150 CPPUNIT_ASSERT( b
>= a
);
151 CPPUNIT_ASSERT( b
>= CYRILLIC_SMALL_LETTER_YU
);
152 CPPUNIT_ASSERT( b
>= wxUniChar(CYRILLIC_SMALL_LETTER_YU
) );
154 CPPUNIT_ASSERT( b
>= b
);
155 CPPUNIT_ASSERT( b
>= ARABIC_LETTER_NOON
);
156 CPPUNIT_ASSERT( b
>= wxUniChar(ARABIC_LETTER_NOON
) );
158 CPPUNIT_ASSERT( b
- a
== 504 );
159 CPPUNIT_ASSERT( a
- b
== -504 );
162 void UniCharTestCase::StringCompare()
164 // test string comparison with chars
166 const wxString sb
= "b";
168 wchar_t c2
= wxT('a');
171 CPPUNIT_ASSERT( sa
== 'a');
172 CPPUNIT_ASSERT( 'a' == sa
);
173 CPPUNIT_ASSERT( sb
!= 'a');
174 CPPUNIT_ASSERT( 'a' != sb
);
176 CPPUNIT_ASSERT( sa
== c1
);
177 CPPUNIT_ASSERT( c1
== sa
);
178 CPPUNIT_ASSERT( sb
!= c1
);
179 CPPUNIT_ASSERT( c1
!= sb
);
181 CPPUNIT_ASSERT( sa
== c2
);
182 CPPUNIT_ASSERT( c2
== sa
);
183 CPPUNIT_ASSERT( sb
!= c2
);
184 CPPUNIT_ASSERT( c2
!= sb
);
186 CPPUNIT_ASSERT( sa
== c3
);
187 CPPUNIT_ASSERT( c3
== sa
);
188 CPPUNIT_ASSERT( sb
!= c3
);
189 CPPUNIT_ASSERT( c3
!= sb
);
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
);
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
);
205 void UniCharTestCase::StringCompareIntl()
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
;
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
);
218 CPPUNIT_ASSERT( sa
== c2
);
219 CPPUNIT_ASSERT( c2
== sa
);
220 CPPUNIT_ASSERT( sb
!= c2
);
221 CPPUNIT_ASSERT( c2
!= sb
);
223 CPPUNIT_ASSERT( sa
== c3
);
224 CPPUNIT_ASSERT( c3
== sa
);
225 CPPUNIT_ASSERT( sb
!= c3
);
226 CPPUNIT_ASSERT( c3
!= sb
);
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
);
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
);
240 #endif // wxUSE_UNICODE