Results 1 to 2 of 2

Thread: Unit Test: Test if QPushButton has a menu

  1. #1
    Join Date
    Oct 2010
    Location
    Berlin, Germany
    Posts
    358
    Thanks
    18
    Thanked 68 Times in 66 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Unit Test: Test if QPushButton has a menu

    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:


    Qt Code:
    1. BOOST_AUTO_TEST_CASE(EachButtonHasMenuOnClick)
    2. {
    3. BOOST_FOREACH(QPushButton* elButton, m_perilib.findChildren<QPushButton*>())
    4. {
    5. // click on button
    6. QTest::mouseClick( elButton, Qt::LeftButton );
    7.  
    8. // check if menu is visible
    9. QMenu* elButtonMenu = elButton->menu();
    10. BOOST_REQUIRE(elButtonMenu);
    11. BOOST_CHECK_EQUAL(true, elButtonMenu->isVisible());
    12.  
    13. // click again (somewhere outside the menu) to close menu
    14. QTest::mouseClick( elButton, Qt::LeftButton );
    15. BOOST_CHECK_EQUAL(false, elButtonMenu->isVisible());
    16. }
    17. }
    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

  2. #2
    Join Date
    May 2012
    Posts
    136
    Thanks
    2
    Thanked 27 Times in 24 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Unit Test: Test if QPushButton has a menu

    Can't you just send a mouse click event to the main window using postevent?

Similar Threads

  1. How can we make unit test for multithread in QT
    By learning_qt in forum Qt Programming
    Replies: 8
    Last Post: 15th January 2013, 16:09
  2. debugging a unit test
    By Martin Drozdik in forum Newbie
    Replies: 4
    Last Post: 1st June 2012, 01:38
  3. Problem with Qt Unit Test
    By rubikon in forum Qt Programming
    Replies: 3
    Last Post: 25th November 2011, 09:18
  4. Unit test coverage
    By leoalvesmachado in forum Newbie
    Replies: 3
    Last Post: 16th April 2010, 13:48
  5. How to unit test a Qt Gui
    By mitskits in forum Qt Programming
    Replies: 1
    Last Post: 20th January 2006, 07:36

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.