How can I test method calling QMetaObject::invokeMethod with Qt::QueuedConnection -- using gtest gmock framework

304 views Asked by At

Suppose I have a method and I want to test it using gtest/gmock framework. This method calls another method inside itself using a Qt queued invoke:

void MyClass::handleFoo()
{
    // ...
    Q_ASSERT(QMetaObject::invokeMethod(this, "handleBar", Qt::QueuedConnection));
}

void MyClass::handleBar()
{
    _view.show();
}
TEST_F(MyTestSuite, MyTest)
{
    EXPECT_CALL(_viewMock, show()); // Fails with never called

    emit _myClassObj->foo();

    // Tried QCoreApplication::processEvents() -- does not help
}

Is there any way to do it? I think maybe I should just test these two handlers separately. But how can I test that the method handleFoo() will indeed call handleBar()?

0

There are 0 answers