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 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;
}
//---------------------------------------------------------------------------------------------------------------------

View File

@ -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

View File

@ -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;
}
//---------------------------------------------------------------------------------------------------------------------

View File

@ -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);