Hello,
I have a GUI with lots of buttons. Each button should show a menu when clicked. I want to test this behaviour in the following unit test:
BOOST_AUTO_TEST_CASE(EachButtonHasMenuOnClick)
{
BOOST_FOREACH
(QPushButton* elButton, m_perilib.
findChildren<QPushButton
*>
()) {
// click on button
QTest::mouseClick( elButton, Qt::LeftButton );
// check if menu is visible
QMenu* elButtonMenu
= elButton
->menu
();
BOOST_REQUIRE(elButtonMenu);
BOOST_CHECK_EQUAL(true, elButtonMenu->isVisible());
// click again (somewhere outside the menu) to close menu
QTest::mouseClick( elButton, Qt::LeftButton );
BOOST_CHECK_EQUAL(false, elButtonMenu->isVisible());
}
}
BOOST_AUTO_TEST_CASE(EachButtonHasMenuOnClick)
{
BOOST_FOREACH(QPushButton* elButton, m_perilib.findChildren<QPushButton*>())
{
// click on button
QTest::mouseClick( elButton, Qt::LeftButton );
// check if menu is visible
QMenu* elButtonMenu = elButton->menu();
BOOST_REQUIRE(elButtonMenu);
BOOST_CHECK_EQUAL(true, elButtonMenu->isVisible());
// click again (somewhere outside the menu) to close menu
QTest::mouseClick( elButton, Qt::LeftButton );
BOOST_CHECK_EQUAL(false, elButtonMenu->isVisible());
}
}
To copy to clipboard, switch view to plain text mode
But the problem is: the menu is opened modal, so QTest::mouseClick does not return until the user closes the menu by clicking anywhere. That is quite bad for an automated unit test... Is there any simple solution? Or do I have to use a different thread?
thx!
Felix
Bookmarks