Forcing events with QOpenGLWidget (testing)
-
Greetings:
I am trying to implement some tests within my QOpenGLWidget application; for example, a test might be to setup a 400px400px window, left click on location (1,1), move to location (200,200), release (these three operations effectively rotate the object), and then do some project/unproject to make sure the right things are at the right places. Anyways, I created functions that manually perform these operations and then call
update()
however the image only displays after the operations are finished and when it shows it is in the starting position. I believe I am not invoking the test in an appropriate way for the underlying objects to do what they're supposed to do. My application is similar in construction to Qt's "hellogl2" sample application here.- What is the preferred way to initiate these tests? I currently set a boolean within the widget class for testing and do a check on it within
paintGL()
which kicks of the tests. This feels clunky so I am wondering if there is a better way. - I made my own functions that do the same things that my
mousePressEvent()
,mouseMoveEvent()
, andmouseReleaseEvent()
functions perform; these are what the testing function calls. Is there a better way for me to tell Qt about these events so I can use the actual aforementionedmouse*Event()
functions instead of the ones made for testing?
I appreciate any guidance this forum can provide. Thank you for your help with this.
Kind regards,
Anthony - What is the preferred way to initiate these tests? I currently set a boolean within the widget class for testing and do a check on it within
-
Are you looking for testlib framework ?
-
Are you looking for testlib framework ?
Thank you @dheerendra for your reply. I created a command line argument to my application for running these GUI tests and was hoping to not have separate executables for running the tests (this way, if there are issues with the application a user can run the tests directly). Can I achieve this with
QTest
? Thank you for your help with this. -
Just look at the QTest lib in Assistant & try running some examples. You will get the feel of it. It will not take much time to check this.
-
Just look at the QTest lib in Assistant & try running some examples. You will get the feel of it. It will not take much time to check this.
Thank you @dheerendra for your reply. I spent some time looking at Qt Test and am unsure of how to get it to drive my whole application rather than just some small portions of it. The click and drag that I want to do exercises quite a few of my custom methods within QOpenGLWidget. So, how do I structure the test object to be able to do this since a lot of things are handled under the hood by Qt? My
main.cpp
does the following to kick everything off. How would the test case appropriately start things so I could, then, add the appropriateQTest::mouseClick()
operations? Thank you for your help with this.QApplication app(argc, argv); QSurfaceFormat fmt; MainWindow mainWindow; fmt.setDepthBufferSize(24); QSurfaceFormat::setDefaultFormat(fmt); mainWindow.resize(mainWindow.sizeHint()); desktopArea = QApplication::desktop()->width() * QApplication::desktop()->height(); widgetArea = mainWindow.width() * mainWindow.height(); if (((float)widgetArea / (float)desktopArea) < 0.75f) mainWindow.show(); else mainWindow.showMaximized(); return app.exec();
-
Greetings:
I created the following test object for the case above. The issue I encounter is how to provide an appropriate QWindow or QWidget pointer to
QTest::mouseClick()
. My MainWindow class inherits from QMainWindow and sets in motion the creation of my Window class (which inherits from QWidget) which creates my GLWidget class (which inherits from QOpenGLWidget). Do I need to ultimately circumvent all of this and manually create these items? Thank you for your help with this.#include <QtTest/QtTest> // Qt Test class #include "glwidget.h" // GLWidget class #include "mainwindow.h" // MainWindow class class TestHT: public QObject { Q_OBJECT private slots: void dragTopMiddleToCenter(); }; void TestHT::dragTopMiddleToCenter() { // Test that drags from top middle to center // initialize renderable area QSurfaceFormat fmt; // initialize main window MainWindow mainWindow; // set depth fmt.setDepthBufferSize(24); // finalize renderable area QSurfaceFormat::setDefaultFormat(fmt); // handle transparency GLWidget::setTransparent(parser.isSet(transparentOption)); if (GLWidget::isTransparent()) { mainWindow.setAttribute(Qt::WA_TranslucentBackground); mainWindow.setAttribute(Qt::WA_NoSystemBackground, false); } // setup window size mainWindow.resize(mainWindow.sizeHint()); desktopArea = QApplication::desktop()->width() * QApplication::desktop()->height(); widgetArea = mainWindow.width() * mainWindow.height(); // display window if (((float)widgetArea / (float)desktopArea) < 0.75f) mainWindow.show(); else mainWindow.showMaximized(); // do mouse click QTest::mouseClick(mainWindow, Qt::LeftButton, Qt::NoModifier, QPoint(1, 1), 400); QVERIFY(1 == 1); }