summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib/kernel
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@qt.io>2019-07-30 10:16:53 +0200
committerFriedemann Kleint <Friedemann.Kleint@qt.io>2019-08-13 19:07:05 +0200
commitecb6327762e58a83309027da90ebb953411a264e (patch)
tree169dfa41a4e5053e45e681d707f8adc0fba54a9f /tests/auto/corelib/kernel
parent02ae522f54e93af46fb7cae5fcbc630a804cab50 (diff)
QTestLib: Introduce initMain() to run in main before qApp exists
When running Qt autotests on a developer machine with a high resolution, failures occur due to either some widget becoming too small, some rounding fuzz appearing when Qt High DPI scaling is active, or some test taking screenshots failing to deal with device pixel ratios != 1 in the obtained pixmaps. It is not feasible to adapt all tests to pass on high resolution monitors in both modes (Qt High DPI scaling enabled/disabled). It should be possible to specify the High DPI setting per test. Previously, it was not possible to set the Qt High DPI scaling attributes since they must be applied before QApplication instantiation. Enable this by checking for the presence of a static void initMain() function on the test object and invoking it before QApplication instantiation. Prototypically use it in tst_qtimer and to turn off High DPI scaling for tst_QGL. [ChangeLog][QtTestLib] It is now possible to perform static initialization before QApplication instantiation by implementing a initMain() function in the test class. Change-Id: Idec0134b189710a14c41a451fa8445bc0c5b1cf3 Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io> Reviewed-by: Paul Wicking <paul.wicking@qt.io> Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
Diffstat (limited to 'tests/auto/corelib/kernel')
-rw-r--r--tests/auto/corelib/kernel/qtimer/tst_qtimer.cpp27
1 files changed, 18 insertions, 9 deletions
diff --git a/tests/auto/corelib/kernel/qtimer/tst_qtimer.cpp b/tests/auto/corelib/kernel/qtimer/tst_qtimer.cpp
index 262dbea913..8e0bdac520 100644
--- a/tests/auto/corelib/kernel/qtimer/tst_qtimer.cpp
+++ b/tests/auto/corelib/kernel/qtimer/tst_qtimer.cpp
@@ -47,7 +47,11 @@
class tst_QTimer : public QObject
{
Q_OBJECT
+public:
+ static void initMain();
+
private slots:
+ void cleanupTestCase();
void zeroTimer();
void singleShotTimeout();
void timeout();
@@ -1138,22 +1142,27 @@ struct StaticSingleShotUser
}
};
+// NOTE: to prevent any static initialization order fiasco, we implement
+// initMain() to instantiate staticSingleShotUser before qApp
+
static StaticSingleShotUser *s_staticSingleShotUser = nullptr;
-void tst_QTimer::singleShot_static()
+void tst_QTimer::initMain()
{
- QCoreApplication::processEvents();
- QCOMPARE(s_staticSingleShotUser->helper.calls, s_staticSingleShotUser->calls());
+ s_staticSingleShotUser = new StaticSingleShotUser;
}
-// NOTE: to prevent any static initialization order fiasco, we handle QTEST_MAIN
-// ourselves, but instantiate the staticSingleShotUser before qApp
+void tst_QTimer::cleanupTestCase()
+{
+ delete s_staticSingleShotUser;
+}
-int main(int argc, char *argv[])
+void tst_QTimer::singleShot_static()
{
- StaticSingleShotUser staticSingleShotUser;
- s_staticSingleShotUser = &staticSingleShotUser;
- QTEST_MAIN_IMPL(tst_QTimer)
+ QCoreApplication::processEvents();
+ QCOMPARE(s_staticSingleShotUser->helper.calls, s_staticSingleShotUser->calls());
}
+QTEST_MAIN(tst_QTimer)
+
#include "tst_qtimer.moc"