diff --git a/scripts/lrelease.sh b/scripts/lrelease.sh index d0cfa693d..7c9d657e4 100755 --- a/scripts/lrelease.sh +++ b/scripts/lrelease.sh @@ -2,5 +2,5 @@ # Run this script if you want release all translated string in program. # lrelease doesn't work with recursive *.pro file and without direct pointing to correct *.pro doesn't find anything. # Please run this script from folder /scripts. -lrelease -removeidentical -nounfinished ../share/translations/translations.pro -lrelease -removeidentical -nounfinished ../share/translations/measurements.pro +lrelease ../share/translations/translations.pro +lrelease ../share/translations/measurements.pro diff --git a/src/app/valentina/valentina.pro b/src/app/valentina/valentina.pro index 6d01bcc0e..a75a7fc91 100644 --- a/src/app/valentina/valentina.pro +++ b/src/app/valentina/valentina.pro @@ -2023,7 +2023,7 @@ for(_translation_name, INSTALL_TRANSLATIONS) { _translation_name_ts = $$section(_translation_name_qm, ".", 0, 0).ts !exists($${PWD}/$$_translation_name) { - system($$shell_path($$[QT_INSTALL_BINS]/$$LRELEASE) -removeidentical -nounfinished $$shell_path($${PWD}/$${TRANSLATIONS_PATH}/$$_translation_name_ts) -qm $$shell_path($${PWD}/$$_translation_name)) + system($$shell_path($$[QT_INSTALL_BINS]/$$LRELEASE) $$shell_path($${PWD}/$${TRANSLATIONS_PATH}/$$_translation_name_ts) -qm $$shell_path($${PWD}/$$_translation_name)) } QMAKE_CLEAN += $${PWD}/$$_translation_name } diff --git a/src/test/ValentinaTest/ValentinaTest.pro b/src/test/ValentinaTest/ValentinaTest.pro index 956656501..8d64bb5d7 100644 --- a/src/test/ValentinaTest/ValentinaTest.pro +++ b/src/test/ValentinaTest/ValentinaTest.pro @@ -47,7 +47,8 @@ SOURCES += \ tst_tapecommandline.cpp \ tst_valentinacommandline.cpp \ tst_qmutokenparser.cpp \ - tst_vmeasurements.cpp + tst_vmeasurements.cpp \ + tst_qmuparsererrormsg.cpp HEADERS += \ tst_vposter.h \ @@ -62,7 +63,8 @@ HEADERS += \ tst_tapecommandline.h \ tst_valentinacommandline.h \ tst_qmutokenparser.h \ - tst_vmeasurements.h + tst_vmeasurements.h \ + tst_qmuparsererrormsg.h # Set using ccache. Function enable_ccache() defined in common.pri. $$enable_ccache() diff --git a/src/test/ValentinaTest/abstracttest.cpp b/src/test/ValentinaTest/abstracttest.cpp index c377009df..00039288b 100644 --- a/src/test/ValentinaTest/abstracttest.cpp +++ b/src/test/ValentinaTest/abstracttest.cpp @@ -72,6 +72,12 @@ QString AbstractTest::TapePath() const #endif } +//--------------------------------------------------------------------------------------------------------------------- +QString AbstractTest::TranslationsPath() const +{ + return QApplication::applicationDirPath() + QStringLiteral("/../../../app/valentina/bin/translations"); +} + //--------------------------------------------------------------------------------------------------------------------- bool AbstractTest::Run(bool showWarn, int exit, int &exitCode, const QString &program, const QStringList &arguments, int msecs) diff --git a/src/test/ValentinaTest/abstracttest.h b/src/test/ValentinaTest/abstracttest.h index 62d1fd4df..349009cff 100644 --- a/src/test/ValentinaTest/abstracttest.h +++ b/src/test/ValentinaTest/abstracttest.h @@ -36,6 +36,8 @@ constexpr auto TST_EX_BIN = -1; // Can't find binary. constexpr auto TST_EX_TIME_OUT = -2; // The operation timed out or an error occurred. constexpr auto TST_EX_CRASH = -3; // Program crashed. +enum ErrorState {ErrorLoad = 0, ErrorInstall, ErrorSize, NoError}; + class AbstractTest : public QObject { Q_OBJECT @@ -47,6 +49,7 @@ protected: QString ValentinaPath() const; QString TapePath() const; + QString TranslationsPath() const; bool Run(bool showWarn, int exit, int &exitCode, const QString &program, const QStringList &arguments, int msecs = 30000); diff --git a/src/test/ValentinaTest/qttestmainlambda.cpp b/src/test/ValentinaTest/qttestmainlambda.cpp index abc305b92..97bc40375 100644 --- a/src/test/ValentinaTest/qttestmainlambda.cpp +++ b/src/test/ValentinaTest/qttestmainlambda.cpp @@ -39,6 +39,7 @@ #include "tst_valentinacommandline.h" #include "tst_qmutokenparser.h" #include "tst_vmeasurements.h" +#include "tst_qmuparsererrormsg.h" int main(int argc, char** argv) { @@ -64,6 +65,7 @@ int main(int argc, char** argv) ASSERT_TEST(new TST_ValentinaCommandLine()); ASSERT_TEST(new TST_QmuTokenParser()); ASSERT_TEST(new TST_VMeasurements()); + ASSERT_TEST(new TST_QmuParserErrorMsg()); return status; } diff --git a/src/test/ValentinaTest/tst_measurementregexp.cpp b/src/test/ValentinaTest/tst_measurementregexp.cpp index dd9aae9bb..c7b2f94b0 100644 --- a/src/test/ValentinaTest/tst_measurementregexp.cpp +++ b/src/test/ValentinaTest/tst_measurementregexp.cpp @@ -35,11 +35,9 @@ #include #include -enum ErrorState {ErrorLoad = 0, ErrorInstall, ErrorSize, NoError}; - //--------------------------------------------------------------------------------------------------------------------- TST_MeasurementRegExp::TST_MeasurementRegExp(QObject *parent) - :QObject(parent), + :AbstractTest(parent), pmsTranslator(nullptr), trMs(nullptr) { @@ -396,12 +394,6 @@ void TST_MeasurementRegExp::TestCorrectOrderMeasurement() QCOMPARE(name, expect); } -//--------------------------------------------------------------------------------------------------------------------- -QString TST_MeasurementRegExp::TranslationsPath() const -{ - return QApplication::applicationDirPath() + QStringLiteral("/../../../app/valentina/bin/translations"); -} - //--------------------------------------------------------------------------------------------------------------------- int TST_MeasurementRegExp::LoadTranslation(const QString &checkedSystem, const QString &checkedLocale) { diff --git a/src/test/ValentinaTest/tst_measurementregexp.h b/src/test/ValentinaTest/tst_measurementregexp.h index 49a94d7bc..4eaee04c5 100644 --- a/src/test/ValentinaTest/tst_measurementregexp.h +++ b/src/test/ValentinaTest/tst_measurementregexp.h @@ -29,12 +29,12 @@ #ifndef TST_MEASUREMENTREGEXP_H #define TST_MEASUREMENTREGEXP_H -#include +#include "abstracttest.h" class QTranslator; class VTranslateMeasurements; -class TST_MeasurementRegExp : public QObject +class TST_MeasurementRegExp : public AbstractTest { Q_OBJECT public: @@ -54,7 +54,6 @@ private: QPointer pmsTranslator; VTranslateMeasurements *trMs; - QString TranslationsPath() const; int LoadTranslation(const QString &checkedSystem, const QString &checkedLocale); void InitTrMs(); void CheckNames() const; diff --git a/src/test/ValentinaTest/tst_qmuparsererrormsg.cpp b/src/test/ValentinaTest/tst_qmuparsererrormsg.cpp new file mode 100644 index 000000000..4c15c0eb5 --- /dev/null +++ b/src/test/ValentinaTest/tst_qmuparsererrormsg.cpp @@ -0,0 +1,215 @@ +/************************************************************************ + ** + ** @file tst_qmuparsererrormsg.cpp + ** @author Roman Telezhynskyi + ** @date 16 10, 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_qmuparsererrormsg.h" +#include "../vmisc/def.h" +#include "../vmisc/logging.h" + +#include + +//--------------------------------------------------------------------------------------------------------------------- +TST_QmuParserErrorMsg::TST_QmuParserErrorMsg(QObject *parent) : + AbstractTest(parent), + appTranslator(nullptr), + msg(nullptr) +{ +} + +//--------------------------------------------------------------------------------------------------------------------- +TST_QmuParserErrorMsg::~TST_QmuParserErrorMsg() +{ + delete appTranslator; + delete msg; +} + +//--------------------------------------------------------------------------------------------------------------------- +void TST_QmuParserErrorMsg::TestEErrorCodes_data() +{ + { + QDir dir(TranslationsPath()); + const QStringList fileNames = dir.entryList(QStringList("valentina_*.qm")); + + QVERIFY2(SupportedLocales().size() == fileNames.size(), "Unexpected count of files."); + } + + QTest::addColumn("code"); + QTest::addColumn("locale"); + QTest::addColumn("tok"); + QTest::addColumn("pos"); + + AddCase(qmu::ecUNASSIGNABLE_TOKEN, true, true); + AddCase(qmu::ecINTERNAL_ERROR, false, false); + AddCase(qmu::ecINVALID_NAME, true, false); + AddCase(qmu::ecINVALID_BINOP_IDENT, true, false); + AddCase(qmu::ecINVALID_INFIX_IDENT, true, false); + AddCase(qmu::ecINVALID_POSTFIX_IDENT, true, false); + AddCase(qmu::ecINVALID_FUN_PTR, false, false); + AddCase(qmu::ecEMPTY_EXPRESSION, false, false); + AddCase(qmu::ecINVALID_VAR_PTR, false, false); + AddCase(qmu::ecUNEXPECTED_OPERATOR, true, true); + AddCase(qmu::ecUNEXPECTED_EOF, false, true); + AddCase(qmu::ecUNEXPECTED_ARG_SEP, false, true); + AddCase(qmu::ecUNEXPECTED_PARENS, true, true); + AddCase(qmu::ecUNEXPECTED_FUN, true, true); + AddCase(qmu::ecUNEXPECTED_VAL, true, true); + AddCase(qmu::ecUNEXPECTED_VAR, true, true); + AddCase(qmu::ecUNEXPECTED_ARG, false, true); + AddCase(qmu::ecMISSING_PARENS, false, false); + AddCase(qmu::ecTOO_MANY_PARAMS, true, true); + AddCase(qmu::ecTOO_FEW_PARAMS, true, true); + AddCase(qmu::ecDIV_BY_ZERO, false, false); + AddCase(qmu::ecDOMAIN_ERROR, false, false); + AddCase(qmu::ecNAME_CONFLICT, false, false); + AddCase(qmu::ecOPT_PRI, false, false); + AddCase(qmu::ecBUILTIN_OVERLOAD, true, false); + AddCase(qmu::ecUNEXPECTED_STR, false, true); + AddCase(qmu::ecUNTERMINATED_STRING, false, true); + AddCase(qmu::ecSTRING_EXPECTED, false, false); + AddCase(qmu::ecVAL_EXPECTED, false, false); + AddCase(qmu::ecOPRT_TYPE_CONFLICT, true, true); + AddCase(qmu::ecSTR_RESULT, false, false); + AddCase(qmu::ecGENERIC, false, false); + AddCase(qmu::ecLOCALE, false, false); + AddCase(qmu::ecUNEXPECTED_CONDITIONAL, true, false); + AddCase(qmu::ecMISSING_ELSE_CLAUSE, false, false); + AddCase(qmu::ecMISPLACED_COLON, false, true); +} + +//--------------------------------------------------------------------------------------------------------------------- +void TST_QmuParserErrorMsg::TestEErrorCodes() +{ + QFETCH(int, code); + QFETCH(QString, locale); + QFETCH(bool, tok); + QFETCH(bool, pos); + + const int res = LoadTranslation(locale); + + switch(res) + { + case ErrorInstall: + case ErrorSize: + case ErrorLoad: + { + const QString message = QString("Failed to check translation for locale = %1").arg(locale); + QSKIP(qUtf8Printable(message)); + break; + } + case NoError: + { + CheckStrings(code, tok, pos); + + if (not appTranslator.isNull()) + { + const bool result = QCoreApplication::removeTranslator(appTranslator); + + if (result == false) + { + const QString message = QString("Can't remove translation for locale = %1").arg(locale); + QWARN(qUtf8Printable(message)); + } + delete appTranslator; + } + break; + } + default: + QWARN("Unexpected state"); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void TST_QmuParserErrorMsg::AddCase(int code, bool tok, bool pos) +{ + const QStringList locales = SupportedLocales(); + + for(int l = 0, sz = locales.size(); l < sz; ++l) + { + const QString locale = locales.at(l); + const QString tag = QString("Check translation code=%1 in file valentina_%2.qm").arg(code).arg(locale); + QTest::newRow(qUtf8Printable(tag)) << code << locale << tok << pos; + } +} + +//--------------------------------------------------------------------------------------------------------------------- +int TST_QmuParserErrorMsg::LoadTranslation(const QString &checkedLocale) +{ + const QString path = TranslationsPath(); + const QString file = QString("valentina_%1.qm").arg(checkedLocale); + + if (QFileInfo(path+"/"+file).size() <= 34) + { + const QString message = QString("Translation for locale = %1 is empty. \nFull path: %2/%3") + .arg(checkedLocale) + .arg(path) + .arg(file); + QWARN(qUtf8Printable(message)); + + return ErrorSize; + } + + appTranslator = new QTranslator(this); + + if (not appTranslator->load(file, path)) + { + const QString message = QString("Can't load translation for locale = %1. \nFull path: %2/%3") + .arg(checkedLocale) + .arg(path) + .arg(file); + QWARN(qUtf8Printable(message)); + + delete appTranslator; + + return ErrorLoad; + } + + if (not QCoreApplication::installTranslator(appTranslator)) + { + const QString message = QString("Can't install translation for locale = %1. \nFull path: %2/%3") + .arg(checkedLocale) + .arg(path) + .arg(file); + QWARN(qUtf8Printable(message)); + + delete appTranslator; + + return ErrorInstall; + } + + delete msg; + msg = new qmu::QmuParserErrorMsg();//Very important do it after load QM file. + + return NoError; +} + +//--------------------------------------------------------------------------------------------------------------------- +void TST_QmuParserErrorMsg::CheckStrings(int code, bool tok, bool pos) +{ + const QString translated = (*msg)[code]; + QCOMPARE(translated.indexOf(QLatin1Literal("$TOK$")) != -1, tok); + QCOMPARE(translated.indexOf(QLatin1Literal("$POS$")) != -1, pos); +} diff --git a/src/test/ValentinaTest/tst_qmuparsererrormsg.h b/src/test/ValentinaTest/tst_qmuparsererrormsg.h new file mode 100644 index 000000000..7f5d67054 --- /dev/null +++ b/src/test/ValentinaTest/tst_qmuparsererrormsg.h @@ -0,0 +1,59 @@ +/************************************************************************ + ** + ** @file tst_qmuparsererrormsg.h + ** @author Roman Telezhynskyi + ** @date 16 10, 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_QMUPARSERERRORMSG_H +#define TST_QMUPARSERERRORMSG_H + +#include "abstracttest.h" +#include "../qmuparser/qmuparsererror.h" + +#include + +class TST_QmuParserErrorMsg : public AbstractTest +{ + Q_OBJECT +public: + explicit TST_QmuParserErrorMsg(QObject *parent = nullptr); + virtual ~TST_QmuParserErrorMsg() Q_DECL_OVERRIDE; + +private slots: + void TestEErrorCodes_data(); + void TestEErrorCodes(); + +private: + Q_DISABLE_COPY(TST_QmuParserErrorMsg) + + QPointer appTranslator; + qmu::QmuParserErrorMsg *msg; + + void AddCase(int code, bool tok, bool pos); + int LoadTranslation(const QString &checkedLocale); + void CheckStrings(int code, bool tok, bool pos); +}; + +#endif // TST_QMUPARSERERRORMSG_H