mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-31 12:55:33 +08:00
* class now only contains DBus related code * other functions have been moved to CTesting
This commit is contained in:
committed by
Mathew Sutcliffe
parent
d1827bd162
commit
dc1d5d8586
105
src/blackmisc/dbusutils.cpp
Normal file
105
src/blackmisc/dbusutils.cpp
Normal 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
45
src/blackmisc/dbusutils.h
Normal 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
|
||||
@@ -9,7 +9,6 @@
|
||||
|
||||
#include "testserviceinterface.h"
|
||||
#include "testservice.h"
|
||||
#include "testutils.h"
|
||||
#include "testing.h"
|
||||
#include "blackmisc/test/testdata.h"
|
||||
#include <QTextStream>
|
||||
|
||||
@@ -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
|
||||
@@ -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
|
||||
Reference in New Issue
Block a user