Restore in-scope files missing from the merge and scope-aware CMakeLists
The merge from story/release-validation-scope only carried files that existed at the common base or on that branch. In-scope files added on story/release-2-cleanup after the base (per-module unit-test dirs, the Release 2 driver and rpmbuild script) were missing, breaking ADD_SUBDIRECTORY(unit-test) references. - Restore the 33 missing in-scope files from story/release-2-cleanup. - Lts/Common/CMakeLists.txt and LtsUtilsGui/CMakeLists.txt: take the story/release-2-cleanup versions (the validation versions still reference out-of-scope subdirectories: httq, LtsRestClient, LtsWebSocket, ConnectDialog, StyleManager).
This commit is contained in:
1 parent
cfe15c72c4
commit
262fd226f9
35 files changed
+6856
-16
No files matched your search
+29
@@ -0,0 +1,29 @@
|
||||
#
|
||||
# Unit tests for the LtsCommandLineParser module.
|
||||
# One test executable per module, each registered with ctest.
|
||||
#
|
||||
if (NOT BUILD_TESTING)
|
||||
return()
|
||||
endif()
|
||||
|
||||
# --- LtsCommandLineParser: option registration, parsing, domain id handling
|
||||
if (TARGET LtsCommandLineParser)
|
||||
# probe helper: runs init() with a real command line (QtTest's main cannot
|
||||
# forward CLI options); used by iniFileProvidesDomainId
|
||||
ADD_EXECUTABLE(commandlineparser_ini_probe commandlineparser_ini_probe.cpp)
|
||||
TARGET_LINK_LIBRARIES(commandlineparser_ini_probe
|
||||
LtsCommandLineParser
|
||||
Qt6::Core
|
||||
)
|
||||
|
||||
ADD_EXECUTABLE(commandlineparser_unit_test commandlineparser_unit_test.cpp)
|
||||
ADD_DEPENDENCIES(commandlineparser_unit_test commandlineparser_ini_probe)
|
||||
TARGET_COMPILE_DEFINITIONS(commandlineparser_unit_test PRIVATE
|
||||
INI_PROBE_EXE="$<TARGET_FILE:commandlineparser_ini_probe>")
|
||||
TARGET_LINK_LIBRARIES(commandlineparser_unit_test
|
||||
LtsCommandLineParser
|
||||
Qt6::Core
|
||||
Qt6::Test
|
||||
)
|
||||
ADD_TEST(NAME commandlineparser_unit_test COMMAND $<TARGET_FILE:commandlineparser_unit_test>)
|
||||
endif()
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
/**
|
||||
* @RDE_HEADER@
|
||||
* Helper probe for the LtsCommandLineParser unit test: runs init() with the
|
||||
* real command line (QTest's main cannot forward CLI options) and reports
|
||||
* the resulting domain id.
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
*/
|
||||
|
||||
#include <QtCore/QCoreApplication>
|
||||
|
||||
#include <LtsCommandLineParser/LtsCommandLineParser.h>
|
||||
|
||||
#include <cstdio>
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
QCoreApplication app(argc, argv);
|
||||
|
||||
LtsCommandLineParser::LtsCommandLineParser parser;
|
||||
parser.setUnitModuleTestMode(true);
|
||||
if (!parser.init(false))
|
||||
{
|
||||
std::printf("INIT_FAIL\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
std::printf("DOMAINID=%d\n", parser.domainId());
|
||||
return 0;
|
||||
}
|
||||
+173
@@ -0,0 +1,173 @@
|
||||
/**
|
||||
* @RDE_HEADER@
|
||||
* Unittest
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
*/
|
||||
|
||||
#include <QtTest/QTest>
|
||||
|
||||
#include <LtsCommandLineParser/LtsCommandLineParser.h>
|
||||
|
||||
#include <QtCore/QDir>
|
||||
#include <QtCore/QProcess>
|
||||
#include <QtCore/QSettings>
|
||||
#include <QtCore/QTemporaryDir>
|
||||
#include <QtCore/QUrl>
|
||||
|
||||
class commandlineparser_unit_test : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
private Q_SLOTS:
|
||||
void optionDefaults();
|
||||
void parseWithOptions();
|
||||
void tcpConnectionUrl();
|
||||
void setDomainIdOverridesGenerated();
|
||||
void domainIdFallbackRange();
|
||||
void initCleanRun();
|
||||
void iniFileProvidesDomainId();
|
||||
void unknownOptionBehaviour();
|
||||
};
|
||||
|
||||
using Lcp = LtsCommandLineParser::LtsCommandLineParser;
|
||||
|
||||
void commandlineparser_unit_test::optionDefaults()
|
||||
{
|
||||
Lcp parser;
|
||||
// nothing parsed yet
|
||||
QVERIFY(!parser.domainIdProvided());
|
||||
QVERIFY(!parser.exerciseIdProvided());
|
||||
QVERIFY(!parser.iniFileSet());
|
||||
QVERIFY(!parser.useTcpConnection());
|
||||
QVERIFY(!parser.tcpConnectionUrl().isValid());
|
||||
QCOMPARE(parser.exerciseId(), 0);
|
||||
QCOMPARE(parser.iniFile(), QString());
|
||||
}
|
||||
|
||||
void commandlineparser_unit_test::parseWithOptions()
|
||||
{
|
||||
Lcp parser(Lcp::ProvideCommandLineParameterOptions(
|
||||
Lcp::DomainId | Lcp::ExerciseId | Lcp::CustomConfigFile | Lcp::TcpConnectionUrl));
|
||||
const bool ok = parser.parse({
|
||||
QStringLiteral("prog"),
|
||||
QStringLiteral("-d"), QStringLiteral("42"),
|
||||
QStringLiteral("-e"), QStringLiteral("7"),
|
||||
QStringLiteral("-i"), QStringLiteral("/tmp/lts-cc.conf"),
|
||||
QStringLiteral("-t"), QStringLiteral("tcpv4_lan://10.0.0.1:7400")
|
||||
});
|
||||
QVERIFY(ok);
|
||||
QVERIFY(parser.domainIdProvided());
|
||||
QVERIFY(parser.exerciseIdProvided());
|
||||
QVERIFY(parser.iniFileSet());
|
||||
QVERIFY(parser.useTcpConnection());
|
||||
}
|
||||
|
||||
void commandlineparser_unit_test::tcpConnectionUrl()
|
||||
{
|
||||
// the tcpv4_lan scheme is canonicalized to tcpv4lan
|
||||
{
|
||||
Lcp parser(Lcp::ProvideCommandLineParameterOptions(Lcp::TcpConnectionUrl));
|
||||
QVERIFY(parser.parse({
|
||||
QStringLiteral("prog"),
|
||||
QStringLiteral("-t"), QStringLiteral("tcpv4_lan://10.0.0.1:7400")
|
||||
}));
|
||||
const QUrl url = parser.tcpConnectionUrl();
|
||||
QCOMPARE(url.scheme(), QStringLiteral("tcpv4lan"));
|
||||
QCOMPARE(url.host(), QStringLiteral("10.0.0.1"));
|
||||
QCOMPARE(url.port(), 7400);
|
||||
}
|
||||
|
||||
// http/file input is rewritten to the tcpv4lan scheme
|
||||
{
|
||||
Lcp parser(Lcp::ProvideCommandLineParameterOptions(Lcp::TcpConnectionUrl));
|
||||
QVERIFY(parser.parse({
|
||||
QStringLiteral("prog"),
|
||||
QStringLiteral("-t"), QStringLiteral("http://192.168.0.2:7500")
|
||||
}));
|
||||
QCOMPARE(parser.tcpConnectionUrl().scheme(), QStringLiteral("tcpv4lan"));
|
||||
}
|
||||
|
||||
// without the option enabled the URL is never returned
|
||||
{
|
||||
Lcp parser(Lcp::ProvideCommandLineParameterOptions(Lcp::DomainId));
|
||||
const QUrl url = parser.tcpConnectionUrl();
|
||||
QVERIFY(!url.isValid());
|
||||
QVERIFY(!parser.useTcpConnection());
|
||||
}
|
||||
}
|
||||
|
||||
void commandlineparser_unit_test::setDomainIdOverridesGenerated()
|
||||
{
|
||||
Lcp parser;
|
||||
parser.setDomainId(7);
|
||||
// the function-set id is always returned, never the IP-generated fallback
|
||||
QCOMPARE(parser.domainId(), 7);
|
||||
}
|
||||
|
||||
void commandlineparser_unit_test::domainIdFallbackRange()
|
||||
{
|
||||
// without an explicit id the parser falls back to the id generated from
|
||||
// the local IPv4 address (or 0 when none is found)
|
||||
Lcp parser;
|
||||
const int id = parser.domainId();
|
||||
QVERIFY2(id >= 0 && id <= 232,
|
||||
qPrintable(QStringLiteral("domainId() fallback out of range: %1").arg(id)));
|
||||
}
|
||||
|
||||
void commandlineparser_unit_test::initCleanRun()
|
||||
{
|
||||
// init() parses the test executable's own argument list (program name
|
||||
// only under ctest) and succeeds
|
||||
Lcp parser;
|
||||
QVERIFY(parser.init(false));
|
||||
}
|
||||
|
||||
void commandlineparser_unit_test::iniFileProvidesDomainId()
|
||||
{
|
||||
// init() re-parses the application's own argument list and QCommandLineParser
|
||||
// resets the option state on every parse, so -i can only reach it through the
|
||||
// process argv. QtTest's main cannot forward CLI options, so the (non-QtTest)
|
||||
// probe executable runs init() with a real command line instead.
|
||||
// The ini file is created under the working directory (rather than the
|
||||
// default /tmp) so the test is independent of /tmp's state.
|
||||
QTemporaryDir tmp(QDir::current().absolutePath() + QStringLiteral("/lcp_ut_XXXXXX"));
|
||||
QVERIFY(tmp.isValid());
|
||||
const QString iniFile = tmp.path() + QStringLiteral("/lts-cc.conf");
|
||||
{
|
||||
QSettings s(iniFile, QSettings::IniFormat);
|
||||
s.setValue(QStringLiteral("Global/DomainId"), 7);
|
||||
s.sync();
|
||||
}
|
||||
|
||||
QProcess proc;
|
||||
proc.start(QStringLiteral(INI_PROBE_EXE), { QStringLiteral("-i"), iniFile });
|
||||
QVERIFY(proc.waitForFinished(10000));
|
||||
const QByteArray out = proc.readAllStandardOutput();
|
||||
// no -d given: the domain id is read from the ini file
|
||||
QVERIFY2(out.contains(QByteArrayLiteral("DOMAINID=7")),
|
||||
qPrintable(QString::fromUtf8(out)));
|
||||
}
|
||||
|
||||
void commandlineparser_unit_test::unknownOptionBehaviour()
|
||||
{
|
||||
// the version option is registered unless NoVersion is set
|
||||
Lcp withVersion;
|
||||
QVERIFY(withVersion.parse({ QStringLiteral("prog"), QStringLiteral("-v") }));
|
||||
QVERIFY(withVersion.isSet(QStringLiteral("v")));
|
||||
|
||||
// with NoVersion, -v is not registered and parsing fails
|
||||
Lcp strict(Lcp::NoVersion);
|
||||
QVERIFY(!strict.parse({ QStringLiteral("prog"), QStringLiteral("-v") }));
|
||||
|
||||
// the help option is always registered
|
||||
Lcp parser;
|
||||
parser.setUnitModuleTestMode(true);
|
||||
QVERIFY(parser.parse({ QStringLiteral("prog"), QStringLiteral("-h") }));
|
||||
QVERIFY(parser.isSet(QStringLiteral("h")));
|
||||
}
|
||||
|
||||
QTEST_MAIN(commandlineparser_unit_test)
|
||||
|
||||
#include "commandlineparser_unit_test.moc"
|
||||
Reference in new issue
Block a user