mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-22 14:55:36 +08:00
Add X-Plane utils unit test
This commit is contained in:
12
resources/share/test/testaircraft.acf
Normal file
12
resources/share/test/testaircraft.acf
Normal file
@@ -0,0 +1,12 @@
|
||||
I
|
||||
1004 version
|
||||
ACF
|
||||
|
||||
PROPERTIES_BEGIN
|
||||
P acf/_ICAO BE58
|
||||
P acf/_ITT_is_C 1
|
||||
P acf/_descrip Beechcraft Baron B58
|
||||
P acf/_n_ref 0.0
|
||||
P acf/_name Beechcraft Baron 58
|
||||
P acf/_studio swift project
|
||||
P acf/_author swift project
|
||||
@@ -3,3 +3,4 @@ SUBDIRS += \
|
||||
testinterpolatorlinear \
|
||||
testinterpolatormisc \
|
||||
testinterpolatorparts \
|
||||
testxplane \
|
||||
|
||||
107
tests/blackmisc/simulation/testxplane/testxplane.cpp
Normal file
107
tests/blackmisc/simulation/testxplane/testxplane.cpp
Normal file
@@ -0,0 +1,107 @@
|
||||
/* 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 "blackmisc/simulation/xplane/qtfreeutils.h"
|
||||
#include "blackmisc/directoryutils.h"
|
||||
#include "test.h"
|
||||
|
||||
#include <QTest>
|
||||
|
||||
using namespace BlackMisc;
|
||||
using namespace BlackMisc::Simulation::XPlane::QtFreeUtils;
|
||||
|
||||
namespace BlackMiscTest
|
||||
{
|
||||
//! X-Plane utils test
|
||||
class CTestXPlane : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
private slots:
|
||||
void getFileNameTest();
|
||||
void getDirNameTest();
|
||||
void getBaseNameTest();
|
||||
void splitTest();
|
||||
void acfPropertiesTest();
|
||||
};
|
||||
|
||||
void CTestXPlane::getFileNameTest()
|
||||
{
|
||||
QCOMPARE(QString::fromStdString(getFileName("c:\\foo\\bar\\test.txt")), QString("test.txt"));
|
||||
QCOMPARE(QString::fromStdString(getFileName("c:/foo/bar/test.txt")), QString("test.txt"));
|
||||
QCOMPARE(QString::fromStdString(getFileName("/foo/bar/test.txt")), QString("test.txt"));
|
||||
QCOMPARE(QString::fromStdString(getFileName("foo/test.txt")), QString("test.txt"));
|
||||
QCOMPARE(QString::fromStdString(getFileName("test.txt")), QString("test.txt"));
|
||||
QCOMPARE(QString::fromStdString(getFileName("foo/test.txt.txt")), QString("test.txt.txt"));
|
||||
}
|
||||
|
||||
void CTestXPlane::getDirNameTest()
|
||||
{
|
||||
QCOMPARE(QString::fromStdString(getDirName("c:\\foo\\bar\\test.txt")), QString("bar"));
|
||||
QCOMPARE(QString::fromStdString(getDirName("c:/foo/bar/test.txt")), QString("bar"));
|
||||
QCOMPARE(QString::fromStdString(getDirName("/foo/bar/test.txt")), QString("bar"));
|
||||
QCOMPARE(QString::fromStdString(getDirName("foo/test.txt")), QString("foo"));
|
||||
QCOMPARE(QString::fromStdString(getDirName("test.txt")), QString());
|
||||
QCOMPARE(QString::fromStdString(getDirName("foo/test.txt.txt")), QString("foo"));
|
||||
}
|
||||
|
||||
void CTestXPlane::getBaseNameTest()
|
||||
{
|
||||
QCOMPARE(QString::fromStdString(getBaseName("c:\\foo\\bar\\test.txt")), QString("test"));
|
||||
QCOMPARE(QString::fromStdString(getBaseName("c:/foo/bar/test.txt")), QString("test"));
|
||||
QCOMPARE(QString::fromStdString(getBaseName("/foo/bar/test.txt")), QString("test"));
|
||||
QCOMPARE(QString::fromStdString(getBaseName("foo/test.txt")), QString("test"));
|
||||
QCOMPARE(QString::fromStdString(getBaseName("test.txt")), QString("test"));
|
||||
QCOMPARE(QString::fromStdString(getBaseName("foo/test.txt.txt")), QString("test"));
|
||||
}
|
||||
|
||||
void CTestXPlane::splitTest()
|
||||
{
|
||||
const std::string sentence("This is a test!");
|
||||
std::vector<std::string> result = split(sentence);
|
||||
QVERIFY(result.size() == 4);
|
||||
QCOMPARE(QString::fromStdString(result[0]), QString("This"));
|
||||
QCOMPARE(QString::fromStdString(result[3]), QString("test!"));
|
||||
|
||||
std::vector<std::string> result2 = split(sentence, 1);
|
||||
QVERIFY(result2.size() == 2);
|
||||
QCOMPARE(QString::fromStdString(result2[0]), QString("This"));
|
||||
QCOMPARE(QString::fromStdString(result2[1]), QString("is a test!"));
|
||||
|
||||
std::vector<std::string> result3 = split(sentence, 0, ".");
|
||||
QVERIFY(result3.size() == 1);
|
||||
QCOMPARE(QString::fromStdString(result3[0]), QString("This is a test!"));
|
||||
|
||||
std::vector<std::string> result4 = split("");
|
||||
QVERIFY(result4.size() == 1);
|
||||
QCOMPARE(QString::fromStdString(result4[0]), QString(""));
|
||||
}
|
||||
|
||||
void CTestXPlane::acfPropertiesTest()
|
||||
{
|
||||
QString testAcfFile = CDirectoryUtils::testFilesDirectory() + "/testaircraft.acf";
|
||||
AcfProperties acfProperties = extractAcfProperties(testAcfFile.toStdString());
|
||||
QCOMPARE(QString::fromStdString(acfProperties.aircraftIcaoCode), QString("BE58"));
|
||||
QCOMPARE(QString::fromStdString(acfProperties.modelDescription), QString("[ACF] Beechcraft Baron B58"));
|
||||
QCOMPARE(QString::fromStdString(acfProperties.author), QString("swift project"));
|
||||
QCOMPARE(QString::fromStdString(acfProperties.modelName), QString("Beechcraft Baron 58"));
|
||||
QCOMPARE(QString::fromStdString(acfProperties.modelString), QString("swift project Beechcraft Baron 58"));
|
||||
}
|
||||
}
|
||||
|
||||
//! main
|
||||
BLACKTEST_APPLESS_MAIN(BlackMiscTest::CTestXPlane);
|
||||
|
||||
#include "testxplane.moc"
|
||||
|
||||
//! \endcond
|
||||
27
tests/blackmisc/simulation/testxplane/testxplane.pro
Normal file
27
tests/blackmisc/simulation/testxplane/testxplane.pro
Normal file
@@ -0,0 +1,27 @@
|
||||
load(common_pre)
|
||||
|
||||
QT += core dbus testlib
|
||||
|
||||
TARGET = testxplane
|
||||
CONFIG -= app_bundle
|
||||
CONFIG += blackconfig
|
||||
CONFIG += blackmisc
|
||||
CONFIG += testcase
|
||||
CONFIG += no_testcase_installs
|
||||
|
||||
TEMPLATE = app
|
||||
|
||||
DEPENDPATH += \
|
||||
. \
|
||||
$$SourceRoot/src \
|
||||
$$SourceRoot/tests \
|
||||
|
||||
INCLUDEPATH += \
|
||||
$$SourceRoot/src \
|
||||
$$SourceRoot/tests \
|
||||
|
||||
SOURCES += testxplane.cpp
|
||||
|
||||
DESTDIR = $$DestRoot/bin
|
||||
|
||||
load(common_post)
|
||||
Reference in New Issue
Block a user