swift
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 
11 #include <QDBusConnection>
12 #include <QTest>
13 
14 #include "test.h"
15 
16 #include "misc/dbusutils.h"
17 #include "misc/registermetadata.h"
19 #include "misc/test/testservice.h"
21 
22 using namespace swift::misc;
23 using namespace swift::misc::simulation;
24 using namespace swift::misc::test;
25 
26 namespace MiscTest
27 {
29  class CTestDBus : public QObject
30  {
31  Q_OBJECT
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  {
48  QDBusConnection connection = QDBusConnection::sessionBus();
49  if (!CTestService::canRegisterTestService(connection))
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;
69  s = CDBusUtils::dBusSignature(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
Aircraft model (used by another pilot, my models on disk)
Definition: aircraftmodel.h:71
Comprehensive information of an aircraft.
Value object encapsulating a list of aircraft.
Testservice for PQ / CValueObject DBus tests. This part is the callee.
Definition: testservice.h:65
Proxy class for swift::misc::Test::CTestService. This part is the caller.
Generate data for testing purposes.
Definition: testdata.h:45
Free functions in swift::misc.
void registerMetadata()
Register all relevant metadata in Misc.
SWIFTTEST_MAIN(MiscTest::CTestDBus)
main