diff --git a/src/app/valentina/valentina.pro b/src/app/valentina/valentina.pro index f64ed64d5..b25a4b603 100644 --- a/src/app/valentina/valentina.pro +++ b/src/app/valentina/valentina.pro @@ -344,7 +344,7 @@ INSTALL_TRANSLATIONS += \ $${TRANSLATIONS_PATH}/measurements_p9_fi_FI.qm \ $${TRANSLATIONS_PATH}/measurements_p9_en_US.qm -TRANSLATIONS += \ +INSTALL_TRANSLATIONS += \ $${TRANSLATIONS_PATH}/measurements_p10_ru_RU.qm \ $${TRANSLATIONS_PATH}/measurements_p10_uk_UA.qm \ $${TRANSLATIONS_PATH}/measurements_p10_de_DE.qm \ diff --git a/src/test/ValentinaTest/ValentinaTest.pro b/src/test/ValentinaTest/ValentinaTest.pro index 2678849d2..3eeac216d 100644 --- a/src/test/ValentinaTest/ValentinaTest.pro +++ b/src/test/ValentinaTest/ValentinaTest.pro @@ -42,7 +42,8 @@ SOURCES += \ tst_nameregexp.cpp \ tst_vlayoutdetail.cpp \ tst_varc.cpp \ - stable.cpp + stable.cpp \ + tst_measurementregexp.cpp HEADERS += \ tst_vposter.h \ @@ -52,7 +53,8 @@ HEADERS += \ tst_nameregexp.h \ tst_vlayoutdetail.h \ tst_varc.h \ - stable.h + stable.h \ + tst_measurementregexp.h # Set using ccache. Function enable_ccache() defined in common.pri. $$enable_ccache() @@ -115,6 +117,42 @@ CONFIG(debug, debug|release){ } } +#VPatternDB static library (depend on vgeometry, vmisc, VLayout) +unix|win32: LIBS += -L$$OUT_PWD/../../libs/vpatterndb/$${DESTDIR} -lvpatterndb + +INCLUDEPATH += $$PWD/../../libs/vpatterndb +DEPENDPATH += $$PWD/../../libs/vpatterndb + +win32:!win32-g++: PRE_TARGETDEPS += $$OUT_PWD/../../libs/vpatterndb/$${DESTDIR}/vpatterndb.lib +else:unix|win32-g++: PRE_TARGETDEPS += $$OUT_PWD/../../libs/vpatterndb/$${DESTDIR}/libvpatterndb.a + +#VMisc static library +unix|win32: LIBS += -L$$OUT_PWD/../../libs/vmisc/$${DESTDIR}/ -lvmisc + +INCLUDEPATH += $$PWD/../../libs/vmisc +DEPENDPATH += $$PWD/../../libs/vmisc + +win32:!win32-g++: PRE_TARGETDEPS += $$OUT_PWD/../../libs/vmisc/$${DESTDIR}/vmisc.lib +else:unix|win32-g++: PRE_TARGETDEPS += $$OUT_PWD/../../libs/vmisc/$${DESTDIR}/libvmisc.a + +# VGeometry static library (depend on ifc) +unix|win32: LIBS += -L$$OUT_PWD/../../libs/vgeometry/$${DESTDIR} -lvgeometry + +INCLUDEPATH += $$PWD/../../libs/vgeometry +DEPENDPATH += $$PWD/../../libs/vgeometry + +win32:!win32-g++: PRE_TARGETDEPS += $$OUT_PWD/../../libs/vgeometry/$${DESTDIR}/vgeometry.lib +else:unix|win32-g++: PRE_TARGETDEPS += $$OUT_PWD/../../libs/vgeometry/$${DESTDIR}/libvgeometry.a + +# IFC static library (depend on QMuParser) +unix|win32: LIBS += -L$$OUT_PWD/../../libs/ifc/$${DESTDIR}/ -lifc + +INCLUDEPATH += $$PWD/../../libs/ifc +DEPENDPATH += $$PWD/../../libs/ifc + +win32:!win32-g++: PRE_TARGETDEPS += $$OUT_PWD/../../libs/ifc/$${DESTDIR}/ifc.lib +else:unix|win32-g++: PRE_TARGETDEPS += $$OUT_PWD/../../libs/ifc/$${DESTDIR}/libifc.a + # VLayout static library unix|win32: LIBS += -L$$OUT_PWD/../../libs/vlayout/$${DESTDIR} -lvlayout @@ -124,11 +162,10 @@ DEPENDPATH += $$PWD/../../libs/vlayout win32:!win32-g++: PRE_TARGETDEPS += $$OUT_PWD/../../libs/vlayout/$${DESTDIR}/vlayout.lib else:unix|win32-g++: PRE_TARGETDEPS += $$OUT_PWD/../../libs/vlayout/$${DESTDIR}/libvlayout.a -# VGeometry static library -unix|win32: LIBS += -L$$OUT_PWD/../../libs/vgeometry/$${DESTDIR} -lvgeometry +# QMuParser library +win32:CONFIG(release, debug|release): LIBS += -L$${OUT_PWD}/../../libs/qmuparser/$${DESTDIR} -lqmuparser2 +else:win32:CONFIG(debug, debug|release): LIBS += -L$${OUT_PWD}/../../libs/qmuparser/$${DESTDIR} -lqmuparser2 +else:unix: LIBS += -L$${OUT_PWD}/../../libs/qmuparser/$${DESTDIR} -lqmuparser -INCLUDEPATH += $$PWD/../../libs/vgeometry -DEPENDPATH += $$PWD/../../libs/vgeometry - -win32:!win32-g++: PRE_TARGETDEPS += $$OUT_PWD/../../libs/vgeometry/$${DESTDIR}/vgeometry.lib -else:unix|win32-g++: PRE_TARGETDEPS += $$OUT_PWD/../../libs/vgeometry/$${DESTDIR}/libvgeometry.a +INCLUDEPATH += $${PWD}/../../libs/qmuparser +DEPENDPATH += $${PWD}/../../libs/qmuparser diff --git a/src/test/ValentinaTest/qttestmainlambda.cpp b/src/test/ValentinaTest/qttestmainlambda.cpp index 08a415890..53346a4e0 100644 --- a/src/test/ValentinaTest/qttestmainlambda.cpp +++ b/src/test/ValentinaTest/qttestmainlambda.cpp @@ -34,6 +34,7 @@ #include "tst_nameregexp.h" #include "tst_vlayoutdetail.h" #include "tst_varc.h" +#include "tst_measurementregexp.h" int main(int argc, char** argv) { @@ -52,6 +53,7 @@ int main(int argc, char** argv) ASSERT_TEST(new TST_NameRegExp()); ASSERT_TEST(new TST_VLayoutDetail()); ASSERT_TEST(new TST_VArc()); + ASSERT_TEST(new TST_MeasurementRegExp()); return status; } diff --git a/src/test/ValentinaTest/tst_measurementregexp.cpp b/src/test/ValentinaTest/tst_measurementregexp.cpp new file mode 100644 index 000000000..8d94bc86c --- /dev/null +++ b/src/test/ValentinaTest/tst_measurementregexp.cpp @@ -0,0 +1,234 @@ +/************************************************************************ + ** + ** @file tst_measurementregexp.cpp + ** @author Roman Telezhynskyi + ** @date 16 9, 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_measurementregexp.h" +#include "../qmuparser/qmudef.h" +#include "../vmisc/def.h" +#include "../vpatterndb/vtranslatemeasurements.h" + +#include +#include + +enum ErrorState {ErrorLoad = 0, ErrorInstall, ErrorSize, NoError}; + +//--------------------------------------------------------------------------------------------------------------------- +TST_MeasurementRegExp::TST_MeasurementRegExp(QObject *parent) + :QObject(parent), + pmsTranslator(nullptr), + trMs(nullptr) +{ +} + +//--------------------------------------------------------------------------------------------------------------------- +TST_MeasurementRegExp::~TST_MeasurementRegExp() +{ + delete pmsTranslator; + delete trMs; +} + +//--------------------------------------------------------------------------------------------------------------------- +// cppcheck-suppress unusedFunction +void TST_MeasurementRegExp::TestOriginalMeasurementNamesRegExp() +{ + const QStringList originalNames = OriginalNames(); + const QRegularExpression re(NameRegExp()); + + foreach(const QString &str, originalNames) + { + QCOMPARE(re.match(str).hasMatch(), true); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +// cppcheck-suppress unusedFunction +void TST_MeasurementRegExp::TestMeasurementRegExp() +{ + const int systemCounts = 55; + const QStringList locales {"ru_RU", "uk_UA", "de_DE", "cs_CZ", "he_IL", "fr_FR", "it_IT", "nl_NL", "id_ID", + "es_ES", "fi_FI", "en_US"}; + + { + const int combinations = systemCounts * locales.size(); // 55*12=660 + + QDir dir(TranslationsPath()); + const QStringList fileNames = dir.entryList(QStringList("measurements_p*_*.qm")); + + QVERIFY2(combinations == fileNames.size(), "Unexpected count of files."); + } + + for(int s = 0; s < systemCounts; ++s) + { + for(int l = 0, sz = locales.size(); l < sz; ++l) + { + const int res = LoadTranslation(QString("p%1").arg(s), locales.at(l)); + + switch(res) + { + case ErrorInstall: + case ErrorSize: + case ErrorLoad: + { + const QString message = QString("Failed to check translation for system = p%1 and locale = %2") + .arg(s) + .arg(locales.at(l)); + QFAIL(message.toUtf8().constData()); + break; + } + case NoError: + { + CheckNames(); + + if (not pmsTranslator.isNull()) + { + const bool result = QCoreApplication::removeTranslator(pmsTranslator); + + if (result == false) + { + const QString message = QString("Can't remove translation for system = p%1 and locale = %2") + .arg(s) + .arg(locales.at(l)); + QWARN(message.toUtf8().constData()); + } + delete pmsTranslator; + } + } + default: + QWARN("Unexpected state"); + } + } + } +} + +//--------------------------------------------------------------------------------------------------------------------- +QString TST_MeasurementRegExp::TranslationsPath() const +{ + return QApplication::applicationDirPath() + QStringLiteral("/../../../app/valentina/bin/translations"); +} + +//--------------------------------------------------------------------------------------------------------------------- +int TST_MeasurementRegExp::LoadTranslation(const QString &checkedSystem, const QString &checkedLocale) +{ + const QString path = TranslationsPath(); + const QString file = QString("measurements_%1_%2.qm").arg(checkedSystem).arg(checkedLocale); + + if (QFileInfo(path+"/"+file).size() <= 34) + { + const QString message = QString("Translation for system = %1 and locale = %2 is empty. \nFull path: %3/%4") + .arg(checkedSystem) + .arg(checkedLocale) + .arg(path) + .arg(file); + QWARN(message.toUtf8().constData()); + + return ErrorSize; + } + + pmsTranslator = new QTranslator(this); + + if (not pmsTranslator->load(file, path)) + { + const QString message = QString("Can't load translation for system = %1 and locale = %2. \nFull path: %3/%4") + .arg(checkedSystem) + .arg(checkedLocale) + .arg(path) + .arg(file); + QWARN(message.toUtf8().constData()); + + delete pmsTranslator; + + return ErrorLoad; + } + + if (not QCoreApplication::installTranslator(pmsTranslator)) + { + const QString message = QString("Can't install translation for system = %1 and locale = %2. \nFull path: %3/%4") + .arg(checkedSystem) + .arg(checkedLocale) + .arg(path) + .arg(file); + QWARN(message.toUtf8().constData()); + + delete pmsTranslator; + + return ErrorInstall; + } + + InitTrMs();//Very important do it after load QM file. + + return NoError; +} + +//--------------------------------------------------------------------------------------------------------------------- +void TST_MeasurementRegExp::InitTrMs() +{ + if (trMs != nullptr) + { + trMs->Retranslate(); + } + else + { + trMs = new VTranslateMeasurements(); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void TST_MeasurementRegExp::CheckNames() const +{ + const QStringList originalNames = OriginalNames(); + const QRegularExpression re(NameRegExp()); + + foreach(const QString &str, originalNames) + { + const QString translated = trMs->MToUser(str); + QCOMPARE(re.match(translated).hasMatch(), true); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +QStringList TST_MeasurementRegExp::OriginalNames() const +{ + const QStringList originalNames = QStringList() << ListGroupA() + << ListGroupB() + << ListGroupC() + << ListGroupD() + << ListGroupE() + << ListGroupF() + << ListGroupG() + << ListGroupH() + << ListGroupI() + << ListGroupJ() + << ListGroupK() + << ListGroupL() + << ListGroupM() + << ListGroupN() + << ListGroupO() + << ListGroupP() + << ListGroupQ(); + + return originalNames; +} diff --git a/src/test/ValentinaTest/tst_measurementregexp.h b/src/test/ValentinaTest/tst_measurementregexp.h new file mode 100644 index 000000000..0385bd847 --- /dev/null +++ b/src/test/ValentinaTest/tst_measurementregexp.h @@ -0,0 +1,61 @@ +/************************************************************************ + ** + ** @file tst_measurementregexp.h + ** @author Roman Telezhynskyi + ** @date 16 9, 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_MEASUREMENTREGEXP_H +#define TST_MEASUREMENTREGEXP_H + +#include + +class QTranslator; +class VTranslateMeasurements; + +class TST_MeasurementRegExp : public QObject +{ + Q_OBJECT +public: + explicit TST_MeasurementRegExp(QObject *parent = 0); + virtual ~TST_MeasurementRegExp() Q_DECL_OVERRIDE; + +private slots: + void TestOriginalMeasurementNamesRegExp(); + void TestMeasurementRegExp(); + +private: + Q_DISABLE_COPY(TST_MeasurementRegExp) + + QPointer pmsTranslator; + VTranslateMeasurements *trMs; + + QString TranslationsPath() const; + int LoadTranslation(const QString &checkedSystem, const QString &checkedLocale); + void InitTrMs(); + void CheckNames() const; + QStringList OriginalNames() const; +}; + +#endif // TST_MEASUREMENTREGEXP_H