diff options
author | Ulf Hermann <ulf.hermann@qt.io> | 2016-09-06 14:18:50 +0200 |
---|---|---|
committer | Ulf Hermann <ulf.hermann@qt.io> | 2016-09-12 15:37:50 +0000 |
commit | 314931009b6205e58391afcff6b25ee317dd7d91 (patch) | |
tree | dab8279e3afdbe119ef8bc5e65802de862b54bbc /tests/auto/compiled/tst_compiled.cpp | |
parent | a1ca15291fec29194348dccf213b0587a505aafb (diff) |
Add onEntry and onExit templates to QScxmlStateMachines
These help to avoid repeating "if (isInState) ..." if you only want to
execute a handler when a state is entered, or "if (!isInState) ..." if
you want to execute it only when a state is left.
Change-Id: I0a73585591163dd2741b2d9d4897ee50e9623853
Reviewed-by: Erik Verbruggen <erik.verbruggen@qt.io>
Diffstat (limited to 'tests/auto/compiled/tst_compiled.cpp')
-rw-r--r-- | tests/auto/compiled/tst_compiled.cpp | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/tests/auto/compiled/tst_compiled.cpp b/tests/auto/compiled/tst_compiled.cpp index 0e4bb02..e09300e 100644 --- a/tests/auto/compiled/tst_compiled.cpp +++ b/tests/auto/compiled/tst_compiled.cpp @@ -135,8 +135,21 @@ public slots: { received = received || enabled; } + + void enter() + { + entered = true; + } + + void exit() + { + exited = true; + } + public: bool received = false; + bool entered = false; + bool exited = false; }; void tst_Compiled::connection() @@ -155,6 +168,16 @@ void tst_Compiled::connection() QMetaObject::Connection conB = stateMachine.connectToState("b", &receiverB, SLOT(receive(bool))); QMetaObject::Connection conFinal = stateMachine.connectToState("final", &receiverFinal, SLOT(receive(bool))); +#if defined(__cpp_return_type_deduction) && __cpp_return_type_deduction == 201304 + // C++14 available: test for onEntry and onExit + typedef QScxmlStateMachine QXSM; + QMetaObject::Connection aEntry = stateMachine.connectToState("a", QXSM::onEntry(&receiverA, "enter")); + QMetaObject::Connection aExit = stateMachine.connectToState("a", QXSM::onExit(&receiverA, "exit")); + + QVERIFY(aEntry); + QVERIFY(aExit); +#endif + QVERIFY(conA); QVERIFY(conA1); QVERIFY(conA2); @@ -174,6 +197,13 @@ void tst_Compiled::connection() QVERIFY(disconnect(conA2)); QVERIFY(disconnect(conB)); QVERIFY(disconnect(conFinal)); + +#if defined(__cpp_return_type_deduction) && __cpp_return_type_deduction == 201304 + QVERIFY(receiverA.entered); + QVERIFY(!receiverA.exited); + QVERIFY(disconnect(aEntry)); + QVERIFY(disconnect(aExit)); +#endif } class MyConnection : public Connection |