bump product version to 5.0.4.1
[LibreOffice.git] / sal / qa / rtl / locale / rtl_locale.cxx
blobef8d7e31a6563e40286b28c2d7fedb482b70ccca
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <sal/types.h>
21 #include <osl/thread.h>
22 #include <rtl/locale.h>
23 #include <rtl/ustring.hxx>
25 #include <cppunit/TestFixture.h>
26 #include <cppunit/extensions/HelperMacros.h>
27 #include <cppunit/plugin/TestPlugIn.h>
29 namespace rtl_locale
31 // default locale for test purpose
32 void setDefaultLocale()
34 rtl_locale_setDefault(rtl::OUString("de").getStr(), rtl::OUString("DE").getStr(), /* rtl::OUString() */ rtl::OUString("hochdeutsch").getStr() );
37 class getDefault : public CppUnit::TestFixture
39 public:
40 // initialise your test code values here.
41 void setUp() SAL_OVERRIDE
43 // start message
44 rtl_locale::setDefaultLocale();
47 void tearDown() SAL_OVERRIDE
51 void getDefault_001()
53 rtl_Locale* pData = rtl_locale_getDefault();
54 CPPUNIT_ASSERT_MESSAGE("locale must not null", pData != NULL);
57 // Change the following lines only, if you add, remove or rename
58 // member functions of the current class,
59 // because these macros are need by auto register mechanism.
61 CPPUNIT_TEST_SUITE(getDefault);
62 CPPUNIT_TEST(getDefault_001);
63 CPPUNIT_TEST_SUITE_END();
64 }; // class getDefault
66 class setDefault : public CppUnit::TestFixture
68 public:
69 // initialise your test code values here.
70 void setUp() SAL_OVERRIDE
72 // start message
73 rtl_locale::setDefaultLocale();
76 void tearDown() SAL_OVERRIDE
78 setDefaultLocale();
81 // insert your test code here.
82 void setDefault_001()
84 rtl_locale_setDefault(rtl::OUString("en").getStr(), rtl::OUString("US").getStr(), rtl::OUString().getStr());
85 rtl_Locale* pData = rtl_locale_getDefault();
86 CPPUNIT_ASSERT_MESSAGE("locale must not null", pData != NULL);
88 // be sure to not GPF
91 // Change the following lines only, if you add, remove or rename
92 // member functions of the current class,
93 // because these macros are need by auto register mechanism.
95 CPPUNIT_TEST_SUITE(setDefault);
96 CPPUNIT_TEST(setDefault_001);
97 CPPUNIT_TEST_SUITE_END();
98 }; // class setDefault
100 class getLanguage : public CppUnit::TestFixture
102 public:
103 // initialise your test code values here.
104 void setUp() SAL_OVERRIDE
106 // start message
107 rtl_locale::setDefaultLocale();
110 void tearDown() SAL_OVERRIDE
114 // insert your test code here.
115 void getLanguage_001()
117 rtl_Locale* pData = rtl_locale_getDefault();
118 rtl::OUString suLanguage = pData->Language;
119 CPPUNIT_ASSERT_MESSAGE( "locale language must be 'de'", suLanguage == "de" );
121 void getLanguage_002()
123 rtl_Locale* pData = rtl_locale_getDefault();
124 rtl::OUString suLanguage(rtl_locale_getLanguage(pData), SAL_NO_ACQUIRE);
125 CPPUNIT_ASSERT_MESSAGE( "locale language must be 'de'", suLanguage == "de" );
128 // Change the following lines only, if you add, remove or rename
129 // member functions of the current class,
130 // because these macros are need by auto register mechanism.
132 CPPUNIT_TEST_SUITE(getLanguage);
133 CPPUNIT_TEST(getLanguage_001);
134 CPPUNIT_TEST(getLanguage_002);
135 CPPUNIT_TEST_SUITE_END();
136 }; // class getLanguage
138 class getCountry : public CppUnit::TestFixture
140 public:
141 // initialise your test code values here.
142 void setUp() SAL_OVERRIDE
144 // start message
145 rtl_locale::setDefaultLocale();
148 void tearDown() SAL_OVERRIDE
152 // insert your test code here.
153 void getCountry_001()
155 rtl_Locale* pData = rtl_locale_getDefault();
156 rtl::OUString suCountry = pData->Country;
157 CPPUNIT_ASSERT_MESSAGE( "locale country must be 'DE'", suCountry == "DE" );
159 void getCountry_002()
161 rtl_Locale* pData = rtl_locale_getDefault();
162 rtl::OUString suCountry(rtl_locale_getCountry(pData), SAL_NO_ACQUIRE);
163 CPPUNIT_ASSERT_MESSAGE( "locale country must be 'DE'", suCountry == "DE" );
166 // Change the following lines only, if you add, remove or rename
167 // member functions of the current class,
168 // because these macros are need by auto register mechanism.
170 CPPUNIT_TEST_SUITE(getCountry);
171 CPPUNIT_TEST(getCountry_001);
172 CPPUNIT_TEST(getCountry_002);
173 CPPUNIT_TEST_SUITE_END();
174 }; // class getCountry
176 class getVariant : public CppUnit::TestFixture
178 public:
179 // initialise your test code values here.
180 void setUp() SAL_OVERRIDE
182 // start message
183 rtl_locale::setDefaultLocale();
186 void tearDown() SAL_OVERRIDE
190 // insert your test code here.
191 void getVariant_001()
193 rtl_Locale* pData = rtl_locale_getDefault();
194 rtl::OUString suVariant = pData->Variant;
195 CPPUNIT_ASSERT_MESSAGE( "locale variant must be 'hochdeutsch'", suVariant == "hochdeutsch" );
197 void getVariant_002()
199 rtl_Locale* pData = rtl_locale_getDefault();
200 rtl::OUString suVariant(rtl_locale_getVariant(pData), SAL_NO_ACQUIRE);
201 CPPUNIT_ASSERT_MESSAGE( "locale variant must be 'hochdeutsch'", suVariant == "hochdeutsch" );
204 // Change the following lines only, if you add, remove or rename
205 // member functions of the current class,
206 // because these macros are need by auto register mechanism.
208 CPPUNIT_TEST_SUITE(getVariant);
209 CPPUNIT_TEST(getVariant_001);
210 CPPUNIT_TEST(getVariant_002);
211 CPPUNIT_TEST_SUITE_END();
212 }; // class getVariant
214 class hashCode : public CppUnit::TestFixture
216 public:
217 // initialise your test code values here.
218 void setUp() SAL_OVERRIDE
220 // start message
221 rtl_locale::setDefaultLocale();
224 void tearDown() SAL_OVERRIDE
228 // insert your test code here.
229 void hashCode_001()
231 rtl_Locale* pData = rtl_locale_getDefault();
232 sal_Int32 nHashCode = pData->HashCode;
233 CPPUNIT_ASSERT_MESSAGE("locale hashcode must be 3831", nHashCode != 0);
235 void hashCode_002()
237 rtl_Locale* pData = rtl_locale_getDefault();
238 sal_Int32 nHashCode = rtl_locale_hashCode(pData);
239 CPPUNIT_ASSERT_MESSAGE("locale hashcode must be 3831", nHashCode != 0);
242 // Change the following lines only, if you add, remove or rename
243 // member functions of the current class,
244 // because these macros are need by auto register mechanism.
246 CPPUNIT_TEST_SUITE(hashCode);
247 CPPUNIT_TEST(hashCode_001);
248 CPPUNIT_TEST(hashCode_002);
249 CPPUNIT_TEST_SUITE_END();
250 }; // class hashCode
252 class equals : public CppUnit::TestFixture
254 public:
255 // initialise your test code values here.
256 void setUp() SAL_OVERRIDE
258 // start message
259 rtl_locale::setDefaultLocale();
262 void tearDown() SAL_OVERRIDE
266 // insert your test code here.
267 void equals_001()
269 rtl_Locale* pData1 = rtl_locale_register(rtl::OUString("en").getStr(), rtl::OUString("US").getStr(), rtl::OUString().getStr());
270 rtl_Locale* pData2 = rtl_locale_register(rtl::OUString("en").getStr(), rtl::OUString("US").getStr(), rtl::OUString().getStr());
272 bool bLocaleAreEqual = false;
273 bLocaleAreEqual = (pData1 == pData2);
275 CPPUNIT_ASSERT_MESSAGE("check operator ==()", bLocaleAreEqual);
278 void equals_002()
280 rtl_Locale* pData1 = rtl_locale_register(rtl::OUString("en").getStr(), rtl::OUString("US").getStr(), rtl::OUString().getStr());
281 rtl_Locale* pData2 = rtl_locale_register(rtl::OUString("en").getStr(), rtl::OUString("US").getStr(), rtl::OUString().getStr());
283 sal_Int32 nEqual = rtl_locale_equals(pData1, pData2);
284 CPPUNIT_ASSERT(nEqual != 0);
287 // Change the following lines only, if you add, remove or rename
288 // member functions of the current class,
289 // because these macros are need by auto register mechanism.
291 CPPUNIT_TEST_SUITE(equals);
292 CPPUNIT_TEST(equals_001);
293 CPPUNIT_TEST(equals_002);
294 CPPUNIT_TEST_SUITE_END();
295 }; // class equals
297 CPPUNIT_TEST_SUITE_REGISTRATION(rtl_locale::getDefault);
298 CPPUNIT_TEST_SUITE_REGISTRATION(rtl_locale::setDefault);
299 CPPUNIT_TEST_SUITE_REGISTRATION(rtl_locale::getLanguage);
300 CPPUNIT_TEST_SUITE_REGISTRATION(rtl_locale::getCountry);
301 CPPUNIT_TEST_SUITE_REGISTRATION(rtl_locale::getVariant);
302 CPPUNIT_TEST_SUITE_REGISTRATION(rtl_locale::hashCode);
303 CPPUNIT_TEST_SUITE_REGISTRATION(rtl_locale::equals);
304 } // namespace rtl_locale
306 // this macro creates an empty function, which will called by the RegisterAllFunctions()
307 // to let the user the possibility to also register some functions by hand.
309 CPPUNIT_PLUGIN_IMPLEMENT();
311 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */