1 /****************************************************************************
2 **
3 ** Copyright (C) 2015 The Qt Company Ltd.
4 ** Contact: http://www.qt.io/licensing/
5 **
6 ** This file is part of the test suite of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and The Qt Company. For licensing terms
14 ** and conditions see http://www.qt.io/terms-conditions. For further
15 ** information use the contact form at http://www.qt.io/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 or version 3 as published by the Free
20 ** Software Foundation and appearing in the file LICENSE.LGPLv21 and
21 ** LICENSE.LGPLv3 included in the packaging of this file. Please review the
22 ** following information to ensure the GNU Lesser General Public License
23 ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
24 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
25 **
26 ** As a special exception, The Qt Company gives you certain additional
27 ** rights. These rights are described in The Qt Company LGPL Exception
28 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
29 **
30 ** GNU General Public License Usage
31 ** Alternatively, this file may be used under the terms of the GNU
32 ** General Public License version 3.0 as published by the Free Software
33 ** Foundation and appearing in the file LICENSE.GPL included in the
34 ** packaging of this file. Please review the following information to
35 ** ensure the GNU General Public License version 3.0 requirements will be
36 ** met: http://www.gnu.org/copyleft/gpl.html.
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41
42
43 #include <QtTest/QtTest>
44 #include <math.h>
45 #include <qglobal.h>
46 #include <qdir.h>
47 #include <qtextcodec.h>
48 #include <qdatetime.h>
49 #include <float.h>
50
51 #include <qlocale.h>
52 #include <qnumeric.h>
53
54 #ifdef Q_OS_LINUX
55 # include <fenv.h>
56 #endif
57
58 #ifdef Q_OS_WINCE
59 #include <qcoreapplication.h>
60 #include <windows.h> // needed for GetUserDefaultLCID
61 #define _control87 _controlfp
GetThreadLocale(void)62 extern "C" DWORD GetThreadLocale(void) {
63 return GetUserDefaultLCID();
64 }
65
66 #endif
67
68 #if defined(Q_OS_UNIX) && !defined(Q_OS_MAC)
69 # include <stdlib.h>
70 #endif
71
72 #if defined(Q_OS_SYMBIAN)
73 # include <e32std.h>
74 # include <private/qcore_symbian_p.h>
75 #endif
76
77 Q_DECLARE_METATYPE(qlonglong)
78 Q_DECLARE_METATYPE(QDate)
79 Q_DECLARE_METATYPE(QLocale::FormatType)
80
81 //TESTED_CLASS=
82 //TESTED_FILES=
83
84 class tst_QLocale : public QObject
85 {
86 Q_OBJECT
87
88 public:
89 tst_QLocale();
90
91 private slots:
92 void initTestCase();
93 void windowsDefaultLocale();
94 #ifdef Q_OS_MAC
95 void macDefaultLocale();
96 #endif
97
98 void ctor();
99 void emptyCtor();
100 void unixLocaleName();
101 void double_conversion_data();
102 void double_conversion();
103 void long_long_conversion_data();
104 void long_long_conversion();
105 void long_long_conversion_extra();
106 void testInfAndNan();
107 void fpExceptions();
108 void negativeZero();
109 void dayOfWeek();
110 void dayOfWeek_data();
111 void formatDate();
112 void formatDate_data();
113 void formatTime();
114 void formatTime_data();
115 void formatDateTime();
116 void formatDateTime_data();
117 void toDateTime_data();
118 void toDateTime();
119 void negativeNumbers();
120 void numberOptions();
121 void testNames_data();
122 void testNames();
123 void dayName_data();
124 void dayName();
125 void standaloneDayName_data();
126 void standaloneDayName();
127 void underflowOverflow();
128 void measurementSystems_data();
129 void measurementSystems();
130 void systemMeasurementSystems_data();
131 void systemMeasurementSystems();
132
133 void dateFormat();
134 void timeFormat();
135 void dateTimeFormat();
136 void monthName();
137 void standaloneMonthName();
138
139 // QSystemLocale tests
140 void queryDateTime();
141 void queryMeasureSystem_data();
142 void queryMeasureSystem();
143
144 // defaultNumberingSystem test
145 void defaultNumeringSystem();
146
147 #if defined(Q_OS_SYMBIAN)
148 void symbianSystemLocale();
149 #endif
150
151 void ampm();
152 void currency();
153 void quoteString();
154 void uiLanguages();
155 void weekendDays();
156 void listPatterns();
157
158 private:
159 QString m_decimal, m_thousand, m_sdate, m_ldate, m_time;
160 QString m_sysLocaleApp;
161 };
162
tst_QLocale()163 tst_QLocale::tst_QLocale()
164 {
165 qRegisterMetaType<QLocale::FormatType>("QLocale::FormatType");
166 }
167
initTestCase()168 void tst_QLocale::initTestCase()
169 {
170 QDir workingDirectory = QDir::current();
171 QString sysLocaleApp = QLatin1String("syslocaleapp/syslocaleapp");
172 // Windows: cd up to be able to locate the binary of the sub-process.
173 #ifdef Q_OS_WIN
174 sysLocaleApp.append(QLatin1String(".exe"));
175 if (workingDirectory.absolutePath().endsWith(QLatin1String("/debug"), Qt::CaseInsensitive)
176 || workingDirectory.absolutePath().endsWith(QLatin1String("/release"), Qt::CaseInsensitive)) {
177 QVERIFY(workingDirectory.cdUp());
178 QVERIFY(QDir::setCurrent(workingDirectory.absolutePath()));
179 }
180 #endif
181 m_sysLocaleApp = workingDirectory.absoluteFilePath(sysLocaleApp);
182 QVERIFY2(QFileInfo(m_sysLocaleApp).exists(),
183 qPrintable(QString::fromLatin1("SysLocalApp executable '%1' does not exist!")
184 .arg(QDir::toNativeSeparators(m_sysLocaleApp))));
185 }
186
ctor()187 void tst_QLocale::ctor()
188 {
189 #ifdef Q_OS_WINCE
190 int argc = 1;
191 char argv[20] = "tst_qlocale.exe";
192 QCoreApplication app(argc, (char**)&argv);
193 #endif
194 QLocale default_locale = QLocale::system();
195 QLocale::Language default_lang = default_locale.language();
196 QLocale::Country default_country = default_locale.country();
197
198 qDebug("Default: %s/%s", QLocale::languageToString(default_lang).toLatin1().constData(),
199 QLocale::countryToString(default_country).toLatin1().constData());
200
201 {
202 QLocale l;
203 QVERIFY(l.language() == default_lang);
204 QVERIFY(l.country() == default_country);
205 }
206
207 #define TEST_CTOR(req_lang, req_country, exp_lang, exp_country) \
208 { \
209 QLocale l(QLocale::req_lang, QLocale::req_country); \
210 QCOMPARE(l.language(), exp_lang); \
211 QCOMPARE(l.country(), exp_country); \
212 }
213 {
214 QLocale l(QLocale::C, QLocale::AnyCountry);
215 QCOMPARE(l.language(), QLocale::C);
216 QCOMPARE(l.country(), QLocale::AnyCountry);
217 }
218 TEST_CTOR(AnyLanguage, AnyCountry, default_lang, default_country)
219 TEST_CTOR(C, AnyCountry, QLocale::C, QLocale::AnyCountry)
220 TEST_CTOR(Aymara, AnyCountry, default_lang, default_country)
221 TEST_CTOR(Aymara, France, default_lang, default_country)
222
223 TEST_CTOR(English, AnyCountry, QLocale::English, QLocale::UnitedStates)
224 TEST_CTOR(English, UnitedStates, QLocale::English, QLocale::UnitedStates)
225 TEST_CTOR(English, France, QLocale::English, QLocale::UnitedStates)
226 TEST_CTOR(English, UnitedKingdom, QLocale::English, QLocale::UnitedKingdom)
227
228 TEST_CTOR(French, France, QLocale::French, QLocale::France)
229 TEST_CTOR(C, France, QLocale::C, QLocale::AnyCountry)
230 TEST_CTOR(Spanish, LatinAmericaAndTheCaribbean, QLocale::Spanish, QLocale::LatinAmericaAndTheCaribbean)
231
232 QLocale::setDefault(QLocale(QLocale::English, QLocale::France));
233
234 {
235 QLocale l;
236 QVERIFY(l.language() == QLocale::English);
237 QVERIFY(l.country() == QLocale::UnitedStates);
238 }
239
240 TEST_CTOR(French, France, QLocale::French, QLocale::France)
241 TEST_CTOR(English, UnitedKingdom, QLocale::English, QLocale::UnitedKingdom)
242
243 TEST_CTOR(French, France, QLocale::French, QLocale::France)
244 TEST_CTOR(C, AnyCountry, QLocale::C, QLocale::AnyCountry)
245 TEST_CTOR(C, France, QLocale::C, QLocale::AnyCountry)
246 TEST_CTOR(Aymara, AnyCountry, QLocale::English, QLocale::UnitedStates)
247
248 QLocale::setDefault(QLocale(QLocale::English, QLocale::UnitedKingdom));
249
250 {
251 QLocale l;
252 QVERIFY(l.language() == QLocale::English);
253 QVERIFY(l.country() == QLocale::UnitedKingdom);
254 }
255
256 TEST_CTOR(French, France, QLocale::French, QLocale::France)
257 TEST_CTOR(English, UnitedKingdom, QLocale::English, QLocale::UnitedKingdom)
258
259 TEST_CTOR(C, AnyCountry, QLocale::C, QLocale::AnyCountry)
260 TEST_CTOR(C, France, QLocale::C, QLocale::AnyCountry)
261
262 QLocale::setDefault(QLocale(QLocale::Aymara, QLocale::France));
263
264 {
265 QLocale l;
266 QVERIFY(l.language() == QLocale::English);
267 QVERIFY(l.country() == QLocale::UnitedKingdom);
268 }
269
270 TEST_CTOR(Aymara, AnyCountry, QLocale::English, QLocale::UnitedKingdom)
271 TEST_CTOR(Aymara, France, QLocale::English, QLocale::UnitedKingdom)
272
273 TEST_CTOR(English, AnyCountry, QLocale::English, QLocale::UnitedStates)
274 TEST_CTOR(English, UnitedStates, QLocale::English, QLocale::UnitedStates)
275 TEST_CTOR(English, France, QLocale::English, QLocale::UnitedStates)
276 TEST_CTOR(English, UnitedKingdom, QLocale::English, QLocale::UnitedKingdom)
277
278 TEST_CTOR(French, France, QLocale::French, QLocale::France)
279 TEST_CTOR(C, AnyCountry, QLocale::C, QLocale::AnyCountry)
280 TEST_CTOR(C, France, QLocale::C, QLocale::AnyCountry)
281
282 QLocale::setDefault(QLocale(QLocale::Aymara, QLocale::AnyCountry));
283
284 {
285 QLocale l;
286 QVERIFY(l.language() == QLocale::English);
287 QVERIFY(l.country() == QLocale::UnitedKingdom);
288 }
289
290
291 TEST_CTOR(Aymara, AnyCountry, QLocale::English, QLocale::UnitedKingdom)
292 TEST_CTOR(Aymara, France, QLocale::English, QLocale::UnitedKingdom)
293
294 TEST_CTOR(English, AnyCountry, QLocale::English, QLocale::UnitedStates)
295 TEST_CTOR(English, UnitedStates, QLocale::English, QLocale::UnitedStates)
296 TEST_CTOR(English, France, QLocale::English, QLocale::UnitedStates)
297 TEST_CTOR(English, UnitedKingdom, QLocale::English, QLocale::UnitedKingdom)
298
299 TEST_CTOR(French, France, QLocale::French, QLocale::France)
300 TEST_CTOR(C, AnyCountry, QLocale::C, QLocale::AnyCountry)
301 TEST_CTOR(C, France, QLocale::C, QLocale::AnyCountry)
302
303 TEST_CTOR(Arabic, AnyCountry, QLocale::Arabic, QLocale::SaudiArabia)
304 TEST_CTOR(Dutch, AnyCountry, QLocale::Dutch, QLocale::Netherlands)
305 TEST_CTOR(German, AnyCountry, QLocale::German, QLocale::Germany)
306 TEST_CTOR(Greek, AnyCountry, QLocale::Greek, QLocale::Greece)
307 TEST_CTOR(Malay, AnyCountry, QLocale::Malay, QLocale::Malaysia)
308 TEST_CTOR(Persian, AnyCountry, QLocale::Persian, QLocale::Iran)
309 TEST_CTOR(Portuguese, AnyCountry, QLocale::Portuguese, QLocale::Portugal)
310 TEST_CTOR(Serbian, AnyCountry, QLocale::Serbian, QLocale::SerbiaAndMontenegro)
311 TEST_CTOR(Somali, AnyCountry, QLocale::Somali, QLocale::Somalia)
312 TEST_CTOR(Spanish, AnyCountry, QLocale::Spanish, QLocale::Spain)
313 TEST_CTOR(Swedish, AnyCountry, QLocale::Swedish, QLocale::Sweden)
314 TEST_CTOR(Uzbek, AnyCountry, QLocale::Uzbek, QLocale::Uzbekistan)
315
316 #undef TEST_CTOR
317
318 #define TEST_CTOR(req_lc, exp_lang, exp_country) \
319 { \
320 QLocale l(req_lc); \
321 QVERIFY2(l.language() == QLocale::exp_lang \
322 && l.country() == QLocale::exp_country, \
323 QString("requested: \"" + QString(req_lc) + "\", got: " \
324 + QLocale::languageToString(l.language()) \
325 + "/" + QLocale::countryToString(l.country())).toLatin1().constData()); \
326 }
327
328 QLocale::setDefault(QLocale(QLocale::C));
329
330 TEST_CTOR("C", C, AnyCountry)
331 TEST_CTOR("bla", C, AnyCountry)
332 TEST_CTOR("zz", C, AnyCountry)
333 TEST_CTOR("zz_zz", C, AnyCountry)
334 TEST_CTOR("zz...", C, AnyCountry)
335 TEST_CTOR("", C, AnyCountry)
336 TEST_CTOR("en/", C, AnyCountry)
337 TEST_CTOR(QString::null, C, AnyCountry)
338 TEST_CTOR("en", English, UnitedStates)
339 TEST_CTOR("en", English, UnitedStates)
340 TEST_CTOR("en.", English, UnitedStates)
341 TEST_CTOR("en@", English, UnitedStates)
342 TEST_CTOR("en.@", English, UnitedStates)
343 TEST_CTOR("en_", English, UnitedStates)
344 TEST_CTOR("en_U", English, UnitedStates)
345 TEST_CTOR("en_.", English, UnitedStates)
346 TEST_CTOR("en_.@", English, UnitedStates)
347 TEST_CTOR("en.bla", English, UnitedStates)
348 TEST_CTOR("en@bla", English, UnitedStates)
349 TEST_CTOR("en_blaaa", English, UnitedStates)
350 TEST_CTOR("en_zz", English, UnitedStates)
351 TEST_CTOR("en_GB", English, UnitedKingdom)
352 TEST_CTOR("en_GB.bla", English, UnitedKingdom)
353 TEST_CTOR("en_GB@.bla", English, UnitedKingdom)
354 TEST_CTOR("en_GB@bla", English, UnitedKingdom)
355 TEST_CTOR("en-GB", English, UnitedKingdom)
356 TEST_CTOR("en-GB@bla", English, UnitedKingdom)
357
358 QVERIFY(QLocale::Norwegian == QLocale::NorwegianBokmal);
359 TEST_CTOR("no", Norwegian, Norway)
360 TEST_CTOR("nb", Norwegian, Norway)
361 TEST_CTOR("nn", NorwegianNynorsk, Norway)
362 TEST_CTOR("no_NO", Norwegian, Norway)
363 TEST_CTOR("nb_NO", Norwegian, Norway)
364 TEST_CTOR("nn_NO", NorwegianNynorsk, Norway)
365 TEST_CTOR("es_ES", Spanish, Spain)
366 TEST_CTOR("es_419", Spanish, LatinAmericaAndTheCaribbean)
367 TEST_CTOR("es-419", Spanish, LatinAmericaAndTheCaribbean)
368 TEST_CTOR("fr_MA", French, Morocco)
369
370 // test default countries for languages
371 TEST_CTOR("zh", Chinese, China)
372 TEST_CTOR("zh-Hans", Chinese, China)
373 TEST_CTOR("mn", Mongolian, Mongolia)
374 TEST_CTOR("ne", Nepali, Nepal)
375
376 #undef TEST_CTOR
377 #define TEST_CTOR(req_lc, exp_lang, exp_script, exp_country) \
378 { \
379 QLocale l(req_lc); \
380 QVERIFY2(l.language() == QLocale::exp_lang \
381 && l.script() == QLocale::exp_script \
382 && l.country() == QLocale::exp_country, \
383 QString("requested: \"" + QString(req_lc) + "\", got: " \
384 + QLocale::languageToString(l.language()) \
385 + "/" + QLocale::scriptToString(l.script()) \
386 + "/" + QLocale::countryToString(l.country())).toLatin1().constData()); \
387 }
388
389 TEST_CTOR("zh_CN", Chinese, AnyScript, China)
390 TEST_CTOR("zh_Hans_CN", Chinese, SimplifiedHanScript, China)
391 TEST_CTOR("zh_Hans", Chinese, SimplifiedHanScript, China)
392 TEST_CTOR("zh_Hant", Chinese, TraditionalHanScript, HongKong)
393 TEST_CTOR("zh_Hans_MO", Chinese, SimplifiedHanScript, Macau)
394 TEST_CTOR("zh_Hant_MO", Chinese, TraditionalHanScript, Macau)
395 TEST_CTOR("az_Latn_AZ", Azerbaijani, LatinScript, Azerbaijan)
396 TEST_CTOR("ha_NG", Hausa, AnyScript, Nigeria)
397 TEST_CTOR("ha_Latn_NG", Hausa, LatinScript, Nigeria)
398
399 #undef TEST_CTOR
400 }
401
emptyCtor()402 void tst_QLocale::emptyCtor()
403 {
404 #if defined(Q_OS_WINCE) || defined(Q_OS_SYMBIAN)
405 QSKIP("Uses unsupported Windows CE / Symbian QProcess functionality (std streams, env)", SkipAll);
406 #endif
407 #if defined(QT_NO_PROCESS)
408 QSKIP("Qt was compiled with QT_NO_PROCESS", SkipAll);
409 #else
410 #define TEST_CTOR(req_lc, exp_str) \
411 { \
412 /* Test constructor without arguments. Needs separate process */ \
413 /* because of caching of the system locale. */ \
414 QProcess process; \
415 process.setEnvironment(QStringList(env) << QString("LANG=%1").arg(req_lc)); \
416 process.start(m_sysLocaleApp); \
417 QVERIFY(process.waitForStarted()); \
418 process.waitForReadyRead(); \
419 QString ret = QString(process.readAll()); \
420 process.waitForFinished(); \
421 QVERIFY2(!ret.isEmpty(), "Cannot launch external process"); \
422 QVERIFY2(QString(exp_str) == ret, QString("Expected: " + QString(exp_str) + ", got: " \
423 + ret + ". Requested: " + QString(req_lc)).toLatin1().constData()); \
424 }
425
426 // Get an environment free of any locale-related variables
427 QStringList env;
428 foreach (QString const& entry, QProcess::systemEnvironment()) {
429 if (entry.startsWith("LANG=") || entry.startsWith("LC_"))
430 continue;
431 env << entry;
432 }
433
434 // Get default locale.
435 QProcess p;
436 p.setEnvironment(env);
437 p.start("syslocaleapp/syslocaleapp");
438 p.waitForReadyRead();
439 QString defaultLoc = QString(p.readAll());
440 p.waitForFinished();
441
442 TEST_CTOR("C", "C")
443 TEST_CTOR("bla", "C")
444 TEST_CTOR("zz", "C")
445 TEST_CTOR("zz_zz", "C")
446 TEST_CTOR("zz...", "C")
447 TEST_CTOR("en", "en_US")
448 TEST_CTOR("en", "en_US")
449 TEST_CTOR("en.", "en_US")
450 TEST_CTOR("en@", "en_US")
451 TEST_CTOR("en.@", "en_US")
452 TEST_CTOR("en_", "en_US")
453 TEST_CTOR("en_.", "en_US")
454 TEST_CTOR("en_.@", "en_US")
455 TEST_CTOR("en.bla", "en_US")
456 TEST_CTOR("en@bla", "en_US")
457 TEST_CTOR("en_blaaa", "en_US")
458 TEST_CTOR("en_zz", "en_US")
459 TEST_CTOR("en_GB", "en_GB")
460 TEST_CTOR("en_GB.bla", "en_GB")
461 TEST_CTOR("en_GB@.bla", "en_GB")
462 TEST_CTOR("en_GB@bla", "en_GB")
463 TEST_CTOR("de", "de_DE")
464
465 QVERIFY(QLocale::Norwegian == QLocale::NorwegianBokmal);
466 TEST_CTOR("no", "nb_NO")
467 TEST_CTOR("nb", "nb_NO")
468 TEST_CTOR("nn", "nn_NO")
469 TEST_CTOR("no_NO", "nb_NO")
470 TEST_CTOR("nb_NO", "nb_NO")
471 TEST_CTOR("nn_NO", "nn_NO")
472
473 TEST_CTOR("DE", "de_DE");
474 TEST_CTOR("EN", "en_US");
475
476 TEST_CTOR("en/", defaultLoc)
477 TEST_CTOR("asdfghj", defaultLoc);
478 TEST_CTOR("123456", defaultLoc);
479
480 #undef TEST_CTOR
481 #endif
482 }
483
unixLocaleName()484 void tst_QLocale::unixLocaleName()
485 {
486 #define TEST_NAME(req_lang, req_country, exp_name) \
487 { \
488 QLocale l(QLocale::req_lang, QLocale::req_country); \
489 QCOMPARE(l.name(), QString(exp_name)); \
490 }
491
492 QLocale::setDefault(QLocale(QLocale::C));
493
494 TEST_NAME(C, AnyCountry, "C")
495 TEST_NAME(English, AnyCountry, "en_US")
496 TEST_NAME(English, UnitedKingdom, "en_GB")
497 TEST_NAME(Aymara, UnitedKingdom, "C")
498
499 #undef TEST_NAME
500 }
501
double_conversion_data()502 void tst_QLocale::double_conversion_data()
503 {
504 QTest::addColumn<QString>("locale_name");
505 QTest::addColumn<QString>("num_str");
506 QTest::addColumn<bool>("good");
507 QTest::addColumn<double>("num");
508
509 QTest::newRow("C 1") << QString("C") << QString("1") << true << 1.0;
510 QTest::newRow("C 1.0") << QString("C") << QString("1.0") << true << 1.0;
511 QTest::newRow("C 1.234") << QString("C") << QString("1.234") << true << 1.234;
512 QTest::newRow("C 1.234e-10") << QString("C") << QString("1.234e-10") << true << 1.234e-10;
513 QTest::newRow("C 1.234E10") << QString("C") << QString("1.234E10") << true << 1.234e10;
514 QTest::newRow("C 1e10") << QString("C") << QString("1e10") << true << 1.0e10;
515 QTest::newRow("C 1") << QString("C") << QString(" 1") << true << 1.0;
516 QTest::newRow("C 1") << QString("C") << QString(" 1") << true << 1.0;
517 QTest::newRow("C 1 ") << QString("C") << QString("1 ") << true << 1.0;
518 QTest::newRow("C 1 ") << QString("C") << QString("1 ") << true << 1.0;
519
520 QTest::newRow("C 1,") << QString("C") << QString("1,") << false << 0.0;
521 QTest::newRow("C 1,2") << QString("C") << QString("1,2") << false << 0.0;
522 QTest::newRow("C 1,23") << QString("C") << QString("1,23") << false << 0.0;
523 QTest::newRow("C 1,234") << QString("C") << QString("1,234") << true << 1234.0;
524 QTest::newRow("C 1,234,") << QString("C") << QString("1,234,") << false << 0.0;
525 QTest::newRow("C 1,234,5") << QString("C") << QString("1,234,5") << false << 0.0;
526 QTest::newRow("C 1,234,56") << QString("C") << QString("1,234,56") << false << 0.0;
527 QTest::newRow("C 1,234,567") << QString("C") << QString("1,234,567") << true << 1234567.0;
528 QTest::newRow("C 1,234,567.") << QString("C") << QString("1,234,567.") << true << 1234567.0;
529 QTest::newRow("C 1,234,567.8") << QString("C") << QString("1,234,567.8")<< true << 1234567.8;
530 QTest::newRow("C 1,234567.8") << QString("C") << QString("1,234567.8") << false << 0.0;
531 QTest::newRow("C 12,34567.8") << QString("C") << QString("12,34567.8") << false << 0.0;
532 QTest::newRow("C 1234,567.8") << QString("C") << QString("1234,567.8") << false << 0.0;
533 QTest::newRow("C 1234567.8") << QString("C") << QString("1234567.8") << true << 1234567.8;
534 QTest::newRow("C ,") << QString("C") << QString(",") << false << 0.0;
535 QTest::newRow("C ,123") << QString("C") << QString(",123") << false << 0.0;
536 QTest::newRow("C ,3") << QString("C") << QString(",3") << false << 0.0;
537 QTest::newRow("C , 3") << QString("C") << QString(", 3") << false << 0.0;
538 QTest::newRow("C , 3") << QString("C") << QString(", 3") << false << 0.0;
539 QTest::newRow("C , 3.2") << QString("C") << QString(", 3.2") << false << 0.0;
540 QTest::newRow("C , 3.2e2") << QString("C") << QString(", 3.2e2") << false << 0.0;
541 QTest::newRow("C , e2") << QString("C") << QString(", e2") << false << 0.0;
542 QTest::newRow("C 1,,234") << QString("C") << QString("1,,234") << false << 0.0;
543
544 QTest::newRow("C empty") << QString("C") << QString("") << false << 0.0;
545 QTest::newRow("C null") << QString("C") << QString() << false << 0.0;
546 QTest::newRow("C .") << QString("C") << QString(".") << false << 0.0;
547 QTest::newRow("C 1e") << QString("C") << QString("1e") << false << 0.0;
548 QTest::newRow("C 1,0") << QString("C") << QString("1,0") << false << 0.0;
549 QTest::newRow("C 1,000") << QString("C") << QString("1,000") << true << 1000.0;
550 QTest::newRow("C 1,000e-6") << QString("C") << QString("1,000e-6") << true << 1000.0e-6;
551 QTest::newRow("C 1e1.0") << QString("C") << QString("1e1.0") << false << 0.0;
552 QTest::newRow("C 1e+") << QString("C") << QString("1e+") << false << 0.0;
553 QTest::newRow("C 1e-") << QString("C") << QString("1e-") << false << 0.0;
554
555 QTest::newRow("C .1") << QString("C") << QString(".1") << true << 0.1;
556 QTest::newRow("C -.1") << QString("C") << QString("-.1") << true << -0.1;
557 QTest::newRow("C 1.") << QString("C") << QString("1.") << true << 1.0;
558 QTest::newRow("C 1.E10") << QString("C") << QString("1.E10") << true << 1.0e10;
559 QTest::newRow("C 1e+10") << QString("C") << QString("1e+10") << true << 1.0e+10;
560
561 QTest::newRow("de_DE 1.") << QString("de_DE") << QString("1.") << false << 0.0;
562 QTest::newRow("de_DE 1.2") << QString("de_DE") << QString("1.2") << false << 0.0;
563 QTest::newRow("de_DE 1.23") << QString("de_DE") << QString("1.23") << false << 0.0;
564 QTest::newRow("de_DE 1.234") << QString("de_DE") << QString("1.234") << true << 1234.0;
565 QTest::newRow("de_DE 1.234,") << QString("de_DE") << QString("1.234.") << false << 0.0;
566 QTest::newRow("de_DE 1.234.5") << QString("de_DE") << QString("1.234.5") << false << 0.0;
567 QTest::newRow("de_DE 1.234.56") << QString("de_DE") << QString("1.234.56") << false << 0.0;
568 QTest::newRow("de_DE 1.234.567") << QString("de_DE") << QString("1.234.567") << true << 1234567.0;
569 QTest::newRow("de_DE 1.234.567,") << QString("de_DE") << QString("1.234.567,") << true << 1234567.0;
570 QTest::newRow("de_DE 1.234.567,8") << QString("de_DE") << QString("1.234.567,8")<< true << 1234567.8;
571 QTest::newRow("de_DE 1.234567,8") << QString("de_DE") << QString("1.234567,8") << false << 0.0;
572 QTest::newRow("de_DE 12.34567,8") << QString("de_DE") << QString("12.34567,8") << false << 0.0;
573 QTest::newRow("de_DE 1234.567,8") << QString("de_DE") << QString("1234.567,8") << false << 0.0;
574 QTest::newRow("de_DE 1234567,8") << QString("de_DE") << QString("1234567,8") << true << 1234567.8;
575 QTest::newRow("de_DE .123") << QString("de_DE") << QString(".123") << false << 0.0;
576 QTest::newRow("de_DE .3") << QString("de_DE") << QString(".3") << false << 0.0;
577 QTest::newRow("de_DE . 3") << QString("de_DE") << QString(". 3") << false << 0.0;
578 QTest::newRow("de_DE . 3") << QString("de_DE") << QString(". 3") << false << 0.0;
579 QTest::newRow("de_DE . 3,2") << QString("de_DE") << QString(". 3,2") << false << 0.0;
580 QTest::newRow("de_DE . 3,2e2") << QString("de_DE") << QString(". 3,2e2") << false << 0.0;
581 QTest::newRow("de_DE . e2") << QString("de_DE") << QString(". e2") << false << 0.0;
582 QTest::newRow("de_DE 1..234") << QString("de_DE") << QString("1..234") << false << 0.0;
583
584 QTest::newRow("de_DE 1") << QString("de_DE") << QString("1") << true << 1.0;
585 QTest::newRow("de_DE 1.0") << QString("de_DE") << QString("1.0") << false << 0.0;
586 QTest::newRow("de_DE 1.234e-10") << QString("de_DE") << QString("1.234e-10") << true << 1234.0e-10;
587 QTest::newRow("de_DE 1.234E10") << QString("de_DE") << QString("1.234E10") << true << 1234.0e10;
588 QTest::newRow("de_DE 1e10") << QString("de_DE") << QString("1e10") << true << 1.0e10;
589 QTest::newRow("de_DE .1") << QString("de_DE") << QString(".1") << false << 0.0;
590 QTest::newRow("de_DE -.1") << QString("de_DE") << QString("-.1") << false << 0.0;
591 QTest::newRow("de_DE 1.E10") << QString("de_DE") << QString("1.E10") << false << 0.0;
592 QTest::newRow("de_DE 1e+10") << QString("de_DE") << QString("1e+10") << true << 1.0e+10;
593
594 QTest::newRow("de_DE 1,0") << QString("de_DE") << QString("1,0") << true << 1.0;
595 QTest::newRow("de_DE 1,234") << QString("de_DE") << QString("1,234") << true << 1.234;
596 QTest::newRow("de_DE 1,234e-10") << QString("de_DE") << QString("1,234e-10") << true << 1.234e-10;
597 QTest::newRow("de_DE 1,234E10") << QString("de_DE") << QString("1,234E10") << true << 1.234e10;
598 QTest::newRow("de_DE ,1") << QString("de_DE") << QString(",1") << true << 0.1;
599 QTest::newRow("de_DE -,1") << QString("de_DE") << QString("-,1") << true << -0.1;
600 QTest::newRow("de_DE 1,") << QString("de_DE") << QString("1,") << true << 1.0;
601 QTest::newRow("de_DE 1,E10") << QString("de_DE") << QString("1,E10") << true << 1.0e10;
602
603 QTest::newRow("de_DE empty") << QString("de_DE") << QString("") << false << 0.0;
604 QTest::newRow("de_DE null") << QString("de_DE") << QString() << false << 0.0;
605 QTest::newRow("de_DE .") << QString("de_DE") << QString(".") << false << 0.0;
606 QTest::newRow("de_DE 1e") << QString("de_DE") << QString("1e") << false << 0.0;
607 QTest::newRow("de_DE 1e1.0") << QString("de_DE") << QString("1e1.0") << false << 0.0;
608 QTest::newRow("de_DE 1e+") << QString("de_DE") << QString("1e+") << false << 0.0;
609 QTest::newRow("de_DE 1e-") << QString("de_DE") << QString("1e-") << false << 0.0;
610
611 QTest::newRow("C 9,876543") << QString("C") << QString("9,876543") << false << 0.0;
612 QTest::newRow("C 9,876543.2") << QString("C") << QString("9,876543.2") << false << 0.0;
613 QTest::newRow("C 9,876543e-2") << QString("C") << QString("9,876543e-2") << false << 0.0;
614 QTest::newRow("C 9,876543.0e-2") << QString("C") << QString("9,876543.0e-2") << false << 0.0;
615
616 QTest::newRow("de_DE 9.876543") << QString("de_DE") << QString("9876.543") << false << 0.0;
617 QTest::newRow("de_DE 9.876543,2") << QString("de_DE") << QString("9.876543,2") << false << 0.0;
618 QTest::newRow("de_DE 9.876543e-2") << QString("de_DE") << QString("9.876543e-2") << false << 0.0;
619 QTest::newRow("de_DE 9.876543,0e-2") << QString("de_DE") << QString("9.876543,0e-2") << false << 0.0;
620 QTest::newRow("de_DE 9.876543e--2") << QString("de_DE") << QString("9.876543e")+QChar(8722)+QString("2") << false << 0.0;
621 QTest::newRow("de_DE 9.876543,0e--2") << QString("de_DE") << QString("9.876543,0e")+QChar(8722)+QString("2") << false << 0.0;
622 }
623
double_conversion()624 void tst_QLocale::double_conversion()
625 {
626 #define MY_DOUBLE_EPSILON (2.22045e-16)
627
628 QFETCH(QString, locale_name);
629 QFETCH(QString, num_str);
630 QFETCH(bool, good);
631 QFETCH(double, num);
632
633 QLocale locale(locale_name);
634 QCOMPARE(locale.name(), locale_name);
635
636 bool ok;
637 double d = locale.toDouble(num_str, &ok);
638 QCOMPARE(ok, good);
639
640 if (ok) {
641 double diff = d - num;
642 if (diff < 0)
643 diff = -diff;
644 QVERIFY(diff <= MY_DOUBLE_EPSILON);
645 }
646 }
647
long_long_conversion_data()648 void tst_QLocale::long_long_conversion_data()
649 {
650 QTest::addColumn<QString>("locale_name");
651 QTest::addColumn<QString>("num_str");
652 QTest::addColumn<bool>("good");
653 QTest::addColumn<qlonglong>("num");
654
655 QTest::newRow("C null") << QString("C") << QString() << false << (qlonglong) 0;
656 QTest::newRow("C empty") << QString("C") << QString("") << false << (qlonglong) 0;
657 QTest::newRow("C 1") << QString("C") << "1" << true << (qlonglong) 1;
658 QTest::newRow("C 1,") << QString("C") << "1," << false << (qlonglong) 0;
659 QTest::newRow("C 1,2") << QString("C") << "1,2" << false << (qlonglong) 0;
660 QTest::newRow("C 1,23") << QString("C") << "1,23" << false << (qlonglong) 0;
661 QTest::newRow("C 1,234") << QString("C") << "1,234" << true << (qlonglong) 1234;
662 QTest::newRow("C 1234567") << QString("C") << "1234567"<< true << (qlonglong) 1234567;
663 QTest::newRow("C 1,234567") << QString("C") << "1,234567"<< false << (qlonglong) 0;
664 QTest::newRow("C 12,34567") << QString("C") << "12,34567"<< false << (qlonglong) 0;
665 QTest::newRow("C 123,4567") << QString("C") << "123,4567"<< false << (qlonglong) 0;
666 QTest::newRow("C 1234,567") << QString("C") << "1234,567"<< false << (qlonglong) 0;
667 QTest::newRow("C 12345,67") << QString("C") << "12345,67"<< false << (qlonglong) 0;
668 QTest::newRow("C 123456,7") << QString("C") << "123456,7"<< false << (qlonglong) 0;
669 QTest::newRow("C 1,234,567") << QString("C")<< "1,234,567"<< true << (qlonglong) 1234567;
670
671 QTest::newRow("de_DE 1") << QString("de_DE") << "1" << true << (qlonglong) 1;
672 QTest::newRow("de_DE 1.") << QString("de_DE") << "1." << false << (qlonglong) 0;
673 QTest::newRow("de_DE 1.2") << QString("de_DE") << "1.2" << false << (qlonglong) 0;
674 QTest::newRow("de_DE 1.23") << QString("de_DE") << "1.23" << false << (qlonglong) 0;
675 QTest::newRow("de_DE 1.234") << QString("de_DE") << "1.234" << true << (qlonglong) 1234;
676 QTest::newRow("de_DE 1234567") << QString("de_DE") << "1234567"<< true << (qlonglong) 1234567;
677 QTest::newRow("de_DE 1.234567") << QString("de_DE") << "1.234567"<< false << (qlonglong) 0;
678 QTest::newRow("de_DE 12.34567") << QString("de_DE") << "12.34567"<< false << (qlonglong) 0;
679 QTest::newRow("de_DE 123.4567") << QString("de_DE") << "123.4567"<< false << (qlonglong) 0;
680 QTest::newRow("de_DE 1234.567") << QString("de_DE") << "1234.567"<< false << (qlonglong) 0;
681 QTest::newRow("de_DE 12345.67") << QString("de_DE") << "12345.67"<< false << (qlonglong) 0;
682 QTest::newRow("de_DE 123456.7") << QString("de_DE") << "123456.7"<< false << (qlonglong) 0;
683 QTest::newRow("de_DE 1.234.567") << QString("de_DE")<< "1.234.567"<< true << (qlonglong) 1234567;
684 QTest::newRow("de_DE 1.234.567 ldspcs") << QString("de_DE")<< " 1.234.567" << true << (qlonglong) 1234567;
685 QTest::newRow("de_DE 1.234.567 trspcs") << QString("de_DE")<< "1.234.567 "<< true << (qlonglong) 1234567;
686 QTest::newRow("de_DE 1.234.567 ldtrspcs") << QString("de_DE")<< " 1.234.567 "<< true << (qlonglong) 1234567;
687
688 // test that space is also accepted whenever QLocale::groupSeparator() == 0xa0 (which looks like space).
689 QTest::newRow("nb_NO 123 groupsep") << QString("nb_NO")<< QString("1")+QChar(0xa0)+QString("234") << true << (qlonglong) 1234;
690 QTest::newRow("nb_NO 123 groupsep_space") << QString("nb_NO")<< QString("1")+QChar(0x20)+QString("234") << true << (qlonglong) 1234;
691
692 QTest::newRow("nb_NO 123 ldspcs") << QString("nb_NO")<< " 123" << true << (qlonglong) 123;
693 QTest::newRow("nb_NO 123 trspcs") << QString("nb_NO")<< "123 "<< true << (qlonglong) 123;
694 QTest::newRow("nb_NO 123 ldtrspcs") << QString("nb_NO")<< " 123 "<< true << (qlonglong) 123;
695
696 QTest::newRow("C 1234") << QString("C") << " 1234" << true << (qlonglong) 1234;
697 QTest::newRow("C 1234 ") << QString("C") << "1234 " << true << (qlonglong) 1234;
698 QTest::newRow("C 1234 ") << QString("C") << " 1234 " << true << (qlonglong) 1234;
699 }
700
long_long_conversion()701 void tst_QLocale::long_long_conversion()
702 {
703 QFETCH(QString, locale_name);
704 QFETCH(QString, num_str);
705 QFETCH(bool, good);
706 QFETCH(qlonglong, num);
707
708 QLocale locale(locale_name);
709 QCOMPARE(locale.name(), locale_name);
710
711 bool ok;
712 qlonglong l = locale.toLongLong(num_str, &ok);
713 QCOMPARE(ok, good);
714
715 if (ok) {
716 QCOMPARE(l, num);
717 }
718 }
719
long_long_conversion_extra()720 void tst_QLocale::long_long_conversion_extra()
721 {
722 QLocale l(QLocale::C);
723 QCOMPARE(l.toString((qlonglong)1), QString("1"));
724 QCOMPARE(l.toString((qlonglong)12), QString("12"));
725 QCOMPARE(l.toString((qlonglong)123), QString("123"));
726 QCOMPARE(l.toString((qlonglong)1234), QString("1,234"));
727 QCOMPARE(l.toString((qlonglong)12345), QString("12,345"));
728 QCOMPARE(l.toString((qlonglong)-1), QString("-1"));
729 QCOMPARE(l.toString((qlonglong)-12), QString("-12"));
730 QCOMPARE(l.toString((qlonglong)-123), QString("-123"));
731 QCOMPARE(l.toString((qlonglong)-1234), QString("-1,234"));
732 QCOMPARE(l.toString((qlonglong)-12345), QString("-12,345"));
733 QCOMPARE(l.toString((qulonglong)1), QString("1"));
734 QCOMPARE(l.toString((qulonglong)12), QString("12"));
735 QCOMPARE(l.toString((qulonglong)123), QString("123"));
736 QCOMPARE(l.toString((qulonglong)1234), QString("1,234"));
737 QCOMPARE(l.toString((qulonglong)12345), QString("12,345"));
738 }
739
740 /*
741 void tst_QLocale::languageToString()
742 {
743 }
744
745 void tst_QLocale::setDefault()
746 {
747 }
748 */
749
testInfAndNan()750 void tst_QLocale::testInfAndNan()
751 {
752 double neginf = log(0.0);
753 double nan = sqrt(-1.0);
754
755 #ifdef Q_OS_WIN
756 // these cause INVALID floating point exception so we want to clear the status.
757 _clear87();
758 #endif
759
760 QVERIFY(qIsInf(-neginf));
761 QVERIFY(!qIsNaN(-neginf));
762 QVERIFY(!qIsFinite(-neginf));
763
764 QVERIFY(!qIsInf(nan));
765 QVERIFY(qIsNaN(nan));
766 QVERIFY(!qIsFinite(nan));
767
768 QVERIFY(!qIsInf(1.234));
769 QVERIFY(!qIsNaN(1.234));
770 QVERIFY(qIsFinite(1.234));
771 }
772
fpExceptions()773 void tst_QLocale::fpExceptions()
774 {
775 #ifndef _MCW_EM
776 #define _MCW_EM 0x0008001F
777 #endif
778 #ifndef _EM_INEXACT
779 #define _EM_INEXACT 0x00000001
780 #endif
781
782 // check that qdtoa doesn't throw floating point exceptions when they are enabled
783 #ifdef Q_OS_WIN
784 unsigned int oldbits = _control87(0, 0);
785 _control87( 0 | _EM_INEXACT, _MCW_EM );
786 #endif
787
788 #ifdef Q_OS_LINUX
789 fenv_t envp;
790 fegetenv(&envp);
791 feclearexcept(FE_ALL_EXCEPT);
792 feenableexcept(FE_DIVBYZERO | FE_OVERFLOW | FE_UNDERFLOW | FE_INVALID);
793 #endif
794
795 QString::number(1000.1245);
796 QString::number(1.1);
797 QString::number(0.0);
798
799 QVERIFY(true);
800
801 #ifdef Q_OS_WIN
802 _clear87();
803 _control87(oldbits, 0xFFFFF);
804 #endif
805
806 #ifdef Q_OS_LINUX
807 fesetenv(&envp);
808 #endif
809 }
810
negativeZero()811 void tst_QLocale::negativeZero()
812 {
813 double negativeZero( 0.0 ); // Initialise to zero.
814 uchar *ptr = (uchar *)&negativeZero;
815 #ifdef QT_ARMFPA
816 ptr[3] = 0x80;
817 #else
818 ptr[QSysInfo::ByteOrder == QSysInfo::BigEndian ? 0 : 7] = 0x80;
819 #endif
820 QString s = QString::number(negativeZero);
821 QCOMPARE(s, QString("0"));
822 }
823
dayOfWeek_data()824 void tst_QLocale::dayOfWeek_data()
825 {
826 QTest::addColumn<QDate>("date");
827 QTest::addColumn<QString>("shortName");
828 QTest::addColumn<QString>("longName");
829
830 QTest::newRow("Sun") << QDate(2006, 1, 1) << "Sun" << "Sunday";
831 QTest::newRow("Mon") << QDate(2006, 1, 2) << "Mon" << "Monday";
832 QTest::newRow("Tue") << QDate(2006, 1, 3) << "Tue" << "Tuesday";
833 QTest::newRow("Wed") << QDate(2006, 1, 4) << "Wed" << "Wednesday";
834 QTest::newRow("Thu") << QDate(2006, 1, 5) << "Thu" << "Thursday";
835 QTest::newRow("Fri") << QDate(2006, 1, 6) << "Fri" << "Friday";
836 QTest::newRow("Sat") << QDate(2006, 1, 7) << "Sat" << "Saturday";
837 }
838
dayOfWeek()839 void tst_QLocale::dayOfWeek()
840 {
841 QFETCH(QDate, date);
842 QFETCH(QString, shortName);
843 QFETCH(QString, longName);
844
845 QCOMPARE(QLocale::c().toString(date, "ddd"), shortName);
846 QCOMPARE(QLocale::c().toString(date, "dddd"), longName);
847 }
848
formatDate_data()849 void tst_QLocale::formatDate_data()
850 {
851 QTest::addColumn<QDate>("date");
852 QTest::addColumn<QString>("format");
853 QTest::addColumn<QString>("result");
854
855 QTest::newRow("1") << QDate(1974, 12, 1) << "d/M/yyyy" << "1/12/1974";
856 QTest::newRow("2") << QDate(1974, 12, 1) << "d/M/yyyyy" << "1/12/1974y";
857 QTest::newRow("4") << QDate(1974, 1, 1) << "d/M/yyyy" << "1/1/1974";
858 QTest::newRow("5") << QDate(1974, 1, 1) << "dd/MM/yyy" << "01/01/74y";
859 QTest::newRow("6") << QDate(1974, 12, 1) << "ddd/MMM/yy" << "Sun/Dec/74";
860 QTest::newRow("7") << QDate(1974, 12, 1) << "dddd/MMMM/y" << "Sunday/December/y";
861 QTest::newRow("8") << QDate(1974, 12, 1) << "ddddd/MMMMM/yy" << "Sunday1/December12/74";
862 QTest::newRow("9") << QDate(1974, 12, 1) << "'dddd'/MMMM/yy" << "dddd/December/74";
863 QTest::newRow("10") << QDate(1974, 12, 1) << "d'dd'd/MMMM/yyy" << "1dd1/December/74y";
864 QTest::newRow("11") << QDate(1974, 12, 1) << "d'dd'd/MMM'M'/yy" << "1dd1/DecM/74";
865 QTest::newRow("12") << QDate(1974, 12, 1) << "d'd'dd/M/yy" << "1d01/12/74";
866
867 QTest::newRow("20") << QDate(1974, 12, 1) << "foo" << "foo";
868 QTest::newRow("21") << QDate(1974, 12, 1) << "'" << "";
869 QTest::newRow("22") << QDate(1974, 12, 1) << "''" << "'";
870 QTest::newRow("23") << QDate(1974, 12, 1) << "'''" << "'";
871 QTest::newRow("24") << QDate(1974, 12, 1) << "\"" << "\"";
872 QTest::newRow("25") << QDate(1974, 12, 1) << "\"\"" << "\"\"";
873 QTest::newRow("26") << QDate(1974, 12, 1) << "\"yy\"" << "\"74\"";
874 QTest::newRow("27") << QDate(1974, 12, 1) << "'\"yy\"'" << "\"yy\"";
875 QTest::newRow("28") << QDate() << "'\"yy\"'" << "";
876 QTest::newRow("29") << QDate(1974, 12, 1) << "hh:mm:ss.zzz ap d'd'dd/M/yy" << "hh:mm:ss.zzz ap 1d01/12/74";
877
878 }
879
formatDate()880 void tst_QLocale::formatDate()
881 {
882 QFETCH(QDate, date);
883 QFETCH(QString, format);
884 QFETCH(QString, result);
885
886 QLocale l(QLocale::C);
887 QCOMPARE(l.toString(date, format), result);
888 }
889
Q_DECLARE_METATYPE(QTime)890 Q_DECLARE_METATYPE(QTime)
891
892 void tst_QLocale::formatTime_data()
893 {
894 QTest::addColumn<QTime>("time");
895 QTest::addColumn<QString>("format");
896 QTest::addColumn<QString>("result");
897
898 QTest::newRow("1") << QTime(1, 2, 3) << "h:m:s" << "1:2:3";
899 QTest::newRow("3") << QTime(1, 2, 3) << "H:m:s" << "1:2:3";
900 QTest::newRow("4") << QTime(1, 2, 3) << "hh:mm:ss" << "01:02:03";
901 QTest::newRow("5") << QTime(1, 2, 3) << "HH:mm:ss" << "01:02:03";
902 QTest::newRow("6") << QTime(1, 2, 3) << "hhh:mmm:sss" << "011:022:033";
903
904 QTest::newRow("8") << QTime(14, 2, 3) << "h:m:s" << "14:2:3";
905 QTest::newRow("9") << QTime(14, 2, 3) << "H:m:s" << "14:2:3";
906 QTest::newRow("10") << QTime(14, 2, 3) << "hh:mm:ss" << "14:02:03";
907 QTest::newRow("11") << QTime(14, 2, 3) << "HH:mm:ss" << "14:02:03";
908 QTest::newRow("12") << QTime(14, 2, 3) << "hhh:mmm:sss" << "1414:022:033";
909
910 QTest::newRow("14") << QTime(14, 2, 3) << "h:m:s ap" << "2:2:3 pm";
911 QTest::newRow("15") << QTime(14, 2, 3) << "H:m:s AP" << "14:2:3 PM";
912 QTest::newRow("16") << QTime(14, 2, 3) << "hh:mm:ss aap" << "02:02:03 pmpm";
913 QTest::newRow("17") << QTime(14, 2, 3) << "HH:mm:ss AP aa" << "14:02:03 PM pmpm";
914
915 QTest::newRow("18") << QTime(1, 2, 3) << "h:m:s ap" << "1:2:3 am";
916 QTest::newRow("19") << QTime(1, 2, 3) << "H:m:s AP" << "1:2:3 AM";
917
918 QTest::newRow("20") << QTime(1, 2, 3) << "foo" << "foo";
919 QTest::newRow("21") << QTime(1, 2, 3) << "'" << "";
920 QTest::newRow("22") << QTime(1, 2, 3) << "''" << "'";
921 QTest::newRow("23") << QTime(1, 2, 3) << "'''" << "'";
922 QTest::newRow("24") << QTime(1, 2, 3) << "\"" << "\"";
923 QTest::newRow("25") << QTime(1, 2, 3) << "\"\"" << "\"\"";
924 QTest::newRow("26") << QTime(1, 2, 3) << "\"H\"" << "\"1\"";
925 QTest::newRow("27") << QTime(1, 2, 3) << "'\"H\"'" << "\"H\"";
926
927 QTest::newRow("28") << QTime(1, 2, 3, 456) << "H:m:s.z" << "1:2:3.456";
928 QTest::newRow("29") << QTime(1, 2, 3, 456) << "H:m:s.zz" << "1:2:3.456456";
929 QTest::newRow("30") << QTime(1, 2, 3, 456) << "H:m:s.zzz" << "1:2:3.456";
930 QTest::newRow("31") << QTime(1, 2, 3, 4) << "H:m:s.z" << "1:2:3.4";
931 QTest::newRow("32") << QTime(1, 2, 3, 4) << "H:m:s.zzz" << "1:2:3.004";
932 QTest::newRow("33") << QTime() << "H:m:s.zzz" << "";
933 QTest::newRow("34") << QTime(1, 2, 3, 4) << "dd MM yyyy H:m:s.zzz" << "dd MM yyyy 1:2:3.004";
934 }
935
formatTime()936 void tst_QLocale::formatTime()
937 {
938 QFETCH(QTime, time);
939 QFETCH(QString, format);
940 QFETCH(QString, result);
941
942 QLocale l(QLocale::C);
943 QCOMPARE(l.toString(time, format), result);
944 }
945
946
formatDateTime_data()947 void tst_QLocale::formatDateTime_data()
948 {
949 QTest::addColumn<QString>("localeName");
950 QTest::addColumn<QDateTime>("dateTime");
951 QTest::addColumn<QString>("format");
952 QTest::addColumn<QString>("result");
953
954 QTest::newRow("1C") << "C" << QDateTime(QDate(1974, 12, 1), QTime(5, 14, 13))
955 << "d/M/yyyy hh:h:mm" << "1/12/1974 05:5:14";
956 QTest::newRow("2C") << "C" << QDateTime(QDate(1974, 12, 1), QTime(15, 14, 13))
957 << "d/M/yyyyy h" << "1/12/1974y 15";
958 QTest::newRow("4C") << "C" << QDateTime(QDate(1974, 1, 1), QTime(15, 14, 13))
959 << "d/M/yyyy zzz" << "1/1/1974 000";
960 QTest::newRow("5C") << "C" << QDateTime(QDate(1974, 1, 1), QTime(15, 14, 13))
961 << "dd/MM/yyy z" << "01/01/74y 0";
962 QTest::newRow("6C") << "C" << QDateTime(QDate(1974, 12, 2), QTime(15, 14, 13))
963 << "ddd/MMM/yy AP" << "Mon/Dec/74 PM";
964 QTest::newRow("7C") << "C" << QDateTime(QDate(1974, 12, 2), QTime(15, 14, 13))
965 << "dddd/MMMM/y apa" << "Monday/December/y pmpm";
966 QTest::newRow("8C") << "C" << QDateTime(QDate(1974, 12, 2), QTime(15, 14, 13))
967 << "ddddd/MMMMM/yy ss" << "Monday2/December12/74 13";
968 QTest::newRow("9C") << "C" << QDateTime(QDate(1974, 12, 1), QTime(15, 14, 13))
969 << "'dddd'/MMMM/yy s" << "dddd/December/74 13";
970 QTest::newRow("10C") << "C" << QDateTime(QDate(1974, 12, 1), QTime(15, 4, 13))
971 << "d'dd'd/MMMM/yyy m'm'mm" << "1dd1/December/74y 4m04";
972 QTest::newRow("11C") << "C" << QDateTime(QDate(1974, 12, 1), QTime(15, 14, 3))
973 << "d'dd'd/MMM'M'/yysss" << "1dd1/DecM/74033";
974 QTest::newRow("12C") << "C" << QDateTime(QDate(1974, 12, 1), QTime(15, 14, 13))
975 << "d'd'dd/M/yyh" << "1d01/12/7415";
976
977 QTest::newRow("20C") << "C" << QDateTime(QDate(1974, 12, 1), QTime(15, 14, 13))
978 << "foo" << "foo";
979 QTest::newRow("21C") << "C" << QDateTime(QDate(1974, 12, 1), QTime(15, 14, 13))
980 << "'" << "";
981 QTest::newRow("22C") << "C" << QDateTime(QDate(1974, 12, 1), QTime(15, 14, 13))
982 << "''" << "'";
983 QTest::newRow("23C") << "C" << QDateTime(QDate(1974, 12, 1), QTime(15, 14, 13))
984 << "'''" << "'";
985 QTest::newRow("24C") << "C" << QDateTime(QDate(1974, 12, 1), QTime(15, 14, 13))
986 << "\"" << "\"";
987 QTest::newRow("25C") << "C" << QDateTime(QDate(1974, 12, 1), QTime(15, 14, 13))
988 << "\"\"" << "\"\"";
989 QTest::newRow("26C") << "C" << QDateTime(QDate(1974, 12, 1), QTime(15, 14, 13))
990 << "\"yymm\"" << "\"7414\"";
991 QTest::newRow("27C") << "C" << QDateTime(QDate(1974, 12, 1), QTime(15, 14, 13))
992 << "'\"yymm\"'" << "\"yymm\"";
993 QTest::newRow("27C") << "C" << QDateTime()
994 << "'\"yymm\"'" << "";
995
996 QTest::newRow("1no_NO") << "no_NO" << QDateTime(QDate(1974, 12, 1), QTime(5, 14, 13))
997 << "d/M/yyyy hh:h:mm" << "1/12/1974 05:5:14";
998 QTest::newRow("2no_NO") << "no_NO" << QDateTime(QDate(1974, 12, 1), QTime(15, 14, 13))
999 << "d/M/yyyyy h" << "1/12/1974y 15";
1000 QTest::newRow("4no_NO") << "no_NO" << QDateTime(QDate(1974, 1, 1), QTime(15, 14, 13))
1001 << "d/M/yyyy zzz" << "1/1/1974 000";
1002 QTest::newRow("5no_NO") << "no_NO" << QDateTime(QDate(1974, 1, 1), QTime(15, 14, 13))
1003 << "dd/MM/yyy z" << "01/01/74y 0";
1004 QTest::newRow("6no_NO") << "no_NO" << QDateTime(QDate(1974, 12, 2), QTime(15, 14, 13))
1005 << "ddd/MMM/yy AP" << "man./des./74 PM";
1006 QTest::newRow("7no_NO") << "no_NO" << QDateTime(QDate(1974, 12, 2), QTime(15, 14, 13))
1007 << "dddd/MMMM/y apa" << "mandag/desember/y pmpm";
1008 QTest::newRow("8no_NO") << "no_NO" << QDateTime(QDate(1974, 12, 2), QTime(15, 14, 13))
1009 << "ddddd/MMMMM/yy ss" << "mandag2/desember12/74 13";
1010 QTest::newRow("9no_NO") << "no_NO" << QDateTime(QDate(1974, 12, 1), QTime(15, 14, 13))
1011 << "'dddd'/MMMM/yy s" << "dddd/desember/74 13";
1012 QTest::newRow("10no_NO") << "no_NO" << QDateTime(QDate(1974, 12, 1), QTime(15, 4, 13))
1013 << "d'dd'd/MMMM/yyy m'm'mm" << "1dd1/desember/74y 4m04";
1014 QTest::newRow("11no_NO") << "no_NO" << QDateTime(QDate(1974, 12, 1), QTime(15, 14, 3))
1015 << "d'dd'd/MMM'M'/yysss" << "1dd1/des.M/74033";
1016 QTest::newRow("12no_NO") << "no_NO" << QDateTime(QDate(1974, 12, 1), QTime(15, 14, 13))
1017 << "d'd'dd/M/yyh" << "1d01/12/7415";
1018
1019 QTest::newRow("20no_NO") << "no_NO" << QDateTime(QDate(1974, 12, 1), QTime(15, 14, 13))
1020 << "foo" << "foo";
1021 QTest::newRow("21no_NO") << "no_NO" << QDateTime(QDate(1974, 12, 1), QTime(15, 14, 13))
1022 << "'" << "";
1023 QTest::newRow("22no_NO") << "no_NO" << QDateTime(QDate(1974, 12, 1), QTime(15, 14, 13))
1024 << "''" << "'";
1025 QTest::newRow("23no_NO") << "no_NO" << QDateTime(QDate(1974, 12, 1), QTime(15, 14, 13))
1026 << "'''" << "'";
1027 QTest::newRow("24no_NO") << "no_NO" << QDateTime(QDate(1974, 12, 1), QTime(15, 14, 13))
1028 << "\"" << "\"";
1029 QTest::newRow("25no_NO") << "no_NO" << QDateTime(QDate(1974, 12, 1), QTime(15, 14, 13))
1030 << "\"\"" << "\"\"";
1031 QTest::newRow("26no_NO") << "no_NO" << QDateTime(QDate(1974, 12, 1), QTime(15, 14, 13))
1032 << "\"yymm\"" << "\"7414\"";
1033 QTest::newRow("27no_NO") << "no_NO" << QDateTime(QDate(1974, 12, 1), QTime(15, 14, 13))
1034 << "'\"yymm\"'" << "\"yymm\"";
1035 QTest::newRow("27no_NO") << "no_NO" << QDateTime()
1036 << "'\"yymm\"'" << "";
1037
1038 }
1039
formatDateTime()1040 void tst_QLocale::formatDateTime()
1041 {
1042 QFETCH(QString, localeName);
1043 QFETCH(QDateTime, dateTime);
1044 QFETCH(QString, format);
1045 QFETCH(QString, result);
1046
1047 QLocale l(localeName);
1048 QCOMPARE(l.toString(dateTime, format), result);
1049 }
1050
toDateTime_data()1051 void tst_QLocale::toDateTime_data()
1052 {
1053 QTest::addColumn<QString>("localeName");
1054 QTest::addColumn<QDateTime>("result");
1055 QTest::addColumn<QString>("format");
1056 QTest::addColumn<QString>("string");
1057
1058 QTest::newRow("1C") << "C" << QDateTime(QDate(1974, 12, 1), QTime(5, 14, 0))
1059 << "d/M/yyyy hh:h:mm" << "1/12/1974 05:5:14";
1060 QTest::newRow("2C") << "C" << QDateTime(QDate(1974, 12, 1), QTime(15, 0, 0))
1061 << "d/M/yyyyy h" << "1/12/1974y 15";
1062 QTest::newRow("4C") << "C" << QDateTime(QDate(1974, 1, 1), QTime(0, 0, 0))
1063 << "d/M/yyyy zzz" << "1/1/1974 000";
1064 QTest::newRow("5C") << "C" << QDateTime(QDate(1974, 1, 1), QTime(0, 0, 0))
1065 << "dd/MM/yyy z" << "01/01/74y 0";
1066 QTest::newRow("8C") << "C" << QDateTime(QDate(1974, 12, 2), QTime(0, 0, 13))
1067 << "ddddd/MMMMM/yy ss" << "Monday2/December12/74 13";
1068 QTest::newRow("9C") << "C" << QDateTime(QDate(1974, 12, 1), QTime(0, 0, 13))
1069 << "'dddd'/MMMM/yy s" << "dddd/December/74 13";
1070 QTest::newRow("10C") << "C" << QDateTime(QDate(1974, 12, 1), QTime(0, 4, 0))
1071 << "d'dd'd/MMMM/yyy m'm'mm" << "1dd1/December/74y 4m04";
1072 QTest::newRow("11C") << "C" << QDateTime(QDate(1974, 12, 1), QTime(0, 0, 3))
1073 << "d'dd'd/MMM'M'/yysss" << "1dd1/DecM/74033";
1074 QTest::newRow("12C") << "C" << QDateTime(QDate(1974, 12, 1), QTime(15, 0, 0))
1075 << "d'd'dd/M/yyh" << "1d01/12/7415";
1076
1077 QTest::newRow("1no_NO") << "no_NO" << QDateTime(QDate(1974, 12, 1), QTime(5, 14, 0))
1078 << "d/M/yyyy hh:h:mm" << "1/12/1974 05:5:14";
1079 QTest::newRow("2no_NO") << "no_NO" << QDateTime(QDate(1974, 12, 1), QTime(15, 0, 0))
1080 << "d/M/yyyyy h" << "1/12/1974y 15";
1081 QTest::newRow("4no_NO") << "no_NO" << QDateTime(QDate(1974, 1, 1), QTime(0, 0, 0))
1082 << "d/M/yyyy zzz" << "1/1/1974 000";
1083 QTest::newRow("5no_NO") << "no_NO" << QDateTime(QDate(1974, 1, 1), QTime(0, 0, 0))
1084 << "dd/MM/yyy z" << "01/01/74y 0";
1085 QTest::newRow("8no_NO") << "no_NO" << QDateTime(QDate(1974, 12, 2), QTime(0, 0, 13))
1086 << "ddddd/MMMMM/yy ss" << "mandag2/desember12/74 13";
1087 QTest::newRow("9no_NO") << "no_NO" << QDateTime(QDate(1974, 12, 1), QTime(0, 0, 13))
1088 << "'dddd'/MMMM/yy s" << "dddd/desember/74 13";
1089 QTest::newRow("10no_NO") << "no_NO" << QDateTime(QDate(1974, 12, 1), QTime(0, 4, 0))
1090 << "d'dd'd/MMMM/yyy m'm'mm" << "1dd1/desember/74y 4m04";
1091 QTest::newRow("11no_NO") << "no_NO" << QDateTime(QDate(1974, 12, 1), QTime(0, 0, 3))
1092 << "d'dd'd/MMM'M'/yysss" << "1dd1/des.M/74033";
1093 QTest::newRow("12no_NO") << "no_NO" << QDateTime(QDate(1974, 12, 1), QTime(15, 0, 0))
1094 << "d'd'dd/M/yyh" << "1d01/12/7415";
1095
1096 QTest::newRow("RFC-1123") << "C" << QDateTime(QDate(2007, 11, 1), QTime(18, 8, 30))
1097 << "ddd, dd MMM yyyy hh:mm:ss 'GMT'" << "Thu, 01 Nov 2007 18:08:30 GMT";
1098
1099 QTest::newRow("longFormat") << "en_US" << QDateTime(QDate(2009, 1, 5), QTime(11, 48, 32))
1100 << "dddd, MMMM d, yyyy h:mm:ss AP " << "Monday, January 5, 2009 11:48:32 AM ";
1101 }
1102
toDateTime()1103 void tst_QLocale::toDateTime()
1104 {
1105 QFETCH(QString, localeName);
1106 QFETCH(QDateTime, result);
1107 QFETCH(QString, format);
1108 QFETCH(QString, string);
1109
1110 QLocale l(localeName);
1111 QCOMPARE(l.toDateTime(string, format), result);
1112 if (l.dateTimeFormat(QLocale::LongFormat) == format)
1113 QCOMPARE(l.toDateTime(string, QLocale::LongFormat), result);
1114 }
1115
1116 #ifdef Q_OS_MAC
macDefaultLocale()1117 void tst_QLocale::macDefaultLocale()
1118 {
1119 QLocale locale = QLocale::system();
1120 if (locale.name() != QLatin1String("en_US")) {
1121 QSKIP("This test only tests for en_US", SkipAll);
1122 }
1123
1124 QTime invalidTime;
1125 QDate invalidDate;
1126 QCOMPARE(locale.toString(invalidTime, QLocale::ShortFormat), QString());
1127 QCOMPARE(locale.toString(invalidDate, QLocale::ShortFormat), QString());
1128 QCOMPARE(locale.toString(invalidTime, QLocale::NarrowFormat), QString());
1129 QCOMPARE(locale.toString(invalidDate, QLocale::NarrowFormat), QString());
1130 QCOMPARE(locale.toString(invalidTime, QLocale::LongFormat), QString());
1131 QCOMPARE(locale.toString(invalidDate, QLocale::LongFormat), QString());
1132 QCOMPARE(locale.decimalPoint(), QChar('.'));
1133 QCOMPARE(locale.groupSeparator(), QChar(','));
1134 QCOMPARE(locale.dateFormat(QLocale::ShortFormat), QString("M/d/yy"));
1135 QCOMPARE(locale.dateFormat(QLocale::LongFormat), QString("MMMM d, yyyy"));
1136 QCOMPARE(locale.timeFormat(QLocale::ShortFormat), QString("h:mm AP"));
1137 QCOMPARE(locale.timeFormat(QLocale::LongFormat), QString("h:mm:ss AP t"));
1138
1139 // make sure we are using the system to parse them
1140 QCOMPARE(locale.toString(1234.56), QString("1,234.56"));
1141 QCOMPARE(locale.toString(QDate(1974, 12, 1), QLocale::ShortFormat), QString("12/1/74"));
1142 QCOMPARE(locale.toString(QDate(1974, 12, 1), QLocale::NarrowFormat), locale.toString(QDate(1974, 12, 1), QLocale::ShortFormat));
1143 QCOMPARE(locale.toString(QDate(1974, 12, 1), QLocale::LongFormat), QString("December 1, 1974"));
1144 QCOMPARE(locale.toString(QTime(1,2,3), QLocale::ShortFormat), QString("1:02 AM"));
1145 QCOMPARE(locale.toString(QTime(1,2,3), QLocale::NarrowFormat), locale.toString(QTime(1,2,3), QLocale::ShortFormat));
1146
1147 QTime currentTime = QTime::currentTime();
1148 QTime utcTime = QDateTime::currentDateTime().toUTC().time();
1149
1150 int diff = currentTime.hour() - utcTime.hour();
1151
1152 // Check if local time and utc time are on opposite sides of the 24-hour wrap-around.
1153 if (diff < -12)
1154 diff += 24;
1155 if (diff > 12)
1156 diff -= 24;
1157
1158 const QString timeString = locale.toString(QTime(1,2,3), QLocale::LongFormat);
1159 QVERIFY(timeString.contains(QString("1:02:03")));
1160
1161 // System Preferences->Language & Text, Region Tab, should choose "United States" for Region field
1162 QCOMPARE(locale.toCurrencyString(qulonglong(1234)), QString("$1,234.00"));
1163 QCOMPARE(locale.toCurrencyString(qlonglong(-1234)), QString("($1,234.00)"));
1164 QCOMPARE(locale.toCurrencyString(double(1234.56)), QString("$1,234.56"));
1165 QCOMPARE(locale.toCurrencyString(double(-1234.56)), QString("($1,234.56)"));
1166
1167 // Depending on the configured time zone, the time string might not
1168 // contain a GMT specifier. (Sometimes it just names the zone, like "CEST")
1169 if (timeString.contains(QString("GMT"))) {
1170 QString expectedGMTSpecifier("GMT");
1171 if (diff >= 0)
1172 expectedGMTSpecifier.append("+");
1173 else
1174 expectedGMTSpecifier.append("-");
1175 if (qAbs(diff) < 10)
1176 expectedGMTSpecifier.append(QString("0%1").arg(qAbs(diff)));
1177 else
1178 expectedGMTSpecifier.append(QString("%1").arg(qAbs(diff)));
1179 QVERIFY2(timeString.contains(expectedGMTSpecifier), qPrintable(
1180 QString("timeString `%1', expectedGMTSpecifier `%2'")
1181 .arg(timeString)
1182 .arg(expectedGMTSpecifier)
1183 ));
1184 }
1185 QCOMPARE(locale.dayName(1), QString("Monday"));
1186 QCOMPARE(locale.dayName(7), QString("Sunday"));
1187 QCOMPARE(locale.monthName(1), QString("January"));
1188 QCOMPARE(locale.monthName(12), QString("December"));
1189 QCOMPARE(locale.firstDayOfWeek(), Qt::Sunday);
1190 QCOMPARE(locale.quoteString("string"), QString::fromUtf8("\xe2\x80\x9c" "string" "\xe2\x80\x9d"));
1191 QCOMPARE(locale.quoteString("string", QLocale::AlternateQuotation), QString::fromUtf8("\xe2\x80\x98" "string" "\xe2\x80\x99"));
1192
1193 QList<Qt::DayOfWeek> days;
1194 days << Qt::Monday << Qt::Tuesday << Qt::Wednesday << Qt::Thursday << Qt::Friday;
1195 QCOMPARE(locale.weekdays(), days);
1196
1197 }
1198 #endif
1199
1200 #ifdef Q_OS_WIN
1201 #include <qt_windows.h>
1202
getWinLocaleInfo(LCTYPE type)1203 static QString getWinLocaleInfo(LCTYPE type)
1204 {
1205 LCID id = GetThreadLocale();
1206 int cnt = GetLocaleInfo(id, type, 0, 0) * 2;
1207
1208 if (cnt == 0) {
1209 qWarning("QLocale: empty windows locale info (%d)", type);
1210 return QString();
1211 }
1212
1213 QByteArray buff(cnt, 0);
1214
1215 cnt = GetLocaleInfo(id, type, reinterpret_cast<wchar_t*>(buff.data()), buff.size() / 2);
1216
1217 if (cnt == 0) {
1218 qWarning("QLocale: empty windows locale info (%d)", type);
1219 return QString();
1220 }
1221
1222 return QString::fromWCharArray(reinterpret_cast<wchar_t*>(buff.data()));
1223 }
1224
setWinLocaleInfo(LCTYPE type,const QString & value)1225 static void setWinLocaleInfo(LCTYPE type, const QString &value)
1226 {
1227 LCID id = GetThreadLocale();
1228 SetLocaleInfo(id, type, reinterpret_cast<const wchar_t*>(value.utf16()));
1229 }
1230
1231 class RestoreLocaleHelper {
1232 public:
RestoreLocaleHelper()1233 RestoreLocaleHelper() {
1234 m_decimal = getWinLocaleInfo(LOCALE_SDECIMAL);
1235 m_thousand = getWinLocaleInfo(LOCALE_STHOUSAND);
1236 m_sdate = getWinLocaleInfo(LOCALE_SSHORTDATE);
1237 m_ldate = getWinLocaleInfo(LOCALE_SLONGDATE);
1238 m_time = getWinLocaleInfo(LOCALE_STIMEFORMAT);
1239 }
1240
~RestoreLocaleHelper()1241 ~RestoreLocaleHelper() {
1242 // restore these, or the user will get a surprise
1243 setWinLocaleInfo(LOCALE_SDECIMAL, m_decimal);
1244 setWinLocaleInfo(LOCALE_STHOUSAND, m_thousand);
1245 setWinLocaleInfo(LOCALE_SSHORTDATE, m_sdate);
1246 setWinLocaleInfo(LOCALE_SLONGDATE, m_ldate);
1247 setWinLocaleInfo(LOCALE_STIMEFORMAT, m_time);
1248 }
1249
1250 QString m_decimal, m_thousand, m_sdate, m_ldate, m_time;
1251
1252 };
1253
1254 #endif
1255
windowsDefaultLocale()1256 void tst_QLocale::windowsDefaultLocale()
1257 {
1258 #ifndef Q_OS_WIN
1259 QSKIP("This is a Windows test", SkipAll);
1260 #else
1261 RestoreLocaleHelper systemLocale;
1262 // set weird system defaults and make sure we're using them
1263 setWinLocaleInfo(LOCALE_SDECIMAL, QLatin1String("@"));
1264 setWinLocaleInfo(LOCALE_STHOUSAND, QLatin1String("?"));
1265 setWinLocaleInfo(LOCALE_SSHORTDATE, QLatin1String("d*M*yyyy"));
1266 setWinLocaleInfo(LOCALE_SLONGDATE, QLatin1String("d@M@yyyy"));
1267 setWinLocaleInfo(LOCALE_STIMEFORMAT, QLatin1String("h^m^s"));
1268 QLocale locale = QLocale::system();
1269
1270 // make sure we are seeing the system's format strings
1271 QCOMPARE(locale.decimalPoint(), QChar('@'));
1272 QCOMPARE(locale.groupSeparator(), QChar('?'));
1273 QCOMPARE(locale.dateFormat(QLocale::ShortFormat), QString("d*M*yyyy"));
1274 QCOMPARE(locale.dateFormat(QLocale::LongFormat), QString("d@M@yyyy"));
1275 QCOMPARE(locale.timeFormat(QLocale::ShortFormat), QString("h^m^s"));
1276 QCOMPARE(locale.timeFormat(QLocale::LongFormat), QString("h^m^s"));
1277 QCOMPARE(locale.dateTimeFormat(QLocale::ShortFormat), QString("d*M*yyyy h^m^s"));
1278 QCOMPARE(locale.dateTimeFormat(QLocale::LongFormat), QString("d@M@yyyy h^m^s"));
1279
1280 // make sure we are using the system to parse them
1281 QCOMPARE(locale.toString(1234.56), QString("1?234@56"));
1282 QCOMPARE(locale.toString(QDate(1974, 12, 1), QLocale::ShortFormat), QString("1*12*1974"));
1283 QCOMPARE(locale.toString(QDate(1974, 12, 1), QLocale::NarrowFormat), locale.toString(QDate(1974, 12, 1), QLocale::ShortFormat));
1284 QCOMPARE(locale.toString(QDate(1974, 12, 1), QLocale::LongFormat), QString("1@12@1974"));
1285 QCOMPARE(locale.toString(QTime(1,2,3), QLocale::ShortFormat), QString("1^2^3"));
1286 QCOMPARE(locale.toString(QTime(1,2,3), QLocale::NarrowFormat), locale.toString(QTime(1,2,3), QLocale::ShortFormat));
1287 QCOMPARE(locale.toString(QTime(1,2,3), QLocale::LongFormat), QString("1^2^3"));
1288 QCOMPARE(locale.toString(QDateTime(QDate(1974, 12, 1), QTime(1,2,3)), QLocale::ShortFormat),
1289 QString("1*12*1974 1^2^3"));
1290 QCOMPARE(locale.toString(QDateTime(QDate(1974, 12, 1), QTime(1,2,3)), QLocale::NarrowFormat),
1291 locale.toString(QDateTime(QDate(1974, 12, 1), QTime(1,2,3)), QLocale::ShortFormat));
1292 QCOMPARE(locale.toString(QDateTime(QDate(1974, 12, 1), QTime(1,2,3)), QLocale::LongFormat),
1293 QString("1@12@1974 1^2^3"));
1294 QCOMPARE(locale.toString(QTime(1,2,3), QLocale::LongFormat), QString("1^2^3"));
1295 #endif
1296 }
1297
numberOptions()1298 void tst_QLocale::numberOptions()
1299 {
1300 bool ok;
1301
1302 QLocale locale(QLocale::C);
1303 QCOMPARE(locale.numberOptions(), 0);
1304 QCOMPARE(locale.toInt(QString("12,345"), &ok), 12345);
1305 QVERIFY(ok);
1306 QCOMPARE(locale.toInt(QString("12345"), &ok), 12345);
1307 QVERIFY(ok);
1308 QCOMPARE(locale.toString(12345), QString("12,345"));
1309
1310 locale.setNumberOptions(QLocale::OmitGroupSeparator);
1311 QCOMPARE(locale.numberOptions(), QLocale::OmitGroupSeparator);
1312 QCOMPARE(locale.toInt(QString("12,345"), &ok), 12345);
1313 QVERIFY(ok);
1314 QCOMPARE(locale.toInt(QString("12345"), &ok), 12345);
1315 QVERIFY(ok);
1316 QCOMPARE(locale.toString(12345), QString("12345"));
1317
1318 locale.setNumberOptions(QLocale::RejectGroupSeparator);
1319 QCOMPARE(locale.numberOptions(), QLocale::RejectGroupSeparator);
1320 locale.toInt(QString("12,345"), &ok);
1321 QVERIFY(!ok);
1322 QCOMPARE(locale.toInt(QString("12345"), &ok), 12345);
1323 QVERIFY(ok);
1324 QCOMPARE(locale.toString(12345), QString("12,345"));
1325
1326 QLocale locale2 = locale;
1327 QCOMPARE(locale2.numberOptions(), QLocale::RejectGroupSeparator);
1328 }
1329
negativeNumbers()1330 void tst_QLocale::negativeNumbers()
1331 {
1332 QLocale locale(QLocale::C);
1333
1334 bool ok;
1335 int i;
1336
1337 i = locale.toInt(QLatin1String("-100"), &ok);
1338 QVERIFY(ok);
1339 QCOMPARE(i, -100);
1340
1341 i = locale.toInt(QLatin1String("-1,000"), &ok);
1342 QVERIFY(ok);
1343 QCOMPARE(i, -1000);
1344
1345 i = locale.toInt(QLatin1String("-1000"), &ok);
1346 QVERIFY(ok);
1347 QCOMPARE(i, -1000);
1348
1349 i = locale.toInt(QLatin1String("-10,000"), &ok);
1350 QVERIFY(ok);
1351 QCOMPARE(i, -10000);
1352
1353 i = locale.toInt(QLatin1String("-10000"), &ok);
1354 QVERIFY(ok);
1355 QCOMPARE(i, -10000);
1356
1357 i = locale.toInt(QLatin1String("-100,000"), &ok);
1358 QVERIFY(ok);
1359 QCOMPARE(i, -100000);
1360
1361 i = locale.toInt(QLatin1String("-100000"), &ok);
1362 QVERIFY(ok);
1363 QCOMPARE(i, -100000);
1364
1365 i = locale.toInt(QLatin1String("-1,000,000"), &ok);
1366 QVERIFY(ok);
1367 QCOMPARE(i, -1000000);
1368
1369 i = locale.toInt(QLatin1String("-1000000"), &ok);
1370 QVERIFY(ok);
1371 QCOMPARE(i, -1000000);
1372 }
1373
1374 #include <private/qlocale_p.h>
1375 #include <private/qlocale_data_p.h>
1376
1377 static const int locale_data_count = sizeof(locale_data)/sizeof(locale_data[0]);
1378
testNames_data()1379 void tst_QLocale::testNames_data()
1380 {
1381 QTest::addColumn<int>("language");
1382 QTest::addColumn<int>("country");
1383
1384 for (int i = 0; i < locale_data_count; ++i) {
1385 const QLocalePrivate &item = locale_data[i];
1386
1387 const QString testName = QString::fromLatin1("data_%1 (%2/%3)").arg(i)
1388 .arg(QLocale::languageToString((QLocale::Language)item.m_language_id))
1389 .arg(QLocale::countryToString((QLocale::Country)item.m_country_id));
1390 QTest::newRow(testName.toLatin1().constData()) << (int)item.m_language_id << (int)item.m_country_id;
1391 }
1392 }
1393
testNames()1394 void tst_QLocale::testNames()
1395 {
1396 QFETCH(int, language);
1397 QFETCH(int, country);
1398
1399 QLocale l1((QLocale::Language)language, (QLocale::Country)country);
1400 if (language == QLocale::AnyLanguage && country == QLocale::AnyCountry)
1401 language = QLocale::C;
1402 QCOMPARE((int)l1.language(), language);
1403 QCOMPARE((int)l1.country(), country);
1404
1405 QString name = l1.name();
1406
1407 QLocale l2(name);
1408 QCOMPARE((int)l2.language(), language);
1409 QCOMPARE((int)l2.country(), country);
1410 QCOMPARE(l2.name(), name);
1411
1412 QLocale l3(name + QLatin1String("@foo"));
1413 QCOMPARE((int)l3.language(), language);
1414 QCOMPARE((int)l3.country(), country);
1415 QCOMPARE(l3.name(), name);
1416
1417 QLocale l4(name + QLatin1String(".foo"));
1418 QCOMPARE((int)l4.language(), language);
1419 QCOMPARE((int)l4.country(), country);
1420 QCOMPARE(l4.name(), name);
1421
1422 if (language != QLocale::C) {
1423 int idx = name.indexOf(QLatin1Char('_'));
1424 QVERIFY(idx != -1);
1425 QString lang = name.left(idx);
1426
1427 QCOMPARE((int)QLocale(lang).language(), language);
1428 QCOMPARE((int)QLocale(lang + QLatin1String("@foo")).language(), language);
1429 QCOMPARE((int)QLocale(lang + QLatin1String(".foo")).language(), language);
1430 }
1431 }
1432
dayName_data()1433 void tst_QLocale::dayName_data()
1434 {
1435 QTest::addColumn<QString>("locale_name");
1436 QTest::addColumn<QString>("dayName");
1437 QTest::addColumn<int>("day");
1438 QTest::addColumn<QLocale::FormatType>("format");
1439
1440 QTest::newRow("no_NO") << QString("no_NO") << QString("tirsdag") << 2 << QLocale::LongFormat;
1441 QTest::newRow("nb_NO") << QString("nb_NO") << QString("tirsdag") << 2 << QLocale::LongFormat;
1442 QTest::newRow("nn_NO") << QString("nn_NO") << QString("tysdag") << 2 << QLocale::LongFormat;
1443
1444 QTest::newRow("C long") << QString("C") << QString("Sunday") << 7 << QLocale::LongFormat;
1445 QTest::newRow("C short") << QString("C") << QString("Sun") << 7 << QLocale::ShortFormat;
1446 QTest::newRow("C narrow") << QString("C") << QString("7") << 7 << QLocale::NarrowFormat;
1447
1448 QTest::newRow("ru_RU long") << QString("ru_RU") << QString::fromUtf8("\320\262\320\276\321\201\320\272\321\200\320\265\321\201\320\265\320\275\321\214\320\265") << 7 << QLocale::LongFormat;
1449 QTest::newRow("ru_RU short") << QString("ru_RU") << QString::fromUtf8("\320\262\321\201") << 7 << QLocale::ShortFormat;
1450 QTest::newRow("ru_RU narrow") << QString("ru_RU") << QString::fromUtf8("\320\222") << 7 << QLocale::NarrowFormat;
1451 }
1452
dayName()1453 void tst_QLocale::dayName()
1454 {
1455 QFETCH(QString, locale_name);
1456 QFETCH(QString, dayName);
1457 QFETCH(int, day);
1458 QFETCH(QLocale::FormatType, format);
1459
1460 QLocale l(locale_name);
1461 QCOMPARE(l.dayName(day, format), dayName);
1462
1463 QLocale ir("ga_IE");
1464 QCOMPARE(ir.dayName(1, QLocale::ShortFormat), QLatin1String("Luan"));
1465 QCOMPARE(ir.dayName(7, QLocale::ShortFormat), QLatin1String("Domh"));
1466
1467 QLocale gr("el_GR");
1468 QCOMPARE(gr.dayName(2, QLocale::ShortFormat), QString::fromUtf8("\316\244\317\201\316\257"));
1469 QCOMPARE(gr.dayName(4, QLocale::ShortFormat), QString::fromUtf8("\316\240\316\255\316\274"));
1470 QCOMPARE(gr.dayName(6, QLocale::ShortFormat), QString::fromUtf8("\316\243\316\254\316\262"));
1471 }
1472
standaloneDayName_data()1473 void tst_QLocale::standaloneDayName_data()
1474 {
1475 QTest::addColumn<QString>("locale_name");
1476 QTest::addColumn<QString>("dayName");
1477 QTest::addColumn<int>("day");
1478 QTest::addColumn<QLocale::FormatType>("format");
1479
1480 QTest::newRow("no_NO") << QString("no_NO") << QString("tirsdag") << 2 << QLocale::LongFormat;
1481 QTest::newRow("nb_NO") << QString("nb_NO") << QString("tirsdag") << 2 << QLocale::LongFormat;
1482 QTest::newRow("nn_NO") << QString("nn_NO") << QString("tysdag") << 2 << QLocale::LongFormat;
1483
1484 QTest::newRow("C invalid: 0 long") << QString("C") << QString() << 0 << QLocale::LongFormat;
1485 QTest::newRow("C invalid: 0 short") << QString("C") << QString() << 0 << QLocale::ShortFormat;
1486 QTest::newRow("C invalid: 0 narrow") << QString("C") << QString() << 0 << QLocale::NarrowFormat;
1487 QTest::newRow("C invalid: 8 long") << QString("C") << QString() << 8 << QLocale::LongFormat;
1488 QTest::newRow("C invalid: 8 short") << QString("C") << QString() << 8 << QLocale::ShortFormat;
1489 QTest::newRow("C invalid: 8 narrow") << QString("C") << QString() << 8 << QLocale::NarrowFormat;
1490
1491 QTest::newRow("C long") << QString("C") << QString("Sunday") << 7 << QLocale::LongFormat;
1492 QTest::newRow("C short") << QString("C") << QString("Sun") << 7 << QLocale::ShortFormat;
1493 QTest::newRow("C narrow") << QString("C") << QString("S") << 7 << QLocale::NarrowFormat;
1494
1495 QTest::newRow("ru_RU long") << QString("ru_RU") << QString::fromUtf8("\320\222\320\276\321\201\320\272\321\200\320\265\321\201\320\265\320\275\321\214\320\265") << 7 << QLocale::LongFormat;
1496 QTest::newRow("ru_RU short") << QString("ru_RU") << QString::fromUtf8("\320\222\321\201") << 7 << QLocale::ShortFormat;
1497 QTest::newRow("ru_RU narrow") << QString("ru_RU") << QString::fromUtf8("\320\222") << 7 << QLocale::NarrowFormat;
1498 }
1499
standaloneDayName()1500 void tst_QLocale::standaloneDayName()
1501 {
1502 QFETCH(QString, locale_name);
1503 QFETCH(QString, dayName);
1504 QFETCH(int, day);
1505 QFETCH(QLocale::FormatType, format);
1506
1507 QLocale l(locale_name);
1508 QCOMPARE(l.standaloneDayName(day, format), dayName);
1509 }
1510
underflowOverflow()1511 void tst_QLocale::underflowOverflow()
1512 {
1513 QString
1514 a(QLatin1String("0.0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001e10"));
1515
1516 bool ok = false;
1517 a.toDouble(&ok);
1518 QVERIFY(!ok);
1519
1520 a = QLatin1String("1e600");
1521 ok = false;
1522 a.toDouble(&ok);
1523 QVERIFY(!ok);
1524
1525 a = QLatin1String("-9223372036854775809");
1526 a.toLongLong(&ok);
1527 QVERIFY(!ok);
1528 }
1529
measurementSystems_data()1530 void tst_QLocale::measurementSystems_data()
1531 {
1532 QTest::addColumn<QString>("localeName");
1533 QTest::addColumn<int>("mSystem");
1534
1535 QTest::newRow("no_NO") << QString("no_NO") << (int)QLocale::MetricSystem; // Norwegian/Norway
1536 QTest::newRow("sv_SE") << QString("sv_SE") << (int)QLocale::MetricSystem; // Swedish/Sweden
1537 QTest::newRow("en_US") << QString("en_US") << (int)QLocale::ImperialSystem; // English/United States
1538 QTest::newRow("en_GB") << QString("en_GB") << (int)QLocale::MetricSystem; // English/Great Britain
1539 QTest::newRow("no") << QString("no") << (int)QLocale::MetricSystem; // Norwegian
1540 QTest::newRow("en") << QString("en") << (int)QLocale::ImperialSystem; // English
1541 QTest::newRow("es_US") << QString("es_US") << (int)QLocale::ImperialSystem; // Spanish/United States
1542 QTest::newRow("es_ES") << QString("es_ES") << (int)QLocale::MetricSystem; // Spanish/Spain
1543 QTest::newRow("es") << QString("es") << (int)QLocale::MetricSystem; // Spanish
1544 }
1545
measurementSystems()1546 void tst_QLocale::measurementSystems()
1547 {
1548 QSKIP("Meh, skip the test as we do not reread the environment variables anymore", SkipAll);
1549 QFETCH(QString, localeName);
1550 QFETCH(int, mSystem);
1551
1552 // Method should be const.
1553 const QLocale locale(localeName);
1554 QCOMPARE((int)locale.measurementSystem(), mSystem);
1555 }
1556
systemMeasurementSystems_data()1557 void tst_QLocale::systemMeasurementSystems_data()
1558 {
1559 QTest::addColumn<QString>("lcAllLocale");
1560 QTest::addColumn<QString>("lcMeasurementLocale");
1561 QTest::addColumn<QString>("langLocale");
1562 QTest::addColumn<int>("mSystem");
1563
1564 QTest::newRow("row0") << QString("no_NO") << QString("no_NO") << QString("no_NO")
1565 << (int)QLocale::MetricSystem;
1566 QTest::newRow("row1") << QString("no_NO") << QString("no_NO") << QString("en_US")
1567 << (int)QLocale::MetricSystem;
1568 QTest::newRow("row2") << QString("no_NO") << QString("en_US") << QString("no_NO")
1569 << (int)QLocale::MetricSystem;
1570 QTest::newRow("row3") << QString("no_NO") << QString("en_US") << QString("en_US")
1571 << (int)QLocale::MetricSystem;
1572 QTest::newRow("row4") << QString("en_US") << QString("no_NO") << QString("no_NO")
1573 << (int)QLocale::ImperialSystem;
1574 QTest::newRow("row5") << QString("en_US") << QString("no_NO") << QString("en_US")
1575 << (int)QLocale::ImperialSystem;
1576 QTest::newRow("row6") << QString("en_US") << QString("en_US") << QString("no_NO")
1577 << (int)QLocale::ImperialSystem;
1578 QTest::newRow("row7") << QString("en_US") << QString("en_US") << QString("en_US")
1579 << (int)QLocale::ImperialSystem;
1580 QTest::newRow("row8") << QString("") << QString("") << QString("")
1581 << (int)QLocale::MetricSystem;
1582 QTest::newRow("row9") << QString("") << QString("") << QString("no_NO")
1583 << (int)QLocale::MetricSystem;
1584 QTest::newRow("row10") << QString("") << QString("") << QString("en_US")
1585 << (int)QLocale::ImperialSystem;
1586 QTest::newRow("row11") << QString("") << QString("no_NO") << QString("")
1587 << (int)QLocale::MetricSystem;
1588 QTest::newRow("row12") << QString("") << QString("en_US") << QString("")
1589 << (int)QLocale::ImperialSystem;
1590 QTest::newRow("row13") << QString("") << QString("no_NO") << QString("en_US")
1591 << (int)QLocale::MetricSystem;
1592 QTest::newRow("row14") << QString("") << QString("en_US") << QString("no_NO")
1593 << (int)QLocale::ImperialSystem;
1594 QTest::newRow("row15") << QString("no_NO") << QString("") << QString("")
1595 << (int)QLocale::MetricSystem;
1596 QTest::newRow("row16") << QString("en_US") << QString("") << QString("")
1597 << (int)QLocale::ImperialSystem;
1598 QTest::newRow("row17") << QString("no_NO") << QString("en_US") << QString("")
1599 << (int)QLocale::MetricSystem;
1600 QTest::newRow("row18") << QString("en_US") << QString("no_NO") << QString("")
1601 << (int)QLocale::ImperialSystem;
1602 QTest::newRow("row19") << QString("no_NO") << QString("") << QString("en_US")
1603 << (int)QLocale::MetricSystem;
1604 QTest::newRow("row20") << QString("en_US") << QString("") << QString("no_NO")
1605 << (int)QLocale::ImperialSystem;
1606 }
1607
systemMeasurementSystems()1608 void tst_QLocale::systemMeasurementSystems()
1609 {
1610 QSKIP("Meh, skip the test as we do not reread the environment variables anymore", SkipAll);
1611 // Theoretically, we could include HPUX in this test, but its setenv implementation
1612 // stinks. It's called putenv, and it requires you to keep the variable you pass
1613 // to it around forever.
1614 #if defined(Q_OS_UNIX) && !defined(Q_OS_MAC) && !defined(Q_OS_SYMBIAN)
1615 QFETCH(QString, lcAllLocale);
1616 QFETCH(QString, lcMeasurementLocale);
1617 QFETCH(QString, langLocale);
1618 QFETCH(int, mSystem);
1619
1620 // Save any old environment variables.
1621 QString oldLcAll = QString::fromLocal8Bit(getenv("LC_ALL"));
1622 QString oldLcMeasurement = QString::fromLocal8Bit(getenv("LC_MEASUREMENT"));
1623 QString oldLang = QString::fromLocal8Bit(getenv("LANG"));
1624
1625 qputenv("LC_ALL", lcAllLocale.toLocal8Bit());
1626 qputenv("LC_MEASUREMENT", lcMeasurementLocale.toLocal8Bit());
1627 qputenv("LANG", langLocale.toLocal8Bit());
1628
1629 // Method should be const.
1630 const QLocale locale(QLocale::system());
1631 QCOMPARE((int)locale.measurementSystem(), mSystem);
1632
1633 // Restore environment.
1634 qputenv("LC_ALL", oldLcAll.toLocal8Bit());
1635 qputenv("LC_MEASUREMENT", oldLcMeasurement.toLocal8Bit());
1636 qputenv("LANG", oldLang.toLocal8Bit());
1637 #else
1638 QSKIP("Test doesn't work on Mac, Windows or Symbian", SkipAll);
1639 #endif
1640 }
1641
1642 class SystemLocale : public QSystemLocale
1643 {
1644 public:
query(QueryType type,QVariant in) const1645 virtual QVariant query(QueryType type, QVariant in) const
1646 {
1647 switch (type) {
1648 case DateTimeFormatLong: return QLatin1String("dddd ddd dd d MMMM MMM MM M yyyy hh:mm:ss.zzz");
1649 case DateTimeFormatShort: return QLatin1String("d M yy h:m");
1650 case DateTimeToStringLong:
1651 case DateTimeToStringShort:
1652 return in.toDateTime().toString(type == DateTimeToStringShort
1653 ? QLatin1String("dMyyhm")
1654 : QLatin1String("ddMMyyyyhhmmsszzz"));
1655 default:
1656 break;
1657 }
1658 return QSystemLocale::query(type, in);
1659 }
1660 };
1661
1662
1663
queryDateTime()1664 void tst_QLocale::queryDateTime()
1665 {
1666 SystemLocale loc;
1667 QCOMPARE(QLocale::system().dateTimeFormat(QLocale::LongFormat),
1668 loc.query(QSystemLocale::DateTimeFormatLong, QVariant()).toString());
1669 QCOMPARE(QLocale::system().dateTimeFormat(QLocale::ShortFormat),
1670 loc.query(QSystemLocale::DateTimeFormatShort, QVariant()).toString());
1671 QCOMPARE(QLocale::system().toString(QDateTime(QDate(1974, 12, 1), QTime(1, 2, 3, 4)), QLocale::ShortFormat),
1672 QString("1127412"));
1673 QCOMPARE(QLocale::system().toString(QDateTime(QDate(1974, 12, 1), QTime(1, 2, 3, 4)), QLocale::NarrowFormat),
1674 QLocale::system().toString(QDateTime(QDate(1974, 12, 1), QTime(1, 2, 3, 4)), QLocale::ShortFormat));
1675 QCOMPARE(QLocale::system().toString(QDateTime(QDate(1974, 12, 1), QTime(1, 2, 3, 4)), QLocale::LongFormat),
1676 QString("01121974010203004"));
1677 }
1678
1679 #ifndef QT_NO_SYSTEMLOCALE
queryMeasureSystem_data()1680 void tst_QLocale::queryMeasureSystem_data()
1681 {
1682 QTest::addColumn<QString>("lcAllLocale");
1683 QTest::addColumn<QString>("lcMeasurementLocale");
1684 QTest::addColumn<QString>("langLocale");
1685 QTest::addColumn<int>("mSystem");
1686
1687 QTest::newRow("row0") << QString("no_NO") << QString("no_NO") << QString("no_NO")
1688 << (int)QLocale::MetricSystem;
1689 QTest::newRow("row1") << QString("no_NO") << QString("no_NO") << QString("en_US")
1690 << (int)QLocale::MetricSystem;
1691 QTest::newRow("row2") << QString("no_NO") << QString("en_US") << QString("no_NO")
1692 << (int)QLocale::MetricSystem;
1693 QTest::newRow("row3") << QString("no_NO") << QString("en_US") << QString("en_US")
1694 << (int)QLocale::MetricSystem;
1695 QTest::newRow("row4") << QString("en_US") << QString("no_NO") << QString("no_NO")
1696 << (int)QLocale::ImperialSystem;
1697 QTest::newRow("row5") << QString("en_US") << QString("no_NO") << QString("en_US")
1698 << (int)QLocale::ImperialSystem;
1699 QTest::newRow("row6") << QString("en_US") << QString("en_US") << QString("no_NO")
1700 << (int)QLocale::ImperialSystem;
1701 QTest::newRow("row7") << QString("en_US") << QString("en_US") << QString("en_US")
1702 << (int)QLocale::ImperialSystem;
1703 QTest::newRow("row8") << QString("") << QString("") << QString("")
1704 << (int)QLocale::MetricSystem;
1705 QTest::newRow("row9") << QString("") << QString("") << QString("no_NO")
1706 << (int)QLocale::MetricSystem;
1707 QTest::newRow("row10") << QString("") << QString("") << QString("en_US")
1708 << (int)QLocale::ImperialSystem;
1709 QTest::newRow("row11") << QString("") << QString("no_NO") << QString("")
1710 << (int)QLocale::MetricSystem;
1711 QTest::newRow("row12") << QString("") << QString("en_US") << QString("")
1712 << (int)QLocale::ImperialSystem;
1713 QTest::newRow("row13") << QString("") << QString("no_NO") << QString("en_US")
1714 << (int)QLocale::MetricSystem;
1715 QTest::newRow("row14") << QString("") << QString("en_US") << QString("no_NO")
1716 << (int)QLocale::ImperialSystem;
1717 QTest::newRow("row15") << QString("no_NO") << QString("") << QString("")
1718 << (int)QLocale::MetricSystem;
1719 QTest::newRow("row16") << QString("en_US") << QString("") << QString("")
1720 << (int)QLocale::ImperialSystem;
1721 QTest::newRow("row17") << QString("no_NO") << QString("en_US") << QString("")
1722 << (int)QLocale::MetricSystem;
1723 QTest::newRow("row18") << QString("en_US") << QString("no_NO") << QString("")
1724 << (int)QLocale::ImperialSystem;
1725 QTest::newRow("row19") << QString("no_NO") << QString("") << QString("en_US")
1726 << (int)QLocale::MetricSystem;
1727 QTest::newRow("row20") << QString("en_US") << QString("") << QString("no_NO")
1728 << (int)QLocale::ImperialSystem;
1729 }
1730
queryMeasureSystem()1731 void tst_QLocale::queryMeasureSystem()
1732 {
1733 QSKIP("Meh, skip the test as we do not reread the environment variables anymore", SkipAll);
1734 // Theoretically, we could include HPUX in this test, but its setenv implementation
1735 // stinks. It's called putenv, and it requires you to keep the variable you pass
1736 // to it around forever.
1737 #if defined(Q_OS_UNIX) && !defined(Q_OS_MAC) && !defined(Q_OS_SYMBIAN)
1738 QFETCH(QString, lcAllLocale);
1739 QFETCH(QString, lcMeasurementLocale);
1740 QFETCH(QString, langLocale);
1741 QFETCH(int, mSystem);
1742
1743 // Save any old environment variables.
1744 QString oldLcAll = QString::fromLocal8Bit(getenv("LC_ALL"));
1745 QString oldLcMeasurement = QString::fromLocal8Bit(getenv("LC_MEASUREMENT"));
1746 QString oldLang = QString::fromLocal8Bit(getenv("LANG"));
1747
1748 qputenv("LC_ALL", lcAllLocale.toLocal8Bit());
1749 qputenv("LC_MEASUREMENT", lcMeasurementLocale.toLocal8Bit());
1750 qputenv("LANG", langLocale.toLocal8Bit());
1751
1752 // Method should be const.
1753 const QSystemLocale locale;
1754 QCOMPARE(locale.query(QSystemLocale::MeasurementSystem, QVariant()).toInt(), mSystem);
1755
1756 // Restore environment.
1757 qputenv("LC_ALL", oldLcAll.toLocal8Bit());
1758 qputenv("LC_MEASUREMENT", oldLcMeasurement.toLocal8Bit());
1759 qputenv("LANG", oldLang.toLocal8Bit());
1760 #else
1761 QSKIP("Test doesn't work on Mac, Windows or Symbian", SkipAll);
1762 #endif
1763 }
1764 #endif // QT_NO_SYSTEMLOCALE
1765
defaultNumeringSystem()1766 void tst_QLocale::defaultNumeringSystem()
1767 {
1768 QLocale sk("sk_SK");
1769 QCOMPARE(sk.toString(123), QLatin1String("123"));
1770
1771 QLocale ta("ta_IN");
1772 QCOMPARE(ta.toString(123), QLatin1String("123"));
1773
1774 QLocale te("te_IN");
1775 QCOMPARE(te.toString(123), QLatin1String("123"));
1776
1777 QLocale hi("hi_IN");
1778 QCOMPARE(hi.toString(123), QLatin1String("123"));
1779
1780 QLocale gu("gu_IN");
1781 QCOMPARE(gu.toString(123), QLatin1String("123"));
1782
1783 QLocale kn("kn_IN");
1784 QCOMPARE(kn.toString(123), QLatin1String("123"));
1785
1786 QLocale pa("pa_IN");
1787 QCOMPARE(pa.toString(123), QLatin1String("123"));
1788
1789 QLocale ne("ne_IN");
1790 QCOMPARE(ne.toString(123), QLatin1String("123"));
1791
1792 QLocale mr("mr_IN");
1793 QCOMPARE(mr.toString(123), QLatin1String("123"));
1794
1795 QLocale ml("ml_IN");
1796 QCOMPARE(ml.toString(123), QLatin1String("123"));
1797
1798 QLocale kok("kok_IN");
1799 QCOMPARE(kok.toString(123), QLatin1String("123"));
1800 }
1801
ampm()1802 void tst_QLocale::ampm()
1803 {
1804 QLocale c(QLocale::C);
1805 QCOMPARE(c.amText(), QLatin1String("AM"));
1806 QCOMPARE(c.pmText(), QLatin1String("PM"));
1807
1808 QLocale de("de_DE");
1809 QCOMPARE(de.amText(), QLatin1String("vorm."));
1810 QCOMPARE(de.pmText(), QLatin1String("nachm."));
1811
1812 QLocale sv("sv_SE");
1813 QCOMPARE(sv.amText(), QLatin1String("fm"));
1814 QCOMPARE(sv.pmText(), QLatin1String("em"));
1815
1816 QLocale nn("nl_NL");
1817 QCOMPARE(nn.amText(), QLatin1String("AM"));
1818 QCOMPARE(nn.pmText(), QLatin1String("PM"));
1819
1820 QLocale ua("uk_UA");
1821 QCOMPARE(ua.amText(), QString::fromUtf8("\320\264\320\277"));
1822 QCOMPARE(ua.pmText(), QString::fromUtf8("\320\277\320\277"));
1823
1824 QLocale tr("tr_TR");
1825 QCOMPARE(tr.amText(), QString::fromUtf8("\303\226\303\226"));
1826 QCOMPARE(tr.pmText(), QString::fromUtf8("\303\226\123"));
1827
1828 QLocale id("id_ID");
1829 QCOMPARE(id.amText(), QLatin1String("AM"));
1830 QCOMPARE(id.pmText(), QLatin1String("PM"));
1831
1832 QLocale ta("ta_LK");
1833 QCOMPARE(ta.amText(), QLatin1String("AM"));
1834 QCOMPARE(ta.pmText(), QLatin1String("PM"));
1835 }
1836
dateFormat()1837 void tst_QLocale::dateFormat()
1838 {
1839 const QLocale c(QLocale::C);
1840 // check that the NarrowFormat is the same as ShortFormat.
1841 QCOMPARE(c.dateFormat(QLocale::NarrowFormat), c.dateFormat(QLocale::ShortFormat));
1842
1843 const QLocale no("no_NO");
1844 QCOMPARE(no.dateFormat(QLocale::NarrowFormat), QLatin1String("dd.MM.yy"));
1845 QCOMPARE(no.dateFormat(QLocale::ShortFormat), QLatin1String("dd.MM.yy"));
1846 QCOMPARE(no.dateFormat(QLocale::LongFormat), QLatin1String("dddd d. MMMM yyyy"));
1847
1848 const QLocale ca("en_CA");
1849 QCOMPARE(ca.dateFormat(QLocale::ShortFormat), QLatin1String("M/d/yy"));
1850 QCOMPARE(ca.dateFormat(QLocale::LongFormat), QLatin1String("dddd, MMMM d, yyyy"));
1851
1852 const QLocale ja("ja_JP");
1853 QCOMPARE(ja.dateFormat(QLocale::ShortFormat), QLatin1String("yyyy/MM/dd"));
1854
1855 const QLocale ir("ga_IE");
1856 QCOMPARE(ir.dateFormat(QLocale::ShortFormat), QLatin1String("dd/MM/yyyy"));
1857 }
1858
timeFormat()1859 void tst_QLocale::timeFormat()
1860 {
1861 const QLocale c(QLocale::C);
1862 // check that the NarrowFormat is the same as ShortFormat.
1863 QCOMPARE(c.timeFormat(QLocale::NarrowFormat), c.timeFormat(QLocale::ShortFormat));
1864
1865 const QLocale no("no_NO");
1866 QCOMPARE(no.timeFormat(QLocale::NarrowFormat), QLatin1String("HH:mm"));
1867 QCOMPARE(no.timeFormat(QLocale::ShortFormat), QLatin1String("HH:mm"));
1868 QCOMPARE(no.timeFormat(QLocale::LongFormat), QLatin1String("'kl'. HH:mm:ss t"));
1869
1870 const QLocale id("id_ID");
1871 QCOMPARE(id.timeFormat(QLocale::ShortFormat), QLatin1String("HH.mm"));
1872 QCOMPARE(id.timeFormat(QLocale::LongFormat), QLatin1String("HH.mm.ss t"));
1873
1874 const QLocale cat("ca_ES");
1875 QCOMPARE(cat.timeFormat(QLocale::ShortFormat), QLatin1String("H.mm"));
1876 QCOMPARE(cat.timeFormat(QLocale::LongFormat), QLatin1String("H.mm.ss t"));
1877
1878 const QLocale bra("pt_BR");
1879 QCOMPARE(bra.timeFormat(QLocale::ShortFormat), QLatin1String("HH:mm"));
1880 QCOMPARE(bra.timeFormat(QLocale::LongFormat), QLatin1String("HH:mm:ss t"));
1881 }
1882
dateTimeFormat()1883 void tst_QLocale::dateTimeFormat()
1884 {
1885 const QLocale c(QLocale::C);
1886 // check that the NarrowFormat is the same as ShortFormat.
1887 QCOMPARE(c.dateTimeFormat(QLocale::NarrowFormat), c.dateTimeFormat(QLocale::ShortFormat));
1888
1889 const QLocale no("no_NO");
1890 QCOMPARE(no.dateTimeFormat(QLocale::NarrowFormat), QLatin1String("dd.MM.yy HH:mm"));
1891 QCOMPARE(no.dateTimeFormat(QLocale::ShortFormat), QLatin1String("dd.MM.yy HH:mm"));
1892 QCOMPARE(no.dateTimeFormat(QLocale::LongFormat), QLatin1String("dddd d. MMMM yyyy 'kl'. HH:mm:ss t"));
1893 }
1894
monthName()1895 void tst_QLocale::monthName()
1896 {
1897 const QLocale c(QLocale::C);
1898 QCOMPARE(c.monthName(0, QLocale::ShortFormat), QString());
1899 QCOMPARE(c.monthName(0, QLocale::LongFormat), QString());
1900 QCOMPARE(c.monthName(0, QLocale::NarrowFormat), QString());
1901 QCOMPARE(c.monthName(13, QLocale::ShortFormat), QString());
1902 QCOMPARE(c.monthName(13, QLocale::LongFormat), QString());
1903 QCOMPARE(c.monthName(13, QLocale::NarrowFormat), QString());
1904
1905 QCOMPARE(c.monthName(1, QLocale::LongFormat), QLatin1String("January"));
1906 QCOMPARE(c.monthName(1, QLocale::ShortFormat), QLatin1String("Jan"));
1907 QCOMPARE(c.monthName(1, QLocale::NarrowFormat), QLatin1String("1"));
1908
1909 const QLocale de("de_DE");
1910 QCOMPARE(de.monthName(12, QLocale::LongFormat), QLatin1String("Dezember"));
1911 QCOMPARE(de.monthName(12, QLocale::ShortFormat), QLatin1String("Dez"));
1912 // 'de' locale doesn't have narrow month name
1913 QCOMPARE(de.monthName(12, QLocale::NarrowFormat), QLatin1String("D"));
1914
1915 QLocale ru("ru_RU");
1916 QCOMPARE(ru.monthName(1, QLocale::LongFormat), QString::fromUtf8("\321\217\320\275\320\262\320\260\321\200\321\217"));
1917 QCOMPARE(ru.monthName(1, QLocale::ShortFormat), QString::fromUtf8("\321\217\320\275\320\262"));
1918 QCOMPARE(ru.monthName(1, QLocale::NarrowFormat), QString::fromUtf8("\320\257"));
1919
1920 // check that our CLDR scripts handle surrogate pairs correctly
1921 QLocale dsrt("en-Dsrt-US");
1922 QCOMPARE(dsrt.monthName(1, QLocale::LongFormat), QString::fromUtf8("\xf0\x90\x90\x96\xf0\x90\x90\xb0\xf0\x90\x91\x8c\xf0\x90\x90\xb7\xf0\x90\x90\xad\xf0\x90\x90\xaf\xf0\x90\x91\x89\xf0\x90\x90\xa8"));
1923
1924 QLocale ir("ga_IE");
1925 QCOMPARE(ir.monthName(1, QLocale::ShortFormat), QLatin1String("Ean"));
1926 QCOMPARE(ir.monthName(12, QLocale::ShortFormat), QLatin1String("Noll"));
1927
1928 QLocale cz("cs_CZ");
1929 QCOMPARE(cz.monthName(1, QLocale::ShortFormat), QLatin1String("led"));
1930 QCOMPARE(cz.monthName(12, QLocale::ShortFormat), QLatin1String("pro"));
1931 }
1932
standaloneMonthName()1933 void tst_QLocale::standaloneMonthName()
1934 {
1935 const QLocale c(QLocale::C);
1936 QCOMPARE(c.monthName(0, QLocale::ShortFormat), QString());
1937 QCOMPARE(c.monthName(0, QLocale::LongFormat), QString());
1938 QCOMPARE(c.monthName(0, QLocale::NarrowFormat), QString());
1939 QCOMPARE(c.monthName(13, QLocale::ShortFormat), QString());
1940 QCOMPARE(c.monthName(13, QLocale::LongFormat), QString());
1941 QCOMPARE(c.monthName(13, QLocale::NarrowFormat), QString());
1942
1943 QCOMPARE(c.standaloneMonthName(1, QLocale::LongFormat), QLatin1String("January"));
1944 QCOMPARE(c.standaloneMonthName(1, QLocale::ShortFormat), QLatin1String("Jan"));
1945
1946 const QLocale de("de_DE");
1947 // For de_DE locale Unicode CLDR database doesn't contain standalone long months
1948 // so just checking if the return value is the same as in monthName().
1949 QCOMPARE(de.standaloneMonthName(12, QLocale::LongFormat), QLatin1String("Dezember"));
1950 QCOMPARE(de.standaloneMonthName(12, QLocale::LongFormat), de.monthName(12, QLocale::LongFormat));
1951 QCOMPARE(de.standaloneMonthName(12, QLocale::ShortFormat), QLatin1String("Dez"));
1952 QCOMPARE(de.standaloneMonthName(12, QLocale::NarrowFormat), QLatin1String("D"));
1953
1954 QLocale ru("ru_RU");
1955 QCOMPARE(ru.standaloneMonthName(1, QLocale::LongFormat), QString::fromUtf8("\320\257\320\275\320\262\320\260\321\200\321\214"));
1956 QCOMPARE(ru.standaloneMonthName(1, QLocale::ShortFormat), QString::fromUtf8("\320\257\320\275\320\262\56"));
1957 QCOMPARE(ru.standaloneMonthName(1, QLocale::NarrowFormat), QString::fromUtf8("\320\257"));
1958 }
1959
1960 #if defined(Q_OS_SYMBIAN)
symbianSystemLocale()1961 void tst_QLocale::symbianSystemLocale()
1962 {
1963 # if defined(__SERIES60_31__)
1964 QSKIP("S60 3.1 doesn't support system format properly", SkipAll);
1965 # else
1966 // Simple test to verify that Symbian system locale works at all
1967 const QSystemLocale locale;
1968 TExtendedLocale s60Locale;
1969 s60Locale.LoadSystemSettings();
1970
1971 TTime s60Date(_L("20090117:")); // Symbian offsets day and month from zero
1972 QDate date(2009,2,18);
1973
1974 TPtrC s60DateFormat = s60Locale.GetShortDateFormatSpec();
1975 QString dateFormat = locale.query(QSystemLocale::DateFormatShort, QVariant()).toString();
1976
1977 TBuf<50> s60FormattedDate;
1978 TRAPD(err, s60Date.FormatL(s60FormattedDate, s60DateFormat));
1979 QVERIFY(err == KErrNone);
1980 QString s60FinalResult = qt_TDesC2QString(s60FormattedDate);
1981 QString finalResult = date.toString(dateFormat);
1982
1983 QCOMPARE(finalResult, s60FinalResult);
1984 # endif
1985 }
1986 #endif
1987
currency()1988 void tst_QLocale::currency()
1989 {
1990 const QLocale c(QLocale::C);
1991 QCOMPARE(c.toCurrencyString(qulonglong(1234)), QString("1234"));
1992 QCOMPARE(c.toCurrencyString(qlonglong(-1234)), QString("-1234"));
1993 QCOMPARE(c.toCurrencyString(double(1234.56)), QString("1234.56"));
1994 QCOMPARE(c.toCurrencyString(double(-1234.56)), QString("-1234.56"));
1995
1996 const QLocale ru_RU("ru_RU");
1997 QCOMPARE(ru_RU.toCurrencyString(qulonglong(1234)), QString::fromUtf8("1234\xc2\xa0\xd1\x80\xd1\x83\xd0\xb1."));
1998 QCOMPARE(ru_RU.toCurrencyString(qlonglong(-1234)), QString::fromUtf8("-1234\xc2\xa0\xd1\x80\xd1\x83\xd0\xb1."));
1999 QCOMPARE(ru_RU.toCurrencyString(double(1234.56)), QString::fromUtf8("1234,56\xc2\xa0\xd1\x80\xd1\x83\xd0\xb1."));
2000 QCOMPARE(ru_RU.toCurrencyString(double(-1234.56)), QString::fromUtf8("-1234,56\xc2\xa0\xd1\x80\xd1\x83\xd0\xb1."));
2001
2002 const QLocale de_DE("de_DE");
2003 QCOMPARE(de_DE.toCurrencyString(qulonglong(1234)), QString::fromUtf8("1234\xc2\xa0\xe2\x82\xac"));
2004 QCOMPARE(de_DE.toCurrencyString(qulonglong(1234), QLatin1String("BAZ")), QString::fromUtf8("1234\xc2\xa0" "BAZ"));
2005 QCOMPARE(de_DE.toCurrencyString(qlonglong(-1234)), QString::fromUtf8("-1234\xc2\xa0\xe2\x82\xac"));
2006 QCOMPARE(de_DE.toCurrencyString(qlonglong(-1234), QLatin1String("BAZ")), QString::fromUtf8("-1234\xc2\xa0" "BAZ"));
2007 QCOMPARE(de_DE.toCurrencyString(double(1234.56)), QString::fromUtf8("1234,56\xc2\xa0\xe2\x82\xac"));
2008 QCOMPARE(de_DE.toCurrencyString(double(-1234.56)), QString::fromUtf8("-1234,56\xc2\xa0\xe2\x82\xac"));
2009 QCOMPARE(de_DE.toCurrencyString(double(-1234.56), QLatin1String("BAZ")), QString::fromUtf8("-1234,56\xc2\xa0" "BAZ"));
2010
2011 const QLocale system = QLocale::system();
2012 QVERIFY(system.toCurrencyString(1, QLatin1String("FOO")).contains(QLatin1String("FOO")));
2013 }
2014
quoteString()2015 void tst_QLocale::quoteString()
2016 {
2017 const QString someText("text");
2018 const QLocale c(QLocale::C);
2019 QCOMPARE(c.quoteString(someText), QString::fromUtf8("\x22" "text" "\x22"));
2020 QCOMPARE(c.quoteString(someText, QLocale::AlternateQuotation), QString::fromUtf8("\x27" "text" "\x27"));
2021
2022 const QLocale de_CH("de_CH");
2023 QCOMPARE(de_CH.quoteString(someText), QString::fromUtf8("\xc2\xab" "text" "\xc2\xbb"));
2024 QCOMPARE(de_CH.quoteString(someText, QLocale::AlternateQuotation), QString::fromUtf8("\xe2\x80\xb9" "text" "\xe2\x80\xba"));
2025
2026 }
2027
uiLanguages()2028 void tst_QLocale::uiLanguages()
2029 {
2030 const QLocale c(QLocale::C);
2031 QCOMPARE(c.uiLanguages().size(), 1);
2032 QCOMPARE(c.uiLanguages().at(0), QLatin1String("C"));
2033
2034 const QLocale en_US("en_US");
2035 QCOMPARE(en_US.uiLanguages().size(), 1);
2036 QCOMPARE(en_US.uiLanguages().at(0), QLatin1String("en-US"));
2037
2038 const QLocale ru_RU("ru_RU");
2039 QCOMPARE(ru_RU.uiLanguages().size(), 1);
2040 QCOMPARE(ru_RU.uiLanguages().at(0), QLatin1String("ru-RU"));
2041 }
2042
weekendDays()2043 void tst_QLocale::weekendDays()
2044 {
2045 const QLocale c(QLocale::C);
2046 QList<Qt::DayOfWeek> days;
2047 days << Qt::Monday << Qt::Tuesday << Qt::Wednesday << Qt::Thursday << Qt::Friday;
2048 QCOMPARE(c.weekdays(), days);
2049 }
2050
listPatterns()2051 void tst_QLocale::listPatterns()
2052 {
2053 QStringList sl1;
2054 QStringList sl2;
2055 sl2 << "aaa";
2056 QStringList sl3;
2057 sl3 << "aaa" << "bbb";
2058 QStringList sl4;
2059 sl4 << "aaa" << "bbb" << "ccc";
2060 QStringList sl5;
2061 sl5 << "aaa" << "bbb" << "ccc" << "ddd";
2062
2063 const QLocale c(QLocale::C);
2064 QCOMPARE(c.createSeparatedList(sl1), QString(""));
2065 QCOMPARE(c.createSeparatedList(sl2), QString("aaa"));
2066 QCOMPARE(c.createSeparatedList(sl3), QString("aaa, bbb"));
2067 QCOMPARE(c.createSeparatedList(sl4), QString("aaa, bbb, ccc"));
2068 QCOMPARE(c.createSeparatedList(sl5), QString("aaa, bbb, ccc, ddd"));
2069
2070 const QLocale en_US("en_US");
2071 QCOMPARE(en_US.createSeparatedList(sl1), QString(""));
2072 QCOMPARE(en_US.createSeparatedList(sl2), QString("aaa"));
2073 QCOMPARE(en_US.createSeparatedList(sl3), QString("aaa and bbb"));
2074 QCOMPARE(en_US.createSeparatedList(sl4), QString("aaa, bbb, and ccc"));
2075 QCOMPARE(en_US.createSeparatedList(sl5), QString("aaa, bbb, ccc, and ddd"));
2076
2077 const QLocale zh_CN("zh_CN");
2078 QCOMPARE(zh_CN.createSeparatedList(sl1), QString(""));
2079 QCOMPARE(zh_CN.createSeparatedList(sl2), QString("aaa"));
2080 QCOMPARE(zh_CN.createSeparatedList(sl3), QString::fromUtf8("aaa" "\xe5\x92\x8c" "bbb"));
2081 QCOMPARE(zh_CN.createSeparatedList(sl4), QString::fromUtf8("aaa" "\xe3\x80\x81" "bbb" "\xe5\x92\x8c" "ccc"));
2082 QCOMPARE(zh_CN.createSeparatedList(sl5), QString::fromUtf8("aaa" "\xe3\x80\x81" "bbb" "\xe3\x80\x81" "ccc" "\xe5\x92\x8c" "ddd"));
2083 }
2084
2085 QTEST_APPLESS_MAIN(tst_QLocale)
2086 #include "tst_qlocale.moc"
2087