-
-
Notifications
You must be signed in to change notification settings - Fork 60
Expand file tree
/
Copy pathmain.cpp
More file actions
123 lines (105 loc) · 3.85 KB
/
main.cpp
File metadata and controls
123 lines (105 loc) · 3.85 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
/***
* Copyright (C) Falko Axmann. All rights reserved.
* Licensed under the MIT license.
* See LICENSE.txt file in the project root for full license information.
****/
/**
* This is a very basic example to demonstrate how to run your UI tests
* using GTest. It can be useful when you have to make sure that your
* UI tests work well in an existing, GTest based environment.
*
* Keep in mind that GTest is not designed for UI testing and that the
* order of the test execution is not guaranteed. Thus, you should only
* have one test per executable.
*/
#include <QGuiApplication>
#include <QQmlApplicationEngine>
#include <Spix/Events/Identifiers.h>
#include <Spix/QtQmlBot.h>
#include <atomic>
#include <gtest/gtest.h>
class SpixGTest;
static SpixGTest* srv;
class SpixGTest : public spix::TestServer {
public:
SpixGTest(int argc, char* argv[])
{
m_argc = argc;
m_argv = argv;
}
int testResult() { return m_result.load(); }
protected:
int m_argc;
char** m_argv;
std::atomic<int> m_result {0};
void executeTest() override
{
srv = this;
::testing::InitGoogleTest(&m_argc, m_argv);
auto testResult = RUN_ALL_TESTS();
m_result.store(testResult);
}
};
TEST(GTestExample, BasicUITest)
{
srv->mouseClick(spix::ItemPath("mainWindow/Button_1"));
srv->wait(std::chrono::milliseconds(500));
srv->mouseClick(spix::ItemPath("mainWindow/Button_2"));
srv->wait(std::chrono::milliseconds(500));
srv->mouseClick(spix::ItemPath("mainWindow/Button_2"));
srv->wait(std::chrono::milliseconds(500));
srv->mouseClick(spix::ItemPath("mainWindow/Button_1"));
srv->wait(std::chrono::milliseconds(500));
srv->mouseClick(spix::ItemPath("mainWindow/Button_2"));
srv->wait(std::chrono::milliseconds(500));
srv->mouseClick(spix::ItemPath("mainWindow/Button_1"));
srv->wait(std::chrono::milliseconds(500));
srv->mouseClick(spix::ItemPath("mainWindow/Button_1"), spix::MouseButtons::Right);
srv->wait(std::chrono::milliseconds(500));
srv->mouseClick(spix::ItemPath("mainWindow/Button_2"), spix::MouseButtons::Left, spix::KeyModifiers::Shift);
srv->wait(std::chrono::milliseconds(500));
srv->mouseClick(spix::ItemPath("mainWindow/Button_2"), spix::MouseButtons::Left, spix::KeyModifiers::Control);
srv->wait(std::chrono::milliseconds(500));
srv->mouseClick(spix::ItemPath("mainWindow/Button_2"), spix::MouseButtons::Left,
spix::KeyModifiers::Shift | spix::KeyModifiers::Control);
srv->wait(std::chrono::milliseconds(500));
srv->mouseClick(spix::ItemPath("mainWindow/propItem/.propertyWithTarget"));
srv->wait(std::chrono::milliseconds(500));
srv->mouseClick(spix::ItemPath("mainWindow/.propertyWithTarget"));
srv->wait(std::chrono::milliseconds(500));
srv->mouseClick(spix::ItemPath("mainWindow/.propertyWithParent/Button_2"));
srv->wait(std::chrono::milliseconds(500));
srv->wait(std::chrono::milliseconds(500));
auto result = srv->getStringProperty("mainWindow/results", "text");
auto expected_result = R"RSLT(Button 1 clicked
Button 2 clicked
Button 2 clicked
Button 1 clicked
Button 2 clicked
Button 1 clicked
Button 1 right clicked
Button 2 shift clicked
Button 2 control clicked
Button 2 shift control clicked
Button 1 clicked
Button 1 clicked
Button 2 clicked)RSLT";
EXPECT_EQ(result, expected_result);
EXPECT_EQ(srv->getErrors(), std::vector<std::string> {});
srv->quit();
}
int main(int argc, char* argv[])
{
// Init Qt Qml Application
QGuiApplication app(argc, argv);
QQmlApplicationEngine engine;
engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
if (engine.rootObjects().isEmpty())
return -1;
// Instantiate and run tests
SpixGTest tests(argc, argv);
auto bot = new spix::QtQmlBot();
bot->runTestServer(tests);
app.exec();
return tests.testResult();
}