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