diff options
author | Jarek Kobus <jaroslaw.kobus@theqtcompany.com> | 2015-12-16 15:36:05 +0100 |
---|---|---|
committer | Erik Verbruggen <erik.verbruggen@theqtcompany.com> | 2015-12-17 12:51:54 +0000 |
commit | 610c54726cd41e97e1b4bd39222cf7ea4e1ccd95 (patch) | |
tree | 255ab7f13194f40653afa07c6cd3e70ccf606e2c /tests | |
parent | a49bd5a0051c713e78dfc2b463f4226cb5422097 (diff) |
Fix connecting to a signal of a final state, more tests
Change-Id: Ia01a5463a26368a907e8ce4443efbc112eb76b11
Reviewed-by: Erik Verbruggen <erik.verbruggen@theqtcompany.com>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/statemachine/test1.scxml | 16 | ||||
-rw-r--r-- | tests/auto/statemachine/tst_statemachine.cpp | 50 |
2 files changed, 57 insertions, 9 deletions
diff --git a/tests/auto/statemachine/test1.scxml b/tests/auto/statemachine/test1.scxml index a8a9070..366d849 100644 --- a/tests/auto/statemachine/test1.scxml +++ b/tests/auto/statemachine/test1.scxml @@ -1,11 +1,13 @@ <?xml version="1.0" ?> <scxml xmlns="http://www.w3.org/2005/07/scxml" version="1.0" name="test1"> - <state id="a"> - <state id="a1"/> - <state id="a2"/> - </state> - <state id="b"> - <final id="final"/> - </state> + <parallel id="top"> + <state id="a"> + <state id="a1"/> + <state id="a2"/> + </state> + <state id="b"> + <final id="final"/> + </state> + </parallel> </scxml> diff --git a/tests/auto/statemachine/tst_statemachine.cpp b/tests/auto/statemachine/tst_statemachine.cpp index 3ebed91..165607e 100644 --- a/tests/auto/statemachine/tst_statemachine.cpp +++ b/tests/auto/statemachine/tst_statemachine.cpp @@ -36,6 +36,8 @@ Q_DECLARE_METATYPE(QScxmlError); +enum { SpyWaitTime = 8000 }; + class tst_StateMachine: public QObject { Q_OBJECT @@ -43,6 +45,9 @@ class tst_StateMachine: public QObject private Q_SLOTS: void stateNames_data(); void stateNames(); + void activeStateNames_data(); + void activeStateNames(); + void connectToFinal(); }; void tst_StateMachine::stateNames_data() @@ -56,8 +61,7 @@ void tst_StateMachine::stateNames_data() << (QStringList() << QString("a1") << QString("a2") << QString("final")); QTest::newRow("test1-not-compressed") << QString(":/tst_statemachine/test1.scxml") << false - << (QStringList() << QString("a") << QString("a1") << QString("a2") << QString("b") << QString("final")); - + << (QStringList() << QString("a") << QString("a1") << QString("a2") << QString("b") << QString("final") << QString("top")); } void tst_StateMachine::stateNames() @@ -72,6 +76,48 @@ void tst_StateMachine::stateNames() QCOMPARE(stateMachine->stateNames(compressed), expectedStates); } +void tst_StateMachine::activeStateNames_data() +{ + QTest::addColumn<QString>("scxmlFileName"); + QTest::addColumn<bool>("compressed"); + QTest::addColumn<QStringList>("expectedStates"); + + QTest::newRow("test1-compressed") << QString(":/tst_statemachine/test1.scxml") + << true + << (QStringList() << QString("a1") << QString("final")); + QTest::newRow("test1-not-compressed") << QString(":/tst_statemachine/test1.scxml") + << false + << (QStringList() << QString("a") << QString("a1") << QString("b") << QString("final") << QString("top")); +} + +void tst_StateMachine::activeStateNames() +{ + QFETCH(QString, scxmlFileName); + QFETCH(bool, compressed); + QFETCH(QStringList, expectedStates); + + QScopedPointer<QScxmlStateMachine> stateMachine(QScxmlStateMachine::fromFile(scxmlFileName)); + QVERIFY(!stateMachine.isNull()); + + QSignalSpy stableStateSpy(stateMachine.data(), SIGNAL(reachedStableState(bool))); + + stateMachine->init(); + stateMachine->start(); + + stableStateSpy.wait(5000); + + QCOMPARE(stateMachine->activeStateNames(compressed), expectedStates); +} + +void tst_StateMachine::connectToFinal() +{ + QScopedPointer<QScxmlStateMachine> stateMachine(QScxmlStateMachine::fromFile(QString(":/tst_statemachine/test1.scxml"))); + QVERIFY(!stateMachine.isNull()); + + QState dummy; + QVERIFY(stateMachine->connect(QString("final"), SIGNAL(entered()), &dummy, SLOT(deleteLater()))); +} + QTEST_MAIN(tst_StateMachine) #include "tst_statemachine.moc" |