Fix unit tests.

This commit is contained in:
Roman Telezhynskyi 2022-08-08 16:14:46 +03:00
parent 4e07172a6f
commit 7af257d552
4 changed files with 64 additions and 39 deletions

View File

@ -497,7 +497,12 @@ void VPApplication::ProcessArguments(const VPCommandLinePtr &cmd)
{ {
const QStringList rawLayouts = cmd->OptionRawLayouts(); const QStringList rawLayouts = cmd->OptionRawLayouts();
const QStringList args = cmd->OptionFileNames(); 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()) if (not cmd->IsGuiEnabled())
{ {
@ -642,11 +647,16 @@ 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(); const QStringList args = cmd->OptionFileNames();
if (args.count() > 0)
if (args.count() <= 0)
{ {
QCoreApplication::exit(V_EX_DATAERR);
return false;
}
if (not cmd->IsGuiEnabled() && args.count() > 1) if (not cmd->IsGuiEnabled() && args.count() > 1)
{ {
qCCritical(pApp, "%s\n", qPrintable(tr("Export mode doesn't support opening several files."))); qCCritical(pApp, "%s\n", qPrintable(tr("Export mode doesn't support opening several files.")));
@ -667,7 +677,7 @@ void VPApplication::StartWithFiles(const VPCommandLinePtr &cmd, const QStringLis
{ {
if (not cmd->IsGuiEnabled()) if (not cmd->IsGuiEnabled())
{ {
return; // process only one input file return false; // process only one input file
} }
delete MainWindow(); delete MainWindow();
continue; continue;
@ -678,16 +688,18 @@ void VPApplication::StartWithFiles(const VPCommandLinePtr &cmd, const QStringLis
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()) if (cmd->IsTestModeEnabled())
{ {
qCCritical(pApp, "%s\n", qPrintable(tr("Please, provide one input file."))); qCCritical(pApp, "%s\n", qPrintable(tr("Please, provide one input file.")));
cmd.get()->parser.showHelp(V_EX_USAGE); cmd.get()->parser.showHelp(V_EX_USAGE);
return false;
} }
NewMainWindow(cmd); NewMainWindow(cmd);
@ -695,6 +707,8 @@ void VPApplication::SingleStart(const VPCommandLinePtr &cmd, const QStringList &
{ {
MainWindow()->ImportRawLayouts(rawLayouts); MainWindow()->ImportRawLayouts(rawLayouts);
} }
return true;
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------

View File

@ -96,8 +96,8 @@ private:
void StartLocalServer(const QString &serverName); void StartLocalServer(const QString &serverName);
void StartWithFiles(const VPCommandLinePtr &cmd, const QStringList &rawLayouts); auto StartWithFiles(const VPCommandLinePtr &cmd, const QStringList &rawLayouts) -> bool;
void SingleStart(const VPCommandLinePtr &cmd, const QStringList &rawLayouts); auto SingleStart(const VPCommandLinePtr &cmd, const QStringList &rawLayouts) -> bool;
}; };
#endif // VPAPPLICATION_H #endif // VPAPPLICATION_H

View File

@ -666,7 +666,12 @@ void MApplication::ParseCommandLine(const SocketConnection &connection, const QS
} }
const QStringList args = parser.positionalArguments(); 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) 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(); const QStringList args = parser.positionalArguments();
if (args.count() <= 0) if (args.count() <= 0)
{ {
return; QCoreApplication::exit(V_EX_DATAERR);
return false;
} }
if (m_testMode && args.count() > 1) if (m_testMode && args.count() > 1)
@ -828,7 +834,7 @@ void MApplication::StartWithFiles(QCommandLineParser &parser)
{ {
if (m_testMode) if (m_testMode)
{ {
return; // process only one input file return false; // process only one input file
} }
delete MainWindow(); delete MainWindow();
continue; continue;
@ -854,10 +860,12 @@ void MApplication::StartWithFiles(QCommandLineParser &parser)
MainWindow()->SetPUnit(unit); MainWindow()->SetPUnit(unit);
} }
} }
return true;
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
void MApplication::SingleStart(QCommandLineParser &parser) auto MApplication::SingleStart(QCommandLineParser &parser) -> bool
{ {
if (not m_testMode) if (not m_testMode)
{ {
@ -867,7 +875,10 @@ void MApplication::SingleStart(QCommandLineParser &parser)
{ {
qCCritical(mApp, "%s\n", qPrintable(tr("Please, provide one input file."))); qCCritical(mApp, "%s\n", qPrintable(tr("Please, provide one input file.")));
parser.showHelp(V_EX_USAGE); parser.showHelp(V_EX_USAGE);
return false;
} }
return true;
} }
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------

View File

@ -101,8 +101,8 @@ private:
static void InitParserOptions(QCommandLineParser &parser); static void InitParserOptions(QCommandLineParser &parser);
void StartLocalServer(const QString &serverName); void StartLocalServer(const QString &serverName);
void StartWithFiles(QCommandLineParser &parser); auto StartWithFiles(QCommandLineParser &parser) -> bool;
void SingleStart(QCommandLineParser &parser); auto SingleStart(QCommandLineParser &parser) -> bool;
static void ParseDimensionAOption(QCommandLineParser &parser, int &dimensionAValue, bool &flagDimensionA); static void ParseDimensionAOption(QCommandLineParser &parser, int &dimensionAValue, bool &flagDimensionA);
static void ParseDimensionBOption(QCommandLineParser &parser, int &dimensionBValue, bool &flagDimensionB); static void ParseDimensionBOption(QCommandLineParser &parser, int &dimensionBValue, bool &flagDimensionB);