From e1513d7f904f03617c38f14d65cdaa8afd4ff2b2 Mon Sep 17 00:00:00 2001 From: Jarek Kobus Date: Wed, 10 Feb 2016 09:56:29 +0100 Subject: Add externalEventOccurred() signal. This signal is emitted only for events sent from SCXML file which are of qt:signal type. Reasoning: I want to use state names which contain dots, e.g. "Letter.A", "Letter.B", etc. The reason for that is I may listen to "done.state.Letter.*" event, which will be generated automatically whenever one of Letter.* went to its final state. Unfortunately, I cannot use qt-mode in that case, since dots in state names are not allowed in qt-mode. I'm forced to use non-qt-mode. In the same document I send external signals with . In order to listen to these signals I need to connect to the generic eventOccurred() signal in cpp code, since there is no other way in non-qt-mode. However, when I'm connected to eventOccurred() my slot is being invoked for every internal event, which slows down the execution. Practically, I'm not interested in internal events at all, but only for those marked with type="qt:signal". That's why this patch provides additional generic signal for "qt:signal" only event. Change-Id: Ic9206e98a20f72142f5584e0568f9f33d56f8e97 Reviewed-by: Ulf Hermann --- tests/auto/statemachine/eventoccurred.scxml | 45 ++++++++++++++++++++++++++++ tests/auto/statemachine/tst_statemachine.cpp | 27 +++++++++++++++++ tests/auto/statemachine/tst_statemachine.qrc | 1 + 3 files changed, 73 insertions(+) create mode 100644 tests/auto/statemachine/eventoccurred.scxml (limited to 'tests/auto/statemachine') diff --git a/tests/auto/statemachine/eventoccurred.scxml b/tests/auto/statemachine/eventoccurred.scxml new file mode 100644 index 0000000..6c164c2 --- /dev/null +++ b/tests/auto/statemachine/eventoccurred.scxml @@ -0,0 +1,45 @@ + + + + + + + + + + + + + + + + diff --git a/tests/auto/statemachine/tst_statemachine.cpp b/tests/auto/statemachine/tst_statemachine.cpp index 7a269b2..fccfd25 100644 --- a/tests/auto/statemachine/tst_statemachine.cpp +++ b/tests/auto/statemachine/tst_statemachine.cpp @@ -46,6 +46,7 @@ private Q_SLOTS: void activeStateNames_data(); void activeStateNames(); void connectToFinal(); + void eventOccurred(); }; void tst_StateMachine::stateNames_data() @@ -128,6 +129,32 @@ void tst_StateMachine::connectToFinal() QVERIFY(stateMachine->connectToState(QString("final"), &dummy, SLOT(deleteLater()))); } +void tst_StateMachine::eventOccurred() +{ + QScopedPointer stateMachine(QScxmlStateMachine::fromFile(QString(":/tst_statemachine/eventoccurred.scxml"))); + QVERIFY(!stateMachine.isNull()); + + qRegisterMetaType(); + QSignalSpy finishedSpy(stateMachine.data(), SIGNAL(finished())); + QSignalSpy eventOccurredSpy(stateMachine.data(), SIGNAL(eventOccurred(QScxmlEvent))); + QSignalSpy externalEventOccurredSpy(stateMachine.data(), SIGNAL(externalEventOccurred(QScxmlEvent))); + + stateMachine->start(); + + finishedSpy.wait(5000); + + QCOMPARE(eventOccurredSpy.count(), 4); + QCOMPARE(qvariant_cast(eventOccurredSpy.at(0).at(0)).name(), QLatin1String("internalEvent2")); + QCOMPARE(qvariant_cast(eventOccurredSpy.at(1).at(0)).name(), QLatin1String("externalEvent")); + QCOMPARE(qvariant_cast(eventOccurredSpy.at(2).at(0)).name(), QLatin1String("timeout")); + QCOMPARE(qvariant_cast(eventOccurredSpy.at(3).at(0)).name(), QLatin1String("done.state.top")); + + + QCOMPARE(externalEventOccurredSpy.count(), 1); + QCOMPARE(qvariant_cast(externalEventOccurredSpy.at(0).at(0)).name(), QLatin1String("externalEvent")); +} + + QTEST_MAIN(tst_StateMachine) #include "tst_statemachine.moc" diff --git a/tests/auto/statemachine/tst_statemachine.qrc b/tests/auto/statemachine/tst_statemachine.qrc index 69c96ae..8a006d7 100644 --- a/tests/auto/statemachine/tst_statemachine.qrc +++ b/tests/auto/statemachine/tst_statemachine.qrc @@ -1,5 +1,6 @@ + eventoccurred.scxml statenames.scxml statenamesnested.scxml -- cgit v1.2.3