14 #include "misc/simulation/settings/xswiftbussettingsqtfree.inc"
19 using namespace swift::misc::simulation::xplane::qtfreeutils;
20 using namespace swift::misc::simulation::settings;
30 void getFileNameTest();
31 void getDirNameTest();
32 void getBaseNameTest();
34 void acfPropertiesTest();
35 void xSwiftBusSettingsTest();
39 void CTestXPlane::getFileNameTest()
41 QCOMPARE(QString::fromStdString(
getFileName(
"c:\\foo\\bar\\test.txt")), QString(
"test.txt"));
42 QCOMPARE(QString::fromStdString(
getFileName(
"c:/foo/bar/test.txt")), QString(
"test.txt"));
43 QCOMPARE(QString::fromStdString(
getFileName(
"/foo/bar/test.txt")), QString(
"test.txt"));
44 QCOMPARE(QString::fromStdString(
getFileName(
"foo/test.txt")), QString(
"test.txt"));
45 QCOMPARE(QString::fromStdString(
getFileName(
"test.txt")), QString(
"test.txt"));
46 QCOMPARE(QString::fromStdString(
getFileName(
"foo/test.txt.txt")), QString(
"test.txt.txt"));
47 QCOMPARE(QString::fromStdString(
getFileName(
"foo/bar")), QString(
"bar"));
50 void CTestXPlane::getDirNameTest()
52 QCOMPARE(QString::fromStdString(
getDirName(
"c:\\foo\\bar\\test.txt")), QString(
"bar"));
53 QCOMPARE(QString::fromStdString(
getDirName(
"c:/foo/bar/test.txt")), QString(
"bar"));
54 QCOMPARE(QString::fromStdString(
getDirName(
"/foo/bar/test.txt")), QString(
"bar"));
55 QCOMPARE(QString::fromStdString(
getDirName(
"foo/test.txt")), QString(
"foo"));
56 QCOMPARE(QString::fromStdString(
getDirName(
"test.txt")), QString());
57 QCOMPARE(QString::fromStdString(
getDirName(
"foo/test.txt.txt")), QString(
"foo"));
60 void CTestXPlane::getBaseNameTest()
62 QCOMPARE(QString::fromStdString(
getBaseName(
"c:\\foo\\bar\\test.txt")), QString(
"test"));
63 QCOMPARE(QString::fromStdString(
getBaseName(
"c:/foo/bar/test.txt")), QString(
"test"));
64 QCOMPARE(QString::fromStdString(
getBaseName(
"/foo/bar/test.txt")), QString(
"test"));
65 QCOMPARE(QString::fromStdString(
getBaseName(
"foo/test.txt")), QString(
"test"));
66 QCOMPARE(QString::fromStdString(
getBaseName(
"test.txt")), QString(
"test"));
67 QCOMPARE(QString::fromStdString(
getBaseName(
"foo/test.txt.txt")), QString(
"test"));
70 void CTestXPlane::splitTest()
72 const std::string sentence(
"This is a test!");
73 std::vector<std::string> result =
split(sentence);
74 QVERIFY(result.size() == 4);
75 QCOMPARE(QString::fromStdString(result[0]), QString(
"This"));
76 QCOMPARE(QString::fromStdString(result[3]), QString(
"test!"));
78 std::vector<std::string> result2 =
split(sentence, 1);
79 QVERIFY(result2.size() == 2);
80 QCOMPARE(QString::fromStdString(result2[0]), QString(
"This"));
81 QCOMPARE(QString::fromStdString(result2[1]), QString(
"is a test!"));
83 std::vector<std::string> result3 =
split(sentence, 0,
".");
84 QVERIFY(result3.size() == 1);
85 QCOMPARE(QString::fromStdString(result3[0]), QString(
"This is a test!"));
87 std::vector<std::string> result4 =
split(
"");
88 QVERIFY(result4.size() == 1);
89 QCOMPARE(QString::fromStdString(result4[0]), QString(
""));
92 void CTestXPlane::acfPropertiesTest()
96 QCOMPARE(QString::fromStdString(acfProperties.
aircraftIcaoCode), QString(
"BE58"));
97 QCOMPARE(QString::fromStdString(acfProperties.
modelDescription), QString(
"[ACF] Beechcraft Baron B58"));
98 QCOMPARE(QString::fromStdString(acfProperties.
author), QString(
"swift project"));
99 QCOMPARE(QString::fromStdString(acfProperties.
modelName), QString(
"Beechcraft Baron 58"));
100 QCOMPARE(QString::fromStdString(acfProperties.
modelString), QString(
"swift project Beechcraft Baron 58"));
103 void CTestXPlane::xSwiftBusSettingsTest()
125 QVERIFY2(s2.getNightTextureModeQt() ==
"foo",
"Expect lower case foo");
141 QVERIFY2(s2.getNightTextureModeQt() ==
"foo",
"Expect lower case foo");
144 void CTestXPlane::qtFreeUtils()
148 QVERIFY2(qFuzzyCompare(77.0, vOut),
"Wrong normalize 0-360");
151 QVERIFY2(qFuzzyCompare(1.0, vOut),
"Wrong normalize 0-360");
154 QVERIFY2(qFuzzyCompare(350.0, vOut),
"Wrong normalize 0-360");
157 QVERIFY2(qFuzzyCompare(350.0, vOut),
"Wrong normalize 0-360");
160 QVERIFY2(qFuzzyCompare(180.0, vOut),
"Wrong normalize 0-360");
163 QVERIFY2(qFuzzyCompare(-10.0, vOut),
"Wrong normalize +-180");
166 QVERIFY2(qFuzzyCompare(100.0, vOut),
"Wrong normalize +-180");
169 QVERIFY2(qFuzzyCompare(-170.0, vOut),
"Wrong normalize +-180");
172 QVERIFY2(qFuzzyCompare(0, vOut),
"Wrong normalize +-180");
175 QVERIFY2(qFuzzyCompare(170, vOut),
"Wrong normalize +-180");
182 #include "testxplane.moc"
static const QString & sessionBusAddress()
Address denoting a session bus server.
static const QString & testFilesDirectory()
Where test files are located.
qint64 getMSecsSinceEpoch() const
Timestamp as ms value.
QString toQString(bool i18n=false) const
Cast as QString.
QString toXSwiftBusJsonStringQt() const
As JSON string.
void setDBusServerAddressQt(const QString &dBusAddress)
Set DBus server.
virtual void setCurrentUtcTime()
Sets both timestamps.
void setNightTextureModeQt(const QString &nightTexture)
The the night texture mode.
QString getDBusServerAddressQt() const
DBus server.
QString getNightTextureModeQt() const
The the night texture mode.
bool isDrawingLabels() const
Get whether the plugin draws type and callsign labels above aircraft.
bool setMaxPlanes(int planes)
Set the maximum number of aircraft.
double getMaxDrawDistanceNM() const
Set the maximum distance at which to draw aircraft (nautical miles).
void setDrawingLabels(bool drawing)
Set whether the plugin draws type and callsign labels above aircraft.
int getFollowAircraftDistanceM() const
Get follow aircraft distance.
bool setMaxDrawDistanceNM(double nauticalMiles)
Set the maximum distance at which to draw aircraft (nautical miles).
int getMaxPlanes() const
Get the maximum number of aircraft.
bool setFollowAircraftDistanceM(int meters)
Set follow aircraft distance.
Free functions in swift::misc.
std::string getBaseName(const std::string &filePath)
Get the base name of the file.
AcfProperties extractAcfProperties(const std::string &filePath)
Extract ACF properties from an aircraft file.
std::string getFileName(const std::string &filePath)
Get filename (including all extensions) from a filePath.
double normalizeValue(const double value, const double start, const double end)
Normalize value to range start -> end (like for +-180degrees)
std::string getDirName(const std::string &filePath)
Get the name of the parent directory.
std::vector< std::string > split(const std::string &str, size_t maxSplitCount=0, const std::string &delimiter=" ")
Split string by delimiter and maxSplitCount times.
std::string author
Model author.
std::string modelDescription
Model description.
std::string aircraftIcaoCode
Aircraft ICAO code.
std::string modelString
Generated model string.
std::string modelName
Model name.
SWIFTTEST_MAIN(MiscTest::CTestXPlane)
main