2

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 !

Deswing
  • 21
  • 5
  • Possible duplicate of [How to test Qts SCXML state machines](https://stackoverflow.com/questions/40677999/how-to-test-qts-scxml-state-machines) – Kdawg Jul 19 '17 at 13:37
  • indeed when I force the QCoreApplication::processEvents() the event are processed. but is this a proper solution? – Deswing Jul 19 '17 at 15:08
  • AFAIK, without an event loop running, you'll never see the state machine progress through its states, so you'll need to do that or something similar. – Kdawg Jul 19 '17 at 15:43

0 Answers0