update dev300-m57
[ooovba.git] / sal / qa / rtl / locale / rtl_locale.cxx
blob910bde1dceedb68f3205db8e39ce2b135f4bd00e
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: rtl_locale.cxx,v $
10 * $Revision: 1.5 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
32 // MARKER(update_precomp.py): autogen include statement, do not remove
33 #include "precompiled_sal.hxx"
34 // autogenerated file with codegen.pl
36 #include <cppunit/simpleheader.hxx>
37 #include <rtl/locale.hxx>
38 #include <osl/thread.h>
40 namespace rtl_locale
42 // default locale for test purpose
43 void setDefaultLocale()
45 rtl::OLocale::setDefault(rtl::OUString::createFromAscii("de"), rtl::OUString::createFromAscii("DE"), /* rtl::OUString() */ rtl::OUString::createFromAscii("hochdeutsch") );
48 class getDefault : public CppUnit::TestFixture
50 public:
51 // initialise your test code values here.
52 void setUp()
56 void tearDown()
60 // insert your test code here.
61 void getDefault_000()
63 // this is demonstration code
64 // CPPUNIT_ASSERT_MESSAGE("a message", 1 == 1);
66 // due to the fact, we set the default locale at first, this test is no longer possible
67 // ::rtl::OLocale aLocale = ::rtl::OLocale::getDefault();
68 // CPPUNIT_ASSERT_MESSAGE("locale must be null", aLocale.getData() == NULL);
72 void getDefault_001()
74 // rtl::OLocale::setDefault(rtl::OUString::createFromAscii("de"), rtl::OUString::createFromAscii("DE"), rtl::OUString());
75 rtl::OLocale aLocale = ::rtl::OLocale::getDefault();
76 CPPUNIT_ASSERT_MESSAGE("locale must not null", aLocale.getData() != NULL);
79 // Change the following lines only, if you add, remove or rename
80 // member functions of the current class,
81 // because these macros are need by auto register mechanism.
83 CPPUNIT_TEST_SUITE(getDefault);
84 CPPUNIT_TEST(getDefault_000);
85 CPPUNIT_TEST(getDefault_001);
86 CPPUNIT_TEST_SUITE_END();
87 }; // class getDefault
90 class setDefault : public CppUnit::TestFixture
92 public:
93 // initialise your test code values here.
94 void setUp()
98 void tearDown()
100 setDefaultLocale();
103 // insert your test code here.
104 void setDefault_001()
106 rtl::OLocale::setDefault(rtl::OUString::createFromAscii("en"), rtl::OUString::createFromAscii("US"), rtl::OUString());
107 rtl::OLocale aLocale = ::rtl::OLocale::getDefault();
108 CPPUNIT_ASSERT_MESSAGE("locale must not null", aLocale.getData() != NULL);
110 // be sure to not GPF
113 // Change the following lines only, if you add, remove or rename
114 // member functions of the current class,
115 // because these macros are need by auto register mechanism.
117 CPPUNIT_TEST_SUITE(setDefault);
118 CPPUNIT_TEST(setDefault_001);
119 CPPUNIT_TEST_SUITE_END();
120 }; // class setDefault
123 class getLanguage : public CppUnit::TestFixture
125 public:
126 // initialise your test code values here.
127 void setUp()
131 void tearDown()
135 // insert your test code here.
136 void getLanguage_001()
138 rtl::OLocale aLocale = ::rtl::OLocale::getDefault();
139 rtl::OUString suLanguage = aLocale.getLanguage();
140 t_print("Language: %s\n", rtl::OUStringToOString(suLanguage, osl_getThreadTextEncoding()).getStr());
141 CPPUNIT_ASSERT_MESSAGE("locale language must be 'de'", suLanguage.equals(rtl::OUString::createFromAscii("de")));
143 void getLanguage_002()
145 rtl::OLocale aLocale = ::rtl::OLocale::getDefault();
146 rtl::OUString suLanguage = rtl_locale_getLanguage(aLocale.getData());
147 t_print("Language: %s\n", rtl::OUStringToOString(suLanguage, osl_getThreadTextEncoding()).getStr());
148 CPPUNIT_ASSERT_MESSAGE("locale language must be 'de'", suLanguage.equals(rtl::OUString::createFromAscii("de")));
151 // Change the following lines only, if you add, remove or rename
152 // member functions of the current class,
153 // because these macros are need by auto register mechanism.
155 CPPUNIT_TEST_SUITE(getLanguage);
156 CPPUNIT_TEST(getLanguage_001);
157 CPPUNIT_TEST(getLanguage_002);
158 CPPUNIT_TEST_SUITE_END();
159 }; // class getLanguage
162 class getCountry : public CppUnit::TestFixture
164 public:
165 // initialise your test code values here.
166 void setUp()
170 void tearDown()
174 // insert your test code here.
175 void getCountry_001()
177 rtl::OLocale aLocale = ::rtl::OLocale::getDefault();
178 rtl::OUString suCountry = aLocale.getCountry();
179 t_print("Country: %s\n", rtl::OUStringToOString(suCountry, osl_getThreadTextEncoding()).getStr());
180 CPPUNIT_ASSERT_MESSAGE("locale country must be 'DE'", suCountry.equals(rtl::OUString::createFromAscii("DE")));
182 void getCountry_002()
184 rtl::OLocale aLocale = ::rtl::OLocale::getDefault();
185 rtl::OUString suCountry = rtl_locale_getCountry(aLocale.getData());
186 t_print("Country: %s\n", rtl::OUStringToOString(suCountry, osl_getThreadTextEncoding()).getStr());
187 CPPUNIT_ASSERT_MESSAGE("locale country must be 'DE'", suCountry.equals(rtl::OUString::createFromAscii("DE")));
190 // Change the following lines only, if you add, remove or rename
191 // member functions of the current class,
192 // because these macros are need by auto register mechanism.
194 CPPUNIT_TEST_SUITE(getCountry);
195 CPPUNIT_TEST(getCountry_001);
196 CPPUNIT_TEST(getCountry_002);
197 CPPUNIT_TEST_SUITE_END();
198 }; // class getCountry
201 class getVariant : public CppUnit::TestFixture
203 public:
204 // initialise your test code values here.
205 void setUp()
209 void tearDown()
213 // insert your test code here.
214 void getVariant_001()
216 rtl::OLocale aLocale = ::rtl::OLocale::getDefault();
217 rtl::OUString suVariant = aLocale.getVariant();
218 t_print("Variant: %s\n", rtl::OUStringToOString(suVariant, osl_getThreadTextEncoding()).getStr());
219 CPPUNIT_ASSERT_MESSAGE("locale variant must be 'hochdeutsch'", suVariant.equals(rtl::OUString::createFromAscii("hochdeutsch")));
221 void getVariant_002()
223 rtl::OLocale aLocale = ::rtl::OLocale::getDefault();
224 rtl::OUString suVariant = rtl_locale_getVariant(aLocale.getData());
225 t_print("Variant: %s\n", rtl::OUStringToOString(suVariant, osl_getThreadTextEncoding()).getStr());
226 CPPUNIT_ASSERT_MESSAGE("locale variant must be 'hochdeutsch'", suVariant.equals(rtl::OUString::createFromAscii("hochdeutsch")));
229 // Change the following lines only, if you add, remove or rename
230 // member functions of the current class,
231 // because these macros are need by auto register mechanism.
233 CPPUNIT_TEST_SUITE(getVariant);
234 CPPUNIT_TEST(getVariant_001);
235 CPPUNIT_TEST(getVariant_002);
236 CPPUNIT_TEST_SUITE_END();
237 }; // class getVariant
240 class hashCode : public CppUnit::TestFixture
242 public:
243 // initialise your test code values here.
244 void setUp()
248 void tearDown()
252 // insert your test code here.
253 void hashCode_001()
255 rtl::OLocale aLocale = ::rtl::OLocale::getDefault();
256 sal_Int32 nHashCode = aLocale.hashCode();
257 t_print("Hashcode: %d\n", nHashCode);
258 CPPUNIT_ASSERT_MESSAGE("locale hashcode must be 3831", nHashCode != 0);
260 void hashCode_002()
262 rtl::OLocale aLocale = ::rtl::OLocale::getDefault();
263 sal_Int32 nHashCode = rtl_locale_hashCode(aLocale.getData());
264 t_print("Hashcode: %d\n", nHashCode);
265 CPPUNIT_ASSERT_MESSAGE("locale hashcode must be 3831", nHashCode != 0);
268 // Change the following lines only, if you add, remove or rename
269 // member functions of the current class,
270 // because these macros are need by auto register mechanism.
272 CPPUNIT_TEST_SUITE(hashCode);
273 CPPUNIT_TEST(hashCode_001);
274 CPPUNIT_TEST(hashCode_002);
275 CPPUNIT_TEST_SUITE_END();
276 }; // class hashCode
279 class equals : public CppUnit::TestFixture
281 public:
282 // initialise your test code values here.
283 void setUp()
287 void tearDown()
291 // insert your test code here.
292 void equals_001()
294 rtl::OLocale aLocale1 = rtl::OLocale::registerLocale(rtl::OUString::createFromAscii("en"), rtl::OUString::createFromAscii("US"), rtl::OUString());
295 rtl::OLocale aLocale2 = rtl::OLocale::registerLocale(rtl::OUString::createFromAscii("en"), rtl::OUString::createFromAscii("US"));
297 sal_Bool bLocaleAreEqual = sal_False;
298 bLocaleAreEqual = (aLocale1 == aLocale2);
300 CPPUNIT_ASSERT_MESSAGE("check operator ==()", bLocaleAreEqual == sal_True);
303 void equals_002()
305 rtl::OLocale aLocale1 = rtl::OLocale::registerLocale(rtl::OUString::createFromAscii("en"), rtl::OUString::createFromAscii("US"), rtl::OUString());
306 rtl::OLocale aLocale2 = rtl::OLocale::registerLocale(rtl::OUString::createFromAscii("en"), rtl::OUString::createFromAscii("US"));
308 sal_Int32 nEqual = rtl_locale_equals(aLocale1.getData(), aLocale2.getData());
309 t_print("rtl_locale_equals() result: %d\n", nEqual);
310 CPPUNIT_ASSERT(nEqual != 0);
313 // Change the following lines only, if you add, remove or rename
314 // member functions of the current class,
315 // because these macros are need by auto register mechanism.
317 CPPUNIT_TEST_SUITE(equals);
318 CPPUNIT_TEST(equals_001);
319 CPPUNIT_TEST(equals_002);
320 CPPUNIT_TEST_SUITE_END();
321 }; // class equals
323 // -----------------------------------------------------------------------------
324 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_locale::getDefault, "rtl_locale");
325 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_locale::setDefault, "rtl_locale");
326 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_locale::getLanguage, "rtl_locale");
327 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_locale::getCountry, "rtl_locale");
328 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_locale::getVariant, "rtl_locale");
329 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_locale::hashCode, "rtl_locale");
330 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_locale::equals, "rtl_locale");
331 } // namespace rtl_locale
334 // -----------------------------------------------------------------------------
336 // this macro creates an empty function, which will called by the RegisterAllFunctions()
337 // to let the user the possibility to also register some functions by hand.
338 // NOADDITIONAL;
340 void RegisterAdditionalFunctions(FktRegFuncPtr)
342 // start message
343 t_print("Initializing ...\n" );
344 rtl_locale::setDefaultLocale();
345 t_print("Initialization Done.\n" );