diff --git a/samples/blackmiscquantities/main.cpp b/samples/blackmiscquantities/main.cpp index 92d681596..debc4a382 100644 --- a/samples/blackmiscquantities/main.cpp +++ b/samples/blackmiscquantities/main.cpp @@ -27,7 +27,6 @@ int main(int argc, char *argv[]) bool t = translator.load("blackmisc_i18n_de", ":blackmisc/translations/"); out << (t ? "Translator loaded" : "Translator not loaded") << endl; - QCoreApplication a(argc, argv); out << "Use I18N version, y? n?"; out.flush(); diff --git a/samples/blackmiscquantities/samplesphysicalquantities.cpp b/samples/blackmiscquantities/samplesphysicalquantities.cpp index a6ee0799e..fb0f3b74b 100644 --- a/samples/blackmiscquantities/samplesphysicalquantities.cpp +++ b/samples/blackmiscquantities/samplesphysicalquantities.cpp @@ -16,33 +16,11 @@ using namespace BlackMisc::PhysicalQuantities; namespace BlackMiscTest { - /** + /* * Running the quantities */ int CSamplesPhysicalQuantities::samples(QTextStream &out) { - // parsing - CSpeed parsedPq1 = CPqString::parseToVariant("100.123 km/h").value(); - CLength parsedPq2 = CPqString::parseToVariant("-33.123ft").value(); - CVariant parsedPq3 = CPqString::parseToVariant("666"); - out << "parsed" << " " << parsedPq1 << " " << parsedPq2 << " " << parsedPq3 << endl; - - CSpeed speedParsed = CPqString::parse("111.33ft/s"); - CFrequency frequencyParsed = CPqString::parse("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 CLengthUnit lu1(CLengthUnit::cm()); CLengthUnit lu2(CLengthUnit::ft()); @@ -56,8 +34,7 @@ namespace BlackMiscTest out << CLengthUnit::ft() << endl; out << l1 << " " << l2 << " " << l3 << " " << l4 << endl; - out << l1.valueRoundedWithUnit(CLengthUnit::ft(), 5) - << " " << l2.valueRoundedWithUnit(CLengthUnit::km()) << endl; + out << l1.valueRoundedWithUnit(CLengthUnit::ft(), 5) << " " << l2.valueRoundedWithUnit(CLengthUnit::km()) << endl; out << l3.getUnit() << endl; l2.switchUnit(CLengthUnit::ft()); // now in ft diff --git a/tests/blackcore/expect.cpp b/tests/blackcore/expect.cpp index fc9bf6f08..8b213ae95 100644 --- a/tests/blackcore/expect.cpp +++ b/tests/blackcore/expect.cpp @@ -1,7 +1,11 @@ -/* Copyright (C) 2013 VATSIM Community / contributors - * This Source Code Form is subject to the terms of the Mozilla Public - * 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/. */ +/* 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 "expect.h" #include diff --git a/tests/blackcore/expect.h b/tests/blackcore/expect.h index c1402f866..27aee8bca 100644 --- a/tests/blackcore/expect.h +++ b/tests/blackcore/expect.h @@ -1,7 +1,13 @@ -/* Copyright (C) 2013 VATSIM Community / contributors - * This Source Code Form is subject to the terms of the Mozilla Public - * 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/. */ +/* 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. + */ + +//! \file #ifndef BLACKCORETEST_EXPECT_H #define BLACKCORETEST_EXPECT_H @@ -15,202 +21,202 @@ 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 SourceLocation -{ -public: - SourceLocation(const QString& f, int ln) : file(f), line(ln) {} //!< Constructor - const QString file; //!< Source code filename - const int line; //!< Line number -}; + //! Class representing a position in a source code file, for error reporting. Used in combination with the SOURCE_LOCATION macro. + class SourceLocation + { + public: + SourceLocation(const QString &f, int ln) : file(f), line(ln) {} //!< Constructor + const QString file; //!< Source code filename + const int line; //!< Line number + }; //! Evaluates to an instance of SourceLocation representing the position where the macro is used. #define SOURCE_LOCATION (BlackCoreTest::SourceLocation(__FILE__, __LINE__)) //! RAII class for Qt signal/slot connections. All connections are closed when object is destroyed. -class ConnectGuard -{ -public: - //! Constructor. - ConnectGuard() {} - - //! Destructor. - ~ConnectGuard() { cleanup(); } - - //! Add a connection to the object. - ConnectGuard& operator+= (const QMetaObject::Connection& conn) { m_conns += conn; return *this; } - - //! Disconnect and remove all stored connections. - void cleanup() { for (auto i = m_conns.begin(); i != m_conns.end(); ++i) QObject::disconnect(*i); m_conns.clear(); } - - //! Copying is only allowed when there are no connections stored. - //! @{ - ConnectGuard(const ConnectGuard& other) { Q_ASSERT(other.m_conns.isEmpty()); Q_UNUSED(other); } - ConnectGuard& operator= (const ConnectGuard& other) { Q_ASSERT(other.m_conns.isEmpty()); Q_UNUSED(other); return *this; } - //! @} - -private: - QVector m_conns; -}; - -/*! - * One unit of expectation, as returned by Expect::unit(). - * - * Contains a sequence of signals to send, and a sequence of signals that are expected to be received in reply. - */ -class ExpectUnit -{ -public: - /*! - * Adds a signal to the list of signals to send, with optional arguments. - * \param slot A pointer-to-member-function of the subject class. - * \return this object, so methods can be chained. - */ - //! @{ - template ExpectUnit& send(F slot) { m_sends.push_back(std::bind(slot, subject())); return *this; } - template ExpectUnit& send(F slot, T1 arg1) { m_sends.push_back(std::bind(slot, subject(), arg1)); return *this; } - template ExpectUnit& send(F slot, T1 arg1, T2 arg2) { m_sends.push_back(std::bind(slot, subject(), arg1, arg2)); return *this; } - template ExpectUnit& send(F slot, T1 arg1, T2 arg2, T3 arg3) { m_sends.push_back(std::bind(slot, subject(), arg1, arg2, arg3)); return *this; } - template ExpectUnit& send(F slot, T1 arg1, T2 arg2, T3 arg3, T4 arg4) { m_sends.push_back(std::bind(slot, subject(), arg1, arg2, arg3, arg4)); return *this; } - template ExpectUnit& send(F slot, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5) { m_sends.push_back(std::bind(slot, subject(), arg1, arg2, arg3, arg4, arg5)); return *this; } - //! @} - - /*! - * Adds a signal to the list of signals which are expects to be received. - * \param signal A pointer-to-member-function of the subject class. - * \param slot A callable object which will be connected to the signal, e.g. to validate the signal arguments. - * \return this object, so methods can be chained. - */ - template ExpectUnit& expect(F1 signal, F2 slot) + class ConnectGuard { - auto subj = subject(); - auto next = [=]{ this->next(); }; - m_expects.push_back([=]{ - m_waitingFor = subj->metaObject()->className(); - m_waitingFor += "::"; - m_waitingFor += QMetaMethod::fromSignal(signal).name(); - m_guard += QObject::connect(subj, signal, slot); - m_guard += QObject::connect(subj, signal, next); - }); - return *this; - } + public: + //! Constructor. + ConnectGuard() {} + + //! Destructor. + ~ConnectGuard() { cleanup(); } + + //! Add a connection to the object. + ConnectGuard &operator+= (const QMetaObject::Connection &conn) { m_conns += conn; return *this; } + + //! Disconnect and remove all stored connections. + void cleanup() { for (auto i = m_conns.begin(); i != m_conns.end(); ++i) QObject::disconnect(*i); m_conns.clear(); } + + //! Copying is only allowed when there are no connections stored. + //! @{ + ConnectGuard(const ConnectGuard &other) { Q_ASSERT(other.m_conns.isEmpty()); Q_UNUSED(other); } + ConnectGuard &operator= (const ConnectGuard &other) { Q_ASSERT(other.m_conns.isEmpty()); Q_UNUSED(other); return *this; } + //! @} + + private: + QVector m_conns; + }; /*! - * Adds a signal to the list of signals which are expected to be received. - * \param signal A pointer-to-member-function of the subject class. - * \return this object, so methods can be chained. + * One unit of expectation, as returned by Expect::unit(). + * + * Contains a sequence of signals to send, and a sequence of signals that are expected to be received in reply. */ - template ExpectUnit& expect(F signal) { return expect(signal, []{}); } - - /*! - * Sends all the queued signals, then waits for each of the expected signals in sequence. - * If the full sequence of expected signals is not received, calls QTest::qFail(). - * \param timeout Time to wait in seconds. Qt event queue is processed when waiting. - */ - void wait(int timeout); - -private: - friend class Expect; - - ExpectUnit(Expect* parent, QObject* subject, const SourceLocation& srcloc) : m_parent(parent), m_subject(subject), m_srcloc(srcloc) {} - - void init() const; - void next() const; - - QPointer m_parent; - QPointer m_subject; - SourceLocation m_srcloc; - QString m_waitingFor; - QVector> m_sends; - QVector> m_expects; - mutable QVector>::const_iterator m_nextExpect; - mutable ConnectGuard m_guard; - - mutable std::function m_onDone; - void onDone(std::function callback) const { m_onDone = callback; } - - // Helper traits class. Given T is a pointer-to-member-of-U, ClassOf::type is U. - template struct ClassOf; - template struct ClassOf { typedef U type; }; - - // Given T is a pointer-to-member-of-U, subject() returns Expect's subject casted to U*. - template typename ClassOf::type* subject() const { return qobject_cast::type*>(m_subject.data()); } -}; - -/*! - * Class for writing unit tests in which signals are sent to some object, and other signals are expected to be received in reply. - * Loosely modelled on the C library libexpect. - * - * Commonly used in combination with the macros EXPECT_UNIT or EXPECT_WAIT. - */ -class Expect : public QObject -{ - Q_OBJECT - -public: - /*! - * Constructor. - * \param testSubject The object to be tested. - */ - explicit Expect(QObject* testSubject) : m_subject(testSubject), m_failed(false) {} - - /*! - * Add a single expectation that will remain for the lifetime of the object. - * \param signal A pointer-to-member-function of the subject class. - * \param slot A callable object which will be connected to the signal, e.g. to validate the signal arguments. - */ - template void always(F1 signal, F2 slot) + class ExpectUnit { - m_guard += QObject::connect(m_subject, signal, slot); - } + public: + /*! + * Adds a signal to the list of signals to send, with optional arguments. + * \param slot A pointer-to-member-function of the subject class. + * \return this object, so methods can be chained. + */ + //! @{ + template ExpectUnit &send(F slot) { m_sends.push_back(std::bind(slot, subject())); return *this; } + template ExpectUnit &send(F slot, T1 arg1) { m_sends.push_back(std::bind(slot, subject(), arg1)); return *this; } + template ExpectUnit &send(F slot, T1 arg1, T2 arg2) { m_sends.push_back(std::bind(slot, subject(), arg1, arg2)); return *this; } + template ExpectUnit &send(F slot, T1 arg1, T2 arg2, T3 arg3) { m_sends.push_back(std::bind(slot, subject(), arg1, arg2, arg3)); return *this; } + template ExpectUnit &send(F slot, T1 arg1, T2 arg2, T3 arg3, T4 arg4) { m_sends.push_back(std::bind(slot, subject(), arg1, arg2, arg3, arg4)); return *this; } + template ExpectUnit &send(F slot, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5) { m_sends.push_back(std::bind(slot, subject(), arg1, arg2, arg3, arg4, arg5)); return *this; } + //! @} + + /*! + * Adds a signal to the list of signals which are expects to be received. + * \param signal A pointer-to-member-function of the subject class. + * \param slot A callable object which will be connected to the signal, e.g. to validate the signal arguments. + * \return this object, so methods can be chained. + */ + template ExpectUnit &expect(F1 signal, F2 slot) + { + auto subj = subject(); + auto next = [ = ] { this->next(); }; + m_expects.push_back([ = ] + { + m_waitingFor = subj->metaObject()->className(); + m_waitingFor += "::"; + m_waitingFor += QMetaMethod::fromSignal(signal).name(); + m_guard += QObject::connect(subj, signal, slot); + m_guard += QObject::connect(subj, signal, next); + }); + return *this; + } + + /*! + * Adds a signal to the list of signals which are expected to be received. + * \param signal A pointer-to-member-function of the subject class. + * \return this object, so methods can be chained. + */ + template ExpectUnit &expect(F signal) { return expect(signal, [] {}); } + + /*! + * Sends all the queued signals, then waits for each of the expected signals in sequence. + * If the full sequence of expected signals is not received, calls QTest::qFail(). + * \param timeout Time to wait in seconds. Qt event queue is processed when waiting. + */ + void wait(int timeout); + + private: + friend class Expect; + + ExpectUnit(Expect *parent, QObject *subject, const SourceLocation &srcloc) : m_parent(parent), m_subject(subject), m_srcloc(srcloc) {} + + void init() const; + void next() const; + + QPointer m_parent; + QPointer m_subject; + SourceLocation m_srcloc; + QString m_waitingFor; + QVector> m_sends; + QVector> m_expects; + mutable QVector>::const_iterator m_nextExpect; + mutable ConnectGuard m_guard; + + mutable std::function m_onDone; + void onDone(std::function callback) const { m_onDone = callback; } + + // Helper traits class. Given T is a pointer-to-member-of-U, ClassOf::type is U. + template struct ClassOf; + template struct ClassOf { typedef U type; }; + + // Given T is a pointer-to-member-of-U, subject() returns Expect's subject casted to U*. + template typename ClassOf::type *subject() const { return qobject_cast::type *>(m_subject.data()); } + }; /*! - * Returns a new unit of expectation for the subject. Commonly called via the EXPECT_UNIT macro. - * \param srcloc Represents the caller's location in the source code, for error reporting. + * Class for writing unit tests in which signals are sent to some object, and other signals are expected to be received in reply. + * Loosely modelled on the C library libexpect. + * + * Commonly used in combination with the macros EXPECT_UNIT or EXPECT_WAIT. */ - ExpectUnit unit(const SourceLocation& srcloc = SOURCE_LOCATION) { return ExpectUnit(this, m_subject, srcloc); } + class Expect : public QObject + { + Q_OBJECT + + public: + /*! + * Constructor. + * \param testSubject The object to be tested. + */ + explicit Expect(QObject *testSubject) : m_subject(testSubject), m_failed(false) {} + + /*! + * Add a single expectation that will remain for the lifetime of the object. + * \param signal A pointer-to-member-function of the subject class. + * \param slot A callable object which will be connected to the signal, e.g. to validate the signal arguments. + */ + template void always(F1 signal, F2 slot) + { + m_guard += QObject::connect(m_subject, signal, slot); + } + + /*! + * Returns a new unit of expectation for the subject. Commonly called via the EXPECT_UNIT macro. + * \param srcloc Represents the caller's location in the source code, for error reporting. + */ + ExpectUnit unit(const SourceLocation &srcloc = SOURCE_LOCATION) { return ExpectUnit(this, m_subject, srcloc); } + + /*! + * Allows two or more units of expectation to be waited on simultaneously. Commonly valled via the EXPECT_WAIT macro. + * \param srcloc Represents the caller's location in the source code, for error reporting. + * \param timeout Time to wait in seconds. Qt event queue is processed when waiting. + */ + //! @{ + void wait(const SourceLocation &srcloc, int timeout, const ExpectUnit &u1) { m_units.insert(&u1); wait(srcloc, timeout); } + void wait(const SourceLocation &srcloc, int timeout, const ExpectUnit &u1, const ExpectUnit &u2) { m_units.insert(&u1); m_units.insert(&u2); wait(srcloc, timeout); } + void wait(const SourceLocation &srcloc, int timeout, const ExpectUnit &u1, const ExpectUnit &u2, const ExpectUnit &u3) { m_units.insert(&u1); m_units.insert(&u2); m_units.insert(&u3); wait(srcloc, timeout); } + void wait(const SourceLocation &srcloc, int timeout, const ExpectUnit &u1, const ExpectUnit &u2, const ExpectUnit &u3, const ExpectUnit &u4) { m_units.insert(&u1); m_units.insert(&u2); m_units.insert(&u3); m_units.insert(&u4); wait(srcloc, timeout); } + void wait(const SourceLocation &srcloc, int timeout, const ExpectUnit &u1, const ExpectUnit &u2, const ExpectUnit &u3, const ExpectUnit &u4, const ExpectUnit &u5) { m_units.insert(&u1); m_units.insert(&u2); m_units.insert(&u3); m_units.insert(&u4); m_units.insert(&u5); wait(srcloc, timeout); } + //! @} + + private: + friend class ExpectUnit; + + void wait(const SourceLocation &srcloc, int timeout); + void reportTimeout(const SourceLocation &srcloc, const QSet &units); + + QPointer m_subject; + QSet m_units; + ConnectGuard m_guard; + bool m_failed; + }; /*! - * Allows two or more units of expectation to be waited on simultaneously. Commonly valled via the EXPECT_WAIT macro. - * \param srcloc Represents the caller's location in the source code, for error reporting. - * \param timeout Time to wait in seconds. Qt event queue is processed when waiting. + * Wrapper for Expect::unit() which fills in the source location parameter. + * Returns a new unit of expectation for the subject. + * \param EXP Instance of Expect on which to call unit(). */ - //! @{ - void wait(const SourceLocation& srcloc, int timeout, const ExpectUnit& u1) { m_units.insert(&u1); wait(srcloc, timeout); } - void wait(const SourceLocation& srcloc, int timeout, const ExpectUnit& u1, const ExpectUnit& u2) { m_units.insert(&u1); m_units.insert(&u2); wait(srcloc, timeout); } - void wait(const SourceLocation& srcloc, int timeout, const ExpectUnit& u1, const ExpectUnit& u2, const ExpectUnit& u3) { m_units.insert(&u1); m_units.insert(&u2); m_units.insert(&u3); wait(srcloc, timeout); } - void wait(const SourceLocation& srcloc, int timeout, const ExpectUnit& u1, const ExpectUnit& u2, const ExpectUnit& u3, const ExpectUnit& u4) { m_units.insert(&u1); m_units.insert(&u2); m_units.insert(&u3); m_units.insert(&u4); wait(srcloc, timeout); } - void wait(const SourceLocation& srcloc, int timeout, const ExpectUnit& u1, const ExpectUnit& u2, const ExpectUnit& u3, const ExpectUnit& u4, const ExpectUnit& u5) { m_units.insert(&u1); m_units.insert(&u2); m_units.insert(&u3); m_units.insert(&u4); m_units.insert(&u5); wait(srcloc, timeout); } - //! @} - -private: - friend class ExpectUnit; - - void wait(const SourceLocation& srcloc, int timeout); - void reportTimeout(const SourceLocation& srcloc, const QSet& units); - - QPointer m_subject; - QSet m_units; - ConnectGuard m_guard; - bool m_failed; -}; - -/*! - * Wrapper for Expect::unit() which fills in the source location parameter. - * Returns a new unit of expectation for the subject. - * \param EXP Instance of Expect on which to call unit(). - */ #define EXPECT_UNIT(EXP) ((EXP).unit(SOURCE_LOCATION)) -/*! - * Wrapper for Expect::wait() which fills in the source location parameter. - * Allows two or more units of expectation to be waited on simultaneously. - * \param EXP Instance of Expect on which to call wait(). - * \param TIME Time to wait in seconds. Qt event queue is processed when waiting. - */ + /*! + * Wrapper for Expect::wait() which fills in the source location parameter. + * Allows two or more units of expectation to be waited on simultaneously. + * \param EXP Instance of Expect on which to call wait(). + * \param TIME Time to wait in seconds. Qt event queue is processed when waiting. + */ //! @{ #define EXPECT_WAIT_2(EXP, TIME, U1, U2) ((EXP).wait(SOURCE_LOCATION, (TIME), (U1), (U2))) #define EXPECT_WAIT_3(EXP, TIME, U1, U2, U3) ((EXP).wait(SOURCE_LOCATION, (TIME), (U1), (U2), (U3))) @@ -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))) //! @} -} //namespace BlackCoreTest +} // ns -#endif //BLACKCORETEST_EXPECT_H \ No newline at end of file +#endif // guard diff --git a/tests/blackcore/testblackcoremain.h b/tests/blackcore/testblackcoremain.h index 61fa25be4..7ba691bdc 100644 --- a/tests/blackcore/testblackcoremain.h +++ b/tests/blackcore/testblackcoremain.h @@ -1,7 +1,13 @@ -/* Copyright (C) 2013 VATSIM Community / contributors - * This Source Code Form is subject to the terms of the Mozilla Public - * 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/. */ +/* 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. + */ + +//! \file #ifndef BLACKCORETEST_TESTMAIN_H #define BLACKCORETEST_TESTMAIN_H @@ -12,22 +18,17 @@ namespace BlackCoreTest { -/*! - * Class firing all unit tests in this namespace. - * Avoids clashes with other main(..) functions and allows to fire the test cases - * simply from any other main. - */ -class CBlackCoreTestMain -{ -public: /*! - * \brief Starting all - * \param argc - * \param argv - * \return + * Class firing all unit tests in this namespace. + * Avoids clashes with other main(..) functions and allows to fire the test cases + * simply from any other main. */ - static int unitMain(int argc, char *argv[]); -}; + class CBlackCoreTestMain + { + public: + //! Unit tests + static int unitMain(int argc, char *argv[]); + }; } #endif // guard diff --git a/tests/blackmisc/main.cpp b/tests/blackmisc/main.cpp index eea9b367b..33baf301d 100644 --- a/tests/blackmisc/main.cpp +++ b/tests/blackmisc/main.cpp @@ -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 "blackmisc/blackmiscfreefunctions.h" #include diff --git a/tests/blackmisc/testaviation.cpp b/tests/blackmisc/testaviation.cpp index dbf3cddd1..05347bb3d 100644 --- a/tests/blackmisc/testaviation.cpp +++ b/tests/blackmisc/testaviation.cpp @@ -1,7 +1,11 @@ -/* Copyright (C) 2013 VATSIM Community / authors - * This Source Code Form is subject to the terms of the Mozilla Public - * 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/. */ +/* 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 "testaviation.h" #include "blackmisc/pq/constants.h" diff --git a/tests/blackmisc/testaviation.h b/tests/blackmisc/testaviation.h index 6c206e103..91331b8b0 100644 --- a/tests/blackmisc/testaviation.h +++ b/tests/blackmisc/testaviation.h @@ -1,5 +1,5 @@ -/* Copyright (C) 2014 - * swift project community / contributors +/* 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, diff --git a/tests/blackmisc/testblackmiscmain.cpp b/tests/blackmisc/testblackmiscmain.cpp index b7466e81e..6c14d7dc5 100644 --- a/tests/blackmisc/testblackmiscmain.cpp +++ b/tests/blackmisc/testblackmiscmain.cpp @@ -1,7 +1,11 @@ -/* Copyright (C) 2013 VATSIM Community / contributors - * This Source Code Form is subject to the terms of the Mozilla Public - * 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/. */ +/* 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 "testphysicalquantities.h" #include "testaviation.h" diff --git a/tests/blackmisc/testcontainers.cpp b/tests/blackmisc/testcontainers.cpp index f35ae7a2f..205c4634c 100644 --- a/tests/blackmisc/testcontainers.cpp +++ b/tests/blackmisc/testcontainers.cpp @@ -7,8 +7,6 @@ * contained in the LICENSE file. */ -//! \file - #include "testcontainers.h" #include "testvalueobject.h" #include "blackmisc/blackmiscfreefunctions.h" diff --git a/tests/blackmisc/testgeo.cpp b/tests/blackmisc/testgeo.cpp index 56d431657..9121c9e8c 100644 --- a/tests/blackmisc/testgeo.cpp +++ b/tests/blackmisc/testgeo.cpp @@ -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 "blackmisc/geo/latitude.h" #include "blackmisc/geo/longitude.h" @@ -6,10 +15,8 @@ using namespace BlackMisc::Geo; using namespace BlackMisc::PhysicalQuantities; using namespace BlackMisc::Math; - namespace BlackMiscTest { - /* * Geo classes tests */ diff --git a/tests/blackmisc/testhardware.cpp b/tests/blackmisc/testhardware.cpp index 03420842f..a194e2b16 100644 --- a/tests/blackmisc/testhardware.cpp +++ b/tests/blackmisc/testhardware.cpp @@ -1,7 +1,11 @@ -/* Copyright (C) 2013 VATSIM Community / authors - * This Source Code Form is subject to the terms of the Mozilla Public - * 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/. */ +/* 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 "testhardware.h" #include "blackmisc/hardware/keyboardkey.h" diff --git a/tests/blackmisc/testoriginator.cpp b/tests/blackmisc/testoriginator.cpp index 1b458a5e1..aab7f7c24 100644 --- a/tests/blackmisc/testoriginator.cpp +++ b/tests/blackmisc/testoriginator.cpp @@ -7,8 +7,6 @@ * contained in the LICENSE file. */ -//! \file - #include "testoriginator.h" #include "blackmisc/blackmiscfreefunctions.h" #include "blackmisc/originatorlist.h" diff --git a/tests/blackmisc/testphysicalquantities.cpp b/tests/blackmisc/testphysicalquantities.cpp index 1664cbc46..a32ce3739 100644 --- a/tests/blackmisc/testphysicalquantities.cpp +++ b/tests/blackmisc/testphysicalquantities.cpp @@ -1,7 +1,11 @@ -/* Copyright (C) 2013 VATSIM Community / contributors - * This Source Code Form is subject to the terms of the Mozilla Public - * 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/. */ +/* 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 "testphysicalquantities.h" @@ -175,8 +179,7 @@ namespace BlackMiscTest a1.switchUnit(CAccelerationUnit::ft_s2()); QVERIFY2(a1 == a2, "Accelerations should be similar"); QVERIFY2(CMathUtils::epsilonEqual(BlackMisc::Math::CMathUtils::round(a2.value() * ftFactor, 6), - a1.valueRounded(6)), - "Numerical values should be equal"); + a1.valueRounded(6)), "Numerical values should be equal"); } /* @@ -207,6 +210,17 @@ namespace BlackMiscTest QVERIFY2(CLength(-22.8, CLengthUnit::ft()) != CLength("-22.8 cm"), "Length !="); QVERIFY2(CSpeed(123.45, CSpeedUnit::km_h()) == CSpeed("123.45km/h"), "Speed"); QVERIFY2(CMass(33.45, CMassUnit::kg()) == CMass("33.45000 kg"), "CMass"); + + + // parsing via variant + CSpeed parsedPq1 = CPqString::parseToVariant("100.123 km/h").value(); + QVERIFY2(CSpeed(100.123, CSpeedUnit::km_h()) == parsedPq1, "Parsed speed via variant"); + + CLength parsedPq2 = CPqString::parseToVariant("-33.123ft").value(); + QVERIFY2(CLength(-33.123, CLengthUnit::ft()) == parsedPq2, "Parsed length via variant"); + + CFrequency parsedPq3 = CPqString::parse("122.8MHz"); + QVERIFY2(CFrequency(122.8, CFrequencyUnit::MHz()) == parsedPq3, "Parsed frequency via variant"); } /* @@ -214,6 +228,7 @@ namespace BlackMiscTest */ void CTestPhysicalQuantities::basicArithmetic() { + // pressure CPressure p1 = CPhysicalQuantitiesConstants::ISASeaLevelPressure(); CPressure p2(p1); p2 *= 2.0; @@ -225,5 +240,22 @@ namespace BlackMiscTest QVERIFY2(p3.value() == 0, "Value needs to be zero"); p3 = CPressure(1013, CPressureUnit::hPa()); 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 diff --git a/tests/blackmisc/testphysicalquantities.h b/tests/blackmisc/testphysicalquantities.h index a4283496f..2258ddeb8 100644 --- a/tests/blackmisc/testphysicalquantities.h +++ b/tests/blackmisc/testphysicalquantities.h @@ -1,5 +1,5 @@ -/* Copyright (C) 2014 - * swift project community / contributors +/* 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, diff --git a/tests/blackmisc/testvariantandmap.cpp b/tests/blackmisc/testvariantandmap.cpp index d5ad3e236..f582ee0f8 100644 --- a/tests/blackmisc/testvariantandmap.cpp +++ b/tests/blackmisc/testvariantandmap.cpp @@ -1,7 +1,11 @@ -/* Copyright (C) 2013 VATSIM Community / contributors - * This Source Code Form is subject to the terms of the Mozilla Public - * 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/. */ +/* 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 "testvariantandmap.h" #include "blackmisc/aviation/atcstation.h"