summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib/statemachine
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/corelib/statemachine')
-rw-r--r--tests/auto/corelib/statemachine/qstatemachine/tst_qstatemachine.cpp38
1 files changed, 38 insertions, 0 deletions
diff --git a/tests/auto/corelib/statemachine/qstatemachine/tst_qstatemachine.cpp b/tests/auto/corelib/statemachine/qstatemachine/tst_qstatemachine.cpp
index dd036641b2..15f23e05cd 100644
--- a/tests/auto/corelib/statemachine/qstatemachine/tst_qstatemachine.cpp
+++ b/tests/auto/corelib/statemachine/qstatemachine/tst_qstatemachine.cpp
@@ -209,6 +209,7 @@ private slots:
void createSignalTransitionWhenRunning();
void createEventTransitionWhenRunning();
void signalTransitionSenderInDifferentThread();
+ void signalTransitionSenderInDifferentThread2();
void signalTransitionRegistrationThreadSafety();
void childModeConstructor();
};
@@ -4895,6 +4896,43 @@ void tst_QStateMachine::signalTransitionSenderInDifferentThread()
QTRY_VERIFY(thread.wait());
}
+void tst_QStateMachine::signalTransitionSenderInDifferentThread2()
+{
+ QStateMachine machine;
+ QState *s1 = new QState(&machine);
+ machine.setInitialState(s1);
+
+ QState *s2 = new QState(&machine);
+ SignalEmitter emitter;
+ // At the time of the transition creation, the machine and the emitter
+ // are both in the same thread.
+ s1->addTransition(&emitter, SIGNAL(signalWithNoArg()), s2);
+
+ QFinalState *s3 = new QFinalState(&machine);
+ s2->addTransition(&emitter, SIGNAL(signalWithDefaultArg()), s3);
+
+ QThread thread;
+ // Move the machine and its states to a secondary thread, but let the
+ // SignalEmitter stay in the main thread.
+ machine.moveToThread(&thread);
+
+ thread.start();
+ QTRY_VERIFY(thread.isRunning());
+
+ QSignalSpy startedSpy(&machine, SIGNAL(started()));
+ QSignalSpy finishedSpy(&machine, SIGNAL(finished()));
+ machine.start();
+ QTRY_COMPARE(startedSpy.count(), 1);
+
+ emitter.emitSignalWithNoArg();
+ // The second emission should not get "lost".
+ emitter.emitSignalWithDefaultArg();
+ QTRY_COMPARE(finishedSpy.count(), 1);
+
+ thread.quit();
+ QTRY_VERIFY(thread.wait());
+}
+
class SignalTransitionMutatorThread : public QThread
{
public: