How to test state machines Qt SCXML

I am trying to test the behavior of a state machine using the Qt test environment. I just don't understand how I should test the Qt SCXML implementation. Of course there is QSignalSpy, but this is only for signals / slops that do not require the start of an event loop. What I really want to do is:

myStateMachine.submitEvent("MyEvent");
// Run event loop
// Check result

I tried QCoreApplication::processEvents(), it sometimes worked, but sometimes it also gets stuck on a call processEvents(). I guess I could start an endless loop. Also googling didn't help, but there should be a way to do it right.

+4
source share
2 answers

QtTest QTest::qWait() .

QSignalSpy , . QSignalSpy::wait()

, , , . -

QEventLoop loop;
connect(sender1, SIGNAL(signal1()), &loop, SLOT(quit()));
connect(sender2, SIGNAL(signal2()), &loop, SLOT(quit()));
loop.exec();

, ,

+3

, QScxmlStateMachine::reachedStableState.

// We declared a QTestEventLoop as m_eventLoop
connect(stateMachine, &QScxmlStateMachine::reachedStableState, 
        &m_eventLoop, &QTestEventLoop::exitLoop);

stateMachine->submitEvent("MyEvent");
m_eventLoop.enterLoopMSecs(3000);
// check the state, results etc
0

Source: https://habr.com/ru/post/1661194/


All Articles