| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
#ifndef KSNIP_TESTRUNNER_H |
| 25 |
#define KSNIP_TESTRUNNER_H |
| 26 |
|
| 27 |
#include <gmock/gmock.h> |
| 28 |
|
| 29 |
class GoogleTestEventListener : public ::testing::EmptyTestEventListener { |
| 30 |
|
| 31 |
void OnTestStart(const ::testing::TestInfo&) override { |
| 32 |
} |
| 33 |
|
| 34 |
void OnTestPartResult(const ::testing::TestPartResult& test_part_result) override { |
| 35 |
if (test_part_result.failed()) { |
| 36 |
QFAIL( |
| 37 |
QString("mock objects failed with '%1' at %2:%3") |
| 38 |
.arg(QString(test_part_result.summary())) |
| 39 |
.arg(test_part_result.file_name()) |
| 40 |
.arg(test_part_result.line_number()) |
| 41 |
.toLatin1().constData() |
| 42 |
); |
| 43 |
} |
| 44 |
} |
| 45 |
|
| 46 |
void OnTestEnd(const ::testing::TestInfo&) override { |
| 47 |
} |
| 48 |
}; |
| 49 |
|
| 50 |
|
| 51 |
#define INIT_GOOGLE_MOCKS(argc, argv) { \ |
| 52 |
::testing::InitGoogleTest (&(argc), (argv)); \ |
| 53 |
::testing::TestEventListeners& listeners = ::testing::UnitTest::GetInstance()->listeners(); \ |
| 54 |
delete listeners.Release(listeners.default_result_printer());\ |
| 55 |
listeners.Append(new GoogleTestEventListener); } |
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
#if defined(QT_WIDGETS_LIB) |
| 62 |
|
| 63 |
#include <QtTest/qtest_widgets.h> |
| 64 |
|
| 65 |
#ifdef QT_KEYPAD_NAVIGATION |
| 66 |
# define QTEST_DISABLE_KEYPAD_NAVIGATION QApplication::setNavigationMode(Qt::NavigationModeNone); |
| 67 |
#else |
| 68 |
# define QTEST_DISABLE_KEYPAD_NAVIGATION |
| 69 |
#endif |
| 70 |
|
| 71 |
#define TEST_MAIN(TestObject) \ |
| 72 |
int main(int argc, char *argv[]) \ |
| 73 |
{ \ |
| 74 |
INIT_GOOGLE_MOCKS (argc, argv); \ |
| 75 |
\ |
| 76 |
QApplication app(argc, argv); \ |
| 77 |
app.setAttribute(Qt::AA_Use96Dpi, true); \ |
| 78 |
QTEST_DISABLE_KEYPAD_NAVIGATION \ |
| 79 |
TestObject tc; \ |
| 80 |
QTEST_SET_MAIN_SOURCE_PATH \ |
| 81 |
return QTest::qExec(&tc, argc, argv); \ |
| 82 |
} |
| 83 |
|
| 84 |
#elif defined(QT_GUI_LIB) |
| 85 |
|
| 86 |
#include <QtTest/qtest_gui.h> |
| 87 |
|
| 88 |
#define TEST_MAIN(TestObject) \ |
| 89 |
int main(int argc, char *argv[]) \ |
| 90 |
{ \ |
| 91 |
INIT_GOOGLE_MOCKS (argc, argv); \ |
| 92 |
\ |
| 93 |
QGuiApplication app(argc, argv); \ |
| 94 |
app.setAttribute(Qt::AA_Use96Dpi, true); \ |
| 95 |
TestObject tc; \ |
| 96 |
QTEST_SET_MAIN_SOURCE_PATH \ |
| 97 |
return QTest::qExec(&tc, argc, argv); \ |
| 98 |
} |
| 99 |
|
| 100 |
#else |
| 101 |
|
| 102 |
#define TEST_MAIN(TestObject) \ |
| 103 |
int main(int argc, char *argv[]) \ |
| 104 |
{ \ |
| 105 |
INIT_GOOGLE_MOCKS (argc, argv); \ |
| 106 |
\ |
| 107 |
QCoreApplication app(argc, argv); \ |
| 108 |
app.setAttribute(Qt::AA_Use96Dpi, true); \ |
| 109 |
TestObject tc; \ |
| 110 |
QTEST_SET_MAIN_SOURCE_PATH \ |
| 111 |
return QTest::qExec(&tc, argc, argv); \ |
| 112 |
} |
| 113 |
|
| 114 |
#endif |
| 115 |
|
| 116 |
#endif |