From 1ec1d9bc56572a92108a4b1bf48587717e7c630b Mon Sep 17 00:00:00 2001 From: Rhys Weatherley Date: Mon, 5 Oct 2009 08:06:07 +1000 Subject: Add unit tests for QGLContextResource Reviewed-by: trustme --- src/opengl/qgl_p.h | 2 +- tests/auto/qgl/tst_qgl.cpp | 50 +++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 50 insertions(+), 2 deletions(-) diff --git a/src/opengl/qgl_p.h b/src/opengl/qgl_p.h index 1957429..2bf3374 100644 --- a/src/opengl/qgl_p.h +++ b/src/opengl/qgl_p.h @@ -506,7 +506,7 @@ inline GLenum qt_gl_preferredTextureTarget() } // One resource per group of shared contexts. -class QGLContextResource : public QObject +class Q_AUTOTEST_EXPORT QGLContextResource : public QObject { Q_OBJECT public: diff --git a/tests/auto/qgl/tst_qgl.cpp b/tests/auto/qgl/tst_qgl.cpp index f15b249..e036e4b 100644 --- a/tests/auto/qgl/tst_qgl.cpp +++ b/tests/auto/qgl/tst_qgl.cpp @@ -1754,6 +1754,29 @@ void tst_QGL::destroyFBOAfterContext() delete fbo; } +#ifdef QT_BUILD_INTERNAL + +class tst_QGLResource : public QObject +{ + Q_OBJECT +public: + tst_QGLResource(QObject *parent = 0) : QObject(parent) {} + ~tst_QGLResource() { ++deletions; } + + static int deletions; +}; + +int tst_QGLResource::deletions = 0; + +static void qt_shared_test_free(void *data) +{ + delete reinterpret_cast(data); +} + +Q_GLOBAL_STATIC_WITH_ARGS(QGLContextResource, qt_shared_test, (qt_shared_test_free)) + +#endif + void tst_QGL::shareRegister() { #ifdef QT_BUILD_INTERNAL @@ -1775,6 +1798,12 @@ void tst_QGL::shareRegister() guard.setId(3); QVERIFY(guard.id() == 3); + // Add a resource to the first context. + tst_QGLResource *res1 = new tst_QGLResource(); + QVERIFY(!qt_shared_test()->value(glw1->context())); + qt_shared_test()->insert(glw1->context(), res1); + QVERIFY(qt_shared_test()->value(glw1->context()) == res1); + // Create another context that shares with the first. QGLWidget *glw2 = new QGLWidget(0, glw1); if (!glw2->isSharing()) { @@ -1784,6 +1813,10 @@ void tst_QGL::shareRegister() } QVERIFY(glw1->context() != glw2->context()); + // Check that the first context's resource is also on the second. + QVERIFY(qt_shared_test()->value(glw1->context()) == res1); + QVERIFY(qt_shared_test()->value(glw2->context()) == res1); + // Guard should still be the same. QVERIFY(guard.context() == glw1->context()); QVERIFY(guard.id() == 3); @@ -1814,6 +1847,14 @@ void tst_QGL::shareRegister() QGLSharedResourceGuard guard3(glw3->context()); guard3.setId(5); + // Add a resource to the third context. + tst_QGLResource *res3 = new tst_QGLResource(); + QVERIFY(!qt_shared_test()->value(glw3->context())); + qt_shared_test()->insert(glw3->context(), res3); + QVERIFY(qt_shared_test()->value(glw1->context()) == res1); + QVERIFY(qt_shared_test()->value(glw2->context()) == res1); + QVERIFY(qt_shared_test()->value(glw3->context()) == res3); + // First two should still be sharing, but third is in its own list. list = shareReg->shares(glw1->context()); QCOMPARE(list.size(), 2); @@ -1849,6 +1890,11 @@ void tst_QGL::shareRegister() // Delete the first context. delete glw1; + // The first context's resource should transfer to the second context. + QCOMPARE(tst_QGLResource::deletions, 0); + QVERIFY(qt_shared_test()->value(glw2->context()) == res1); + QVERIFY(qt_shared_test()->value(glw3->context()) == res3); + // Shared guard should now be the second context, with the id the same. QVERIFY(guard.context() == glw2->context()); QVERIFY(guard.id() == 3); @@ -1859,9 +1905,11 @@ void tst_QGL::shareRegister() list = shareReg->shares(glw2->context()); QCOMPARE(list.size(), 0); - // Clean up. + // Clean up and check that the resources are properly deleted. delete glw2; + QCOMPARE(tst_QGLResource::deletions, 1); delete glw3; + QCOMPARE(tst_QGLResource::deletions, 2); // Guards should now be null and the id zero. QVERIFY(guard.context() == 0); -- cgit v0.12