From 7af257d552c799c385d40091566fe884ef55cfc2 Mon Sep 17 00:00:00 2001 From: Roman Telezhynskyi Date: Mon, 8 Aug 2022 16:14:46 +0300 Subject: [PATCH] Fix unit tests. --- src/app/puzzle/vpapplication.cpp | 74 +++++++++++++++++++------------- src/app/puzzle/vpapplication.h | 4 +- src/app/tape/mapplication.cpp | 21 ++++++--- src/app/tape/mapplication.h | 4 +- 4 files changed, 64 insertions(+), 39 deletions(-) diff --git a/src/app/puzzle/vpapplication.cpp b/src/app/puzzle/vpapplication.cpp index 5d6b1ef84..8c63b5452 100644 --- a/src/app/puzzle/vpapplication.cpp +++ b/src/app/puzzle/vpapplication.cpp @@ -497,7 +497,12 @@ void VPApplication::ProcessArguments(const VPCommandLinePtr &cmd) { const QStringList rawLayouts = cmd->OptionRawLayouts(); const QStringList args = cmd->OptionFileNames(); - args.count() > 0 ? StartWithFiles(cmd, rawLayouts) : SingleStart(cmd, rawLayouts); + bool success = args.count() > 0 ? StartWithFiles(cmd, rawLayouts) : SingleStart(cmd, rawLayouts); + + if (not success) + { + return; + } if (not cmd->IsGuiEnabled()) { @@ -642,52 +647,59 @@ void VPApplication::StartLocalServer(const QString &serverName) } //--------------------------------------------------------------------------------------------------------------------- -void VPApplication::StartWithFiles(const VPCommandLinePtr &cmd, const QStringList &rawLayouts) +auto VPApplication::StartWithFiles(const VPCommandLinePtr &cmd, const QStringList &rawLayouts) -> bool { const QStringList args = cmd->OptionFileNames(); - if (args.count() > 0) + + if (args.count() <= 0) { - if (not cmd->IsGuiEnabled() && args.count() > 1) + QCoreApplication::exit(V_EX_DATAERR); + return false; + } + + if (not cmd->IsGuiEnabled() && args.count() > 1) + { + qCCritical(pApp, "%s\n", qPrintable(tr("Export mode doesn't support opening several files."))); + cmd.get()->parser.showHelp(V_EX_USAGE); + } + + if (args.count() > 1 && not rawLayouts.isEmpty()) + { + qCCritical(pApp, "%s\n", + qPrintable(tr("Import raw layout data does not support opening several layout files."))); + cmd.get()->parser.showHelp(V_EX_USAGE); + } + + for (const auto &arg : args) + { + NewMainWindow(cmd); + if (not MainWindow()->LoadFile(arg)) { - qCCritical(pApp, "%s\n", qPrintable(tr("Export mode doesn't support opening several files."))); - cmd.get()->parser.showHelp(V_EX_USAGE); + if (not cmd->IsGuiEnabled()) + { + return false; // process only one input file + } + delete MainWindow(); + continue; } - if (args.count() > 1 && not rawLayouts.isEmpty()) + if (not rawLayouts.isEmpty()) { - qCCritical(pApp, "%s\n", - qPrintable(tr("Import raw layout data does not support opening several layout files."))); - cmd.get()->parser.showHelp(V_EX_USAGE); - } - - for (const auto &arg : args) - { - NewMainWindow(cmd); - if (not MainWindow()->LoadFile(arg)) - { - if (not cmd->IsGuiEnabled()) - { - return; // process only one input file - } - delete MainWindow(); - continue; - } - - if (not rawLayouts.isEmpty()) - { - MainWindow()->ImportRawLayouts(rawLayouts); - } + MainWindow()->ImportRawLayouts(rawLayouts); } } + + return true; } //--------------------------------------------------------------------------------------------------------------------- -void VPApplication::SingleStart(const VPCommandLinePtr &cmd, const QStringList &rawLayouts) +auto VPApplication::SingleStart(const VPCommandLinePtr &cmd, const QStringList &rawLayouts) -> bool { if (cmd->IsTestModeEnabled()) { qCCritical(pApp, "%s\n", qPrintable(tr("Please, provide one input file."))); cmd.get()->parser.showHelp(V_EX_USAGE); + return false; } NewMainWindow(cmd); @@ -695,6 +707,8 @@ void VPApplication::SingleStart(const VPCommandLinePtr &cmd, const QStringList & { MainWindow()->ImportRawLayouts(rawLayouts); } + + return true; } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/app/puzzle/vpapplication.h b/src/app/puzzle/vpapplication.h index 47d6b0159..a079811cc 100644 --- a/src/app/puzzle/vpapplication.h +++ b/src/app/puzzle/vpapplication.h @@ -96,8 +96,8 @@ private: void StartLocalServer(const QString &serverName); - void StartWithFiles(const VPCommandLinePtr &cmd, const QStringList &rawLayouts); - void SingleStart(const VPCommandLinePtr &cmd, const QStringList &rawLayouts); + auto StartWithFiles(const VPCommandLinePtr &cmd, const QStringList &rawLayouts) -> bool; + auto SingleStart(const VPCommandLinePtr &cmd, const QStringList &rawLayouts) -> bool; }; #endif // VPAPPLICATION_H diff --git a/src/app/tape/mapplication.cpp b/src/app/tape/mapplication.cpp index 20a6c0a50..ee4d4d8a3 100644 --- a/src/app/tape/mapplication.cpp +++ b/src/app/tape/mapplication.cpp @@ -666,7 +666,12 @@ void MApplication::ParseCommandLine(const SocketConnection &connection, const QS } const QStringList args = parser.positionalArguments(); - args.count() > 0 ? StartWithFiles(parser) : SingleStart(parser); + bool success = args.count() > 0 ? StartWithFiles(parser) : SingleStart(parser); + + if (not success) + { + return; + } if (m_testMode) { @@ -792,12 +797,13 @@ void MApplication::StartLocalServer(const QString &serverName) } //--------------------------------------------------------------------------------------------------------------------- -void MApplication::StartWithFiles(QCommandLineParser &parser) +auto MApplication::StartWithFiles(QCommandLineParser &parser) -> bool { const QStringList args = parser.positionalArguments(); if (args.count() <= 0) { - return; + QCoreApplication::exit(V_EX_DATAERR); + return false; } if (m_testMode && args.count() > 1) @@ -828,7 +834,7 @@ void MApplication::StartWithFiles(QCommandLineParser &parser) { if (m_testMode) { - return; // process only one input file + return false; // process only one input file } delete MainWindow(); continue; @@ -854,10 +860,12 @@ void MApplication::StartWithFiles(QCommandLineParser &parser) MainWindow()->SetPUnit(unit); } } + + return true; } //--------------------------------------------------------------------------------------------------------------------- -void MApplication::SingleStart(QCommandLineParser &parser) +auto MApplication::SingleStart(QCommandLineParser &parser) -> bool { if (not m_testMode) { @@ -867,7 +875,10 @@ void MApplication::SingleStart(QCommandLineParser &parser) { qCCritical(mApp, "%s\n", qPrintable(tr("Please, provide one input file."))); parser.showHelp(V_EX_USAGE); + return false; } + + return true; } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/app/tape/mapplication.h b/src/app/tape/mapplication.h index d07f31cfc..51a0a6b70 100644 --- a/src/app/tape/mapplication.h +++ b/src/app/tape/mapplication.h @@ -101,8 +101,8 @@ private: static void InitParserOptions(QCommandLineParser &parser); void StartLocalServer(const QString &serverName); - void StartWithFiles(QCommandLineParser &parser); - void SingleStart(QCommandLineParser &parser); + auto StartWithFiles(QCommandLineParser &parser) -> bool; + auto SingleStart(QCommandLineParser &parser) -> bool; static void ParseDimensionAOption(QCommandLineParser &parser, int &dimensionAValue, bool &flagDimensionA); static void ParseDimensionBOption(QCommandLineParser &parser, int &dimensionBValue, bool &flagDimensionB);