From 45ee787a3f7f5d058de1f9649e696ce49bc4d5ac Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Mon, 14 Dec 2015 12:49:48 +0200 Subject: [PATCH] New test check if string contain correct place markers, i.e., %1, %2, ..., %99. --HG-- branch : develop --- src/test/ValentinaTest/tst_tstranslation.cpp | 107 +++++++++++++++++++ src/test/ValentinaTest/tst_tstranslation.h | 2 + 2 files changed, 109 insertions(+) diff --git a/src/test/ValentinaTest/tst_tstranslation.cpp b/src/test/ValentinaTest/tst_tstranslation.cpp index 665165d65..8de6f2d88 100644 --- a/src/test/ValentinaTest/tst_tstranslation.cpp +++ b/src/test/ValentinaTest/tst_tstranslation.cpp @@ -28,6 +28,7 @@ #include "tst_tstranslation.h" #include "../vmisc/logging.h" +#include "../vmisc/def.h" #include #include @@ -145,6 +146,112 @@ void TST_TSTranslation::CheckEmptyToolButton() } } +//--------------------------------------------------------------------------------------------------------------------- +void TST_TSTranslation::CheckPlaceMarkerExist_data() +{ + const QStringList locales = SupportedLocales(); + + { + QDir dir(TS_DIR); + const QStringList fileNames = dir.entryList(QStringList("valentina*.ts")); + QVERIFY2(locales.size() == fileNames.size()-1, "Unexpected count of files."); + } + + QTest::addColumn("filename"); + + for(int i = 0; i < locales.size(); ++i) + { + const QString filename = QString("valentina_%1.ts").arg(locales.at(i)); + const QString tag = QString("Check localization strings valentina_%1.ts").arg(locales.at(i)); + QTest::newRow(qUtf8Printable(tag)) << filename; + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void TST_TSTranslation::CheckPlaceMarkerExist() +{ + QFETCH(QString, filename); + + const QDomNodeList messages = LoadTSFile(filename); + if (messages.isEmpty()) + { + QSKIP("Can't begin test."); + } + + for (qint32 i = 0, num = messages.size(); i < num; ++i) + { + const QDomElement message = messages.at(i).toElement(); + if (message.isNull() == false) + { + const QString source = message.firstChildElement(TagSource).text(); + if (source.isEmpty()) + { + continue; + } + + const QDomElement translationTag = message.firstChildElement(TagTranslation); + if (translationTag.hasAttribute(AttrType)) + { + const QString attrVal = translationTag.attribute(AttrType); + if (attrVal == AttrValVanished || attrVal == AttrValUnfinished) + { + continue; + } + } + const QString translation = translationTag.text(); + if (translation.isEmpty()) + { + continue; + } + + int sourceMarkCount = 0; + int translationMarkCount = 0; + + for (int i = 1; i <= 99; ++i) + { + const QString marker = QLatin1Literal("%") + QString().setNum(i); + const bool sourceMark = source.indexOf(marker) != -1; + if (sourceMark) + { + ++sourceMarkCount; + if (sourceMarkCount != i) + { + const QString message = QString("In source string '%1' was missed place marker '%2'.") + .arg(source).arg(QLatin1Literal("%") + QString().setNum(sourceMarkCount)); + QFAIL(qUtf8Printable(message)); + } + } + + const bool translationMark = translation.indexOf(marker) != -1; + if (translationMark) + { + ++translationMarkCount; + if (translationMarkCount != i) + { + const QString message = QString("In translation string '%1' was missed place marker '%2'.") + .arg(translation).arg(QLatin1Literal("%") + QString().setNum(translationMarkCount)); + QFAIL(qUtf8Printable(message)); + } + } + + if (sourceMark != translationMark) + { + const QString message = + QString("Compare to source string in translation string '%1' was missed place marker '%2'.") + .arg(translation).arg(marker); + QFAIL(qUtf8Printable(message)); + } + } + + } + else + { + const QString message = QString("Message %1 is null.").arg(i); + QFAIL(qUtf8Printable(message)); + } + } +} + //--------------------------------------------------------------------------------------------------------------------- QDomNodeList TST_TSTranslation::LoadTSFile(const QString &filename) { diff --git a/src/test/ValentinaTest/tst_tstranslation.h b/src/test/ValentinaTest/tst_tstranslation.h index 3756bc52f..982c61dfc 100644 --- a/src/test/ValentinaTest/tst_tstranslation.h +++ b/src/test/ValentinaTest/tst_tstranslation.h @@ -43,6 +43,8 @@ public: private slots: void CheckEnglishLocalization(); void CheckEmptyToolButton(); + void CheckPlaceMarkerExist_data(); + void CheckPlaceMarkerExist(); private: Q_DISABLE_COPY(TST_TSTranslation)