mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-07 11:05:33 +08:00
refs #875, moved already existing test utility classes to BlackMisc::Test
This commit is contained in:
committed by
Mathew Sutcliffe
parent
31b6ef83f0
commit
ae5b0310b6
@@ -1,33 +0,0 @@
|
||||
/* Copyright (C) 2016
|
||||
* 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 "blackmisc/test.h"
|
||||
|
||||
namespace BlackMisc
|
||||
{
|
||||
CTestBase::CTestBase(int argc, const char *const *argv)
|
||||
{
|
||||
for (int i = 0; i < argc; ++i)
|
||||
{
|
||||
m_arguments.append(argv[i]);
|
||||
}
|
||||
|
||||
// Output to stdout
|
||||
m_arguments.append({ "-o", "-,txt" });
|
||||
}
|
||||
|
||||
CTestBase::~CTestBase()
|
||||
{}
|
||||
|
||||
int CTestBase::exec(QObject *test, const QString &name)
|
||||
{
|
||||
auto additionalArguments = QStringList { "-o", name + "_testresults.xml,xml" };
|
||||
return this->qExec(test, m_arguments + additionalArguments);
|
||||
}
|
||||
}
|
||||
@@ -1,66 +0,0 @@
|
||||
/* Copyright (C) 2016
|
||||
* 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_H
|
||||
#define BLACKMISC_TEST_H
|
||||
|
||||
#include "blackmisc/blackmiscexport.h"
|
||||
#include <QStringList>
|
||||
|
||||
#ifdef QT_TESTLIB_LIB
|
||||
#include <QtTest>
|
||||
#endif
|
||||
|
||||
class QObject;
|
||||
|
||||
namespace BlackMisc
|
||||
{
|
||||
/*!
|
||||
* Helper base class for executing unit tests.
|
||||
* Contains the parts that do not depend upon QtTest library, and pure
|
||||
* virtual functions for derived class to implement the parts that do.
|
||||
*/
|
||||
class BLACKMISC_EXPORT CTestBase
|
||||
{
|
||||
public:
|
||||
//! Constructor expects command line arguments.
|
||||
CTestBase(int argc, const char *const *argv);
|
||||
|
||||
//! Destructor.
|
||||
virtual ~CTestBase();
|
||||
|
||||
//! Execute the given test case.
|
||||
int exec(QObject *test, const QString &name);
|
||||
|
||||
private:
|
||||
virtual int qExec(QObject *test, const QStringList &args) = 0;
|
||||
|
||||
QStringList m_arguments;
|
||||
};
|
||||
|
||||
#ifdef QT_TESTLIB_LIB
|
||||
/*!
|
||||
* Helper derived class for executing unit tests.
|
||||
* Defined inline and only when building with QT += testlib so blackmisc
|
||||
* doesn't need to link against QtTest library.
|
||||
*/
|
||||
class CTest : public CTestBase
|
||||
{
|
||||
public:
|
||||
using CTestBase::CTestBase;
|
||||
|
||||
private:
|
||||
virtual int qExec(QObject *test, const QStringList &args) override { return QTest::qExec(test, args); }
|
||||
};
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif
|
||||
36
src/blackmisc/test/test.cpp
Normal file
36
src/blackmisc/test/test.cpp
Normal file
@@ -0,0 +1,36 @@
|
||||
/* Copyright (C) 2016
|
||||
* 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 "blackmisc/test/test.h"
|
||||
|
||||
namespace BlackMisc
|
||||
{
|
||||
namespace Test
|
||||
{
|
||||
CTestBase::CTestBase(int argc, const char *const *argv)
|
||||
{
|
||||
for (int i = 0; i < argc; ++i)
|
||||
{
|
||||
m_arguments.append(argv[i]);
|
||||
}
|
||||
|
||||
// Output to stdout
|
||||
m_arguments.append({ "-o", "-,txt" });
|
||||
}
|
||||
|
||||
CTestBase::~CTestBase()
|
||||
{}
|
||||
|
||||
int CTestBase::exec(QObject *test, const QString &name)
|
||||
{
|
||||
auto additionalArguments = QStringList { "-o", name + "_testresults.xml,xml" };
|
||||
return this->qExec(test, m_arguments + additionalArguments);
|
||||
}
|
||||
} // ns
|
||||
} // ns
|
||||
69
src/blackmisc/test/test.h
Normal file
69
src/blackmisc/test/test.h
Normal file
@@ -0,0 +1,69 @@
|
||||
/* Copyright (C) 2016
|
||||
* 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_TEST_H
|
||||
#define BLACKMISC_TEST_TEST_H
|
||||
|
||||
#include "blackmisc/blackmiscexport.h"
|
||||
#include <QStringList>
|
||||
|
||||
#ifdef QT_TESTLIB_LIB
|
||||
#include <QtTest>
|
||||
#endif
|
||||
|
||||
class QObject;
|
||||
|
||||
namespace BlackMisc
|
||||
{
|
||||
namespace Test
|
||||
{
|
||||
/*!
|
||||
* Helper base class for executing unit tests.
|
||||
* Contains the parts that do not depend upon QtTest library, and pure
|
||||
* virtual functions for derived class to implement the parts that do.
|
||||
*/
|
||||
class BLACKMISC_EXPORT CTestBase
|
||||
{
|
||||
public:
|
||||
//! Constructor expects command line arguments.
|
||||
CTestBase(int argc, const char *const *argv);
|
||||
|
||||
//! Destructor.
|
||||
virtual ~CTestBase();
|
||||
|
||||
//! Execute the given test case.
|
||||
int exec(QObject *test, const QString &name);
|
||||
|
||||
private:
|
||||
virtual int qExec(QObject *test, const QStringList &args) = 0;
|
||||
|
||||
QStringList m_arguments;
|
||||
};
|
||||
|
||||
#ifdef QT_TESTLIB_LIB
|
||||
/*!
|
||||
* Helper derived class for executing unit tests.
|
||||
* Defined inline and only when building with QT += testlib so blackmisc
|
||||
* doesn't need to link against QtTest library.
|
||||
*/
|
||||
class CTest : public CTestBase
|
||||
{
|
||||
public:
|
||||
using CTestBase::CTestBase;
|
||||
|
||||
private:
|
||||
virtual int qExec(QObject *test, const QStringList &args) override { return QTest::qExec(test, args); }
|
||||
};
|
||||
#endif
|
||||
} // ns
|
||||
} // ns
|
||||
|
||||
#endif // guard
|
||||
@@ -17,8 +17,8 @@
|
||||
#include "blackmisc/pq/units.h"
|
||||
#include "blackmisc/propertyindexvariantmap.h"
|
||||
#include "blackmisc/sequence.h"
|
||||
#include "blackmisc/testing.h"
|
||||
#include "blackmisc/variant.h"
|
||||
#include "testing.h"
|
||||
|
||||
#include <QDateTime>
|
||||
#include <QList>
|
||||
@@ -34,7 +34,7 @@ using namespace BlackMisc::PhysicalQuantities;
|
||||
|
||||
namespace BlackMisc
|
||||
{
|
||||
namespace Aviation
|
||||
namespace Test
|
||||
{
|
||||
CAtcStationList CTesting::createAtcStations(int number, bool byPropertyIndex)
|
||||
{
|
||||
@@ -161,8 +161,7 @@ namespace BlackMisc
|
||||
" 8° 21′ 13″ N", "11° 47′ 09″ W",
|
||||
"18° 21′ 13″ S", "11° 47′ 09″ E",
|
||||
"09° 12′ 13″ S", "11° 47′ 09″ W"
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
CCoordinateGeodetic c;
|
||||
const CAltitude a(333, CLengthUnit::m());
|
||||
@@ -172,5 +171,11 @@ namespace BlackMisc
|
||||
c = CCoordinateGeodetic::fromWgs84(wgsLatLng.at(idx), wgsLatLng.at(idx + 1), a);
|
||||
}
|
||||
}
|
||||
} // namespace
|
||||
|
||||
const CAtcStationList &CTesting::stations10k()
|
||||
{
|
||||
static const CAtcStationList s = createAtcStations(10000, false);
|
||||
return s;
|
||||
}
|
||||
} // namespace
|
||||
} // namespace
|
||||
@@ -9,35 +9,34 @@
|
||||
|
||||
//! \file
|
||||
|
||||
#ifndef BLACKMISC_TESTING_H
|
||||
#define BLACKMISC_TESTING_H
|
||||
#ifndef BLACKMISC_TEST_TESTING_H
|
||||
#define BLACKMISC_TEST_TESTING_H
|
||||
|
||||
#include "blackmisc/aviation/atcstation.h"
|
||||
#include "blackmisc/aviation/atcstationlist.h"
|
||||
#include "blackmisc/blackmiscexport.h"
|
||||
|
||||
#include <QString>
|
||||
|
||||
//! Generate data for testing purposes.
|
||||
namespace BlackMisc
|
||||
{
|
||||
namespace Aviation
|
||||
namespace Test
|
||||
{
|
||||
//! Generate data for testing aviation classes
|
||||
class BLACKMISC_EXPORT CTesting
|
||||
{
|
||||
public:
|
||||
//! Generate number of ATC stations
|
||||
static CAtcStationList createAtcStations(int number, bool byPropertyIndex = false);
|
||||
static BlackMisc::Aviation::CAtcStationList createAtcStations(int number, bool byPropertyIndex = false);
|
||||
|
||||
//! Single station, annotated by index
|
||||
static CAtcStation createStation(int index, bool byPropertyIndex = false);
|
||||
static BlackMisc::Aviation::CAtcStation createStation(int index, bool byPropertyIndex = false);
|
||||
|
||||
//! Generate number of ATC stations
|
||||
static void readStations(const CAtcStationList &stations, bool byPropertyIndex = false);
|
||||
static void readStations(const BlackMisc::Aviation::CAtcStationList &stations, bool byPropertyIndex = false);
|
||||
|
||||
//! Read properties of a station and concatenate them
|
||||
static QString readStation(const CAtcStation &station, bool byPropertyIndex = false);
|
||||
static QString readStation(const BlackMisc::Aviation::CAtcStation &station, bool byPropertyIndex = false);
|
||||
|
||||
//! Calculate n times distance (greater circle distance)
|
||||
static void calculateDistance(int n);
|
||||
@@ -46,16 +45,11 @@ namespace BlackMisc
|
||||
static void copy10kStations(int times);
|
||||
|
||||
//! Const 10000 stations
|
||||
static const CAtcStationList &stations10k()
|
||||
{
|
||||
static const CAtcStationList s = createAtcStations(10000, false);
|
||||
return s;
|
||||
}
|
||||
static const BlackMisc::Aviation::CAtcStationList &stations10k();
|
||||
|
||||
//! parse coordinates from WGS
|
||||
static void parseWgs(int times);
|
||||
};
|
||||
|
||||
} // ns
|
||||
} // ns
|
||||
|
||||
Reference in New Issue
Block a user