1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
29 // MARKER(update_precomp.py): autogen include statement, do not remove
30 #include "precompiled_sal.hxx"
31 // autogenerated file with codegen.pl
33 #include <testshl/simpleheader.hxx>
34 #include <rtl/locale.hxx>
35 #include <osl/thread.h>
39 // default locale for test purpose
40 void setDefaultLocale()
42 rtl::OLocale::setDefault(rtl::OUString::createFromAscii("de"), rtl::OUString::createFromAscii("DE"), /* rtl::OUString() */ rtl::OUString::createFromAscii("hochdeutsch") );
45 class getDefault
: public CppUnit::TestFixture
48 // initialise your test code values here.
57 // insert your test code here.
60 // this is demonstration code
61 // CPPUNIT_ASSERT_MESSAGE("a message", 1 == 1);
63 // due to the fact, we set the default locale at first, this test is no longer possible
64 // ::rtl::OLocale aLocale = ::rtl::OLocale::getDefault();
65 // CPPUNIT_ASSERT_MESSAGE("locale must be null", aLocale.getData() == NULL);
71 // rtl::OLocale::setDefault(rtl::OUString::createFromAscii("de"), rtl::OUString::createFromAscii("DE"), rtl::OUString());
72 rtl::OLocale aLocale
= ::rtl::OLocale::getDefault();
73 CPPUNIT_ASSERT_MESSAGE("locale must not null", aLocale
.getData() != NULL
);
76 // Change the following lines only, if you add, remove or rename
77 // member functions of the current class,
78 // because these macros are need by auto register mechanism.
80 CPPUNIT_TEST_SUITE(getDefault
);
81 CPPUNIT_TEST(getDefault_000
);
82 CPPUNIT_TEST(getDefault_001
);
83 CPPUNIT_TEST_SUITE_END();
84 }; // class getDefault
87 class setDefault
: public CppUnit::TestFixture
90 // initialise your test code values here.
100 // insert your test code here.
101 void setDefault_001()
103 rtl::OLocale::setDefault(rtl::OUString::createFromAscii("en"), rtl::OUString::createFromAscii("US"), rtl::OUString());
104 rtl::OLocale aLocale
= ::rtl::OLocale::getDefault();
105 CPPUNIT_ASSERT_MESSAGE("locale must not null", aLocale
.getData() != NULL
);
107 // be sure to not GPF
110 // Change the following lines only, if you add, remove or rename
111 // member functions of the current class,
112 // because these macros are need by auto register mechanism.
114 CPPUNIT_TEST_SUITE(setDefault
);
115 CPPUNIT_TEST(setDefault_001
);
116 CPPUNIT_TEST_SUITE_END();
117 }; // class setDefault
120 class getLanguage
: public CppUnit::TestFixture
123 // initialise your test code values here.
132 // insert your test code here.
133 void getLanguage_001()
135 rtl::OLocale aLocale
= ::rtl::OLocale::getDefault();
136 rtl::OUString suLanguage
= aLocale
.getLanguage();
137 t_print("Language: %s\n", rtl::OUStringToOString(suLanguage
, osl_getThreadTextEncoding()).getStr());
138 CPPUNIT_ASSERT_MESSAGE("locale language must be 'de'", suLanguage
.equals(rtl::OUString::createFromAscii("de")));
140 void getLanguage_002()
142 rtl::OLocale aLocale
= ::rtl::OLocale::getDefault();
143 rtl::OUString suLanguage
= rtl_locale_getLanguage(aLocale
.getData());
144 t_print("Language: %s\n", rtl::OUStringToOString(suLanguage
, osl_getThreadTextEncoding()).getStr());
145 CPPUNIT_ASSERT_MESSAGE("locale language must be 'de'", suLanguage
.equals(rtl::OUString::createFromAscii("de")));
148 // Change the following lines only, if you add, remove or rename
149 // member functions of the current class,
150 // because these macros are need by auto register mechanism.
152 CPPUNIT_TEST_SUITE(getLanguage
);
153 CPPUNIT_TEST(getLanguage_001
);
154 CPPUNIT_TEST(getLanguage_002
);
155 CPPUNIT_TEST_SUITE_END();
156 }; // class getLanguage
159 class getCountry
: public CppUnit::TestFixture
162 // initialise your test code values here.
171 // insert your test code here.
172 void getCountry_001()
174 rtl::OLocale aLocale
= ::rtl::OLocale::getDefault();
175 rtl::OUString suCountry
= aLocale
.getCountry();
176 t_print("Country: %s\n", rtl::OUStringToOString(suCountry
, osl_getThreadTextEncoding()).getStr());
177 CPPUNIT_ASSERT_MESSAGE("locale country must be 'DE'", suCountry
.equals(rtl::OUString::createFromAscii("DE")));
179 void getCountry_002()
181 rtl::OLocale aLocale
= ::rtl::OLocale::getDefault();
182 rtl::OUString suCountry
= rtl_locale_getCountry(aLocale
.getData());
183 t_print("Country: %s\n", rtl::OUStringToOString(suCountry
, osl_getThreadTextEncoding()).getStr());
184 CPPUNIT_ASSERT_MESSAGE("locale country must be 'DE'", suCountry
.equals(rtl::OUString::createFromAscii("DE")));
187 // Change the following lines only, if you add, remove or rename
188 // member functions of the current class,
189 // because these macros are need by auto register mechanism.
191 CPPUNIT_TEST_SUITE(getCountry
);
192 CPPUNIT_TEST(getCountry_001
);
193 CPPUNIT_TEST(getCountry_002
);
194 CPPUNIT_TEST_SUITE_END();
195 }; // class getCountry
198 class getVariant
: public CppUnit::TestFixture
201 // initialise your test code values here.
210 // insert your test code here.
211 void getVariant_001()
213 rtl::OLocale aLocale
= ::rtl::OLocale::getDefault();
214 rtl::OUString suVariant
= aLocale
.getVariant();
215 t_print("Variant: %s\n", rtl::OUStringToOString(suVariant
, osl_getThreadTextEncoding()).getStr());
216 CPPUNIT_ASSERT_MESSAGE("locale variant must be 'hochdeutsch'", suVariant
.equals(rtl::OUString::createFromAscii("hochdeutsch")));
218 void getVariant_002()
220 rtl::OLocale aLocale
= ::rtl::OLocale::getDefault();
221 rtl::OUString suVariant
= rtl_locale_getVariant(aLocale
.getData());
222 t_print("Variant: %s\n", rtl::OUStringToOString(suVariant
, osl_getThreadTextEncoding()).getStr());
223 CPPUNIT_ASSERT_MESSAGE("locale variant must be 'hochdeutsch'", suVariant
.equals(rtl::OUString::createFromAscii("hochdeutsch")));
226 // Change the following lines only, if you add, remove or rename
227 // member functions of the current class,
228 // because these macros are need by auto register mechanism.
230 CPPUNIT_TEST_SUITE(getVariant
);
231 CPPUNIT_TEST(getVariant_001
);
232 CPPUNIT_TEST(getVariant_002
);
233 CPPUNIT_TEST_SUITE_END();
234 }; // class getVariant
237 class hashCode
: public CppUnit::TestFixture
240 // initialise your test code values here.
249 // insert your test code here.
252 rtl::OLocale aLocale
= ::rtl::OLocale::getDefault();
253 sal_Int32 nHashCode
= aLocale
.hashCode();
254 t_print("Hashcode: %d\n", nHashCode
);
255 CPPUNIT_ASSERT_MESSAGE("locale hashcode must be 3831", nHashCode
!= 0);
259 rtl::OLocale aLocale
= ::rtl::OLocale::getDefault();
260 sal_Int32 nHashCode
= rtl_locale_hashCode(aLocale
.getData());
261 t_print("Hashcode: %d\n", nHashCode
);
262 CPPUNIT_ASSERT_MESSAGE("locale hashcode must be 3831", nHashCode
!= 0);
265 // Change the following lines only, if you add, remove or rename
266 // member functions of the current class,
267 // because these macros are need by auto register mechanism.
269 CPPUNIT_TEST_SUITE(hashCode
);
270 CPPUNIT_TEST(hashCode_001
);
271 CPPUNIT_TEST(hashCode_002
);
272 CPPUNIT_TEST_SUITE_END();
276 class equals
: public CppUnit::TestFixture
279 // initialise your test code values here.
288 // insert your test code here.
291 rtl::OLocale aLocale1
= rtl::OLocale::registerLocale(rtl::OUString::createFromAscii("en"), rtl::OUString::createFromAscii("US"), rtl::OUString());
292 rtl::OLocale aLocale2
= rtl::OLocale::registerLocale(rtl::OUString::createFromAscii("en"), rtl::OUString::createFromAscii("US"));
294 sal_Bool bLocaleAreEqual
= sal_False
;
295 bLocaleAreEqual
= (aLocale1
== aLocale2
);
297 CPPUNIT_ASSERT_MESSAGE("check operator ==()", bLocaleAreEqual
== sal_True
);
302 rtl::OLocale aLocale1
= rtl::OLocale::registerLocale(rtl::OUString::createFromAscii("en"), rtl::OUString::createFromAscii("US"), rtl::OUString());
303 rtl::OLocale aLocale2
= rtl::OLocale::registerLocale(rtl::OUString::createFromAscii("en"), rtl::OUString::createFromAscii("US"));
305 sal_Int32 nEqual
= rtl_locale_equals(aLocale1
.getData(), aLocale2
.getData());
306 t_print("rtl_locale_equals() result: %d\n", nEqual
);
307 CPPUNIT_ASSERT(nEqual
!= 0);
310 // Change the following lines only, if you add, remove or rename
311 // member functions of the current class,
312 // because these macros are need by auto register mechanism.
314 CPPUNIT_TEST_SUITE(equals
);
315 CPPUNIT_TEST(equals_001
);
316 CPPUNIT_TEST(equals_002
);
317 CPPUNIT_TEST_SUITE_END();
320 // -----------------------------------------------------------------------------
321 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_locale::getDefault
, "rtl_locale");
322 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_locale::setDefault
, "rtl_locale");
323 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_locale::getLanguage
, "rtl_locale");
324 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_locale::getCountry
, "rtl_locale");
325 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_locale::getVariant
, "rtl_locale");
326 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_locale::hashCode
, "rtl_locale");
327 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(rtl_locale::equals
, "rtl_locale");
328 } // namespace rtl_locale
331 // -----------------------------------------------------------------------------
333 // this macro creates an empty function, which will called by the RegisterAllFunctions()
334 // to let the user the possibility to also register some functions by hand.
337 void RegisterAdditionalFunctions(FktRegFuncPtr
)
340 t_print("Initializing ...\n" );
341 rtl_locale::setDefaultLocale();
342 t_print("Initialization Done.\n" );