1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 <rtl/locale.h>
22 #include <rtl/ustring.hxx>
24 #include <cppunit/TestFixture.h>
25 #include <cppunit/extensions/HelperMacros.h>
26 #include <cppunit/plugin/TestPlugIn.h>
30 // default locale for test purpose
31 static void setDefaultLocale()
33 rtl_locale_setDefault(OUString("de").getStr(), OUString("DE").getStr(), /* OUString() */ OUString("hochdeutsch").getStr() );
36 class getDefault
: public CppUnit::TestFixture
39 // initialise your test code values here.
43 rtl_locale::setDefaultLocale();
48 rtl_Locale
* pData
= rtl_locale_getDefault();
49 CPPUNIT_ASSERT_MESSAGE("locale must not null", pData
!= nullptr);
52 // Change the following lines only, if you add, remove or rename
53 // member functions of the current class,
54 // because these macros are need by auto register mechanism.
56 CPPUNIT_TEST_SUITE(getDefault
);
57 CPPUNIT_TEST(getDefault_001
);
58 CPPUNIT_TEST_SUITE_END();
59 }; // class getDefault
61 class setDefault
: public CppUnit::TestFixture
64 // initialise your test code values here.
68 rtl_locale::setDefaultLocale();
71 void tearDown() override
76 // insert your test code here.
79 rtl_locale_setDefault(OUString("en").getStr(), OUString("US").getStr(), OUString().getStr());
80 rtl_Locale
* pData
= rtl_locale_getDefault();
81 CPPUNIT_ASSERT_MESSAGE("locale must not null", pData
!= nullptr);
86 // Change the following lines only, if you add, remove or rename
87 // member functions of the current class,
88 // because these macros are need by auto register mechanism.
90 CPPUNIT_TEST_SUITE(setDefault
);
91 CPPUNIT_TEST(setDefault_001
);
92 CPPUNIT_TEST_SUITE_END();
93 }; // class setDefault
95 class getLanguage
: public CppUnit::TestFixture
98 // initialise your test code values here.
102 rtl_locale::setDefaultLocale();
105 // insert your test code here.
106 void getLanguage_001()
108 rtl_Locale
* pData
= rtl_locale_getDefault();
109 OUString suLanguage
= pData
->Language
;
110 CPPUNIT_ASSERT_EQUAL_MESSAGE( "locale language must be 'de'", OUString("de"), suLanguage
);
112 void getLanguage_002()
114 rtl_Locale
* pData
= rtl_locale_getDefault();
115 OUString
suLanguage(rtl_locale_getLanguage(pData
), SAL_NO_ACQUIRE
);
116 CPPUNIT_ASSERT_EQUAL_MESSAGE( "locale language must be 'de'", OUString("de"), suLanguage
);
119 // Change the following lines only, if you add, remove or rename
120 // member functions of the current class,
121 // because these macros are need by auto register mechanism.
123 CPPUNIT_TEST_SUITE(getLanguage
);
124 CPPUNIT_TEST(getLanguage_001
);
125 CPPUNIT_TEST(getLanguage_002
);
126 CPPUNIT_TEST_SUITE_END();
127 }; // class getLanguage
129 class getCountry
: public CppUnit::TestFixture
132 // initialise your test code values here.
133 void setUp() override
136 rtl_locale::setDefaultLocale();
139 // insert your test code here.
140 void getCountry_001()
142 rtl_Locale
* pData
= rtl_locale_getDefault();
143 OUString suCountry
= pData
->Country
;
144 CPPUNIT_ASSERT_EQUAL_MESSAGE( "locale country must be 'DE'", OUString("DE"), suCountry
);
146 void getCountry_002()
148 rtl_Locale
* pData
= rtl_locale_getDefault();
149 OUString
suCountry(rtl_locale_getCountry(pData
), SAL_NO_ACQUIRE
);
150 CPPUNIT_ASSERT_EQUAL_MESSAGE( "locale country must be 'DE'", OUString("DE"), suCountry
);
153 // Change the following lines only, if you add, remove or rename
154 // member functions of the current class,
155 // because these macros are need by auto register mechanism.
157 CPPUNIT_TEST_SUITE(getCountry
);
158 CPPUNIT_TEST(getCountry_001
);
159 CPPUNIT_TEST(getCountry_002
);
160 CPPUNIT_TEST_SUITE_END();
161 }; // class getCountry
163 class getVariant
: public CppUnit::TestFixture
166 // initialise your test code values here.
167 void setUp() override
170 rtl_locale::setDefaultLocale();
173 // insert your test code here.
174 void getVariant_001()
176 rtl_Locale
* pData
= rtl_locale_getDefault();
177 OUString suVariant
= pData
->Variant
;
178 CPPUNIT_ASSERT_EQUAL_MESSAGE( "locale variant must be 'hochdeutsch'", OUString("hochdeutsch"), suVariant
);
180 void getVariant_002()
182 rtl_Locale
* pData
= rtl_locale_getDefault();
183 OUString
suVariant(rtl_locale_getVariant(pData
), SAL_NO_ACQUIRE
);
184 CPPUNIT_ASSERT_EQUAL_MESSAGE( "locale variant must be 'hochdeutsch'", OUString("hochdeutsch"), suVariant
);
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(getVariant
);
192 CPPUNIT_TEST(getVariant_001
);
193 CPPUNIT_TEST(getVariant_002
);
194 CPPUNIT_TEST_SUITE_END();
195 }; // class getVariant
197 class hashCode
: public CppUnit::TestFixture
200 // initialise your test code values here.
201 void setUp() override
204 rtl_locale::setDefaultLocale();
207 // insert your test code here.
210 rtl_Locale
* pData
= rtl_locale_getDefault();
211 sal_Int32 nHashCode
= pData
->HashCode
;
212 CPPUNIT_ASSERT_MESSAGE("locale hashcode must be 3831", nHashCode
!= 0);
216 rtl_Locale
* pData
= rtl_locale_getDefault();
217 sal_Int32 nHashCode
= rtl_locale_hashCode(pData
);
218 CPPUNIT_ASSERT_MESSAGE("locale hashcode must be 3831", nHashCode
!= 0);
221 // Change the following lines only, if you add, remove or rename
222 // member functions of the current class,
223 // because these macros are need by auto register mechanism.
225 CPPUNIT_TEST_SUITE(hashCode
);
226 CPPUNIT_TEST(hashCode_001
);
227 CPPUNIT_TEST(hashCode_002
);
228 CPPUNIT_TEST_SUITE_END();
231 class equals
: public CppUnit::TestFixture
234 // initialise your test code values here.
235 void setUp() override
238 rtl_locale::setDefaultLocale();
241 // insert your test code here.
244 rtl_Locale
* pData1
= rtl_locale_register(OUString("en").getStr(), OUString("US").getStr(), OUString().getStr());
245 rtl_Locale
* pData2
= rtl_locale_register(OUString("en").getStr(), OUString("US").getStr(), OUString().getStr());
247 bool bLocaleAreEqual
= (pData1
== pData2
);
249 CPPUNIT_ASSERT_MESSAGE("check operator ==()", bLocaleAreEqual
);
254 rtl_Locale
* pData1
= rtl_locale_register(OUString("en").getStr(), OUString("US").getStr(), OUString().getStr());
255 rtl_Locale
* pData2
= rtl_locale_register(OUString("en").getStr(), OUString("US").getStr(), OUString().getStr());
257 sal_Int32 nEqual
= rtl_locale_equals(pData1
, pData2
);
258 CPPUNIT_ASSERT(nEqual
!= 0);
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.
265 CPPUNIT_TEST_SUITE(equals
);
266 CPPUNIT_TEST(equals_001
);
267 CPPUNIT_TEST(equals_002
);
268 CPPUNIT_TEST_SUITE_END();
271 CPPUNIT_TEST_SUITE_REGISTRATION(rtl_locale::getDefault
);
272 CPPUNIT_TEST_SUITE_REGISTRATION(rtl_locale::setDefault
);
273 CPPUNIT_TEST_SUITE_REGISTRATION(rtl_locale::getLanguage
);
274 CPPUNIT_TEST_SUITE_REGISTRATION(rtl_locale::getCountry
);
275 CPPUNIT_TEST_SUITE_REGISTRATION(rtl_locale::getVariant
);
276 CPPUNIT_TEST_SUITE_REGISTRATION(rtl_locale::hashCode
);
277 CPPUNIT_TEST_SUITE_REGISTRATION(rtl_locale::equals
);
278 } // namespace rtl_locale
280 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */