dev@1430
|
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
|
dev@1430
|
2
|
dev@1430
|
3 /*
|
dev@1430
|
4 Sonic Visualiser
|
dev@1430
|
5 An audio file viewer and annotation editor.
|
dev@1430
|
6 Centre for Digital Music, Queen Mary, University of London.
|
dev@1430
|
7 This file copyright 2017 Lucas Thompson.
|
dev@1430
|
8
|
dev@1430
|
9 This program is free software; you can redistribute it and/or
|
dev@1430
|
10 modify it under the terms of the GNU General Public License as
|
dev@1430
|
11 published by the Free Software Foundation; either version 2 of the
|
dev@1430
|
12 License, or (at your option) any later version. See the file
|
dev@1430
|
13 COPYING included with this distribution for more information.
|
dev@1430
|
14 */
|
dev@1430
|
15
|
dev@1430
|
16 #ifndef _TEST_HELPER_H_
|
dev@1430
|
17 #define _TEST_HELPER_H_
|
dev@1430
|
18
|
dev@1430
|
19 #include <initializer_list>
|
dev@1430
|
20 #include <memory>
|
dev@1430
|
21 #include <iostream>
|
dev@1430
|
22 #include <functional>
|
dev@1430
|
23
|
dev@1430
|
24 #include <QtTest>
|
dev@1430
|
25
|
dev@1430
|
26 namespace Test
|
dev@1430
|
27 {
|
dev@1430
|
28
|
dev@1430
|
29 template <class T>
|
dev@1430
|
30 using Factory = std::function<std::unique_ptr<T>()>;
|
dev@1430
|
31
|
dev@1430
|
32 template <class T, typename... Args>
|
dev@1430
|
33 auto createFactory(Args... FArgs) -> Factory<T>
|
dev@1430
|
34 {
|
dev@1431
|
35 return [&]() { return std::unique_ptr<T> { new T {FArgs...} }; };
|
dev@1430
|
36 }
|
dev@1430
|
37
|
dev@1430
|
38 using TestStatus = int;
|
dev@1430
|
39
|
dev@1430
|
40 auto startTestRunner(
|
dev@1431
|
41 std::initializer_list<Factory<QObject>> tests,
|
dev@1431
|
42 int argc,
|
dev@1431
|
43 char *argv[],
|
dev@1431
|
44 QString testName,
|
dev@1431
|
45 QString orgName = "sonic-visualiser"
|
dev@1430
|
46 ) -> TestStatus
|
dev@1430
|
47 {
|
dev@1430
|
48 int good = 0, bad = 0;
|
dev@1430
|
49
|
dev@1430
|
50 QCoreApplication app(argc, argv);
|
dev@1430
|
51 app.setOrganizationName(orgName);
|
dev@1430
|
52 app.setApplicationName(testName);
|
dev@1430
|
53 auto executeTest = [&](std::unique_ptr<QObject> t) {
|
dev@1430
|
54 if (QTest::qExec(t.get(), argc, argv) == 0) ++good;
|
dev@1430
|
55 else ++bad;
|
dev@1430
|
56 };
|
dev@1430
|
57
|
dev@1430
|
58 for (const auto& test : tests) {
|
dev@1430
|
59 executeTest(test());
|
dev@1430
|
60 }
|
dev@1430
|
61
|
dev@1430
|
62 if (bad > 0) {
|
dev@1432
|
63 std::cerr << "\n********* " << bad << " test suite(s) failed!\n" << std::endl;
|
dev@1431
|
64 return 1;
|
dev@1430
|
65 } else {
|
dev@1432
|
66 std::cerr << "All tests passed" << std::endl;
|
dev@1431
|
67 return 0;
|
dev@1430
|
68 }
|
dev@1430
|
69 }
|
dev@1430
|
70
|
dev@1430
|
71 } // namespace
|
dev@1430
|
72
|
dev@1430
|
73 #endif |