-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathqtestmainwindow.cpp
64 lines (52 loc) · 1.96 KB
/
qtestmainwindow.cpp
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
#include "qtestmainwindow.h"
QTestMainWindow::QTestMainWindow(QWidget *parent /*= nullptr*/):MainWindow(parent)
{
if (_appMachine) {
_appMachine->connectToState("testCancelled", [this](bool active) {
if (active) {
log("User cancelled!", QtWarningMsg);
if (_interpreter) {
_interpreter->stop();
_interpreter.reset();
}
}
});
}
}
void QTestMainWindow::processTest(const QString &fileName, const bool isSpecial)
{
if (isSpecial) {
_interpreter.reset();
this->_appMachine->submitEvent("Inp.Test.Skipped");
} else {
_interpreter.reset(QScxmlStateMachine::fromFile(fileName));
const auto errors = _interpreter->parseErrors();
if (errors.size()) {
for (const auto &it : errors) {
log(it.toString(), QtCriticalMsg);
}
}
connect(_interpreter.get(), &QScxmlStateMachine::runningChanged, this, [=](bool running) {
if (running) {
this->_appMachine->submitEvent("Inp.Test.Started");
}
});
connect(_interpreter.get(), &QScxmlStateMachine::finished, this, [=]() {
const bool pass = this->_interpreter->isActive("pass");
this->_appMachine->submitEvent(pass ? "Inp.Test.Passed" : "Inp.Test.Failed");
});
connect(_interpreter.get(), &QScxmlStateMachine::reachedStableState, this, [=]() {
this->_appMachine->submitEvent("Inp.Test.Stable");
});
/* state machine activity */
_interpreter->connectToEvent("*", [this](const QScxmlEvent &) {
if (this->_appMachine->isActive("testIdle")) {
this->_appMachine->submitEvent("Inp.Test.Active");
}
});
_interpreter->start();
if (!_interpreter->isRunning()) {
this->_appMachine->submitEvent("Inp.Test.Timeout");
}
}
}