diff --git a/src/blackmisc/test.cpp b/src/blackmisc/test.cpp new file mode 100644 index 000000000..781d2f09c --- /dev/null +++ b/src/blackmisc/test.cpp @@ -0,0 +1,33 @@ +/* Copyright (C) 2016 + * 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 "blackmisc/test.h" + +namespace BlackMisc +{ + CTestBase::CTestBase(int argc, const char *const *argv) + { + for (int i = 0; i < argc; ++i) + { + m_arguments.append(argv[i]); + } + + // Output to stdout + m_arguments.append({ "-o", "-,txt" }); + } + + CTestBase::~CTestBase() + {} + + int CTestBase::exec(QObject *test, const QString &name) + { + auto additionalArguments = QStringList { "-o", name + "_testresults.xml,xml" }; + return this->qExec(test, m_arguments + additionalArguments); + } +} diff --git a/src/blackmisc/test.h b/src/blackmisc/test.h new file mode 100644 index 000000000..705fcf432 --- /dev/null +++ b/src/blackmisc/test.h @@ -0,0 +1,66 @@ +/* Copyright (C) 2016 + * 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 BLACKMISC_TEST_H +#define BLACKMISC_TEST_H + +#include "blackmisc/blackmiscexport.h" +#include + +#ifdef QT_TESTLIB_LIB +#include +#endif + +class QObject; + +namespace BlackMisc +{ + /*! + * Helper base class for executing unit tests. + * Contains the parts that do not depend upon QtTest library, and pure + * virtual functions for derived class to implement the parts that do. + */ + class BLACKMISC_EXPORT CTestBase + { + public: + //! Constructor expects command line arguments. + CTestBase(int argc, const char *const *argv); + + //! Destructor. + virtual ~CTestBase(); + + //! Execute the given test case. + int exec(QObject *test, const QString &name); + + private: + virtual int qExec(QObject *test, const QStringList &args) = 0; + + QStringList m_arguments; + }; + +#ifdef QT_TESTLIB_LIB + /*! + * Helper derived class for executing unit tests. + * Defined inline and only when building with QT += testlib so blackmisc + * doesn't need to link against QtTest library. + */ + class CTest : public CTestBase + { + public: + using CTestBase::CTestBase; + + private: + virtual int qExec(QObject *test, const QStringList &args) override { return QTest::qExec(test, args); } + }; +#endif +} + +#endif diff --git a/tests/blackcore/testblackcoremain.cpp b/tests/blackcore/testblackcoremain.cpp index f924db963..cf08e31c3 100644 --- a/tests/blackcore/testblackcoremain.cpp +++ b/tests/blackcore/testblackcoremain.cpp @@ -18,25 +18,29 @@ #include "testinterpolator.h" #include "testnetwork.h" #include "testreaders.h" +#include "blackmisc/test.h" +#include #include namespace BlackCoreTest { int CBlackCoreTestMain::unitMain(int argc, char *argv[]) { + BlackMisc::CTest test(argc, argv); + int status = 0; { CTestInterpolator interpolatorTests; - status |= QTest::qExec(&interpolatorTests, argc, argv); + status |= test.exec(&interpolatorTests, "blackcore_interpolator"); } { CTestReaders readersTests; - status |= QTest::qExec(&readersTests, argc, argv); + status |= test.exec(&readersTests, "blackcore_readers"); } { CTestNetwork networkTests; - status |= QTest::qExec(&networkTests, argc, argv); + status |= test.exec(&networkTests, "blackcore_network"); } return status; } diff --git a/tests/blackgui/testblackguimain.cpp b/tests/blackgui/testblackguimain.cpp index 0f54ce596..ef2133640 100644 --- a/tests/blackgui/testblackguimain.cpp +++ b/tests/blackgui/testblackguimain.cpp @@ -16,7 +16,9 @@ #include "testblackguimain.h" #include "testutils.h" +#include "blackmisc/test.h" +#include #include namespace BlackGuiTest @@ -26,10 +28,12 @@ namespace BlackGuiTest */ int CBlackGuiTestMain::unitMain(int argc, char *argv[]) { + BlackMisc::CTest test(argc, argv); + int status = 0; { CTestGuiUtilities utilityTests; - status |= QTest::qExec(&utilityTests, argc, argv); + status |= test.exec(&utilityTests, "blackgui_guiutilities"); } return status; } diff --git a/tests/blackmisc/testblackmiscmain.cpp b/tests/blackmisc/testblackmiscmain.cpp index 103bd8096..0e6194729 100644 --- a/tests/blackmisc/testblackmiscmain.cpp +++ b/tests/blackmisc/testblackmiscmain.cpp @@ -27,7 +27,9 @@ #include "testvaluecache.h" #include "testvariantandmap.h" #include "testweather.h" +#include "blackmisc/test.h" +#include #include namespace BlackMiscTest @@ -37,32 +39,56 @@ namespace BlackMiscTest */ int CBlackMiscTestMain::unitMain(int argc, char *argv[]) { + BlackMisc::CTest test(argc, argv); + int status = 0; { - CTestPhysicalQuantities pqBaseTests ; + CTestPhysicalQuantities pqBaseTests; + status |= test.exec(&pqBaseTests, "blackmisc_physicalQuantities"); + } + { CTestAviation avBaseTests; + status |= test.exec(&avBaseTests, "blackmisc_aviation"); + } + { CTestGeo geoTests; + status |= test.exec(&geoTests, "blackmisc_geo"); + } + { CTestContainers containerTests; + status |= test.exec(&containerTests, "blackmisc_containers"); + } + { CTestVariantAndMap variantAndMap; + status |= test.exec(&variantAndMap, "blackmisc_variantandmap"); + } + { CTestInput inputTests; + status |= test.exec(&inputTests, "blackmisc_input"); + } + { CTestIdentifier identifierTests; + status |= test.exec(&identifierTests, "blackmisc_identifier"); + } + { CTestSlot slotTests; + status |= test.exec(&slotTests, "blackmisc_slot"); + } + { CTestValueCache valueCacheTests; + status |= test.exec(&valueCacheTests, "blackmisc_valuecache"); + } + { CTestWeather weatherTests; + status |= test.exec(&weatherTests, "blackmisc_weather"); + } + { CTestMath mathTests; + status |= test.exec(&mathTests, "blackmisc_math"); + } + { CTestLibraryPath libraryPathTests; - status |= QTest::qExec(&pqBaseTests, argc, argv); - status |= QTest::qExec(&avBaseTests, argc, argv); - status |= QTest::qExec(&geoTests, argc, argv); - status |= QTest::qExec(&identifierTests, argc, argv); - status |= QTest::qExec(&containerTests, argc, argv); - status |= QTest::qExec(&variantAndMap, argc, argv); - status |= QTest::qExec(&inputTests, argc, argv); - status |= QTest::qExec(&slotTests, argc, argv); - status |= QTest::qExec(&valueCacheTests, argc, argv); - status |= QTest::qExec(&weatherTests, argc, argv); - status |= QTest::qExec(&mathTests, argc, argv); - status |= QTest::qExec(&libraryPathTests, argc, argv); + status |= test.exec(&libraryPathTests, "blackmisc_librarypath"); } return status; }