diff options
author | Denis Dzyubenko <denis.dzyubenko@nokia.com> | 2011-02-08 18:53:55 (GMT) |
---|---|---|
committer | Denis Dzyubenko <denis.dzyubenko@nokia.com> | 2011-02-17 13:35:17 (GMT) |
commit | 2f880e66c2dedc8b072dca4672035fc5b2e659bc (patch) | |
tree | a34049c3c2ba8ddf7fbf5076e484d2a70508f776 /tests/auto/qlocale | |
parent | 8a74c5112aa81c5638b14d8b5285e6ef8474a195 (diff) | |
download | Qt-2f880e66c2dedc8b072dca4672035fc5b2e659bc.zip Qt-2f880e66c2dedc8b072dca4672035fc5b2e659bc.tar.gz Qt-2f880e66c2dedc8b072dca4672035fc5b2e659bc.tar.bz2 |
Added currency support for QLocale
REMARK: This commit is missing updated static cldr data in
src/corelib/tools/qlocale_data_p.h that has been left out
intentionally to avoid repository bloating.
Before compiling make sure to update that file using the scripts
util/local_database/cldr2qlocalexml.py and
util/local_database/qlocalexml2cpp.py.
Otherwise you will most likely experience segmentation faults.
Task-number: QTBUG-17100
Reviewed-by: Zeno Albisser
Diffstat (limited to 'tests/auto/qlocale')
-rw-r--r-- | tests/auto/qlocale/tst_qlocale.cpp | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/tests/auto/qlocale/tst_qlocale.cpp b/tests/auto/qlocale/tst_qlocale.cpp index 16846de..08c96a0 100644 --- a/tests/auto/qlocale/tst_qlocale.cpp +++ b/tests/auto/qlocale/tst_qlocale.cpp @@ -140,6 +140,7 @@ private slots: #endif void ampm(); + void currency(); private: QString m_decimal, m_thousand, m_sdate, m_ldate, m_time; @@ -1095,6 +1096,11 @@ void tst_QLocale::macDefaultLocale() const QString timeString = locale.toString(QTime(1,2,3), QLocale::LongFormat); QVERIFY(timeString.contains(QString("1:02:03"))); + QCOMPARE(locale.toCurrencyString(qulonglong(1234)), QString("$1,234")); + QCOMPARE(locale.toCurrencyString(qlonglong(-1234)), QString("$-1,234")); + QCOMPARE(locale.toCurrencyString(double(1234.56)), QString("$1,234.56")); + QCOMPARE(locale.toCurrencyString(double(-1234.56)), QString("$-1,234.56")); + // Depending on the configured time zone, the time string might not // contain a GMT specifier. (Sometimes it just names the zone, like "CEST") if (timeString.contains(QString("GMT"))) { @@ -2123,5 +2129,26 @@ void tst_QLocale::symbianSystemLocale() } #endif +void tst_QLocale::currency() +{ + const QLocale c(QLocale::C); + QCOMPARE(c.toCurrencyString(qulonglong(1234)), QString("1234")); + QCOMPARE(c.toCurrencyString(qlonglong(-1234)), QString("-1234")); + QCOMPARE(c.toCurrencyString(double(1234.56)), QString("1234.56")); + QCOMPARE(c.toCurrencyString(double(-1234.56)), QString("-1234.56")); + + const QLocale ru_RU("ru_RU"); + QCOMPARE(ru_RU.toCurrencyString(qulonglong(1234)), QString::fromUtf8("1234\xc2\xa0\xd1\x80\xd1\x83\xd0\xb1.")); + QCOMPARE(ru_RU.toCurrencyString(qlonglong(-1234)), QString::fromUtf8("-1234\xc2\xa0\xd1\x80\xd1\x83\xd0\xb1.")); + QCOMPARE(ru_RU.toCurrencyString(double(1234.56)), QString::fromUtf8("1234,56\xc2\xa0\xd1\x80\xd1\x83\xd0\xb1.")); + QCOMPARE(ru_RU.toCurrencyString(double(-1234.56)), QString::fromUtf8("-1234,56\xc2\xa0\xd1\x80\xd1\x83\xd0\xb1.")); + + const QLocale de_DE("de_DE"); + QCOMPARE(de_DE.toCurrencyString(qulonglong(1234)), QString::fromUtf8("1234""\xc2\xa0\xe2\x82\xac")); + QCOMPARE(de_DE.toCurrencyString(qlonglong(-1234)), QString::fromUtf8("-1234""\xc2\xa0\xe2\x82\xac")); + QCOMPARE(de_DE.toCurrencyString(double(1234.56)), QString::fromUtf8("1234,56""\xc2\xa0\xe2\x82\xac")); + QCOMPARE(de_DE.toCurrencyString(double(-1234.56)), QString::fromUtf8("-1234,56""\xc2\xa0\xe2\x82\xac")); +} + QTEST_APPLESS_MAIN(tst_QLocale) #include "tst_qlocale.moc" |