Moved some samples into unit tests

This commit is contained in:
Klaus Basan
2015-05-30 01:55:04 +02:00
parent 4cafc259bb
commit dc918dfaba
16 changed files with 310 additions and 263 deletions

View File

@@ -27,7 +27,6 @@ int main(int argc, char *argv[])
bool t = translator.load("blackmisc_i18n_de", ":blackmisc/translations/"); bool t = translator.load("blackmisc_i18n_de", ":blackmisc/translations/");
out << (t ? "Translator loaded" : "Translator not loaded") << endl; out << (t ? "Translator loaded" : "Translator not loaded") << endl;
QCoreApplication a(argc, argv); QCoreApplication a(argc, argv);
out << "Use I18N version, y? n?"; out << "Use I18N version, y? n?";
out.flush(); out.flush();

View File

@@ -16,33 +16,11 @@ using namespace BlackMisc::PhysicalQuantities;
namespace BlackMiscTest namespace BlackMiscTest
{ {
/** /*
* Running the quantities * Running the quantities
*/ */
int CSamplesPhysicalQuantities::samples(QTextStream &out) int CSamplesPhysicalQuantities::samples(QTextStream &out)
{ {
// parsing
CSpeed parsedPq1 = CPqString::parseToVariant("100.123 km/h").value<CSpeed>();
CLength parsedPq2 = CPqString::parseToVariant("-33.123ft").value<CLength>();
CVariant parsedPq3 = CPqString::parseToVariant("666");
out << "parsed" << " " << parsedPq1 << " " << parsedPq2 << " " << parsedPq3 << endl;
CSpeed speedParsed = CPqString::parse<CSpeed>("111.33ft/s");
CFrequency frequencyParsed = CPqString::parse<CFrequency>("122.8MHz");
out << "parsed" << " " << speedParsed << " " << speedParsed.valueRoundedWithUnit(2, true) << frequencyParsed << " " << frequencyParsed.valueRoundedWithUnit(2, true) << endl;
// the time clasas
CTime time1;
time1.parseFromString("11:30"); // hhmm
out << time1 << " " << time1.toQTime().toString() << " " << time1.formattedHrsMin() << endl;
CTime time2;
time2.parseFromString("-11:30"); // hhmm
out << time2 << " " << time2.toQTime().toString() << " " << time2.formattedHrsMin() << endl;
time1 += time2;
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());
@@ -56,8 +34,7 @@ namespace BlackMiscTest
out << CLengthUnit::ft() << endl; out << CLengthUnit::ft() << endl;
out << l1 << " " << l2 << " " << l3 << " " << l4 << endl; out << l1 << " " << l2 << " " << l3 << " " << l4 << endl;
out << l1.valueRoundedWithUnit(CLengthUnit::ft(), 5) out << l1.valueRoundedWithUnit(CLengthUnit::ft(), 5) << " " << l2.valueRoundedWithUnit(CLengthUnit::km()) << endl;
<< " " << l2.valueRoundedWithUnit(CLengthUnit::km()) << endl;
out << l3.getUnit() << endl; out << l3.getUnit() << endl;
l2.switchUnit(CLengthUnit::ft()); // now in ft l2.switchUnit(CLengthUnit::ft()); // now in ft

View File

@@ -1,7 +1,11 @@
/* Copyright (C) 2013 VATSIM Community / contributors /* Copyright (C) 2013
* 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 "expect.h" #include "expect.h"
#include <QCoreApplication> #include <QCoreApplication>

View File

@@ -1,7 +1,13 @@
/* Copyright (C) 2013 VATSIM Community / contributors /* Copyright (C) 2013
* 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 BLACKCORETEST_EXPECT_H #ifndef BLACKCORETEST_EXPECT_H
#define BLACKCORETEST_EXPECT_H #define BLACKCORETEST_EXPECT_H
@@ -15,7 +21,6 @@
namespace BlackCoreTest namespace BlackCoreTest
{ {
class Expect; class Expect;
//! Class representing a position in a source code file, for error reporting. Used in combination with the SOURCE_LOCATION macro. //! Class representing a position in a source code file, for error reporting. Used in combination with the SOURCE_LOCATION macro.
@@ -88,7 +93,8 @@ public:
{ {
auto subj = subject<F1>(); auto subj = subject<F1>();
auto next = [ = ] { this->next(); }; auto next = [ = ] { this->next(); };
m_expects.push_back([=]{ m_expects.push_back([ = ]
{
m_waitingFor = subj->metaObject()->className(); m_waitingFor = subj->metaObject()->className();
m_waitingFor += "::"; m_waitingFor += "::";
m_waitingFor += QMetaMethod::fromSignal(signal).name(); m_waitingFor += QMetaMethod::fromSignal(signal).name();
@@ -218,6 +224,6 @@ private:
#define EXPECT_WAIT_5(EXP, TIME, U1, U2, U3, U4, U5) ((EXP).wait(SOURCE_LOCATION, (TIME), (U1), (U2), (U3), (U4), (U5))) #define EXPECT_WAIT_5(EXP, TIME, U1, U2, U3, U4, U5) ((EXP).wait(SOURCE_LOCATION, (TIME), (U1), (U2), (U3), (U4), (U5)))
//! @} //! @}
} //namespace BlackCoreTest } // ns
#endif //BLACKCORETEST_EXPECT_H #endif // guard

View File

@@ -1,7 +1,13 @@
/* Copyright (C) 2013 VATSIM Community / contributors /* Copyright (C) 2013
* 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 BLACKCORETEST_TESTMAIN_H #ifndef BLACKCORETEST_TESTMAIN_H
#define BLACKCORETEST_TESTMAIN_H #define BLACKCORETEST_TESTMAIN_H
@@ -20,12 +26,7 @@ namespace BlackCoreTest
class CBlackCoreTestMain class CBlackCoreTestMain
{ {
public: public:
/*! //! Unit tests
* \brief Starting all
* \param argc
* \param argv
* \return
*/
static int unitMain(int argc, char *argv[]); static int unitMain(int argc, char *argv[]);
}; };
} }

View File

@@ -1,3 +1,12 @@
/* Copyright (C) 2013
* 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 "testblackmiscmain.h" #include "testblackmiscmain.h"
#include "blackmisc/blackmiscfreefunctions.h" #include "blackmisc/blackmiscfreefunctions.h"
#include <QCoreApplication> #include <QCoreApplication>

View File

@@ -1,7 +1,11 @@
/* Copyright (C) 2013 VATSIM Community / authors /* Copyright (C) 2013
* 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 "testaviation.h" #include "testaviation.h"
#include "blackmisc/pq/constants.h" #include "blackmisc/pq/constants.h"

View File

@@ -1,5 +1,5 @@
/* Copyright (C) 2014 /* Copyright (C) 2013
* swift project community / contributors * 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 * 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, * directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project,

View File

@@ -1,7 +1,11 @@
/* Copyright (C) 2013 VATSIM Community / contributors /* Copyright (C) 2013
* 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 "testphysicalquantities.h" #include "testphysicalquantities.h"
#include "testaviation.h" #include "testaviation.h"

View File

@@ -7,8 +7,6 @@
* contained in the LICENSE file. * contained in the LICENSE file.
*/ */
//! \file
#include "testcontainers.h" #include "testcontainers.h"
#include "testvalueobject.h" #include "testvalueobject.h"
#include "blackmisc/blackmiscfreefunctions.h" #include "blackmisc/blackmiscfreefunctions.h"

View File

@@ -1,3 +1,12 @@
/* Copyright (C) 2013
* 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 "testgeo.h" #include "testgeo.h"
#include "blackmisc/geo/latitude.h" #include "blackmisc/geo/latitude.h"
#include "blackmisc/geo/longitude.h" #include "blackmisc/geo/longitude.h"
@@ -6,10 +15,8 @@ using namespace BlackMisc::Geo;
using namespace BlackMisc::PhysicalQuantities; using namespace BlackMisc::PhysicalQuantities;
using namespace BlackMisc::Math; using namespace BlackMisc::Math;
namespace BlackMiscTest namespace BlackMiscTest
{ {
/* /*
* Geo classes tests * Geo classes tests
*/ */

View File

@@ -1,7 +1,11 @@
/* Copyright (C) 2013 VATSIM Community / authors /* Copyright (C) 2013
* 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 "testhardware.h" #include "testhardware.h"
#include "blackmisc/hardware/keyboardkey.h" #include "blackmisc/hardware/keyboardkey.h"

View File

@@ -7,8 +7,6 @@
* contained in the LICENSE file. * contained in the LICENSE file.
*/ */
//! \file
#include "testoriginator.h" #include "testoriginator.h"
#include "blackmisc/blackmiscfreefunctions.h" #include "blackmisc/blackmiscfreefunctions.h"
#include "blackmisc/originatorlist.h" #include "blackmisc/originatorlist.h"

View File

@@ -1,7 +1,11 @@
/* Copyright (C) 2013 VATSIM Community / contributors /* Copyright (C) 2013
* 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 "testphysicalquantities.h" #include "testphysicalquantities.h"
@@ -175,8 +179,7 @@ namespace BlackMiscTest
a1.switchUnit(CAccelerationUnit::ft_s2()); a1.switchUnit(CAccelerationUnit::ft_s2());
QVERIFY2(a1 == a2, "Accelerations should be similar"); QVERIFY2(a1 == a2, "Accelerations should be similar");
QVERIFY2(CMathUtils::epsilonEqual(BlackMisc::Math::CMathUtils::round(a2.value() * ftFactor, 6), QVERIFY2(CMathUtils::epsilonEqual(BlackMisc::Math::CMathUtils::round(a2.value() * ftFactor, 6),
a1.valueRounded(6)), a1.valueRounded(6)), "Numerical values should be equal");
"Numerical values should be equal");
} }
/* /*
@@ -207,6 +210,17 @@ namespace BlackMiscTest
QVERIFY2(CLength(-22.8, CLengthUnit::ft()) != CLength("-22.8 cm"), "Length !="); QVERIFY2(CLength(-22.8, CLengthUnit::ft()) != CLength("-22.8 cm"), "Length !=");
QVERIFY2(CSpeed(123.45, CSpeedUnit::km_h()) == CSpeed("123.45km/h"), "Speed"); QVERIFY2(CSpeed(123.45, CSpeedUnit::km_h()) == CSpeed("123.45km/h"), "Speed");
QVERIFY2(CMass(33.45, CMassUnit::kg()) == CMass("33.45000 kg"), "CMass"); QVERIFY2(CMass(33.45, CMassUnit::kg()) == CMass("33.45000 kg"), "CMass");
// parsing via variant
CSpeed parsedPq1 = CPqString::parseToVariant("100.123 km/h").value<CSpeed>();
QVERIFY2(CSpeed(100.123, CSpeedUnit::km_h()) == parsedPq1, "Parsed speed via variant");
CLength parsedPq2 = CPqString::parseToVariant("-33.123ft").value<CLength>();
QVERIFY2(CLength(-33.123, CLengthUnit::ft()) == parsedPq2, "Parsed length via variant");
CFrequency parsedPq3 = CPqString::parse<CFrequency>("122.8MHz");
QVERIFY2(CFrequency(122.8, CFrequencyUnit::MHz()) == parsedPq3, "Parsed frequency via variant");
} }
/* /*
@@ -214,6 +228,7 @@ namespace BlackMiscTest
*/ */
void CTestPhysicalQuantities::basicArithmetic() void CTestPhysicalQuantities::basicArithmetic()
{ {
// pressure
CPressure p1 = CPhysicalQuantitiesConstants::ISASeaLevelPressure(); CPressure p1 = CPhysicalQuantitiesConstants::ISASeaLevelPressure();
CPressure p2(p1); CPressure p2(p1);
p2 *= 2.0; p2 *= 2.0;
@@ -225,5 +240,22 @@ namespace BlackMiscTest
QVERIFY2(p3.value() == 0, "Value needs to be zero"); QVERIFY2(p3.value() == 0, "Value needs to be zero");
p3 = CPressure(1013, CPressureUnit::hPa()); p3 = CPressure(1013, CPressureUnit::hPa());
QVERIFY2(p3 * 1.5 == 1.5 * p3, "Basic commutative test on PQ failed"); QVERIFY2(p3 * 1.5 == 1.5 * p3, "Basic commutative test on PQ failed");
// the time clasas
CTime time1;
time1.parseFromString("11:30"); // hhmm
CTime time2;
time2.parseFromString("-11:30"); // hhmm
CTime time3 = time1 + time2;
QVERIFY2(time3.isZeroEpsilonConsidered(), "Time must be 0");
// angle
CAngle a1(180, CAngleUnit::deg());
CAngle a2(1.5 * CAngle::PI(), CAngleUnit::rad());
a1 += a2;
QVERIFY2(a1.valueInteger(CAngleUnit::deg()) == 450, "Expect 450 degrees");
} }
} // namespace } // namespace

View File

@@ -1,5 +1,5 @@
/* Copyright (C) 2014 /* Copyright (C) 2013
* swift project community / contributors * 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 * 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, * directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project,

View File

@@ -1,7 +1,11 @@
/* Copyright (C) 2013 VATSIM Community / contributors /* Copyright (C) 2013
* 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 "testvariantandmap.h" #include "testvariantandmap.h"
#include "blackmisc/aviation/atcstation.h" #include "blackmisc/aviation/atcstation.h"