From 852bd63fe15e2ca65da412017863aefd6e1ff7c7 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Sun, 4 Oct 2015 15:20:12 +0300 Subject: [PATCH] Class for testing run valentina.exe. --HG-- branch : develop --- src/app/valentina/mainwindow.cpp | 18 ++- src/test/ValentinaTest/ValentinaTest.pro | 21 ++- src/test/ValentinaTest/abstracttest.cpp | 8 +- src/test/ValentinaTest/abstracttest.h | 2 +- src/test/ValentinaTest/qttestmainlambda.cpp | 2 + .../ValentinaTest/tst_valentina/empty.val | 18 +++ .../ValentinaTest/tst_valentina/issue_372.val | 33 +++++ .../tst_valentinacommandline.cpp | 135 ++++++++++++++++++ .../ValentinaTest/tst_valentinacommandline.h | 52 +++++++ 9 files changed, 279 insertions(+), 10 deletions(-) create mode 100644 src/test/ValentinaTest/tst_valentina/empty.val create mode 100644 src/test/ValentinaTest/tst_valentina/issue_372.val create mode 100644 src/test/ValentinaTest/tst_valentinacommandline.cpp create mode 100644 src/test/ValentinaTest/tst_valentinacommandline.h diff --git a/src/app/valentina/mainwindow.cpp b/src/app/valentina/mainwindow.cpp index d046cd2d0..a5de2ce02 100644 --- a/src/app/valentina/mainwindow.cpp +++ b/src/app/valentina/mainwindow.cpp @@ -3133,7 +3133,14 @@ bool MainWindow::LoadPattern(const QString &fileName, const QString& customMeasu { qCCritical(vMainWindow, "%s", qUtf8Printable(tr("This file already opened in another window."))); Clear(); - return false; + if (VApplication::CheckGUI()) + { + return false; + } + else + { + std::exit(V_EX_NOINPUT); + } } } @@ -3189,7 +3196,14 @@ bool MainWindow::LoadPattern(const QString &fileName, const QString& customMeasu qCCritical(vMainWindow, "%s\n\n%s\n\n%s", qUtf8Printable(tr("File error.")), qUtf8Printable(e.ErrorMessage()), qUtf8Printable(e.DetailedInformation())); Clear(); - return false; + if (VApplication::CheckGUI()) + { + return false; + } + else + { + std::exit(V_EX_NOINPUT); + } } #ifdef Q_OS_WIN32 diff --git a/src/test/ValentinaTest/ValentinaTest.pro b/src/test/ValentinaTest/ValentinaTest.pro index 2a9a4495f..cffd07c6e 100644 --- a/src/test/ValentinaTest/ValentinaTest.pro +++ b/src/test/ValentinaTest/ValentinaTest.pro @@ -44,7 +44,8 @@ SOURCES += \ tst_varc.cpp \ stable.cpp \ tst_measurementregexp.cpp \ - tst_tapecommandline.cpp + tst_tapecommandline.cpp \ + tst_valentinacommandline.cpp HEADERS += \ tst_vposter.h \ @@ -56,7 +57,8 @@ HEADERS += \ tst_varc.h \ stable.h \ tst_measurementregexp.h \ - tst_tapecommandline.h + tst_tapecommandline.h \ + tst_valentinacommandline.h # Set using ccache. Function enable_ccache() defined in common.pri. $$enable_ccache() @@ -192,9 +194,14 @@ TAPE_TEST_FILES += \ tst_tape/broken3.vit \ tst_tape/broken4.vit +VALENTINA_TEST_FILES += \ + tst_valentina/empty.val \ + tst_valentina/issue_372.val + # Compilation will fail without this files after we added them to this section. OTHER_FILES += \ - $$TAPE_TEST_FILES + $$TAPE_TEST_FILES \ + $$VALENTINA_TEST_FILES for(DIR, TAPE_TEST_FILES) { #add these absolute paths to a variable which @@ -203,3 +210,11 @@ for(DIR, TAPE_TEST_FILES) { } copyToDestdir($$tape_path, $$shell_path($${OUT_PWD}/$$DESTDIR/tst_tape)) + +for(DIR, VALENTINA_TEST_FILES) { + #add these absolute paths to a variable which + #ends up as 'mkcommands = path1 path2 path3 ...' + valentina_path += $${PWD}/$$DIR +} + +copyToDestdir($$valentina_path, $$shell_path($${OUT_PWD}/$$DESTDIR/tst_valentina)) diff --git a/src/test/ValentinaTest/abstracttest.cpp b/src/test/ValentinaTest/abstracttest.cpp index a04a5e559..85a602560 100644 --- a/src/test/ValentinaTest/abstracttest.cpp +++ b/src/test/ValentinaTest/abstracttest.cpp @@ -55,7 +55,7 @@ QString AbstractTest::ValentinaPath() const { const QString path = QStringLiteral("/../../../app/valentina/bin/valentina"); #ifdef Q_OS_WIN - return QApplication::applicationDirPath() + path + QStringLiteral(".exe"); + return QApplication::applicationDirPath() + path + QLatin1Literal(".exe"); #else return QApplication::applicationDirPath() + path; #endif @@ -66,14 +66,14 @@ QString AbstractTest::TapePath() const { const QString path = QStringLiteral("/../../../app/tape/bin/tape"); #ifdef Q_OS_WIN - return QApplication::applicationDirPath() + path + QStringLiteral(".exe"); + return QApplication::applicationDirPath() + path + QLatin1Literal(".exe"); #else return QApplication::applicationDirPath() + path; #endif } //--------------------------------------------------------------------------------------------------------------------- -bool AbstractTest::Run(bool showWarn, int &exitCode, const QString &program, const QStringList &arguments) +bool AbstractTest::Run(bool showWarn, int &exitCode, const QString &program, const QStringList &arguments, int msecs) { const QString parameters = QString("Program: %1 \nArguments: %2.").arg(program).arg(arguments.join(", ")); @@ -90,7 +90,7 @@ bool AbstractTest::Run(bool showWarn, int &exitCode, const QString &program, con process->setWorkingDirectory(info.absoluteDir().absolutePath()); process->start(program, arguments); - if (not process->waitForFinished())// 30 sec + if (not process->waitForFinished(msecs)) { const QString msg = QString("The operation timed out or an error occurred.\n%1").arg(parameters); QWARN(qUtf8Printable(msg)); diff --git a/src/test/ValentinaTest/abstracttest.h b/src/test/ValentinaTest/abstracttest.h index f4adde6e7..078b34745 100644 --- a/src/test/ValentinaTest/abstracttest.h +++ b/src/test/ValentinaTest/abstracttest.h @@ -48,7 +48,7 @@ protected: QString ValentinaPath() const; QString TapePath() const; - bool Run(bool showWarn, int &exitCode, const QString &program, const QStringList &arguments); + bool Run(bool showWarn, int &exitCode, const QString &program, const QStringList &arguments, int msecs = 30000); bool CopyRecursively(const QString &srcFilePath, const QString &tgtFilePath) const; }; diff --git a/src/test/ValentinaTest/qttestmainlambda.cpp b/src/test/ValentinaTest/qttestmainlambda.cpp index 16f24b183..2ef27d586 100644 --- a/src/test/ValentinaTest/qttestmainlambda.cpp +++ b/src/test/ValentinaTest/qttestmainlambda.cpp @@ -36,6 +36,7 @@ #include "tst_varc.h" #include "tst_measurementregexp.h" #include "tst_tapecommandline.h" +#include "tst_valentinacommandline.h" int main(int argc, char** argv) { @@ -56,6 +57,7 @@ int main(int argc, char** argv) ASSERT_TEST(new TST_VArc()); ASSERT_TEST(new TST_MeasurementRegExp()); ASSERT_TEST(new TST_TapeCommandLine()); + ASSERT_TEST(new TST_ValentinaCommandLine()); return status; } diff --git a/src/test/ValentinaTest/tst_valentina/empty.val b/src/test/ValentinaTest/tst_valentina/empty.val new file mode 100644 index 000000000..f1cd9ab2c --- /dev/null +++ b/src/test/ValentinaTest/tst_valentina/empty.val @@ -0,0 +1,18 @@ + + + + 0.2.0 + cm + + + + + + + + + + +
+ + diff --git a/src/test/ValentinaTest/tst_valentina/issue_372.val b/src/test/ValentinaTest/tst_valentina/issue_372.val new file mode 100644 index 000000000..ae49cd5dd --- /dev/null +++ b/src/test/ValentinaTest/tst_valentina/issue_372.val @@ -0,0 +1,33 @@ + + + + 0.2.0 + cm + + + + + + + + + + + + + + + + + + +
+ + + + + + +
+
+
diff --git a/src/test/ValentinaTest/tst_valentinacommandline.cpp b/src/test/ValentinaTest/tst_valentinacommandline.cpp new file mode 100644 index 000000000..4bce7a2fa --- /dev/null +++ b/src/test/ValentinaTest/tst_valentinacommandline.cpp @@ -0,0 +1,135 @@ +/************************************************************************ + ** + ** @file tst_valentinacommandline.cpp + ** @author Roman Telezhynskyi + ** @date 4 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_valentinacommandline.h" +#include "../vmisc/vsysexits.h" + +#include + +const QString tmpTestFolder = QStringLiteral("tst_valentina_tmp"); + +TST_ValentinaCommandLine::TST_ValentinaCommandLine(QObject *parent) + :AbstractTest(parent) +{ +} + +//--------------------------------------------------------------------------------------------------------------------- +// cppcheck-suppress unusedFunction +void TST_ValentinaCommandLine::init() +{ + QDir tmpDir(tmpTestFolder); + if (not tmpDir.removeRecursively()) + { + QFAIL("Fail to remove temp directory."); + } + + if (not CopyRecursively(QApplication::applicationDirPath() + QLatin1Char('/') + QLatin1Literal("tst_valentina"), + QApplication::applicationDirPath() + QLatin1Char('/') + tmpTestFolder)) + { + QFAIL("Fail to prepare files for testing."); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +// cppcheck-suppress unusedFunction +void TST_ValentinaCommandLine::OpenPatterns_data() const +{ + QTest::addColumn("file"); + QTest::addColumn("result"); + QTest::addColumn("exitCode"); + + // The file doesn't exist! + QTest::newRow("Send wrong path to a file") << "wrongPath.val" + << false + << V_EX_NOINPUT; + + QTest::newRow("Measurement independent empty file") << "empty.val" + << true + << V_EX_OK; +} + +//--------------------------------------------------------------------------------------------------------------------- +// cppcheck-suppress unusedFunction +void TST_ValentinaCommandLine::OpenPatterns() +{ + QFETCH(QString, file); + QFETCH(bool, result); + QFETCH(int, exitCode); + + int exit; + const bool res = Run(result, exit, ValentinaPath(), QStringList() << "--test" + << QApplication::applicationDirPath() + QLatin1Char('/') + tmpTestFolder + QLatin1Char('/') + file); + + QCOMPARE(res, result); + QCOMPARE(exit, exitCode); +} + +//--------------------------------------------------------------------------------------------------------------------- +// cppcheck-suppress unusedFunction +void TST_ValentinaCommandLine::ExportMode_data() const +{ + QTest::addColumn("file"); + QTest::addColumn("arguments"); + QTest::addColumn("result"); + QTest::addColumn("exitCode"); + + QTest::newRow("Issue #372")<< "issue_372.val" + << "-p;;0;;-o;;output" + << true + << V_EX_OK; +} + +//--------------------------------------------------------------------------------------------------------------------- +// cppcheck-suppress unusedFunction +void TST_ValentinaCommandLine::ExportMode() +{ + QFETCH(QString, file); + QFETCH(QString, arguments); + QFETCH(bool, result); + QFETCH(int, exitCode); + + int exit; + const QStringList arg = QStringList() << QApplication::applicationDirPath() + QLatin1Char('/') + tmpTestFolder + + QLatin1Char('/') + file + << arguments.split(";;"); + const bool res = Run(result, exit, ValentinaPath(), arg); + + QCOMPARE(res, result); + QCOMPARE(exit, exitCode); +} + +//--------------------------------------------------------------------------------------------------------------------- +// cppcheck-suppress unusedFunction +void TST_ValentinaCommandLine::cleanup() +{ + QDir tmpDir(tmpTestFolder); + if (not tmpDir.removeRecursively()) + { + QWARN("Fail to remove temp directory."); + } +} diff --git a/src/test/ValentinaTest/tst_valentinacommandline.h b/src/test/ValentinaTest/tst_valentinacommandline.h new file mode 100644 index 000000000..974a31a4a --- /dev/null +++ b/src/test/ValentinaTest/tst_valentinacommandline.h @@ -0,0 +1,52 @@ +/************************************************************************ + ** + ** @file tst_valentinacommandline.h + ** @author Roman Telezhynskyi + ** @date 4 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_VALENTINACOMMANDLINE_H +#define TST_VALENTINACOMMANDLINE_H + +#include "abstracttest.h" + +class TST_ValentinaCommandLine : public AbstractTest +{ + Q_OBJECT +public: + TST_ValentinaCommandLine(QObject *parent = 0); + +private slots: + void init(); + void OpenPatterns_data() const; + void OpenPatterns(); + void ExportMode_data() const; + void ExportMode(); + void cleanup(); + +private: + Q_DISABLE_COPY(TST_ValentinaCommandLine) +}; + +#endif // TST_VALENTINACOMMANDLINE_H