1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
|
/**
* Copyright (c) 2020-2025 Governikus GmbH & Co. KG, Germany
*/
#include <QProcess>
#include <QtTest>
using namespace Qt::Literals::StringLiterals;
class test_CommandLineParser
: public QObject
{
Q_OBJECT
private:
static const int PROCESS_TIMEOUT = 30000;
private Q_SLOTS:
void checkHelp()
{
#ifdef Q_OS_WIN
QSKIP("Windows uses console or a dialog and won't be tested");
#endif
const QString& path = QStringLiteral(AUSWEISAPP_BINARY_DIR);
const QString& app = path + "AusweisApp"_L1;
QStringList args;
args << "--help"_L1;
args << "-platform"_L1 << "offscreen"_L1;
QProcess process;
process.setProgram(app);
process.setWorkingDirectory(path);
process.setArguments(args);
process.start();
QVERIFY(process.waitForFinished(PROCESS_TIMEOUT));
QStringList out;
out << QStringLiteral("Usage: %1 [options]").arg(app);
out << QString();
out << QStringLiteral("Options:");
out << QStringLiteral(" -h, --help Displays help on commandline options.");
out << QStringLiteral(" --help-all Displays help, including generic Qt options.");
out << QStringLiteral(" -v, --version Displays version information.");
out << QStringLiteral(" --keep Keep logfile.");
out << QStringLiteral(" --no-logfile Disable logfile.");
out << QStringLiteral(" --no-loghandler Disable default log handler.");
out << QStringLiteral(" --show Show window on startup.");
out << QStringLiteral(" --no-proxy Ignore proxy settings.");
out << QStringLiteral(" --ui <qml,webservice,websocket> Use given UI plugin.");
out << QStringLiteral(" --port <24727> Use listening port.");
out << QStringLiteral(" --address <127.0.0.1,::1> Use address binding.");
out << QString();
const auto& standardOut = process.readAllStandardOutput();
const auto& expected = out.join('\n'_L1).toLocal8Bit();
// helps to debug if QCOMPARE fails
qDebug().noquote() << '\n' << standardOut;
qDebug().noquote() << '\n' << expected;
QCOMPARE(process.exitStatus(), QProcess::NormalExit);
QCOMPARE(standardOut, expected);
QCOMPARE(process.readAllStandardError(), QByteArray());
}
};
QTEST_GUILESS_MAIN(test_CommandLineParser)
#include "test_CommandLineParser.moc"
|