]> git.saurik.com Git - wxWidgets.git/blob - tests/xlocale/xlocale.cpp
no real change: divide in groups the wxEvtHandler methods
[wxWidgets.git] / tests / xlocale / xlocale.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: tests/xlocale/xlocale.cpp
3 // Purpose: wxXLocale & related unit test
4 // Author: Brian Vanderburg II, Vadim Zeitlin
5 // Created: 2008-01-16
6 // RCS-ID: $Id$
7 // Copyright: (c) 2008 Brian Vanderburg II
8 // 2008 Vadim Zeitlin <vadim@wxwidgets.org>
9 // Licence: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
11
12 // ----------------------------------------------------------------------------
13 // headers
14 // ----------------------------------------------------------------------------
15
16 #include "testprec.h"
17
18 #ifdef __BORLANDC__
19 #pragma hdrstop
20 #endif
21
22 #if wxUSE_XLOCALE
23
24 #ifndef WX_PRECOMP
25 #include "wx/wx.h"
26 #endif // WX_PRECOMP
27
28 #include "wx/xlocale.h"
29
30 // --------------------------------------------------------------------------
31 // test class
32 // --------------------------------------------------------------------------
33
34 class XLocaleTestCase : public CppUnit::TestCase
35 {
36 public:
37 XLocaleTestCase() { }
38
39 private:
40 CPPUNIT_TEST_SUITE( XLocaleTestCase );
41 CPPUNIT_TEST( TestCtor );
42 CPPUNIT_TEST( TestCtypeFunctions );
43 CPPUNIT_TEST_SUITE_END();
44
45 void TestCtor();
46 void TestCtypeFunctions();
47
48 void TestCtypeFunctionsWith(const wxXLocale& loc);
49
50 DECLARE_NO_COPY_CLASS(XLocaleTestCase)
51 };
52
53 // register in the unnamed registry so that these tests are run by default
54 CPPUNIT_TEST_SUITE_REGISTRATION( XLocaleTestCase );
55
56 // also include in it's own registry so that these tests can be run alone
57 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( XLocaleTestCase, "XLocaleTestCase" );
58
59
60 // test the different wxXLocale ctors
61 void XLocaleTestCase::TestCtor()
62 {
63 CPPUNIT_ASSERT( !wxXLocale().IsOk() );
64 CPPUNIT_ASSERT( wxCLocale.IsOk() );
65 CPPUNIT_ASSERT( wxXLocale("C").IsOk() );
66 #ifdef wxHAS_XLOCALE_SUPPORT
67 CPPUNIT_ASSERT( wxXLocale(wxLANGUAGE_FRENCH).IsOk() );
68 #ifdef __WXMSW__
69 CPPUNIT_ASSERT( wxXLocale("french").IsOk() );
70 #else
71 CPPUNIT_ASSERT( wxXLocale("fr_FR").IsOk() );
72 #endif
73 #endif
74 CPPUNIT_ASSERT( !wxXLocale("bloordyblop").IsOk() );
75 }
76
77 // test the ctype functions with the given locale
78 void XLocaleTestCase::TestCtypeFunctionsWith(const wxXLocale& loc)
79 {
80 // isalnum
81 CPPUNIT_ASSERT( wxIsalnum_l('0', loc) );
82 CPPUNIT_ASSERT( wxIsalnum_l('9', loc) );
83 CPPUNIT_ASSERT( wxIsalnum_l('A', loc) );
84 CPPUNIT_ASSERT( wxIsalnum_l('Z', loc) );
85 CPPUNIT_ASSERT( wxIsalnum_l('a', loc) );
86 CPPUNIT_ASSERT( wxIsalnum_l('z', loc) );
87 CPPUNIT_ASSERT( !wxIsalnum_l('*', loc) );
88 CPPUNIT_ASSERT( !wxIsalnum_l('@', loc) );
89 CPPUNIT_ASSERT( !wxIsalnum_l('+', loc) );
90
91 // isalpha
92 CPPUNIT_ASSERT( !wxIsalpha_l('0', loc) );
93 CPPUNIT_ASSERT( !wxIsalpha_l('9', loc) );
94 CPPUNIT_ASSERT( wxIsalpha_l('A', loc) );
95 CPPUNIT_ASSERT( wxIsalpha_l('Z', loc) );
96 CPPUNIT_ASSERT( wxIsalpha_l('a', loc) );
97 CPPUNIT_ASSERT( wxIsalpha_l('z', loc) );
98 CPPUNIT_ASSERT( !wxIsalpha_l('*', loc) );
99 CPPUNIT_ASSERT( !wxIsalpha_l('@', loc) );
100 CPPUNIT_ASSERT( !wxIsalpha_l('+', loc) );
101
102 // TODO: iscntrl
103
104 // isdigit
105 CPPUNIT_ASSERT( wxIsdigit_l('0', loc) );
106 CPPUNIT_ASSERT( wxIsdigit_l('9', loc) );
107 CPPUNIT_ASSERT( !wxIsdigit_l('A', loc) );
108 CPPUNIT_ASSERT( !wxIsdigit_l('Z', loc) );
109 CPPUNIT_ASSERT( !wxIsdigit_l('a', loc) );
110 CPPUNIT_ASSERT( !wxIsdigit_l('z', loc) );
111
112 // TODO: isgraph
113
114 // islower
115 CPPUNIT_ASSERT( !wxIslower_l('A', loc) );
116 CPPUNIT_ASSERT( !wxIslower_l('Z', loc) );
117 CPPUNIT_ASSERT( wxIslower_l('a', loc) );
118 CPPUNIT_ASSERT( wxIslower_l('z', loc) );
119 CPPUNIT_ASSERT( !wxIslower_l('0', loc) );
120 CPPUNIT_ASSERT( !wxIslower_l('9', loc) );
121
122
123 // TODO: isprint
124 // TODO: ispunct
125
126 // isspace
127 CPPUNIT_ASSERT( wxIsspace_l(' ', loc) );
128 CPPUNIT_ASSERT( wxIsspace_l('\t', loc) );
129 CPPUNIT_ASSERT( wxIsspace_l('\r', loc) );
130 CPPUNIT_ASSERT( wxIsspace_l('\n', loc) );
131 CPPUNIT_ASSERT( !wxIsspace_l('0', loc) );
132 CPPUNIT_ASSERT( !wxIsspace_l('a', loc) );
133 CPPUNIT_ASSERT( !wxIsspace_l('A', loc) );
134
135 // isupper
136 CPPUNIT_ASSERT( !wxIsupper_l('0', loc) );
137 CPPUNIT_ASSERT( !wxIsupper_l('9', loc) );
138 CPPUNIT_ASSERT( wxIsupper_l('A', loc) );
139 CPPUNIT_ASSERT( wxIsupper_l('Z', loc) );
140 CPPUNIT_ASSERT( !wxIsupper_l('a', loc) );
141 CPPUNIT_ASSERT( !wxIsupper_l('z', loc) );
142
143 // isxdigit
144 CPPUNIT_ASSERT( wxIsxdigit_l('0', loc) );
145 CPPUNIT_ASSERT( wxIsxdigit_l('9', loc) );
146 CPPUNIT_ASSERT( wxIsxdigit_l('A', loc) );
147 CPPUNIT_ASSERT( wxIsxdigit_l('F', loc) );
148 CPPUNIT_ASSERT( !wxIsxdigit_l('Z', loc) );
149 CPPUNIT_ASSERT( wxIsxdigit_l('a', loc) );
150 CPPUNIT_ASSERT( wxIsxdigit_l('f', loc) );
151 CPPUNIT_ASSERT( !wxIsxdigit_l('z', loc) );
152
153 // tolower
154 CPPUNIT_ASSERT_EQUAL( 'a', (char)wxTolower_l('A', loc) );
155 CPPUNIT_ASSERT_EQUAL( 'a', (char)wxTolower_l('a', loc) );
156 CPPUNIT_ASSERT_EQUAL( 'z', (char)wxTolower_l('Z', loc) );
157 CPPUNIT_ASSERT_EQUAL( 'z', (char)wxTolower_l('z', loc) );
158 CPPUNIT_ASSERT_EQUAL( '0', (char)wxTolower_l('0', loc) );
159 CPPUNIT_ASSERT_EQUAL( '9', (char)wxTolower_l('9', loc) );
160
161 // toupper
162 CPPUNIT_ASSERT_EQUAL( 'A', (char)wxToupper_l('A', loc) );
163 CPPUNIT_ASSERT_EQUAL( 'A', (char)wxToupper_l('a', loc) );
164 CPPUNIT_ASSERT_EQUAL( 'Z', (char)wxToupper_l('Z', loc) );
165 CPPUNIT_ASSERT_EQUAL( 'Z', (char)wxToupper_l('z', loc) );
166 CPPUNIT_ASSERT_EQUAL( '0', (char)wxToupper_l('0', loc) );
167 CPPUNIT_ASSERT_EQUAL( '9', (char)wxToupper_l('9', loc) );
168 }
169
170 void XLocaleTestCase::TestCtypeFunctions()
171 {
172 TestCtypeFunctionsWith(wxCLocale);
173
174 #ifdef wxHAS_XLOCALE_SUPPORT
175 wxXLocale locFR(wxLANGUAGE_FRENCH);
176 CPPUNIT_ASSERT( locFR.IsOk() ); // doesn't make sense to continue otherwise
177
178 TestCtypeFunctionsWith(locFR);
179
180 CPPUNIT_ASSERT( wxIsalpha_l('\xe9', locFR) );
181 CPPUNIT_ASSERT( wxIslower_l('\xe9', locFR) );
182 CPPUNIT_ASSERT( !wxIslower_l('\xc9', locFR) );
183 CPPUNIT_ASSERT( wxIsupper_l('\xc9', locFR) );
184 #endif
185 }
186
187 #endif // wxUSE_XLOCALE