I'm trying to implement a QT state machine based workflow, and for testing purpose, I'm tring to play my workflow using QTest.
void initTestCase()
{
machine = loadScxmlFile("StateMachine.scxml");
machine->start();
auto wrapper = new Wrapper(machine);
wrapper->connect();
qDebug() << "machinestate" << wrapper->getmachineState();
qDebug() << "activeStateBefore" << wrapper->getmachineState();
wrapper->initialize();
qDebug() << "activeStateAfter" << wrapper->getmachineState();
}
But sadly, even if I load my scxml properly, and even if it looks running and initialized, the active_state is always empty.
Config: Using QtTest library 5.9.0, Qt 5.9.0 (x86_64-little_endian-llp64 shared (dynamic) release build; by MSVC 2015)
QDEBUG : TestXImagerMock::initTestCase() machinestate ()
QDEBUG : TestXImagerMock::initTestCase() activeStateBefore ()
QDEBUG : TestXImagerMock::initTestCase() activeStateAfter ()
PASS : TestXImagerMock::initTestCase()
When I try to use a proper QCoreApplication everything looks like a charm so it seems the problem comes from the QTEST_MAIN
QCoreApplication testapplication(argc, nullptr);
testapplication.exec();
gives
QDEBUG : TestXImagerMock::initTestCase() onEntry_NotInitialized
QDEBUG : TestXImagerMock::initTestCase() onEntry_NotInitialized
QDEBUG : TestXImagerMock::initTestCase() onEntry_Initializing
but thoses logs comes after the testapplication.exec()
was called.
Do I need to add something to have the same behaviour in the QCoreApplication created by QTest?
Thanks !