From a403691459a34f0eaf5b45b4d8040f07ba2d622d Mon Sep 17 00:00:00 2001 From: EndrII Date: Wed, 14 Apr 2021 12:16:40 +0300 Subject: [PATCH] fix test system --- tests/tstMain.cpp | 65 +++++++++++++++++++++++++---------------------- 1 file changed, 34 insertions(+), 31 deletions(-) diff --git a/tests/tstMain.cpp b/tests/tstMain.cpp index 33efad1..25783d7 100644 --- a/tests/tstMain.cpp +++ b/tests/tstMain.cpp @@ -8,6 +8,13 @@ #include #include "exampletest.h" +// Use This macros for initialize your own test classes. +// Check exampletests +#define TestCase(name, testClass) \ + void name() { \ + initTest(new testClass()); \ + } + /** * @brief The tstMain class - this is main test class */ @@ -15,9 +22,6 @@ class tstMain : public QObject { Q_OBJECT -private: - QList _tests; - public: tstMain(); @@ -25,9 +29,22 @@ public: ~tstMain(); private slots: - void initTestCase(); - void unitTests(); + + // BEGIN TESTS CASES + TestCase(exampleTest, ExampleTest) + // END TEST CASES + +private: + + /** + * @brief initTest This method prepare @a test for run in the QApplication loop. + * @param test are input test case class. + */ + void initTest(Test* test); + + QList _tests; + QCoreApplication *_app = nullptr; }; /** @@ -37,28 +54,10 @@ private slots: tstMain::tstMain() { // init xample unit test - _tests.push_back(new ExampleTest()); - -} - -tstMain::~tstMain() { - -} - -/** - * @brief tstMain::initTestCase - this method contains initialization of the data tests. - */ -void tstMain::initTestCase() { -} - -/** - * @brief tstMain::unitTests create application for testing - */ -void tstMain::unitTests() { int argc =0; char * argv[] = {nullptr}; - QCoreApplication app(argc, argv); + _app = new QCoreApplication(argc, argv); QCoreApplication::setApplicationName("testRENAME_ME"); QCoreApplication::setOrganizationName("QuasarApp"); @@ -66,17 +65,21 @@ void tstMain::unitTests() { QDir(path).removeRecursively(); - QTimer::singleShot(0, this, [&app, this]() { +} - for (auto test : qAsConst(_tests) ) { - test->test(); - delete test; - } +tstMain::~tstMain() { + _app->exit(0); + delete _app; +} - app.exit(0); +void tstMain::initTest(Test *test) { + QTimer::singleShot(0, this, [this, test]() { + test->test(); + delete test; + _app->exit(0); }); - app.exec(); + _app->exec(); } QTEST_APPLESS_MAIN(tstMain)