From 9341ac7d2f04d6f36b6b23b654e3cb3db42ed027 Mon Sep 17 00:00:00 2001 From: Rhys Weatherley Date: Thu, 1 Oct 2009 16:36:05 +1000 Subject: Add unit tests for QGLShareRegister Reviewed-by: Sarah Smith --- src/opengl/qgl_p.h | 2 +- tests/auto/qgl/tst_qgl.cpp | 122 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 123 insertions(+), 1 deletion(-) diff --git a/src/opengl/qgl_p.h b/src/opengl/qgl_p.h index 2e8ac88..a113b0f 100644 --- a/src/opengl/qgl_p.h +++ b/src/opengl/qgl_p.h @@ -399,7 +399,7 @@ public: Q_DECLARE_OPERATORS_FOR_FLAGS(QGLExtensions::Extensions) -class QGLShareRegister +class Q_AUTOTEST_EXPORT QGLShareRegister { public: QGLShareRegister() {} diff --git a/tests/auto/qgl/tst_qgl.cpp b/tests/auto/qgl/tst_qgl.cpp index 8027e9b..a49f543 100644 --- a/tests/auto/qgl/tst_qgl.cpp +++ b/tests/auto/qgl/tst_qgl.cpp @@ -54,6 +54,10 @@ #include #include +#ifdef QT_BUILD_INTERNAL +#include +#endif + //TESTED_CLASS= //TESTED_FILES= @@ -85,6 +89,7 @@ private slots: void replaceClipping(); void clipTest(); void destroyFBOAfterContext(); + void shareRegister(); }; tst_QGL::tst_QGL() @@ -1749,5 +1754,122 @@ void tst_QGL::destroyFBOAfterContext() delete fbo; } +void tst_QGL::shareRegister() +{ +#ifdef QT_BUILD_INTERNAL + QGLShareRegister *shareReg = qgl_share_reg(); + QVERIFY(shareReg != 0); + + // Create a context. + QGLWidget *glw1 = new QGLWidget(); + glw1->makeCurrent(); + + // Nothing should be sharing with glw1's context yet. + QList list; + list = shareReg->shares(glw1->context()); + QCOMPARE(list.size(), 0); + + // Create a guard for the first context. + QGLSharedResourceGuard guard(glw1->context()); + QVERIFY(guard.id() == 0); + guard.setId(3); + QVERIFY(guard.id() == 3); + + // Create another context that shares with the first. + QGLWidget *glw2 = new QGLWidget(0, glw1); + if (!glw2->isSharing()) { + delete glw2; + delete glw1; + QSKIP("Context sharing is not supported", SkipSingle); + } + QVERIFY(glw1->context() != glw2->context()); + + // Guard should still be the same. + QVERIFY(guard.context() == glw1->context()); + QVERIFY(guard.id() == 3); + + // Now there are two items in the share lists. + list = shareReg->shares(glw1->context()); + QCOMPARE(list.size(), 2); + QVERIFY(list.contains(glw1->context())); + QVERIFY(list.contains(glw2->context())); + list = shareReg->shares(glw2->context()); + QCOMPARE(list.size(), 2); + QVERIFY(list.contains(glw1->context())); + QVERIFY(list.contains(glw2->context())); + + // Check the sharing relationships. + QVERIFY(shareReg->checkSharing(glw1->context(), glw1->context())); + QVERIFY(shareReg->checkSharing(glw2->context(), glw2->context())); + QVERIFY(shareReg->checkSharing(glw1->context(), glw2->context())); + QVERIFY(shareReg->checkSharing(glw2->context(), glw1->context())); + QVERIFY(!shareReg->checkSharing(0, glw2->context())); + QVERIFY(!shareReg->checkSharing(glw1->context(), 0)); + QVERIFY(!shareReg->checkSharing(0, 0)); + + // Create a third context, not sharing with the others. + QGLWidget *glw3 = new QGLWidget(); + + // Create a guard on the standalone context. + QGLSharedResourceGuard guard3(glw3->context()); + guard3.setId(5); + + // First two should still be sharing, but third is in its own list. + list = shareReg->shares(glw1->context()); + QCOMPARE(list.size(), 2); + QVERIFY(list.contains(glw1->context())); + QVERIFY(list.contains(glw2->context())); + list = shareReg->shares(glw2->context()); + QCOMPARE(list.size(), 2); + QVERIFY(list.contains(glw1->context())); + QVERIFY(list.contains(glw2->context())); + list = shareReg->shares(glw3->context()); + QCOMPARE(list.size(), 0); + + // Check the sharing relationships again. + QVERIFY(shareReg->checkSharing(glw1->context(), glw1->context())); + QVERIFY(shareReg->checkSharing(glw2->context(), glw2->context())); + QVERIFY(shareReg->checkSharing(glw1->context(), glw2->context())); + QVERIFY(shareReg->checkSharing(glw2->context(), glw1->context())); + QVERIFY(!shareReg->checkSharing(glw1->context(), glw3->context())); + QVERIFY(!shareReg->checkSharing(glw2->context(), glw3->context())); + QVERIFY(!shareReg->checkSharing(glw3->context(), glw1->context())); + QVERIFY(!shareReg->checkSharing(glw3->context(), glw2->context())); + QVERIFY(shareReg->checkSharing(glw3->context(), glw3->context())); + QVERIFY(!shareReg->checkSharing(0, glw2->context())); + QVERIFY(!shareReg->checkSharing(glw1->context(), 0)); + QVERIFY(!shareReg->checkSharing(0, glw3->context())); + QVERIFY(!shareReg->checkSharing(glw3->context(), 0)); + QVERIFY(!shareReg->checkSharing(0, 0)); + + // Shared guard should still be the same. + QVERIFY(guard.context() == glw1->context()); + QVERIFY(guard.id() == 3); + + // Delete the first context. + delete glw1; + + // Shared guard should now be the second context, with the id the same. + QVERIFY(guard.context() == glw2->context()); + QVERIFY(guard.id() == 3); + QVERIFY(guard3.context() == glw3->context()); + QVERIFY(guard3.id() == 5); + + // Re-check the share list for the second context (should be empty now). + list = shareReg->shares(glw2->context()); + QCOMPARE(list.size(), 0); + + // Clean up. + delete glw2; + delete glw3; + + // Guards should now be null and the id zero. + QVERIFY(guard.context() == 0); + QVERIFY(guard.id() == 0); + QVERIFY(guard3.context() == 0); + QVERIFY(guard3.id() == 0); +#endif +} + QTEST_MAIN(tst_QGL) #include "tst_qgl.moc" -- cgit v0.12