Adjusted samples

* using QTextStream
* some new samples
This commit is contained in:
Klaus Basan
2015-01-23 02:01:44 +01:00
parent 9910e9adb1
commit 4bd9f987ce
5 changed files with 116 additions and 86 deletions

View File

@@ -1,36 +1,43 @@
/* Copyright (C) 2013 VATSIM Community / authors /* Copyright (C) 2015
* This Source Code Form is subject to the terms of the Mozilla Public * swift project Community / Contributors
* License, v. 2.0. If a copy of the MPL was not distributed with this *
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ * 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 "samplesphysicalquantities.h" #include "samplesphysicalquantities.h"
#include "samplesaviation.h" #include "samplesaviation.h"
#include "blackmisc/blackmiscfreefunctions.h" #include "blackmisc/blackmiscfreefunctions.h"
#include <QTextStream>
using namespace BlackMisc; using namespace BlackMisc;
using namespace BlackMiscTest; using namespace BlackMiscTest;
/*! //! Samples
* Sample tests
*/
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
QTextStream out(stdout, QIODevice::WriteOnly);
BlackMisc::initResources(); BlackMisc::initResources();
QFile file(":blackmisc/translations/blackmisc_i18n_de.qm"); QFile file(":blackmisc/translations/blackmisc_i18n_de.qm");
qDebug() << (file.exists() ? "Found translations in resources" : "No translations in resources"); out << (file.exists() ? "Found translations in resources" : "No translations in resources") << endl;
QTranslator translator; QTranslator translator;
bool t = translator.load("blackmisc_i18n_de", ":blackmisc/translations/"); bool t = translator.load("blackmisc_i18n_de", ":blackmisc/translations/");
qDebug() << (t ? "Translator loaded" : "Translator not loaded"); out << (t ? "Translator loaded" : "Translator not loaded") << endl;
QCoreApplication a(argc, argv); QCoreApplication a(argc, argv);
qDebug() << "Use I18N version, y? n?"; out << "Use I18N version, y? n?";
out.flush();
int yn = getchar(); int yn = getchar();
t = (yn == 'y' || yn == 'Y'); t = (yn == 'y' || yn == 'Y');
t = t ? a.installTranslator(&translator) : false; t = t ? a.installTranslator(&translator) : false;
qDebug() << (t ? "Installed translator" : "No translator "); out << (t ? "Installed translator" : "No translator ");
CSamplesPhysicalQuantities::samples(); CSamplesPhysicalQuantities::samples(out);
CSamplesAviation::samples(); CSamplesAviation::samples(out);
return 0; return 0;
} }

View File

@@ -1,7 +1,11 @@
/* Copyright (C) 2013 VATSIM Community / contributors /* Copyright (C) 2015
* This Source Code Form is subject to the terms of the Mozilla Public * swift project Community / Contributors
* License, v. 2.0. If a copy of the MPL was not distributed with this *
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ * 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 "samplesaviation.h" #include "samplesaviation.h"
#include "blackmisc/pqconstants.h" #include "blackmisc/pqconstants.h"
@@ -29,33 +33,33 @@ namespace BlackMiscTest
/* /*
* Samples * Samples
*/ */
int CSamplesAviation::samples() int CSamplesAviation::samples(QTextStream &out)
{ {
CHeading h1(180, CHeading::Magnetic, CAngleUnit::deg()); CHeading h1(180, CHeading::Magnetic, CAngleUnit::deg());
CHeading h2(180, CHeading::True, CAngleUnit::deg()); CHeading h2(180, CHeading::True, CAngleUnit::deg());
qDebug() << h1; out << h1 << endl;
qDebug() << h1 << h2 << (h1 == h2) << (h1 != h2) << (h1 == h1); out << h1 << " " << h2 << " " << (h1 == h2) << " " << (h1 != h2) << " " << (h1 == h1) << endl;
// COM system // COM system
CComSystem c1 = CComSystem::getCom1System(125.3); CComSystem c1 = CComSystem::getCom1System(125.3);
qDebug() << c1; out << c1 << endl;
c1.setActiveUnicom(); c1.setActiveUnicom();
qDebug() << c1; out << c1 << endl;
// NAV system // NAV system
CNavSystem nav1 = CNavSystem::getNav1System(110.0); CNavSystem nav1 = CNavSystem::getNav1System(110.0);
qDebug() << nav1; out << nav1 << endl;
// Transponder tests // Transponder tests
CTransponder tr1("T1", 7000, CTransponder::StateStandby); CTransponder tr1("T1", 7000, CTransponder::StateStandby);
CTransponder tr2("T2", "4532", CTransponder::ModeMil3); CTransponder tr2("T2", "4532", CTransponder::ModeMil3);
qDebug() << tr1 << tr2; out << tr1 << " " << tr2 << endl;
// Callsign and ATC station // Callsign and ATC station
CCallsign callsign1("d-ambz"); CCallsign callsign1("d-ambz");
CCallsign callsign2("DAmbz"); CCallsign callsign2("DAmbz");
qDebug() << callsign1 << callsign2 << (callsign1 == callsign2); out << callsign1 << " " << callsign2 << " " << (callsign1 == callsign2) << endl;
QDateTime dtFrom = QDateTime::currentDateTimeUtc(); QDateTime dtFrom = QDateTime::currentDateTimeUtc();
QDateTime dtUntil = dtFrom.addSecs(60 * 60.0); // 1 hour QDateTime dtUntil = dtFrom.addSecs(60 * 60.0); // 1 hour
@@ -70,8 +74,11 @@ namespace BlackMiscTest
CAtcStation station3(CCallsign("eddm_twr"), CUser("654321", "Jen Doe"), CAtcStation station3(CCallsign("eddm_twr"), CUser("654321", "Jen Doe"),
CFrequency(118.7, CFrequencyUnit::MHz()), CFrequency(118.7, CFrequencyUnit::MHz()),
geoPos, CLength(100, CLengthUnit::km()), false, dtFrom2, dtUntil2); geoPos, CLength(100, CLengthUnit::km()), false, dtFrom2, dtUntil2);
qDebug() << station1 << station2 << (station1.getCallsign() == station2.getCallsign()); out << station1 << " " << station2 << " " << (station1.getCallsign() == station2.getCallsign()) << endl;
// User parsing
CUser user("12345", "Joe KING KGLC");
out << user.getRealName() << user.getHomebase() << endl;
// ATC List // ATC List
CAtcStationList atcList; CAtcStationList atcList;
@@ -83,18 +90,18 @@ namespace BlackMiscTest
atcList.push_back(station3); atcList.push_back(station3);
atcList = atcList.findBy(&CAtcStation::getCallsign, "eddm_twr", &CAtcStation::getFrequency, CFrequency(118.7, CFrequencyUnit::MHz())); atcList = atcList.findBy(&CAtcStation::getCallsign, "eddm_twr", &CAtcStation::getFrequency, CFrequency(118.7, CFrequencyUnit::MHz()));
atcList = atcList.sortedBy(&CAtcStation::getBookedFromUtc, &CAtcStation::getCallsign, &CAtcStation::getControllerRealName); atcList = atcList.sortedBy(&CAtcStation::getBookedFromUtc, &CAtcStation::getCallsign, &CAtcStation::getControllerRealName);
qDebug() << atcList; out << atcList << endl;
qDebug() << "-----------------------------------------------"; out << "-----------------------------------------------" << endl;
// flight plan // flight plan
CAltitude alt("FL110"); CAltitude alt("FL110");
CAltitude altMsl(alt); CAltitude altMsl(alt);
altMsl.toMeanSeaLevel(); altMsl.toMeanSeaLevel();
qDebug() << alt << altMsl; out << alt << " " << altMsl << endl;
CAirportIcao frankfurt("eddf"); CAirportIcao frankfurt("eddf");
qDebug() << frankfurt; out << frankfurt << endl;
qDebug() << "-----------------------------------------------"; out << "-----------------------------------------------" << endl;
return 0; return 0;
} }

View File

@@ -1,11 +1,19 @@
/* Copyright (C) 2013 VATSIM Community / contributors /* Copyright (C) 2015
* This Source Code Form is subject to the terms of the Mozilla Public * swift project Community / Contributors
* License, v. 2.0. If a copy of the MPL was not distributed with this *
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ * 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 BLACKMISCTEST_SAMPLESAVIATION_H #ifndef BLACKMISCTEST_SAMPLESAVIATION_H
#define BLACKMISCTEST_SAMPLESAVIATION_H #define BLACKMISCTEST_SAMPLESAVIATION_H
#include <QTextStream>
namespace BlackMiscTest namespace BlackMiscTest
{ {
@@ -14,7 +22,7 @@ namespace BlackMiscTest
{ {
public: public:
//! Run the samples //! Run the samples
static int samples(); static int samples(QTextStream &out);
}; };
} // namespace } // namespace

View File

@@ -1,7 +1,11 @@
/* Copyright (C) 2013 VATSIM Community / contributors /* Copyright (C) 2015
* This Source Code Form is subject to the terms of the Mozilla Public * swift project Community / Contributors
* License, v. 2.0. If a copy of the MPL was not distributed with this *
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ * 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 "samplesphysicalquantities.h" #include "samplesphysicalquantities.h"
#include "blackmisc/variant.h" #include "blackmisc/variant.h"
@@ -15,65 +19,65 @@ namespace BlackMiscTest
/** /**
* Running the quantities * Running the quantities
*/ */
int CSamplesPhysicalQuantities::samples() int CSamplesPhysicalQuantities::samples(QTextStream &out)
{ {
// parsing // parsing
CSpeed parsedPq1 = CPqString::parseToVariant("100.123 km/h").value<CSpeed>(); CSpeed parsedPq1 = CPqString::parseToVariant("100.123 km/h").value<CSpeed>();
CLength parsedPq2 = CPqString::parseToVariant("-33.123ft").value<CLength>(); CLength parsedPq2 = CPqString::parseToVariant("-33.123ft").value<CLength>();
CVariant parsedPq3 = CPqString::parseToVariant("666"); CVariant parsedPq3 = CPqString::parseToVariant("666");
qDebug() << "parsed" << parsedPq1 << parsedPq2 << parsedPq3; out << "parsed" << " " << parsedPq1 << " " << parsedPq2 << " " << parsedPq3 << endl;
CSpeed speedParsed = CPqString::parse<CSpeed>("111.33ft/s"); CSpeed speedParsed = CPqString::parse<CSpeed>("111.33ft/s");
CFrequency frequencyParsed = CPqString::parse<CFrequency>("122.8MHz"); CFrequency frequencyParsed = CPqString::parse<CFrequency>("122.8MHz");
qDebug() << "parsed" << speedParsed << speedParsed.valueRoundedWithUnit(2, true) << frequencyParsed << frequencyParsed.valueRoundedWithUnit(2, true); out << "parsed" << " " << speedParsed << " " << speedParsed.valueRoundedWithUnit(2, true) << frequencyParsed << " " << frequencyParsed.valueRoundedWithUnit(2, true) << endl;
// the time clasas // the time clasas
CTime time1; CTime time1;
time1.parseFromString("11:30"); // hhmm time1.parseFromString("11:30"); // hhmm
qDebug() << time1 << time1.toQTime() << time1.formattedHrsMin(); out << time1 << " " << time1.toQTime().toString() << " " << time1.formattedHrsMin() << endl;
CTime time2; CTime time2;
time2.parseFromString("-11:30"); // hhmm time2.parseFromString("-11:30"); // hhmm
qDebug() << time2 << time2.toQTime() << time2.formattedHrsMin(); out << time2 << " " << time2.toQTime().toString() << " " << time2.formattedHrsMin() << endl;
time1 += time2; time1 += time2;
qDebug() << time1 << time1.toQTime() << time1.formattedHrsMin(); out << "0 time: " << time1 << " " << time1.toQTime().toString() << " " << time1.formattedHrsMin() << endl;
// standard tests // standard tests
CLengthUnit lu1(CLengthUnit::cm()); CLengthUnit lu1(CLengthUnit::cm());
CLengthUnit lu2(CLengthUnit::ft()); CLengthUnit lu2(CLengthUnit::ft());
QString lu1s = lu1.toQString(true); QString lu1s = lu1.toQString(true);
QString lu2s = lu2.toQString(true); QString lu2s = lu2.toQString(true);
qDebug() << lu1 << lu2 << lu1s << lu2s << lu1.getName(true) << lu2.getName(true); out << "units: " << lu1 << " " << lu2 << " " << lu1s << " " << lu2s << " " << lu1.getName(true) << " " << lu2.getName(true) << endl;
const CLength l1(5.0, CLengthUnit::ft()); // 5 ft const CLength l1(5.0, CLengthUnit::ft()); // 5 ft
CLength l2(1, CLengthUnit::NM()); // 1NM CLength l2(1, CLengthUnit::NM()); // 1NM
CLength l3(1, CLengthUnit::km()); CLength l3(1, CLengthUnit::km());
CLength l4(l3); CLength l4(l3);
qDebug() << CLengthUnit::ft(); out << CLengthUnit::ft() << endl;
qDebug() << l1 << l2 << l3 << l4; out << l1 << " " << l2 << " " << l3 << " " << l4 << endl;
qDebug() << l1.valueRoundedWithUnit(CLengthUnit::ft(), 5) out << l1.valueRoundedWithUnit(CLengthUnit::ft(), 5)
<< l2.valueRoundedWithUnit(CLengthUnit::km()); << " " << l2.valueRoundedWithUnit(CLengthUnit::km()) << endl;
qDebug() << l3.getUnit(); out << l3.getUnit() << endl;
l2.switchUnit(CLengthUnit::ft()); // now in ft l2.switchUnit(CLengthUnit::ft()); // now in ft
l3 += l3; // 2km now l3 += l3; // 2km now
l3 *= 1.5;// 3km now l3 *= 1.5;// 3km now
qDebug() << l2 << l3; out << l2 << " " << l3 << endl;
l3 = l3 * 2; l3 = l3 * 2;
qDebug() << "doubled l3:" << l3; out << "doubled l3: " << l3 << endl;
// more tests // more tests
CFrequency f1(1E6, CFrequencyUnit::Hz()); // 1MHz CFrequency f1(1E6, CFrequencyUnit::Hz()); // 1MHz
qDebug() << f1 << f1.valueRoundedWithUnit(CFrequencyUnit::MHz()) << f1.valueRoundedWithUnit(CFrequencyUnit::GHz(), 3); out << f1 << " " << f1.valueRoundedWithUnit(CFrequencyUnit::MHz()) << " " << f1.valueRoundedWithUnit(CFrequencyUnit::GHz(), 3);
CSpeed s1 = CSpeed(100, CSpeedUnit::km_h()); CSpeed s1 = CSpeed(100, CSpeedUnit::km_h());
CSpeed s2 = CSpeed(1000, CSpeedUnit::ft_min()); CSpeed s2 = CSpeed(1000, CSpeedUnit::ft_min());
CSpeed s3 = CSpeed(s2); CSpeed s3 = CSpeed(s2);
s3.switchUnit(CSpeedUnit::m_s()); s3.switchUnit(CSpeedUnit::m_s());
qDebug() << s1 << s1.valueRoundedWithUnit(CSpeedUnit::defaultUnit()) << s1.valueRoundedWithUnit(CSpeedUnit::NM_h()); out << s1 << " " << s1.valueRoundedWithUnit(CSpeedUnit::defaultUnit()) << " " << s1.valueRoundedWithUnit(CSpeedUnit::NM_h());
qDebug() << s2 << s3; out << s2 << " " << s3 << endl;
CAngle a1(180, CAngleUnit::deg()); CAngle a1(180, CAngleUnit::deg());
CAngle a2(1.5 * CAngle::PI(), CAngleUnit::rad()); CAngle a2(1.5 * CAngle::PI(), CAngleUnit::rad());
@@ -81,36 +85,36 @@ namespace BlackMiscTest
CAngle a4(35.4336, CAngleUnit::sexagesimalDeg()); // 35.72666 CAngle a4(35.4336, CAngleUnit::sexagesimalDeg()); // 35.72666
a1 += a2; a1 += a2;
// a1 = d2; // must not work // a1 = d2; // must not work
qDebug() << a1; out << a1;
a1.switchUnit(CAngleUnit::deg()); a1.switchUnit(CAngleUnit::deg());
// a2 += d1; // must not work // a2 += d1; // must not work
a2 = a1 + a1; a2 = a1 + a1;
a2.switchUnit(CAngleUnit::deg()); a2.switchUnit(CAngleUnit::deg());
qDebug() << a1.valueRoundedWithUnit() << a1.piFactor(); out << a1.valueRoundedWithUnit() << " " << a1.piFactor() << endl;
qDebug() << a2; out << a2 << endl;
a3.switchUnit(CAngleUnit::sexagesimalDeg()); a3.switchUnit(CAngleUnit::sexagesimalDeg());
a4.switchUnit(CAngleUnit::deg()); a4.switchUnit(CAngleUnit::deg());
qDebug() << a3 << a4; out << a3 << " " << a4 << endl;
CMass w1(1, CMassUnit::tonne()); CMass w1(1, CMassUnit::tonne());
CMass w2(w1); CMass w2(w1);
w2.switchUnit(CMassUnit::lb()); w2.switchUnit(CMassUnit::lb());
qDebug() << w1 << w1.valueRoundedWithUnit(CMassUnit::kg()) << w2; out << w1 << " " << w1.valueRoundedWithUnit(CMassUnit::kg()) << " " << w2 << endl;
CPressure p1(1013.25, CPressureUnit::hPa()); CPressure p1(1013.25, CPressureUnit::hPa());
qDebug() << p1 << p1.valueRoundedWithUnit(CPressureUnit::psi()) << p1.valueRoundedWithUnit(CPressureUnit::inHg()); out << p1 << " " << p1.valueRoundedWithUnit(CPressureUnit::psi()) << " " << p1.valueRoundedWithUnit(CPressureUnit::inHg()) << endl;
CTemperature t1; CTemperature t1;
CTemperature t2(20, CTemperatureUnit::C()); CTemperature t2(20, CTemperatureUnit::C());
CTemperature t3(1, CTemperatureUnit::F()); CTemperature t3(1, CTemperatureUnit::F());
qDebug() << t1 << t2 << t2.valueRoundedWithUnit(CTemperatureUnit::defaultUnit(), -1, true); out << t1 << " " << t2 << " " << t2.valueRoundedWithUnit(CTemperatureUnit::defaultUnit(), -1, true);
qDebug() << t3.valueRoundedWithUnit(CTemperatureUnit::F(), -1, true) << t3.valueRoundedWithUnit(CTemperatureUnit::C(), -1, true) << "I18N/UTF"; out << t3.valueRoundedWithUnit(CTemperatureUnit::F(), -1, true) << " " << t3.valueRoundedWithUnit(CTemperatureUnit::C(), -1, true) << " " << "I18N/UTF" << endl;
(t1 - t2).switchUnit(CTemperatureUnit::F()); // was not working since wrong return type const (t1 - t2).switchUnit(CTemperatureUnit::F()); // was not working since wrong return type const
// CLengthUnit duA(CSpeedUnit::ft_min()); // no longer possible // CLengthUnit duA(CSpeedUnit::ft_min()); // no longer possible
CLengthUnit duB(CLengthUnit::cm()); CLengthUnit duB(CLengthUnit::cm());
qDebug() << duB; out << duB << endl;
CTime ti1(1, CTimeUnit::h()); CTime ti1(1, CTimeUnit::h());
CTime ti2(ti1); CTime ti2(ti1);
@@ -122,14 +126,14 @@ namespace BlackMiscTest
CTime ti7("20s"); CTime ti7("20s");
CTime ti8("12:30:40"); CTime ti8("12:30:40");
qDebug() << ti1 << ti2 << ti3 << ti4 << ti5; out << ti1 << " " << ti2 << " " << ti3 << " " << ti4 << " " << ti5 << endl;
qDebug() << ti6 << ti7 << ti8; out << ti6 << " " << ti7 << " " << ti8 << endl;
CAcceleration ac1(10, CAccelerationUnit::m_s2()); CAcceleration ac1(10, CAccelerationUnit::m_s2());
qDebug() << ac1 << ac1.toQString(true) << ac1.valueRoundedWithUnit(-1, true) << "I18N/UTF"; out << ac1 << " " << ac1.toQString(true) << " " << ac1.valueRoundedWithUnit(-1, true) << " " << "I18N/UTF" << endl;
// bye // bye
qDebug() << "-----------------------------------------------"; out << "-----------------------------------------------" << endl;
return 0; return 0;
} }

View File

@@ -1,27 +1,31 @@
/* Copyright (C) 2013 VATSIM Community / authors /* Copyright (C) 2015
* This Source Code Form is subject to the terms of the Mozilla Public * swift project Community / Contributors
* License, v. 2.0. If a copy of the MPL was not distributed with this *
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ * 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 BLACKMISCTEST_SAMPLESPHYSICALQUANTITIES_H #ifndef BLACKMISCTEST_SAMPLESPHYSICALQUANTITIES_H
#define BLACKMISCTEST_SAMPLESPHYSICALQUANTITIES_H #define BLACKMISCTEST_SAMPLESPHYSICALQUANTITIES_H
#include "blackmisc/pqconstants.h" #include "blackmisc/pqconstants.h"
#include <QDebug> #include <QDebug>
#include <QTextStream>
namespace BlackMiscTest { namespace BlackMiscTest
/*!
* \brief Samples for physical quantities
*/
class CSamplesPhysicalQuantities
{ {
public:
/*! //! Samples for physical quantities
* \brief Run the samples class CSamplesPhysicalQuantities
*/ {
static int samples(); public:
}; //! Run the samples
static int samples(QTextStream &out);
};
} }
#endif // guard #endif // guard