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() );
68 CPPUNIT_ASSERT( wxXLocale("fr_FR").IsOk() );
69 CPPUNIT_ASSERT( wxXLocale("french").IsOk() );
71 CPPUNIT_ASSERT( !wxXLocale("bloordyblop").IsOk() );
74 // test the ctype functions with the given locale
75 void XLocaleTestCase
::TestCtypeFunctionsWith(const wxXLocale
& loc
)
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
) );
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
) );
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
) );
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
) );
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
) );
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
) );
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
) );
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
) );
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
) );
167 void XLocaleTestCase
::TestCtypeFunctions()
169 TestCtypeFunctionsWith(wxCLocale
);
171 #ifdef wxHAS_XLOCALE_SUPPORT
172 wxXLocale
locFR("fr_FR");
173 TestCtypeFunctionsWith(locFR
);
175 CPPUNIT_ASSERT( wxIsalpha_l('é', locFR
) );
176 CPPUNIT_ASSERT( wxIslower_l('é', locFR
) );
177 CPPUNIT_ASSERT( !wxIslower_l('É', locFR
) );
178 CPPUNIT_ASSERT( wxIsupper_l('É', locFR
) );
182 #endif // wxUSE_XLOCALE