mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-05-04 08:55:43 +08:00
refs #445, unit tests
* tests for DB reading * adjusted other unit tests (livery, formatting, doxygen)
This commit is contained in:
committed by
Mathew Sutcliffe
parent
25fd0f4f2d
commit
edf8191969
@@ -9,6 +9,7 @@
|
|||||||
|
|
||||||
#include "testblackcoremain.h"
|
#include "testblackcoremain.h"
|
||||||
#include "testinterpolator.h"
|
#include "testinterpolator.h"
|
||||||
|
#include "testreaders.h"
|
||||||
#include "testnetwork.h"
|
#include "testnetwork.h"
|
||||||
|
|
||||||
namespace BlackCoreTest
|
namespace BlackCoreTest
|
||||||
@@ -24,6 +25,10 @@ namespace BlackCoreTest
|
|||||||
CTestInterpolator interpolatorTests;
|
CTestInterpolator interpolatorTests;
|
||||||
status |= QTest::qExec(&interpolatorTests, argc, argv);
|
status |= QTest::qExec(&interpolatorTests, argc, argv);
|
||||||
}
|
}
|
||||||
|
{
|
||||||
|
CTestReaders readersTests;
|
||||||
|
status |= QTest::qExec(&readersTests, argc, argv);
|
||||||
|
}
|
||||||
{
|
{
|
||||||
CTestNetwork networkTests;
|
CTestNetwork networkTests;
|
||||||
status |= QTest::qExec(&networkTests, argc, argv);
|
status |= QTest::qExec(&networkTests, argc, argv);
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ void BlackCoreTest::CTestNetwork::networkTest(BlackCore::INetwork *net)
|
|||||||
.send(&INetwork::presetCallsign, "SWIFT")
|
.send(&INetwork::presetCallsign, "SWIFT")
|
||||||
.send(&INetwork::presetIcaoCodes, CAircraftIcaoData(
|
.send(&INetwork::presetIcaoCodes, CAircraftIcaoData(
|
||||||
CAircraftIcaoCode("C172", "L1P"),
|
CAircraftIcaoCode("C172", "L1P"),
|
||||||
CAirlineIcaoCode("YYY"), "white"))
|
CAirlineIcaoCode("YYY")))
|
||||||
.send(&INetwork::initiateConnection)
|
.send(&INetwork::initiateConnection)
|
||||||
.expect(&INetwork::connectionStatusChanged, [](INetwork::ConnectionStatus, INetwork::ConnectionStatus newStatus)
|
.expect(&INetwork::connectionStatusChanged, [](INetwork::ConnectionStatus, INetwork::ConnectionStatus newStatus)
|
||||||
{
|
{
|
||||||
@@ -38,6 +38,7 @@ void BlackCoreTest::CTestNetwork::networkTest(BlackCore::INetwork *net)
|
|||||||
})
|
})
|
||||||
.expect(&INetwork::connectionStatusChanged, [](INetwork::ConnectionStatus, INetwork::ConnectionStatus newStatus)
|
.expect(&INetwork::connectionStatusChanged, [](INetwork::ConnectionStatus, INetwork::ConnectionStatus newStatus)
|
||||||
{
|
{
|
||||||
|
//! \todo verify how we want to handle the situation if the connect fails. On Jenkins that would cause a failed test case and hence a failed build
|
||||||
QVERIFY(newStatus == INetwork::Connected);
|
QVERIFY(newStatus == INetwork::Connected);
|
||||||
qDebug() << "CONNECTED";
|
qDebug() << "CONNECTED";
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -39,9 +39,9 @@ namespace BlackCoreTest
|
|||||||
//! Common part used by all tests.
|
//! Common part used by all tests.
|
||||||
void networkTest(BlackCore::INetwork *);
|
void networkTest(BlackCore::INetwork *);
|
||||||
|
|
||||||
BlackCore::CNetworkVatlib m_networkVatlib ;
|
BlackCore::CNetworkVatlib m_networkVatlib ; //!< vatlib instance
|
||||||
};
|
};
|
||||||
|
|
||||||
} //namespace BlackCoreTest
|
} //namespace
|
||||||
|
|
||||||
#endif // guard
|
#endif // guard
|
||||||
|
|||||||
95
tests/blackcore/testreaders.cpp
Normal file
95
tests/blackcore/testreaders.cpp
Normal file
@@ -0,0 +1,95 @@
|
|||||||
|
/* Copyright (C) 2015
|
||||||
|
* 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 "testreaders.h"
|
||||||
|
#include "expect.h"
|
||||||
|
#include "blackcore/reader_settings.h"
|
||||||
|
#include "blackmisc/networkutils.h"
|
||||||
|
#include "blackmisc/aviation/aircrafticaocode.h"
|
||||||
|
#include "blackmisc/aviation/airlineicaocode.h"
|
||||||
|
|
||||||
|
using namespace BlackCore;
|
||||||
|
using namespace BlackMisc;
|
||||||
|
using namespace BlackMisc::Aviation;
|
||||||
|
using namespace BlackMisc::Simulation;
|
||||||
|
|
||||||
|
namespace BlackCoreTest
|
||||||
|
{
|
||||||
|
|
||||||
|
CTestReaders::CTestReaders(QObject *parent) :
|
||||||
|
QObject(parent),
|
||||||
|
m_icaoReader(this,
|
||||||
|
CReaderSettings::instance().protocolIcaoReader(),
|
||||||
|
CReaderSettings::instance().serverIcaoReader(),
|
||||||
|
CReaderSettings::instance().baseUrlIcaoReader()
|
||||||
|
),
|
||||||
|
m_modelReader(this,
|
||||||
|
CReaderSettings::instance().protocolModelReader(),
|
||||||
|
CReaderSettings::instance().serverModelReader(),
|
||||||
|
CReaderSettings::instance().baseUrlModelReader()
|
||||||
|
)
|
||||||
|
{ }
|
||||||
|
|
||||||
|
void CTestReaders::readIcaoData()
|
||||||
|
{
|
||||||
|
QString server(CReaderSettings::instance().serverIcaoReader());
|
||||||
|
if (!pingServer(server)) { return; }
|
||||||
|
m_icaoReader.start();
|
||||||
|
Expect e(&this->m_icaoReader);
|
||||||
|
EXPECT_UNIT(e)
|
||||||
|
.send(&CIcaoDataReader::readInBackgroundThread)
|
||||||
|
.expect(&CIcaoDataReader::readAll, [server]()
|
||||||
|
{
|
||||||
|
qDebug() << "Read ICAO data from" << server;
|
||||||
|
})
|
||||||
|
.wait(10);
|
||||||
|
|
||||||
|
QVERIFY2(this->m_icaoReader.getAircraftIcaoCodesCount() > 0, "No aircraft ICAOs");
|
||||||
|
QVERIFY2(this->m_icaoReader.getAirlineIcaoCodesCount() > 0, "No airline ICAOs");
|
||||||
|
|
||||||
|
CAircraftIcaoCode aircraftIcao(this->m_icaoReader.getAircraftIcaoCodes().front());
|
||||||
|
CAirlineIcaoCode airlineIcao(this->m_icaoReader.getAirlineIcaoCodes().front());
|
||||||
|
QVERIFY2(aircraftIcao.hasCompleteData(), "Missing data for aircraft ICAO");
|
||||||
|
QVERIFY2(airlineIcao.hasCompleteData(), "Missing data for airline ICAO");
|
||||||
|
}
|
||||||
|
|
||||||
|
void CTestReaders::readModelData()
|
||||||
|
{
|
||||||
|
QString server(CReaderSettings::instance().serverModelReader());
|
||||||
|
if (!pingServer(server)) { return; }
|
||||||
|
m_modelReader.start();
|
||||||
|
Expect e(&this->m_modelReader);
|
||||||
|
EXPECT_UNIT(e)
|
||||||
|
.send(&CModelDataReader::readInBackgroundThread)
|
||||||
|
.expect(&CModelDataReader::readAll, [server]()
|
||||||
|
{
|
||||||
|
qDebug() << "Read model data from" << server;
|
||||||
|
})
|
||||||
|
.wait(10);
|
||||||
|
|
||||||
|
QVERIFY2(this->m_modelReader.getDistributorsCount() > 0, "No distributors");
|
||||||
|
QVERIFY2(this->m_modelReader.getLiveriesCount() > 0, "No liveries");
|
||||||
|
|
||||||
|
CLivery livery(this->m_modelReader.getLiveries().front());
|
||||||
|
CDistributor distributor(this->m_modelReader.getDistributors().front());
|
||||||
|
QVERIFY2(livery.hasCompleteData(), "Missing data for livery");
|
||||||
|
QVERIFY2(distributor.hasCompleteData(), "Missing data for distributor");
|
||||||
|
}
|
||||||
|
|
||||||
|
bool CTestReaders::pingServer(const QString &server)
|
||||||
|
{
|
||||||
|
QString m;
|
||||||
|
if (!CNetworkUtils::canConnect(server, 80, m, 2500))
|
||||||
|
{
|
||||||
|
qWarning() << "Skipping unit test as" << server << "cannot be connected";
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
} // ns
|
||||||
50
tests/blackcore/testreaders.h
Normal file
50
tests/blackcore/testreaders.h
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
/* Copyright (C) 2015
|
||||||
|
* 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 BLACKCORETEST_TESTREADERS_H
|
||||||
|
#define BLACKCORETEST_TESTREADERS_H
|
||||||
|
|
||||||
|
#include "blackcore/network_vatlib.h"
|
||||||
|
#include "blackcore/modeldatareader.h"
|
||||||
|
#include "blackcore/icaodatareader.h"
|
||||||
|
#include <QtTest/QtTest>
|
||||||
|
|
||||||
|
namespace BlackCoreTest
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Test data readers (for bookings, JSON, etc.)
|
||||||
|
*/
|
||||||
|
class CTestReaders : public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
//! Constructor.
|
||||||
|
explicit CTestReaders(QObject *parent = nullptr);
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
//! Read ICAO data
|
||||||
|
void readIcaoData();
|
||||||
|
|
||||||
|
//! Read model data
|
||||||
|
void readModelData();
|
||||||
|
|
||||||
|
private:
|
||||||
|
BlackCore::CIcaoDataReader m_icaoReader;
|
||||||
|
BlackCore::CModelDataReader m_modelReader;
|
||||||
|
|
||||||
|
//! Test if server is available
|
||||||
|
static bool pingServer(const QString &server);
|
||||||
|
};
|
||||||
|
|
||||||
|
} //namespace
|
||||||
|
|
||||||
|
#endif // guard
|
||||||
@@ -165,8 +165,7 @@ namespace BlackMiscTest
|
|||||||
|
|
||||||
CAircraftIcaoData icao1(
|
CAircraftIcaoData icao1(
|
||||||
CAircraftIcaoCode("C172", "L1P"),
|
CAircraftIcaoCode("C172", "L1P"),
|
||||||
CAirlineIcaoCode("GA"),
|
CAirlineIcaoCode("GA")
|
||||||
"0000ff"
|
|
||||||
);
|
);
|
||||||
CAircraftIcaoData icao2(icao1);
|
CAircraftIcaoData icao2(icao1);
|
||||||
QVERIFY2(icao1 == icao2, "ICAOs shall be equal");
|
QVERIFY2(icao1 == icao2, "ICAOs shall be equal");
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ namespace BlackMiscTest
|
|||||||
explicit CTestIdentifier(QObject *parent = nullptr) : QObject(parent) {}
|
explicit CTestIdentifier(QObject *parent = nullptr) : QObject(parent) {}
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
|
//! Identifier tests
|
||||||
void identifierBasics();
|
void identifierBasics();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user