File indexing completed on 2023-09-24 07:58:21
0001 /* 0002 SPDX-FileCopyrightText: 2013 Ivan Cukic <ivan.cukic(at)kde.org> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #include <QCoreApplication> 0008 #include <QList> 0009 #include <QTest> 0010 0011 #include <common/test.h> 0012 0013 #include "QueryTest.h" 0014 #include "ResultSetQuickCheckTest.h" 0015 #include "ResultSetTest.h" 0016 #include "ResultWatcherTest.h" 0017 0018 class TestRunner : public QObject 0019 { 0020 public: 0021 TestRunner() 0022 : m_nextToStart(0) 0023 { 0024 } 0025 0026 TestRunner &addTest(Test *test) 0027 { 0028 if (m_nextToStart == 0) { 0029 m_tests << test; 0030 } 0031 return *this; 0032 } 0033 0034 TestRunner &operator<<(Test *test) 0035 { 0036 addTest(test); 0037 return *this; 0038 } 0039 0040 void start() 0041 { 0042 if (m_nextToStart) { 0043 return; 0044 } 0045 0046 if (m_tests.size() == 0) { 0047 // We do not have a QCoreApplication here, calling system exit 0048 ::exit(0); 0049 return; 0050 } 0051 0052 next(); 0053 } 0054 0055 private: 0056 void next() 0057 { 0058 if (m_nextToStart >= m_tests.size()) { 0059 QCoreApplication::exit(0); 0060 return; 0061 } 0062 0063 Test *test = m_tests[m_nextToStart++]; 0064 0065 QObject::connect(test, &Test::testFinished, this, &TestRunner::next, Qt::QueuedConnection); 0066 0067 QTest::qExec(test); 0068 } 0069 0070 private: 0071 QList<Test *> m_tests; 0072 int m_nextToStart; 0073 }; 0074 0075 int main(int argc, char *argv[]) 0076 { 0077 QCoreApplication app(argc, argv); 0078 0079 TestRunner &runner = *(new TestRunner()); 0080 0081 qDebug() << app.arguments(); 0082 0083 bool all = (app.arguments().size() <= 1); 0084 0085 #define ADD_TEST(TestName) \ 0086 qDebug() << "Test " << #TestName << " is enabled " << (all || app.arguments().contains(QLatin1String(#TestName))); \ 0087 if (all || app.arguments().contains(QLatin1String(#TestName))) { \ 0088 runner << new TestName##Test(); \ 0089 } 0090 0091 ADD_TEST(Query) 0092 ADD_TEST(ResultSet) 0093 ADD_TEST(ResultSetQuickCheck) 0094 ADD_TEST(ResultWatcher) 0095 0096 runner.start(); 0097 0098 #undef ADD_TEST 0099 return app.exec(); 0100 // QTest::qExec(&tc, argc, argv); 0101 }