qtestlib

Injecting a mock of a QTimer

独自空忆成欢 提交于 2021-02-10 14:48:41
问题 I'm writing a unit test with QTest for a legacy code like: #include <QTimer> class MyObject: public QObject{ public: void foo(){ t1.start(500); } private: QTimer t1{this}; }; And want to mock a QTimer and then test if the QTimer::start(int) is properly called. I was trying several approaches. Dependency injection with template template<typename TIMER = QTimer> class MyObjecr: public QObject , but getting Template classes not supported by Q_OBJECT And LD_PRELOAD=libQTimerMock.so with a simple

How can you edit a QTableView cell from a QTest unit test?

可紊 提交于 2020-12-29 06:51:30
问题 I'm writing a unit test for a custom Validator in a QTableView using the QTestLib framework. One of the most basic test cases could be described like this: Double click the table cell in the third column and the fourth row, and append the number '5' to its content. It is not sufficient to simply change the value in the model or anything, the test case shall perform it like this: Double Click the table cell to set it into edit mode Press the [End] key. Press the [5] key. Note: This question

How can you edit a QTableView cell from a QTest unit test?

╄→尐↘猪︶ㄣ 提交于 2020-12-29 06:50:09
问题 I'm writing a unit test for a custom Validator in a QTableView using the QTestLib framework. One of the most basic test cases could be described like this: Double click the table cell in the third column and the fourth row, and append the number '5' to its content. It is not sufficient to simply change the value in the model or anything, the test case shall perform it like this: Double Click the table cell to set it into edit mode Press the [End] key. Press the [5] key. Note: This question

QTest mouseClick on a QPushButton

亡梦爱人 提交于 2019-12-30 11:56:07
问题 i tried to click a QPushButton with the mouseClick function of the QTest namespace. The QPushButton is a private Member of an Widget. The position of the mouse cursor during the click is in the center of the button, but the Button is not clicked... Can somebady explain me why? MyWidget *myWidget= new myWidget(); myWidget->show(); while ( !myWidget->isVisible() ) { QTest::qWait(200); } QTest::qWait(500); QTest::mouseMove ( myWidget, QPoint( 70, 100 ), -1 ); QTest::mouseClick ( myWidget, Qt:

Problems with QTest::mouseClick on QListWidget

跟風遠走 提交于 2019-12-21 12:06:29
问题 I am trying to use QTest to do some testing. I have a QListWidget that I would like to click on to get a selection. But after the click, nothing is selected. Does anyone have any ideas? Here is my test class void TestGui::List() { TestDialog dlg; dlg.show (); // Click on the centre of the second object QListWidget *list = dlg.ListWidget (); QListWidgetItem *item = list->item ( 1 ); QRect rect = list->visualItemRect ( item ); QTest::mouseClick ( list, Qt::LeftButton, 0, rect.center() ); //

Qt UI testing: How to simulate a click on a QMenuBar item using QTest?

左心房为你撑大大i 提交于 2019-12-20 23:53:34
问题 I am trying to simulate a mouse click on a QMenu item from a QMenuBar, for example clicking on "Save As" QAction using the QTestLib framework. I am triyng this under Windows XP 32 bit and Qt 5.0.2. Any Ideas? 回答1: Probably this question is not relevant for question owner, but I suppose it could be helpful for others. Unlike QToolBar , QMenu doesn't have method widgetForAction . I found a simple workaround for this case. Try popup menu with QTest::mouseClick if nothing happens try to use QTest

How to write the qmake file for a test case? [duplicate]

一个人想着一个人 提交于 2019-12-13 12:49:42
问题 This question already has an answer here : Include a .pro file in Qt? (1 answer) Closed 5 years ago . I just don't understand what is the overall layout of a Qt project with a program and a test... The project of QTest tutorial only have the test program, but my project already have another program. If I add the test case, it claims "multiple definition of main()", as QTEST_MAIN is actually another main() . In addition, I got "undefined reference to vtable" on my test class, and don't know

How to access a QAction using the QtTest lib?

蹲街弑〆低调 提交于 2019-12-12 04:22:43
问题 I have a pop-up menu in a QTableWidget (resultTable). In the constructor of my class I set the context menu policy: resultTable->setContextMenuPolicy(Qt::CustomContextMenu); connect(resultTable, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(popUpMenuResultTable(QPoint))); The popUpMenuResultTable function: void MyClass::popUpMenuResultTable(QPoint pos) { QMenu menu; QAction* actionExport = menu.addAction(QIcon(":/new/prefix1/FileIcon.png"), tr("Export")); connect(actionExport, SIGNAL

QT close window by QTest in locked thread

倖福魔咒の 提交于 2019-12-11 23:29:40
问题 I have a QT application and I want to test it with QTest. Shortly about what I wanna do: I have a Main Window, where the button Settings is located. If I click on this button, the QDialog is appeared. I want to test if this really happens MainWindow mwindow; QTest::mouseClick(mwindow->showButton, QtCore::Qt::LeftButton) and then I would check for presence of text in new dialog and so on. The dialog appears but - how do I close it within the test without closing it manually? And how do I test

Qt: How do I get the currently running window?

前提是你 提交于 2019-12-10 13:04:28
问题 I'm writing a test app which simulates key presses and I would like to get what window is displayed after each key presses. Here's the code block. std::auto_ptr<MyForm> pForm(new MyForm(3,3)); QTest::keyPress(pForm.get(), Qt::Key_0); After pressing 0 here, A window is gonna show up and I would like to check what window it is so I could QCompare/evaluate it later. Any Ideas? Updated: I'm getting a segmentation fault when I use std::auto_ptr<MyForm> pForm(new MyForm(3,3)); QTest::keyPress(pForm