xref: /aoo41x/main/sal/qa/rtl/locale/rtl_locale.cxx (revision cdf0e10c)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir 
29*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
30*cdf0e10cSrcweir #include "precompiled_sal.hxx"
31*cdf0e10cSrcweir // autogenerated file with codegen.pl
32*cdf0e10cSrcweir 
33*cdf0e10cSrcweir #include <testshl/simpleheader.hxx>
34*cdf0e10cSrcweir #include <rtl/locale.hxx>
35*cdf0e10cSrcweir #include <osl/thread.h>
36*cdf0e10cSrcweir 
37*cdf0e10cSrcweir namespace rtl_locale
38*cdf0e10cSrcweir {
39*cdf0e10cSrcweir     // default locale for test purpose
40*cdf0e10cSrcweir     void setDefaultLocale()
41*cdf0e10cSrcweir     {
42*cdf0e10cSrcweir         rtl::OLocale::setDefault(rtl::OUString::createFromAscii("de"), rtl::OUString::createFromAscii("DE"), /* rtl::OUString() */ rtl::OUString::createFromAscii("hochdeutsch") );
43*cdf0e10cSrcweir     }
44*cdf0e10cSrcweir 
45*cdf0e10cSrcweir class getDefault : public CppUnit::TestFixture
46*cdf0e10cSrcweir {
47*cdf0e10cSrcweir public:
48*cdf0e10cSrcweir     // initialise your test code values here.
49*cdf0e10cSrcweir     void setUp()
50*cdf0e10cSrcweir     {
51*cdf0e10cSrcweir     }
52*cdf0e10cSrcweir 
53*cdf0e10cSrcweir     void tearDown()
54*cdf0e10cSrcweir     {
55*cdf0e10cSrcweir     }
56*cdf0e10cSrcweir 
57*cdf0e10cSrcweir     // insert your test code here.
58*cdf0e10cSrcweir     void getDefault_000()
59*cdf0e10cSrcweir     {
60*cdf0e10cSrcweir         // this is demonstration code
61*cdf0e10cSrcweir         // CPPUNIT_ASSERT_MESSAGE("a message", 1 == 1);
62*cdf0e10cSrcweir 
63*cdf0e10cSrcweir         // due to the fact, we set the default locale at first, this test is no longer possible
64*cdf0e10cSrcweir    	// ::rtl::OLocale aLocale = ::rtl::OLocale::getDefault();
65*cdf0e10cSrcweir         // CPPUNIT_ASSERT_MESSAGE("locale must be null", aLocale.getData() == NULL);
66*cdf0e10cSrcweir 
67*cdf0e10cSrcweir     }
68*cdf0e10cSrcweir 
69*cdf0e10cSrcweir     void getDefault_001()
70*cdf0e10cSrcweir     {
71*cdf0e10cSrcweir         // rtl::OLocale::setDefault(rtl::OUString::createFromAscii("de"), rtl::OUString::createFromAscii("DE"), rtl::OUString());
72*cdf0e10cSrcweir    	rtl::OLocale aLocale = ::rtl::OLocale::getDefault();
73*cdf0e10cSrcweir         CPPUNIT_ASSERT_MESSAGE("locale must not null", aLocale.getData() != NULL);
74*cdf0e10cSrcweir     }
75*cdf0e10cSrcweir 
76*cdf0e10cSrcweir     // Change the following lines only, if you add, remove or rename
77*cdf0e10cSrcweir     // member functions of the current class,
78*cdf0e10cSrcweir     // because these macros are need by auto register mechanism.
79*cdf0e10cSrcweir 
80*cdf0e10cSrcweir     CPPUNIT_TEST_SUITE(getDefault);
81*cdf0e10cSrcweir     CPPUNIT_TEST(getDefault_000);
82*cdf0e10cSrcweir     CPPUNIT_TEST(getDefault_001);
83*cdf0e10cSrcweir     CPPUNIT_TEST_SUITE_END();
84*cdf0e10cSrcweir }; // class getDefault
85*cdf0e10cSrcweir 
86*cdf0e10cSrcweir 
87*cdf0e10cSrcweir class setDefault : public CppUnit::TestFixture
88*cdf0e10cSrcweir {
89*cdf0e10cSrcweir public:
90*cdf0e10cSrcweir     // initialise your test code values here.
91*cdf0e10cSrcweir     void setUp()
92*cdf0e10cSrcweir     {
93*cdf0e10cSrcweir     }
94*cdf0e10cSrcweir 
95*cdf0e10cSrcweir     void tearDown()
96*cdf0e10cSrcweir     {
97*cdf0e10cSrcweir         setDefaultLocale();
98*cdf0e10cSrcweir     }
99*cdf0e10cSrcweir 
100*cdf0e10cSrcweir     // insert your test code here.
101*cdf0e10cSrcweir     void setDefault_001()
102*cdf0e10cSrcweir     {
103*cdf0e10cSrcweir         rtl::OLocale::setDefault(rtl::OUString::createFromAscii("en"), rtl::OUString::createFromAscii("US"), rtl::OUString());
104*cdf0e10cSrcweir    	rtl::OLocale aLocale = ::rtl::OLocale::getDefault();
105*cdf0e10cSrcweir         CPPUNIT_ASSERT_MESSAGE("locale must not null", aLocale.getData() != NULL);
106*cdf0e10cSrcweir 
107*cdf0e10cSrcweir         // be sure to not GPF
108*cdf0e10cSrcweir     }
109*cdf0e10cSrcweir 
110*cdf0e10cSrcweir     // Change the following lines only, if you add, remove or rename
111*cdf0e10cSrcweir     // member functions of the current class,
112*cdf0e10cSrcweir     // because these macros are need by auto register mechanism.
113*cdf0e10cSrcweir 
114*cdf0e10cSrcweir     CPPUNIT_TEST_SUITE(setDefault);
115*cdf0e10cSrcweir     CPPUNIT_TEST(setDefault_001);
116*cdf0e10cSrcweir     CPPUNIT_TEST_SUITE_END();
117*cdf0e10cSrcweir }; // class setDefault
118*cdf0e10cSrcweir 
119*cdf0e10cSrcweir 
120*cdf0e10cSrcweir class getLanguage : public CppUnit::TestFixture
121*cdf0e10cSrcweir {
122*cdf0e10cSrcweir public:
123*cdf0e10cSrcweir     // initialise your test code values here.
124*cdf0e10cSrcweir     void setUp()
125*cdf0e10cSrcweir     {
126*cdf0e10cSrcweir     }
127*cdf0e10cSrcweir 
128*cdf0e10cSrcweir     void tearDown()
129*cdf0e10cSrcweir     {
130*cdf0e10cSrcweir     }
131*cdf0e10cSrcweir 
132*cdf0e10cSrcweir     // insert your test code here.
133*cdf0e10cSrcweir     void getLanguage_001()
134*cdf0e10cSrcweir     {
135*cdf0e10cSrcweir    	rtl::OLocale aLocale = ::rtl::OLocale::getDefault();
136*cdf0e10cSrcweir         rtl::OUString suLanguage = aLocale.getLanguage();
137*cdf0e10cSrcweir         t_print("Language: %s\n", rtl::OUStringToOString(suLanguage, osl_getThreadTextEncoding()).getStr());
138*cdf0e10cSrcweir         CPPUNIT_ASSERT_MESSAGE("locale language must be 'de'", suLanguage.equals(rtl::OUString::createFromAscii("de")));
139*cdf0e10cSrcweir     }
140*cdf0e10cSrcweir     void getLanguage_002()
141*cdf0e10cSrcweir     {
142*cdf0e10cSrcweir    	rtl::OLocale aLocale = ::rtl::OLocale::getDefault();
143*cdf0e10cSrcweir         rtl::OUString suLanguage = rtl_locale_getLanguage(aLocale.getData());
144*cdf0e10cSrcweir         t_print("Language: %s\n", rtl::OUStringToOString(suLanguage, osl_getThreadTextEncoding()).getStr());
145*cdf0e10cSrcweir         CPPUNIT_ASSERT_MESSAGE("locale language must be 'de'", suLanguage.equals(rtl::OUString::createFromAscii("de")));
146*cdf0e10cSrcweir     }
147*cdf0e10cSrcweir 
148*cdf0e10cSrcweir     // Change the following lines only, if you add, remove or rename
149*cdf0e10cSrcweir     // member functions of the current class,
150*cdf0e10cSrcweir     // because these macros are need by auto register mechanism.
151*cdf0e10cSrcweir 
152*cdf0e10cSrcweir     CPPUNIT_TEST_SUITE(getLanguage);
153*cdf0e10cSrcweir     CPPUNIT_TEST(getLanguage_001);
154*cdf0e10cSrcweir     CPPUNIT_TEST(getLanguage_002);
155*cdf0e10cSrcweir     CPPUNIT_TEST_SUITE_END();
156*cdf0e10cSrcweir }; // class getLanguage
157*cdf0e10cSrcweir 
158*cdf0e10cSrcweir 
159*cdf0e10cSrcweir class getCountry : public CppUnit::TestFixture
160*cdf0e10cSrcweir {
161*cdf0e10cSrcweir public:
162*cdf0e10cSrcweir     // initialise your test code values here.
163*cdf0e10cSrcweir     void setUp()
164*cdf0e10cSrcweir     {
165*cdf0e10cSrcweir     }
166*cdf0e10cSrcweir 
167*cdf0e10cSrcweir     void tearDown()
168*cdf0e10cSrcweir     {
169*cdf0e10cSrcweir     }
170*cdf0e10cSrcweir 
171*cdf0e10cSrcweir     // insert your test code here.
172*cdf0e10cSrcweir     void getCountry_001()
173*cdf0e10cSrcweir     {
174*cdf0e10cSrcweir    	rtl::OLocale aLocale = ::rtl::OLocale::getDefault();
175*cdf0e10cSrcweir         rtl::OUString suCountry = aLocale.getCountry();
176*cdf0e10cSrcweir         t_print("Country: %s\n", rtl::OUStringToOString(suCountry, osl_getThreadTextEncoding()).getStr());
177*cdf0e10cSrcweir         CPPUNIT_ASSERT_MESSAGE("locale country must be 'DE'", suCountry.equals(rtl::OUString::createFromAscii("DE")));
178*cdf0e10cSrcweir     }
179*cdf0e10cSrcweir     void getCountry_002()
180*cdf0e10cSrcweir     {
181*cdf0e10cSrcweir    	rtl::OLocale aLocale = ::rtl::OLocale::getDefault();
182*cdf0e10cSrcweir         rtl::OUString suCountry = rtl_locale_getCountry(aLocale.getData());
183*cdf0e10cSrcweir         t_print("Country: %s\n", rtl::OUStringToOString(suCountry, osl_getThreadTextEncoding()).getStr());
184*cdf0e10cSrcweir         CPPUNIT_ASSERT_MESSAGE("locale country must be 'DE'", suCountry.equals(rtl::OUString::createFromAscii("DE")));
185*cdf0e10cSrcweir     }
186*cdf0e10cSrcweir 
187*cdf0e10cSrcweir     // Change the following lines only, if you add, remove or rename
188*cdf0e10cSrcweir     // member functions of the current class,
189*cdf0e10cSrcweir     // because these macros are need by auto register mechanism.
190*cdf0e10cSrcweir 
191*cdf0e10cSrcweir     CPPUNIT_TEST_SUITE(getCountry);
192*cdf0e10cSrcweir     CPPUNIT_TEST(getCountry_001);
193*cdf0e10cSrcweir     CPPUNIT_TEST(getCountry_002);
194*cdf0e10cSrcweir     CPPUNIT_TEST_SUITE_END();
195*cdf0e10cSrcweir }; // class getCountry
196*cdf0e10cSrcweir 
197*cdf0e10cSrcweir 
198*cdf0e10cSrcweir class getVariant : public CppUnit::TestFixture
199*cdf0e10cSrcweir {
200*cdf0e10cSrcweir public:
201*cdf0e10cSrcweir     // initialise your test code values here.
202*cdf0e10cSrcweir     void setUp()
203*cdf0e10cSrcweir     {
204*cdf0e10cSrcweir     }
205*cdf0e10cSrcweir 
206*cdf0e10cSrcweir     void tearDown()
207*cdf0e10cSrcweir     {
208*cdf0e10cSrcweir     }
209*cdf0e10cSrcweir 
210*cdf0e10cSrcweir     // insert your test code here.
211*cdf0e10cSrcweir     void getVariant_001()
212*cdf0e10cSrcweir     {
213*cdf0e10cSrcweir    	rtl::OLocale aLocale = ::rtl::OLocale::getDefault();
214*cdf0e10cSrcweir         rtl::OUString suVariant = aLocale.getVariant();
215*cdf0e10cSrcweir         t_print("Variant: %s\n", rtl::OUStringToOString(suVariant, osl_getThreadTextEncoding()).getStr());
216*cdf0e10cSrcweir         CPPUNIT_ASSERT_MESSAGE("locale variant must be 'hochdeutsch'", suVariant.equals(rtl::OUString::createFromAscii("hochdeutsch")));
217*cdf0e10cSrcweir     }
218*cdf0e10cSrcweir     void getVariant_002()
219*cdf0e10cSrcweir     {
220*cdf0e10cSrcweir    	rtl::OLocale aLocale = ::rtl::OLocale::getDefault();
221*cdf0e10cSrcweir         rtl::OUString suVariant = rtl_locale_getVariant(aLocale.getData());
222*cdf0e10cSrcweir         t_print("Variant: %s\n", rtl::OUStringToOString(suVariant, osl_getThreadTextEncoding()).getStr());
223*cdf0e10cSrcweir         CPPUNIT_ASSERT_MESSAGE("locale variant must be 'hochdeutsch'", suVariant.equals(rtl::OUString::createFromAscii("hochdeutsch")));
224*cdf0e10cSrcweir     }
225*cdf0e10cSrcweir 
226*cdf0e10cSrcweir     // Change the following lines only, if you add, remove or rename
227*cdf0e10cSrcweir     // member functions of the current class,
228*cdf0e10cSrcweir     // because these macros are need by auto register mechanism.
229*cdf0e10cSrcweir 
230*cdf0e10cSrcweir     CPPUNIT_TEST_SUITE(getVariant);
231*cdf0e10cSrcweir     CPPUNIT_TEST(getVariant_001);
232*cdf0e10cSrcweir     CPPUNIT_TEST(getVariant_002);
233*cdf0e10cSrcweir     CPPUNIT_TEST_SUITE_END();
234*cdf0e10cSrcweir }; // class getVariant
235*cdf0e10cSrcweir 
236*cdf0e10cSrcweir 
237*cdf0e10cSrcweir class hashCode : public CppUnit::TestFixture
238*cdf0e10cSrcweir {
239*cdf0e10cSrcweir public:
240*cdf0e10cSrcweir     // initialise your test code values here.
241*cdf0e10cSrcweir     void setUp()
242*cdf0e10cSrcweir     {
243*cdf0e10cSrcweir     }
244*cdf0e10cSrcweir 
245*cdf0e10cSrcweir     void tearDown()
246*cdf0e10cSrcweir     {
247*cdf0e10cSrcweir     }
248*cdf0e10cSrcweir 
249*cdf0e10cSrcweir     // insert your test code here.
250*cdf0e10cSrcweir     void hashCode_001()
251*cdf0e10cSrcweir     {
252*cdf0e10cSrcweir    	rtl::OLocale aLocale = ::rtl::OLocale::getDefault();
253*cdf0e10cSrcweir         sal_Int32 nHashCode = aLocale.hashCode();
254*cdf0e10cSrcweir         t_print("Hashcode: %d\n", nHashCode);
255*cdf0e10cSrcweir         CPPUNIT_ASSERT_MESSAGE("locale hashcode must be 3831", nHashCode != 0);
256*cdf0e10cSrcweir     }
257*cdf0e10cSrcweir     void hashCode_002()
258*cdf0e10cSrcweir     {
259*cdf0e10cSrcweir    	rtl::OLocale aLocale = ::rtl::OLocale::getDefault();
260*cdf0e10cSrcweir         sal_Int32 nHashCode = rtl_locale_hashCode(aLocale.getData());
261*cdf0e10cSrcweir         t_print("Hashcode: %d\n", nHashCode);
262*cdf0e10cSrcweir         CPPUNIT_ASSERT_MESSAGE("locale hashcode must be 3831", nHashCode != 0);
263*cdf0e10cSrcweir     }
264*cdf0e10cSrcweir 
265*cdf0e10cSrcweir     // Change the following lines only, if you add, remove or rename
266*cdf0e10cSrcweir     // member functions of the current class,
267*cdf0e10cSrcweir     // because these macros are need by auto register mechanism.
268*cdf0e10cSrcweir 
269*cdf0e10cSrcweir     CPPUNIT_TEST_SUITE(hashCode);
270*cdf0e10cSrcweir     CPPUNIT_TEST(hashCode_001);
271*cdf0e10cSrcweir     CPPUNIT_TEST(hashCode_002);
272*cdf0e10cSrcweir     CPPUNIT_TEST_SUITE_END();
273*cdf0e10cSrcweir }; // class hashCode
274*cdf0e10cSrcweir 
275*cdf0e10cSrcweir 
276*cdf0e10cSrcweir class equals : public CppUnit::TestFixture
277*cdf0e10cSrcweir {
278*cdf0e10cSrcweir public:
279*cdf0e10cSrcweir     // initialise your test code values here.
280*cdf0e10cSrcweir     void setUp()
281*cdf0e10cSrcweir     {
282*cdf0e10cSrcweir     }
283*cdf0e10cSrcweir 
284*cdf0e10cSrcweir     void tearDown()
285*cdf0e10cSrcweir     {
286*cdf0e10cSrcweir     }
287*cdf0e10cSrcweir 
288*cdf0e10cSrcweir     // insert your test code here.
289*cdf0e10cSrcweir     void equals_001()
290*cdf0e10cSrcweir     {
291*cdf0e10cSrcweir         rtl::OLocale aLocale1 = rtl::OLocale::registerLocale(rtl::OUString::createFromAscii("en"), rtl::OUString::createFromAscii("US"), rtl::OUString());
292*cdf0e10cSrcweir         rtl::OLocale aLocale2 = rtl::OLocale::registerLocale(rtl::OUString::createFromAscii("en"), rtl::OUString::createFromAscii("US"));
293*cdf0e10cSrcweir 
294*cdf0e10cSrcweir         sal_Bool bLocaleAreEqual = sal_False;
295*cdf0e10cSrcweir         bLocaleAreEqual = (aLocale1 == aLocale2);
296*cdf0e10cSrcweir 
297*cdf0e10cSrcweir         CPPUNIT_ASSERT_MESSAGE("check operator ==()", bLocaleAreEqual == sal_True);
298*cdf0e10cSrcweir     }
299*cdf0e10cSrcweir 
300*cdf0e10cSrcweir     void equals_002()
301*cdf0e10cSrcweir     {
302*cdf0e10cSrcweir         rtl::OLocale aLocale1 = rtl::OLocale::registerLocale(rtl::OUString::createFromAscii("en"), rtl::OUString::createFromAscii("US"), rtl::OUString());
303*cdf0e10cSrcweir         rtl::OLocale aLocale2 = rtl::OLocale::registerLocale(rtl::OUString::createFromAscii("en"), rtl::OUString::createFromAscii("US"));
304*cdf0e10cSrcweir 
305*cdf0e10cSrcweir         sal_Int32 nEqual = rtl_locale_equals(aLocale1.getData(), aLocale2.getData());
306*cdf0e10cSrcweir         t_print("rtl_locale_equals() result: %d\n", nEqual);
307*cdf0e10cSrcweir         CPPUNIT_ASSERT(nEqual != 0);
308*cdf0e10cSrcweir     }
309*cdf0e10cSrcweir 
310*cdf0e10cSrcweir     // Change the following lines only, if you add, remove or rename
311*cdf0e10cSrcweir     // member functions of the current class,
312*cdf0e10cSrcweir     // because these macros are need by auto register mechanism.
313*cdf0e10cSrcweir 
314*cdf0e10cSrcweir     CPPUNIT_TEST_SUITE(equals);
315*cdf0e10cSrcweir     CPPUNIT_TEST(equals_001);
316*cdf0e10cSrcweir     CPPUNIT_TEST(equals_002);
317*cdf0e10cSrcweir     CPPUNIT_TEST_SUITE_END();
318*cdf0e10cSrcweir }; // class equals
319*cdf0e10cSrcweir 
320*cdf0e10cSrcweir // -----------------------------------------------------------------------------
321*cdf0e10cSrcweir CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_locale::getDefault, "rtl_locale");
322*cdf0e10cSrcweir CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_locale::setDefault, "rtl_locale");
323*cdf0e10cSrcweir CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_locale::getLanguage, "rtl_locale");
324*cdf0e10cSrcweir CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_locale::getCountry, "rtl_locale");
325*cdf0e10cSrcweir CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_locale::getVariant, "rtl_locale");
326*cdf0e10cSrcweir CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_locale::hashCode, "rtl_locale");
327*cdf0e10cSrcweir CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_locale::equals, "rtl_locale");
328*cdf0e10cSrcweir } // namespace rtl_locale
329*cdf0e10cSrcweir 
330*cdf0e10cSrcweir 
331*cdf0e10cSrcweir // -----------------------------------------------------------------------------
332*cdf0e10cSrcweir 
333*cdf0e10cSrcweir // this macro creates an empty function, which will called by the RegisterAllFunctions()
334*cdf0e10cSrcweir // to let the user the possibility to also register some functions by hand.
335*cdf0e10cSrcweir // NOADDITIONAL;
336*cdf0e10cSrcweir 
337*cdf0e10cSrcweir void RegisterAdditionalFunctions(FktRegFuncPtr)
338*cdf0e10cSrcweir {
339*cdf0e10cSrcweir     // start message
340*cdf0e10cSrcweir     t_print("Initializing ...\n" );
341*cdf0e10cSrcweir     rtl_locale::setDefaultLocale();
342*cdf0e10cSrcweir     t_print("Initialization Done.\n" );
343*cdf0e10cSrcweir }
344