diff options
author | Pasi Keränen <pasi.keranen@qt.io> | 2019-01-25 15:16:54 +0200 |
---|---|---|
committer | Pasi Keränen <pasi.keranen@qt.io> | 2019-02-06 12:38:42 +0000 |
commit | 50565141cceb780bba1805fc7aab307a34ba27d1 (patch) | |
tree | 1954017cc1d8302253af14768f456ce2a626a6e0 /tests | |
parent | 8ca98cea890c52a6576a1a277f2acffde9ef965e (diff) |
Add variant filtering
Add variant filtering to loading of presentations.
[ChangeLog][QtStudio3D][Support for variants] Qt 3D Studio runtime now supports loading presentations containing variant tags.
Task-number: QT3DS-2662
Change-Id: Id5637d23f5e9d178b8c40a3bb7c8b8950297548f
Reviewed-by: Miikka Heikkinen <miikka.heikkinen@qt.io>
Reviewed-by: Laszlo Agocs <laszlo.agocs@qt.io>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/auto.pro | 3 | ||||
-rw-r--r-- | tests/auto/behaviors/tst_q3dsbehaviors.cpp | 4 | ||||
-rw-r--r-- | tests/auto/q3dslancelot/scenegrabber/main.cpp | 4 | ||||
-rw-r--r-- | tests/auto/slideplayer/tst_q3dsslideplayer.cpp | 4 | ||||
-rw-r--r-- | tests/auto/slides/tst_q3dsslides.cpp | 4 | ||||
-rw-r--r-- | tests/auto/uippresentation/tst_q3dsuippresentation.cpp | 2 | ||||
-rw-r--r-- | tests/auto/variantparser/data/materials/ConeRed.materialdef | 25 | ||||
-rw-r--r-- | tests/auto/variantparser/data/materials/CubeBlue.materialdef | 25 | ||||
-rw-r--r-- | tests/auto/variantparser/data/materials/SphereGreen.materialdef | 25 | ||||
-rw-r--r-- | tests/auto/variantparser/data/presentations/varianttest.uip | 70 | ||||
-rw-r--r-- | tests/auto/variantparser/data/varianttest.uia | 15 | ||||
-rw-r--r-- | tests/auto/variantparser/tst_q3dsvariantparser.cpp | 331 | ||||
-rw-r--r-- | tests/auto/variantparser/variantparser.pro | 8 | ||||
-rw-r--r-- | tests/auto/variantparser/variantparser.qrc | 5 |
14 files changed, 519 insertions, 6 deletions
diff --git a/tests/auto/auto.pro b/tests/auto/auto.pro index 3a06f0e..2f72778 100644 --- a/tests/auto/auto.pro +++ b/tests/auto/auto.pro @@ -13,7 +13,8 @@ SUBDIRS += \ slides \ slideplayer \ surfaceviewer \ - q3dslancelot + q3dslancelot \ + variantparser qtHaveModule(quick) { SUBDIRS += \ diff --git a/tests/auto/behaviors/tst_q3dsbehaviors.cpp b/tests/auto/behaviors/tst_q3dsbehaviors.cpp index 3a37c85..4e09f21 100644 --- a/tests/auto/behaviors/tst_q3dsbehaviors.cpp +++ b/tests/auto/behaviors/tst_q3dsbehaviors.cpp @@ -76,7 +76,9 @@ void tst_Q3DSBehaviors::initTestCase() m_view->forceResize(640, 480); Q3DSUtils::setDialogsEnabled(false); - QVERIFY(m_view->engine()->setSource(QLatin1String(":/data/behaviors.uip"))); + Q3DSSourceInfo sourceInfo; + sourceInfo.setFileName(QLatin1String(":/data/behaviors.uip")); + QVERIFY(m_view->engine()->setSource(sourceInfo)); m_view->show(); QVERIFY(QTest::qWaitForWindowExposed(m_view)); diff --git a/tests/auto/q3dslancelot/scenegrabber/main.cpp b/tests/auto/q3dslancelot/scenegrabber/main.cpp index 6246746..c14a298 100644 --- a/tests/auto/q3dslancelot/scenegrabber/main.cpp +++ b/tests/auto/q3dslancelot/scenegrabber/main.cpp @@ -183,7 +183,9 @@ int main(int argc, char *argv[]) // End parsing GrabbingView v(ofile); - v.engine()->setSource(ifile); + Q3DSSourceInfo sourceInfo; + sourceInfo.setFileName(ifile); + v.engine()->setSource(sourceInfo); v.forceResize(1280, 720); v.show(); diff --git a/tests/auto/slideplayer/tst_q3dsslideplayer.cpp b/tests/auto/slideplayer/tst_q3dsslideplayer.cpp index 421c505..e0ee1f3 100644 --- a/tests/auto/slideplayer/tst_q3dsslideplayer.cpp +++ b/tests/auto/slideplayer/tst_q3dsslideplayer.cpp @@ -108,7 +108,9 @@ void tst_Q3DSSlidePlayer::initTestCase() m_view->forceResize(640, 480); Q3DSUtils::setDialogsEnabled(false); - m_view->engine()->setSource(QLatin1String(":/simpleslides.uip")); + Q3DSSourceInfo sourceInfo; + sourceInfo.setFileName(QLatin1String(":/simpleslides.uip")); + m_view->engine()->setSource(sourceInfo); QVERIFY(m_view->engine()->presentation()); QVERIFY(m_view->engine()->sceneManager()); diff --git a/tests/auto/slides/tst_q3dsslides.cpp b/tests/auto/slides/tst_q3dsslides.cpp index 23149a3..5f8527e 100644 --- a/tests/auto/slides/tst_q3dsslides.cpp +++ b/tests/auto/slides/tst_q3dsslides.cpp @@ -148,7 +148,9 @@ void tst_Q3DSSlides::initTestCase() Q3DSUtils::setDialogsEnabled(false); // This tests the basic Presentation (top level) slide change - m_view->engine()->setSource(QLatin1String(":/test3.uip")); + Q3DSSourceInfo sourceInfo; + sourceInfo.setFileName(QLatin1String(":/test3.uip")); + m_view->engine()->setSource(sourceInfo); QVERIFY(m_view->engine()->presentation()); QVERIFY(m_view->engine()->sceneManager()); diff --git a/tests/auto/uippresentation/tst_q3dsuippresentation.cpp b/tests/auto/uippresentation/tst_q3dsuippresentation.cpp index 0babb7a..d769957 100644 --- a/tests/auto/uippresentation/tst_q3dsuippresentation.cpp +++ b/tests/auto/uippresentation/tst_q3dsuippresentation.cpp @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2018 The Qt Company Ltd. +** Copyright (C) 2019 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the test suite of the Qt Toolkit. diff --git a/tests/auto/variantparser/data/materials/ConeRed.materialdef b/tests/auto/variantparser/data/materials/ConeRed.materialdef new file mode 100644 index 0000000..c2b384b --- /dev/null +++ b/tests/auto/variantparser/data/materials/ConeRed.materialdef @@ -0,0 +1,25 @@ +<MaterialData version="1.0"> + <Property name="shaderlighting">Pixel</Property> + <Property name="blendmode">Normal</Property> + <Property name="diffuse">1 0 0</Property> + <Property name="specularamount">0</Property> + <Property name="specularroughness">0</Property> + <Property name="opacity">100</Property> + <Property name="emissivecolor">1 1 1</Property> + <Property name="emissivepower">0</Property> + <Property name="bumpamount">0.5</Property> + <Property name="displaceamount">20</Property> + <Property name="translucentfalloff">1</Property> + <Property name="diffuselightwrap">0</Property> + <Property name="specularmodel">Default</Property> + <Property name="speculartint">1 1 1</Property> + <Property name="ior">1.5</Property> + <Property name="fresnelPower">0</Property> + <Property name="vertexcolors">False</Property> + <Property name="sourcepath"></Property> + <Property name="importid"></Property> + <Property name="importfile"></Property> + <Property name="name"><![CDATA[materials/ConeRed]]></Property> + <Property name="type">Material</Property> + <Property name="path"><![CDATA[/Users/pasikeranen/Documents/VariantTest/materials/ConeRed.materialdef]]></Property> +</MaterialData> diff --git a/tests/auto/variantparser/data/materials/CubeBlue.materialdef b/tests/auto/variantparser/data/materials/CubeBlue.materialdef new file mode 100644 index 0000000..16deeaf --- /dev/null +++ b/tests/auto/variantparser/data/materials/CubeBlue.materialdef @@ -0,0 +1,25 @@ +<MaterialData version="1.0"> + <Property name="shaderlighting">Pixel</Property> + <Property name="blendmode">Normal</Property> + <Property name="diffuse">0 0 1</Property> + <Property name="specularamount">0</Property> + <Property name="specularroughness">0</Property> + <Property name="opacity">100</Property> + <Property name="emissivecolor">1 1 1</Property> + <Property name="emissivepower">0</Property> + <Property name="bumpamount">0.5</Property> + <Property name="displaceamount">20</Property> + <Property name="translucentfalloff">1</Property> + <Property name="diffuselightwrap">0</Property> + <Property name="specularmodel">Default</Property> + <Property name="speculartint">1 1 1</Property> + <Property name="ior">1.5</Property> + <Property name="fresnelPower">0</Property> + <Property name="vertexcolors">False</Property> + <Property name="sourcepath"></Property> + <Property name="importid"></Property> + <Property name="importfile"></Property> + <Property name="name"><![CDATA[materials/CubeBlue]]></Property> + <Property name="type">Material</Property> + <Property name="path"><![CDATA[/Users/pasikeranen/Documents/VariantTest/materials/CubeBlue.materialdef]]></Property> +</MaterialData> diff --git a/tests/auto/variantparser/data/materials/SphereGreen.materialdef b/tests/auto/variantparser/data/materials/SphereGreen.materialdef new file mode 100644 index 0000000..fa412f6 --- /dev/null +++ b/tests/auto/variantparser/data/materials/SphereGreen.materialdef @@ -0,0 +1,25 @@ +<MaterialData version="1.0"> + <Property name="shaderlighting">Pixel</Property> + <Property name="blendmode">Normal</Property> + <Property name="diffuse">0 0.513726 0</Property> + <Property name="specularamount">0</Property> + <Property name="specularroughness">0</Property> + <Property name="opacity">100</Property> + <Property name="emissivecolor">1 1 1</Property> + <Property name="emissivepower">0</Property> + <Property name="bumpamount">0.5</Property> + <Property name="displaceamount">20</Property> + <Property name="translucentfalloff">1</Property> + <Property name="diffuselightwrap">0</Property> + <Property name="specularmodel">Default</Property> + <Property name="speculartint">1 1 1</Property> + <Property name="ior">1.5</Property> + <Property name="fresnelPower">0</Property> + <Property name="vertexcolors">False</Property> + <Property name="sourcepath"></Property> + <Property name="importid"></Property> + <Property name="importfile"></Property> + <Property name="name"><![CDATA[materials/SphereGreen]]></Property> + <Property name="type">Material</Property> + <Property name="path"><![CDATA[/Users/pasikeranen/Documents/VariantTest/materials/SphereGreen.materialdef]]></Property> +</MaterialData> diff --git a/tests/auto/variantparser/data/presentations/varianttest.uip b/tests/auto/variantparser/data/presentations/varianttest.uip new file mode 100644 index 0000000..9357388 --- /dev/null +++ b/tests/auto/variantparser/data/presentations/varianttest.uip @@ -0,0 +1,70 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<UIP version="5" > + <Project > + <ProjectSettings author="" company="" presentationWidth="1920" presentationHeight="1080" maintainAspect="False" preferKtx="False" > + <CustomColors count="16" >#7391ff #ffffff #ffffff #ffffff #ffffff #ffffff #ffffff #ffffff #ffffff #ffffff #ffffff #ffffff #ffffff #ffffff #ffffff #ffffff</CustomColors> + </ProjectSettings> + <Graph > + <Scene id="Scene" > + <Layer id="SphereLayer" variants="Geom:Sphere,Geom:All,Position:Center"> + <Camera id="Camera_001" /> + <Light id="Light_001" /> + <Model id="Sphere" > + <ReferencedMaterial id="SphereGreen" name="Default" /> + </Model> + </Layer> + <Layer id="CubeLayer" variants="Geom:Cube,Geom:All,Position:Edge"> + <Model id="Cube" > + <ReferencedMaterial id="CubeBlue" name="Default" /> + </Model> + <Camera id="Camera_002" /> + <Light id="Light_002" /> + </Layer> + <Layer id="ConeLayer" variants="Geom:Cone,Geom:All,Position:Edge" > + <Model id="Cone" > + <ReferencedMaterial id="ConeRed" name="Default" /> + </Model> + <Camera id="Camera_003" /> + <Light id="Light_003" /> + </Layer> + <Layer id="Layer" > + <Camera id="Camera" /> + <Light id="Light" /> + </Layer> + <Material id="__Container" > + <Material id="materials/ConeRed" /> + <Material id="materials/CubeBlue" /> + <Material id="materials/SphereGreen" /> + </Material> + </Scene> + </Graph> + <Logic > + <State name="Master Slide" component="#Scene" > + <Add ref="#Layer" name="MasterLayer" /> + <Add ref="#Camera" /> + <Add ref="#Light" name="MasterLight" /> + <Add ref="#__Container" name="__Container" /> + <Add ref="#materials/ConeRed" name="materials/ConeRed" diffuse="1 0 0" importid="" /> + <Add ref="#materials/CubeBlue" name="materials/CubeBlue" diffuse="0 0 1" importid="" /> + <Add ref="#materials/SphereGreen" name="materials/SphereGreen" diffuse="0 0.513726 0" importid="" /> + <State id="Scene-Slide1" name="Slide1" > + <Add ref="#SphereLayer" name="SphereLayer" /> + <Add ref="#Camera_001" /> + <Add ref="#Light_001" rotation="26 34 -45" /> + <Add ref="#Sphere" name="Sphere" position="0 0 -225" sourcepath="#Sphere" /> + <Add ref="#SphereGreen" name="SphereGreen" referencedmaterial="#materials/SphereGreen" sourcepath="../materials/SphereGreen.materialdef" /> + <Add ref="#CubeLayer" name="CubeLayer" /> + <Add ref="#Cube" name="Cube" position="260 0 -225" rotation="-20 0 0" sourcepath="#Cube" /> + <Add ref="#CubeBlue" name="CubeBlue" referencedmaterial="#materials/CubeBlue" sourcepath="../materials/CubeBlue.materialdef" /> + <Add ref="#Camera_002" /> + <Add ref="#Light_002" rotation="0 24 0" /> + <Add ref="#ConeLayer" name="ConeLayer" /> + <Add ref="#Cone" name="Cone" position="-260 -43 -225" rotation="10 0 0" sourcepath="#Cone" /> + <Add ref="#ConeRed" name="ConeRed" referencedmaterial="#materials/ConeRed" sourcepath="../materials/ConeRed.materialdef" /> + <Add ref="#Camera_003" /> + <Add ref="#Light_003" rotation="12 -34 26" /> + </State> + </State> + </Logic> + </Project> +</UIP> diff --git a/tests/auto/variantparser/data/varianttest.uia b/tests/auto/variantparser/data/varianttest.uia new file mode 100644 index 0000000..d97c877 --- /dev/null +++ b/tests/auto/variantparser/data/varianttest.uia @@ -0,0 +1,15 @@ +<?xml version='1.0' encoding='utf-8'?> +<application xmlns="http://qt.io/qt3dstudio/uia"> + <assets initial="varianttest"> + <presentation src="presentations/varianttest.uip" id="varianttest"/> + </assets> + <statemachine ref="#logic"> + <visual-states> + <state ref="Initial"> + <enter> + <goto-slide rel="next" element="main:Scene"/> + </enter> + </state> + </visual-states> + </statemachine> +</application> diff --git a/tests/auto/variantparser/tst_q3dsvariantparser.cpp b/tests/auto/variantparser/tst_q3dsvariantparser.cpp new file mode 100644 index 0000000..d2fcbcb --- /dev/null +++ b/tests/auto/variantparser/tst_q3dsvariantparser.cpp @@ -0,0 +1,331 @@ +/**************************************************************************** +** +** Copyright (C) 2019 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:GPL-EXCEPT$ +** 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 The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 as published by the Free Software +** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QtTest/QtTest> +#include <private/q3dsuipparser_p.h> +#include <private/q3dsutils_p.h> +#include <private/q3dsdatamodelparser_p.h> + +class tst_Q3DSVariantParser : public QObject +{ + Q_OBJECT + +private slots: + bool doesSceneContainLayer(Q3DSScene *scene, QString layerName); + + void initTestCase(); + void cleanup(); + + void testInvalidVariantsFiltered(); + void testNoVariantsFiltered(); + + void testAllVariantFiltered(); + void testCubeOnlyVariant(); + void testSphereOnlyVariant(); + void testConeOnlyVariant(); + + void testCenterVariant(); + void testEdgeVariant(); + void testEdgeAndAllVariant(); + void testEdgeAndCubeVariant(); + +private: + QString presName = QLatin1String("varianttest"); +}; + +bool tst_Q3DSVariantParser::doesSceneContainLayer(Q3DSScene *scene, QString layerName) +{ + bool layerFound = false; + for (int i = 0; i < scene->childCount(); ++i) { + Q3DSGraphObject *n = scene->childAtIndex(i); + if (n->type() == Q3DSGraphObject::Layer) + layerFound |= (n->name() == layerName); + } + + return layerFound; +} + +void tst_Q3DSVariantParser::initTestCase() +{ + Q3DSUtils::setDialogsEnabled(false); +} + +void tst_Q3DSVariantParser::cleanup() +{ +} + +void tst_Q3DSVariantParser::testInvalidVariantsFiltered() +{ + QHash<QStringRef, QVector<QStringRef>> variantMap; + QString group = QLatin1String("VarGroupDummy"); + QString variant = QLatin1String("VariantDummy"); + QVector<QStringRef> variants; + variants.append(QStringRef(&variant)); + variantMap[QStringRef(&group)] = variants; + + Q3DSUipParser parser; + QScopedPointer<Q3DSUipPresentation> pres( + parser.parse(QLatin1String(":/data/varianttest.uip"), + presName, + variantMap)); + QVERIFY(!pres.isNull()); + QVERIFY(!parser.readerErrorString().isEmpty()); + Q3DSScene *scene = pres->scene(); + QVERIFY(scene); + QVERIFY(scene->childCount() > 0); + QVERIFY(doesSceneContainLayer(scene, QLatin1String("CubeLayer"))); + QVERIFY(doesSceneContainLayer(scene, QLatin1String("SphereLayer"))); + QVERIFY(doesSceneContainLayer(scene, QLatin1String("ConeLayer"))); +} + +void tst_Q3DSVariantParser::testNoVariantsFiltered() +{ + QHash<QStringRef, QVector<QStringRef>> variantMap; + + Q3DSUipParser parser; + QScopedPointer<Q3DSUipPresentation> pres( + parser.parse(QLatin1String(":/data/varianttest.uip"), + presName, + variantMap)); + QVERIFY(!pres.isNull()); + QVERIFY(!parser.readerErrorString().isEmpty()); + Q3DSScene *scene = pres->scene(); + QVERIFY(scene); + QVERIFY(scene->childCount() > 0); + QVERIFY(doesSceneContainLayer(scene, QLatin1String("CubeLayer"))); + QVERIFY(doesSceneContainLayer(scene, QLatin1String("SphereLayer"))); + QVERIFY(doesSceneContainLayer(scene, QLatin1String("ConeLayer"))); +} + +void tst_Q3DSVariantParser::testAllVariantFiltered() +{ + QHash<QStringRef, QVector<QStringRef>> variantMap; + QString group = QLatin1String("Geom"); + QString variant = QLatin1String("All"); + QVector<QStringRef> variants; + variants.append(QStringRef(&variant)); + variantMap[QStringRef(&group)] = variants; + + Q3DSUipParser parser; + QScopedPointer<Q3DSUipPresentation> pres( + parser.parse(QLatin1String(":/data/varianttest.uip"), + presName, + variantMap)); + QVERIFY(!pres.isNull()); + QVERIFY(!parser.readerErrorString().isEmpty()); + Q3DSScene *scene = pres->scene(); + QVERIFY(scene); + QVERIFY(scene->childCount() > 0); + QVERIFY(doesSceneContainLayer(scene, QLatin1String("CubeLayer"))); + QVERIFY(doesSceneContainLayer(scene, QLatin1String("SphereLayer"))); + QVERIFY(doesSceneContainLayer(scene, QLatin1String("ConeLayer"))); +} + +void tst_Q3DSVariantParser::testCubeOnlyVariant() +{ + QHash<QStringRef, QVector<QStringRef>> variantMap; + QString group = QLatin1String("Geom"); + QString variant = QLatin1String("Cube"); + QVector<QStringRef> variants; + variants.append(QStringRef(&variant)); + variantMap[QStringRef(&group)] = variants; + + Q3DSUipParser parser; + QScopedPointer<Q3DSUipPresentation> pres( + parser.parse(QLatin1String(":/data/varianttest.uip"), + presName, + variantMap)); + QVERIFY(!pres.isNull()); + QVERIFY(!parser.readerErrorString().isEmpty()); + Q3DSScene *scene = pres->scene(); + QVERIFY(scene); + QVERIFY(scene->childCount() > 0); + QVERIFY(doesSceneContainLayer(scene, QLatin1String("CubeLayer"))); + QVERIFY(!doesSceneContainLayer(scene, QLatin1String("SphereLayer"))); + QVERIFY(!doesSceneContainLayer(scene, QLatin1String("ConeLayer"))); +} + +void tst_Q3DSVariantParser::testSphereOnlyVariant() +{ + QHash<QStringRef, QVector<QStringRef>> variantMap; + QString group = QLatin1String("Geom"); + QString variant = QLatin1String("Sphere"); + QVector<QStringRef> variants; + variants.append(QStringRef(&variant)); + variantMap[QStringRef(&group)] = variants; + + Q3DSUipParser parser; + QScopedPointer<Q3DSUipPresentation> pres( + parser.parse(QLatin1String(":/data/varianttest.uip"), + presName, + variantMap)); + QVERIFY(!pres.isNull()); + QVERIFY(!parser.readerErrorString().isEmpty()); + Q3DSScene *scene = pres->scene(); + QVERIFY(scene); + QVERIFY(scene->childCount() > 0); + QVERIFY(!doesSceneContainLayer(scene, QLatin1String("CubeLayer"))); + QVERIFY(doesSceneContainLayer(scene, QLatin1String("SphereLayer"))); + QVERIFY(!doesSceneContainLayer(scene, QLatin1String("ConeLayer"))); +} + +void tst_Q3DSVariantParser::testConeOnlyVariant() +{ + QHash<QStringRef, QVector<QStringRef>> variantMap; + QString group = QLatin1String("Geom"); + QString variant = QLatin1String("Cone"); + QVector<QStringRef> variants; + variants.append(QStringRef(&variant)); + variantMap[QStringRef(&group)] = variants; + + Q3DSUipParser parser; + QScopedPointer<Q3DSUipPresentation> pres( + parser.parse(QLatin1String(":/data/varianttest.uip"), + presName, + variantMap)); + QVERIFY(!pres.isNull()); + QVERIFY(!parser.readerErrorString().isEmpty()); + Q3DSScene *scene = pres->scene(); + QVERIFY(scene); + QVERIFY(scene->childCount() > 0); + QVERIFY(!doesSceneContainLayer(scene, QLatin1String("CubeLayer"))); + QVERIFY(!doesSceneContainLayer(scene, QLatin1String("SphereLayer"))); + QVERIFY(doesSceneContainLayer(scene, QLatin1String("ConeLayer"))); +} + +void tst_Q3DSVariantParser::testCenterVariant() +{ + QHash<QStringRef, QVector<QStringRef>> variantMap; + QString group = QLatin1String("Position"); + QString variant = QLatin1String("Center"); + QVector<QStringRef> variants; + variants.append(QStringRef(&variant)); + variantMap[QStringRef(&group)] = variants; + + Q3DSUipParser parser; + QScopedPointer<Q3DSUipPresentation> pres( + parser.parse(QLatin1String(":/data/varianttest.uip"), + presName, + variantMap)); + QVERIFY(!pres.isNull()); + QVERIFY(!parser.readerErrorString().isEmpty()); + Q3DSScene *scene = pres->scene(); + QVERIFY(scene); + QVERIFY(scene->childCount() > 0); + QVERIFY(!doesSceneContainLayer(scene, QLatin1String("CubeLayer"))); + QVERIFY(doesSceneContainLayer(scene, QLatin1String("SphereLayer"))); + QVERIFY(!doesSceneContainLayer(scene, QLatin1String("ConeLayer"))); +} + +void tst_Q3DSVariantParser::testEdgeVariant() +{ + QHash<QStringRef, QVector<QStringRef>> variantMap; + QString group = QLatin1String("Position"); + QString variant = QLatin1String("Edge"); + QVector<QStringRef> variants; + variants.append(QStringRef(&variant)); + variantMap[QStringRef(&group)] = variants; + + Q3DSUipParser parser; + QScopedPointer<Q3DSUipPresentation> pres( + parser.parse(QLatin1String(":/data/varianttest.uip"), + presName, + variantMap)); + QVERIFY(!pres.isNull()); + QVERIFY(!parser.readerErrorString().isEmpty()); + Q3DSScene *scene = pres->scene(); + QVERIFY(scene); + QVERIFY(scene->childCount() > 0); + QVERIFY(doesSceneContainLayer(scene, QLatin1String("CubeLayer"))); + QVERIFY(!doesSceneContainLayer(scene, QLatin1String("SphereLayer"))); + QVERIFY(doesSceneContainLayer(scene, QLatin1String("ConeLayer"))); +} + +void tst_Q3DSVariantParser::testEdgeAndAllVariant() +{ + QHash<QStringRef, QVector<QStringRef>> variantMap; + QString group1 = QLatin1String("Position"); + QString variant1 = QLatin1String("Edge"); + QString group2 = QLatin1String("Geom"); + QString variant2 = QLatin1String("All"); + QVector<QStringRef> variants1; + variants1.append(QStringRef(&variant1)); + variantMap[QStringRef(&group1)] = variants1; + QVector<QStringRef> variants2; + variants2.append(QStringRef(&variant2)); + variantMap[QStringRef(&group1)] = variants1; + variantMap[QStringRef(&group2)] = variants2; + + Q3DSUipParser parser; + QScopedPointer<Q3DSUipPresentation> pres( + parser.parse(QLatin1String(":/data/varianttest.uip"), + presName, + variantMap)); + QVERIFY(!pres.isNull()); + QVERIFY(!parser.readerErrorString().isEmpty()); + Q3DSScene *scene = pres->scene(); + QVERIFY(scene); + QVERIFY(scene->childCount() > 0); + QVERIFY(doesSceneContainLayer(scene, QLatin1String("CubeLayer"))); + QVERIFY(!doesSceneContainLayer(scene, QLatin1String("SphereLayer"))); + QVERIFY(doesSceneContainLayer(scene, QLatin1String("ConeLayer"))); +} + +void tst_Q3DSVariantParser::testEdgeAndCubeVariant() +{ + QHash<QStringRef, QVector<QStringRef>> variantMap; + QStringList variantList1; + QString group1 = QLatin1String("Position"); + QString variant1 = QLatin1String("Edge"); + QString group2 = QLatin1String("Geom"); + QString variant2 = QLatin1String("Cube"); + QVector<QStringRef> variants1; + variants1.append(QStringRef(&variant1)); + variantMap[QStringRef(&group1)] = variants1; + QVector<QStringRef> variants2; + variants2.append(QStringRef(&variant2)); + variantMap[QStringRef(&group1)] = variants1; + variantMap[QStringRef(&group2)] = variants2; + + Q3DSUipParser parser; + QScopedPointer<Q3DSUipPresentation> pres( + parser.parse(QLatin1String(":/data/varianttest.uip"), + presName, + variantMap)); + QVERIFY(!pres.isNull()); + QVERIFY(!parser.readerErrorString().isEmpty()); + Q3DSScene *scene = pres->scene(); + QVERIFY(scene); + QVERIFY(scene->childCount() > 0); + QVERIFY(doesSceneContainLayer(scene, QLatin1String("CubeLayer"))); + QVERIFY(!doesSceneContainLayer(scene, QLatin1String("SphereLayer"))); + QVERIFY(!doesSceneContainLayer(scene, QLatin1String("ConeLayer"))); +} + +#include <tst_q3dsvariantparser.moc> +QTEST_MAIN(tst_Q3DSVariantParser) diff --git a/tests/auto/variantparser/variantparser.pro b/tests/auto/variantparser/variantparser.pro new file mode 100644 index 0000000..c08f76f --- /dev/null +++ b/tests/auto/variantparser/variantparser.pro @@ -0,0 +1,8 @@ +TARGET = tst_variantparser +CONFIG += testcase + +QT += testlib 3drender 3dstudioruntime2-private + +SOURCES += tst_q3dsvariantparser.cpp + +RESOURCES += variantparser.qrc diff --git a/tests/auto/variantparser/variantparser.qrc b/tests/auto/variantparser/variantparser.qrc new file mode 100644 index 0000000..f161d8a --- /dev/null +++ b/tests/auto/variantparser/variantparser.qrc @@ -0,0 +1,5 @@ +<RCC> + <qresource prefix="/"> + <file>data</file> + </qresource> +</RCC> |