How to test Qt SCXML state machines

女生的网名这么多〃 提交于 2019-12-05 13:24:36

In a QtTest based test you can use QTest::qWait() to run the event loop for a given time.

You can also use QSignalSpy to wait for a signal to happen within a certain time, see QSignalSpy::wait()

If there are more than one signal that can trigger test continuation, you can also use a nested event loop, e.g. something like this

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

Potentially combined with a timer to end the loop in case none of those signals arrive

We had the same issue and we took advantage of QScxmlStateMachine::reachedStableState signal.

// 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
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!