From 516a1127509f53f956e990d6930c404263e19e18 Mon Sep 17 00:00:00 2001 From: Kim Gronholm Date: Fri, 6 May 2011 15:22:20 +0300 Subject: Added one auto test case more --- tests/auto/auto.pro | 2 + tests/auto/main.qml | 80 +++++++++++++++++++++++++++++++++++++ tests/auto/tst_qmlshadersplugin.cpp | 31 ++++++++++++++ 3 files changed, 113 insertions(+) create mode 100644 tests/auto/main.qml diff --git a/tests/auto/auto.pro b/tests/auto/auto.pro index 4ca586f..cfea478 100644 --- a/tests/auto/auto.pro +++ b/tests/auto/auto.pro @@ -16,3 +16,5 @@ HEADERS += \ ../../src/shadereffect.h \ ../../src/shadereffectbuffer.h \ ../../src/scenegraph/qsggeometry.h + +OTHER_FILES += main.qml diff --git a/tests/auto/main.qml b/tests/auto/main.qml new file mode 100644 index 0000000..fc80b39 --- /dev/null +++ b/tests/auto/main.qml @@ -0,0 +1,80 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QML Shaders plugin of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** 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, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 1.0 +import Qt.labs.shaders 1.0 + + Rectangle { + width: 300 + height: 300 + + Text { + id: textLabel + text: "Hello World" + anchors.centerIn: parent + font.pixelSize: 48 + } + + ShaderEffectItem { + objectName: "effectItem" + property variant source: ShaderEffectSource { objectName: "effectSource"; sourceItem: textLabel; hideSource: true } + property real wiggleAmount: 0.01 + anchors.fill: textLabel + + SequentialAnimation on wiggleAmount { + loops: Animation.Infinite + NumberAnimation { to: -0.01; duration: 500 } + NumberAnimation { to: 0.01; duration: 500 } + } + + fragmentShader: " + varying highp vec2 qt_TexCoord0; + uniform sampler2D source; + uniform highp float wiggleAmount; + void main(void) + { + highp vec2 wiggledTexCoord = qt_TexCoord0; + wiggledTexCoord.s += sin(4.0 * 3.141592653589 * wiggledTexCoord.t) * wiggleAmount; + gl_FragColor = texture2D(source, wiggledTexCoord.st); + } + " + } + } diff --git a/tests/auto/tst_qmlshadersplugin.cpp b/tests/auto/tst_qmlshadersplugin.cpp index d17baea..19c5d9d 100644 --- a/tests/auto/tst_qmlshadersplugin.cpp +++ b/tests/auto/tst_qmlshadersplugin.cpp @@ -72,6 +72,7 @@ private slots: void initTestCase(); void shaderEffectItemAPI(); void shaderEffectSourceAPI(); + void combined(); private: QDeclarativeEngine engine; @@ -108,17 +109,20 @@ void tst_qmlshadersplugin::shaderEffectItemAPI() QCOMPARE(obj->property("vertexShader").toString(), QString("")); QCOMPARE(obj->property("blending").toBool(), true); QCOMPARE(obj->property("meshResolution").toSize(), QSize(1, 1)); + QCOMPARE(obj->property("visible").toBool(), true); // Seting the values QVERIFY(obj->setProperty("fragmentShader", QString(qt_default_fragment_code))); QVERIFY(obj->setProperty("vertexShader", QString(qt_default_vertex_code))); QVERIFY(obj->setProperty("blending", false)); QVERIFY(obj->setProperty("meshResolution", QSize(20, 10))); + QVERIFY(obj->setProperty("visible", false)); QCOMPARE(obj->property("fragmentShader").toString(), QString(qt_default_fragment_code)); QCOMPARE(obj->property("vertexShader").toString(), QString(qt_default_vertex_code)); QCOMPARE(obj->property("blending").toBool(), false); QCOMPARE(obj->property("meshResolution").toSize(), QSize(20, 10)); + QCOMPARE(obj->property("visible").toBool(), false); delete obj; } @@ -169,6 +173,33 @@ void tst_qmlshadersplugin::shaderEffectSourceAPI() delete obj; } +void tst_qmlshadersplugin::combined() +{ + QGLFormat format = QGLFormat::defaultFormat(); + format.setSampleBuffers(false); + format.setSwapInterval(1); + + QGLWidget* glWidget = new QGLWidget(format); + glWidget->setAutoFillBackground(false); + + QDeclarativeView view; + view.setViewportUpdateMode(QGraphicsView::FullViewportUpdate); + view.setAttribute(Qt::WA_OpaquePaintEvent); + view.setAttribute(Qt::WA_NoSystemBackground); + view.setViewport(glWidget); + view.setSource(QUrl::fromLocalFile("main.qml")); + view.show(); + QTest::qWait(1000); + + QObject *item = view.rootObject()->findChild("effectItem"); + QVERIFY(item != 0); + + QObject *src = view.rootObject()->findChild("effectSource"); + QVERIFY(src != 0); + + QCOMPARE(item->property("source"), QVariant::fromValue(src)); +} + QTEST_MAIN(tst_qmlshadersplugin) #include "tst_qmlshadersplugin.moc" -- cgit v1.2.3