swift
Loading...
Searching...
No Matches
testdbus.cpp
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (C) 2017 swift Project Community / Contributors
2// SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-swift-pilot-client-1
3
5
10
11#include <QDBusConnection>
12#include <QTest>
13
14#include "test.h"
15
16#include "misc/dbusutils.h"
21
22using namespace swift::misc;
23using namespace swift::misc::simulation;
24using namespace swift::misc::test;
25
26namespace MiscTest
27{
29 class CTestDBus : public QObject
30 {
32
33 private slots:
35 void initTestCase();
36
38 void marshallUnmarshall();
39
41 void signatureSize();
42 };
43
44 void CTestDBus::initTestCase() { swift::misc::registerMetadata(); }
45
46 void CTestDBus::marshallUnmarshall()
47 {
50 {
51 QSKIP("Cannot register DBus service, skip unit test");
52 return;
53 }
54 CTestService *testService = CTestService::registerTestService(connection, false, QCoreApplication::instance());
55 Q_UNUSED(testService);
56 ITestServiceInterface testServiceInterface(CTestService::InterfaceName(), CTestService::ObjectPath(),
57 connection);
58 const int errors = ITestServiceInterface::pingTests(testServiceInterface, false);
59 QVERIFY2(errors == 0, "DBus Ping tests fail");
60 }
61
62 void CTestDBus::signatureSize()
63 {
64 constexpr int max = 255;
65 QString s;
66
67 // normally CSimulatedAircraftList is expected to be the biggest one
68 const CAircraftModel model;
70 QVERIFY2(s.length() <= max, "Signature CAircraftModel");
71
72 const CSimulatedAircraft aircraft;
73 s = CDBusUtils::dBusSignature(aircraft);
74 QVERIFY2(s.length() <= max, "Signature CSimulatedAircraft");
75
76 const CSimulatedAircraftList al;
78 QVERIFY2(s.length() <= max, "Signature CSimulatedAircraftList");
79 }
80} // namespace MiscTest
81
84
85#include "testdbus.moc"
86
DBus implementation classes tests.
Definition testdbus.cpp:30
static QString dBusSignature(const ValueObj &obj)
Signature for swift::misc::CValueObject.
Definition dbusutils.h:25
static bool canRegisterTestService(QDBusConnection &connection)
Can the testservice be registered?
static const QString & InterfaceName()
DBus interface name.
static const QString & ObjectPath()
DBus object path.
static CTestService * registerTestService(QDBusConnection &connection, bool verbose, QObject *parent=nullptr)
Register testservice with connection.
static int pingTests(ITestServiceInterface &testServiceInterface, bool verbose)
Ping via DBus, tests object marshalling/unmarshalling.
Generate data for testing purposes.
Definition testdata.h:45
Free functions in swift::misc.
void registerMetadata()
Register all relevant metadata in Misc.
QCoreApplication * instance()
QDBusConnection sessionBus()
QObject(QObject *parent)
Q_OBJECTQ_OBJECT
qsizetype length() const const
QVERIFY2(condition, message)
#define SWIFTTEST_MAIN(TestObject)
Implements a main() function that executes all tests in TestObject including instantiating a QCoreApp...
Definition test.h:57