refs #875, refs #879, renamed CTestUtils to CDBusUtils

* class now only contains DBus related code
* other functions have been moved to CTesting
This commit is contained in:
Klaus Basan
2017-02-11 13:00:20 +01:00
committed by Mathew Sutcliffe
parent d1827bd162
commit dc1d5d8586
8 changed files with 157 additions and 165 deletions

View File

@@ -13,7 +13,7 @@
#include "blackmisc/dbusserver.h"
#include "blackmisc/registermetadata.h"
#include "blackmisc/network/networkutils.h"
#include "blackmisc/test/testutils.h"
#include "blackmisc/dbusutils.h"
#include "servicetool.h"
#include <stdio.h>
#include <QCoreApplication>
@@ -132,7 +132,7 @@ int main(int argc, char *argv[])
if (mode.startsWith("2"))
{
out << "---------------------------------" << endl;
BlackMisc::Test::CTestUtils::showDBusSignatures(out);
BlackMisc::CDBusUtils::showDBusSignatures(out);
out << "---------------------------------" << endl;
goto Menu;
}

View File

@@ -14,7 +14,6 @@
#include "blackcore/application.h"
#include "blackmisc/test/testservice.h"
#include "blackmisc/test/testserviceinterface.h"
#include "blackmisc/test/testutils.h"
#include "blackmisc/dbusserver.h"
#include "blackmisc/network/server.h"

105
src/blackmisc/dbusutils.cpp Normal file
View File

@@ -0,0 +1,105 @@
/* Copyright (C) 2017
* swift Project Community / Contributors
*
* This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level
* directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project,
* including this file, may be copied, modified, propagated, or distributed except according to the terms
* contained in the LICENSE file.
*/
#include "dbusutils.h"
#include "blackmisc/simulation/simulatedaircraftlist.h"
#include "blackmisc/aviation/airport.h"
#include <QString>
#include <QStringBuilder>
#include <QVariant>
using namespace BlackMisc;
using namespace BlackMisc::Aviation;
using namespace BlackMisc::Geo;
using namespace BlackMisc::Network;
using namespace BlackMisc::PhysicalQuantities;
using namespace BlackMisc::Simulation;
namespace BlackMisc
{
QString CDBusUtils::getQDBusArgumentSignature(const QDBusArgument &arg, int level)
{
arg.beginArray();
QVariant qv;
const QString indent(level * 2, ' ');
QString out;
while (!arg.atEnd())
{
const QString type = CDBusUtils::dbusTypeAsString(arg.currentType());
const QString signature = arg.currentSignature();
qv = arg.asVariant(); // this advances in the stream
if (qv.canConvert<QDBusArgument>())
{
out += indent % type % QLatin1Literal("signature ") % signature % QLatin1Char('\n');
out += CDBusUtils::getQDBusArgumentSignature(qv.value<QDBusArgument>(), level + 1) % QLatin1Char('\n');
}
else
{
out += indent % QLatin1Literal("type: ") % type % QLatin1Literal("signature ") % signature % QLatin1Literal(" value ") % qv.toString() % QLatin1Char('\n');
}
}
arg.endArray();
return out;
}
QString CDBusUtils::dbusTypeAsString(QDBusArgument::ElementType type)
{
switch (type)
{
case QDBusArgument::BasicType: return QLatin1Literal("BasicType");
case QDBusArgument::VariantType: return QLatin1Literal("VariantType");
case QDBusArgument::ArrayType: return QLatin1Literal("ArrayType");
case QDBusArgument::StructureType: return QLatin1Literal("StructureType");
case QDBusArgument::MapType: return QLatin1Literal("MapType");
case QDBusArgument::MapEntryType: return QLatin1Literal("MapEntryType");
case QDBusArgument::UnknownType:
default:
return QLatin1Literal("Unknown type");
}
}
void CDBusUtils::showDBusSignatures(QTextStream &out)
{
const CCallsign cs;
const CLength l;
const CAircraftIcaoCode icao;
const CAircraftModel model;
const CCountry country;
const CAirportIcaoCode airportIcao;
const CLivery livery;
const CAirport airport;
const CSimulatedAircraft aircraft;
const CSimulatedAircraftList aircraftList;
const CVariant var;
QString s;
s = CDBusUtils::dBusSignature(cs);
out << "CCallsign" << " size: " << s.size() << " sig: " << s << endl;
s = CDBusUtils::dBusSignature(l);
out << "CLength" << " size: " << s.size() << " sig: " << s << endl;
s = CDBusUtils::dBusSignature(icao);
out << "CAircraftIcaoCode" << " size: " << s.size() << " sig: " << s << endl;
s = CDBusUtils::dBusSignature(airportIcao);
out << "CAirportIcaoCode" << " size: " << s.size() << " sig: " << s << endl;
s = CDBusUtils::dBusSignature(livery);
out << "CLivery" << " size: " << s.size() << " sig: " << s << endl;
s = CDBusUtils::dBusSignature(country);
out << "CCountry" << " size: " << s.size() << " sig: " << s << endl;
s = CDBusUtils::dBusSignature(airport);
out << "CAirport" << " size: " << s.size() << " sig: " << s << endl;
s = CDBusUtils::dBusSignature(model);
out << "CAircraftModel" << " size: " << s.size() << " sig: " << s << endl;
s = CDBusUtils::dBusSignature(aircraft);
out << "CSimulatedAircraft" << " size: " << s.size() << " sig: " << s << endl;
s = CDBusUtils::dBusSignature(aircraftList);
out << "CSimulatedAircraftList" << " size: " << s.size() << " sig: " << s << endl;
s = CDBusUtils::dBusSignature(var);
out << "CVariant" << " size: " << s.size() << " sig: " << s << endl;
}
} // ns

45
src/blackmisc/dbusutils.h Normal file
View File

@@ -0,0 +1,45 @@
/* Copyright (C) 2017
* swift Project Community / Contributors
*
* This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level
* directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project,
* including this file, may be copied, modified, propagated, or distributed except according to the terms
* contained in the LICENSE file.
*/
//! \file
#ifndef BLACKMISC_DBUSUTILS_H
#define BLACKMISC_DBUSUTILS_H
#include "blackmisc/blackmiscexport.h"
#include <QDBusArgument>
#include <QTextStream>
namespace BlackMisc
{
//! Utils for UNIT tests / samples
class BLACKMISC_EXPORT CDBusUtils
{
public:
//! Get QDBusArgument signature (formatted)
static QString getQDBusArgumentSignature(const QDBusArgument &arg, int level = 0);
//! Signature for BlackMisc::CValueObject
template<typename ValueObj>
static QString dBusSignature(const ValueObj &obj)
{
QDBusArgument arg;
obj.marshallToDbus(arg);
return arg.currentSignature();
}
//! Type as string
static QString dbusTypeAsString(QDBusArgument::ElementType type);
//! Show some (important) DBus signatures
static void showDBusSignatures(QTextStream &out);
};
} // ns
#endif // guard

View File

@@ -9,7 +9,6 @@
#include "testserviceinterface.h"
#include "testservice.h"
#include "testutils.h"
#include "testing.h"
#include "blackmisc/test/testdata.h"
#include <QTextStream>

View File

@@ -1,109 +0,0 @@
/* Copyright (C) 2013
* swift Project Community / Contributors
*
* This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level
* directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project,
* including this file, may be copied, modified, propagated, or distributed except according to the terms
* contained in the LICENSE file.
*/
#include "testutils.h"
#include "blackmisc/simulation/simulatedaircraftlist.h"
#include "blackmisc/aviation/airport.h"
#include <QString>
#include <QStringBuilder>
#include <QVariant>
#include <typeinfo>
using namespace BlackMisc;
using namespace BlackMisc::Aviation;
using namespace BlackMisc::Geo;
using namespace BlackMisc::Network;
using namespace BlackMisc::PhysicalQuantities;
using namespace BlackMisc::Simulation;
namespace BlackMisc
{
namespace Test
{
QString CTestUtils::getQDBusArgumentSignature(const QDBusArgument &arg, int level)
{
arg.beginArray();
QVariant qv;
const QString indent(level * 2, ' ');
QString out;
while (!arg.atEnd())
{
const QString type = CTestUtils::dbusTypeAsString(arg.currentType());
const QString signature = arg.currentSignature();
qv = arg.asVariant(); // this advances in the stream
if (qv.canConvert<QDBusArgument>())
{
out += indent % type % QLatin1Literal("signature ") % signature % QLatin1Char('\n');
out += CTestUtils::getQDBusArgumentSignature(qv.value<QDBusArgument>(), level + 1) % QLatin1Char('\n');
}
else
{
out += indent % QLatin1Literal("type: ") % type % QLatin1Literal("signature ") % signature % QLatin1Literal(" value ") % qv.toString() % QLatin1Char('\n');
}
}
arg.endArray();
return out;
}
QString CTestUtils::dbusTypeAsString(QDBusArgument::ElementType type)
{
switch (type)
{
case QDBusArgument::BasicType: return QLatin1Literal("BasicType");
case QDBusArgument::VariantType: return QLatin1Literal("VariantType");
case QDBusArgument::ArrayType: return QLatin1Literal("ArrayType");
case QDBusArgument::StructureType: return QLatin1Literal("StructureType");
case QDBusArgument::MapType: return QLatin1Literal("MapType");
case QDBusArgument::MapEntryType: return QLatin1Literal("MapEntryType");
case QDBusArgument::UnknownType:
default:
return QLatin1Literal("Unknown type");
}
}
void CTestUtils::showDBusSignatures(QTextStream &out)
{
const CCallsign cs;
const CLength l;
const CAircraftIcaoCode icao;
const CAircraftModel model;
const CCountry country;
const CAirportIcaoCode airportIcao;
const CLivery livery;
const CAirport airport;
const CSimulatedAircraft aircraft;
const CSimulatedAircraftList aircraftList;
const CVariant var;
QString s;
s = CTestUtils::dBusSignature(cs);
out << "CCallsign" << " size: " << s.size() << " sig: " << s << endl;
s = CTestUtils::dBusSignature(l);
out << "CLength" << " size: " << s.size() << " sig: " << s << endl;
s = CTestUtils::dBusSignature(icao);
out << "CAircraftIcaoCode" << " size: " << s.size() << " sig: " << s << endl;
s = CTestUtils::dBusSignature(airportIcao);
out << "CAirportIcaoCode" << " size: " << s.size() << " sig: " << s << endl;
s = CTestUtils::dBusSignature(livery);
out << "CLivery" << " size: " << s.size() << " sig: " << s << endl;
s = CTestUtils::dBusSignature(country);
out << "CCountry" << " size: " << s.size() << " sig: " << s << endl;
s = CTestUtils::dBusSignature(airport);
out << "CAirport" << " size: " << s.size() << " sig: " << s << endl;
s = CTestUtils::dBusSignature(model);
out << "CAircraftModel" << " size: " << s.size() << " sig: " << s << endl;
s = CTestUtils::dBusSignature(aircraft);
out << "CSimulatedAircraft" << " size: " << s.size() << " sig: " << s << endl;
s = CTestUtils::dBusSignature(aircraftList);
out << "CSimulatedAircraftList" << " size: " << s.size() << " sig: " << s << endl;
s = CTestUtils::dBusSignature(var);
out << "CVariant" << " size: " << s.size() << " sig: " << s << endl;
}
} // ns
} // ns

View File

@@ -1,48 +0,0 @@
/* Copyright (C) 2013
* swift Project Community / Contributors
*
* This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level
* directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project,
* including this file, may be copied, modified, propagated, or distributed except according to the terms
* contained in the LICENSE file.
*/
//! \file
#ifndef BLACKMISC_TEST_TESTUTILS_H
#define BLACKMISC_TEST_TESTUTILS_H
#include "blackmisc/blackmiscexport.h"
#include <QDBusArgument>
#include <QTextStream>
namespace BlackMisc
{
namespace Test
{
//! Utils for UNIT tests / samples
class BLACKMISC_EXPORT CTestUtils
{
public:
//! Get QDBusArgument signature (formatted)
static QString getQDBusArgumentSignature(const QDBusArgument &arg, int level = 0);
//! Signature for BlackMisc::CValueObject
template<typename ValueObj>
static QString dBusSignature(const ValueObj &obj)
{
QDBusArgument arg;
obj.marshallToDbus(arg);
return arg.currentSignature();
}
//! Type as string
static QString dbusTypeAsString(QDBusArgument::ElementType type);
//! Show some (important) DBus signatures
static void showDBusSignatures(QTextStream &out);
};
} // ns
} // ns
#endif // guard

View File

@@ -16,12 +16,13 @@
#include "testdbus.h"
#include "blackmisc/simulation/simulatedaircraftlist.h"
#include "blackmisc/test/testutils.h"
#include "blackmisc/test/testservice.h"
#include "blackmisc/test/testserviceinterface.h"
#include "blackmisc/dbusutils.h"
#include <QDBusConnection>
#include <QTest>
using namespace BlackMisc;
using namespace BlackMisc::Simulation;
using namespace BlackMisc::Test;
@@ -49,15 +50,15 @@ namespace BlackMiscTest
// normally CSimulatedAircraftList is expected to be the biggest one
const CAircraftModel model;
s = CTestUtils::dBusSignature(model);
s = CDBusUtils::dBusSignature(model);
QVERIFY2(s.length() <= max, "Signature CAircraftModel");
const CSimulatedAircraft aircraft;
s = CTestUtils::dBusSignature(aircraft);
s = CDBusUtils::dBusSignature(aircraft);
QVERIFY2(s.length() <= max, "Signature CSimulatedAircraft");
const CSimulatedAircraftList al;
s = CTestUtils::dBusSignature(al);
s = CDBusUtils::dBusSignature(al);
QVERIFY2(s.length() <= max, "Signature CSimulatedAircraftList");
}
}