mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-08-07 18:15:51 +08:00
Ref T251, unit test for gnd flag sending
This commit is contained in:
@@ -43,6 +43,16 @@ namespace BlackMisc
|
||||
return this->getEngine(engineNumber).isOn();
|
||||
}
|
||||
|
||||
void CAircraftEngineList::initEngines(int engineNumber, bool on)
|
||||
{
|
||||
this->clear();
|
||||
for (int e = 0; e < engineNumber; e++)
|
||||
{
|
||||
const CAircraftEngine engine(e + 1, on);
|
||||
this->push_back(engine);
|
||||
}
|
||||
}
|
||||
|
||||
bool CAircraftEngineList::isAnyEngineOn() const
|
||||
{
|
||||
return this->contains(&CAircraftEngine::isOn, true);
|
||||
|
||||
@@ -53,6 +53,9 @@ namespace BlackMisc
|
||||
//! Engine number 1..x on?
|
||||
bool isEngineOn(int engineNumber) const;
|
||||
|
||||
//! Init some engines
|
||||
void initEngines(int engineNumber, bool on);
|
||||
|
||||
//! Is any engine on?
|
||||
bool isAnyEngineOn() const;
|
||||
|
||||
|
||||
@@ -16,6 +16,8 @@
|
||||
#include <QList>
|
||||
#include <QStringList>
|
||||
|
||||
using namespace BlackMisc;
|
||||
|
||||
class QPixmap;
|
||||
|
||||
const QJsonValue &operator >>(const QJsonValue &json, int &value)
|
||||
@@ -308,74 +310,74 @@ QJsonObject &operator<<(QJsonObject &json, const std::pair<QString, const QByteA
|
||||
return json;
|
||||
}
|
||||
|
||||
QJsonObject &operator<<(QJsonObject &json, const std::pair<BlackMisc::CExplicitLatin1String, const int &> &value)
|
||||
QJsonObject &operator<<(QJsonObject &json, const std::pair<CExplicitLatin1String, const int &> &value)
|
||||
{
|
||||
json[value.first] = QJsonValue(value.second);
|
||||
return json;
|
||||
}
|
||||
|
||||
QJsonObject &operator<<(QJsonObject &json, const std::pair<BlackMisc::CExplicitLatin1String, const qint16 &> &value)
|
||||
QJsonObject &operator<<(QJsonObject &json, const std::pair<CExplicitLatin1String, const qint16 &> &value)
|
||||
{
|
||||
json[value.first] = QJsonValue(value.second);
|
||||
return json;
|
||||
}
|
||||
|
||||
QJsonObject &operator<<(QJsonObject &json, const std::pair<BlackMisc::CExplicitLatin1String, const qulonglong &> &value)
|
||||
QJsonObject &operator<<(QJsonObject &json, const std::pair<CExplicitLatin1String, const qulonglong &> &value)
|
||||
{
|
||||
json[value.first] = QJsonValue(static_cast<int>(value.second));
|
||||
return json;
|
||||
}
|
||||
|
||||
QJsonObject &operator<<(QJsonObject &json, const std::pair<BlackMisc::CExplicitLatin1String, const qlonglong &> &value)
|
||||
QJsonObject &operator<<(QJsonObject &json, const std::pair<CExplicitLatin1String, const qlonglong &> &value)
|
||||
{
|
||||
json[value.first] = QJsonValue(value.second);
|
||||
return json;
|
||||
}
|
||||
|
||||
QJsonObject &operator<<(QJsonObject &json, const std::pair<BlackMisc::CExplicitLatin1String, const uint &> &value)
|
||||
QJsonObject &operator<<(QJsonObject &json, const std::pair<CExplicitLatin1String, const uint &> &value)
|
||||
{
|
||||
json[value.first] = QJsonValue(static_cast<int>(value.second));
|
||||
return json;
|
||||
}
|
||||
|
||||
QJsonObject &operator<<(QJsonObject &json, const std::pair<BlackMisc::CExplicitLatin1String, const QString &> &value)
|
||||
QJsonObject &operator<<(QJsonObject &json, const std::pair<CExplicitLatin1String, const QString &> &value)
|
||||
{
|
||||
json[value.first] = QJsonValue(value.second);
|
||||
return json;
|
||||
}
|
||||
|
||||
QJsonObject &operator<<(QJsonObject &json, const std::pair<BlackMisc::CExplicitLatin1String, const QStringList &> &value)
|
||||
QJsonObject &operator<<(QJsonObject &json, const std::pair<CExplicitLatin1String, const QStringList &> &value)
|
||||
{
|
||||
json[value.first] = QJsonValue(QJsonArray::fromStringList(value.second));
|
||||
return json;
|
||||
}
|
||||
|
||||
QJsonObject &operator<<(QJsonObject &json, const std::pair<BlackMisc::CExplicitLatin1String, const double &> &value)
|
||||
QJsonObject &operator<<(QJsonObject &json, const std::pair<CExplicitLatin1String, const double &> &value)
|
||||
{
|
||||
json[value.first] = QJsonValue(value.second);
|
||||
return json;
|
||||
}
|
||||
|
||||
QJsonObject &operator<<(QJsonObject &json, const std::pair<BlackMisc::CExplicitLatin1String, const bool &> &value)
|
||||
QJsonObject &operator<<(QJsonObject &json, const std::pair<CExplicitLatin1String, const bool &> &value)
|
||||
{
|
||||
json[value.first] = QJsonValue(value.second);
|
||||
return json;
|
||||
}
|
||||
|
||||
QJsonObject &operator<<(QJsonObject &json, const std::pair<BlackMisc::CExplicitLatin1String, const QDateTime &> &value)
|
||||
QJsonObject &operator<<(QJsonObject &json, const std::pair<CExplicitLatin1String, const QDateTime &> &value)
|
||||
{
|
||||
json[value.first] = QJsonValue(value.second.toString());
|
||||
return json;
|
||||
}
|
||||
|
||||
QJsonObject &operator<<(QJsonObject &json, const std::pair<BlackMisc::CExplicitLatin1String, const QPixmap &> &value)
|
||||
QJsonObject &operator<<(QJsonObject &json, const std::pair<CExplicitLatin1String, const QPixmap &> &value)
|
||||
{
|
||||
QString pm(BlackMisc::pixmapToPngHexString(value.second));
|
||||
json[value.first] = pm;
|
||||
return json;
|
||||
}
|
||||
|
||||
QJsonObject &operator<<(QJsonObject &json, const std::pair<BlackMisc::CExplicitLatin1String, const QByteArray &> &value)
|
||||
QJsonObject &operator<<(QJsonObject &json, const std::pair<CExplicitLatin1String, const QByteArray &> &value)
|
||||
{
|
||||
QString pm(BlackMisc::bytesToHexString(value.second));
|
||||
json[value.first] = pm;
|
||||
@@ -393,6 +395,13 @@ namespace BlackMisc
|
||||
return acceptCacheFormat ? Json::swiftDataObjectValue(jsonDoc.object()) : jsonDoc.object();
|
||||
}
|
||||
|
||||
QString stringFromJsonObject(const QJsonObject &jsonObject, QJsonDocument::JsonFormat format)
|
||||
{
|
||||
const QJsonDocument doc(jsonObject);
|
||||
const QString strJson(doc.toJson(format));
|
||||
return strJson;
|
||||
}
|
||||
|
||||
QJsonArray jsonArrayFromString(const QString &json)
|
||||
{
|
||||
if (json.isEmpty()) { return QJsonArray();}
|
||||
|
||||
@@ -239,6 +239,10 @@ namespace BlackMisc
|
||||
//! \ingroup JSON
|
||||
BLACKMISC_EXPORT QJsonObject jsonObjectFromString(const QString &json, bool acceptCacheFormat = false);
|
||||
|
||||
//! JSON Object from string
|
||||
//! \ingroup JSON
|
||||
BLACKMISC_EXPORT QString stringFromJsonObject(const QJsonObject &jsonObject, QJsonDocument::JsonFormat format = QJsonDocument::Indented);
|
||||
|
||||
//! JSON Array from string
|
||||
//! \ingroup JSON
|
||||
BLACKMISC_EXPORT QJsonArray jsonArrayFromString(const QString &json);
|
||||
@@ -444,7 +448,7 @@ namespace BlackMisc
|
||||
#define BLACKMISC_DECLARE_USING_MIXIN_JSON(DERIVED) \
|
||||
using ::BlackMisc::Mixin::JsonByMetaClass<DERIVED>::toJson; \
|
||||
using ::BlackMisc::Mixin::JsonByMetaClass<DERIVED>::convertFromJson;
|
||||
} // Mixin
|
||||
} // Mixin ns
|
||||
} // guard
|
||||
|
||||
#endif // guard
|
||||
|
||||
67
tests/blackmisc/testaircraftparts.cpp
Normal file
67
tests/blackmisc/testaircraftparts.cpp
Normal file
@@ -0,0 +1,67 @@
|
||||
/* Copyright (C) 2018
|
||||
* 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.
|
||||
*/
|
||||
|
||||
//! \cond PRIVATE_TESTS
|
||||
|
||||
/*!
|
||||
* \file
|
||||
* \ingroup testblackmisc
|
||||
*/
|
||||
|
||||
#include "testaircraftparts.h"
|
||||
#include "blackmisc/aviation/aircraftparts.h"
|
||||
#include "blackmisc/json.h"
|
||||
#include <QTest>
|
||||
#include <QJsonObject>
|
||||
|
||||
using namespace BlackMisc::Aviation;
|
||||
using namespace BlackMisc::Json;
|
||||
|
||||
namespace BlackMiscTest
|
||||
{
|
||||
void CTestAircraftParts::groundFlag()
|
||||
{
|
||||
const CAircraftParts ap1 = this->testParts1();
|
||||
CAircraftParts ap2(ap1);
|
||||
const QJsonObject ap1Json = ap1.toJson();
|
||||
QJsonObject ap2Json = ap2.toJson();
|
||||
QJsonObject deltaJson12 = getIncrementalObject(ap1Json, ap2Json);
|
||||
QJsonObject deltaJson21 = getIncrementalObject(ap2Json, ap1Json);
|
||||
QVERIFY2(deltaJson12.isEmpty(), "Values shall be the same");
|
||||
QVERIFY2(deltaJson21.isEmpty(), "Values shall be the same");
|
||||
|
||||
ap2.setOnGround(false);
|
||||
ap2Json = ap2.toJson();
|
||||
deltaJson12 = getIncrementalObject(ap1Json, ap2Json);
|
||||
deltaJson21 = getIncrementalObject(ap2Json, ap1Json);
|
||||
|
||||
QVERIFY2(deltaJson12.keys().size() == 1, "Values shall be 1");
|
||||
QVERIFY2(deltaJson21.keys().size() == 1, "Values shall be 1");
|
||||
bool deltaGnd = deltaJson12.value("on_ground").toBool(true);
|
||||
QVERIFY2(deltaGnd == false, "Values shall be false");
|
||||
deltaGnd = deltaJson21.value("on_ground").toBool(false);
|
||||
QVERIFY2(deltaGnd == true, "Values shall be false");
|
||||
|
||||
// const QString json1 = stringFromJsonObject(deltaJson12);
|
||||
// const QString json2 = stringFromJsonObject(deltaJson21);
|
||||
}
|
||||
|
||||
CAircraftParts CTestAircraftParts::testParts1() const
|
||||
{
|
||||
CAircraftLights lights;
|
||||
lights.allLightsOn();
|
||||
CAircraftEngineList engines;
|
||||
engines.initEngines(4, true);
|
||||
const bool onGround = true;
|
||||
CAircraftParts ap(lights, true, 0, false, engines, onGround);
|
||||
return ap;
|
||||
}
|
||||
} // ns
|
||||
|
||||
//! \endcond
|
||||
43
tests/blackmisc/testaircraftparts.h
Normal file
43
tests/blackmisc/testaircraftparts.h
Normal file
@@ -0,0 +1,43 @@
|
||||
/* Copyright (C) 2018
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef BLACKMISCTEST_TESTAIRCRAFTPARTS_H
|
||||
#define BLACKMISCTEST_TESTAIRCRAFTPARTS_H
|
||||
|
||||
//! \cond PRIVATE_TESTS
|
||||
//! \file
|
||||
//! \ingroup testblackmisc
|
||||
|
||||
#include "blackmisc/aviation/aircraftparts.h"
|
||||
#include <QObject>
|
||||
|
||||
namespace BlackMiscTest
|
||||
{
|
||||
//! Geo classes tests
|
||||
class CTestAircraftParts : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
//! Standard test case constructor
|
||||
explicit CTestAircraftParts(QObject *parent = nullptr) : QObject(parent) {}
|
||||
|
||||
private slots:
|
||||
//! Test ground flag
|
||||
void groundFlag();
|
||||
|
||||
private:
|
||||
//! Test parts
|
||||
BlackMisc::Aviation::CAircraftParts testParts1() const;
|
||||
};
|
||||
} // namespace
|
||||
|
||||
//! \endcond
|
||||
|
||||
#endif // guard
|
||||
@@ -17,6 +17,7 @@
|
||||
#include "testdbus.h"
|
||||
#include "testflightplan.h"
|
||||
#include "testgeo.h"
|
||||
#include "testaircraftparts.h"
|
||||
#include "testicon.h"
|
||||
#include "testidentifier.h"
|
||||
#include "testinput.h"
|
||||
@@ -58,6 +59,10 @@ namespace BlackMiscTest
|
||||
CTestPropertyIndex piTests;
|
||||
status |= test.exec(&piTests, "blackmisc_propertyindex");
|
||||
}
|
||||
{
|
||||
CTestAircraftParts apTests;
|
||||
status |= test.exec(&apTests, "blackmisc_aircraftParts");
|
||||
}
|
||||
{
|
||||
CTestGeo geoTests;
|
||||
status |= test.exec(&geoTests, "blackmisc_geo");
|
||||
|
||||
Reference in New Issue
Block a user