From 0299123821c6c6367c23f59e135737f32b26c898 Mon Sep 17 00:00:00 2001 From: Tomas Junnonen Date: Mon, 15 Feb 2010 14:54:48 +0200 Subject: Changes: First public release RevBy: TrustMe --- tests/ut_translations/.gitignore | 1 + .../ut_translations/translations-qttrid/.gitignore | 1 + .../translations-qttrid/translations-qttrid.pro | 18 + .../ut_translations-qttrid_ar_EG.ts | 73 ++ .../ut_translations-qttrid_de_DE.ts | 60 ++ .../ut_translations-qttrid_en_GB.ts | 61 ++ .../translations-tr/translations-tr.pro | 21 + .../translations-tr/ut_translations-tr_en_GB.ts | 11 + .../translations-tr/ut_translations-tr_fi_FI.ts | 11 + tests/ut_translations/ut_translations.cpp | 878 +++++++++++++++++++++ tests/ut_translations/ut_translations.h | 78 ++ tests/ut_translations/ut_translations.pro | 10 + 12 files changed, 1223 insertions(+) create mode 100644 tests/ut_translations/.gitignore create mode 100644 tests/ut_translations/translations-qttrid/.gitignore create mode 100644 tests/ut_translations/translations-qttrid/translations-qttrid.pro create mode 100644 tests/ut_translations/translations-qttrid/ut_translations-qttrid_ar_EG.ts create mode 100644 tests/ut_translations/translations-qttrid/ut_translations-qttrid_de_DE.ts create mode 100644 tests/ut_translations/translations-qttrid/ut_translations-qttrid_en_GB.ts create mode 100644 tests/ut_translations/translations-tr/translations-tr.pro create mode 100644 tests/ut_translations/translations-tr/ut_translations-tr_en_GB.ts create mode 100644 tests/ut_translations/translations-tr/ut_translations-tr_fi_FI.ts create mode 100644 tests/ut_translations/ut_translations.cpp create mode 100644 tests/ut_translations/ut_translations.h create mode 100644 tests/ut_translations/ut_translations.pro (limited to 'tests/ut_translations') diff --git a/tests/ut_translations/.gitignore b/tests/ut_translations/.gitignore new file mode 100644 index 00000000..5ffec3f0 --- /dev/null +++ b/tests/ut_translations/.gitignore @@ -0,0 +1 @@ +ut_translations diff --git a/tests/ut_translations/translations-qttrid/.gitignore b/tests/ut_translations/translations-qttrid/.gitignore new file mode 100644 index 00000000..6e922cde --- /dev/null +++ b/tests/ut_translations/translations-qttrid/.gitignore @@ -0,0 +1 @@ +ut_translations-qttrid.ts diff --git a/tests/ut_translations/translations-qttrid/translations-qttrid.pro b/tests/ut_translations/translations-qttrid/translations-qttrid.pro new file mode 100644 index 00000000..c8d3fd56 --- /dev/null +++ b/tests/ut_translations/translations-qttrid/translations-qttrid.pro @@ -0,0 +1,18 @@ +QMAKE_EXTRA_TARGETS += check +check.depends = . +check.commands = echo "nothing to do here for “make check”" + +QMAKE_EXTRA_TARGETS += check-xml +check-xml.depends = . +check-xml.commands = echo "nothing to do here for “make check-xml”" + +LANGUAGES = ar_EG en_GB de_DE +CATALOGNAME = ut_translations-qttrid +SOURCEDIR = $$PWD/.. +TRANSLATIONDIR = $$PWD +TRANSLATION_INSTALLDIR = $$[QT_INSTALL_LIBS]/libdui-tests/translations-qttrid +DUIROOT = ../../.. +# these include files are installed to $$[QT_INSTALL_DATA]/mkspecs/features +# and included in the "libdui-dev" package: +include($$DUIROOT/src/dui_defines.prf) +include($$DUIROOT/src/translations.prf) diff --git a/tests/ut_translations/translations-qttrid/ut_translations-qttrid_ar_EG.ts b/tests/ut_translations/translations-qttrid/ut_translations-qttrid_ar_EG.ts new file mode 100644 index 00000000..2607fa42 --- /dev/null +++ b/tests/ut_translations/translations-qttrid/ut_translations-qttrid_ar_EG.ts @@ -0,0 +1,73 @@ + + + + + + + + + Untranslated message (engineering English) + + + + + + Translated message (engineering English) + + + + + + Big localized number: %L1 (engineering English) + Big localized number: %L1 + + + + + Big non-localized number: %L1 (engineering English) + Big non-localized number: %1 + + + + %Ln messages received. + + 1st translation: %Ln + 2nd translation: %Ln + 3rd translation: %Ln + 4th translation: %Ln + 5th translation: %Ln + 6th translation: %Ln + + + + + %Ln non-local messages received. + + 1st non-local translation: %n + 2nd non-local translation: %n + 3rd non-local translation: %n + 4th non-local translation: %n + 5th non-local translation: %n + 6th non-local translation: %n + + + + + Name: %1 City: %2 + + + + + %Ln messages received from %1. + %Ln messages received from %1 + + + + + + + + + + + diff --git a/tests/ut_translations/translations-qttrid/ut_translations-qttrid_de_DE.ts b/tests/ut_translations/translations-qttrid/ut_translations-qttrid_de_DE.ts new file mode 100644 index 00000000..6c28f9c4 --- /dev/null +++ b/tests/ut_translations/translations-qttrid/ut_translations-qttrid_de_DE.ts @@ -0,0 +1,60 @@ + + + + + + + + + Untranslated message (engineering English) + + + + + + Translated message (engineering English) + Übersetzte Meldung + + + + + Big localized number: %L1 (engineering English) + + + + + + Big non-localized number: %L1 (engineering English) + + + + + %Ln messages received. + + %Ln Meldung erhalten. + %Ln Meldungen erhalten. + + + + + %Ln non-local messages received. + + %n nicht-lokalisierte Meldung erhalten. + %n nicht-lokalisierte Meldungen erhalten. + + + + + Name: %1 City: %2 + Name: %1 Stadt: %2 + + + + %Ln messages received from %1. + + %Ln Nachricht erhalten von %1. + %Ln Nachrichten erhalten von %1. + + + + diff --git a/tests/ut_translations/translations-qttrid/ut_translations-qttrid_en_GB.ts b/tests/ut_translations/translations-qttrid/ut_translations-qttrid_en_GB.ts new file mode 100644 index 00000000..66373946 --- /dev/null +++ b/tests/ut_translations/translations-qttrid/ut_translations-qttrid_en_GB.ts @@ -0,0 +1,61 @@ + + + + + + + + + Untranslated message (engineering English) + + + + + + Translated message (engineering English) + Translated message + + + + + Big localized number: %L1 (engineering English) + Big localized number: %L1 + + + + + Big non-localized number: %L1 (engineering English) + Big non-localized number: %1 + + + + %Ln messages received. + + %Ln message received. + %Ln messages received. + + + + + %Ln non-local messages received. + + %n non-local message received. + %n non-local messages received. + + + + + Name: %1 City: %2 + + + + + %Ln messages received from %1. + %Ln messages received from %1 + + + + + + + diff --git a/tests/ut_translations/translations-tr/translations-tr.pro b/tests/ut_translations/translations-tr/translations-tr.pro new file mode 100644 index 00000000..c1c3f6a1 --- /dev/null +++ b/tests/ut_translations/translations-tr/translations-tr.pro @@ -0,0 +1,21 @@ +QMAKE_EXTRA_TARGETS += check +check.depends = . +check.commands = echo "nothing to do here for “make check”" + +QMAKE_EXTRA_TARGETS += check-xml +check-xml.depends = . +check-xml.commands = echo "nothing to do here for “make check-xml”" + +LANGUAGES = en_GB fi_FI +DISABLE_QTTRID_ENGINEERING_ENGLISH = yes +CATALOGNAME = ut_translations-tr +SOURCEDIR = $$PWD/.. +TRANSLATIONDIR = $$PWD +TRANSLATION_INSTALLDIR = $$[QT_INSTALL_LIBS]/libdui-tests/translations-tr +# add “-verbose” to force without “-idbased” which is the default in translations.pri +LRELEASE_OPTIONS = "-verbose" +DUIROOT = ../../.. +# these include files are installed to $$[QT_INSTALL_DATA]/mkspecs/features +# and included in the "libdui-dev" package: +include($$DUIROOT/src/dui_defines.prf) +include($$DUIROOT/src/translations.prf) diff --git a/tests/ut_translations/translations-tr/ut_translations-tr_en_GB.ts b/tests/ut_translations/translations-tr/ut_translations-tr_en_GB.ts new file mode 100644 index 00000000..592e1ab6 --- /dev/null +++ b/tests/ut_translations/translations-tr/ut_translations-tr_en_GB.ts @@ -0,0 +1,11 @@ + + + + + Ut_Translations + + hello_str + Hello world + + + diff --git a/tests/ut_translations/translations-tr/ut_translations-tr_fi_FI.ts b/tests/ut_translations/translations-tr/ut_translations-tr_fi_FI.ts new file mode 100644 index 00000000..f9cbd79d --- /dev/null +++ b/tests/ut_translations/translations-tr/ut_translations-tr_fi_FI.ts @@ -0,0 +1,11 @@ + + + + + Ut_Translations + + hello_str + Moi maailma + + + diff --git a/tests/ut_translations/ut_translations.cpp b/tests/ut_translations/ut_translations.cpp new file mode 100644 index 00000000..d92b09cb --- /dev/null +++ b/tests/ut_translations/ut_translations.cpp @@ -0,0 +1,878 @@ +/*************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (directui@nokia.com) +** +** This file is part of libdui. +** +** If you have questions regarding the use of this file, please contact +** Nokia at directui@nokia.com. +** +** This library is free software; you can redistribute it and/or +** modify it under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation +** and appearing in the file LICENSE.LGPL included in the packaging +** of this file. +** +****************************************************************************/ + +#include "ut_translations.h" +#include + +bool confIsDown() +{ + DuiGConfItem languageItem("/Dui/i18n/Language"); + QString originalValue = languageItem.value().toString(); + int skipConf = 0; + + if (originalValue.isEmpty()) { + languageItem.set("xx"); + //GConf is not running here, so skip it + if (languageItem.value().toString() != "xx") { + skipConf = 1; + } else { + languageItem.set(originalValue); + } + } + + return skipConf == 1; +} + +void Ut_Translations::initTestCase() +{ + static int argc = 0; + static char *argv[1] = { (char *) "" }; + qap = new QCoreApplication(argc, argv); + // could also use: QCoreApplication::applicationDirPath() + // but it seems to have some problems under scratchbox + DuiLocale::addTranslationPath(qApp->applicationDirPath() + "/translations-tr"); + DuiLocale::addTranslationPath(qApp->applicationDirPath() + "/translations-qttrid"); + QTextCodec::setCodecForCStrings(QTextCodec::codecForName("UTF-8")); +} + +void Ut_Translations::cleanupTestCase() +{ + delete qap; +} + +void Ut_Translations::init() +{ +} + +void Ut_Translations::cleanup() +{ +} + +void Ut_Translations::testinstallTrCatalogThenUseQtTr_data() +{ + QTest::addColumn("localeName"); + QTest::addColumn("catalog"); + QTest::addColumn("string_id"); + QTest::addColumn("translation"); + + QTest::newRow("fi_FI") << QString("fi_FI") + << QString("ut_translations-tr") + << QString("hello_str") + << QString("Moi maailma"); + QTest::newRow("en_GB") << QString("en_GB") + << QString("ut_translations-tr") + << QString("hello_str") + << QString("Hello world"); +} + +void Ut_Translations::testinstallTrCatalogThenUseQtTr() +{ + QFETCH(QString, localeName); + QFETCH(QString, catalog); + QFETCH(QString, string_id); + QFETCH(QString, translation); + + DuiLocale locale(localeName); + QString context("Ut_Translations"); + DuiLocale localeWithoutTranslations("ru_RU"); + // The following line removes the message catalog which + // may have been installed by previous unit tests in this + // file or by a previous execution of this test: + DuiLocale::setDefault(localeWithoutTranslations); + // Everything should be untranslated now: + QCOMPARE(locale.translate(qPrintable(context), qPrintable(string_id)), + string_id); + QCOMPARE(tr(qPrintable(string_id)), string_id); + locale.installTrCatalog(catalog); + // The .ts file we are using here uses + // + // Ut_Translations + // ... + // therefore we have to give "Ut_Translations" as context + // to locale.translate(): + QCOMPARE(locale.translate(qPrintable(context), qPrintable(string_id)), + translation); + // Make the locale the default to enable the message catalog also for + // tr(): + DuiLocale::setDefault(locale); + // Note that the context for tr() is automatically + // "Ut_Translations" + QCOMPARE(tr(qPrintable(string_id)), translation); +} + +void Ut_Translations::testOriginalQtTr_data() +{ + QTest::addColumn("catalog"); + QTest::addColumn("string_id"); + QTest::addColumn("translation"); + + QTest::newRow("fi_FI") << QString(qApp->applicationDirPath() + "/translations-tr/ut_translations-tr_fi_FI.qm") + << QString("hello_str") + << QString("Moi maailma"); + QTest::newRow("en_GB") << QString(qApp->applicationDirPath() + "/translations-tr/ut_translations-tr_en_GB.qm") + << QString("hello_str") + << QString("Hello world"); +} + +void Ut_Translations::testOriginalQtTr() +{ + QFETCH(QString, catalog); + QFETCH(QString, string_id); + QFETCH(QString, translation); + + // Note that the context for tr() is "Ut_Translations", i.e. + // the section + // + // Ut_Translations + // ... + // + // from the .ts file is used here. + + DuiLocale localeWithoutTranslations("en_GB"); + // do not install any catalogs for this locale and make it the default: + DuiLocale::setDefault(localeWithoutTranslations); + // Everything should be untranslated now: + QCOMPARE(tr(qPrintable(string_id)), string_id); + + QTranslator translator; + translator.load(catalog); + qap->installTranslator(&translator); + QCOMPARE(tr(qPrintable(string_id)), translation); +} + +void Ut_Translations::testQtTrId_data() +{ + QTest::addColumn("localeName"); + QTest::addColumn("messageId"); + QTest::addColumn("engEnglish"); + QTest::addColumn("translation"); + + QTest::newRow("en_GB untranslated") + << QString("en_GB") + //% "Untranslated message (engineering English)" + << QString(QT_TRID_NOOP("xx_untranslated_message")) + << QString("!! Untranslated message (engineering English)") + << QString("!! Untranslated message (engineering English)"); + + QTest::newRow("en_GB translated") + << QString("en_GB") + //% "Translated message (engineering English)" + << QString(QT_TRID_NOOP("xx_translated_message")) + << QString("!! Translated message (engineering English)") + << QString("Translated message"); + + QTest::newRow("de_DE untranslated") + << QString("de_DE") + //% "Untranslated message (engineering English)" + << QString(QT_TRID_NOOP("xx_untranslated_message")) + << QString("!! Untranslated message (engineering English)") + << QString("!! Untranslated message (engineering English)"); + + QTest::newRow("de_DE translated") + << QString("de_DE") + //% "Translated message (engineering English)" + << QString(QT_TRID_NOOP("xx_translated_message")) + << QString("!! Translated message (engineering English)") + << QString("Übersetzte Meldung"); +} + +void Ut_Translations::testQtTrId() +{ + QFETCH(QString, localeName); + QFETCH(QString, messageId); + QFETCH(QString, engEnglish); + QFETCH(QString, translation); + + DuiLocale localeWithoutTranslations("en_GB"); + // do not install any catalogs for this locale and make it the default: + DuiLocale::setDefault(localeWithoutTranslations); + // Everything should be untranslated now: + QCOMPARE(qtTrId(qPrintable(messageId)), messageId); + + // after loading catalog + DuiLocale locale(localeName); + + // installs the catalog for the “Engineering English”: + locale.installTrCatalog("ut_translations-qttrid.qm"); + QCOMPARE(locale.translate("", qPrintable(messageId)), engEnglish); + + DuiLocale::setDefault(locale); + // now qtTrId should return the engineering English: + QCOMPARE(qtTrId(qPrintable(messageId)), engEnglish); + + // installs the catalog for the real translation: + locale.installTrCatalog("ut_translations-qttrid"); + QCOMPARE(locale.translate("", qPrintable(messageId)), translation); + + DuiLocale::setDefault(locale); + // now qtTrId should return the real translation, unless + // the message is not translated at all: + QCOMPARE(qtTrId(qPrintable(messageId)), translation); +} + +void Ut_Translations::testQtTrIdLocalizedNumbers_data() +{ + QTest::addColumn("localeName"); + QTest::addColumn("messageId"); + QTest::addColumn("number"); + QTest::addColumn("engEnglish"); + QTest::addColumn("translation"); + + QTest::newRow("en_GB 4711") + << QString("en_GB") + //% "Big localized number: %L1 (engineering English)" + << QString(QT_TRID_NOOP("id_%L1_big_number")) + << 4711.0 + << QString("!! Big localized number: %L1 (engineering English)") + << QString("Big localized number: 4,711"); + + QTest::newRow("en_GB 4711 nonlocal") + << QString("en_GB") + //% "Big non-localized number: %L1 (engineering English)" + << QString(QT_TRID_NOOP("id_%L1_big_nonlocal_number")) + << 4711.0 + << QString("!! Big non-localized number: %L1 (engineering English)") + << QString("Big non-localized number: 4711"); + + QTest::newRow("ar_EG 4711") + << QString("ar_EG") + //% "Big localized number: %L1 (engineering English)" + << QString(QT_TRID_NOOP("id_%L1_big_number")) + << 4711.0 + << QString("!! Big localized number: %L1 (engineering English)") + << QString("Big localized number: ٤٬٧١١"); + + QTest::newRow("ar_EG 4711 nonlocal") + << QString("ar_EG") + //% "Big non-localized number: %L1 (engineering English)" + << QString(QT_TRID_NOOP("id_%L1_big_nonlocal_number")) + << 4711.0 + << QString("!! Big non-localized number: %L1 (engineering English)") + << QString("Big non-localized number: 4711"); +} + +void Ut_Translations::testQtTrIdLocalizedNumbers() +{ + QFETCH(QString, localeName); + QFETCH(QString, messageId); + QFETCH(double, number); + QFETCH(QString, engEnglish); + QFETCH(QString, translation); + + DuiLocale localeWithoutTranslations("en_GB"); + // do not install any catalogs for this locale and make it the default: + DuiLocale::setDefault(localeWithoutTranslations); + // Everything should be untranslated now: + QCOMPARE(qtTrId(qPrintable(messageId)).arg(number), messageId.arg(number)); + + DuiLocale locale(localeName); + + // installs the catalog for the “Engineering English”: + locale.installTrCatalog("ut_translations-qttrid.qm"); + QCOMPARE(locale.translate("", qPrintable(messageId)).arg(number), + engEnglish.arg(number)); + + DuiLocale::setDefault(locale); + // now qtTrId should return the engineering English: + QCOMPARE(qtTrId(qPrintable(messageId)).arg(number), engEnglish.arg(number)); + + // installs the catalog for the real translation: + locale.installTrCatalog("ut_translations-qttrid"); + QCOMPARE(locale.translate("", qPrintable(messageId)).arg(number), translation); + + DuiLocale::setDefault(locale); + // now qtTrId should return the real translation, unless + // the message is not translated at all: + QCOMPARE(qtTrId(qPrintable(messageId)).arg(number), translation); +} + +void Ut_Translations::testQtTrIdLocalizedNumbersPlural_data() +{ + QTest::addColumn("localeName"); + QTest::addColumn("messageId"); + QTest::addColumn("number"); + QTest::addColumn("engEnglish"); + QTest::addColumn("engEnglishLocalizedNumber"); + QTest::addColumn("translation"); + + // The following 2 qtTrId() lines are dummies to make lupdate work + // (QT_TRID_NOOP has no support for plural apparently): + + //% "%Ln messages received." + qtTrId("id_%Ln_messages_received.", 0); + //% "%Ln non-local messages received." + qtTrId("id_%Ln_nonlocal_messages_received.", 0); + + QTest::newRow("en_GB 0") + << QString("en_GB") + << QString("id_%Ln_messages_received.") + << 0 + << QString("!! 0 messages received.") + << QString("!! 0 messages received.") + << QString("0 messages received."); + QTest::newRow("en_GB 1") + << QString("en_GB") + << QString("id_%Ln_messages_received.") + << 1 + << QString("!! 1 messages received.") + << QString("!! 1 messages received.") + << QString("1 message received."); + QTest::newRow("en_GB 2") + << QString("en_GB") + << QString("id_%Ln_messages_received.") + << 2 + << QString("!! 2 messages received.") + << QString("!! 2 messages received.") + << QString("2 messages received."); + + QTest::newRow("en_GB 0 nonlocal") + << QString("en_GB") + << QString("id_%Ln_nonlocal_messages_received.") + << 0 + << QString("!! 0 non-local messages received.") + << QString("!! 0 non-local messages received.") + << QString("0 non-local messages received."); + QTest::newRow("en_GB 1 nonlocal") + << QString("en_GB") + << QString("id_%Ln_nonlocal_messages_received.") + << 1 + << QString("!! 1 non-local messages received.") + << QString("!! 1 non-local messages received.") + << QString("1 non-local message received."); + QTest::newRow("en_GB 2 nonlocal") + << QString("en_GB") + << QString("id_%Ln_nonlocal_messages_received.") + << 2 + << QString("!! 2 non-local messages received.") + << QString("!! 2 non-local messages received.") + << QString("2 non-local messages received."); + + QTest::newRow("ar_EG 0") + << QString("ar_EG") + << QString("id_%Ln_messages_received.") + << 0 + << QString("!! 0 messages received.") + << QString("!! ٠ messages received.") + << QString("1st translation: ٠"); + QTest::newRow("ar_EG 1") + << QString("ar_EG") + << QString("id_%Ln_messages_received.") + << 1 + << QString("!! 1 messages received.") + << QString("!! ١ messages received.") + << QString("2nd translation: ١"); + QTest::newRow("ar_EG 2") + << QString("ar_EG") + << QString("id_%Ln_messages_received.") + << 2 + << QString("!! 2 messages received.") + << QString("!! ٢ messages received.") + << QString("3rd translation: ٢"); + QTest::newRow("ar_EG 3") + << QString("ar_EG") + << QString("id_%Ln_messages_received.") + << 3 + << QString("!! 3 messages received.") + << QString("!! ٣ messages received.") + << QString("4th translation: ٣"); + QTest::newRow("ar_EG 4") + << QString("ar_EG") + << QString("id_%Ln_messages_received.") + << 4 + << QString("!! 4 messages received.") + << QString("!! ٤ messages received.") + << QString("4th translation: ٤"); + QTest::newRow("ar_EG 5") + << QString("ar_EG") + << QString("id_%Ln_messages_received.") + << 5 + << QString("!! 5 messages received.") + << QString("!! ٥ messages received.") + << QString("4th translation: ٥"); + QTest::newRow("ar_EG 6") + << QString("ar_EG") + << QString("id_%Ln_messages_received.") + << 6 + << QString("!! 6 messages received.") + << QString("!! ٦ messages received.") + << QString("4th translation: ٦"); + QTest::newRow("ar_EG 7") + << QString("ar_EG") + << QString("id_%Ln_messages_received.") + << 7 + << QString("!! 7 messages received.") + << QString("!! ٧ messages received.") + << QString("4th translation: ٧"); + QTest::newRow("ar_EG 8") + << QString("ar_EG") + << QString("id_%Ln_messages_received.") + << 8 + << QString("!! 8 messages received.") + << QString("!! ٨ messages received.") + << QString("4th translation: ٨"); + QTest::newRow("ar_EG 9") + << QString("ar_EG") + << QString("id_%Ln_messages_received.") + << 9 + << QString("!! 9 messages received.") + << QString("!! ٩ messages received.") + << QString("4th translation: ٩"); + QTest::newRow("ar_EG 10") + << QString("ar_EG") + << QString("id_%Ln_messages_received.") + << 10 + << QString("!! 10 messages received.") + << QString("!! ١٠ messages received.") + << QString("4th translation: ١٠"); + + QTest::newRow("ar_EG 0 nonlocal") + << QString("ar_EG") + << QString("id_%Ln_nonlocal_messages_received.") + << 0 + << QString("!! 0 non-local messages received.") + << QString("!! ٠ non-local messages received.") + << QString("1st non-local translation: 0"); + QTest::newRow("ar_EG 1 nonlocal") + << QString("ar_EG") + << QString("id_%Ln_nonlocal_messages_received.") + << 1 + << QString("!! 1 non-local messages received.") + << QString("!! ١ non-local messages received.") + << QString("2nd non-local translation: 1"); + QTest::newRow("ar_EG 2 nonlocal") + << QString("ar_EG") + << QString("id_%Ln_nonlocal_messages_received.") + << 2 + << QString("!! 2 non-local messages received.") + << QString("!! ٢ non-local messages received.") + << QString("3rd non-local translation: 2"); + QTest::newRow("ar_EG 3 nonlocal") + << QString("ar_EG") + << QString("id_%Ln_nonlocal_messages_received.") + << 3 + << QString("!! 3 non-local messages received.") + << QString("!! ٣ non-local messages received.") + << QString("4th non-local translation: 3"); + QTest::newRow("ar_EG 4 nonlocal") + << QString("ar_EG") + << QString("id_%Ln_nonlocal_messages_received.") + << 4 + << QString("!! 4 non-local messages received.") + << QString("!! ٤ non-local messages received.") + << QString("4th non-local translation: 4"); + QTest::newRow("ar_EG 5 nonlocal") + << QString("ar_EG") + << QString("id_%Ln_nonlocal_messages_received.") + << 5 + << QString("!! 5 non-local messages received.") + << QString("!! ٥ non-local messages received.") + << QString("4th non-local translation: 5"); + QTest::newRow("ar_EG 6 nonlocal") + << QString("ar_EG") + << QString("id_%Ln_nonlocal_messages_received.") + << 6 + << QString("!! 6 non-local messages received.") + << QString("!! ٦ non-local messages received.") + << QString("4th non-local translation: 6"); + QTest::newRow("ar_EG 7 nonlocal") + << QString("ar_EG") + << QString("id_%Ln_nonlocal_messages_received.") + << 7 + << QString("!! 7 non-local messages received.") + << QString("!! ٧ non-local messages received.") + << QString("4th non-local translation: 7"); + QTest::newRow("ar_EG 8 nonlocal") + << QString("ar_EG") + << QString("id_%Ln_nonlocal_messages_received.") + << 8 + << QString("!! 8 non-local messages received.") + << QString("!! ٨ non-local messages received.") + << QString("4th non-local translation: 8"); + QTest::newRow("ar_EG 9 nonlocal") + << QString("ar_EG") + << QString("id_%Ln_nonlocal_messages_received.") + << 9 + << QString("!! 9 non-local messages received.") + << QString("!! ٩ non-local messages received.") + << QString("4th non-local translation: 9"); + QTest::newRow("ar_EG 10 nonlocal") + << QString("ar_EG") + << QString("id_%Ln_nonlocal_messages_received.") + << 10 + << QString("!! 10 non-local messages received.") + << QString("!! ١٠ non-local messages received.") + << QString("4th non-local translation: 10"); +} + +void Ut_Translations::testQtTrIdLocalizedNumbersPlural() +{ + QFETCH(QString, localeName); + QFETCH(QString, messageId); + QFETCH(int, number); + QFETCH(QString, engEnglish); + QFETCH(QString, engEnglishLocalizedNumber); + QFETCH(QString, translation); + + QString messageIdNumberReplaced = messageId; + messageIdNumberReplaced.replace("%Ln", QString::number(number)); + + DuiLocale localeWithoutTranslations("en_GB"); + // do not install any catalogs for this locale and make it the default: + DuiLocale::setDefault(localeWithoutTranslations); + // Everything should be untranslated now: + QCOMPARE(qtTrId(qPrintable(messageId), number), messageIdNumberReplaced); + + DuiLocale locale(localeName); + + // installs the catalog for the “Engineering English”: + locale.installTrCatalog("ut_translations-qttrid.qm"); + QCOMPARE(locale.translate("", qPrintable(messageId), "", number), engEnglish); + DuiLocale::setDefault(locale); + + // now qtTrId should return the engineering English: + QCOMPARE(qtTrId(qPrintable(messageId), number), engEnglishLocalizedNumber); + + // installs the catalog for the real translation: + locale.installTrCatalog("ut_translations-qttrid"); + QCOMPARE(locale.translate("", qPrintable(messageId), "", number), translation); + + DuiLocale::setDefault(locale); + // now qtTrId should return the real translation, unless + // the message is not translated at all: + QCOMPARE(qtTrId(qPrintable(messageId), number), translation); +} + +void Ut_Translations::testQtTrIdMultipleVariable_data() +{ + QTest::addColumn("localeName"); + QTest::addColumn("messageId"); + QTest::addColumn("variable1"); + QTest::addColumn("variable2"); + QTest::addColumn("engEnglish"); + QTest::addColumn("translation"); + + QTest::newRow("de_DE") + << QString("de_DE") + //% "Name: %1 City: %2" + << QString(QT_TRID_NOOP("id_name_%1_and_%2_city")) + << QString("Müller") + << QString("Köln") + << QString("!! Name: %1 City: %2") + << QString("Name: Müller Stadt: Köln"); +} + +void Ut_Translations::testQtTrIdMultipleVariable() +{ + QFETCH(QString, localeName); + QFETCH(QString, messageId); + QFETCH(QString, variable1); + QFETCH(QString, variable2); + QFETCH(QString, engEnglish); + QFETCH(QString, translation); + + DuiLocale localeWithoutTranslations("en_GB"); + // do not install any catalogs for this locale and make it the default: + DuiLocale::setDefault(localeWithoutTranslations); + // Everything should be untranslated now: + QCOMPARE(qtTrId(qPrintable(messageId)).arg(variable1).arg(variable2), + messageId.arg(variable1).arg(variable2)); + + DuiLocale locale(localeName); + + // installs the catalog for the “Engineering English”: + locale.installTrCatalog("ut_translations-qttrid.qm"); + QCOMPARE(locale.translate("", qPrintable(messageId)) + .arg(variable1).arg(variable2), + engEnglish.arg(variable1).arg(variable2)); + + DuiLocale::setDefault(locale); + // now qtTrId should return the engineering English: + QCOMPARE(qtTrId(qPrintable(messageId)).arg(variable1).arg(variable2), + engEnglish.arg(variable1).arg(variable2)); + + // installs the catalog for the real translation: + locale.installTrCatalog("ut_translations-qttrid"); + QCOMPARE(locale.translate( + "", qPrintable(messageId)).arg(variable1).arg(variable2), + translation); + + DuiLocale::setDefault(locale); + // now qtTrId should return the real translation, unless + // the message is not translated at all: + QCOMPARE(qtTrId(qPrintable(messageId)).arg(variable1).arg(variable2), + translation); +} + +void Ut_Translations::testQtTrIdMultipleVariableWithPlural_data() +{ + QTest::addColumn("localeName"); + QTest::addColumn("messageId"); + QTest::addColumn("number"); + QTest::addColumn("variable"); + QTest::addColumn("engEnglish"); + QTest::addColumn("translation"); + + // The following qtTrId() line is a dummy to make lupdate work + // (QT_TRID_NOOP has no support for plural apparently): + + //% "%Ln messages received from %1." + qtTrId("id_%Ln_messages_received_from_%1.", 0); + + QTest::newRow("de_DE") + << QString("de_DE") + << QString("id_%Ln_messages_received_from_%1.") + << 0 + << QString("Björn Müller") + << QString("!! 0 messages received from Björn Müller.") + << QString("0 Nachrichten erhalten von Björn Müller."); + QTest::newRow("de_DE") + << QString("de_DE") + << QString("id_%Ln_messages_received_from_%1.") + << 1 + << QString("Björn Müller") + << QString("!! 1 messages received from Björn Müller.") + << QString("1 Nachricht erhalten von Björn Müller."); + QTest::newRow("de_DE") + << QString("de_DE") + << QString("id_%Ln_messages_received_from_%1.") + << 2 + << QString("Björn Müller") + << QString("!! 2 messages received from Björn Müller.") + << QString("2 Nachrichten erhalten von Björn Müller."); +} + +void Ut_Translations::testQtTrIdMultipleVariableWithPlural() +{ + QFETCH(QString, localeName); + QFETCH(QString, messageId); + QFETCH(int, number); + QFETCH(QString, variable); + QFETCH(QString, engEnglish); + QFETCH(QString, translation); + + QString messageIdNumberReplaced = messageId; + messageIdNumberReplaced.replace("%Ln", QString::number(number)); + + DuiLocale localeWithoutTranslations("en_GB"); + // do not install any catalogs for this locale and make it the default: + DuiLocale::setDefault(localeWithoutTranslations); + // Everything should be untranslated now: + QCOMPARE(qtTrId(qPrintable(messageId), number).arg(variable), + messageIdNumberReplaced.arg(variable)); + + DuiLocale locale(localeName); + + // installs the catalog for the “Engineering English”: + locale.installTrCatalog("ut_translations-qttrid.qm"); + QCOMPARE(locale.translate("", qPrintable(messageId), "", number).arg(variable), + engEnglish); + + DuiLocale::setDefault(locale); + // now qtTrId should return the engineering English: + QCOMPARE(qtTrId(qPrintable(messageId), number).arg(variable), engEnglish); + + // installs the catalog for the real translation: + locale.installTrCatalog("ut_translations-qttrid"); + QCOMPARE(locale.translate("", qPrintable(messageId), "", number).arg(variable), + translation); + + DuiLocale::setDefault(locale); + // now qtTrId should return the real translation, unless + // the message is not translated at all: + QCOMPARE(qtTrId(qPrintable(messageId), number).arg(variable), + translation); +} + +void Ut_Translations::testGettingTheDefaultLocaleFromTheEnvironment_data() +{ + QTest::addColumn("localeName"); + + QTest::newRow("en_GB") << "en_GB"; + QTest::newRow("fi_FI") << "fi_FI"; + QTest::newRow("ru_RU") << "ru_RU"; +} + +void Ut_Translations::testGettingTheDefaultLocaleFromTheEnvironment() +{ + QFETCH(QString, localeName); + + DuiLocale::s_systemDefault = NULL; + qputenv("LANG", qPrintable(localeName)); + QCOMPARE(QString(qgetenv("LANG")), QString(localeName)); + + QString languageItemOriginalValue(""); + DuiLocale *locale; + if (confIsDown()) { + // gconf is not available. Therefore, + // DuiLocale::createSystemDuiLocale() will get the language + // from the LANG variable. + locale = new DuiLocale(); + } else { + // gconf is available. Therefore, + // DuiLocale::createSystemDuiLocale() would get the language + // from gconf. But if the language string it gets from gconf + // is empty, it falls back to getting the language from the + // LANG variable, as in the case when gconf is not available + // at all. Therefore, we set the language in gconf to the + // empty string temporarily to test whether getting the locale + // from the LANG variable works: + DuiGConfItem languageItem("/Dui/i18n/Language"); + QString languageItemOriginalValue = languageItem.value().toString(); + languageItem.set(""); + QCOMPARE(languageItem.value().toString(), QString("")); + locale = new DuiLocale(); + languageItem.set(languageItemOriginalValue); + } + + QCOMPARE(locale->name(), localeName); +} + +void Ut_Translations::testCreatingAndDestroyingLocales() +{ + DuiLocale locale1; + DuiLocale locale2("fi_FI"); + QCOMPARE(locale2.name(), QString("fi_FI")); + DuiLocale::setDefault(locale2); + locale1.formatNumber(13); + DuiLocale locale3; + DuiLocale locale4("en_GB"); + QCOMPARE(locale4.name(), QString("en_GB")); + { + DuiLocale locale1; + } + { + DuiLocale locale1; + { + DuiLocale locale2("fi"); + } + { + DuiLocale locale3; + } + DuiLocale::setDefault(locale1); + } +} + +void Ut_Translations::benchmarkDuiLocaleConstructorAndDelete() +{ + QBENCHMARK { + DuiLocale *locale = new DuiLocale("de_DE"); + delete locale; + } +} + +void Ut_Translations::benchmarkDuiLocaleConstructorAndDeleteStack() +{ + QBENCHMARK { + DuiLocale locale("de_DE"); + } +} + +void Ut_Translations::benchmarkQLocaleConstructorAndDelete() +{ + QBENCHMARK { + QLocale *locale = new QLocale("de_DE"); + delete locale; + } +} + +void Ut_Translations::benchmarkQLocaleConstructorAndDeleteStack() +{ + QBENCHMARK { + QLocale locale("de_DE"); + } +} + +void Ut_Translations::benchmarkDuiLocaleAssignmentOperator() +{ + DuiLocale *locale1 = new DuiLocale("de_DE"); + DuiLocale *locale2 = new DuiLocale(); + QBENCHMARK { + *locale2 = *locale1; + } + delete locale1; + delete locale2; +} + +void Ut_Translations::benchmarkDuiLocaleAssignmentOperatorStack() +{ + DuiLocale locale1("de_DE"); + DuiLocale locale2; + QBENCHMARK { + locale2 = locale1; + } +} + +void Ut_Translations::benchmarkQLocaleAssignmentOperator() +{ + QLocale *locale1 = new QLocale("de_DE"); + QLocale *locale2 = new QLocale(); + QBENCHMARK { + *locale2 = *locale1; + } + delete locale1; + delete locale2; +} + +void Ut_Translations::benchmarkQLocaleAssignmentOperatorStack() +{ + QLocale locale1("de_DE"); + QLocale locale2; + QBENCHMARK { + locale2 = locale1; + } +} + +void Ut_Translations::benchmarkDuiLocaleCopyConstructorAndDelete() +{ + DuiLocale *locale1 = new DuiLocale("de_DE"); + QBENCHMARK { + DuiLocale *locale2 = new DuiLocale(*locale1); + delete locale2; + } + delete locale1; +} + +void Ut_Translations::benchmarkDuiLocaleCopyConstructorAndDeleteStack() +{ + DuiLocale locale1("de_DE"); + QBENCHMARK { + DuiLocale locale2(locale1); + } +} + +void Ut_Translations::benchmarkQLocaleCopyConstructorAndDelete() +{ + QLocale *locale1 = new QLocale("de_DE"); + QBENCHMARK { + QLocale *locale2 = new QLocale(*locale1); + delete locale2; + } + delete locale1; +} + +void Ut_Translations::benchmarkQLocaleCopyConstructorAndDeleteStack() +{ + QLocale locale1("de_DE"); + QBENCHMARK { + QLocale locale2(locale1); + } +} + +QTEST_APPLESS_MAIN(Ut_Translations); + diff --git a/tests/ut_translations/ut_translations.h b/tests/ut_translations/ut_translations.h new file mode 100644 index 00000000..480b9a1e --- /dev/null +++ b/tests/ut_translations/ut_translations.h @@ -0,0 +1,78 @@ +/*************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (directui@nokia.com) +** +** This file is part of libdui. +** +** If you have questions regarding the use of this file, please contact +** Nokia at directui@nokia.com. +** +** This library is free software; you can redistribute it and/or +** modify it under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation +** and appearing in the file LICENSE.LGPL included in the packaging +** of this file. +** +****************************************************************************/ + +#ifndef UT_TRANSLATIONS_H +#define UT_TRANSLATIONS_H + + +#include +#include +#define private public +#include +#undef private + +Q_DECLARE_METATYPE(DuiLocale::Category); +Q_DECLARE_METATYPE(DuiLocale); + +class Ut_Translations : public QObject +{ + Q_OBJECT + +private: + QCoreApplication *qap; + +private slots: + void initTestCase(); + void init(); + void cleanupTestCase(); + void cleanup(); + + void testinstallTrCatalogThenUseQtTr_data(); + void testinstallTrCatalogThenUseQtTr(); + void testOriginalQtTr_data(); + void testOriginalQtTr(); + void testQtTrId_data(); + void testQtTrId(); + void testQtTrIdLocalizedNumbers_data(); + void testQtTrIdLocalizedNumbers(); + void testQtTrIdLocalizedNumbersPlural_data(); + void testQtTrIdLocalizedNumbersPlural(); + void testQtTrIdMultipleVariable_data(); + void testQtTrIdMultipleVariable(); + void testQtTrIdMultipleVariableWithPlural_data(); + void testQtTrIdMultipleVariableWithPlural(); + void testGettingTheDefaultLocaleFromTheEnvironment_data(); + void testGettingTheDefaultLocaleFromTheEnvironment(); + void testCreatingAndDestroyingLocales(); + void benchmarkDuiLocaleConstructorAndDelete(); + void benchmarkDuiLocaleConstructorAndDeleteStack(); + void benchmarkQLocaleConstructorAndDelete(); + void benchmarkQLocaleConstructorAndDeleteStack(); + void benchmarkDuiLocaleAssignmentOperator(); + void benchmarkDuiLocaleAssignmentOperatorStack(); + void benchmarkQLocaleAssignmentOperator(); + void benchmarkQLocaleAssignmentOperatorStack(); + void benchmarkDuiLocaleCopyConstructorAndDelete(); + void benchmarkDuiLocaleCopyConstructorAndDeleteStack(); + void benchmarkQLocaleCopyConstructorAndDelete(); + void benchmarkQLocaleCopyConstructorAndDeleteStack(); +}; + + +#endif diff --git a/tests/ut_translations/ut_translations.pro b/tests/ut_translations/ut_translations.pro new file mode 100644 index 00000000..50eabb52 --- /dev/null +++ b/tests/ut_translations/ut_translations.pro @@ -0,0 +1,10 @@ +include(../common_top.pri) + +TARGET = ut_translations + +# Input +HEADERS += ut_translations.h +SOURCES += ut_translations.cpp + +include(../common_bot.pri) + -- cgit v1.2.3