/**************************************************************************** ** ** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). ** Contact: http://www.qt-project.org/legal ** ** This file is part of the test suite of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:LGPL$ ** Commercial License Usage ** Licensees holding valid commercial Qt licenses may use this file in ** accordance with the commercial license agreement provided with the ** Software or, alternatively, in accordance with the terms contained in ** a written agreement between you and Digia. For licensing terms and ** conditions see http://qt.digia.com/licensing. For further information ** use the contact form at http://qt.digia.com/contact-us. ** ** GNU Lesser General Public License Usage ** Alternatively, this file may be used under the terms of the GNU Lesser ** General Public License version 2.1 as published by the Free Software ** Foundation and appearing in the file LICENSE.LGPL included in the ** packaging of this file. Please review the following information to ** ensure the GNU Lesser General Public License version 2.1 requirements ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. ** ** In addition, as a special exception, Digia gives you certain additional ** rights. These rights are described in the Digia Qt LGPL Exception ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. ** ** GNU General Public License Usage ** Alternatively, this file may be used under the terms of the GNU ** General Public License version 3.0 as published by the Free Software ** Foundation and appearing in the file LICENSE.GPL included in the ** packaging of this file. Please review the following information to ** ensure the GNU General Public License version 3.0 requirements will be ** met: http://www.gnu.org/copyleft/gpl.html. ** ** ** $QT_END_LICENSE$ ** ****************************************************************************/ #include #include #include #include class tst_SceneGraph : public QObject { Q_OBJECT private slots: void manyWindows_data(); void manyWindows(); }; template class ScopedList : public QList { public: ~ScopedList() { qDeleteAll(*this); } }; QQuickView *createView(const QString &file, QWindow *parent = 0, int x = -1, int y = -1, int w = -1, int h = -1) { QQuickView *view = new QQuickView(parent); view->setSource(QUrl::fromLocalFile("data/" + file)); if (x >= 0 && y >= 0) view->setPosition(x, y); if (w >= 0 && h >= 0) view->resize(w, h); view->show(); return view; } QImage showAndGrab(const QString &file, int w, int h) { QQuickView view; view.setSource(QUrl::fromLocalFile(QStringLiteral("data/") + file)); if (w >= 0 && h >= 0) view.resize(w, h); view.create(); return view.grabWindow(); } // Assumes the images are opaque white... bool containsSomethingOtherThanWhite(const QImage &image) { Q_ASSERT(image.format() == QImage::Format_ARGB32_Premultiplied || image.format() == QImage::Format_RGB32); int w = image.width(); int h = image.height(); for (int y=0; y tolerance) return false; if (qAbs(qRed(a) - qRed(b)) > tolerance) return false; if (qAbs(qRed(a) - qRed(b)) > tolerance) return false; } } return true; } void tst_SceneGraph::manyWindows_data() { QTest::addColumn("file"); QTest::addColumn("toplevel"); QTest::addColumn("shared"); QTest::newRow("image,toplevel") << QStringLiteral("manyWindows_image.qml") << true << false; QTest::newRow("image,subwindow") << QStringLiteral("manyWindows_image.qml") << false << false; QTest::newRow("dftext,toplevel") << QStringLiteral("manyWindows_dftext.qml") << true << false; QTest::newRow("dftext,subwindow") << QStringLiteral("manyWindows_dftext.qml") << false << false; QTest::newRow("ntext,toplevel") << QStringLiteral("manyWindows_ntext.qml") << true << false; QTest::newRow("ntext,subwindow") << QStringLiteral("manyWindows_ntext.qml") << false << false; QTest::newRow("rects,toplevel") << QStringLiteral("manyWindows_rects.qml") << true << false; QTest::newRow("rects,subwindow") << QStringLiteral("manyWindows_rects.qml") << false << false; QTest::newRow("image,toplevel,sharing") << QStringLiteral("manyWindows_image.qml") << true << true; QTest::newRow("image,subwindow,sharing") << QStringLiteral("manyWindows_image.qml") << false << true; QTest::newRow("dftext,toplevel,sharing") << QStringLiteral("manyWindows_dftext.qml") << true << true; QTest::newRow("dftext,subwindow,sharing") << QStringLiteral("manyWindows_dftext.qml") << false << true; QTest::newRow("ntext,toplevel,sharing") << QStringLiteral("manyWindows_ntext.qml") << true << true; QTest::newRow("ntext,subwindow,sharing") << QStringLiteral("manyWindows_ntext.qml") << false << true; QTest::newRow("rects,toplevel,sharing") << QStringLiteral("manyWindows_rects.qml") << true << true; QTest::newRow("rects,subwindow,sharing") << QStringLiteral("manyWindows_rects.qml") << false << true; } struct ShareContextResetter { public: ~ShareContextResetter() { QSGContext::setSharedOpenGLContext(0); } }; void tst_SceneGraph::manyWindows() { QFETCH(QString, file); QFETCH(bool, toplevel); QFETCH(bool, shared); QOpenGLContext sharedGLContext; ShareContextResetter cleanup; // To avoid dangling pointer in case of test-failure. if (shared) { sharedGLContext.create(); QSGContext::setSharedOpenGLContext(&sharedGLContext); } QScopedPointer parent; if (!toplevel) { parent.reset(new QWindow()); parent->resize(200, 200); parent->show(); } ScopedList views; const int COUNT = 4; QImage baseLine; for (int i=0; igrabWindow(); if (i == 0) { baseLine = content; QVERIFY(containsSomethingOtherThanWhite(baseLine)); } else { QVERIFY(compareImages(content, baseLine)); } } // Wipe and recreate one (scope pointer delets it...) delete views.takeLast(); QQuickView *last = createView(file, parent.data(), 100, 100, 100, 100); QTest::qWaitForWindowExposed(last); views << last; QVERIFY(compareImages(baseLine, last->grabWindow())); // Wipe and recreate all qDeleteAll(views); views.clear(); for (int i=0; igrabWindow(); QVERIFY(compareImages(content, baseLine)); } } #include "tst_scenegraph.moc" QTEST_MAIN(tst_SceneGraph)