xref: /aoo42x/main/sal/qa/rtl/locale/rtl_locale.cxx (revision c346f426)
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 "gtest/gtest.h"
30 #include <rtl/locale.hxx>
31 #include <osl/thread.h>
32 
33 namespace rtl_locale
34 {
35     // default locale for test purpose
setDefaultLocale()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 ::testing::Test
42 {
43 public:
44     // initialise your test code values here.
SetUp()45     void SetUp()
46     {
47     }
48 
TearDown()49     void TearDown()
50     {
51     }
52 }; // class getDefault
53 
TEST_F(getDefault,getDefault_000)54 TEST_F(getDefault, getDefault_000)
55 {
56     // this is demonstration code
57     // ASSERT_TRUE(1 == 1) << "a message";
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     // ASSERT_TRUE(aLocale.getData() == NULL) << "locale must be null";
62 }
63 
TEST_F(getDefault,getDefault_001)64 TEST_F(getDefault, getDefault_001)
65 {
66     // rtl::OLocale::setDefault(rtl::OUString::createFromAscii("de"), rtl::OUString::createFromAscii("DE"), rtl::OUString());
67     rtl::OLocale aLocale = ::rtl::OLocale::getDefault();
68     ASSERT_TRUE(aLocale.getData() != NULL) << "locale must not be null";
69 }
70 
71 class setDefault : public ::testing::Test
72 {
73 public:
74     // initialise your test code values here.
SetUp()75     void SetUp()
76     {
77     }
78 
TearDown()79     void TearDown()
80     {
81         setDefaultLocale();
82     }
83 }; // class setDefault
84 
TEST_F(setDefault,setDefault_001)85 TEST_F(setDefault, setDefault_001)
86 {
87     rtl::OLocale::setDefault(rtl::OUString::createFromAscii("en"), rtl::OUString::createFromAscii("US"), rtl::OUString());
88     rtl::OLocale aLocale = ::rtl::OLocale::getDefault();
89     ASSERT_TRUE(aLocale.getData() != NULL) << "locale must not null";
90 
91     // be sure to not GPF
92 }
93 
94 
95 class getLanguage : public ::testing::Test
96 {
97 public:
SetUp()98     void SetUp()
99     {
100     }
101 
TearDown()102     void TearDown()
103     {
104     }
105 }; // class getLanguage
106 
TEST_F(getLanguage,getLanguage_001)107 TEST_F(getLanguage, getLanguage_001)
108 {
109     rtl::OLocale aLocale = ::rtl::OLocale::getDefault();
110     rtl::OUString suLanguage = aLocale.getLanguage();
111     printf("Language: %s\n", rtl::OUStringToOString(suLanguage, osl_getThreadTextEncoding()).getStr());
112     ASSERT_TRUE(suLanguage.equals(rtl::OUString::createFromAscii("de"))) << "locale language must be 'de'";
113 }
114 
TEST_F(getLanguage,getLanguage_002)115 TEST_F(getLanguage, getLanguage_002)
116 {
117     rtl::OLocale aLocale = ::rtl::OLocale::getDefault();
118     rtl::OUString suLanguage = rtl_locale_getLanguage(aLocale.getData());
119     printf("Language: %s\n", rtl::OUStringToOString(suLanguage, osl_getThreadTextEncoding()).getStr());
120     ASSERT_TRUE(suLanguage.equals(rtl::OUString::createFromAscii("de"))) << "locale language must be 'de'";
121 }
122 
123 
124 class getCountry : public ::testing::Test
125 {
126 public:
127     // initialise your test code values here.
SetUp()128     void SetUp()
129     {
130     }
131 
TearDown()132     void TearDown()
133     {
134     }
135 }; // class getCountry
136 
TEST_F(getCountry,getCountry_001)137 TEST_F(getCountry, getCountry_001)
138 {
139     rtl::OLocale aLocale = ::rtl::OLocale::getDefault();
140     rtl::OUString suCountry = aLocale.getCountry();
141     printf("Country: %s\n", rtl::OUStringToOString(suCountry, osl_getThreadTextEncoding()).getStr());
142     ASSERT_TRUE(suCountry.equals(rtl::OUString::createFromAscii("DE"))) << "locale country must be 'DE'";
143 }
144 
TEST_F(getCountry,getCountry_002)145 TEST_F(getCountry, getCountry_002)
146 {
147     rtl::OLocale aLocale = ::rtl::OLocale::getDefault();
148     rtl::OUString suCountry = rtl_locale_getCountry(aLocale.getData());
149     printf("Country: %s\n", rtl::OUStringToOString(suCountry, osl_getThreadTextEncoding()).getStr());
150     ASSERT_TRUE(suCountry.equals(rtl::OUString::createFromAscii("DE"))) << "locale country must be 'DE'";
151 }
152 
153 class getVariant : public ::testing::Test
154 {
155 public:
156     // initialise your test code values here.
SetUp()157     void SetUp()
158     {
159     }
160 
TearDown()161     void TearDown()
162     {
163     }
164 }; // class getVariant
165 
TEST_F(getVariant,getVariant_001)166 TEST_F(getVariant, getVariant_001)
167 {
168     rtl::OLocale aLocale = ::rtl::OLocale::getDefault();
169     rtl::OUString suVariant = aLocale.getVariant();
170     printf("Variant: %s\n", rtl::OUStringToOString(suVariant, osl_getThreadTextEncoding()).getStr());
171     ASSERT_TRUE(suVariant.equals(rtl::OUString::createFromAscii("hochdeutsch"))) << "locale variant must be 'hochdeutsch'";
172 }
173 
TEST_F(getVariant,getVariant_002)174 TEST_F(getVariant, getVariant_002)
175 {
176     rtl::OLocale aLocale = ::rtl::OLocale::getDefault();
177     rtl::OUString suVariant = rtl_locale_getVariant(aLocale.getData());
178     printf("Variant: %s\n", rtl::OUStringToOString(suVariant, osl_getThreadTextEncoding()).getStr());
179     ASSERT_TRUE(suVariant.equals(rtl::OUString::createFromAscii("hochdeutsch"))) << "locale variant must be 'hochdeutsch'";
180 }
181 
182 class hashCode : public ::testing::Test
183 {
184 public:
185     // initialise your test code values here.
SetUp()186     void SetUp()
187     {
188     }
189 
TearDown()190     void TearDown()
191     {
192     }
193 }; // class hashCode
194 
TEST_F(hashCode,hashCode_001)195 TEST_F(hashCode, hashCode_001)
196 {
197     rtl::OLocale aLocale = ::rtl::OLocale::getDefault();
198     sal_Int32 nHashCode = aLocale.hashCode();
199     printf("Hashcode: %d\n", nHashCode);
200     ASSERT_TRUE(nHashCode != 0) << "locale hashcode must be 3831";
201 }
202 
TEST_F(hashCode,hashCode_002)203 TEST_F(hashCode, hashCode_002)
204 {
205     rtl::OLocale aLocale = ::rtl::OLocale::getDefault();
206     sal_Int32 nHashCode = rtl_locale_hashCode(aLocale.getData());
207     printf("Hashcode: %d\n", nHashCode);
208     ASSERT_TRUE(nHashCode != 0) << "locale hashcode must be 3831";
209 }
210 
211 class equals : public ::testing::Test
212 {
213 public:
214     // initialise your test code values here.
SetUp()215     void SetUp()
216     {
217     }
218 
TearDown()219     void TearDown()
220     {
221     }
222 }; // class equals
223 
TEST_F(equals,equals_001)224 TEST_F(equals, equals_001)
225 {
226     rtl::OLocale aLocale1 = rtl::OLocale::registerLocale(rtl::OUString::createFromAscii("en"), rtl::OUString::createFromAscii("US"), rtl::OUString());
227     rtl::OLocale aLocale2 = rtl::OLocale::registerLocale(rtl::OUString::createFromAscii("en"), rtl::OUString::createFromAscii("US"));
228 
229     sal_Bool bLocaleAreEqual = sal_False;
230     bLocaleAreEqual = (aLocale1 == aLocale2);
231 
232     ASSERT_TRUE(bLocaleAreEqual == sal_True) << "check operator ==()";
233 }
234 
TEST_F(equals,equals_002)235 TEST_F(equals, equals_002)
236 {
237     rtl::OLocale aLocale1 = rtl::OLocale::registerLocale(rtl::OUString::createFromAscii("en"), rtl::OUString::createFromAscii("US"), rtl::OUString());
238     rtl::OLocale aLocale2 = rtl::OLocale::registerLocale(rtl::OUString::createFromAscii("en"), rtl::OUString::createFromAscii("US"));
239 
240     sal_Int32 nEqual = rtl_locale_equals(aLocale1.getData(), aLocale2.getData());
241     printf("rtl_locale_equals() result: %d\n", nEqual);
242     ASSERT_TRUE(nEqual != 0);
243 }
244 
245 } // namespace rtl_locale
246 
247 
248 // -----------------------------------------------------------------------------
249 
main(int argc,char ** argv)250 int main(int argc, char **argv)
251 {
252     // start message
253     printf("Initializing ...\n" );
254     rtl_locale::setDefaultLocale();
255     printf("Initialization Done.\n" );
256 
257     ::testing::InitGoogleTest(&argc, argv);
258     return RUN_ALL_TESTS();
259 }
260