fix compilation with VC7
[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 CPPUNIT_ASSERT( wxXLocale("fr_FR").IsOk() );
69 CPPUNIT_ASSERT( wxXLocale("french").IsOk() );
70 #endif
71 CPPUNIT_ASSERT( !wxXLocale("bloordyblop").IsOk() );
72 }
73
74 // test the ctype functions with the given locale
75 void XLocaleTestCase::TestCtypeFunctionsWith(const wxXLocale& loc)
76 {
77 // isalnum
78 CPPUNIT_ASSERT( wxIsalnum_l('0', loc) );
79 CPPUNIT_ASSERT( wxIsalnum_l('9', loc) );
80 CPPUNIT_ASSERT( wxIsalnum_l('A', loc) );
81 CPPUNIT_ASSERT( wxIsalnum_l('Z', loc) );
82 CPPUNIT_ASSERT( wxIsalnum_l('a', loc) );
83 CPPUNIT_ASSERT( wxIsalnum_l('z', loc) );
84 CPPUNIT_ASSERT( !wxIsalnum_l('*', loc) );
85 CPPUNIT_ASSERT( !wxIsalnum_l('@', loc) );
86 CPPUNIT_ASSERT( !wxIsalnum_l('+', loc) );
87
88 // isalpha
89 CPPUNIT_ASSERT( !wxIsalpha_l('0', loc) );
90 CPPUNIT_ASSERT( !wxIsalpha_l('9', loc) );
91 CPPUNIT_ASSERT( wxIsalpha_l('A', loc) );
92 CPPUNIT_ASSERT( wxIsalpha_l('Z', loc) );
93 CPPUNIT_ASSERT( wxIsalpha_l('a', loc) );
94 CPPUNIT_ASSERT( wxIsalpha_l('z', loc) );
95 CPPUNIT_ASSERT( !wxIsalpha_l('*', loc) );
96 CPPUNIT_ASSERT( !wxIsalpha_l('@', loc) );
97 CPPUNIT_ASSERT( !wxIsalpha_l('+', loc) );
98
99 // TODO: iscntrl
100
101 // isdigit
102 CPPUNIT_ASSERT( wxIsdigit_l('0', loc) );
103 CPPUNIT_ASSERT( wxIsdigit_l('9', loc) );
104 CPPUNIT_ASSERT( !wxIsdigit_l('A', loc) );
105 CPPUNIT_ASSERT( !wxIsdigit_l('Z', loc) );
106 CPPUNIT_ASSERT( !wxIsdigit_l('a', loc) );
107 CPPUNIT_ASSERT( !wxIsdigit_l('z', loc) );
108
109 // TODO: isgraph
110
111 // islower
112 CPPUNIT_ASSERT( !wxIslower_l('A', loc) );
113 CPPUNIT_ASSERT( !wxIslower_l('Z', loc) );
114 CPPUNIT_ASSERT( wxIslower_l('a', loc) );
115 CPPUNIT_ASSERT( wxIslower_l('z', loc) );
116 CPPUNIT_ASSERT( !wxIslower_l('0', loc) );
117 CPPUNIT_ASSERT( !wxIslower_l('9', loc) );
118
119
120 // TODO: isprint
121 // TODO: ispunct
122
123 // isspace
124 CPPUNIT_ASSERT( wxIsspace_l(' ', loc) );
125 CPPUNIT_ASSERT( wxIsspace_l('\t', loc) );
126 CPPUNIT_ASSERT( wxIsspace_l('\r', loc) );
127 CPPUNIT_ASSERT( wxIsspace_l('\n', loc) );
128 CPPUNIT_ASSERT( !wxIsspace_l('0', loc) );
129 CPPUNIT_ASSERT( !wxIsspace_l('a', loc) );
130 CPPUNIT_ASSERT( !wxIsspace_l('A', loc) );
131
132 // isupper
133 CPPUNIT_ASSERT( !wxIsupper_l('0', loc) );
134 CPPUNIT_ASSERT( !wxIsupper_l('9', loc) );
135 CPPUNIT_ASSERT( wxIsupper_l('A', loc) );
136 CPPUNIT_ASSERT( wxIsupper_l('Z', loc) );
137 CPPUNIT_ASSERT( !wxIsupper_l('a', loc) );
138 CPPUNIT_ASSERT( !wxIsupper_l('z', loc) );
139
140 // isxdigit
141 CPPUNIT_ASSERT( wxIsxdigit_l('0', loc) );
142 CPPUNIT_ASSERT( wxIsxdigit_l('9', loc) );
143 CPPUNIT_ASSERT( wxIsxdigit_l('A', loc) );
144 CPPUNIT_ASSERT( wxIsxdigit_l('F', loc) );
145 CPPUNIT_ASSERT( !wxIsxdigit_l('Z', loc) );
146 CPPUNIT_ASSERT( wxIsxdigit_l('a', loc) );
147 CPPUNIT_ASSERT( wxIsxdigit_l('f', loc) );
148 CPPUNIT_ASSERT( !wxIsxdigit_l('z', loc) );
149
150 // tolower
151 CPPUNIT_ASSERT_EQUAL( 'a', (char)wxTolower_l('A', loc) );
152 CPPUNIT_ASSERT_EQUAL( 'a', (char)wxTolower_l('a', loc) );
153 CPPUNIT_ASSERT_EQUAL( 'z', (char)wxTolower_l('Z', loc) );
154 CPPUNIT_ASSERT_EQUAL( 'z', (char)wxTolower_l('z', loc) );
155 CPPUNIT_ASSERT_EQUAL( '0', (char)wxTolower_l('0', loc) );
156 CPPUNIT_ASSERT_EQUAL( '9', (char)wxTolower_l('9', loc) );
157
158 // toupper
159 CPPUNIT_ASSERT_EQUAL( 'A', (char)wxToupper_l('A', loc) );
160 CPPUNIT_ASSERT_EQUAL( 'A', (char)wxToupper_l('a', loc) );
161 CPPUNIT_ASSERT_EQUAL( 'Z', (char)wxToupper_l('Z', loc) );
162 CPPUNIT_ASSERT_EQUAL( 'Z', (char)wxToupper_l('z', loc) );
163 CPPUNIT_ASSERT_EQUAL( '0', (char)wxToupper_l('0', loc) );
164 CPPUNIT_ASSERT_EQUAL( '9', (char)wxToupper_l('9', loc) );
165 }
166
167 void XLocaleTestCase::TestCtypeFunctions()
168 {
169 TestCtypeFunctionsWith(wxCLocale);
170
171 #ifdef wxHAS_XLOCALE_SUPPORT
172 wxXLocale locFR("fr_FR");
173 TestCtypeFunctionsWith(locFR);
174
175 CPPUNIT_ASSERT( wxIsalpha_l('é', locFR) );
176 CPPUNIT_ASSERT( wxIslower_l('é', locFR) );
177 CPPUNIT_ASSERT( !wxIslower_l('É', locFR) );
178 CPPUNIT_ASSERT( wxIsupper_l('É', locFR) );
179 #endif
180 }
181
182 #endif // wxUSE_XLOCALE