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