summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib/text/qlocale/tst_qlocale.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/corelib/text/qlocale/tst_qlocale.cpp')
-rw-r--r--tests/auto/corelib/text/qlocale/tst_qlocale.cpp101
1 files changed, 76 insertions, 25 deletions
diff --git a/tests/auto/corelib/text/qlocale/tst_qlocale.cpp b/tests/auto/corelib/text/qlocale/tst_qlocale.cpp
index 676c66df3e..60ed22488f 100644
--- a/tests/auto/corelib/text/qlocale/tst_qlocale.cpp
+++ b/tests/auto/corelib/text/qlocale/tst_qlocale.cpp
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2016 The Qt Company Ltd.
+** Copyright (C) 2020 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the test suite of the Qt Toolkit.
@@ -147,6 +147,8 @@ private slots:
void systemLocale_data();
void systemLocale();
+ void IndianNumberGrouping();
+
// *** ORDER-DEPENDENCY *** (This Is Bad.)
// Test order is determined by order of declaration here: *all* tests that
// QLocale::setDefault() *must* appear *after* all other tests !
@@ -595,10 +597,7 @@ void tst_QLocale::emptyCtor_data()
ADD_CTOR_TEST("zz_zz", "C");
ADD_CTOR_TEST("zz...", "C");
ADD_CTOR_TEST("en.bla", "en_US");
-#if !(defined(Q_OS_DARWIN) && QT_HAS_FEATURE(address_sanitizer))
- // See QTBUG-69875
ADD_CTOR_TEST("en@bla", "en_US");
-#endif
ADD_CTOR_TEST("en_blaaa", "en_US");
ADD_CTOR_TEST("en_zz", "en_US");
ADD_CTOR_TEST("en_GB.bla", "en_GB");
@@ -607,10 +606,7 @@ void tst_QLocale::emptyCtor_data()
// Empty optional fields, but with punctuators supplied
ADD_CTOR_TEST("en.", "en_US");
-#if !(defined(Q_OS_DARWIN) && QT_HAS_FEATURE(address_sanitizer))
- // See QTBUG-69875
ADD_CTOR_TEST("en@", "en_US");
-#endif
ADD_CTOR_TEST("en.@", "en_US");
ADD_CTOR_TEST("en_", "en_US");
ADD_CTOR_TEST("en_.", "en_US");
@@ -1873,14 +1869,16 @@ void tst_QLocale::toDateTime()
// Format number string according to system locale settings.
// Expected in format is US "1,234.56".
-QString systemLocaleFormatNumber(const QString &numberString)
+QString systemLocaleFormatNumber(QString &&numberString)
{
QLocale locale = QLocale::system();
- QString numberStringCopy = numberString;
- return numberStringCopy.replace(QChar(','), QChar('G'))
- .replace(QChar('.'), QChar('D'))
- .replace(QChar('G'), locale.groupSeparator())
- .replace(QChar('D'), locale.decimalPoint());
+ QString numberStringMunged =
+ numberString.replace(QChar(','), QChar('G')).replace(QChar('.'), QChar('D'));
+ if (locale.numberOptions() & QLocale::OmitGroupSeparator)
+ numberStringMunged.remove(QLatin1Char('G'));
+ else
+ numberStringMunged.replace(QChar('G'), locale.groupSeparator());
+ return numberStringMunged.replace(QChar('D'), locale.decimalPoint());
}
void tst_QLocale::macDefaultLocale()
@@ -1903,12 +1901,14 @@ void tst_QLocale::macDefaultLocale()
// independently of the locale. Verify that they have one of the
// allowed values and are not the same.
QVERIFY(locale.decimalPoint() == QChar('.') || locale.decimalPoint() == QChar(','));
- QVERIFY(locale.groupSeparator() == QChar(',')
- || locale.groupSeparator() == QChar('.')
- || locale.groupSeparator() == QChar('\xA0') // no-breaking space
- || locale.groupSeparator() == QChar('\'')
- || locale.groupSeparator() == QChar());
- QVERIFY(locale.decimalPoint() != locale.groupSeparator());
+ if (!(locale.numberOptions() & QLocale::OmitGroupSeparator)) {
+ QVERIFY(locale.groupSeparator() == QChar(',')
+ || locale.groupSeparator() == QChar('.')
+ || locale.groupSeparator() == QChar('\xA0') // no-breaking space
+ || locale.groupSeparator() == QChar('\'')
+ || locale.groupSeparator() == QChar());
+ QVERIFY(locale.decimalPoint() != locale.groupSeparator());
+ }
// make sure we are using the system to parse them
QCOMPARE(locale.toString(1234.56), systemLocaleFormatNumber(QString("1,234.56")));
@@ -2459,9 +2459,9 @@ void tst_QLocale::timeFormat()
QCOMPARE(c.timeFormat(QLocale::NarrowFormat), c.timeFormat(QLocale::ShortFormat));
const QLocale no("no_NO");
- QCOMPARE(no.timeFormat(QLocale::NarrowFormat), QLatin1String("HH.mm"));
- QCOMPARE(no.timeFormat(QLocale::ShortFormat), QLatin1String("HH.mm"));
- QCOMPARE(no.timeFormat(QLocale::LongFormat), QLatin1String("HH.mm.ss t"));
+ QCOMPARE(no.timeFormat(QLocale::NarrowFormat), QLatin1String("HH:mm"));
+ QCOMPARE(no.timeFormat(QLocale::ShortFormat), QLatin1String("HH:mm"));
+ QCOMPARE(no.timeFormat(QLocale::LongFormat), QLatin1String("HH:mm:ss t"));
const QLocale id("id_ID");
QCOMPARE(id.timeFormat(QLocale::ShortFormat), QLatin1String("HH.mm"));
@@ -2483,9 +2483,9 @@ void tst_QLocale::dateTimeFormat()
QCOMPARE(c.dateTimeFormat(QLocale::NarrowFormat), c.dateTimeFormat(QLocale::ShortFormat));
const QLocale no("no_NO");
- QCOMPARE(no.dateTimeFormat(QLocale::NarrowFormat), QLatin1String("dd.MM.yyyy HH.mm"));
- QCOMPARE(no.dateTimeFormat(QLocale::ShortFormat), QLatin1String("dd.MM.yyyy HH.mm"));
- QCOMPARE(no.dateTimeFormat(QLocale::LongFormat), QLatin1String("dddd d. MMMM yyyy HH.mm.ss t"));
+ QCOMPARE(no.dateTimeFormat(QLocale::NarrowFormat), QLatin1String("dd.MM.yyyy HH:mm"));
+ QCOMPARE(no.dateTimeFormat(QLocale::ShortFormat), QLatin1String("dd.MM.yyyy HH:mm"));
+ QCOMPARE(no.dateTimeFormat(QLocale::LongFormat), QLatin1String("dddd d. MMMM yyyy HH:mm:ss t"));
}
void tst_QLocale::monthName()
@@ -2997,5 +2997,56 @@ void tst_QLocale::systemLocale()
QCOMPARE(QLocale::system(), originalSystemLocale);
}
+void tst_QLocale::IndianNumberGrouping()
+{
+ QLocale indian(QLocale::Hindi, QLocale::India);
+
+ qint8 int8 = 100;
+ QString strResult8("100");
+ QCOMPARE(indian.toString(int8), strResult8);
+ QCOMPARE(indian.toShort(strResult8), short(int8));
+
+ quint8 uint8 = 100;
+ QCOMPARE(indian.toString(uint8), strResult8);
+ QCOMPARE(indian.toShort(strResult8), short(uint8));
+
+ // Boundary case 1000 for short and ushort
+ short shortInt = 1000;
+ QString strResult16("1,000");
+ QCOMPARE(indian.toString(shortInt), strResult16);
+ QCOMPARE(indian.toShort(strResult16), shortInt);
+
+ ushort uShortInt = 1000;
+ QCOMPARE(indian.toString(uShortInt), strResult16);
+ QCOMPARE(indian.toUShort(strResult16), uShortInt);
+
+ shortInt = 10000;
+ strResult16 = "10,000";
+ QCOMPARE(indian.toString(shortInt), strResult16);
+ QCOMPARE(indian.toShort(strResult16), shortInt);
+
+ uShortInt = 10000;
+ QCOMPARE(indian.toString(uShortInt), strResult16);
+ QCOMPARE(indian.toUShort(strResult16), uShortInt);
+
+ int intInt = 1000000000;
+ QString strResult32("1,00,00,00,000");
+ QCOMPARE(indian.toString(intInt), strResult32);
+ QCOMPARE(indian.toInt(strResult32), intInt);
+
+ uint uIntInt = 1000000000;
+ QCOMPARE(indian.toString(uIntInt), strResult32);
+ QCOMPARE(indian.toUInt(strResult32), uIntInt);
+
+ QString strResult64("10,00,00,00,00,00,00,00,000");
+ qint64 int64 = Q_INT64_C(1000000000000000000);
+ QCOMPARE(indian.toString(int64), strResult64);
+ QCOMPARE(indian.toLongLong(strResult64), int64);
+
+ quint64 uint64 = Q_UINT64_C(1000000000000000000);
+ QCOMPARE(indian.toString(uint64), strResult64);
+ QCOMPARE(indian.toULongLong(strResult64), uint64);
+}
+
QTEST_MAIN(tst_QLocale)
#include "tst_qlocale.moc"