File indexing completed on 2024-12-22 05:13:37
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 0010 #include <common/test.h> 0011 0012 #include "CleanOnlineTest.h" 0013 #include "OfflineTest.h" 0014 #include "Process.h" 0015 0016 class TestRunner : public QObject 0017 { 0018 public: 0019 TestRunner() 0020 : m_nextToStart(0) 0021 { 0022 } 0023 0024 TestRunner &addTest(Test *test) 0025 { 0026 if (m_nextToStart == 0) { 0027 m_tests << test; 0028 } 0029 return *this; 0030 } 0031 0032 TestRunner &operator<<(Test *test) 0033 { 0034 addTest(test); 0035 return *this; 0036 } 0037 0038 void start() 0039 { 0040 if (m_nextToStart) { 0041 return; 0042 } 0043 0044 next(); 0045 } 0046 0047 private: 0048 void next() 0049 { 0050 if (m_nextToStart >= m_tests.size()) { 0051 QCoreApplication::exit(0); 0052 return; 0053 } 0054 0055 Test *test = m_tests[m_nextToStart++]; 0056 0057 QObject::connect(test, &Test::testFinished, this, &TestRunner::next, Qt::QueuedConnection); 0058 0059 QTest::qExec(test); 0060 } 0061 0062 private: 0063 QList<Test *> m_tests; 0064 int m_nextToStart; 0065 }; 0066 0067 int main(int argc, char *argv[]) 0068 { 0069 QCoreApplication app(argc, argv); 0070 0071 TestRunner &runner = *(new TestRunner()); 0072 0073 (runner << Process::exec(Process::Kill) 0074 0075 // Running the tests for when the service is offline 0076 << new OfflineTest() 0077 0078 // Running the offline tests again so that we are sure 0079 // nothing has changed -- no activities created, changed etc. 0080 << new OfflineTest() 0081 0082 // Starting the manager 0083 << Process::exec(Process::Start) 0084 0085 // Starting the online tests 0086 << new CleanOnlineTest() << new CleanOnlineSetup() 0087 << new OnlineTest() 0088 0089 // Starting the manager 0090 << Process::exec(Process::Stop) 0091 0092 << new OfflineTest() << new OfflineTest() 0093 0094 << Process::exec(Process::Start) << new OnlineTest() 0095 0096 << Process::exec(Process::Stop) 0097 0098 ) 0099 .start(); 0100 0101 return app.exec(); 0102 // QTest::qExec(&tc, argc, argv); 0103 }