From ed156d3d57222a03fff3fa4948567efaf89bd771 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Sat, 3 Oct 2015 14:09:06 +0300 Subject: [PATCH] Testing Tape.exe. More test cases. --HG-- branch : develop --- src/app/tape/main.cpp | 3 +- src/app/valentina/main.cpp | 2 +- src/libs/vmisc/vsysexits.h | 2 + src/test/ValentinaTest/ValentinaTest.pro | 14 +- src/test/ValentinaTest/abstracttest.cpp | 36 ++- src/test/ValentinaTest/abstracttest.h | 7 +- .../ValentinaTest/tst_tape/GOST_man_ru.vst | 158 +++++++++++ .../tst_tape/all_measurements.vit | 254 ++++++++++++++++++ .../tst_tape/all_measurements.vst | 249 +++++++++++++++++ src/test/ValentinaTest/tst_tape/broken1.vit | 19 ++ src/test/ValentinaTest/tst_tape/broken2.vit | 18 ++ src/test/ValentinaTest/tst_tape/broken3.vit | 18 ++ src/test/ValentinaTest/tst_tape/broken4.vit | 18 ++ src/test/ValentinaTest/tst_tape/empty.vit | 16 ++ .../ValentinaTest/tst_tapecommandline.cpp | 49 +++- 15 files changed, 836 insertions(+), 27 deletions(-) create mode 100644 src/test/ValentinaTest/tst_tape/GOST_man_ru.vst create mode 100644 src/test/ValentinaTest/tst_tape/all_measurements.vit create mode 100644 src/test/ValentinaTest/tst_tape/all_measurements.vst create mode 100644 src/test/ValentinaTest/tst_tape/broken1.vit create mode 100644 src/test/ValentinaTest/tst_tape/broken2.vit create mode 100644 src/test/ValentinaTest/tst_tape/broken3.vit create mode 100644 src/test/ValentinaTest/tst_tape/broken4.vit create mode 100644 src/test/ValentinaTest/tst_tape/empty.vit diff --git a/src/app/tape/main.cpp b/src/app/tape/main.cpp index e2ba5da14..718ed5766 100644 --- a/src/app/tape/main.cpp +++ b/src/app/tape/main.cpp @@ -28,6 +28,7 @@ #include "tmainwindow.h" #include "mapplication.h" +#include "../vmisc/vsysexits.h" #include // For QT_REQUIRE_VERSION @@ -54,5 +55,5 @@ int main(int argc, char *argv[]) } app.InitOptions(); app.ParseCommandLine(app.arguments()); - return app.IsTestMode() ? 0 : app.exec(); // single return point is always better than more + return app.IsTestMode() ? V_EX_OK : app.exec(); // single return point is always better than more } diff --git a/src/app/valentina/main.cpp b/src/app/valentina/main.cpp index a39f35be2..728a6d09a 100644 --- a/src/app/valentina/main.cpp +++ b/src/app/valentina/main.cpp @@ -80,5 +80,5 @@ int main(int argc, char *argv[]) } } - return (VApplication::CheckGUI()) ? app.exec() : 0; // single return point is always better than more + return (VApplication::CheckGUI()) ? app.exec() : V_EX_OK; // single return point is always better than more } diff --git a/src/libs/vmisc/vsysexits.h b/src/libs/vmisc/vsysexits.h index 6e5f33f60..e8e024e63 100644 --- a/src/libs/vmisc/vsysexits.h +++ b/src/libs/vmisc/vsysexits.h @@ -31,6 +31,8 @@ #include +constexpr auto V_EX_OK = 0; /*Indicate the successful exit.*/ + constexpr auto V_EX_USAGE = 64; /*The command was used incorrectly, e.g., with the wrong number of arguments, a bad flag, a bad syntax in a parameter, or whatever.*/ diff --git a/src/test/ValentinaTest/ValentinaTest.pro b/src/test/ValentinaTest/ValentinaTest.pro index 31f52e3e9..2a9a4495f 100644 --- a/src/test/ValentinaTest/ValentinaTest.pro +++ b/src/test/ValentinaTest/ValentinaTest.pro @@ -182,7 +182,19 @@ INCLUDEPATH += $${PWD}/../../libs/vpropertyexplorer DEPENDPATH += $${PWD}/../../libs/vpropertyexplorer TAPE_TEST_FILES += \ - tst_tape/keiko.vit + tst_tape/keiko.vit \ + tst_tape/empty.vit \ + tst_tape/all_measurements.vit \ + tst_tape/all_measurements.vst \ + tst_tape/GOST_man_ru.vst \ + tst_tape/broken1.vit \ + tst_tape/broken2.vit \ + tst_tape/broken3.vit \ + tst_tape/broken4.vit + +# Compilation will fail without this files after we added them to this section. +OTHER_FILES += \ + $$TAPE_TEST_FILES for(DIR, TAPE_TEST_FILES) { #add these absolute paths to a variable which diff --git a/src/test/ValentinaTest/abstracttest.cpp b/src/test/ValentinaTest/abstracttest.cpp index ef26e5788..a04a5e559 100644 --- a/src/test/ValentinaTest/abstracttest.cpp +++ b/src/test/ValentinaTest/abstracttest.cpp @@ -28,6 +28,7 @@ #include "abstracttest.h" #include "../vmisc/logging.h" +#include "../vmisc/vsysexits.h" #include @@ -72,18 +73,16 @@ QString AbstractTest::TapePath() const } //--------------------------------------------------------------------------------------------------------------------- -bool AbstractTest::Run(bool showWarn, const QString &program, const QStringList &arguments) +bool AbstractTest::Run(bool showWarn, int &exitCode, const QString &program, const QStringList &arguments) { const QString parameters = QString("Program: %1 \nArguments: %2.").arg(program).arg(arguments.join(", ")); QFileInfo info(program); if (not info.exists()) { - if (showWarn) - { - const QString msg = QString("Can't find binary.\n%1").arg(parameters); - QWARN(qUtf8Printable(msg)); - } + const QString msg = QString("Can't find binary.\n%1").arg(parameters); + QWARN(qUtf8Printable(msg)); + exitCode = TST_EX_BIN; return false; } @@ -93,36 +92,33 @@ bool AbstractTest::Run(bool showWarn, const QString &program, const QStringList if (not process->waitForFinished())// 30 sec { - if (showWarn) - { - const QString msg = QString("The operation timed out or an error occurred.\n%1").arg(parameters); - QWARN(qUtf8Printable(msg)); - } + const QString msg = QString("The operation timed out or an error occurred.\n%1").arg(parameters); + QWARN(qUtf8Printable(msg)); + exitCode = TST_EX_TIME_OUT; return false; } if (process->exitStatus() == QProcess::CrashExit) { - if (showWarn) - { - const QString msg = QString("Program crashed.\n%1\n%2").arg(parameters) - .arg(QString(process->readAllStandardError())); - QWARN(qUtf8Printable(msg)); - } + const QString msg = QString("Program crashed.\n%1\n%2").arg(parameters) + .arg(QString(process->readAllStandardError())); + QWARN(qUtf8Printable(msg)); + exitCode = TST_EX_CRASH; return false; } - if (process->exitCode() != 0) + if (process->exitCode() != V_EX_OK) { if (showWarn) { - const QString msg = QString("Failed.\n%1\n%2").arg(parameters) - .arg(QString(process->readAllStandardError())); + const QString msg = QString("\n%1").arg(QString(process->readAllStandardError())); QWARN(qUtf8Printable(msg)); } + exitCode = process->exitCode(); return false; } + exitCode = process->exitCode(); delete process; return true; } diff --git a/src/test/ValentinaTest/abstracttest.h b/src/test/ValentinaTest/abstracttest.h index 63ccd3bd4..f4adde6e7 100644 --- a/src/test/ValentinaTest/abstracttest.h +++ b/src/test/ValentinaTest/abstracttest.h @@ -31,6 +31,11 @@ #include +// Return codes for testing run application +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. + class AbstractTest : public QObject { Q_OBJECT @@ -43,7 +48,7 @@ protected: QString ValentinaPath() const; QString TapePath() const; - bool Run(bool showWarn, const QString &program, const QStringList &arguments); + bool Run(bool showWarn, int &exitCode, const QString &program, const QStringList &arguments); bool CopyRecursively(const QString &srcFilePath, const QString &tgtFilePath) const; }; diff --git a/src/test/ValentinaTest/tst_tape/GOST_man_ru.vst b/src/test/ValentinaTest/tst_tape/GOST_man_ru.vst new file mode 100644 index 000000000..def58741e --- /dev/null +++ b/src/test/ValentinaTest/tst_tape/GOST_man_ru.vst @@ -0,0 +1,158 @@ + + + 0.3.0 + Типовые фигуры мужчин 1-й полнотной группы, обхват груди 100 см + 0 + mm + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/test/ValentinaTest/tst_tape/all_measurements.vit b/src/test/ValentinaTest/tst_tape/all_measurements.vit new file mode 100644 index 000000000..4b2412f95 --- /dev/null +++ b/src/test/ValentinaTest/tst_tape/all_measurements.vit @@ -0,0 +1,254 @@ + + + + 0.3.0 + false + + cm + + + + 1990-02-15 + male + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/test/ValentinaTest/tst_tape/all_measurements.vst b/src/test/ValentinaTest/tst_tape/all_measurements.vst new file mode 100644 index 000000000..c94e4bbc3 --- /dev/null +++ b/src/test/ValentinaTest/tst_tape/all_measurements.vst @@ -0,0 +1,249 @@ + + + + 0.4.0 + false + + cm + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/test/ValentinaTest/tst_tape/broken1.vit b/src/test/ValentinaTest/tst_tape/broken1.vit new file mode 100644 index 000000000..dc0353b06 --- /dev/null +++ b/src/test/ValentinaTest/tst_tape/broken1.vit @@ -0,0 +1,19 @@ + + + + 0.3.0 + false + + cm + + + + 1900-01-01 + male + username@example.com + + + + + + diff --git a/src/test/ValentinaTest/tst_tape/broken2.vit b/src/test/ValentinaTest/tst_tape/broken2.vit new file mode 100644 index 000000000..8ea264164 --- /dev/null +++ b/src/test/ValentinaTest/tst_tape/broken2.vit @@ -0,0 +1,18 @@ + + + + 0.3.0 + false + + cm + + + + 1900-01-01 + male + username@example.com + + + + + diff --git a/src/test/ValentinaTest/tst_tape/broken3.vit b/src/test/ValentinaTest/tst_tape/broken3.vit new file mode 100644 index 000000000..7b741e7c2 --- /dev/null +++ b/src/test/ValentinaTest/tst_tape/broken3.vit @@ -0,0 +1,18 @@ + + + + 0.3.0 + false + + cm + + + + 1900-01-01 + male + username@example.com + + + + + diff --git a/src/test/ValentinaTest/tst_tape/broken4.vit b/src/test/ValentinaTest/tst_tape/broken4.vit new file mode 100644 index 000000000..fb1d4adf2 --- /dev/null +++ b/src/test/ValentinaTest/tst_tape/broken4.vit @@ -0,0 +1,18 @@ + + + + 0.3.0 + false + + cm + + + + 1900-01-01 + male + username@example.com + + + + + diff --git a/src/test/ValentinaTest/tst_tape/empty.vit b/src/test/ValentinaTest/tst_tape/empty.vit new file mode 100644 index 000000000..91ed6fefb --- /dev/null +++ b/src/test/ValentinaTest/tst_tape/empty.vit @@ -0,0 +1,16 @@ + + + + 0.3.0 + false + + cm + + + + 1900-01-01 + male + username@example.com + + + diff --git a/src/test/ValentinaTest/tst_tapecommandline.cpp b/src/test/ValentinaTest/tst_tapecommandline.cpp index d72a90cc1..fe0d87126 100644 --- a/src/test/ValentinaTest/tst_tapecommandline.cpp +++ b/src/test/ValentinaTest/tst_tapecommandline.cpp @@ -27,6 +27,7 @@ *************************************************************************/ #include "tst_tapecommandline.h" +#include "../vmisc/vsysexits.h" #include @@ -59,9 +60,48 @@ void TST_TapeCommandLine::OpenMeasurements_data() const { QTest::addColumn("file"); QTest::addColumn("result"); + QTest::addColumn("exitCode"); - QTest::newRow("Send wrong path to file") << "wrongPath.vit" << false; // The file doesn't exist! - QTest::newRow("Old individual format to new version") << "keiko.vit" << true; + // The file doesn't exist! + QTest::newRow("Send wrong path to a file") << "wrongPath.vit" + << false + << V_EX_NOINPUT; + + QTest::newRow("Old individual format to new version") << "keiko.vit" + << true + << V_EX_OK; + + QTest::newRow("Open empty file") << "empty.vit" + << true + << V_EX_OK; + + QTest::newRow("Open a individual measurement file with all know measurements") << "all_measurements.vit" + << true + << V_EX_OK; + + QTest::newRow("Open a standard measurement file with all know measurements") << "all_measurements.vst" + << true + << V_EX_OK; + + QTest::newRow("Open a standard measurement file for man ru GOST.") << "GOST_man_ru.vst" + << true + << V_EX_OK; + + QTest::newRow("Broken file. Not unique name.") << "broken1.vit" + << false + << V_EX_NOINPUT; + + QTest::newRow("Broken file. Measurement name can't be empty.") << "broken1.vit" + << false + << V_EX_NOINPUT; + + QTest::newRow("Broken file. An empty value shouldn't break a file.") << "broken3.vit" + << true + << V_EX_OK; + + QTest::newRow("Broken file. Invalid measurement name.") << "broken4.vit" + << false + << V_EX_NOINPUT; } //--------------------------------------------------------------------------------------------------------------------- @@ -69,11 +109,14 @@ void TST_TapeCommandLine::OpenMeasurements() { QFETCH(QString, file); QFETCH(bool, result); + QFETCH(int, exitCode); - const bool res = Run(result, TapePath(), QStringList() << "--test" + int exit; + const bool res = Run(result, exit, TapePath(), QStringList() << "--test" << QApplication::applicationDirPath() + QLatin1Char('/') + tmpTestFolder + QLatin1Char('/') + file); QCOMPARE(res, result); + QCOMPARE(exit, exitCode); } //---------------------------------------------------------------------------------------------------------------------