diff options
Diffstat (limited to 'tests/auto/quick/qquickshadereffect/tst_qquickshadereffect.cpp')
-rw-r--r-- | tests/auto/quick/qquickshadereffect/tst_qquickshadereffect.cpp | 193 |
1 files changed, 17 insertions, 176 deletions
diff --git a/tests/auto/quick/qquickshadereffect/tst_qquickshadereffect.cpp b/tests/auto/quick/qquickshadereffect/tst_qquickshadereffect.cpp index a57b7d4c1f..4f6e5235a8 100644 --- a/tests/auto/quick/qquickshadereffect/tst_qquickshadereffect.cpp +++ b/tests/auto/quick/qquickshadereffect/tst_qquickshadereffect.cpp @@ -75,10 +75,7 @@ public: private slots: void initTestCase(); void cleanupTestCase(); - - void lookThroughShaderCode_data(); - void lookThroughShaderCode(); - + void testConnection(); void deleteSourceItem(); void deleteShaderEffectSource(); void twoImagesOneShaderEffect(); @@ -109,185 +106,29 @@ void tst_qquickshadereffect::cleanupTestCase() { } -void tst_qquickshadereffect::lookThroughShaderCode_data() -{ - QTest::addColumn<QByteArray>("vertexShader"); - QTest::addColumn<QByteArray>("fragmentShader"); - QTest::addColumn<int>("presenceFlags"); - - QTest::newRow("default") - << QByteArray("uniform highp mat4 qt_Matrix; \n" - "attribute highp vec4 qt_Vertex; \n" - "attribute highp vec2 qt_MultiTexCoord0; \n" - "varying highp vec2 qt_TexCoord0; \n" - "void main() { \n" - " qt_TexCoord0 = qt_MultiTexCoord0; \n" - " gl_Position = qt_Matrix * qt_Vertex; \n" - "}") - << QByteArray("varying highp vec2 qt_TexCoord0; \n" - "uniform sampler2D source; \n" - "uniform lowp float qt_Opacity; \n" - "void main() { \n" - " gl_FragColor = texture2D(source, qt_TexCoord0) * qt_Opacity; \n" - "}") - << (VertexPresent | TexCoordPresent | MatrixPresent | OpacityPresent | SourcePresent); - - QTest::newRow("empty") - << QByteArray(" ") // one space -- if completely empty, default will be used instead. - << QByteArray(" ") - << 0; - - - QTest::newRow("inside line comments") - << QByteArray("//uniform highp mat4 qt_Matrix;\n" - "attribute highp vec4 qt_Vertex;\n" - "// attribute highp vec2 qt_MultiTexCoord0;") - << QByteArray("uniform int source; // uniform lowp float qt_Opacity;") - << (VertexPresent | SourcePresent); - - QTest::newRow("inside block comments") - << QByteArray("/*uniform highp mat4 qt_Matrix;\n" - "*/attribute highp vec4 qt_Vertex;\n" - "/*/attribute highp vec2 qt_MultiTexCoord0;//**/") - << QByteArray("/**/uniform int source; /* uniform lowp float qt_Opacity; */") - << (VertexPresent | SourcePresent); - - QTest::newRow("inside preprocessor directive") - << QByteArray("#define uniform\nhighp mat4 qt_Matrix;\n" - "attribute highp vec4 qt_Vertex;\n" - "#if\\\nattribute highp vec2 qt_MultiTexCoord0;") - << QByteArray("uniform int source;\n" - " # undef uniform lowp float qt_Opacity;") - << (VertexPresent | SourcePresent); - - - QTest::newRow("line comments between") - << QByteArray("uniform//foo\nhighp//bar\nmat4//baz\nqt_Matrix;\n" - "attribute//\nhighp//\nvec4//\nqt_Vertex;\n" - " //*/ uniform \n attribute //\\ \n highp //// \n vec2 //* \n qt_MultiTexCoord0;") - << QByteArray("uniform// lowp float qt_Opacity;\nsampler2D source;") - << (VertexPresent | TexCoordPresent | MatrixPresent | SourcePresent); - - QTest::newRow("block comments between") - << QByteArray("uniform/*foo*/highp/*/bar/*/mat4/**//**/qt_Matrix;\n" - "attribute/**/highp/**/vec4/**/qt_Vertex;\n" - " /* * */ attribute /*///*/ highp /****/ vec2 /**/ qt_MultiTexCoord0;") - << QByteArray("uniform/*/ uniform//lowp/*float qt_Opacity;*/sampler2D source;") - << (VertexPresent | TexCoordPresent | MatrixPresent | SourcePresent); - - QTest::newRow("preprocessor directive between") - << QByteArray("uniform\n#foo\nhighp\n#bar\nmat4\n#baz\\\nblimey\nqt_Matrix;\n" - "attribute\n#\nhighp\n#\nvec4\n#\nqt_Vertex;\n" - " #uniform \n attribute \n # foo \n highp \n # bar \n vec2 \n#baz \n qt_MultiTexCoord0;") - << QByteArray("uniform\n#if lowp float qt_Opacity;\nsampler2D source;") - << (VertexPresent | TexCoordPresent | MatrixPresent | SourcePresent); - - QTest::newRow("newline between") - << QByteArray("uniform\nhighp\nmat4\nqt_Matrix\n;\n" - "attribute \t\r\n highp \n vec4 \n\n qt_Vertex ;\n" - " \n attribute \n highp \n vec2 \n qt_Multi\nTexCoord0 \n ;") - << QByteArray("uniform\nsampler2D\nsource;" - "uniform lowp float qt_Opacity;") - << (VertexPresent | MatrixPresent | OpacityPresent | SourcePresent); - - - QTest::newRow("extra characters #1") - << QByteArray("funiform highp mat4 qt_Matrix;\n" - "attribute highp vec4 qt_Vertex_;\n" - "attribute highp vec2 qqt_MultiTexCoord0;") - << QByteArray("uniformm int source;\n" - "uniform4 lowp float qt_Opacity;") - << 0; - - QTest::newRow("extra characters #2") - << QByteArray("attribute phighp vec4 qt_Vertex;\n" - "attribute highpi vec2 qt_MultiTexCoord0;" - "fattribute highp vec4 qt_Vertex;\n" - "attributed highp vec2 qt_MultiTexCoord0;") - << QByteArray(" ") - << 0; - - QTest::newRow("missing characters #1") - << QByteArray("unifor highp mat4 qt_Matrix;\n" - "attribute highp vec4 qt_Vert;\n" - "attribute highp vec2 MultiTexCoord0;") - << QByteArray("niform int source;\n" - "uniform qt_Opacity;") - << 0; - - QTest::newRow("missing characters #2") - << QByteArray("attribute high vec4 qt_Vertex;\n" - "attribute ighp vec2 qt_MultiTexCoord0;" - "tribute highp vec4 qt_Vertex;\n" - "attrib highp vec2 qt_MultiTexCoord0;") - << QByteArray(" ") - << 0; - - QTest::newRow("precision") - << QByteArray("uniform mat4 qt_Matrix;\n" - "attribute kindofhighp vec4 qt_Vertex;\n" - "attribute highp qt_MultiTexCoord0;\n") - << QByteArray("uniform lowp float qt_Opacity;\n" - "uniform mediump float source;\n") - << (MatrixPresent | OpacityPresent | SourcePresent); - - - QTest::newRow("property name #1") - << QByteArray("uniform highp vec3 _0aA9zZ;") - << QByteArray(" ") - << int(SourcePresent); - - QTest::newRow("property name #2") - << QByteArray("uniform mediump vec2 x86;") - << QByteArray(" ") - << int(SourcePresent); - - QTest::newRow("property name #3") - << QByteArray("uniform lowp float X;") - << QByteArray(" ") - << int(SourcePresent); - - QTest::newRow("property name #4") - << QByteArray("uniform highp mat4 mat4x4;") - << QByteArray(" ") - << int(SourcePresent); -} - -void tst_qquickshadereffect::lookThroughShaderCode() +void tst_qquickshadereffect::testConnection() { - QFETCH(QByteArray, vertexShader); - QFETCH(QByteArray, fragmentShader); - QFETCH(int, presenceFlags); - - QQmlEngine engine; - QQmlComponent component(&engine); - component.setData("import QtQuick 2.0\nimport ShaderEffectTest 1.0\nTestShaderEffect {}", QUrl()); - QScopedPointer<TestShaderEffect> item(qobject_cast<TestShaderEffect*>(component.create())); - QCOMPARE(item->signalsConnected, 0); + // verify that the property notify signal is connected + QQuickView *view = new QQuickView(nullptr); + view->setSource(QUrl(QStringLiteral("qrc:/data/connections.qml"))); - QString expected; - if ((presenceFlags & VertexPresent) == 0) - expected += "Warning: Missing reference to \'qt_Vertex\'.\n"; - if ((presenceFlags & TexCoordPresent) == 0) - expected += "Warning: Missing reference to \'qt_MultiTexCoord0\'.\n"; - if ((presenceFlags & MatrixPresent) == 0) - expected += "Warning: Vertex shader is missing reference to \'qt_Matrix\'.\n"; - if ((presenceFlags & OpacityPresent) == 0) - expected += "Warning: Shaders are missing reference to \'qt_Opacity\'.\n"; + auto *shaderEffectItem = qobject_cast<TestShaderEffect*>(view->rootObject()); + QVERIFY(shaderEffectItem); + QCOMPARE(shaderEffectItem->signalsConnected, 0); - item->setVertexShader(vertexShader); - item->setFragmentShader(fragmentShader); - QCOMPARE(item->parseLog(), expected); + view->show(); + QVERIFY(QTest::qWaitForWindowExposed(view)); - // If the uniform was successfully parsed, the notify signal has been connected to an update slot. - QCOMPARE(item->signalsConnected, (presenceFlags & SourcePresent) ? 1 : 0); + QSGRendererInterface *rif = view->rendererInterface(); + if (rif && rif->graphicsApi() != QSGRendererInterface::Software) + QCOMPARE(shaderEffectItem->signalsConnected, 1); } void tst_qquickshadereffect::deleteSourceItem() { // purely to ensure that deleting the sourceItem of a shader doesn't cause a crash QQuickView *view = new QQuickView(nullptr); - view->setSource(QUrl::fromLocalFile(testFile("deleteSourceItem.qml"))); + view->setSource(QUrl(QStringLiteral("qrc:/data/deleteSourceItem.qml"))); view->show(); QVERIFY(QTest::qWaitForWindowExposed(view)); QVERIFY(view); @@ -302,7 +143,7 @@ void tst_qquickshadereffect::deleteShaderEffectSource() { // purely to ensure that deleting the sourceItem of a shader doesn't cause a crash QQuickView *view = new QQuickView(nullptr); - view->setSource(QUrl::fromLocalFile(testFile("deleteShaderEffectSource.qml"))); + view->setSource(QUrl(QStringLiteral("qrc:/data/deleteShaderEffectSource.qml"))); view->show(); QVERIFY(QTest::qWaitForWindowExposed(view)); QVERIFY(view); @@ -315,9 +156,9 @@ void tst_qquickshadereffect::deleteShaderEffectSource() void tst_qquickshadereffect::twoImagesOneShaderEffect() { - // purely to ensure that deleting the sourceItem of a shader doesn't cause a crash + // Don't crash when having a ShaderEffect and an Image sharing the texture via supportsAtlasTextures QQuickView *view = new QQuickView(nullptr); - view->setSource(QUrl::fromLocalFile(testFile("twoImagesOneShaderEffect.qml"))); + view->setSource(QUrl(QStringLiteral("qrc:/data/twoImagesOneShaderEffect.qml"))); view->show(); QVERIFY(QTest::qWaitForWindowExposed(view)); QVERIFY(view); |