From 5343e4e68dd889918944fc964fbe9ee60da6a804 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Sun, 13 Dec 2015 18:33:00 +0200 Subject: [PATCH] Test that allow to fix issues in English localization. --HG-- branch : develop --- src/test/ValentinaTest/ValentinaTest.pro | 8 +- src/test/ValentinaTest/qttestmainlambda.cpp | 2 + src/test/ValentinaTest/tst_tstranslation.cpp | 112 +++++++++++++++++++ src/test/ValentinaTest/tst_tstranslation.h | 48 ++++++++ 4 files changed, 168 insertions(+), 2 deletions(-) create mode 100644 src/test/ValentinaTest/tst_tstranslation.cpp create mode 100644 src/test/ValentinaTest/tst_tstranslation.h diff --git a/src/test/ValentinaTest/ValentinaTest.pro b/src/test/ValentinaTest/ValentinaTest.pro index ce95d7e2e..9779eab2c 100644 --- a/src/test/ValentinaTest/ValentinaTest.pro +++ b/src/test/ValentinaTest/ValentinaTest.pro @@ -51,7 +51,8 @@ SOURCES += \ tst_qmuparsererrormsg.cpp \ tst_vlockguard.cpp \ tst_misc.cpp \ - tst_vcommandline.cpp + tst_vcommandline.cpp \ + tst_tstranslation.cpp HEADERS += \ tst_vposter.h \ @@ -70,11 +71,14 @@ HEADERS += \ tst_qmuparsererrormsg.h \ tst_vlockguard.h \ tst_misc.h \ - tst_vcommandline.h + tst_vcommandline.h \ + tst_tstranslation.h # Set using ccache. Function enable_ccache() defined in common.pri. $$enable_ccache() +DEFINES += TS_DIR=\\\"$${PWD}/../../../share/translations\\\" + CONFIG(debug, debug|release){ # Debug mode unix { diff --git a/src/test/ValentinaTest/qttestmainlambda.cpp b/src/test/ValentinaTest/qttestmainlambda.cpp index a31e10d36..3ada48976 100644 --- a/src/test/ValentinaTest/qttestmainlambda.cpp +++ b/src/test/ValentinaTest/qttestmainlambda.cpp @@ -43,6 +43,7 @@ #include "tst_vlockguard.h" #include "tst_misc.h" #include "tst_vcommandline.h" +#include "tst_tstranslation.h" int main(int argc, char** argv) { @@ -72,6 +73,7 @@ int main(int argc, char** argv) ASSERT_TEST(new TST_VLockGuard()); ASSERT_TEST(new TST_Misc()); ASSERT_TEST(new TST_VCommandLine()); + ASSERT_TEST(new TST_TSTranslation()); return status; } diff --git a/src/test/ValentinaTest/tst_tstranslation.cpp b/src/test/ValentinaTest/tst_tstranslation.cpp new file mode 100644 index 000000000..41d0cc46b --- /dev/null +++ b/src/test/ValentinaTest/tst_tstranslation.cpp @@ -0,0 +1,112 @@ +/************************************************************************ + ** + ** @file tst_tstranslation.cpp + ** @author Roman Telezhynskyi + ** @date 13 12, 2015 + ** + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2015 Valentina project + ** All Rights Reserved. + ** + ** Valentina is free software: you can redistribute it and/or modify + ** it under the terms of the GNU General Public License as published by + ** the Free Software Foundation, either version 3 of the License, or + ** (at your option) any later version. + ** + ** Valentina is distributed in the hope that it will be useful, + ** but WITHOUT ANY WARRANTY; without even the implied warranty of + ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + ** GNU General Public License for more details. + ** + ** You should have received a copy of the GNU General Public License + ** along with Valentina. If not, see . + ** + *************************************************************************/ + +#include "tst_tstranslation.h" +#include "../vmisc/logging.h" + +#include +#include + +//--------------------------------------------------------------------------------------------------------------------- +TST_TSTranslation::TST_TSTranslation(QObject *parent) : + QObject(parent) +{ +} + +//--------------------------------------------------------------------------------------------------------------------- +void TST_TSTranslation::CheckEnglishLocalization() +{ + const QString path = QString("%1/valentina_en_US.ts").arg(TS_DIR); + QFile tsFile(path); + if (not tsFile.exists()) + { + QSKIP("Can't find valentina_en_US.ts"); + } + + if (tsFile.open(QIODevice::ReadOnly) == false) + { + const QString message = QString("Can't open file valentina_en_US.ts.\n%1").arg(tsFile.errorString()); + QSKIP(qUtf8Printable(message)); + } + + QString errorMsg; + int errorLine = -1; + int errorColumn = -1; + QDomDocument ts; + if (ts.setContent(&tsFile, &errorMsg, &errorLine, &errorColumn) == false) + { + tsFile.close(); + const QString message = QString("Parsing error file valentina_en_US.ts in line %1 column %2") + .arg(errorLine).arg(errorColumn); + QFAIL(qUtf8Printable(message)); + } + + const QDomNodeList messages = ts.elementsByTagName(QStringLiteral("message")); + if (messages.isEmpty()) + { + tsFile.close(); + QFAIL("File doesn't contain any messages"); + } + + const QString attrType = QStringLiteral("type"); + const qint32 num = messages.size(); + for (qint32 i = 0; i < num; ++i) + { + const QDomElement message = messages.at(i).toElement(); + if (message.isNull() == false) + { + const QString source = message.firstChildElement(QStringLiteral("source")).text(); + if (source.isEmpty()) + { + continue; + } + + if (message.hasAttribute(attrType)) + { + const QString attrVal = message.attribute(attrType); + if (attrVal == QLatin1Literal("vanished") || attrVal == QLatin1Literal("unfinished")) + { + continue; + } + } + const QString translation = message.firstChildElement(QStringLiteral("translation")).text(); + if (translation.isEmpty()) + { + continue; + } + + QCOMPARE(source, translation); + } + else + { + tsFile.close(); + const QString message = QString("Message %1 is null.").arg(i); + QFAIL(qUtf8Printable(message)); + } + } +} diff --git a/src/test/ValentinaTest/tst_tstranslation.h b/src/test/ValentinaTest/tst_tstranslation.h new file mode 100644 index 000000000..ec3314ea8 --- /dev/null +++ b/src/test/ValentinaTest/tst_tstranslation.h @@ -0,0 +1,48 @@ +/************************************************************************ + ** + ** @file tst_tstranslation.h + ** @author Roman Telezhynskyi + ** @date 13 12, 2015 + ** + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2015 Valentina project + ** All Rights Reserved. + ** + ** Valentina is free software: you can redistribute it and/or modify + ** it under the terms of the GNU General Public License as published by + ** the Free Software Foundation, either version 3 of the License, or + ** (at your option) any later version. + ** + ** Valentina is distributed in the hope that it will be useful, + ** but WITHOUT ANY WARRANTY; without even the implied warranty of + ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + ** GNU General Public License for more details. + ** + ** You should have received a copy of the GNU General Public License + ** along with Valentina. If not, see . + ** + *************************************************************************/ + +#ifndef TST_TSTRANSLATION_H +#define TST_TSTRANSLATION_H + +#include + +class TST_TSTranslation : public QObject +{ + Q_OBJECT +public: + explicit TST_TSTranslation(QObject *parent = 0); + +private slots: + void CheckEnglishLocalization(); + +private: + Q_DISABLE_COPY(TST_TSTranslation) + +}; + +#endif // TST_TSTRANSLATION_H