From 18a3a289ff1f6b07e6414a0f801c4c3e32b4a164 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Tue, 3 Nov 2015 18:19:52 +0200 Subject: [PATCH] New test. Each translated measurement name should be unique. --HG-- branch : develop --- .../ValentinaTest/tst_measurementregexp.cpp | 124 ++++++++++++++---- .../ValentinaTest/tst_measurementregexp.h | 6 +- 2 files changed, 102 insertions(+), 28 deletions(-) diff --git a/src/test/ValentinaTest/tst_measurementregexp.cpp b/src/test/ValentinaTest/tst_measurementregexp.cpp index d9b0cfeae..fa5622d90 100644 --- a/src/test/ValentinaTest/tst_measurementregexp.cpp +++ b/src/test/ValentinaTest/tst_measurementregexp.cpp @@ -67,31 +67,7 @@ void TST_MeasurementRegExp::TestOriginalMeasurementNamesRegExp() // cppcheck-suppress unusedFunction void TST_MeasurementRegExp::TestMeasurementRegExp_data() { - const int systemCounts = 56; - const QStringList locales = SupportedLocales(); - - { - const int combinations = systemCounts * locales.size(); - - QDir dir(TranslationsPath()); - const QStringList fileNames = dir.entryList(QStringList("measurements_p*_*.qm")); - - QVERIFY2(combinations == fileNames.size(), "Unexpected count of files."); - } - - QTest::addColumn("system"); - QTest::addColumn("locale"); - - for(int s = 0; s < systemCounts; ++s) - { - for(int l = 0, sz = locales.size(); l < sz; ++l) - { - const QString system = QString("p%1").arg(s); - const QString locale = locales.at(l); - const QString tag = QString("Check translation measurements_%1_%2.qm").arg(system).arg(locale); - QTest::newRow(qUtf8Printable(tag)) << system << locale; - } - } + PrepareMeasurementData(); } //--------------------------------------------------------------------------------------------------------------------- @@ -117,7 +93,7 @@ void TST_MeasurementRegExp::TestMeasurementRegExp() } case NoError: { - CheckNames(); + CheckRegExpNames(); if (not pmsTranslator.isNull()) { @@ -395,6 +371,86 @@ void TST_MeasurementRegExp::TestCorrectOrderMeasurement() QCOMPARE(name, expect); } +//--------------------------------------------------------------------------------------------------------------------- +void TST_MeasurementRegExp::TestAllTranslatedMeasurementsIsUnique_data() +{ + PrepareMeasurementData(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void TST_MeasurementRegExp::TestAllTranslatedMeasurementsIsUnique() +{ + QFETCH(QString, system); + QFETCH(QString, locale); + + const int res = LoadTranslation(system, locale); + + switch(res) + { + case ErrorInstall: + case ErrorSize: + case ErrorLoad: + { + const QString message = QString("Failed to check translation for system = %1 and locale = %2") + .arg(system) + .arg(locale); + QSKIP(qUtf8Printable(message)); + break; + } + case NoError: + { + CheckIsNamesUnique(); + + if (not pmsTranslator.isNull()) + { + const bool result = QCoreApplication::removeTranslator(pmsTranslator); + + if (result == false) + { + const QString message = QString("Can't remove translation for system = %1 and locale = %2") + .arg(system) + .arg(locale); + QWARN(qUtf8Printable(message)); + } + delete pmsTranslator; + } + break; + } + default: + QWARN("Unexpected state"); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void TST_MeasurementRegExp::PrepareMeasurementData() +{ + const int systemCounts = 56; + const QStringList locales = SupportedLocales(); + + { + const int combinations = systemCounts * locales.size(); + + QDir dir(TranslationsPath()); + const QStringList fileNames = dir.entryList(QStringList("measurements_p*_*.qm")); + + QVERIFY2(combinations == fileNames.size(), "Unexpected count of files."); + } + + QTest::addColumn("system"); + QTest::addColumn("locale"); + + for(int s = 0; s < systemCounts; ++s) + { + for(int l = 0, sz = locales.size(); l < sz; ++l) + { + const QString system = QString("p%1").arg(s); + const QString locale = locales.at(l); + const QString tag = QString("Check translation measurements_%1_%2.qm").arg(system).arg(locale); + QTest::newRow(qUtf8Printable(tag)) << system << locale; + } + } +} + //--------------------------------------------------------------------------------------------------------------------- int TST_MeasurementRegExp::LoadTranslation(const QString &checkedSystem, const QString &checkedLocale) { @@ -462,7 +518,7 @@ void TST_MeasurementRegExp::InitTrMs() } //--------------------------------------------------------------------------------------------------------------------- -void TST_MeasurementRegExp::CheckNames() const +void TST_MeasurementRegExp::CheckRegExpNames() const { const QStringList originalNames = AllGroupNames(); const QRegularExpression re(NameRegExp()); @@ -473,3 +529,17 @@ void TST_MeasurementRegExp::CheckNames() const QCOMPARE(re.match(translated).hasMatch(), true); } } + +//--------------------------------------------------------------------------------------------------------------------- +void TST_MeasurementRegExp::CheckIsNamesUnique() const +{ + const QStringList originalNames = AllGroupNames(); + QSet names; + + foreach(const QString &str, originalNames) + { + const QString translated = trMs->MToUser(str); + QCOMPARE(names.contains(translated), false); + names.insert(translated); + } +} diff --git a/src/test/ValentinaTest/tst_measurementregexp.h b/src/test/ValentinaTest/tst_measurementregexp.h index 8969a8620..7395b3a74 100644 --- a/src/test/ValentinaTest/tst_measurementregexp.h +++ b/src/test/ValentinaTest/tst_measurementregexp.h @@ -49,6 +49,8 @@ private slots: void TestMeasurementRegExp(); void TestCorrectOrderMeasurement_data(); void TestCorrectOrderMeasurement(); + void TestAllTranslatedMeasurementsIsUnique_data(); + void TestAllTranslatedMeasurementsIsUnique(); private: Q_DISABLE_COPY(TST_MeasurementRegExp) @@ -56,9 +58,11 @@ private: QPointer pmsTranslator; VTranslateMeasurements *trMs; + void PrepareMeasurementData(); int LoadTranslation(const QString &checkedSystem, const QString &checkedLocale); void InitTrMs(); - void CheckNames() const; + void CheckRegExpNames() const; + void CheckIsNamesUnique() const; }; #endif // TST_MEASUREMENTREGEXP_H