-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtestrunner.h
More file actions
49 lines (40 loc) · 1.19 KB
/
testrunner.h
File metadata and controls
49 lines (40 loc) · 1.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/*
* Thanks to
* https://marcoarena.wordpress.com/2012/06/23/increase-your-qtest-productivity
*
* @aroquemaurel
*/
#ifndef TESTRUNNER_H
#define TESTRUNNER_H
// Qt includes
#include <QTest>
#include <QSharedPointer>
// std includes
#include <algorithm>
#include <list>
#include <iostream>
// Test Runner allows automatic execution of tests
class TestRunner
{
public:
static TestRunner& Instance();
template <typename T> char RegisterTest(char *name) {
if ( std::find_if( begin(m_tests), end(m_tests), [&name](QSharedPointer<QObject>& elem)
{ return elem->objectName() == name; }) == end(m_tests) ) {
QSharedPointer<QObject> test(new T());
test->setObjectName(name);
m_tests.push_back(test);
}
return char(1);
}
int RunAll(int argc, char *argv[]);
private:
std::list<QSharedPointer<QObject>> m_tests;
};
// Use this macro after your test declaration
#define DECLARE_TEST(className)\
static char test_##className = TestRunner::Instance().RegisterTest<className>(#className);
// Use this macro to execute all tests
#define RUN_ALL_TESTS(argc, argv)\
TestRunner::Instance().RunAll(argc, argv);
#endif // TESTRUNNER_H