Initial commit

This commit is contained in:
torsten committed 2026-08-13 18:33:10 +02:00
commit b7d90b9afe
16245 files changed
+3396666

No files matched your search

+151
View File
@@ -0,0 +1,151 @@
/**
* @RDE_HEADER@
* unit test main
* $Id$
* $HeadURL$
* $Author$
* Created by Christian Fröbel, SLSE, 2017-06-19
*/
#include "parse_line_test.h"
#include "ava_comm_test.h"
#include "ava_control_test.h"
#include "av_helper_test.h"
#include "asset_assignment_manager_test.h"
#include "audio_video_handler_impl_test.h"
#include "choose_stream_test.h"
#include "ava_timeline_test.h"
#include "avs_command_queue_test.h"
#include "rt_state_test.h"
#include "list_response_collector_test.h"
#include <nglapplication/nglcoreapplication.h>
#include <QtTest/QtTest>
#include <QCommandLineParser>
#include <QCommandLineOption>
#include <QStringList>
#include <map>
#include <functional>
#include <memory>
#include <algorithm>
#include <iterator>
#include <iostream>
using namespace AudioVideoManagement;
namespace
{
QStringList toStringList(int argc, char **argv)
{
QStringList options;
options.reserve(argc);
for (int i = 0; i < argc; ++i)
options.append(QString::fromUtf8(argv[i]));
return options;
}
QStringList removeParsedArgs(const QStringList &args)
{
QStringList reducedArgs = {args.front()};
auto separatorPos = std::find(args.begin(), args.end(), QStringLiteral("--"));
if (separatorPos == args.end())
return reducedArgs;
++separatorPos;
std::copy(separatorPos, args.end(), std::back_inserter(reducedArgs));
return reducedArgs;
}
/**
* Maps the name of the test class to an instance of it.
*/
using TestMap = std::map<QString, std::unique_ptr<QObject>>;
template<class Test>
void addTest(TestMap& tests)
{
std::unique_ptr<QObject> test(new Test);
auto result = tests.insert(std::make_pair(QString::fromUtf8(test->metaObject()->className()), std::move(test)));
Q_ASSERT(result.second);
}
/**
* Instantiate all test classes and return them.
* Every new test class needs to be added here.
*/
TestMap allTests()
{
TestMap tests;
addTest<ParseLineTest>(tests);
addTest<AvaCommTest>(tests);
addTest<AvaControlTest>(tests);
addTest<AvHelperTest>(tests);
addTest<AssetAssignmentManagerTest>(tests);
addTest<AudioVideoHandlerImplTest>(tests);
addTest<ChooseStreamTest>(tests);
addTest<AvsCommandQueueTest>(tests);
addTest<AvaTimelineTest>(tests);
addTest<RtStateTest>(tests);
addTest<ListResponseCollectorTest>(tests);
return tests;
}
int runTests(const QStringList &selectedTests, const TestMap &allTests, const QStringList &args)
{
int result = 0;
for (const QString &testName : selectedTests)
{
auto found = allTests.find(testName);
if (found == allTests.end())
{
std::cout << "Unknown test: " << testName.toUtf8().constData() << std::endl;
result = 1;
continue;
}
QObject* test = found->second.get();
result |= QTest::qExec(test, args);
}
return result;
}
int runAllTests(const TestMap &allTests, const QStringList &args)
{
QStringList allTestNames;
allTestNames.reserve(allTests.size());
for (const auto &test: allTests)
allTestNames.append(test.first);
return runTests(allTestNames, allTests, args);
}
} // anonymous namespace
int main(int argc, char **argv)
{
int fakeArgc = 1;
NGLCoreApplication app(fakeArgc, argv);
app.createLogger("AVM", "log4cxx_avmTests.props");
// Before passing the command line arguments to QTest::qExec() we do some parsing ourselves.
// The problem is that QTest conceptionally only allows one instance of a single test class.
// As we want to instantiate and test more than one test class, we offer a command line option
// to select one or more test classes to run: -t <TestClass>.
// Other options which shall be passed to QTest::qExec() must come after -t-options and
// an explicit '--' separator.
QCommandLineParser parser;
parser.setSingleDashWordOptionMode(QCommandLineParser::ParseAsLongOptions);
QCommandLineOption selectTestOption(QStringList{QStringLiteral("t"), QStringLiteral("test")}, QStringLiteral("Test-class to run"), QStringLiteral("test"));
parser.addOption(selectTestOption);
QStringList commandLineArgs = toStringList(argc, argv);
(void) parser.parse(commandLineArgs);
QStringList reducedCommandLineArgs = removeParsedArgs(commandLineArgs);
if (parser.isSet(selectTestOption))
{
QStringList selectedTests = parser.values(selectTestOption.valueName());
return runTests(selectedTests, allTests(), reducedCommandLineArgs);
}
return runAllTests(allTests(), reducedCommandLineArgs);
}