]>
git.saurik.com Git - wxWidgets.git/blob - tests/xlocale/xlocale.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: tests/xlocale/xlocale.cpp
3 // Purpose: wxXLocale & related unit test
4 // Author: Brian Vanderburg II, Vadim Zeitlin
7 // Copyright: (c) 2008 Brian Vanderburg II
8 // 2008 Vadim Zeitlin <vadim@wxwidgets.org>
9 // Licence: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
12 // ----------------------------------------------------------------------------
14 // ----------------------------------------------------------------------------
28 #include "wx/xlocale.h"
30 // --------------------------------------------------------------------------
32 // --------------------------------------------------------------------------
34 class XLocaleTestCase
: public CppUnit::TestCase
40 CPPUNIT_TEST_SUITE( XLocaleTestCase
);
41 CPPUNIT_TEST( TestCtor
);
42 CPPUNIT_TEST( TestCtypeFunctions
);
43 CPPUNIT_TEST_SUITE_END();
46 void TestCtypeFunctions();
48 void TestCtypeFunctionsWith(const wxXLocale
& loc
);
50 DECLARE_NO_COPY_CLASS(XLocaleTestCase
)
53 // register in the unnamed registry so that these tests are run by default
54 CPPUNIT_TEST_SUITE_REGISTRATION( XLocaleTestCase
);
56 // also include in it's own registry so that these tests can be run alone
57 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( XLocaleTestCase
, "XLocaleTestCase" );
60 // test the different wxXLocale ctors
61 void XLocaleTestCase::TestCtor()
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() );
69 CPPUNIT_ASSERT( wxXLocale("french").IsOk() );
71 CPPUNIT_ASSERT( wxXLocale("fr_FR").IsOk() );
74 CPPUNIT_ASSERT( !wxXLocale("bloordyblop").IsOk() );
77 // test the ctype functions with the given locale
78 void XLocaleTestCase::TestCtypeFunctionsWith(const wxXLocale
& loc
)
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
) );
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
) );
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
) );
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
) );
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
) );
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
) );
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
) );
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
) );
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
) );
170 void XLocaleTestCase::TestCtypeFunctions()
172 TestCtypeFunctionsWith(wxCLocale
);
174 #ifdef wxHAS_XLOCALE_SUPPORT
175 wxXLocale
locFR(wxLANGUAGE_FRENCH
);
176 CPPUNIT_ASSERT( locFR
.IsOk() ); // doesn't make sense to continue otherwise
178 TestCtypeFunctionsWith(locFR
);
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
) );
187 #endif // wxUSE_XLOCALE