File indexing completed on 2024-11-24 03:40:36

0001 /*
0002   This file is part of the KTextTemplate library
0003 
0004   SPDX-FileCopyrightText: 2010 Stephen Kelly <steveire@gmail.com>
0005 
0006   SPDX-License-Identifier: LGPL-2.1-or-later
0007 
0008 */
0009 
0010 #include "engine.h"
0011 #include "ktexttemplate_paths.h"
0012 #include "nulllocalizer_p.h"
0013 #include "qtlocalizer.h"
0014 #include "util.h"
0015 
0016 #include <QScopedPointer>
0017 #include <QTest>
0018 #include <QTranslator>
0019 
0020 using namespace KTextTemplate;
0021 
0022 #define FR_THOUSAND_SEPARATOR "\u202F"
0023 
0024 #define INIT_LOCALIZER(localizer)                                                                                                                              \
0025     localizer->setAppTranslatorPrefix(QStringLiteral("test_"));                                                                                                \
0026     localizer->setAppTranslatorPath(QStringLiteral(":/"));
0027 
0028 class TestInternationalization : public QObject
0029 {
0030     Q_OBJECT
0031 public:
0032     explicit TestInternationalization(QObject *parent = {})
0033         : QObject(parent)
0034         , nullLocalizer(new NullLocalizer())
0035         , deLocalizer(new QtLocalizer(QLocale(QLocale::German, QLocale::Germany)))
0036         , frLocalizer(new QtLocalizer(QLocale(QLocale::French, QLocale::France)))
0037         , en_GBLocalizer(new QtLocalizer(QLocale(QLocale::English, QLocale::UnitedKingdom)))
0038         , en_USLocalizer(new QtLocalizer(QLocale(QLocale::English, QLocale::UnitedStates)))
0039         , m_engine(new Engine(this))
0040     {
0041         auto cLocale = QLocale::c();
0042         cLocale.setNumberOptions(QLocale::OmitGroupSeparator);
0043         cLocalizer.reset(new QtLocalizer(cLocale));
0044         m_engine->setPluginPaths({QStringLiteral(KTEXTTEMPLATE_PLUGIN_PATH)});
0045         INIT_LOCALIZER(cLocalizer)
0046         INIT_LOCALIZER(deLocalizer)
0047         INIT_LOCALIZER(frLocalizer)
0048         INIT_LOCALIZER(en_GBLocalizer)
0049         INIT_LOCALIZER(en_USLocalizer)
0050         {
0051             auto deTranslator = new QTranslator(this);
0052             const auto result = deTranslator->load(QStringLiteral(":/test_de_DE"));
0053             Q_UNUSED(result);
0054             Q_ASSERT(result);
0055             deLocalizer->installTranslator(deTranslator, QStringLiteral("de_DE"));
0056         }
0057 
0058         {
0059             auto frTranslator = new QTranslator(this);
0060             const auto result = frTranslator->load(QStringLiteral(":/test_fr_FR.qm"));
0061             Q_UNUSED(result);
0062             Q_ASSERT(result);
0063             frLocalizer->installTranslator(frTranslator, QStringLiteral("fr_FR"));
0064         }
0065         m_engine->addDefaultLibrary(QStringLiteral("ktexttemplate_i18ntags"));
0066     }
0067 
0068 private Q_SLOTS:
0069     void initTestCase();
0070 
0071     void testContext();
0072     void testStrings();
0073     void testIntegers();
0074     void testFloats();
0075     void testDates();
0076     void testTimes();
0077     void testDateTimes();
0078     void testLocalizedTemplate();
0079     void testSafeContent();
0080     void testFailure();
0081 
0082     void testStrings_data();
0083     void testIntegers_data();
0084     void testFloats_data();
0085     void testDates_data();
0086     void testTimes_data();
0087     void testDateTimes_data();
0088     void testLocalizedTemplate_data();
0089     void testSafeContent_data();
0090     void testFailure_data();
0091 
0092 private:
0093     QSharedPointer<QtLocalizer> cLocalizer;
0094     const QSharedPointer<AbstractLocalizer> nullLocalizer;
0095     const QSharedPointer<QtLocalizer> deLocalizer;
0096     const QSharedPointer<QtLocalizer> frLocalizer;
0097     const QSharedPointer<QtLocalizer> en_GBLocalizer;
0098     const QSharedPointer<QtLocalizer> en_USLocalizer;
0099 
0100     KTextTemplate::Engine *m_engine;
0101 };
0102 
0103 void TestInternationalization::initTestCase()
0104 {
0105     Q_INIT_RESOURCE(testresource);
0106 }
0107 
0108 void TestInternationalization::testContext()
0109 {
0110     Context c;
0111     QVERIFY(c.localizer());
0112     c.setLocalizer(cLocalizer);
0113     QVERIFY(c.localizer());
0114     c.setLocalizer(QSharedPointer<KTextTemplate::AbstractLocalizer>());
0115     QVERIFY(c.localizer());
0116 }
0117 
0118 void TestInternationalization::testStrings()
0119 {
0120     QFETCH(QString, input);
0121     QFETCH(QString, null_output);
0122     QFETCH(QString, de_output);
0123     QFETCH(QString, fr_output);
0124     QFETCH(QString, disambiguation);
0125     QFETCH(QString, plural);
0126     QFETCH(QVariantList, args);
0127 
0128     if (!disambiguation.isEmpty()) {
0129         if (!plural.isEmpty()) {
0130             QCOMPARE(nullLocalizer->localizePluralContextString(input, plural, disambiguation, args), null_output);
0131             QCOMPARE(deLocalizer->localizePluralContextString(input, plural, disambiguation, args), de_output);
0132             QCOMPARE(frLocalizer->localizePluralContextString(input, plural, disambiguation, args), fr_output);
0133             return;
0134         }
0135         QCOMPARE(nullLocalizer->localizeContextString(input, disambiguation, args), null_output);
0136         QCOMPARE(deLocalizer->localizeContextString(input, disambiguation, args), de_output);
0137         QCOMPARE(frLocalizer->localizeContextString(input, disambiguation, args), fr_output);
0138         return;
0139     }
0140     if (!plural.isEmpty()) {
0141         QCOMPARE(nullLocalizer->localizePluralString(input, plural, args), null_output);
0142         QCOMPARE(deLocalizer->localizePluralString(input, plural, args), de_output);
0143         QCOMPARE(frLocalizer->localizePluralString(input, plural, args), fr_output);
0144         return;
0145     }
0146     QCOMPARE(nullLocalizer->localizeString(input, args), null_output);
0147     QCOMPARE(deLocalizer->localizeString(input, args), de_output);
0148     QCOMPARE(frLocalizer->localizeString(input, args), fr_output);
0149 }
0150 
0151 void TestInternationalization::testStrings_data()
0152 {
0153     QTest::addColumn<QString>("input");
0154     QTest::addColumn<QString>("null_output");
0155     QTest::addColumn<QString>("de_output");
0156     QTest::addColumn<QString>("fr_output");
0157     QTest::addColumn<QString>("disambiguation");
0158     QTest::addColumn<QString>("plural");
0159     QTest::addColumn<QVariantList>("args");
0160 
0161     // Translations here are not meant to be accurate, but are meant
0162     // only to test for example that disambiguation and arg reordering works.
0163 
0164     QTest::newRow("string-01") << "Birthday"
0165                                << "Birthday"
0166                                << "Geburtstag"
0167                                << "Anniversaire" << QString() << QString() << QVariantList();
0168 
0169     QTest::newRow("string-02") << "%n People"
0170                                << "1 People"
0171                                << "1 Person"
0172                                << "1 Personne" << QString() << QStringLiteral("%n People") << QVariantList{1};
0173 
0174     QTest::newRow("string-03") << "%n People"
0175                                << "2 People"
0176                                << "2 Personen"
0177                                << "2 Personnes" << QString() << QStringLiteral("%n People") << QVariantList{2};
0178 
0179     QTest::newRow("string-04") << "Name"
0180                                << "Name"
0181                                << "Name eines Buches"
0182                                << "Nom d'un livre" << QStringLiteral("Name of a Book") << QString() << QVariantList();
0183 
0184     QTest::newRow("string-05") << "Name"
0185                                << "Name"
0186                                << "Namen einer Person"
0187                                << "Nom d'une personne" << QStringLiteral("Name of a Person") << QString() << QVariantList();
0188 
0189     QTest::newRow("string-06") << "%n People"
0190                                << "1 People"
0191                                << "1 Person angemeldet" << QStringLiteral("1 Personne connecté") << QStringLiteral("%n people are logged in")
0192                                << QStringLiteral("%n People") << QVariantList{1};
0193 
0194     QTest::newRow("string-07") << "%n People"
0195                                << "2 People"
0196                                << "2 Personen angemeldet" << QStringLiteral("2 Personnes connecté") << QStringLiteral("%n people are logged in")
0197                                << QStringLiteral("%n People") << QVariantList{2};
0198 
0199     QTest::newRow("string-08") << "%n file(s) copied to %1"
0200                                << "1 files copied to destinationFolder"
0201                                << "1 Datei in destinationFolder kopiert" << QStringLiteral("1 fichier copié dans destinationFolder") << QString()
0202                                << QStringLiteral("%n files copied to %1") << QVariantList{1, QStringLiteral("destinationFolder")};
0203 
0204     QTest::newRow("string-09") << "%n file(s) copied to %1"
0205                                << "2 files copied to destinationFolder"
0206                                << "2 Datein in destinationFolder kopiert" << QStringLiteral("2 fichiers copiés dans destinationFolder") << QString()
0207                                << QStringLiteral("%n files copied to %1") << QVariantList{2, QStringLiteral("destinationFolder")};
0208 
0209     QTest::newRow("string-10") << "%n to %1"
0210                                << "1 copied to destinationFolder"
0211                                << "1 Datei wird nach destinationFolder kopiert" << QStringLiteral("1 fichier est copié sur destinationFolder")
0212                                << QStringLiteral("Files are being copied") << QStringLiteral("%n copied to %1")
0213                                << QVariantList{1, QStringLiteral("destinationFolder")};
0214 
0215     QTest::newRow("string-11") << "%n to %1"
0216                                << "1 copied to destinationFolder"
0217                                << "1 Datei war nach destinationFolder kopiert" << QStringLiteral("1 fichier a été copié à destinationFolder")
0218                                << QStringLiteral("Files have already been copied") << QStringLiteral("%n copied to %1")
0219                                << QVariantList{1, QStringLiteral("destinationFolder")};
0220 
0221     QTest::newRow("string-12") << "%n to %1"
0222                                << "2 copied to destinationFolder"
0223                                << "2 Datein wird nach destinationFolder kopiert" << QStringLiteral("2 fichiers sont copiés à destinationFolder")
0224                                << QStringLiteral("Files are being copied") << QStringLiteral("%n copied to %1")
0225                                << QVariantList{2, QStringLiteral("destinationFolder")};
0226 
0227     QTest::newRow("string-13") << "%n to %1"
0228                                << "2 copied to destinationFolder"
0229                                << "2 Datein war nach destinationFolder kopiert" << QStringLiteral("2 fichiers ont été copiés sur destinationFolder")
0230                                << QStringLiteral("Files have already been copied") << QStringLiteral("%n copied to %1")
0231                                << QVariantList{2, QStringLiteral("destinationFolder")};
0232 
0233     QTest::newRow("string-14") << "from %1 to %2"
0234                                << "from sourceFolder to destinationFolder"
0235                                << "nach destinationFolder von sourceFolder" << QStringLiteral("à partir de sourceFolder destinationFolder")
0236                                << QStringLiteral("Files are being copied from %1 to %2") << QString()
0237                                << QVariantList{QStringLiteral("sourceFolder"), QStringLiteral("destinationFolder")};
0238 
0239     QTest::newRow("string-15") << "%1 messages at %2, fraction of total: %3. Rating : %4"
0240                                << "1000 messages at 2005-05-07, fraction of total: 0.6. Rating : 4.8"
0241                                << "1000 Nachrichten am 2005-05-07, ratio: 0.6. Bemessungen : 4.8"
0242                                << QStringLiteral(
0243                                       "1000 messages au 2005-05-07, la fraction du total: "
0244                                       "0.6. Note: 4.8")
0245                                << QString() << QString() << QVariantList{1000, QDate(2005, 5, 7), 0.6, 4.8};
0246 
0247 #ifndef Q_CC_MSVC
0248     QTest::newRow("string-16") << "Snowman: ☃"
0249                                << "Snowman: ☃"
0250                                << "Schneemann: ☃" << QStringLiteral("bonhomme de neige: ☃") << QString() << QString() << QVariantList();
0251 #endif
0252 }
0253 
0254 using Dict = QHash<QString, QVariant>;
0255 
0256 void TestInternationalization::testLocalizedTemplate()
0257 {
0258     QFETCH(QString, input);
0259     QFETCH(QString, cFragment);
0260     QFETCH(QString, en_USFragment);
0261     QFETCH(QString, en_GBFragment);
0262     QFETCH(QString, deFragment);
0263     QFETCH(QString, frFragment);
0264     QFETCH(Dict, dict);
0265 
0266     auto t = m_engine->newTemplate(input, QString());
0267     Context c(dict);
0268     c.setLocalizer(cLocalizer);
0269     QCOMPARE(t->render(&c), cFragment);
0270     c.setLocalizer(en_USLocalizer);
0271     QCOMPARE(t->render(&c).replace(QStringLiteral("\u202FAM"), QLatin1String(" AM")), en_USFragment);
0272     c.setLocalizer(en_GBLocalizer);
0273     QCOMPARE(t->render(&c), en_GBFragment);
0274     c.setLocalizer(deLocalizer);
0275     QCOMPARE(t->render(&c), deFragment);
0276     c.setLocalizer(frLocalizer);
0277     QCOMPARE(t->render(&c), frFragment);
0278 }
0279 
0280 void TestInternationalization::testLocalizedTemplate_data()
0281 {
0282     QTest::addColumn<QString>("input");
0283     QTest::addColumn<QString>("cFragment");
0284     QTest::addColumn<QString>("en_USFragment");
0285     QTest::addColumn<QString>("en_GBFragment");
0286     QTest::addColumn<QString>("deFragment");
0287     QTest::addColumn<QString>("frFragment");
0288     QTest::addColumn<Dict>("dict");
0289 
0290     Dict dict;
0291     dict.insert(QStringLiteral("date"), QDate(2005, 5, 7));
0292     QTest::newRow("fragment-01") << QStringLiteral(
0293         "{% i18n '%1 messages at %2, fraction of total: %3. "
0294         "Rating : %4' _(1000) _(date) _(0.6) _(4.8) %}")
0295                                  << QStringLiteral(
0296                                         "1000 messages at 7 May 2005, fraction of total: 0.60. "
0297                                         "Rating : 4.80")
0298                                  << QStringLiteral("1,000 messages at 5/7/05, fraction of total: 0.60. Rating : 4.80")
0299                                  << QStringLiteral(
0300                                         "1,000 messages at 07/05/2005, fraction of total: "
0301                                         "0.60. Rating : 4.80")
0302                                  << QStringLiteral("1.000 Nachrichten am 07.05.05, ratio: 0,60. Bemessungen : 4,80")
0303                                  << QString::fromUtf8("1" FR_THOUSAND_SEPARATOR
0304                                                       "000 messages au 07/05/2005, la fraction du "
0305                                                       "total: 0,60. Note: 4,80")
0306                                  << dict;
0307 
0308     dict.insert(QStringLiteral("integer"), 1000);
0309     dict.insert(QStringLiteral("smallFloat"), 0.6);
0310     dict.insert(QStringLiteral("largeFloat"), 4.8);
0311 
0312     QTest::newRow("fragment-02") << QStringLiteral(
0313         "{% i18n '%1 messages at %2, fraction of total: %3. Rating : %4' "
0314         "_(integer) _(date) _(smallFloat) _(largeFloat) %}")
0315                                  << QStringLiteral(
0316                                         "1000 messages at 7 May 2005, fraction of total: 0.60. "
0317                                         "Rating : 4.80")
0318                                  << QStringLiteral("1,000 messages at 5/7/05, fraction of total: 0.60. Rating : 4.80")
0319                                  << QStringLiteral(
0320                                         "1,000 messages at 07/05/2005, fraction of total: "
0321                                         "0.60. Rating : 4.80")
0322                                  << QStringLiteral("1.000 Nachrichten am 07.05.05, ratio: 0,60. Bemessungen : 4,80")
0323                                  << QString::fromUtf8("1" FR_THOUSAND_SEPARATOR
0324                                                       "000 messages au 07/05/2005, la fraction du "
0325                                                       "total: 0,60. Note: 4,80")
0326                                  << dict;
0327 
0328     dict.insert(QStringLiteral("time"), QTime(4, 5, 6));
0329     dict.insert(QStringLiteral("dateTime"), QDateTime(QDate(2005, 5, 7), QTime(4, 5, 6)));
0330 
0331     QTest::newRow("fragment-03") << QStringLiteral(
0332         "{{ _(integer) }} -- {{ _(date) }} -- {{ _(smallFloat) }} -- {{ "
0333         "_(largeFloat) }} -- {{ _(time) }} -- {{ _(dateTime) }}")
0334                                  << QStringLiteral(
0335                                         "1000 -- 7 May 2005 -- 0.60 -- 4.80 -- 04:05:06 -- 7 "
0336                                         "May 2005 04:05:06")
0337                                  << QStringLiteral("1,000 -- 5/7/05 -- 0.60 -- 4.80 -- 4:05 AM -- 5/7/05 4:05 AM")
0338                                  << QStringLiteral("1,000 -- 07/05/2005 -- 0.60 -- 4.80 -- 04:05 -- 07/05/2005 04:05")
0339                                  << QStringLiteral("1.000 -- 07.05.05 -- 0,60 -- 4,80 -- 04:05 -- 07.05.05 04:05")
0340                                  << QString::fromUtf8("1" FR_THOUSAND_SEPARATOR
0341                                                       "000 -- 07/05/2005 -- 0,60 -- 4,80 -- 04:05 -- "
0342                                                       "07/05/2005 04:05")
0343                                  << dict;
0344 
0345     QTest::newRow("fragment-04") << QString::fromLatin1(
0346         "{{ _('Today') }} -- {{ _(integer) }} -- {{ _(date) }} -- {{ "
0347         "_(smallFloat) }} -- {{ _(largeFloat) }} -- {{ _(time) }} -- {{ "
0348         "_(dateTime) }}"
0349         "{% with_locale 'de_DE' %}"
0350         "{{ _('Today') }} -- {{ _(integer) }} -- {{ _(date) }} -- {{ "
0351         "_(smallFloat) }} -- {{ _(largeFloat) }} -- {{ _(time) }} -- {{ "
0352         "_(dateTime) }}"
0353         "{% endwith_locale %}"
0354         "{% with_locale 'fr_FR' %}"
0355         "{{ _('Today') }} -- {{ _(integer) }} -- {{ _(date) }} -- {{ "
0356         "_(smallFloat) }} -- {{ _(largeFloat) }} -- {{ _(time) }} -- {{ "
0357         "_(dateTime) }}"
0358         "{% endwith_locale %}")
0359                                  << QString::fromUtf8(
0360                                         "Today"
0361                                         " -- 1000 -- 7 May 2005 -- 0.60 -- 4.80 -- 04:05:06 -- 7 May "
0362                                         "2005 "
0363                                         "04:05:06"
0364                                         "Heute"
0365                                         " -- 1.000 -- 07.05.05 -- 0,60 -- 4,80 -- 04:05 -- 07.05.05 "
0366                                         "04:05"
0367                                         "Aujourd&#39;hui"
0368                                         " -- 1" FR_THOUSAND_SEPARATOR
0369                                         "000 -- 07/05/2005 -- 0,60 -- 4,80 -- 04:05 -- "
0370                                         "07/05/2005 "
0371                                         "04:05")
0372                                  << QString::fromUtf8(
0373                                         "Today"
0374                                         " -- 1,000 -- 5/7/05 -- 0.60 -- 4.80 -- 4:05 AM -- 5/7/05 4:05 "
0375                                         "AM"
0376                                         "Heute"
0377                                         " -- 1.000 -- 07.05.05 -- 0,60 -- 4,80 -- 04:05 -- 07.05.05 "
0378                                         "04:05"
0379                                         "Aujourd&#39;hui"
0380                                         " -- 1" FR_THOUSAND_SEPARATOR
0381                                         "000 -- 07/05/2005 -- 0,60 -- 4,80 -- 04:05 -- "
0382                                         "07/05/2005 "
0383                                         "04:05")
0384                                  << QString::fromUtf8(
0385                                         "Today"
0386                                         " -- 1,000 -- 07/05/2005 -- 0.60 -- 4.80 -- 04:05 -- 07/05/2005 "
0387                                         "04:05"
0388                                         "Heute"
0389                                         " -- 1.000 -- 07.05.05 -- 0,60 -- 4,80 -- 04:05 -- 07.05.05 "
0390                                         "04:05"
0391                                         "Aujourd&#39;hui"
0392                                         " -- 1" FR_THOUSAND_SEPARATOR
0393                                         "000 -- 07/05/2005 -- 0,60 -- 4,80 -- 04:05 -- "
0394                                         "07/05/2005 "
0395                                         "04:05")
0396                                  << QString::fromUtf8(
0397                                         "Heute"
0398                                         " -- 1.000 -- 07.05.05 -- 0,60 -- 4,80 -- 04:05 -- 07.05.05 "
0399                                         "04:05"
0400                                         "Heute"
0401                                         " -- 1.000 -- 07.05.05 -- 0,60 -- 4,80 -- 04:05 -- 07.05.05 "
0402                                         "04:05"
0403                                         "Aujourd&#39;hui"
0404                                         " -- 1" FR_THOUSAND_SEPARATOR
0405                                         "000 -- 07/05/2005 -- 0,60 -- 4,80 -- 04:05 -- "
0406                                         "07/05/2005 "
0407                                         "04:05")
0408                                  << QString::fromUtf8(
0409                                         "Aujourd&#39;hui"
0410                                         " -- 1" FR_THOUSAND_SEPARATOR
0411                                         "000 -- 07/05/2005 -- 0,60 -- 4,80 -- 04:05 -- "
0412                                         "07/05/2005 "
0413                                         "04:05"
0414                                         "Heute"
0415                                         " -- 1.000 -- 07.05.05 -- 0,60 -- 4,80 -- 04:05 -- 07.05.05 "
0416                                         "04:05"
0417                                         "Aujourd&#39;hui"
0418                                         " -- 1" FR_THOUSAND_SEPARATOR
0419                                         "000 -- 07/05/2005 -- 0,60 -- 4,80 -- 04:05 -- "
0420                                         "07/05/2005 "
0421                                         "04:05")
0422                                  << dict;
0423 
0424     QTest::newRow("fragment-05") << QString::fromLatin1(
0425         "{{ _('Today') }} -- {{ _(integer) }} -- {{ _(date) }} -- {{ "
0426         "_(smallFloat) }} -- {{ _(largeFloat) }} -- {{ _(time) }} -- {{ "
0427         "_(dateTime) }}"
0428         "{% with_locale 'de_DE' %}"
0429         "{{ _('Today') }} -- {{ _(integer) }} -- {{ _(date) }} -- {{ "
0430         "_(smallFloat) }} -- {{ _(largeFloat) }} -- {{ _(time) }} -- {{ "
0431         "_(dateTime) }}"
0432         "{% with_locale 'fr_FR' %}"
0433         "{{ _('Today') }} -- {{ _(integer) }} -- {{ _(date) }} -- {{ "
0434         "_(smallFloat) }} -- {{ _(largeFloat) }} -- {{ _(time) }} -- {{ "
0435         "_(dateTime) }}"
0436         "{% endwith_locale %}"
0437         "{{ _('Today') }} -- {{ _(integer) }} -- {{ _(date) }} -- {{ "
0438         "_(smallFloat) }} -- {{ _(largeFloat) }} -- {{ _(time) }} -- {{ "
0439         "_(dateTime) }}"
0440         "{% endwith_locale %}")
0441                                  << QString::fromUtf8(
0442                                         "Today"
0443                                         " -- 1000 -- 7 May 2005 -- 0.60 -- 4.80 -- 04:05:06 -- 7 May "
0444                                         "2005 "
0445                                         "04:05:06"
0446                                         "Heute"
0447                                         " -- 1.000 -- 07.05.05 -- 0,60 -- 4,80 -- 04:05 -- 07.05.05 "
0448                                         "04:05"
0449                                         "Aujourd&#39;hui"
0450                                         " -- 1" FR_THOUSAND_SEPARATOR
0451                                         "000 -- 07/05/2005 -- 0,60 -- 4,80 -- 04:05 -- "
0452                                         "07/05/2005 "
0453                                         "04:05"
0454                                         "Heute"
0455                                         " -- 1.000 -- 07.05.05 -- 0,60 -- 4,80 -- 04:05 -- 07.05.05 "
0456                                         "04:05")
0457                                  << QString::fromUtf8(
0458                                         "Today"
0459                                         " -- 1,000 -- 5/7/05 -- 0.60 -- 4.80 -- 4:05 AM -- 5/7/05 4:05 "
0460                                         "AM"
0461                                         "Heute"
0462                                         " -- 1.000 -- 07.05.05 -- 0,60 -- 4,80 -- 04:05 -- 07.05.05 "
0463                                         "04:05"
0464                                         "Aujourd&#39;hui"
0465                                         " -- 1" FR_THOUSAND_SEPARATOR
0466                                         "000 -- 07/05/2005 -- 0,60 -- 4,80 -- 04:05 -- "
0467                                         "07/05/2005 "
0468                                         "04:05"
0469                                         "Heute"
0470                                         " -- 1.000 -- 07.05.05 -- 0,60 -- 4,80 -- 04:05 -- 07.05.05 "
0471                                         "04:05")
0472                                  << QString::fromUtf8(
0473                                         "Today"
0474                                         " -- 1,000 -- 07/05/2005 -- 0.60 -- 4.80 -- 04:05 -- 07/05/2005 "
0475                                         "04:05"
0476                                         "Heute"
0477                                         " -- 1.000 -- 07.05.05 -- 0,60 -- 4,80 -- 04:05 -- 07.05.05 "
0478                                         "04:05"
0479                                         "Aujourd&#39;hui"
0480                                         " -- 1" FR_THOUSAND_SEPARATOR
0481                                         "000 -- 07/05/2005 -- 0,60 -- 4,80 -- 04:05 -- "
0482                                         "07/05/2005 "
0483                                         "04:05"
0484                                         "Heute"
0485                                         " -- 1.000 -- 07.05.05 -- 0,60 -- 4,80 -- 04:05 -- 07.05.05 "
0486                                         "04:05")
0487                                  << QString::fromUtf8(
0488                                         "Heute"
0489                                         " -- 1.000 -- 07.05.05 -- 0,60 -- 4,80 -- 04:05 -- 07.05.05 "
0490                                         "04:05"
0491                                         "Heute"
0492                                         " -- 1.000 -- 07.05.05 -- 0,60 -- 4,80 -- 04:05 -- 07.05.05 "
0493                                         "04:05"
0494                                         "Aujourd&#39;hui"
0495                                         " -- 1" FR_THOUSAND_SEPARATOR
0496                                         "000 -- 07/05/2005 -- 0,60 -- 4,80 -- 04:05 -- "
0497                                         "07/05/2005 "
0498                                         "04:05"
0499                                         "Heute"
0500                                         " -- 1.000 -- 07.05.05 -- 0,60 -- 4,80 -- 04:05 -- 07.05.05 "
0501                                         "04:05")
0502                                  << QString::fromUtf8(
0503                                         "Aujourd&#39;hui"
0504                                         " -- 1" FR_THOUSAND_SEPARATOR
0505                                         "000 -- 07/05/2005 -- 0,60 -- 4,80 -- 04:05 -- "
0506                                         "07/05/2005 "
0507                                         "04:05"
0508                                         "Heute"
0509                                         " -- 1.000 -- 07.05.05 -- 0,60 -- 4,80 -- 04:05 -- 07.05.05 "
0510                                         "04:05"
0511                                         "Aujourd&#39;hui"
0512                                         " -- 1" FR_THOUSAND_SEPARATOR
0513                                         "000 -- 07/05/2005 -- 0,60 -- 4,80 -- 04:05 -- "
0514                                         "07/05/2005 "
0515                                         "04:05"
0516                                         "Heute"
0517                                         " -- 1.000 -- 07.05.05 -- 0,60 -- 4,80 -- 04:05 -- 07.05.05 "
0518                                         "04:05")
0519                                  << dict;
0520 
0521     dict.insert(QStringLiteral("list"), QVariantList{1000});
0522     QTest::newRow("fragment-06") << QStringLiteral("{{ _(list.0) }}") << QStringLiteral("1000") << QStringLiteral("1,000") << QStringLiteral("1,000")
0523                                  << QStringLiteral("1.000") << QString::fromUtf8("1" FR_THOUSAND_SEPARATOR "000") << dict;
0524 
0525     dict.clear();
0526     dict.insert(QStringLiteral("longlong"), (qlonglong)1000);
0527     dict.insert(QStringLiteral("float"), (float)0.6);
0528     dict.insert(QStringLiteral("double"), (float)4.8);
0529     dict.insert(QStringLiteral("hash"), QVariantHash());
0530 
0531     QTest::newRow("fragment-07") << QStringLiteral("{{ _(longlong) }} {{ _(float) }} {{ _(double) }}{{ _(hash) }}") << QStringLiteral("1000 0.60 4.80")
0532                                  << QStringLiteral("1,000 0.60 4.80") << QStringLiteral("1,000 0.60 4.80") << QStringLiteral("1.000 0,60 4,80")
0533                                  << QString::fromUtf8("1" FR_THOUSAND_SEPARATOR "000 0,60 4,80") << dict;
0534 
0535     QTest::newRow("fragment-08") << QStringLiteral("{{ 'this'|cut:_(\"i\") }}") << QStringLiteral("ths") << QStringLiteral("ths") << QStringLiteral("ths")
0536                                  << QStringLiteral("ths") << QStringLiteral("ths") << dict;
0537 
0538     // Start testing l10n_filesizeformat
0539     // If build against Qt 5.10 or newer, internally QLocale::formattedDataSize()
0540     // will be used for values that fit into a qint64. QLocale also supports
0541     // translating the unit name, that is the reason why test results differ for
0542     // Qt version before and after 5.10
0543 
0544     dict.clear();
0545     dict.insert(QStringLiteral("fs_int_mib"), 1048576);
0546 
0547     QTest::newRow("fragment-09") << QStringLiteral("{% l10n_filesize fs_int_mib %}") << QStringLiteral("1.05 MB") << QStringLiteral("1.05 MB")
0548                                  << QStringLiteral("1.05 MB") << QStringLiteral("1,05 MB") << QStringLiteral("1,05 Mo") << dict;
0549 
0550     QTest::newRow("fragment-10") << QStringLiteral("{% l10n_filesize_var fs_int_mib size_var %}{{ size_var }}") << QStringLiteral("1.05 MB")
0551                                  << QStringLiteral("1.05 MB") << QStringLiteral("1.05 MB") << QStringLiteral("1,05 MB") << QStringLiteral("1,05 Mo") << dict;
0552 
0553     QTest::newRow("fragment-11") << QStringLiteral("{% l10n_filesize fs_int_mib 2 %}") << QStringLiteral("1.00 MiB") << QStringLiteral("1.00 MiB")
0554                                  << QStringLiteral("1.00 MiB") << QStringLiteral("1,00 MiB") << QStringLiteral("1,00 Mio") << dict;
0555 
0556     QTest::newRow("fragment-12") << QStringLiteral("{% l10n_filesize_var fs_int_mib 2 size_var %}{{ size_var }}") << QStringLiteral("1.00 MiB")
0557                                  << QStringLiteral("1.00 MiB") << QStringLiteral("1.00 MiB") << QStringLiteral("1,00 MiB") << QStringLiteral("1,00 Mio")
0558                                  << dict;
0559 
0560     QTest::newRow("fragment-13") << QStringLiteral("{% l10n_filesize fs_int_mib 10 3 %}") << QStringLiteral("1.049 MB") << QStringLiteral("1.049 MB")
0561                                  << QStringLiteral("1.049 MB") << QStringLiteral("1,049 MB") << QStringLiteral("1,049 Mo") << dict;
0562 
0563     QTest::newRow("fragment-14") << QStringLiteral("{% l10n_filesize_var fs_int_mib 10 3 size_var %}{{ size_var }}") << QStringLiteral("1.049 MB")
0564                                  << QStringLiteral("1.049 MB") << QStringLiteral("1.049 MB") << QStringLiteral("1,049 MB") << QStringLiteral("1,049 Mo")
0565                                  << dict;
0566 
0567     QTest::newRow("fragment-15") << QStringLiteral("{% l10n_filesize fs_int_mib 10 2 1024 %}") << QStringLiteral("1.07 GB") << QStringLiteral("1.07 GB")
0568                                  << QStringLiteral("1.07 GB") << QStringLiteral("1,07 GB") << QStringLiteral("1,07 Go") << dict;
0569 
0570     QTest::newRow("fragment-16") << QStringLiteral("{% l10n_filesize_var fs_int_mib 10 2 1024 size_var %}{{ size_var }}") << QStringLiteral("1.07 GB")
0571                                  << QStringLiteral("1.07 GB") << QStringLiteral("1.07 GB") << QStringLiteral("1,07 GB") << QStringLiteral("1,07 Go") << dict;
0572 
0573     dict.clear();
0574     dict.insert(QStringLiteral("fs_float_mib"), 1024.5);
0575 
0576     QTest::newRow("fragment-17") << QStringLiteral("{% l10n_filesize fs_float_mib 10 2 1024 %}") << QStringLiteral("1.05 MB") << QStringLiteral("1.05 MB")
0577                                  << QStringLiteral("1.05 MB") << QStringLiteral("1,05 MB") << QStringLiteral("1,05 Mo") << dict;
0578 
0579     QTest::newRow("fragment-18") << QStringLiteral("{% l10n_filesize_var fs_float_mib 10 2 1024 size_var %}{{ size_var }}") << QStringLiteral("1.05 MB")
0580                                  << QStringLiteral("1.05 MB") << QStringLiteral("1.05 MB") << QStringLiteral("1,05 MB") << QStringLiteral("1,05 Mo") << dict;
0581 
0582     dict.clear();
0583     dict.insert(QStringLiteral("fs_string_mib"), QStringLiteral("1024.5"));
0584 
0585     QTest::newRow("fragment-19") << QStringLiteral("{% l10n_filesize fs_string_mib 10 2 1024 %}") << QStringLiteral("1.05 MB") << QStringLiteral("1.05 MB")
0586                                  << QStringLiteral("1.05 MB") << QStringLiteral("1,05 MB") << QStringLiteral("1,05 Mo") << dict;
0587 
0588     QTest::newRow("fragment-20") << QStringLiteral("{% l10n_filesize_var fs_string_mib 10 2 1024 size_var %}{{ size_var }}") << QStringLiteral("1.05 MB")
0589                                  << QStringLiteral("1.05 MB") << QStringLiteral("1.05 MB") << QStringLiteral("1,05 MB") << QStringLiteral("1,05 Mo") << dict;
0590 }
0591 
0592 void TestInternationalization::testSafeContent()
0593 {
0594     QFETCH(QString, input);
0595     QFETCH(QString, cFragment);
0596     QFETCH(QString, frFragment);
0597     QFETCH(Dict, dict);
0598 
0599     auto t = m_engine->newTemplate(input, QString());
0600     Context c(dict);
0601     c.setLocalizer(cLocalizer);
0602     QCOMPARE(t->render(&c), cFragment);
0603     c.setLocalizer(frLocalizer);
0604     QCOMPARE(t->render(&c), frFragment);
0605 }
0606 
0607 void TestInternationalization::testSafeContent_data()
0608 {
0609     QTest::addColumn<QString>("input");
0610     QTest::addColumn<QString>("cFragment");
0611     QTest::addColumn<QString>("frFragment");
0612     QTest::addColumn<Dict>("dict");
0613 
0614     Dict dict;
0615     dict.insert(QStringLiteral("date"), QDate(2005, 5, 7));
0616 
0617     QTest::newRow("safe-01") << QStringLiteral("{% i18n 'Today is %1' _(date) %}") << QStringLiteral("Today is 7 May 2005")
0618                              << QStringLiteral("Aujourd&#39;hui est 07/05/2005") << dict;
0619 
0620     QTest::newRow("safe-02") << QStringLiteral("{% autoescape off %}{% i18n 'Today is %1' _(date) %}{% endautoescape %}")
0621                              << QStringLiteral("Today is 7 May 2005") << QStringLiteral("Aujourd'hui est 07/05/2005") << dict;
0622 
0623     QTest::newRow("safe-03") << QStringLiteral(
0624         "{% i18n_var 'Today is %1' _(date) as today_greeting %}-{{ "
0625         "today_greeting }}-") << QStringLiteral("-Today is 7 May 2005-")
0626                              << QStringLiteral("-Aujourd&#39;hui est 07/05/2005-") << dict;
0627 
0628     QTest::newRow("safe-04") << QStringLiteral(
0629         "{% autoescape off %}{% i18n_var 'Today is %1' _(date) as today_greeting "
0630         "%}-{{ today_greeting }}-{% endautoescape %}")
0631                              << QStringLiteral("-Today is 7 May 2005-") << QStringLiteral("-Aujourd'hui est 07/05/2005-") << dict;
0632 
0633     QTest::newRow("safe-05") << QStringLiteral("{% with 'Today' as rawText %}-{{ _(rawText) }}-{% endwith %}") << QStringLiteral("-Today-")
0634                              << QStringLiteral("-Aujourd&#39;hui-") << dict;
0635 
0636     QTest::newRow("safe-06") << QStringLiteral(
0637         "{% autoescape off %}{% with 'Today' as rawText %}-{{ _(rawText) }}-{% "
0638         "endwith %}{% endautoescape %}")
0639                              << QStringLiteral("-Today-") << QStringLiteral("-Aujourd'hui-") << dict;
0640 
0641     dict.insert(QStringLiteral("today_text"), QStringLiteral("Today"));
0642 
0643     QTest::newRow("safe-07") << QStringLiteral("-{{ _(today_text) }}-") << QStringLiteral("-Today-") << QStringLiteral("-Aujourd&#39;hui-") << dict;
0644 
0645     QTest::newRow("safe-08") << QStringLiteral("{% autoescape off %}-{{ _(today_text) }}-{% endautoescape %}") << QStringLiteral("-Today-")
0646                              << QStringLiteral("-Aujourd'hui-") << dict;
0647 
0648     dict.insert(QStringLiteral("today_and_tomorrow_text"), markSafe(QStringLiteral("Today &amp; tomorrow")));
0649 
0650     QTest::newRow("safe-09") << QStringLiteral("-{{ _(today_and_tomorrow_text) }}-") << QStringLiteral("-Today &amp;amp; tomorrow-")
0651                              << QStringLiteral("-Aujourd&#39;hui &amp;amp; demain-") << dict;
0652 
0653     QTest::newRow("safe-10") << QStringLiteral(
0654         "{% autoescape off %}-{{ _(today_and_tomorrow_text) }}-{% endautoescape "
0655         "%}") << QStringLiteral("-Today &amp; tomorrow-")
0656                              << QStringLiteral("-Aujourd'hui &amp; demain-") << dict;
0657 
0658     QTest::newRow("safe-11") << QStringLiteral("{% i18nc 'The current day is' 'Today is' %}") << QStringLiteral("Today is")
0659                              << QStringLiteral("Aujourd&#39;hui est") << dict;
0660 
0661     QTest::newRow("safe-12") << QStringLiteral(
0662         "{% autoescape off %}{% i18nc 'The current day is' 'Today is' %}{% "
0663         "endautoescape %}") << QStringLiteral("Today is")
0664                              << QStringLiteral("Aujourd'hui est") << dict;
0665 
0666     QTest::newRow("safe-13") << QStringLiteral(
0667         "{% i18nc_var 'The current day is' 'Today is' as today_greeting %}-{{ "
0668         "today_greeting }}-") << QStringLiteral("-Today is-")
0669                              << QStringLiteral("-Aujourd&#39;hui est-") << dict;
0670 
0671     QTest::newRow("safe-14") << QStringLiteral(
0672         "{% autoescape off %}{% i18nc_var 'The current day is' 'Today is' as "
0673         "today_greeting %}-{{ today_greeting }}-{% endautoescape %}")
0674                              << QStringLiteral("-Today is-") << QStringLiteral("-Aujourd'hui est-") << dict;
0675 
0676     QTest::newRow("safe-15") << QStringLiteral("{% i18np '%n people today' 1 %}") << QStringLiteral("1 people today") // Not really testing English here.
0677                              << QStringLiteral("1 personne aujourd&#39;hui") << dict;
0678 
0679     QTest::newRow("safe-16") << QStringLiteral("{% i18np '%n people today' 2 %}") << QStringLiteral("2 people today")
0680                              << QStringLiteral("2 personnes aujourd&#39;hui") << dict;
0681 
0682     QTest::newRow("safe-17") << QStringLiteral("{% autoescape off %}{% i18np '%n people today' 1 %}{% endautoescape %}")
0683                              << QStringLiteral("1 people today") // Not really testing
0684                                                                  // English here.
0685                              << QStringLiteral("1 personne aujourd'hui") << dict;
0686 
0687     QTest::newRow("safe-18") << QStringLiteral("{% autoescape off %}{% i18np '%n people today' 2 %}{% endautoescape %}") << QStringLiteral("2 people today")
0688                              << QStringLiteral("2 personnes aujourd'hui") << dict;
0689 
0690     QTest::newRow("safe-19") << QStringLiteral("{% i18np_var '%n people today' 1 as num_people %}-{{ num_people }}-")
0691                              << QStringLiteral("-1 people today-") // Not really testing
0692                                                                    // English here.
0693                              << QStringLiteral("-1 personne aujourd&#39;hui-") << dict;
0694 
0695     QTest::newRow("safe-20") << QStringLiteral("{% i18np_var '%n people today' 2 as num_people %}-{{ num_people }}-") << QStringLiteral("-2 people today-")
0696                              << QStringLiteral("-2 personnes aujourd&#39;hui-") << dict;
0697 
0698     QTest::newRow("safe-21") << QStringLiteral(
0699         "{% autoescape off %}{% i18np_var '%n people today' 1 "
0700         "as num_people %}-{{ num_people }}-{% endautoescape %}")
0701                              << QStringLiteral("-1 people today-") // Not really testing English here.
0702                              << QStringLiteral("-1 personne aujourd'hui-") << dict;
0703 
0704     QTest::newRow("safe-22") << QStringLiteral(
0705         "{% autoescape off %}{% i18np_var '%n people today' 2 as num_people "
0706         "%}-{{ num_people }}-{% endautoescape %}")
0707                              << QStringLiteral("-2 people today-") << QStringLiteral("-2 personnes aujourd'hui-") << dict;
0708 
0709     QTest::newRow("safe-23") << QStringLiteral(
0710         "{% i18ncp 'The number of people who have visited "
0711         "today' '%n people visited today' 1 %}")
0712                              << QStringLiteral("1 people visited today") // Not really testing English here.
0713                              << QStringLiteral("1 personne a visité aujourd&#39;hui") << dict;
0714 
0715     QTest::newRow("safe-24") << QStringLiteral(
0716         "{% i18ncp 'The number of people who have visited "
0717         "today' '%n people visited today' 2 %}")
0718                              << QStringLiteral("2 people visited today") << QStringLiteral("2 personnes a visité aujourd&#39;hui") << dict;
0719 
0720     QTest::newRow("safe-25") << QStringLiteral(
0721         "{% autoescape off %}{% i18ncp 'The number of people who have "
0722         "visited today' '%n people visited today' 1 %}{% endautoescape %}")
0723                              << QStringLiteral("1 people visited today") // Not really testing English here.
0724                              << QStringLiteral("1 personne a visité aujourd'hui") << dict;
0725 
0726     QTest::newRow("safe-26") << QStringLiteral(
0727         "{% autoescape off %}{% i18ncp 'The number of people who have visited "
0728         "today' '%n people visited today' 2 %}{% endautoescape %}")
0729                              << QStringLiteral("2 people visited today") << QStringLiteral("2 personnes a visité aujourd'hui") << dict;
0730 
0731     QTest::newRow("safe-27") << QStringLiteral(
0732         "{% i18ncp_var 'The number of people who have visited today' '%n "
0733         "people visited today' 1 as num_people %}-{{ num_people }}-")
0734                              << QStringLiteral("-1 people visited today-") // Not really testing English here.
0735                              << QStringLiteral("-1 personne a visité aujourd&#39;hui-") << dict;
0736 
0737     QTest::newRow("safe-28") << QStringLiteral(
0738         "{% i18ncp_var 'The number of people who have visited today' '%n people "
0739         "visited today' 2 as num_people %}-{{ num_people }}-")
0740                              << QStringLiteral("-2 people visited today-") << QStringLiteral("-2 personnes a visité aujourd&#39;hui-") << dict;
0741 
0742     QTest::newRow("safe-29") << QStringLiteral(
0743         "{% autoescape off %}{% i18ncp_var 'The number of people who have "
0744         "visited today' '%n people visited today' 1 as num_people %}-{{ "
0745         "num_people }}-{% endautoescape %}")
0746                              << QStringLiteral("-1 people visited today-") // Not really testing English here.
0747                              << QStringLiteral("-1 personne a visité aujourd'hui-") << dict;
0748 
0749     QTest::newRow("safe-30") << QStringLiteral(
0750         "{% autoescape off %}{% i18ncp_var 'The number of people who have "
0751         "visited today' '%n people visited today' 2 as num_people %}-{{ "
0752         "num_people }}-{% endautoescape %}")
0753                              << QStringLiteral("-2 people visited today-") << QStringLiteral("-2 personnes a visité aujourd'hui-") << dict;
0754 }
0755 
0756 void TestInternationalization::testFailure()
0757 {
0758     QFETCH(QString, input);
0759 
0760     auto t = m_engine->newTemplate(input, QString());
0761     QVERIFY(t->error() != NoError);
0762 }
0763 
0764 void TestInternationalization::testFailure_data()
0765 {
0766     QTest::addColumn<QString>("input");
0767 
0768     QTest::newRow("fail-01") << QStringLiteral("{% i18np_var '%n people visited today' as num_people %}");
0769     QTest::newRow("fail-02") << QStringLiteral(
0770         "{% i18ncp_var 'The number of people who have visited today' '%n people "
0771         "visited today' as num_people %}");
0772     QTest::newRow("fail-03") << QStringLiteral("{% i18np '%n people visited today' %}");
0773     QTest::newRow("fail-04") << QStringLiteral(
0774         "{% i18ncp 'The number of people who have visited today' '%n people "
0775         "visited today' %}");
0776 }
0777 
0778 void TestInternationalization::testDates()
0779 {
0780     QFETCH(QDate, date);
0781     QFETCH(QString, cDate);
0782     QFETCH(QString, en_USDate);
0783     QFETCH(QString, en_GBDate);
0784     QFETCH(QString, deDate);
0785     QFETCH(QString, frDate);
0786 
0787     QCOMPARE(nullLocalizer->localizeDate(date), date.toString());
0788     QCOMPARE(cLocalizer->localizeDate(date), cDate);
0789     QCOMPARE(en_USLocalizer->localizeDate(date), en_USDate);
0790     QCOMPARE(en_GBLocalizer->localizeDate(date), en_GBDate);
0791     QCOMPARE(deLocalizer->localizeDate(date), deDate);
0792     QCOMPARE(frLocalizer->localizeDate(date), frDate);
0793 }
0794 
0795 void TestInternationalization::testDates_data()
0796 {
0797     QTest::addColumn<QDate>("date");
0798     QTest::addColumn<QString>("cDate");
0799     QTest::addColumn<QString>("en_USDate");
0800     QTest::addColumn<QString>("en_GBDate");
0801     QTest::addColumn<QString>("deDate");
0802     QTest::addColumn<QString>("frDate");
0803 
0804     QTest::newRow("date-01") << QDate(2010, 5, 9) << QStringLiteral("9 May 2010") << QStringLiteral("5/9/10") << QStringLiteral("09/05/2010")
0805                              << QStringLiteral("09.05.10") << QStringLiteral("09/05/2010");
0806 
0807     QTest::newRow("date-02") << QDate(2010, 10, 11) << QStringLiteral("11 Oct 2010") << QStringLiteral("10/11/10") << QStringLiteral("11/10/2010")
0808                              << QStringLiteral("11.10.10") << QStringLiteral("11/10/2010");
0809 }
0810 
0811 void TestInternationalization::testIntegers()
0812 {
0813     QFETCH(int, integer);
0814     QFETCH(QString, nullInteger);
0815     QFETCH(QString, cInteger);
0816     QFETCH(QString, en_USInteger);
0817     QFETCH(QString, en_GBInteger);
0818     QFETCH(QString, deInteger);
0819     QFETCH(QString, frInteger);
0820 
0821     QCOMPARE(nullLocalizer->localizeNumber(integer), nullInteger);
0822     QCOMPARE(cLocalizer->localizeNumber(integer), cInteger);
0823     QCOMPARE(en_USLocalizer->localizeNumber(integer), en_USInteger);
0824     QCOMPARE(en_GBLocalizer->localizeNumber(integer), en_GBInteger);
0825     QCOMPARE(deLocalizer->localizeNumber(integer), deInteger);
0826     QCOMPARE(frLocalizer->localizeNumber(integer), frInteger);
0827 }
0828 
0829 void TestInternationalization::testIntegers_data()
0830 {
0831     QTest::addColumn<int>("integer");
0832     QTest::addColumn<QString>("nullInteger");
0833     QTest::addColumn<QString>("cInteger");
0834     QTest::addColumn<QString>("en_USInteger");
0835     QTest::addColumn<QString>("en_GBInteger");
0836     QTest::addColumn<QString>("deInteger");
0837     QTest::addColumn<QString>("frInteger");
0838 
0839     QTest::newRow("integer-01") << 7 << QStringLiteral("7") << QStringLiteral("7") << QStringLiteral("7") << QStringLiteral("7") << QStringLiteral("7")
0840                                 << QStringLiteral("7");
0841 
0842     QTest::newRow("integer-02") << 7000 << QStringLiteral("7000") << QStringLiteral("7000") << QStringLiteral("7,000") << QStringLiteral("7,000")
0843                                 << QStringLiteral("7.000") << QString::fromUtf8("7" FR_THOUSAND_SEPARATOR "000");
0844 }
0845 
0846 void TestInternationalization::testFloats()
0847 {
0848     QFETCH(qreal, floatingPoint);
0849     QFETCH(QString, nullFloatingPoint);
0850     QFETCH(QString, cFloatingPoint);
0851     QFETCH(QString, en_USFloatingPoint);
0852     QFETCH(QString, en_GBFloatingPoint);
0853     QFETCH(QString, deFloatingPoint);
0854     QFETCH(QString, frFloatingPoint);
0855 
0856     QCOMPARE(nullLocalizer->localizeNumber(floatingPoint), nullFloatingPoint);
0857     QCOMPARE(cLocalizer->localizeNumber(floatingPoint), cFloatingPoint);
0858     QCOMPARE(en_USLocalizer->localizeNumber(floatingPoint), en_USFloatingPoint);
0859     QCOMPARE(en_GBLocalizer->localizeNumber(floatingPoint), en_GBFloatingPoint);
0860     QCOMPARE(deLocalizer->localizeNumber(floatingPoint), deFloatingPoint);
0861     QCOMPARE(frLocalizer->localizeNumber(floatingPoint), frFloatingPoint);
0862 }
0863 
0864 void TestInternationalization::testFloats_data()
0865 {
0866     QTest::addColumn<qreal>("floatingPoint");
0867     QTest::addColumn<QString>("nullFloatingPoint");
0868     QTest::addColumn<QString>("cFloatingPoint");
0869     QTest::addColumn<QString>("en_USFloatingPoint");
0870     QTest::addColumn<QString>("en_GBFloatingPoint");
0871     QTest::addColumn<QString>("deFloatingPoint");
0872     QTest::addColumn<QString>("frFloatingPoint");
0873 
0874     QTest::newRow("float-01") << qreal(7.4) << QStringLiteral("7.4") << QStringLiteral("7.40") << QStringLiteral("7.40") << QStringLiteral("7.40")
0875                               << QStringLiteral("7,40") << QStringLiteral("7,40");
0876 }
0877 
0878 void TestInternationalization::testTimes()
0879 {
0880     QFETCH(QTime, time);
0881     QFETCH(QString, nullTime);
0882     QFETCH(QString, cTime);
0883     QFETCH(QString, en_USTime);
0884     QFETCH(QString, en_GBTime);
0885     QFETCH(QString, deTime);
0886     QFETCH(QString, frTime);
0887 
0888     QCOMPARE(nullLocalizer->localizeTime(time), nullTime);
0889     QCOMPARE(cLocalizer->localizeTime(time), cTime);
0890     QCOMPARE(en_USLocalizer->localizeTime(time).simplified(), en_USTime);
0891     QCOMPARE(en_GBLocalizer->localizeTime(time), en_GBTime);
0892     QCOMPARE(deLocalizer->localizeTime(time), deTime);
0893     QCOMPARE(frLocalizer->localizeTime(time), frTime);
0894 }
0895 
0896 void TestInternationalization::testTimes_data()
0897 {
0898     QTest::addColumn<QTime>("time");
0899     QTest::addColumn<QString>("nullTime");
0900     QTest::addColumn<QString>("cTime");
0901     QTest::addColumn<QString>("en_USTime");
0902     QTest::addColumn<QString>("en_GBTime");
0903     QTest::addColumn<QString>("deTime");
0904     QTest::addColumn<QString>("frTime");
0905 
0906     QTest::newRow("time-01") << QTime(5, 6, 7) << QStringLiteral("05:06:07") << QStringLiteral("05:06:07") << QStringLiteral("5:06 AM")
0907                              << QStringLiteral("05:06") << QStringLiteral("05:06") << QStringLiteral("05:06");
0908 
0909     QTest::newRow("time-02") << QTime(11, 12, 13) << QStringLiteral("11:12:13") << QStringLiteral("11:12:13") << QStringLiteral("11:12 AM")
0910                              << QStringLiteral("11:12") << QStringLiteral("11:12") << QStringLiteral("11:12");
0911 
0912     QTest::newRow("time-03") << QTime(15, 12, 13) << QStringLiteral("15:12:13") << QStringLiteral("15:12:13") << QStringLiteral("3:12 PM")
0913                              << QStringLiteral("15:12") << QStringLiteral("15:12") << QStringLiteral("15:12");
0914 }
0915 
0916 void TestInternationalization::testDateTimes()
0917 {
0918     QFETCH(QDateTime, dateTime);
0919     QFETCH(QString, cDateTime);
0920     QFETCH(QString, en_USDateTime);
0921     QFETCH(QString, en_GBDateTime);
0922     QFETCH(QString, deDateTime);
0923     QFETCH(QString, frDateTime);
0924 
0925     QCOMPARE(nullLocalizer->localizeDateTime(dateTime), dateTime.toString());
0926     QCOMPARE(cLocalizer->localizeDateTime(dateTime), cDateTime);
0927     QCOMPARE(en_USLocalizer->localizeDateTime(dateTime).simplified(), en_USDateTime);
0928     QCOMPARE(en_GBLocalizer->localizeDateTime(dateTime), en_GBDateTime);
0929     QCOMPARE(deLocalizer->localizeDateTime(dateTime), deDateTime);
0930     QCOMPARE(frLocalizer->localizeDateTime(dateTime), frDateTime);
0931 }
0932 
0933 void TestInternationalization::testDateTimes_data()
0934 {
0935     QTest::addColumn<QDateTime>("dateTime");
0936     QTest::addColumn<QString>("cDateTime");
0937     QTest::addColumn<QString>("en_USDateTime");
0938     QTest::addColumn<QString>("en_GBDateTime");
0939     QTest::addColumn<QString>("deDateTime");
0940     QTest::addColumn<QString>("frDateTime");
0941 
0942     QTest::newRow("datetime-01") << QDateTime(QDate(2005, 6, 7), QTime(5, 6, 7)) << QStringLiteral("7 Jun 2005 05:06:07") << QStringLiteral("6/7/05 5:06 AM")
0943                                  << QStringLiteral("07/06/2005 05:06") << QStringLiteral("07.06.05 05:06") << QStringLiteral("07/06/2005 05:06");
0944 
0945     QTest::newRow("datetime-02") << QDateTime(QDate(2005, 6, 7), QTime(11, 12, 13)) << QStringLiteral("7 Jun 2005 11:12:13")
0946                                  << QStringLiteral("6/7/05 11:12 AM") << QStringLiteral("07/06/2005 11:12") << QStringLiteral("07.06.05 11:12")
0947                                  << QStringLiteral("07/06/2005 11:12");
0948 
0949     QTest::newRow("datetime-03") << QDateTime(QDate(2005, 6, 7), QTime(15, 12, 13)) << QStringLiteral("7 Jun 2005 15:12:13") << QStringLiteral("6/7/05 3:12 PM")
0950                                  << QStringLiteral("07/06/2005 15:12") << QStringLiteral("07.06.05 15:12") << QStringLiteral("07/06/2005 15:12");
0951 
0952     QTest::newRow("datetime-04") << QDateTime(QDate(2005, 10, 11), QTime(5, 6, 7)) << QStringLiteral("11 Oct 2005 05:06:07")
0953                                  << QStringLiteral("10/11/05 5:06 AM") << QStringLiteral("11/10/2005 05:06") << QStringLiteral("11.10.05 05:06")
0954                                  << QStringLiteral("11/10/2005 05:06");
0955 
0956     QTest::newRow("datetime-05") << QDateTime(QDate(2005, 10, 11), QTime(11, 12, 13)) << QStringLiteral("11 Oct 2005 11:12:13")
0957                                  << QStringLiteral("10/11/05 11:12 AM") << QStringLiteral("11/10/2005 11:12") << QStringLiteral("11.10.05 11:12")
0958                                  << QStringLiteral("11/10/2005 11:12");
0959 
0960     QTest::newRow("datetime-06") << QDateTime(QDate(2005, 10, 11), QTime(15, 12, 13)) << QStringLiteral("11 Oct 2005 15:12:13")
0961                                  << QStringLiteral("10/11/05 3:12 PM") << QStringLiteral("11/10/2005 15:12") << QStringLiteral("11.10.05 15:12")
0962                                  << QStringLiteral("11/10/2005 15:12");
0963 }
0964 
0965 QTEST_MAIN(TestInternationalization)
0966 #include "testinternationalization.moc"