diff options
Diffstat (limited to 'tests/auto/threed')
98 files changed, 0 insertions, 19017 deletions
diff --git a/tests/auto/threed/load_model/load_model.pro b/tests/auto/threed/load_model/load_model.pro deleted file mode 100644 index 88a26c5f..00000000 --- a/tests/auto/threed/load_model/load_model.pro +++ /dev/null @@ -1,9 +0,0 @@ -load(qttest_p4.prf) -TEMPLATE=app -QT += testlib -CONFIG += unittest warn_on qt3d - -SOURCES += tst_load_model.cpp - -RESOURCES += \ - load_model.qrc diff --git a/tests/auto/threed/load_model/load_model.qrc b/tests/auto/threed/load_model/load_model.qrc deleted file mode 100644 index 5bb2fec0..00000000 --- a/tests/auto/threed/load_model/load_model.qrc +++ /dev/null @@ -1,13 +0,0 @@ -<RCC> - <qresource prefix="/data"> - <file>models/basic-cube.3ds</file> - <file>models/basic-cube.blend</file> - <file>models/basic-cube.mtl</file> - <file>models/basic-cube.obj</file> - <file>models/wave.obj</file> - <file>models/basic-cube.m3g</file> - <file>models/basic-cube.ply</file> - <file>models/basic-cube.x3d</file> - <file>models/basic-cube.dae</file> - </qresource> -</RCC> diff --git a/tests/auto/threed/load_model/models/basic-cube.3ds b/tests/auto/threed/load_model/models/basic-cube.3ds Binary files differdeleted file mode 100644 index fbd4c072..00000000 --- a/tests/auto/threed/load_model/models/basic-cube.3ds +++ /dev/null diff --git a/tests/auto/threed/load_model/models/basic-cube.blend b/tests/auto/threed/load_model/models/basic-cube.blend Binary files differdeleted file mode 100644 index 663e17de..00000000 --- a/tests/auto/threed/load_model/models/basic-cube.blend +++ /dev/null diff --git a/tests/auto/threed/load_model/models/basic-cube.dae b/tests/auto/threed/load_model/models/basic-cube.dae deleted file mode 100644 index 06167caf..00000000 --- a/tests/auto/threed/load_model/models/basic-cube.dae +++ /dev/null @@ -1,192 +0,0 @@ -<?xml version="1.0" encoding="utf-8"?> -<COLLADA version="1.4.0" xmlns="http://www.collada.org/2005/11/COLLADASchema"> - <asset> - <contributor> - <author>Illusoft Collada 1.4.0 plugin for Blender - http://colladablender.illusoft.com</author> - <authoring_tool>Blender v:249 - Illusoft Collada Exporter v:0.3.162</authoring_tool> - <comments></comments> - <copyright></copyright> - <source_data>file:///Users/sez/depot/research/qt3d_assimp/tests/auto/threed/load_model/models/basic-cube.blend</source_data> - </contributor> - <created>2010-12-15T02:14:49.600213</created> - <modified>2010-12-15T02:14:49.600247</modified> - <unit meter="0.01" name="centimeter"/> - <up_axis>Z_UP</up_axis> - </asset> - <library_effects> - <effect id="Red-fx" name="Red-fx"> - <profile_COMMON> - <technique sid="blender"> - <phong> - <emission> - <color>0.00000 0.00000 0.00000 1</color> - </emission> - <ambient> - <color>0.45937 0.07860 0.07860 1</color> - </ambient> - <diffuse> - <color>0.91873 0.15720 0.15720 1</color> - </diffuse> - <specular> - <color>0.50000 0.50000 0.50000 1</color> - </specular> - <shininess> - <float>12.5</float> - </shininess> - <reflective> - <color>1.00000 1.00000 1.00000 1</color> - </reflective> - <reflectivity> - <float>0.0</float> - </reflectivity> - <transparent> - <color>1 1 1 1</color> - </transparent> - <transparency> - <float>0.0</float> - </transparency> - </phong> - </technique> - </profile_COMMON> - </effect> - <effect id="SlateGray-fx" name="SlateGray-fx"> - <profile_COMMON> - <technique sid="blender"> - <phong> - <emission> - <color>0.00000 0.00000 0.00000 1</color> - </emission> - <ambient> - <color>0.18500 0.28000 0.30500 1</color> - </ambient> - <diffuse> - <color>0.37000 0.56000 0.61000 1</color> - </diffuse> - <specular> - <color>0.50000 0.50000 0.50000 1</color> - </specular> - <shininess> - <float>12.5</float> - </shininess> - <reflective> - <color>1.00000 1.00000 1.00000 1</color> - </reflective> - <reflectivity> - <float>0.0</float> - </reflectivity> - <transparent> - <color>1 1 1 1</color> - </transparent> - <transparency> - <float>0.0</float> - </transparency> - </phong> - </technique> - </profile_COMMON> - </effect> - </library_effects> - <library_materials> - <material id="Red" name="Red"> - <instance_effect url="#Red-fx"/> - </material> - <material id="SlateGray" name="SlateGray"> - <instance_effect url="#SlateGray-fx"/> - </material> - </library_materials> - <library_geometries> - <geometry id="CubeObject-Geometry" name="CubeObject-Geometry"> - <mesh> - <source id="CubeObject-Geometry-Position"> - <float_array count="24" id="CubeObject-Geometry-Position-array">1.00000 1.00000 -1.00000 1.00000 -1.00000 -1.00000 -1.00000 -1.00000 -1.00000 -1.00000 1.00000 -1.00000 1.00000 1.00000 1.00000 1.00000 -1.00000 1.00000 -1.00000 -1.00000 1.00000 -1.00000 1.00000 1.00000</float_array> - <technique_common> - <accessor count="8" source="#CubeObject-Geometry-Position-array" stride="3"> - <param type="float" name="X"></param> - <param type="float" name="Y"></param> - <param type="float" name="Z"></param> - </accessor> - </technique_common> - </source> - <source id="CubeObject-Geometry-Normals"> - <float_array count="18" id="CubeObject-Geometry-Normals-array">0.00000 0.00000 -1.00000 0.00000 -0.00000 1.00000 1.00000 -0.00000 0.00000 -0.00000 -1.00000 -0.00000 -1.00000 0.00000 -0.00000 0.00000 1.00000 0.00000</float_array> - <technique_common> - <accessor count="6" source="#CubeObject-Geometry-Normals-array" stride="3"> - <param type="float" name="X"></param> - <param type="float" name="Y"></param> - <param type="float" name="Z"></param> - </accessor> - </technique_common> - </source> - <vertices id="CubeObject-Geometry-Vertex"> - <input semantic="POSITION" source="#CubeObject-Geometry-Position"/> - </vertices> - <triangles count="10" material="Red"> - <input offset="0" semantic="VERTEX" source="#CubeObject-Geometry-Vertex"/> - <input offset="1" semantic="NORMAL" source="#CubeObject-Geometry-Normals"/> - <p>0 0 1 0 2 0 2 0 3 0 0 0 0 2 4 2 5 2 5 2 1 2 0 2 1 3 5 3 6 3 6 3 2 3 1 3 2 4 6 4 7 4 7 4 3 4 2 4 4 5 0 5 3 5 3 5 7 5 4 5</p> - </triangles> - <triangles count="2" material="SlateGray"> - <input offset="0" semantic="VERTEX" source="#CubeObject-Geometry-Vertex"/> - <input offset="1" semantic="NORMAL" source="#CubeObject-Geometry-Normals"/> - <p>4 1 7 1 6 1 6 1 5 1 4 1</p> - </triangles> - </mesh> - </geometry> - </library_geometries> - <library_visual_scenes> - <visual_scene id="Scene" name="Scene"> - <node layer="L1" id="CubeObject" name="CubeObject"> - <translate sid="translate">0.00000 0.00000 0.00000</translate> - <rotate sid="rotateZ">0 0 1 0.00000</rotate> - <rotate sid="rotateY">0 1 0 -0.00000</rotate> - <rotate sid="rotateX">1 0 0 0.00000</rotate> - <scale sid="scale">1.00000 1.00000 1.00000</scale> - <instance_geometry url="#CubeObject-Geometry"> - <bind_material> - <technique_common> - <instance_material symbol="Red" target="#Red"> - <bind_vertex_input input_semantic="TEXCOORD" input_set="1" semantic="CHANNEL1"/> - </instance_material> - <instance_material symbol="SlateGray" target="#SlateGray"> - <bind_vertex_input input_semantic="TEXCOORD" input_set="1" semantic="CHANNEL1"/> - </instance_material> - </technique_common> - </bind_material> - </instance_geometry> - </node> - </visual_scene> - </library_visual_scenes> - <library_physics_materials> - <physics_material id="CubeObject-PhysicsMaterial" name="CubeObject-PhysicsMaterial"> - <technique_common> - <dynamic_friction>0.5</dynamic_friction> - <restitution>0.0</restitution> - <static_friction>0.5</static_friction> - </technique_common> - </physics_material> - </library_physics_materials> - <library_physics_models> - <physics_model id="Scene-PhysicsModel" name="Scene-PhysicsModel"> - <rigid_body name="CubeObject-RigidBody" sid="CubeObject-RigidBody"> - <technique_common> - <dynamic>false</dynamic> - <mass>0</mass> - <instance_physics_material url="#CubeObject-PhysicsMaterial"/> - <shape> - <instance_geometry url="#CubeObject-Geometry"/> - </shape> - </technique_common> - </rigid_body> - </physics_model> - </library_physics_models> - <library_physics_scenes> - <physics_scene id="Scene-Physics" name="Scene-Physics"> - <instance_physics_model url="#Scene-PhysicsModel"> - <instance_rigid_body body="CubeObject-RigidBody" target="#CubeObject"/> - </instance_physics_model> - </physics_scene> - </library_physics_scenes> - <scene> - <instance_physics_scene url="#Scene-Physics"/> - <instance_visual_scene url="#Scene"/> - </scene> -</COLLADA> diff --git a/tests/auto/threed/load_model/models/basic-cube.m3g b/tests/auto/threed/load_model/models/basic-cube.m3g Binary files differdeleted file mode 100644 index 28962d8a..00000000 --- a/tests/auto/threed/load_model/models/basic-cube.m3g +++ /dev/null diff --git a/tests/auto/threed/load_model/models/basic-cube.mtl b/tests/auto/threed/load_model/models/basic-cube.mtl deleted file mode 100644 index ce8c4b93..00000000 --- a/tests/auto/threed/load_model/models/basic-cube.mtl +++ /dev/null @@ -1,22 +0,0 @@ -# Blender3D MTL File: basic-cube.blend -# Material Count: 2 -newmtl SlateGray -Ns 96.078431 -Ka 0.000000 0.000000 0.000000 -Kd 0.296000 0.448000 0.488000 -Ks 0.500000 0.500000 0.500000 -Ni 1.000000 -d 1.000000 -illum 2 - - -newmtl Red -Ns 96.078431 -Ka 0.000000 0.000000 0.000000 -Kd 0.734986 0.125756 0.125756 -Ks 0.500000 0.500000 0.500000 -Ni 1.000000 -d 1.000000 -illum 2 - - diff --git a/tests/auto/threed/load_model/models/basic-cube.obj b/tests/auto/threed/load_model/models/basic-cube.obj deleted file mode 100644 index 039b220e..00000000 --- a/tests/auto/threed/load_model/models/basic-cube.obj +++ /dev/null @@ -1,27 +0,0 @@ -# Blender3D v249 OBJ File: basic-cube.blend -# www.blender3d.org -mtllib basic-cube.mtl -o CubeObject_CubeMesh -v 1.000000 -1.000000 -1.000000 -v 1.000000 -1.000000 1.000000 -v -1.000000 -1.000000 1.000000 -v -1.000000 -1.000000 -1.000000 -v 1.000000 1.000000 -1.000000 -v 0.999999 1.000000 1.000001 -v -1.000000 1.000000 1.000000 -v -1.000000 1.000000 -1.000000 -vn 0.000000 -1.000000 0.000000 -vn 1.000000 0.000000 0.000000 -vn 0.000000 0.000000 1.000000 -vn -1.000000 0.000000 0.000000 -vn 0.000000 0.000000 -1.000000 -vn 0.000000 1.000000 0.000000 -usemtl Red -f 1//1 2//1 3//1 4//1 -f 1//2 5//2 6//2 2//2 -f 2//3 6//3 7//3 3//3 -f 3//4 7//4 8//4 4//4 -f 5//5 1//5 4//5 8//5 -usemtl SlateGray -f 5//6 8//6 7//6 6//6 - diff --git a/tests/auto/threed/load_model/models/basic-cube.ply b/tests/auto/threed/load_model/models/basic-cube.ply deleted file mode 100644 index ddb5be70..00000000 --- a/tests/auto/threed/load_model/models/basic-cube.ply +++ /dev/null @@ -1,43 +0,0 @@ -ply -format ascii 1.0 -comment Created by Blender3D 249 - www.blender.org, source file: basic-cube.blend -element vertex 24 -property float x -property float y -property float z -property float nx -property float ny -property float nz -element face 6 -property list uchar uint vertex_indices -end_header -1.000000 1.000000 -1.000000 0.000000 0.000000 -1.000000 -1.000000 -1.000000 -1.000000 0.000000 0.000000 -1.000000 --1.000000 -1.000000 -1.000000 0.000000 0.000000 -1.000000 --1.000000 1.000000 -1.000000 0.000000 0.000000 -1.000000 -1.000000 0.999999 1.000000 0.000000 -0.000000 1.000000 --1.000000 1.000000 1.000000 0.000000 -0.000000 1.000000 --1.000000 -1.000000 1.000000 0.000000 -0.000000 1.000000 -0.999999 -1.000001 1.000000 0.000000 -0.000000 1.000000 -1.000000 1.000000 -1.000000 1.000000 -0.000000 0.000000 -1.000000 0.999999 1.000000 1.000000 -0.000000 0.000000 -0.999999 -1.000001 1.000000 1.000000 -0.000000 0.000000 -1.000000 -1.000000 -1.000000 1.000000 -0.000000 0.000000 -1.000000 -1.000000 -1.000000 -0.000000 -1.000000 -0.000000 -0.999999 -1.000001 1.000000 -0.000000 -1.000000 -0.000000 --1.000000 -1.000000 1.000000 -0.000000 -1.000000 -0.000000 --1.000000 -1.000000 -1.000000 -0.000000 -1.000000 -0.000000 --1.000000 -1.000000 -1.000000 -1.000000 0.000000 -0.000000 --1.000000 -1.000000 1.000000 -1.000000 0.000000 -0.000000 --1.000000 1.000000 1.000000 -1.000000 0.000000 -0.000000 --1.000000 1.000000 -1.000000 -1.000000 0.000000 -0.000000 -1.000000 0.999999 1.000000 0.000000 1.000000 0.000000 -1.000000 1.000000 -1.000000 0.000000 1.000000 0.000000 --1.000000 1.000000 -1.000000 0.000000 1.000000 0.000000 --1.000000 1.000000 1.000000 0.000000 1.000000 0.000000 -4 0 1 2 3 -4 4 5 6 7 -4 8 9 10 11 -4 12 13 14 15 -4 16 17 18 19 -4 20 21 22 23 diff --git a/tests/auto/threed/load_model/models/basic-cube.x3d b/tests/auto/threed/load_model/models/basic-cube.x3d deleted file mode 100644 index 0c52894d..00000000 --- a/tests/auto/threed/load_model/models/basic-cube.x3d +++ /dev/null @@ -1,30 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!DOCTYPE X3D PUBLIC "ISO//Web3D//DTD X3D 3.0//EN" "http://www.web3d.org/specifications/x3d-3.0.dtd"> -<X3D version="3.0" profile="Immersive" xmlns:xsd="http://www.w3.org/2001/XMLSchema-instance" xsd:noNamespaceSchemaLocation="http://www.web3d.org/specifications/x3d-3.0.xsd"> -<head> - <meta name="filename" content="basic-cube.x3d" /> - <meta name="generator" content="Blender 249" /> - <meta name="translator" content="X3D exporter v1.55 (2006/01/17)" /> -</head> -<Scene> -<NavigationInfo headlight="FALSE" visibilityLimit="0.0" type='"EXAMINE","ANY"' avatarSize="0.25, 1.75, 0.75" /> -<Background groundColor="0.057 0.221 0.4" skyColor="0.057 0.221 0.4" /> - -<Collision enabled="false"> - <Transform DEF="CubeObject" translation="0.000000 0.000000 0.000000" scale="1.000000 1.000000 1.000000" rotation="-1.000000 0.000000 0.000000 1.570796"> - <Shape> - <Appearance> - <Material DEF="MA_Red" diffuseColor="0.919 0.157 0.157" specularColor="0.401 0.401 0.401" emissiveColor="0.0 0.0 0.0" - ambientIntensity="0.167" shininess="0.098" transparency="0.0" /> - </Appearance> - <IndexedFaceSet solid="true" coordIndex="0 1 2 -1, 0 2 3 -1, 4 7 6 -1, 4 6 5 -1, 0 4 5 -1, 0 5 1 -1, 1 5 6 -1, 1 6 2 -1, 2 6 7 -1, 2 7 3 -1, 4 0 3 -1, 4 3 7 -1, "> - <Coordinate DEF="coord_CubeObject" - point="1.000000 1.000000 -1.000000, 1.000000 -1.000000 -1.000000, -1.000000 -1.000000 -1.000000, -1.000000 1.000000 -1.000000, 1.000000 0.999999 1.000000, 0.999999 -1.000001 1.000000, -1.000000 -1.000000 1.000000, -1.000000 1.000000 1.000000, " /> - </IndexedFaceSet> - </Shape> -</Transform> -</Collision> - - -</Scene> -</X3D> diff --git a/tests/auto/threed/load_model/models/cube.dae b/tests/auto/threed/load_model/models/cube.dae deleted file mode 100644 index cda4d16c..00000000 --- a/tests/auto/threed/load_model/models/cube.dae +++ /dev/null @@ -1,146 +0,0 @@ -<?xml version="1.0" encoding="utf-8"?> -<COLLADA version="1.4.0" xmlns="http://www.collada.org/2005/11/COLLADASchema"> - <asset> - <contributor> - <author>Illusoft Collada 1.4.0 plugin for Blender - http://colladablender.illusoft.com</author> - <authoring_tool>Blender v:249 - Illusoft Collada Exporter v:0.3.162</authoring_tool> - <comments></comments> - <copyright></copyright> - <source_data>file://</source_data> - </contributor> - <created>2010-12-15T02:07:15.785711</created> - <modified>2010-12-15T02:07:15.787585</modified> - <unit meter="0.01" name="centimeter"/> - <up_axis>Z_UP</up_axis> - </asset> - <library_effects> - <effect id="Material-fx" name="Material-fx"> - <profile_COMMON> - <technique sid="blender"> - <phong> - <emission> - <color>0.00000 0.00000 0.00000 1</color> - </emission> - <ambient> - <color>0.40000 0.40000 0.40000 1</color> - </ambient> - <diffuse> - <color>0.80000 0.80000 0.80000 1</color> - </diffuse> - <specular> - <color>0.50000 0.50000 0.50000 1</color> - </specular> - <shininess> - <float>12.5</float> - </shininess> - <reflective> - <color>1.00000 1.00000 1.00000 1</color> - </reflective> - <reflectivity> - <float>0.0</float> - </reflectivity> - <transparent> - <color>1 1 1 1</color> - </transparent> - <transparency> - <float>0.0</float> - </transparency> - </phong> - </technique> - </profile_COMMON> - </effect> - </library_effects> - <library_materials> - <material id="Material" name="Material"> - <instance_effect url="#Material-fx"/> - </material> - </library_materials> - <library_geometries> - <geometry id="Cube_001" name="Cube_001"> - <mesh> - <source id="Cube_001-Position"> - <float_array count="24" id="Cube_001-Position-array">1.00000 1.00000 -1.00000 1.00000 -1.00000 -1.00000 -1.00000 -1.00000 -1.00000 -1.00000 1.00000 -1.00000 1.00000 1.00000 1.00000 1.00000 -1.00000 1.00000 -1.00000 -1.00000 1.00000 -1.00000 1.00000 1.00000</float_array> - <technique_common> - <accessor count="8" source="#Cube_001-Position-array" stride="3"> - <param type="float" name="X"></param> - <param type="float" name="Y"></param> - <param type="float" name="Z"></param> - </accessor> - </technique_common> - </source> - <source id="Cube_001-Normals"> - <float_array count="18" id="Cube_001-Normals-array">0.00000 0.00000 -1.00000 0.00000 -0.00000 1.00000 1.00000 -0.00000 0.00000 -0.00000 -1.00000 -0.00000 -1.00000 0.00000 -0.00000 0.00000 1.00000 0.00000</float_array> - <technique_common> - <accessor count="6" source="#Cube_001-Normals-array" stride="3"> - <param type="float" name="X"></param> - <param type="float" name="Y"></param> - <param type="float" name="Z"></param> - </accessor> - </technique_common> - </source> - <vertices id="Cube_001-Vertex"> - <input semantic="POSITION" source="#Cube_001-Position"/> - </vertices> - <triangles count="12" material="Material"> - <input offset="0" semantic="VERTEX" source="#Cube_001-Vertex"/> - <input offset="1" semantic="NORMAL" source="#Cube_001-Normals"/> - <p>0 0 1 0 2 0 2 0 3 0 0 0 4 1 7 1 6 1 6 1 5 1 4 1 0 2 4 2 5 2 5 2 1 2 0 2 1 3 5 3 6 3 6 3 2 3 1 3 2 4 6 4 7 4 7 4 3 4 2 4 4 5 0 5 3 5 3 5 7 5 4 5</p> - </triangles> - </mesh> - </geometry> - </library_geometries> - <library_visual_scenes> - <visual_scene id="Scene" name="Scene"> - <node layer="L1" id="Cube" name="Cube"> - <translate sid="translate">0.00000 0.00000 0.00000</translate> - <rotate sid="rotateZ">0 0 1 0.00000</rotate> - <rotate sid="rotateY">0 1 0 -0.00000</rotate> - <rotate sid="rotateX">1 0 0 0.00000</rotate> - <scale sid="scale">1.00000 1.00000 1.00000</scale> - <instance_geometry url="#Cube_001"> - <bind_material> - <technique_common> - <instance_material symbol="Material" target="#Material"> - <bind_vertex_input input_semantic="TEXCOORD" input_set="1" semantic="CHANNEL1"/> - </instance_material> - </technique_common> - </bind_material> - </instance_geometry> - </node> - </visual_scene> - </library_visual_scenes> - <library_physics_materials> - <physics_material id="Cube-PhysicsMaterial" name="Cube-PhysicsMaterial"> - <technique_common> - <dynamic_friction>0.5</dynamic_friction> - <restitution>0.0</restitution> - <static_friction>0.5</static_friction> - </technique_common> - </physics_material> - </library_physics_materials> - <library_physics_models> - <physics_model id="Scene-PhysicsModel" name="Scene-PhysicsModel"> - <rigid_body name="Cube-RigidBody" sid="Cube-RigidBody"> - <technique_common> - <dynamic>false</dynamic> - <mass>0</mass> - <instance_physics_material url="#Cube-PhysicsMaterial"/> - <shape> - <instance_geometry url="#Cube_001"/> - </shape> - </technique_common> - </rigid_body> - </physics_model> - </library_physics_models> - <library_physics_scenes> - <physics_scene id="Scene-Physics" name="Scene-Physics"> - <instance_physics_model url="#Scene-PhysicsModel"> - <instance_rigid_body body="Cube-RigidBody" target="#Cube"/> - </instance_physics_model> - </physics_scene> - </library_physics_scenes> - <scene> - <instance_physics_scene url="#Scene-Physics"/> - <instance_visual_scene url="#Scene"/> - </scene> -</COLLADA> diff --git a/tests/auto/threed/load_model/models/teacup.bez b/tests/auto/threed/load_model/models/teacup.bez deleted file mode 100644 index f4dde3ef..00000000 --- a/tests/auto/threed/load_model/models/teacup.bez +++ /dev/null @@ -1,280 +0,0 @@ -26 -1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16 -4,17,18,19,8,20,21,22,12,23,24,25,16,26,27,28 -19,29,30,31,22,32,33,34,25,35,36,37,28,38,39,40 -31,41,42,1,34,43,44,5,37,45,46,9,40,47,48,13 -13,14,15,16,49,50,51,52,53,54,55,56,57,58,59,60 -16,26,27,28,52,61,62,63,56,64,65,66,60,67,68,69 -28,38,39,40,63,70,71,72,66,73,74,75,69,76,77,78 -40,47,48,13,72,79,80,49,75,81,82,53,78,83,84,57 -193,194,195,196,197,198,199,200,201,202,203,204,1,2,3,4 -196,205,206,207,200,208,209,210,204,211,212,213,4,17,18,19 -207,214,215,216,210,217,218,219,213,220,221,222,19,29,30,31 -216,223,224,193,219,225,226,197,222,227,228,201,31,41,42,1 -229,230,231,28,232,233,234,235,236,237,238,239,240,241,242,243 -28,244,245,229,235,246,247,232,239,248,249,236,243,250,251,240 -57,58,59,60,85,86,87,88,89,90,91,92,93,94,95,96 -60,67,68,69,88,97,98,99,92,100,101,102,96,103,104,105 -69,76,77,78,99,106,107,108,102,109,110,111,105,112,113,114 -78,83,84,57,108,115,116,85,111,117,118,89,114,119,120,93 -93,94,95,96,121,122,123,124,125,126,127,128,129,130,131,132 -96,103,104,105,124,133,134,135,128,136,137,138,132,139,140,141 -105,112,113,114,135,142,143,144,138,145,146,147,141,148,149,150 -114,119,120,93,144,151,152,121,147,153,154,125,150,155,156,129 -129,130,131,132,157,158,159,160,161,162,163,164,165,166,167,168 -132,139,140,141,160,169,170,171,164,172,173,174,168,175,176,177 -141,148,149,150,171,178,179,180,174,181,182,183,177,184,185,186 -150,155,156,129,180,187,188,157,183,189,190,161,186,191,192,165 -251 -0.409091,0.772727,0.0 -0.409091,0.772727,-0.229091 -0.229091,0.772727,-0.409091 -0.0,0.772727,-0.409091 -0.409091,0.886364,0.0 -0.409091,0.886364,-0.229091 -0.229091,0.886364,-0.409091 -0.0,0.886364,-0.409091 -0.454545,0.886364,0.0 -0.454545,0.886364,-0.254545 -0.254545,0.886364,-0.454545 -0.0,0.886364,-0.454545 -0.454545,0.772727,0.0 -0.454545,0.772727,-0.254545 -0.254545,0.772727,-0.454545 -0.0,0.772727,-0.454545 --0.229091,0.772727,-0.409091 --0.409091,0.772727,-0.229091 --0.409091,0.772727,0.0 --0.229091,0.886364,-0.409091 --0.409091,0.886364,-0.229091 --0.409091,0.886364,0.0 --0.254545,0.886364,-0.454545 --0.454545,0.886364,-0.254545 --0.454545,0.886364,0.0 --0.254545,0.772727,-0.454545 --0.454545,0.772727,-0.254545 --0.454545,0.772727,0.0 --0.409091,0.772727,0.229091 --0.229091,0.772727,0.409091 -0.0,0.772727,0.409091 --0.409091,0.886364,0.229091 --0.229091,0.886364,0.409091 -0.0,0.886364,0.409091 --0.454545,0.886364,0.254545 --0.254545,0.886364,0.454545 -0.0,0.886364,0.454545 --0.454545,0.772727,0.254545 --0.254545,0.772727,0.454545 -0.0,0.772727,0.454545 -0.229091,0.772727,0.409091 -0.409091,0.772727,0.229091 -0.229091,0.886364,0.409091 -0.409091,0.886364,0.229091 -0.254545,0.886364,0.454545 -0.454545,0.886364,0.254545 -0.254545,0.772727,0.454545 -0.454545,0.772727,0.254545 -0.454545,0.545455,0.0 -0.454545,0.545455,-0.254545 -0.254545,0.545455,-0.454545 -0.0,0.545455,-0.454545 -0.454545,0.272727,0.0 -0.454545,0.272727,-0.254545 -0.254545,0.272727,-0.454545 -0.0,0.272727,-0.454545 -0.318182,0.0454545,0.0 -0.318182,0.0454545,-0.178182 -0.178182,0.0454545,-0.318182 -0.0,0.0454545,-0.318182 --0.254545,0.545455,-0.454545 --0.454545,0.545455,-0.254545 --0.454545,0.545455,0.0 --0.254545,0.272727,-0.454545 --0.454545,0.272727,-0.254545 --0.454545,0.272727,0.0 --0.178182,0.0454545,-0.318182 --0.318182,0.0454545,-0.178182 --0.318182,0.0454545,0.0 --0.454545,0.545455,0.254545 --0.254545,0.545455,0.454545 -0.0,0.545455,0.454545 --0.454545,0.272727,0.254545 --0.254545,0.272727,0.454545 -0.0,0.272727,0.454545 --0.318182,0.0454545,0.178182 --0.178182,0.0454545,0.318182 -0.0,0.0454545,0.318182 -0.254545,0.545455,0.454545 -0.454545,0.545455,0.254545 -0.254545,0.272727,0.454545 -0.454545,0.272727,0.254545 -0.178182,0.0454545,0.318182 -0.318182,0.0454545,0.178182 -0.545455,0.0454545,0.0 -0.545455,0.0454545,-0.305455 -0.305455,0.0454545,-0.545455 -0.0,0.0454545,-0.545455 -0.727273,0.136364,0.0 -0.727273,0.136364,-0.407273 -0.407273,0.136364,-0.727273 -0.0,0.136364,-0.727273 -0.909091,0.136364,0.0 -0.909091,0.136364,-0.509091 -0.509091,0.136364,-0.909091 -0.0,0.136364,-0.909091 --0.305455,0.0454545,-0.545455 --0.545455,0.0454545,-0.305455 --0.545455,0.0454545,0.0 --0.407273,0.136364,-0.727273 --0.727273,0.136364,-0.407273 --0.727273,0.136364,0.0 --0.509091,0.136364,-0.909091 --0.909091,0.136364,-0.509091 --0.909091,0.136364,0.0 --0.545455,0.0454545,0.305455 --0.305455,0.0454545,0.545455 -0.0,0.0454545,0.545455 --0.727273,0.136364,0.407273 --0.407273,0.136364,0.727273 -0.0,0.136364,0.727273 --0.909091,0.136364,0.509091 --0.509091,0.136364,0.909091 -0.0,0.136364,0.909091 -0.305455,0.0454545,0.545455 -0.545455,0.0454545,0.305455 -0.407273,0.136364,0.727273 -0.727273,0.136364,0.407273 -0.509091,0.136364,0.909091 -0.909091,0.136364,0.509091 -1.0,0.136364,0.0 -1.0,0.136364,-0.56 -0.56,0.136364,-1.0 -0.0,0.136364,-1.0 -1.0,0.0909091,0.0 -1.0,0.0909091,-0.56 -0.56,0.0909091,-1.0 -0.0,0.0909091,-1.0 -0.909091,0.0909091,0.0 -0.909091,0.0909091,-0.509091 -0.509091,0.0909091,-0.909091 -0.0,0.0909091,-0.909091 --0.56,0.136364,-1.0 --1.0,0.136364,-0.56 --1.0,0.136364,0.0 --0.56,0.0909091,-1.0 --1.0,0.0909091,-0.56 --1.0,0.0909091,0.0 --0.509091,0.0909091,-0.909091 --0.909091,0.0909091,-0.509091 --0.909091,0.0909091,0.0 --1.0,0.136364,0.56 --0.56,0.136364,1.0 -0.0,0.136364,1.0 --1.0,0.0909091,0.56 --0.56,0.0909091,1.0 -0.0,0.0909091,1.0 --0.909091,0.0909091,0.509091 --0.509091,0.0909091,0.909091 -0.0,0.0909091,0.909091 -0.56,0.136364,1.0 -1.0,0.136364,0.56 -0.56,0.0909091,1.0 -1.0,0.0909091,0.56 -0.509091,0.0909091,0.909091 -0.909091,0.0909091,0.509091 -0.727273,0.0909091,0.0 -0.727273,0.0909091,-0.407273 -0.407273,0.0909091,-0.727273 -0.0,0.0909091,-0.727273 -0.545455,0.0,0.0 -0.545455,0.0,-0.305455 -0.305455,0.0,-0.545455 -0.0,0.0,-0.545455 -0.318182,0.0,0.0 -0.318182,0.0,-0.178182 -0.178182,0.0,-0.318182 -0.0,0.0,-0.318182 --0.407273,0.0909091,-0.727273 --0.727273,0.0909091,-0.407273 --0.727273,0.0909091,0.0 --0.305455,0.0,-0.545455 --0.545455,0.0,-0.305455 --0.545455,0.0,0.0 --0.178182,0.0,-0.318182 --0.318182,0.0,-0.178182 --0.318182,0.0,0.0 --0.727273,0.0909091,0.407273 --0.407273,0.0909091,0.727273 -0.0,0.0909091,0.727273 --0.545455,0.0,0.305455 --0.305455,0.0,0.545455 -0.0,0.0,0.545455 --0.318182,0.0,0.178182 --0.178182,0.0,0.318182 -0.0,0.0,0.318182 -0.407273,0.0909091,0.727273 -0.727273,0.0909091,0.407273 -0.305455,0.0,0.545455 -0.545455,0.0,0.305455 -0.178182,0.0,0.318182 -0.318182,0.0,0.178182 -0.272727,0.0454545,0.0 -0.272727,0.0454545,-0.152727 -0.152727,0.0454545,-0.272727 -0.0,0.0454545,-0.272727 -0.409091,0.272727,0.0 -0.409091,0.272727,-0.229091 -0.229091,0.272727,-0.409091 -0.0,0.272727,-0.409091 -0.409091,0.545455,0.0 -0.409091,0.545455,-0.229091 -0.229091,0.545455,-0.409091 -0.0,0.545455,-0.409091 --0.152727,0.0454545,-0.272727 --0.272727,0.0454545,-0.152727 --0.272727,0.0454545,0.0 --0.229091,0.272727,-0.409091 --0.409091,0.272727,-0.229091 --0.409091,0.272727,0.0 --0.229091,0.545455,-0.409091 --0.409091,0.545455,-0.229091 --0.409091,0.545455,0.0 --0.272727,0.0454545,0.152727 --0.152727,0.0454545,0.272727 -0.0,0.0454545,0.272727 --0.409091,0.272727,0.229091 --0.229091,0.272727,0.409091 -0.0,0.272727,0.409091 --0.409091,0.545455,0.229091 --0.229091,0.545455,0.409091 -0.0,0.545455,0.409091 -0.152727,0.0454545,0.272727 -0.272727,0.0454545,0.152727 -0.229091,0.272727,0.409091 -0.409091,0.272727,0.229091 -0.229091,0.545455,0.409091 -0.409091,0.545455,0.229091 --0.454545,0.704545,0.0 --0.454545,0.704545,-0.0454545 --0.454545,0.772727,-0.0454545 --0.772727,0.863636,0.0 --0.772727,0.863636,-0.0454545 --0.818182,0.954545,-0.0454545 --0.818182,0.954545,0.0 --0.772727,0.522727,0.0 --0.772727,0.522727,-0.0454545 --0.909091,0.477273,-0.0454545 --0.909091,0.477273,0.0 --0.409091,0.363636,0.0 --0.409091,0.363636,-0.0454545 --0.409091,0.295455,-0.0454545 --0.409091,0.295455,0.0 --0.454545,0.772727,0.0454545 --0.454545,0.704545,0.0454545 --0.818182,0.954545,0.0454545 --0.772727,0.863636,0.0454545 --0.909091,0.477273,0.0454545 --0.772727,0.522727,0.0454545 --0.409091,0.295455,0.0454545 --0.409091,0.363636,0.0454545 -# reverse-patches diff --git a/tests/auto/threed/load_model/models/wave.obj b/tests/auto/threed/load_model/models/wave.obj deleted file mode 100644 index d47fba48..00000000 --- a/tests/auto/threed/load_model/models/wave.obj +++ /dev/null @@ -1,476 +0,0 @@ -o Wave_Obj -v -180 -180 20.21 -v -180 -120 39.571 -v -180 -60 103.881 -v -180 0 150.836 -v -180 60 104.229 -v -180 120 39.241 -v -180 180 20.21 -v -170 -180 41.143 -v -170 -120 71.763 -v -170 -60 155.217 -v -170 0 201.577 -v -170 60 142.873 -v -170 120 64.235 -v -170 180 41.143 -v -160 -180 69.49 -v -160 -120 113.906 -v -160 -60 212.144 -v -160 0 253.998 -v -160 60 183.949 -v -160 120 94.971 -v -160 180 69.49 -v -150 -180 103.5 -v -150 -120 161.47 -v -150 -60 269.407 -v -150 0 304.377 -v -150 60 223.999 -v -150 120 128.686 -v -150 180 103.5 -v -140 -180 138.975 -v -140 -120 208.317 -v -140 -60 322.442 -v -140 0 349.416 -v -140 60 260.097 -v -140 120 161.508 -v -140 180 138.975 -v -130 -180 171.412 -v -130 -120 249.8 -v -130 -60 367.819 -v -130 0 386.836 -v -130 60 290.235 -v -130 120 190.26 -v -130 180 171.412 -v -120 -180 198.071 -v -120 -120 283.402 -v -120 -60 403.825 -v -120 0 415.796 -v -120 60 313.627 -v -120 120 213.295 -v -120 180 198.071 -v -110 -180 218.155 -v -110 -120 308.549 -v -110 -60 430.441 -v -110 0 436.769 -v -110 60 330.597 -v -110 120 230.372 -v -110 180 218.155 -v -100 -180 232.096 -v -100 -120 325.951 -v -100 -60 448.727 -v -100 0 450.948 -v -100 60 342.085 -v -100 120 242.103 -v -100 180 232.096 -v -90 -180 240.799 -v -90 -120 336.8 -v -90 -60 460.077 -v -90 0 459.653 -v -90 60 349.144 -v -90 120 249.379 -v -90 180 240.799 -v -80 -180 245.162 -v -80 -120 342.236 -v -80 -60 465.751 -v -80 0 463.975 -v -80 60 352.652 -v -80 120 253.013 -v -80 180 245.162 -v -70 -180 245.876 -v -70 -120 343.125 -v -70 -60 466.678 -v -70 0 464.679 -v -70 60 353.224 -v -70 120 253.607 -v -70 180 245.876 -v -60 -180 243.379 -v -60 -120 340.015 -v -60 -60 463.434 -v -60 0 462.212 -v -60 60 351.221 -v -60 120 251.529 -v -60 180 243.379 -v -50 -180 237.873 -v -50 -120 333.154 -v -50 -60 456.266 -v -50 0 456.739 -v -50 60 346.781 -v -50 120 246.937 -v -50 180 237.873 -v -40 -180 229.336 -v -40 -120 322.509 -v -40 -60 445.118 -v -40 0 448.165 -v -40 60 339.829 -v -40 120 239.788 -v -40 180 229.336 -v -30 -180 217.539 -v -30 -120 307.779 -v -30 -60 429.63 -v -30 0 436.135 -v -30 60 330.084 -v -30 120 229.851 -v -30 180 217.539 -v -20 -180 202.042 -v -20 -120 288.383 -v -20 -60 409.118 -v -20 0 419.997 -v -20 60 317.024 -v -20 120 216.689 -v -20 180 202.042 -v -10 -180 182.22 -v -10 -120 263.461 -v -10 -60 382.526 -v -10 0 398.745 -v -10 60 299.848 -v -10 120 199.654 -v -10 180 182.22 -v 0 -180 157.356 -v 0 -120 231.929 -v 0 -60 348.414 -v 0 0 370.958 -v 0 60 277.434 -v 0 120 177.914 -v 0 180 157.356 -v 10 -180 127.018 -v 10 -120 192.755 -v 10 -60 305.077 -v 10 0 334.827 -v 10 60 248.38 -v 10 120 150.643 -v 10 180 127.018 -v 20 -180 92.098 -v 20 -120 145.878 -v 20 -60 251.138 -v 20 0 288.517 -v 20 60 211.347 -v 20 120 117.688 -v 20 180 92.098 -v 30 -180 56.374 -v 30 -120 94.668 -v 30 -60 187.198 -v 30 0 231.371 -v 30 60 166.122 -v 30 120 81.11 -v 30 180 56.374 -v 40 -180 25.98 -v 40 -120 48.522 -v 40 -60 119.078 -v 40 0 166.372 -v 40 60 115.898 -v 40 120 46.398 -v 40 180 25.98 -v 50 -180 5.981 -v 50 -120 16.643 -v 50 -60 60.852 -v 50 0 102.95 -v 50 60 69.36 -v 50 120 19.719 -v 50 180 5.981 -v 60 -180 0.255 -v 60 -120 1.383 -v 60 -60 23.928 -v 60 0 54.669 -v 60 60 35.477 -v 60 120 4.089 -v 60 180 0.255 -v 70 -180 18.321 -v 70 -120 3.316 -v 70 -60 5.835 -v 70 0 25.99 -v 70 60 15.427 -v 70 120 0.156 -v 70 180 18.321 -v 80 -180 59.32 -v 80 -120 28.502 -v 80 -60 0.178 -v 80 0 11.554 -v 80 60 5.561 -v 80 120 8.051 -v 80 180 59.32 -v 90 -180 57.91 -v 90 -120 68.006 -v 90 -60 0.905 -v 90 0 5.415 -v 90 60 1.77 -v 90 120 31.774 -v 90 180 57.91 -v 100 -180 57.335 -v 100 -120 67.375 -v 100 -60 2.408 -v 100 0 3.583 -v 100 60 0.819 -v 100 120 49.323 -v 100 180 57.335 -v 110 -180 57.545 -v 110 -120 67.606 -v 110 -60 1.766 -v 110 0 4.209 -v 110 60 1.126 -v 110 120 49.47 -v 110 180 57.545 -v 120 -180 58.399 -v 120 -120 68.542 -v 120 -60 0.211 -v 120 0 7.273 -v 120 60 2.852 -v 120 120 18.844 -v 120 180 58.399 -v 130 -180 59.722 -v 130 -120 19.94 -v 130 -60 0.647 -v 130 0 13.771 -v 130 60 7.03 -v 130 120 5.33 -v 130 180 59.722 -v 140 -180 20.309 -v 140 -120 3.839 -v 140 -60 5.366 -v 140 0 25.099 -v 140 60 14.806 -v 140 120 0.252 -v 140 180 20.309 -v 150 -180 2.643 -v 150 -120 0.03 -v 150 -60 16.035 -v 150 0 42.966 -v 150 60 27.3 -v 150 120 1.447 -v 150 180 2.643 -v 160 -180 0.334 -v 160 -120 4.859 -v 160 -60 34.47 -v 160 0 69.362 -v 160 60 45.731 -v 160 120 8.272 -v 160 180 0.334 -v 170 -180 6.626 -v 170 -120 17.756 -v 170 -60 63.11 -v 170 0 105.651 -v 170 60 71.284 -v 170 120 20.723 -v 170 180 6.626 -v 180 -180 20.21 -v 180 -120 39.571 -v 180 -60 103.881 -v 180 0 150.836 -v 180 60 104.229 -v 180 120 39.241 -v 180 180 20.21 -f 1/1 2/2 9/3 8/4 -f 2/1 3/2 10/3 9/4 -f 3/1 4/2 11/3 10/4 -f 4/1 5/2 12/3 11/4 -f 5/1 6/2 13/3 12/4 -f 6/1 7/2 14/3 13/4 -f 8/1 9/2 16/3 15/4 -f 9/1 10/2 17/3 16/4 -f 10/1 11/2 18/3 17/4 -f 11/1 12/2 19/3 18/4 -f 12/1 13/2 20/3 19/4 -f 13/1 14/2 21/3 20/4 -f 15/1 16/2 23/3 22/4 -f 16/1 17/2 24/3 23/4 -f 17/1 18/2 25/3 24/4 -f 18/1 19/2 26/3 25/4 -f 19/1 20/2 27/3 26/4 -f 20/1 21/2 28/3 27/4 -f 22/1 23/2 30/3 29/4 -f 23/1 24/2 31/3 30/4 -f 24/1 25/2 32/3 31/4 -f 25/1 26/2 33/3 32/4 -f 26/1 27/2 34/3 33/4 -f 27/1 28/2 35/3 34/4 -f 29/1 30/2 37/3 36/4 -f 30/1 31/2 38/3 37/4 -f 31/1 32/2 39/3 38/4 -f 32/1 33/2 40/3 39/4 -f 33/1 34/2 41/3 40/4 -f 34/1 35/2 42/3 41/4 -f 36/1 37/2 44/3 43/4 -f 37/1 38/2 45/3 44/4 -f 38/1 39/2 46/3 45/4 -f 39/1 40/2 47/3 46/4 -f 40/1 41/2 48/3 47/4 -f 41/1 42/2 49/3 48/4 -f 43/1 44/2 51/3 50/4 -f 44/1 45/2 52/3 51/4 -f 45/1 46/2 53/3 52/4 -f 46/1 47/2 54/3 53/4 -f 47/1 48/2 55/3 54/4 -f 48/1 49/2 56/3 55/4 -f 50/1 51/2 58/3 57/4 -f 51/1 52/2 59/3 58/4 -f 52/1 53/2 60/3 59/4 -f 53/1 54/2 61/3 60/4 -f 54/1 55/2 62/3 61/4 -f 55/1 56/2 63/3 62/4 -f 57/1 58/2 65/3 64/4 -f 58/1 59/2 66/3 65/4 -f 59/1 60/2 67/3 66/4 -f 60/1 61/2 68/3 67/4 -f 61/1 62/2 69/3 68/4 -f 62/1 63/2 70/3 69/4 -f 64/1 65/2 72/3 71/4 -f 65/1 66/2 73/3 72/4 -f 66/1 67/2 74/3 73/4 -f 67/1 68/2 75/3 74/4 -f 68/1 69/2 76/3 75/4 -f 69/1 70/2 77/3 76/4 -f 71/1 72/2 79/3 78/4 -f 72/1 73/2 80/3 79/4 -f 73/1 74/2 81/3 80/4 -f 74/1 75/2 82/3 81/4 -f 75/1 76/2 83/3 82/4 -f 76/1 77/2 84/3 83/4 -f 78/1 79/2 86/3 85/4 -f 79/1 80/2 87/3 86/4 -f 80/1 81/2 88/3 87/4 -f 81/1 82/2 89/3 88/4 -f 82/1 83/2 90/3 89/4 -f 83/1 84/2 91/3 90/4 -f 85/1 86/2 93/3 92/4 -f 86/1 87/2 94/3 93/4 -f 87/1 88/2 95/3 94/4 -f 88/1 89/2 96/3 95/4 -f 89/1 90/2 97/3 96/4 -f 90/1 91/2 98/3 97/4 -f 92/1 93/2 100/3 99/4 -f 93/1 94/2 101/3 100/4 -f 94/1 95/2 102/3 101/4 -f 95/1 96/2 103/3 102/4 -f 96/1 97/2 104/3 103/4 -f 97/1 98/2 105/3 104/4 -f 99/1 100/2 107/3 106/4 -f 100/1 101/2 108/3 107/4 -f 101/1 102/2 109/3 108/4 -f 102/1 103/2 110/3 109/4 -f 103/1 104/2 111/3 110/4 -f 104/1 105/2 112/3 111/4 -f 106/1 107/2 114/3 113/4 -f 107/1 108/2 115/3 114/4 -f 108/1 109/2 116/3 115/4 -f 109/1 110/2 117/3 116/4 -f 110/1 111/2 118/3 117/4 -f 111/1 112/2 119/3 118/4 -f 113/1 114/2 121/3 120/4 -f 114/1 115/2 122/3 121/4 -f 115/1 116/2 123/3 122/4 -f 116/1 117/2 124/3 123/4 -f 117/1 118/2 125/3 124/4 -f 118/1 119/2 126/3 125/4 -f 120/1 121/2 128/3 127/4 -f 121/1 122/2 129/3 128/4 -f 122/1 123/2 130/3 129/4 -f 123/1 124/2 131/3 130/4 -f 124/1 125/2 132/3 131/4 -f 125/1 126/2 133/3 132/4 -f 127/1 128/2 135/3 134/4 -f 128/1 129/2 136/3 135/4 -f 129/1 130/2 137/3 136/4 -f 130/1 131/2 138/3 137/4 -f 131/1 132/2 139/3 138/4 -f 132/1 133/2 140/3 139/4 -f 134/1 135/2 142/3 141/4 -f 135/1 136/2 143/3 142/4 -f 136/1 137/2 144/3 143/4 -f 137/1 138/2 145/3 144/4 -f 138/1 139/2 146/3 145/4 -f 139/1 140/2 147/3 146/4 -f 141/1 142/2 149/3 148/4 -f 142/1 143/2 150/3 149/4 -f 143/1 144/2 151/3 150/4 -f 144/1 145/2 152/3 151/4 -f 145/1 146/2 153/3 152/4 -f 146/1 147/2 154/3 153/4 -f 148/1 149/2 156/3 155/4 -f 149/1 150/2 157/3 156/4 -f 150/1 151/2 158/3 157/4 -f 151/1 152/2 159/3 158/4 -f 152/1 153/2 160/3 159/4 -f 153/1 154/2 161/3 160/4 -f 155/1 156/2 163/3 162/4 -f 156/1 157/2 164/3 163/4 -f 157/1 158/2 165/3 164/4 -f 158/1 159/2 166/3 165/4 -f 159/1 160/2 167/3 166/4 -f 160/1 161/2 168/3 167/4 -f 162/1 163/2 170/3 169/4 -f 163/1 164/2 171/3 170/4 -f 164/1 165/2 172/3 171/4 -f 165/1 166/2 173/3 172/4 -f 166/1 167/2 174/3 173/4 -f 167/1 168/2 175/3 174/4 -f 169/1 170/2 177/3 176/4 -f 170/1 171/2 178/3 177/4 -f 171/1 172/2 179/3 178/4 -f 172/1 173/2 180/3 179/4 -f 173/1 174/2 181/3 180/4 -f 174/1 175/2 182/3 181/4 -f 176/1 177/2 184/3 183/4 -f 177/1 178/2 185/3 184/4 -f 178/1 179/2 186/3 185/4 -f 179/1 180/2 187/3 186/4 -f 180/1 181/2 188/3 187/4 -f 181/1 182/2 189/3 188/4 -f 183/1 184/2 191/3 190/4 -f 184/1 185/2 192/3 191/4 -f 185/1 186/2 193/3 192/4 -f 186/1 187/2 194/3 193/4 -f 187/1 188/2 195/3 194/4 -f 188/1 189/2 196/3 195/4 -f 190/1 191/2 198/3 197/4 -f 191/1 192/2 199/3 198/4 -f 192/1 193/2 200/3 199/4 -f 193/1 194/2 201/3 200/4 -f 194/1 195/2 202/3 201/4 -f 195/1 196/2 203/3 202/4 -f 197/1 198/2 205/3 204/4 -f 198/1 199/2 206/3 205/4 -f 199/1 200/2 207/3 206/4 -f 200/1 201/2 208/3 207/4 -f 201/1 202/2 209/3 208/4 -f 202/1 203/2 210/3 209/4 -f 204/1 205/2 212/3 211/4 -f 205/1 206/2 213/3 212/4 -f 206/1 207/2 214/3 213/4 -f 207/1 208/2 215/3 214/4 -f 208/1 209/2 216/3 215/4 -f 209/1 210/2 217/3 216/4 -f 211/1 212/2 219/3 218/4 -f 212/1 213/2 220/3 219/4 -f 213/1 214/2 221/3 220/4 -f 214/1 215/2 222/3 221/4 -f 215/1 216/2 223/3 222/4 -f 216/1 217/2 224/3 223/4 -f 218/1 219/2 226/3 225/4 -f 219/1 220/2 227/3 226/4 -f 220/1 221/2 228/3 227/4 -f 221/1 222/2 229/3 228/4 -f 222/1 223/2 230/3 229/4 -f 223/1 224/2 231/3 230/4 -f 225/1 226/2 233/3 232/4 -f 226/1 227/2 234/3 233/4 -f 227/1 228/2 235/3 234/4 -f 228/1 229/2 236/3 235/4 -f 229/1 230/2 237/3 236/4 -f 230/1 231/2 238/3 237/4 -f 232/1 233/2 240/3 239/4 -f 233/1 234/2 241/3 240/4 -f 234/1 235/2 242/3 241/4 -f 235/1 236/2 243/3 242/4 -f 236/1 237/2 244/3 243/4 -f 237/1 238/2 245/3 244/4 -f 239/1 240/2 247/3 246/4 -f 240/1 241/2 248/3 247/4 -f 241/1 242/2 249/3 248/4 -f 242/1 243/2 250/3 249/4 -f 243/1 244/2 251/3 250/4 -f 244/1 245/2 252/3 251/4 -f 246/1 247/2 254/3 253/4 -f 247/1 248/2 255/3 254/4 -f 248/1 249/2 256/3 255/4 -f 249/1 250/2 257/3 256/4 -f 250/1 251/2 258/3 257/4 -f 251/1 252/2 259/3 258/4 diff --git a/tests/auto/threed/load_model/tst_load_model.cpp b/tests/auto/threed/load_model/tst_load_model.cpp deleted file mode 100644 index 824ba5d5..00000000 --- a/tests/auto/threed/load_model/tst_load_model.cpp +++ /dev/null @@ -1,232 +0,0 @@ -/**************************************************************************** -** -** 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 QtQuick3D module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** 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. -** -** 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. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include <QtTest/QtTest> - -#include "qglabstractscene.h" - -class tst_LoadModel : public QObject -{ - Q_OBJECT -public: - tst_LoadModel() {} - ~tst_LoadModel() {} - -private slots: - void load_data(); - void load(); - void create_data(); - void create(); -}; - -// Just try to load all the models in the resources file - no checking -void tst_LoadModel::load_data() -{ - QString model_path(QLatin1String(":/data/models")); - QDir data(model_path); - - // only load if its a supported format - QStringList entries = data.entryList(QGLAbstractScene::supportedFormats()); - - QTest::addColumn<QString>("model"); - - for (int i = 0; i < entries.size(); ++i) - QTest::newRow(qPrintable(entries.at(i))) << entries.at(i); -} - -void tst_LoadModel::load() -{ - QFETCH(QString, model); - - QGLAbstractScene *scene = 0; - QString model_path(QLatin1String(":/data/models/%1")); - model_path = model_path.arg(model); - - QFile f(model_path); - QVERIFY(f.open(QIODevice::ReadOnly)); - - QUrl u; - u.setPath(model_path); - u.setScheme("file"); - - scene = QGLAbstractScene::loadScene(&f,u, QString(), QString()); - QVERIFY(scene != 0); -} - -void tst_LoadModel::create_data() -{ - QTest::addColumn<QString>("model"); - QTest::addColumn<QString>("options"); - QTest::addColumn<QString>("importName"); - QTest::addColumn<QString>("nodeName"); - QTest::addColumn<QString>("materialName"); - QTest::addColumn<QRgb>("materialDiffuse"); - QTest::addColumn<QString>("texture"); - QTest::addColumn<int>("expected_vertices"); - QTest::addColumn<int>("expected_indices"); - - ////// --- OBJ --- - - // default is faceted for obj - QTest::newRow("cube-obj-default") - << "basic-cube.obj" << "" - << "basic-cube.obj" << "CubeObject_CubeMesh" << "Red" - << qRgb(188, 32, 32) << "tex" - << 24 << 36; - - // force a faceted load - QTest::newRow("cube-obj-faceted") - << "basic-cube.obj" << "ForceFaceted" - << "basic-cube.obj" << "CubeObject_CubeMesh" << "Red" - << qRgb(188, 32, 32) << "tex" - << 24 << 36; - - // force a smooth load - QTest::newRow("cube-obj-smooth") - << "basic-cube.obj" << "ForceSmooth" - << "basic-cube.obj" << "CubeObject_CubeMesh" << "Red" - << qRgb(188, 32, 32) << "tex" - << 24 << 36; - - - ////// --- 3DS --- - - // default is faceted - QTest::newRow("cube-3ds-default") - << "basic-cube.3ds" << "" - << "basic-cube.3ds" << "CubeObject::SlateGray" << "SlateGray" - << qRgb(94, 142, 155) << "tex" - << 12 << 36; - - // force smooth - QTest::newRow("cube-3ds-smooth") - << "basic-cube.3ds" << "ForceSmooth" - << "basic-cube.3ds" << "CubeObject::Red" << "Red" - << qRgb(234, 40, 40) << "tex" - << 12 << 36; - - - ////// --- wave model --- - - // default is faceted - QTest::newRow("wave-obj-default") - << "wave.obj" << "" - << "wave.obj" << "Wave_Obj" << "" - << qRgb(0, 0, 0) << "" - << 259 << 1296; - - // force smooth - QTest::newRow("wave-obj-faceted") - << "wave.obj" << "ForceFaceted" - << "wave.obj" << "Wave_Obj" << "" - << qRgb(0, 0, 0) << "" - << 864 << 1296; -} - -void tst_LoadModel::create() -{ - QFETCH(QString, model); - QFETCH(QString, options); - QFETCH(QString, importName); - QFETCH(QString, nodeName); - QFETCH(QString, materialName); - QFETCH(QRgb, materialDiffuse); - QFETCH(QString, texture); - QFETCH(int, expected_vertices); - QFETCH(int, expected_indices); - - QGLAbstractScene *scene = 0; - QString model_path(QLatin1String(":/data/models/%1")); - model_path = model_path.arg(model); - - QFile f(model_path); - QVERIFY(f.open(QIODevice::ReadOnly)); - - QUrl u; - u.setPath(model_path); - u.setScheme("file"); - - scene = QGLAbstractScene::loadScene(&f, u, QString(), options); - QVERIFY(scene != 0); - - QGLSceneNode *node = scene->mainNode(); - - //qDumpScene(node); - - QCOMPARE(node->objectName(), importName); - - QGLSceneNode *foundGeometry = 0; - QGLSceneNode *foundNode = nodeName.isEmpty() ? (QGLSceneNode *)1 : 0; - QGLSceneNode *foundMaterial = materialName.isEmpty() ? (QGLSceneNode *)1 : 0; - QList<QGLSceneNode*> list = node->allChildren(); - for (int i = 0; i < list.size(); ++ i) - { - if (!foundGeometry && list.at(i)->geometry().count() > 0) - foundGeometry = list.at(i); - if (!foundNode && list.at(i)->objectName() == nodeName) - foundNode = list.at(i); - if (!foundMaterial && list.at(i)->material() && - (list.at(i)->material()->objectName() == materialName)) - foundMaterial = list.at(i); - } - - QVERIFY2(foundGeometry != 0, "A non-null geometry node was not found"); - QVERIFY2(foundNode != 0, qPrintable(nodeName + QLatin1String(" named node not found"))); - QVERIFY2(foundMaterial != 0, qPrintable(materialName + QLatin1String(" named material not found"))); - - int r, g, b; - if (!materialName.isEmpty()) - { - foundMaterial->material()->diffuseColor().getRgb(&r, &g, &b); - QCOMPARE(materialDiffuse, qRgb(r, g, b)); - } - - QGeometryData data = foundGeometry->geometry(); - QVERIFY(data.count() > 0); - - QCOMPARE(data.vertices().count(), expected_vertices); - QCOMPARE(data.normals().count(), expected_vertices); - QCOMPARE(data.indices().count(), expected_indices); -} - -QTEST_APPLESS_MAIN(tst_LoadModel) - -#include "tst_load_model.moc" diff --git a/tests/auto/threed/qareaallocator/qareaallocator.pro b/tests/auto/threed/qareaallocator/qareaallocator.pro deleted file mode 100644 index b41e5d7f..00000000 --- a/tests/auto/threed/qareaallocator/qareaallocator.pro +++ /dev/null @@ -1,6 +0,0 @@ -load(qttest_p4.prf) -TEMPLATE=app -QT += testlib -CONFIG += unittest warn_on qt3d - -SOURCES += tst_qareaallocator.cpp diff --git a/tests/auto/threed/qareaallocator/tst_qareaallocator.cpp b/tests/auto/threed/qareaallocator/tst_qareaallocator.cpp deleted file mode 100644 index 40b76faf..00000000 --- a/tests/auto/threed/qareaallocator/tst_qareaallocator.cpp +++ /dev/null @@ -1,280 +0,0 @@ -/**************************************************************************** -** -** 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 QtQuick3D module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** 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. -** -** 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. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include <QtTest/QtTest> -#include "qareaallocator.h" - -class tst_QAreaAllocator : public QObject -{ - Q_OBJECT -public: - tst_QAreaAllocator() {} - ~tst_QAreaAllocator() {} - -private slots: - void create(); - void allocateSimple(); - void allocateGeneral(); - void allocateUniform(); -}; - -void tst_QAreaAllocator::create() -{ - QSimpleAreaAllocator alloc1(QSize(400, 200)); - QCOMPARE(alloc1.size(), QSize(400, 200)); - QCOMPARE(alloc1.minimumAllocation(), QSize(1, 1)); - QCOMPARE(alloc1.margin(), QSize(0, 0)); - - alloc1.setMinimumAllocation(QSize(5, 7)); - QCOMPARE(alloc1.minimumAllocation(), QSize(5, 7)); - - alloc1.setMargin(QSize(8, 9)); - QCOMPARE(alloc1.margin(), QSize(8, 9)); - - alloc1.expand(QSize(300, 21)); - QCOMPARE(alloc1.size(), QSize(400, 200)); - - alloc1.expand(QSize(300, 210)); - QCOMPARE(alloc1.size(), QSize(400, 210)); - - alloc1.expand(QSize(3000, 110)); - QCOMPARE(alloc1.size(), QSize(3000, 210)); - - alloc1.expandBy(QSize(-1, -1000)); - QCOMPARE(alloc1.size(), QSize(3000, 210)); - - alloc1.expandBy(QSize(1, 10)); - QCOMPARE(alloc1.size(), QSize(3001, 220)); - - QGeneralAreaAllocator alloc2(QSize(400, 200)); - QCOMPARE(alloc2.size(), QSize(512, 256)); - QCOMPARE(alloc2.minimumAllocation(), QSize(8, 8)); - QCOMPARE(alloc2.margin(), QSize(0, 0)); - - alloc2.expand(QSize(256, 96)); - QCOMPARE(alloc2.size(), QSize(512, 256)); - - alloc2.expand(QSize(256, 257)); - QCOMPARE(alloc2.size(), QSize(512, 512)); - - alloc2.expand(QSize(513, 257)); - QCOMPARE(alloc2.size(), QSize(1024, 512)); - - alloc2.expandBy(QSize(-100, -100)); - QCOMPARE(alloc2.size(), QSize(1024, 512)); - - alloc2.expandBy(QSize(1, 2)); - QCOMPARE(alloc2.size(), QSize(2048, 1024)); - - QUniformAreaAllocator alloc3(QSize(400, 200), QSize(16, 16)); - QCOMPARE(alloc3.size(), QSize(400, 200)); - QCOMPARE(alloc3.minimumAllocation(), QSize(1, 1)); - QCOMPARE(alloc3.margin(), QSize(0, 0)); - - alloc3.expand(QSize(256, 96)); - QCOMPARE(alloc3.size(), QSize(400, 200)); - - alloc3.expand(QSize(256, 257)); - QCOMPARE(alloc3.size(), QSize(400, 257)); - - alloc3.expand(QSize(513, 257)); - QCOMPARE(alloc3.size(), QSize(513, 257)); - - alloc3.expandBy(QSize(-100, -100)); - QCOMPARE(alloc3.size(), QSize(513, 257)); - - alloc3.expandBy(QSize(1, 2)); - QCOMPARE(alloc3.size(), QSize(514, 259)); -} - -void tst_QAreaAllocator::allocateSimple() -{ - // The simple allocator returns regions in a left-to-right, - // top-to-bottom order across the image extents. - QSimpleAreaAllocator alloc1(QSize(100, 100)); - QRect rect; - for (int y = 0; y < 10; ++y) { - for (int x = 0; x < 10; ++x) { - rect = alloc1.allocate(QSize(10, 10)); - QCOMPARE(rect, QRect(x * 10, y * 10, 10, 10)); - } - } - rect = alloc1.allocate(QSize(10, 10)); - QVERIFY(rect.isNull()); - - // Release doesn't do anything on the simple allocator. - alloc1.release(QRect(0, 0, 10, 10)); - rect = alloc1.allocate(QSize(10, 10)); - QVERIFY(rect.isNull()); - - // Test minimum allocation sizes. - QSimpleAreaAllocator alloc2(QSize(100, 100)); - alloc2.setMinimumAllocation(QSize(10, 5)); - for (int y = 0; y < 10; ++y) { - for (int x = 0; x < 10; ++x) { - rect = alloc2.allocate(QSize(x + 1, y + 1)); - if (y < 5) - QCOMPARE(rect, QRect(x * 10, y * 5, x + 1, y + 1)); - else - QCOMPARE(rect, QRect(x * 10, (y - 5) * 10 + 25, x + 1, y + 1)); - } - } - rect = alloc2.allocate(QSize(10, 10)); - QCOMPARE(rect, QRect(0, 75, 10, 10)); // Still some space left over. - rect = alloc2.allocate(QSize(10, 26)); // Won't fit. - QVERIFY(rect.isNull()); - rect = alloc2.allocate(QSize(10, 10)); // Should still fit. - QCOMPARE(rect, QRect(10, 75, 10, 10)); -} - -void tst_QAreaAllocator::allocateGeneral() -{ - QGeneralAreaAllocator alloc1(QSize(128, 128)); - QRect rect; - QList<QRect> allocations; - for (int y = 0; y < 16; ++y) { - for (int x = 0; x < 16; ++x) { - // The order in which allocations are returned is not - // as predictable as QSimpleAreaAllocator. But we can - // ensure that all allocations are unique and 8x8-aligned. - rect = alloc1.allocate(QSize(8, 8)); - QVERIFY((rect.x() % 8) == 0); - QVERIFY((rect.y() % 8) == 0); - QVERIFY((rect.height() % 8) == 0); - QVERIFY((rect.height() % 8) == 0); - QVERIFY(!allocations.contains(rect)); - allocations += rect; - } - } - QCOMPARE(allocations.size(), 256); - rect = alloc1.allocate(QSize(8, 8)); - QVERIFY(rect.isNull()); - - // Double the width and height and then do some more allocations at 16x16. - alloc1.expandBy(QSize(1, 1)); - for (int z = 0; z < 3; ++z) { - for (int y = 0; y < 8; ++y) { - for (int x = 0; x < 8; ++x) { - rect = alloc1.allocate(QSize(16, 16)); - QVERIFY((rect.x() % 8) == 0); - QVERIFY((rect.y() % 8) == 0); - QVERIFY((rect.height() % 16) == 0); - QVERIFY((rect.height() % 16) == 0); - QVERIFY(!allocations.contains(rect)); - allocations += rect; - } - } - } - QCOMPARE(allocations.size(), 256 + 3 * 8 * 8); - rect = alloc1.allocate(QSize(8, 8)); - QVERIFY(rect.isNull()); - - // Release the 8x8 allocations. - for (int y = 0; y < 16; ++y) - for (int x = 0; x < 16; ++x) - alloc1.release(QRect(x * 8, y * 8, 8, 8)); - rect = alloc1.allocate(QSize(8, 8)); - QVERIFY(!rect.isNull()); - alloc1.release(rect); - - // Allocate some other sizes into the gap we've just made. - rect = alloc1.allocate(QSize(256, 256)); // Too big. - QVERIFY(rect.isNull()); - rect = alloc1.allocate(QSize(64, 128)); - QVERIFY(!rect.isNull()); - rect = alloc1.allocate(QSize(64, 64)); - QVERIFY(!rect.isNull()); - rect = alloc1.allocate(QSize(64, 48)); // Over-allocates to 64x64. - QVERIFY(!rect.isNull()); - rect = alloc1.allocate(QSize(8, 8)); // Will fail. - QVERIFY(rect.isNull()); -} - -void tst_QAreaAllocator::allocateUniform() -{ - // The uniform allocator initially returns regions in a - // left-to-right, top-to-bottom order across the image extents. - QUniformAreaAllocator alloc1(QSize(100, 100), QSize(10, 10)); - QRect rect; - for (int y = 0; y < 10; ++y) { - for (int x = 0; x < 10; ++x) { - rect = alloc1.allocate(QSize(10, 10)); - QCOMPARE(rect, QRect(x * 10, y * 10, 10, 10)); - } - } - rect = alloc1.allocate(QSize(10, 10)); - QVERIFY(rect.isNull()); - - // Release some areas and then allocate again. Should act like a stack. - rect = QRect(60, 50, 10, 10); - QRect rect2 = QRect(50, 40, 10, 10); - alloc1.release(rect); - alloc1.release(rect2); - QCOMPARE(alloc1.allocate(QSize(10, 10)), rect2); - QCOMPARE(alloc1.allocate(QSize(10, 10)), rect); - QVERIFY(alloc1.allocate(QSize(10, 10)).isNull()); - - // Expand the allocation area. - alloc1.release(rect); // Copy across at least 1 free list entry. - alloc1.expandBy(QSize(10, 10)); - for (int count = 0; count < 22; ++count) { - rect = alloc1.allocate(QSize(10, 10)); - QVERIFY(!rect.isNull()); - } - rect = alloc1.allocate(QSize(10, 10)); - QVERIFY(rect.isNull()); - - // Release everything and then reallocate. - for (int y = 0; y < 11; ++y) { - for (int x = 0; x < 11; ++x) - alloc1.release(QRect(x * 10, y * 10, 10, 10)); - } - for (int count = 0; count < (11 * 11); ++count) { - rect = alloc1.allocate(QSize(10, 10)); - QVERIFY(!rect.isNull()); - } - rect = alloc1.allocate(QSize(10, 10)); - QVERIFY(rect.isNull()); -} - -QTEST_APPLESS_MAIN(tst_QAreaAllocator) - -#include "tst_qareaallocator.moc" diff --git a/tests/auto/threed/qarray/qarray.pro b/tests/auto/threed/qarray/qarray.pro deleted file mode 100644 index 9c5f37e0..00000000 --- a/tests/auto/threed/qarray/qarray.pro +++ /dev/null @@ -1,6 +0,0 @@ -load(qttest_p4.prf) -TEMPLATE=app -QT += testlib -CONFIG += unittest warn_on qt3d - -SOURCES += tst_qarray.cpp diff --git a/tests/auto/threed/qarray/tst_qarray.cpp b/tests/auto/threed/qarray/tst_qarray.cpp deleted file mode 100644 index 3a7f36f2..00000000 --- a/tests/auto/threed/qarray/tst_qarray.cpp +++ /dev/null @@ -1,1862 +0,0 @@ -/**************************************************************************** -** -** 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 QtQuick3D module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** 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. -** -** 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. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include <QtTest/QtTest> -#include "qarray.h" -#include <QtGui/qvector3d.h> -#include <QtCore/qstring.h> - -// We ensure to test the following types to cover all of the -// relevant QTypeInfo variations: -// -// QArray<float> Primitive types -// QArray<QString> Movable types -// QArray<ComplexValue> Complex types - -class tst_QArray : public QObject -{ - Q_OBJECT -public: - tst_QArray() {} - ~tst_QArray() {} - -private slots: - void create(); - void append(); - void appendTwoAtATime(); - void appendThreeAtATime(); - void appendFourAtATime(); - void appendArray(); - void setAt(); - void value(); - void replace(); - void copy(); - void resize(); - void reserve(); - void squeeze(); - void compare(); - void remove(); - void removeFirstLast(); - void extend(); - void reverse(); - void reversed(); - void mid(); - void left(); - void right(); - void iterate(); - void copyPrealloc(); - void insert(); - void fromRawData(); - void fromWritableRawData(); - void search(); - void fill(); - void zeroPrealloc(); - void exceptions(); - void dataStream(); -}; - -// This must match the default for PreallocSize. -static const int ExpectedMinCapacity = 8; - -// Exception type that is thrown by ComplexValue. -class ComplexValueException -{ -public: - ComplexValueException(int value, bool inCtor) - : m_value(value), m_inCtor(inCtor) {} - - int value() const { return m_value; } - bool inConstructor() const { return m_inCtor; } - -private: - int m_value; - bool m_inCtor; -}; - -// Complex type that helps the tests determine if QArray is calling -// constructors, destructors, and copy constructors in the right places. -class ComplexValue -{ -public: - enum Mode - { - Default, - Init, - Copy, - CopiedAgain, - Assign, - ThrowInCtor, - ThrowOnCopy - }; - - static int destroyCount; - - ComplexValue() : m_value(-1), m_mode(Default) {} - ComplexValue(int value) : m_value(value), m_mode(Init) {} -#ifndef QT_NO_EXCEPTIONS - ComplexValue(int value, Mode mode) : m_value(value), m_mode(mode) - { - if (mode == ThrowInCtor) - throw new ComplexValueException(value, true); - } -#endif - ComplexValue(const ComplexValue& other) - : m_value(other.m_value) - { - if (other.m_mode == Copy || other.m_mode == CopiedAgain) - m_mode = CopiedAgain; -#ifndef QT_NO_EXCEPTIONS - else if (other.m_mode == ThrowOnCopy) - throw new ComplexValueException(other.m_value, false); -#endif - else - m_mode = Copy; - } - ~ComplexValue() { ++destroyCount; } - - ComplexValue& operator=(const ComplexValue& other) - { -#ifndef QT_NO_EXCEPTIONS - if (other.m_mode == ThrowOnCopy) - throw new ComplexValueException(other.m_value, false); -#endif - m_value = other.m_value; - m_mode = Assign; - return *this; - } - - int value() const { return m_value; } - Mode mode() const { return m_mode; } - - bool operator==(const ComplexValue& other) const - { return m_value == other.m_value; } - bool operator==(int other) const - { return m_value == other; } - bool operator!=(const ComplexValue& other) const - { return m_value != other.m_value; } - bool operator!=(int other) const - { return m_value != other; } - -private: - int m_value; - Mode m_mode; -}; - -int ComplexValue::destroyCount = 0; - -void tst_QArray::create() -{ - QArray<float> array; - - // Check the basic properties. - QVERIFY(array.isEmpty()); - QCOMPARE(array.count(), 0); - QCOMPARE(array.size(), 0); - QCOMPARE(array.capacity(), ExpectedMinCapacity); - QVERIFY(array.constData() != 0); - QVERIFY(array.data() == array.constData()); - QVERIFY(((const QArray<float> *)&array)->data() == array.constData()); - - // The current constData() pointer should be pointing into - // the middle of "array" at the m_prealloc structure. - const float *d = array.constData(); - QVERIFY(d >= (const float *)&array); - QVERIFY(d < (const float *)((&array) + 1)); - - // Add one element and check the basic properties again. - array.append(1.0f); - QVERIFY(!array.isEmpty()); - QCOMPARE(array.count(), 1); - QCOMPARE(array.size(), 1); - QCOMPARE(array.capacity(), ExpectedMinCapacity); - QVERIFY(array.constData() != 0); - QVERIFY(array.data() == array.constData()); - QVERIFY(((const QArray<float> *)&array)->data() == array.constData()); - - // Create another array that is filled with an initial value. - QArray<QVector3D> array2(100, QVector3D(1.0f, 2.0f, 3.0f)); - QVERIFY(!array2.isEmpty()); - QCOMPARE(array2.count(), 100); - QCOMPARE(array2.size(), 100); - QVERIFY(array2.capacity() >= 100); - QVERIFY(array2.constData() != 0); - QVERIFY(array2.data() == array2.constData()); - QVERIFY(((const QArray<QVector3D> *)&array2)->data() == array2.constData()); - for (int index = 0; index < 100; ++index) - QVERIFY(array2.at(index) == QVector3D(1.0f, 2.0f, 3.0f)); - - // Create a filled array that is within the prealloc area. - QArray<float> array3(ExpectedMinCapacity, 42.5f); - QVERIFY(!array3.isEmpty()); - QCOMPARE(array3.count(), ExpectedMinCapacity); - QCOMPARE(array3.size(), ExpectedMinCapacity); - QVERIFY(array3.capacity() == ExpectedMinCapacity); - QVERIFY(array3.constData() != 0); - QVERIFY(array3.data() == array3.constData()); - for (int index = 0; index < ExpectedMinCapacity; ++index) - QVERIFY(array3.at(index) == 42.5f); - - // Create an array of strings. - QArray<QString> array4; - QCOMPARE(array4.size(), 0); - array4.append(QLatin1String("foo")); - array4.append(QLatin1String("bar")); - array4.append(array4[0]); - QCOMPARE(array4[0], QLatin1String("foo")); - QCOMPARE(array4[1], QLatin1String("bar")); - QCOMPARE(array4[2], QLatin1String("foo")); - - // Create an array of complex values and check that the - // copy constructors were called correctly. Also check that - // the destructors are called when the array is destroyed. - ComplexValue::destroyCount = 0; - { - QArray<ComplexValue> array5; - array5.append(ComplexValue(1)); - array5.append(ComplexValue(2)); - array5.append(ComplexValue(3)); - QCOMPARE(ComplexValue::destroyCount, 3); // Destruction of temporaries. - QCOMPARE(array5.size(), 3); - QVERIFY(array5[0].value() == 1); - QVERIFY(array5[0].mode() == ComplexValue::Copy); - QVERIFY(array5[1].value() == 2); - QVERIFY(array5[1].mode() == ComplexValue::Copy); - QVERIFY(array5[2].value() == 3); - QVERIFY(array5[2].mode() == ComplexValue::Copy); - } - QCOMPARE(ComplexValue::destroyCount, 6); -} - -void tst_QArray::append() -{ - QArray<float> array; - int index; - - // Appending up to the minimum capacity should not cause a realloc. - const float *d = array.constData(); - for (index = 0; index < ExpectedMinCapacity; ++index) { - array.append(float(index)); - QVERIFY(array.constData() == d); - } - - // Check that the array contains the values we expected. - QCOMPARE(array.count(), ExpectedMinCapacity); - QCOMPARE(array.capacity(), ExpectedMinCapacity); - for (index = 0; index < ExpectedMinCapacity; ++index) { - QCOMPARE(array[index], float(index)); - } - - // Append 1 more item and check for realloc. - array += float(1000.0f); - QCOMPARE(array.count(), ExpectedMinCapacity + 1); - QVERIFY(array.capacity() > ExpectedMinCapacity); - QVERIFY(array.capacity() >= array.count()); - QCOMPARE(array.size(), array.count()); - - // Check that the array still contains the values we expected. - for (index = 0; index < ExpectedMinCapacity; ++index) { - QCOMPARE(array[index], float(index)); - } - QCOMPARE(array[ExpectedMinCapacity], 1000.0f); - - // Append a large number of values to test constant reallocation. - for (index = 0; index < 1000; ++index) - array.append(float(index)); - QCOMPARE(array.count(), ExpectedMinCapacity + 1 + 1000); - QCOMPARE(array.size(), array.count()); - - // Make two copies of the array. - QVERIFY(array.isDetached()); - QArray<float> array2(array); - QVERIFY(!array.isDetached()); - QVERIFY(!array2.isDetached()); - QCOMPARE(array2.count(), ExpectedMinCapacity + 1 + 1000); - QCOMPARE(array2.size(), array2.count()); - QVERIFY(!array2.isEmpty()); - QVERIFY(array2.capacity() >= array2.size()); - QArray<float> array3; - array3 = array; - QCOMPARE(array3.count(), ExpectedMinCapacity + 1 + 1000); - QCOMPARE(array3.size(), array3.count()); - QVERIFY(!array3.isEmpty()); - QVERIFY(array3.capacity() >= array3.size()); - - // Check that we actually are sharing the data between the copies. - QVERIFY(array.constData() == array2.constData()); - QVERIFY(array.constData() == array3.constData()); - d = array2.constData(); - - // Add another item to the original and check that the copy is unchanged. - array << float(1500.0f); - QVERIFY(array.isDetached()); - QCOMPARE(array.count(), ExpectedMinCapacity + 1 + 1000 + 1); - QCOMPARE(array2.count(), ExpectedMinCapacity + 1 + 1000); - QCOMPARE(array3.count(), ExpectedMinCapacity + 1 + 1000); - - // Check that we have detached the first array (copy-on-write). - QVERIFY(array.constData() != array2.constData()); - QVERIFY(array.constData() != array3.constData()); - QVERIFY(array2.constData() == array3.constData()); - QVERIFY(array2.constData() == d); - - // Check that the original and the copy contain the right values. - for (index = 0; index < ExpectedMinCapacity; ++index) { - QCOMPARE(array.at(index), float(index)); - QCOMPARE(array2.at(index), float(index)); - QCOMPARE(array3.at(index), float(index)); - } - QCOMPARE(array.at(ExpectedMinCapacity), 1000.0f); - QCOMPARE(array2.at(ExpectedMinCapacity), 1000.0f); - QCOMPARE(array3.at(ExpectedMinCapacity), 1000.0f); - for (index = 0; index < 1000; ++index) { - QCOMPARE(array.at(index + ExpectedMinCapacity + 1), float(index)); - } - QCOMPARE(array[ExpectedMinCapacity + 1000 + 1], 1500.0f); - - // Check the detach conditions. - QVERIFY(!array2.isDetached()); - QVERIFY(!array3.isDetached()); - array3.append(1.0f); - QVERIFY(array3.isDetached()); - QVERIFY(!array2.isDetached()); // Still thinks it is shared. - array2.data(); - QVERIFY(array2.isDetached()); // Now knows that it isn't. - - // Create a large array of strings. - QArray<QString> array4; - for (index = 0; index < 1000; ++index) - array4.append(QString::number(index)); - QCOMPARE(array4.size(), 1000); - for (index = 0; index < 1000; ++index) - QVERIFY(array4[index] == QString::number(index)); - - // Make a copy of the array of strings and then force a detach. - QArray<QString> array5(array4); - QCOMPARE(array4.size(), 1000); - QCOMPARE(array5.size(), 1000); - for (index = 0; index < 1000; ++index) { - QVERIFY(array4[index] == QString::number(index)); - QVERIFY(array5[index] == QString::number(index)); - } - array5.append(QString::number(1000)); - QCOMPARE(array4.size(), 1000); - QCOMPARE(array5.size(), 1001); - for (index = 0; index < 1000; ++index) { - QVERIFY(array4[index] == QString::number(index)); - QVERIFY(array5[index] == QString::number(index)); - } - QVERIFY(array5[1000] == QString::number(1000)); - - // Create an array of complex values and force one realloc - // to test that copy constructors and destructors are called - // when moving data from the prealloc array to the heap. - QArray<ComplexValue> array6; - ComplexValue::destroyCount = 0; - for (index = 0; index < ExpectedMinCapacity; ++index) - array6.append(ComplexValue(index)); - QCOMPARE(ComplexValue::destroyCount, ExpectedMinCapacity); - ComplexValue::destroyCount = 0; - array6.append(ComplexValue(ExpectedMinCapacity)); - QCOMPARE(ComplexValue::destroyCount, ExpectedMinCapacity + 1); - for (index = 0; index < (ExpectedMinCapacity + 1); ++index) { - QCOMPARE(array6[index].value(), index); - // The last element should be Copy, but all others are CopiedAgain. - if (index == ExpectedMinCapacity) - QVERIFY(array6[index].mode() == ComplexValue::Copy); - else - QVERIFY(array6[index].mode() == ComplexValue::CopiedAgain); - } - - // Force another realloc to test heap to heap copies. - int capacity = array6.capacity(); - for (int index = array6.size(); index < capacity; ++index) - array6.append(ComplexValue(index)); - ComplexValue::destroyCount = 0; - array6.append(ComplexValue(capacity)); - QCOMPARE(ComplexValue::destroyCount, capacity + 1); - for (index = 0; index < (capacity + 1); ++index) { - QCOMPARE(array6[index].value(), index); - // The last element should be Copy, but all others are CopiedAgain. - if (index == capacity) - QVERIFY(array6[index].mode() == ComplexValue::Copy); - else - QVERIFY(array6[index].mode() == ComplexValue::CopiedAgain); - } - - // Make a copy of array6 and force a detach. - int size = array6.size(); - QArray<ComplexValue> array7(array6); - QCOMPARE(array6.size(), size); - QCOMPARE(array7.size(), size); - for (index = 0; index < size; ++index) { - QVERIFY(array6[index].value() == index); - QVERIFY(array7[index].value() == index); - } - array7.append(ComplexValue(size)); - QCOMPARE(array6.size(), size); - QCOMPARE(array7.size(), size + 1); - for (index = 0; index < size; ++index) { - QVERIFY(array6[index].value() == index); - QVERIFY(array7[index].value() == index); - } - QVERIFY(array7[size].value() == size); - - // Make another copy using operator=. - QArray<ComplexValue> array8; - QCOMPARE(array8.size(), 0); - array8 = array6; - QCOMPARE(array6.size(), size); - QCOMPARE(array8.size(), size); - for (index = 0; index < size; ++index) { - QVERIFY(array6[index].value() == index); - QVERIFY(array8[index].value() == index); - } - array8.append(ComplexValue(size)); - QCOMPARE(array6.size(), size); - QCOMPARE(array8.size(), size + 1); - for (index = 0; index < size; ++index) { - QVERIFY(array6[index].value() == index); - QVERIFY(array8[index].value() == index); - } - QVERIFY(array8[size].value() == size); - - // Copy the same object over itself. - QArray<ComplexValue> array9(array8); - QVERIFY(array9.constData() == array8.constData()); - for (index = 0; index < array8.size(); ++index) - QCOMPARE((*((const QArray<ComplexValue> *)&array9))[index], - array8.at(index)); - array9 = array8; - QVERIFY(array9.constData() == array8.constData()); - for (index = 0; index < array8.size(); ++index) - QCOMPARE(array9.at(index), array8.at(index)); -} - -void tst_QArray::appendTwoAtATime() -{ - int index; - - QArray<float> array; - array.append(1.0f, 2.0f); - array.append(3.0f, 4.0f); - QCOMPARE(array[0], 1.0f); - QCOMPARE(array[1], 2.0f); - QCOMPARE(array[2], 3.0f); - QCOMPARE(array[3], 4.0f); - QCOMPARE(array.count(), 4); - - QArray<float> array2; - for (index = 0; index < 1000; ++index) - array2.append(float(index), float(index + 1)); - QCOMPARE(array2.count(), 2000); - for (index = 0; index < 1000; ++index) { - QCOMPARE(array2[index * 2], float(index)); - QCOMPARE(array2[index * 2 + 1], float(index + 1)); - } - - QArray<QString> array3; - for (index = 0; index < 1000; ++index) - array3.append(QString::number(index), QString::number(index + 1)); - QCOMPARE(array3.count(), 2000); - for (index = 0; index < 1000; ++index) { - QCOMPARE(array3[index * 2], QString::number(index)); - QCOMPARE(array3[index * 2 + 1], QString::number(index + 1)); - } - - QArray<ComplexValue> array4; - for (index = 0; index < 1000; ++index) - array4.append(ComplexValue(index), ComplexValue(index + 1)); - QCOMPARE(array4.count(), 2000); - for (index = 0; index < 1000; ++index) { - QCOMPARE(array4[index * 2].value(), index); - QCOMPARE(array4[index * 2 + 1].value(), index + 1); - } -} - -void tst_QArray::appendThreeAtATime() -{ - int index; - - QArray<float> array; - array.append(1.0f, 2.0f, 3.0f); - array.append(4.0f, 5.0f, 6.0f); - QCOMPARE(array[0], 1.0f); - QCOMPARE(array[1], 2.0f); - QCOMPARE(array[2], 3.0f); - QCOMPARE(array[3], 4.0f); - QCOMPARE(array[4], 5.0f); - QCOMPARE(array[5], 6.0f); - QCOMPARE(array.count(), 6); - - QArray<float> array2; - for (index = 0; index < 1000; ++index) - array2.append(float(index), float(index + 1), float(index + 2)); - QCOMPARE(array2.count(), 3000); - for (index = 0; index < 1000; ++index) { - QCOMPARE(array2[index * 3], float(index)); - QCOMPARE(array2[index * 3 + 1], float(index + 1)); - QCOMPARE(array2[index * 3 + 2], float(index + 2)); - } - - QArray<QString> array3; - for (index = 0; index < 1000; ++index) - array3.append(QString::number(index), QString::number(index + 1), - QString::number(index + 2)); - QCOMPARE(array3.count(), 3000); - for (index = 0; index < 1000; ++index) { - QCOMPARE(array3[index * 3], QString::number(index)); - QCOMPARE(array3[index * 3 + 1], QString::number(index + 1)); - QCOMPARE(array3[index * 3 + 2], QString::number(index + 2)); - } - - QArray<ComplexValue> array4; - for (index = 0; index < 1000; ++index) - array4.append(ComplexValue(index), ComplexValue(index + 1), - ComplexValue(index + 2)); - QCOMPARE(array4.count(), 3000); - for (index = 0; index < 1000; ++index) { - QCOMPARE(array4[index * 3].value(), index); - QCOMPARE(array4[index * 3 + 1].value(), index + 1); - QCOMPARE(array4[index * 3 + 2].value(), index + 2); - } -} - -void tst_QArray::appendFourAtATime() -{ - int index; - - QArray<float> array; - array.append(1.0f, 2.0f, 3.0f, 4.0f); - array.append(5.0f, 6.0f, 7.0f, 8.0f); - QCOMPARE(array[0], 1.0f); - QCOMPARE(array[1], 2.0f); - QCOMPARE(array[2], 3.0f); - QCOMPARE(array[3], 4.0f); - QCOMPARE(array[4], 5.0f); - QCOMPARE(array[5], 6.0f); - QCOMPARE(array[6], 7.0f); - QCOMPARE(array[7], 8.0f); - QCOMPARE(array.count(), 8); - - QArray<float> array2; - for (index = 0; index < 1000; ++index) - array2.append(float(index), float(index + 1), float(index + 2), float(index + 3)); - QCOMPARE(array2.count(), 4000); - for (index = 0; index < 1000; ++index) { - QCOMPARE(array2[index * 4], float(index)); - QCOMPARE(array2[index * 4 + 1], float(index + 1)); - QCOMPARE(array2[index * 4 + 2], float(index + 2)); - QCOMPARE(array2[index * 4 + 3], float(index + 3)); - } - - QArray<QString> array3; - for (index = 0; index < 1000; ++index) - array3.append(QString::number(index), QString::number(index + 1), - QString::number(index + 2), QString::number(index + 3)); - QCOMPARE(array3.count(), 4000); - for (index = 0; index < 1000; ++index) { - QCOMPARE(array3[index * 4], QString::number(index)); - QCOMPARE(array3[index * 4 + 1], QString::number(index + 1)); - QCOMPARE(array3[index * 4 + 2], QString::number(index + 2)); - QCOMPARE(array3[index * 4 + 3], QString::number(index + 3)); - } - - QArray<ComplexValue> array4; - for (index = 0; index < 1000; ++index) - array4.append(ComplexValue(index), ComplexValue(index + 1), - ComplexValue(index + 2), ComplexValue(index + 3)); - QCOMPARE(array4.count(), 4000); - for (index = 0; index < 1000; ++index) { - QCOMPARE(array4[index * 4].value(), index); - QCOMPARE(array4[index * 4 + 1].value(), index + 1); - QCOMPARE(array4[index * 4 + 2].value(), index + 2); - QCOMPARE(array4[index * 4 + 3].value(), index + 3); - } -} - -void tst_QArray::appendArray() -{ - QArray<float> array; - QArray<float> array2; - int index; - - for (index = 0; index < 1000; ++index) { - array.append(index); - array2.append(1000 - index); - } - - array.append(array2); - QCOMPARE(array.count(), 2000); - for (index = 0; index < 1000; ++index) { - QCOMPARE(array[index], float(index)); - QCOMPARE(array[index + 1000], float(1000 - index)); - } - - array2 << array2; - QCOMPARE(array2.count(), 2000); - for (index = 0; index < 1000; ++index) { - QCOMPARE(array2[index], float(1000 - index)); - QCOMPARE(array2[index + 1000], float(1000 - index)); - } - - array2 += (QArray<float>()); - QCOMPARE(array2.count(), 2000); - - QArray<float> array3(array2.constData(), array2.size()); - QCOMPARE(array3.size(), array2.size()); - for (index = 0; index < array2.size(); ++index) - QCOMPARE(array3.at(index), array2.at(index)); -} - -void tst_QArray::setAt() -{ - int index; - - QArray<float> array; - array.append(1.0f); - QCOMPARE(array[0], 1.0f); - - array[0] = 6.0f; - QCOMPARE(array[0], 6.0f); - - QArray<float> array2; - for (index = 0; index < 1000; ++index) - array2.append(index); - for (index = 0; index < 1000; ++index) - array2[index] = index + 1000; - for (index = 0; index < 1000; ++index) - QCOMPARE(array2[index], float(index + 1000)); - for (index = 0; index < 1000; ++index) - array2.replace(index, float(-index)); - for (index = 0; index < 1000; ++index) - QCOMPARE(array2[index], float(-index)); -} - -void tst_QArray::value() -{ - QArray<float> array; - for (int index = 0; index < 1000; ++index) - array.append(float(index)); - - for (int index = 0; index < 1000; ++index) { - QCOMPARE(array.value(index), float(index)); - QCOMPARE(array.value(index, 10001.0f), float(index)); - } - - QCOMPARE(array.value(-1), 0.0f); - QCOMPARE(array.value(1000), 0.0f); - - QCOMPARE(array.value(-1, 10001.0f), 10001.0f); - QCOMPARE(array.value(1000, 10001.0f), 10001.0f); -} - -void tst_QArray::replace() -{ - QArray<float> array; - QArray<float> array2; - int index; - - for (index = 0; index < 1000; ++index) { - array.append(index); - array2.append(1000 - index); - } - - array.replace(500, array2.constData(), 500); - QCOMPARE(array.count(), 1000); - for (index = 0; index < 1000; ++index) { - if (index < 500) - QCOMPARE(array[index], float(index)); - else - QCOMPARE(array[index], float(1000 - (index - 500))); - } - - // Replace and extend the array from the middle. - array.replace(900, array2.constData(), 500); - QCOMPARE(array.count(), 1400); - for (index = 0; index < 1400; ++index) { - if (index < 500) - QCOMPARE(array[index], float(index)); - else if (index < 900) - QCOMPARE(array[index], float(1000 - (index - 500))); - else - QCOMPARE(array[index], float(1000 - (index - 900))); - } - - // Check the bail-out cases when index is negative or count zero. - array.replace(900, array2.constData(), 0); - array.replace(-1, array2.constData(), 900); - QCOMPARE(array.count(), 1400); - for (index = 0; index < 1400; ++index) { - if (index < 500) - QCOMPARE(array[index], float(index)); - else if (index < 900) - QCOMPARE(array[index], float(1000 - (index - 500))); - else - QCOMPARE(array[index], float(1000 - (index - 900))); - } - - // Replace beyond the end of the array. - static float const extras[] = {0.0f, 0.0f, 1.0f, 2.0f, 3.0f, 4.0f}; - array.replace(1402, extras + 2, 4); - QCOMPARE(array.count(), 1406); - for (index = 0; index < 1406; ++index) { - if (index < 500) - QCOMPARE(array[index], float(index)); - else if (index < 900) - QCOMPARE(array[index], float(1000 - (index - 500))); - else if (index < 1400) - QCOMPARE(array[index], float(1000 - (index - 900))); - else - QCOMPARE(array[index], extras[index - 1400]); - } - - QArray<ComplexValue> array3; - QArray<ComplexValue> array4; - for (index = 0; index < 1000; ++index) { - array3.append(ComplexValue(index)); - array4.append(ComplexValue(1000 - index)); - } - array3.replace(0, array4.constData(), array4.size()); - for (index = 0; index < 1000; ++index) - QVERIFY(array3[index] == array4[index]); -} - -// Exercise the various conditionals in operator=(). -void tst_QArray::copy() -{ - QArray<float> array, array2, array3; - - array2.append(1.0f); - array2.append(7.0f); - array = array2; - QCOMPARE(array.count(), 2); - QCOMPARE(array.at(0), float(1.0f)); - QCOMPARE(array.at(1), float(7.0f)); - - array = array3; - QCOMPARE(array.count(), 0); - - array2 = array2; - QCOMPARE(array2.count(), 2); - QCOMPARE(array2.at(0), float(1.0f)); - QCOMPARE(array2.at(1), float(7.0f)); - - QArray<float> array4(array2); - QCOMPARE(array2.count(), 2); - QCOMPARE(array2.at(0), float(1.0f)); - QCOMPARE(array2.at(1), float(7.0f)); - - QArray<float> array5, array6; - for (int index = 0; index < 32; ++index) - array5.append(2.0f); - QCOMPARE(array5.count(), 32); - array6.append(1.0f); - array5 = array6; - QCOMPARE(array5.count(), 1); - QCOMPARE(array5.at(0), float(1.0f)); - - array5.clear(); - QCOMPARE(array5.count(), 0); - QCOMPARE(array6.count(), 1); - QCOMPARE(array6.at(0), float(1.0f)); - array6.clear(); - QCOMPARE(array5.count(), 0); -} - -void tst_QArray::resize() -{ - QArray<int> array; - - array.resize(-1); - QCOMPARE(array.count(), 0); - - array.resize(ExpectedMinCapacity); - QCOMPARE(array.count(), ExpectedMinCapacity); - for (int index = 0; index < ExpectedMinCapacity; ++index) - QCOMPARE(array[index], 0); - array.append(1); - - array.resize(100); - QCOMPARE(array.count(), 100); - QVERIFY(array.capacity() >= 100); - int cap = array.capacity(); - for (int index = 0; index < 100; ++index){ - if (index != 8) - QCOMPARE(array[index], 0); - else - QCOMPARE(array[index], 1); - } - - array.resize(50); - QCOMPARE(array.count(), 50); - QVERIFY(array.capacity() == cap); // Shouldn't change the capacity. - for (int index = 0; index < 50; ++index){ - if (index != 8) - QCOMPARE(array[index], 0); - else - QCOMPARE(array[index], 1); - } - - array.resize(50); - QCOMPARE(array.count(), 50); - - QArray<int> array2(array); - array.resize(40); - QCOMPARE(array.count(), 40); - QCOMPARE(array2.count(), 50); - - array2.resize(20); - QCOMPARE(array2.count(), 20); - - for (int index = 0; index < 40; ++index){ - if (index != 8) - QCOMPARE(array[index], 0); - else - QCOMPARE(array[index], 1); - } - for (int index = 0; index < 20; ++index){ - if (index != 8) - QCOMPARE(array2[index], 0); - else - QCOMPARE(array2[index], 1); - } - - // Check that resizing to zero keeps the same memory storage. - const int *d = array.constData(); - array.resize(0); - QVERIFY(array.constData() == d); - QVERIFY(array.capacity() != ExpectedMinCapacity); - - // Calling clear will reclaim the storage. - array.clear(); - QVERIFY(array.constData() != d); - QVERIFY(array.capacity() == ExpectedMinCapacity); -} - -void tst_QArray::reserve() -{ - QArray<float> array; - array.reserve(1000); - QVERIFY(array.isEmpty()); - QVERIFY(array.capacity() >= 1000); - - // Append elements and check for reallocation. - const float *d = array.constData(); - for (int index = 0; index < 1000; ++index) { - array.append(float(index)); - QVERIFY(array.constData() == d); - } - - // Reserving less doesn't change the capacity, or the count. - array.reserve(50); - QVERIFY(array.capacity() >= 1000); - QCOMPARE(array.count(), 1000); -} - -void tst_QArray::squeeze() -{ - QArray<float> array; - array.reserve(100); - QVERIFY(array.isEmpty()); - QVERIFY(array.capacity() >= 100); - - for (int index = 0; index < 100; ++index) - array.append(float(index)); - - array.reserve(400); - QVERIFY(array.capacity() >= 400); - - array.squeeze(); - QCOMPARE(array.capacity(), 100); - QCOMPARE(array.count(), 100); - - // Test squeezing within the preallocated area. - QArray<float> array2; - array2.append(1.0f); - array2.append(2.0f); - array2.append(3.0f); - array2.squeeze(); - QCOMPARE(array2.capacity(), ExpectedMinCapacity); - QCOMPARE(array2.count(), 3); - - // Test copy-on-write during squeezing. - QArray<float> array3(array); - array3.squeeze(); - QCOMPARE(array3.count(), 100); - QCOMPARE(array.count(), 100); - - // Clear and check that the array reverts to preallocation. - array.resize(0); - array.squeeze(); - QCOMPARE(array.size(), 0); - QCOMPARE(array.capacity(), ExpectedMinCapacity); -} - -void tst_QArray::compare() -{ - QArray<float> array, array2, array3; - - QVERIFY(array == array2); - - array.append(1.0f); - array3.append(1.0f); - QArray<float> array4(array); - - QVERIFY(array == array); - QVERIFY(array != array2); - QVERIFY(array == array3); - QVERIFY(array == array4); - - array2.append(2.0f); - QVERIFY(array != array2); - - array2.append(1.0f); - QVERIFY(array != array2); - - for (int index = 0; index < 100; ++index) - array.append(index); - array2 = array; - QVERIFY(array2 == array); - QVERIFY(!(array2 != array)); -} - -void tst_QArray::remove() -{ - QArray<float> array; - - array.remove(0, 100); - QCOMPARE(array.count(), 0); - - for (int index = 0; index < 100; ++index) - array.append(float(index)); - - array.remove(100, 60); - QCOMPARE(array.count(), 100); - array.remove(-60, 60); - - array.remove(10, 20); - QCOMPARE(array.count(), 80); - for (int index = 0; index < 80; ++index) { - if (index < 10) - QCOMPARE(array[index], float(index)); - else - QCOMPARE(array[index], float(index + 20)); - } - - QArray<float> array2(array); - array2.remove(-10, 20); - array2.remove(60, 20); - QCOMPARE(array2.count(), 60); - for (int index = 0; index < 60; ++index) { - QCOMPARE(array2[index], float(index + 30)); - } - - array.remove(0, 10); - QCOMPARE(array.count(), 70); - for (int index = 0; index < 70; ++index) { - QCOMPARE(array[index], float(index + 30)); - } - - // Remove everything and check that it returns to preallocation. - array.remove(0, array.size()); - QCOMPARE(array.count(), 0); - QCOMPARE(array.capacity(), ExpectedMinCapacity); - - for (int index = 0; index < 100; ++index) - array.append(float(index)); - array.erase(array.end() - 1); - QCOMPARE(array.size(), 99); - array.erase(array.begin(), array.end()); - QCOMPARE(array.count(), 0); -} - -void tst_QArray::removeFirstLast() -{ - QArray<float> array; - - array.removeFirst(); - QVERIFY(array.isEmpty()); - array.removeLast(); - QVERIFY(array.isEmpty()); - - for (int index = 0; index < 100; ++index) - array.append(float(index)); - - array.removeFirst(); - QCOMPARE(array.size(), 99); - for (int index = 0; index < array.size(); ++index) - QCOMPARE(array[index], float(index + 1)); - - array.removeLast(); - QCOMPARE(array.size(), 98); - for (int index = 0; index < array.size(); ++index) - QCOMPARE(array[index], float(index + 1)); -} - -void tst_QArray::extend() -{ - QArray<float> array; - - float *ptr = array.extend(4); - ptr[0] = 1.0f; - ptr[1] = 2.0f; - ptr[2] = 3.0f; - ptr[3] = 4.0f; - QCOMPARE(array.size(), 4); - QCOMPARE(array[0], 1.0f); - QCOMPARE(array[1], 2.0f); - QCOMPARE(array[2], 3.0f); - QCOMPARE(array[3], 4.0f); - - array.append(5.0f); - ptr = array.extend(1); - ptr[0] = 6.0f; - QCOMPARE(array.size(), 6); - QCOMPARE(array[0], 1.0f); - QCOMPARE(array[1], 2.0f); - QCOMPARE(array[2], 3.0f); - QCOMPARE(array[3], 4.0f); - QCOMPARE(array[4], 5.0f); - QCOMPARE(array[5], 6.0f); - - QArray<float> array2(array); - - ptr = array.extend(1); - ptr[0] = 7.0f; - QCOMPARE(array.size(), 7); - QCOMPARE(array[0], 1.0f); - QCOMPARE(array[1], 2.0f); - QCOMPARE(array[2], 3.0f); - QCOMPARE(array[3], 4.0f); - QCOMPARE(array[4], 5.0f); - QCOMPARE(array[5], 6.0f); - QCOMPARE(array[6], 7.0f); - - QCOMPARE(array2.size(), 6); -} - -void tst_QArray::reverse() -{ - QArray<float> array0; - - // null case - array0.reverse(); - QCOMPARE(array0.size(), 0); - - // basic case - float *ptr = array0.extend(1); - ptr[0] = 1.0f; - array0.reverse(); - QCOMPARE(array0.size(), 1); - QCOMPARE(array0.at(0), 1.0f); - - // odd numbered size - QArray<float> array1; - ptr = array1.extend(5); - ptr[0] = 1.0f; - ptr[1] = 2.0f; - ptr[2] = 3.0f; - ptr[3] = 4.0f; - ptr[4] = 5.0f; - array1.reverse(); - QCOMPARE(array1.size(), 5); - QCOMPARE(array1.at(0), 5.0f); - QCOMPARE(array1.at(2), 3.0f); - QCOMPARE(array1.at(4), 1.0f); - - // even numbered size - QArray<float> array2; - ptr = array2.extend(6); - ptr[0] = 1.0f; - ptr[1] = 2.0f; - ptr[2] = 3.0f; - ptr[3] = 4.0f; - ptr[4] = 5.0f; - ptr[5] = 6.0f; - array2.reverse(); - QCOMPARE(array2.size(), 6); - QCOMPARE(array2.at(0), 6.0f); - QCOMPARE(array2.at(2), 4.0f); - QCOMPARE(array2.at(3), 3.0f); - QCOMPARE(array2.at(5), 1.0f); - - // complex type - QVERIFY(QTypeInfo<QString>::isComplex); - QArray<QString> array3(6, QLatin1String("test")); - array3[0] = QLatin1String("zero"); - array3[1] = QLatin1String("one"); - array3[2] = QLatin1String("two"); - array3[3] = QLatin1String("three"); - array3[4] = QLatin1String("four"); - array3[5] = QLatin1String("five"); - array3.reverse(); - QCOMPARE(array3.size(), 6); - QCOMPARE(array3.at(0), QLatin1String("five")); - QCOMPARE(array3.at(2), QLatin1String("three")); - QCOMPARE(array3.at(3), QLatin1String("two")); - QCOMPARE(array3.at(5), QLatin1String("zero")); -} - -void tst_QArray::reversed() -{ - QArray<float> array0; - - // null case - QArray<float> res0 = array0.reversed(); - QCOMPARE(res0.size(), 0); - - // basic case - float *ptr = array0.extend(1); - ptr[0] = 1.0f; - res0 = array0.reversed(); - QCOMPARE(res0.size(), 1); - QCOMPARE(res0.at(0), 1.0f); - - // odd numbered size - QArray<float> array1; - ptr = array1.extend(5); - ptr[0] = 1.0f; - ptr[1] = 2.0f; - ptr[2] = 3.0f; - ptr[3] = 4.0f; - ptr[4] = 5.0f; - QArray<float> res1 = array1.reversed(); - QCOMPARE(res1.size(), 5); - QCOMPARE(res1.at(0), 5.0f); - QCOMPARE(res1.at(2), 3.0f); - QCOMPARE(res1.at(4), 1.0f); - - // even numbered size - QArray<float> array2; - ptr = array2.extend(6); - ptr[0] = 1.0f; - ptr[1] = 2.0f; - ptr[2] = 3.0f; - ptr[3] = 4.0f; - ptr[4] = 5.0f; - ptr[5] = 6.0f; - QArray<float> res2 = array2.reversed(); - QCOMPARE(res2.size(), 6); - QCOMPARE(res2.at(0), 6.0f); - QCOMPARE(res2.at(2), 4.0f); - QCOMPARE(res2.at(3), 3.0f); - QCOMPARE(res2.at(5), 1.0f); - - // simple type with larger size - QArray<QVector3D> array4; - array4.extend(6); - QVector3D va(1.0f, 2.0f, 3.0f); - QVector3D vb(11.0f, 12.0f, 13.0f); - QVector3D vc(21.0f, 22.0f, 23.0f); - QVector3D vd(31.0f, 32.0f, 33.0f); - QVector3D ve(41.0f, 42.0f, 43.0f); - QVector3D vf(51.0f, 52.0f, 53.0f); - array4[0] = va; - array4[1] = vb; - array4[2] = vc; - array4[3] = vd; - array4[4] = ve; - array4[5] = vf; - QArray<QVector3D> res4 = array4.reversed(); - QCOMPARE(res4.size(), 6); - QCOMPARE(res4.at(0), vf); - QCOMPARE(res4.at(2), vd); - QCOMPARE(res4.at(3), vc); - QCOMPARE(res4.at(5), va); -} - -void tst_QArray::mid() -{ - QArray<float> array; - for (int index = 0; index < 1024; ++index) - array.append(float(index)); - - QArray<float> mid = array.mid(0); - QCOMPARE(mid.size(), array.size()); - QVERIFY(!mid.isEmpty()); - QVERIFY(mid.constData() == array.constData()); - for (int index = 0; index < 1024; ++index) { - QCOMPARE(mid.at(index), float(index)); - QCOMPARE(mid[index], float(index)); - } - - mid = array.mid(500, 20); - QCOMPARE(mid.size(), 20); - QVERIFY(!mid.isEmpty()); - for (int index = 0; index < 20; ++index) { - QCOMPARE(mid.at(index), float(index + 500)); - QCOMPARE(mid[index], float(index + 500)); - } - - QArray<float> mid2 = array.mid(500, 20); - QVERIFY(mid == mid2); - QVERIFY(!(mid != mid2)); - - QArray<float> mid3 = array.mid(500, 21); - QVERIFY(mid != mid3); - QVERIFY(!(mid == mid3)); - - QArray<float> mid4 = array.mid(400, 20); - QVERIFY(mid != mid4); - QVERIFY(!(mid == mid4)); - - QArray<float> mid5; - QArray<float> mid6; - QVERIFY(mid != mid5); - QVERIFY(!(mid == mid5)); - QVERIFY(mid5 != mid); - QVERIFY(!(mid5 == mid)); - QVERIFY(mid5 == mid6); - QVERIFY(!(mid5 != mid6)); - - mid = array.mid(500, 0); - QCOMPARE(mid.size(), 0); - QVERIFY(mid.isEmpty()); - - mid = array.mid(1000, 30); - QCOMPARE(mid.size(), 24); - QVERIFY(!mid.isEmpty()); - for (int index = 0; index < 24; ++index) { - QCOMPARE(mid.at(index), float(index + 1000)); - QCOMPARE(mid[index], float(index + 1000)); - } -} - -void tst_QArray::left() -{ - QArray<float> array; - for (int index = 0; index < 1024; ++index) - array.append(float(index)); - - QArray<float> left = array.left(-1); - QVERIFY(left == array); - - left = array.left(0); - QVERIFY(left.isEmpty()); - - left = array.left(500); - QCOMPARE(left.size(), 500); - QVERIFY(left == array.mid(0, 500)); - - left = array.left(2048); - QVERIFY(left == array); -} - -void tst_QArray::right() -{ - QArray<float> array; - for (int index = 0; index < 1024; ++index) - array.append(float(index)); - - QArray<float> right = array.right(-1); - QVERIFY(right == array); - - right = array.right(0); - QVERIFY(right.isEmpty()); - - right = array.right(500); - QCOMPARE(right.size(), 500); - QVERIFY(right == array.mid(1024 - 500, 500)); - - right = array.right(2048); - QVERIFY(right == array); -} - -void tst_QArray::iterate() -{ - QArray<float> array; - for (int index = 0; index < 1024; ++index) - array.append(float(index)); - - QArray<float>::Iterator it1; - int value = 0; - for (it1 = array.begin(); it1 != array.end(); ++it1) - QCOMPARE(*it1, float(value++)); - QCOMPARE(value, array.size()); - - QArray<float>::ConstIterator it2; - value = 0; - for (it2 = array.constBegin(); it2 != array.constEnd(); ++it2) - QCOMPARE(*it2, float(value++)); - QCOMPARE(value, array.size()); - - value = 0; - for (it1 = array.begin(); it1 != array.end(); ++it1) - *it1 = float(1024 - value++); - value = 0; - for (it2 = array.constBegin(); it2 != array.constEnd(); ++it2) { - QCOMPARE(*it2, float(1024 - value)); - QCOMPARE(array[value], float(1024 - value)); - ++value; - } - - for (int index = 0; index < 1024; ++index) - array[index] = float(index); -} - -// Verify that when the data is in the preallocated section, it is -// copied across and the original constData() pointer remains the same. -void tst_QArray::copyPrealloc() -{ - QArray<float> array1; - array1.append(1.0f); - array1.append(2.0f); - - const float *data = array1.constData(); - - QArray<float> array2(array1); - - QVERIFY(array1.constData() == data); - QVERIFY(array2.constData() != data); - - QCOMPARE(array2.size(), 2); - QCOMPARE(array2[0], float(1.0f)); - QCOMPARE(array2[1], float(2.0f)); - - QArray<float> array3; - QCOMPARE(array3.size(), 0); - array3 = array1; - - QVERIFY(array1.constData() == data); - QVERIFY(array3.constData() != data); - - QCOMPARE(array3.size(), 2); - QCOMPARE(array3[0], float(1.0f)); - QCOMPARE(array3[1], float(2.0f)); -} - -void tst_QArray::insert() -{ - QArray<float> array; - for (int index = 0; index < 10; ++index) - array.append(float(index)); - - array.prepend(-1.0f); - QCOMPARE(array.size(), 11); - for (int index = 0; index < array.size(); ++index) - QCOMPARE(array[index], float(index - 1)); - - array.insert(array.size(), 10.0f); - QCOMPARE(array.size(), 12); - for (int index = 0; index < array.size(); ++index) - QCOMPARE(array[index], float(index - 1)); - - array.insert(1, 0.5f); - QCOMPARE(array.size(), 13); - QCOMPARE(array[0], -1.0f); - QCOMPARE(array[1], 0.5f); - QCOMPARE(array[2], 0.0f); - QCOMPARE(array[12], 10.0f); - - array.insert(10, 0, 7.5f); - array.insert(10, 4, 7.5f); - QCOMPARE(array.size(), 17); - QCOMPARE(array[9], 7.0f); - QCOMPARE(array[10], 7.5f); - QCOMPARE(array[11], 7.5f); - QCOMPARE(array[12], 7.5f); - QCOMPARE(array[13], 7.5f); - QCOMPARE(array[14], 8.0f); - QCOMPARE(array[15], 9.0f); - QCOMPARE(array[16], 10.0f); - - // Repeat the tests with QString - QArray<QString> array2; - for (int index = 0; index < 10; ++index) - array2.append(QString::number(index)); - - array2.prepend(QString::number(-1)); - QCOMPARE(array2.size(), 11); - for (int index = 0; index < array2.size(); ++index) - QCOMPARE(array2[index], QString::number(index - 1)); - - array2.insert(array2.size(), QString::number(10)); - QCOMPARE(array2.size(), 12); - for (int index = 0; index < array2.size(); ++index) - QCOMPARE(array2[index], QString::number(index - 1)); - - array2.insert(1, QString::number(5)); - QCOMPARE(array2.size(), 13); - QCOMPARE(array2[0], QString::number(-1)); - QCOMPARE(array2[1], QString::number(5)); - QCOMPARE(array2[2], QString::number(0)); - QCOMPARE(array2[12], QString::number(10)); - - array2.insert(10, 4, QString::number(3)); - QCOMPARE(array2.size(), 17); - QCOMPARE(array2[9], QString::number(7)); - QCOMPARE(array2[10], QString::number(3)); - QCOMPARE(array2[11], QString::number(3)); - QCOMPARE(array2[12], QString::number(3)); - QCOMPARE(array2[13], QString::number(3)); - QCOMPARE(array2[14], QString::number(8)); - QCOMPARE(array2[15], QString::number(9)); - QCOMPARE(array2[16], QString::number(10)); - - // Repeat the tests with ComplexValue - QArray<ComplexValue> array3; - for (int index = 0; index < 10; ++index) - array3.append(ComplexValue(index)); - - array3.prepend(ComplexValue(-1)); - ComplexValue::destroyCount = 0; - QCOMPARE(array3.size(), 11); - for (int index = 0; index < array3.size(); ++index) { - QVERIFY(array3[index] == (index - 1)); - QVERIFY(array3[index].mode() == ComplexValue::Assign); - } - QCOMPARE(ComplexValue::destroyCount, 0); - - array3.insert(array3.size(), ComplexValue(10)); - QCOMPARE(array3.size(), 12); - for (int index = 0; index < array3.size(); ++index) - QVERIFY(array3[index] == (index - 1)); - - array3.insert(1, ComplexValue(5)); - QCOMPARE(array3.size(), 13); - QVERIFY(array3[0] == -1); - QVERIFY(array3[1] == 5); - QVERIFY(array3[2] == 0); - QVERIFY(array3[12] == 10); - - array3.insert(10, 4, ComplexValue(3)); - QCOMPARE(array3.size(), 17); - QVERIFY(array3[9] == 7); - QVERIFY(array3[10] == 3); - QVERIFY(array3[11] == 3); - QVERIFY(array3[12] == 3); - QVERIFY(array3[13] == 3); - QVERIFY(array3[14] == 8); - QVERIFY(array3[15] == 9); - QVERIFY(array3[16] == 10); -} - -void tst_QArray::fromRawData() -{ - QArray<float> array; - float contents[] = {1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, - 7.0f, 8.0f, 9.0f, 10.0f, 11.0f, 12.0f}; - - array = QArray<float>::fromRawData(contents, 0); - QCOMPARE(array.size(), 0); - QCOMPARE(array.capacity(), 0); - QVERIFY(!array.isDetached()); - array.append(1.0f); - QCOMPARE(array.size(), 1); - QVERIFY(array.capacity() > 0); - QCOMPARE(array.at(0), 1.0f); - QVERIFY(array.isDetached()); - - array = QArray<float>::fromRawData(contents, 6); - QCOMPARE(array.size(), 6); - QCOMPARE(array.capacity(), 6); - for (int index = 0; index < 6; ++index) - QCOMPARE(array.at(index), contents[index]); - QVERIFY(array.constData() == contents); - QVERIFY(!array.isDetached()); - - // Force a copy-on-write. - array[3] = 42.0f; - QVERIFY(array.isDetached()); - QCOMPARE(contents[3], 4.0f); - QCOMPARE(array.size(), 6); - QVERIFY(array.capacity() > 6); - for (int index = 0; index < 6; ++index) { - if (index != 3) - QCOMPARE(array.at(index), contents[index]); - else - QCOMPARE(array.at(index), 42.0f); - } - QVERIFY(array.constData() != contents); - - array = QArray<float>::fromRawData(contents, 12); - QCOMPARE(array.size(), 12); - QCOMPARE(array.capacity(), 12); - for (int index = 0; index < 12; ++index) - QCOMPARE(array.at(index), contents[index]); - QVERIFY(array.constData() == contents); - - QString strings[] = {QLatin1String("foo"), QLatin1String("bar")}; - QArray<QString> array2; - array2 = QArray<QString>::fromRawData(strings, 2); - QCOMPARE(array2.size(), 2); - QCOMPARE(array2.capacity(), 2); - QCOMPARE(array2.at(0), QLatin1String("foo")); - QCOMPARE(array2.at(1), QLatin1String("bar")); - QVERIFY(array2.constData() == strings); - - // Force a copy-on-write. - array2[1] = QLatin1String("baz"); - QCOMPARE(array2.size(), 2); - QVERIFY(array2.capacity() > 2); - QCOMPARE(array2.at(0), QLatin1String("foo")); - QCOMPARE(array2.at(1), QLatin1String("baz")); - QVERIFY(array2.constData() != strings); - QCOMPARE(strings[0], QLatin1String("foo")); - QCOMPARE(strings[1], QLatin1String("bar")); -} - -void tst_QArray::fromWritableRawData() -{ - QArray<float> array; - float contents[] = {1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f}; - float contentsModified[] = - {1.0f, 2.0f, 3.0f, 42.0f, 5.0f, 6.0f, 53.0f}; - - array = QArray<float>::fromWritableRawData(contents, 0); - QCOMPARE(array.size(), 0); - QCOMPARE(array.capacity(), 0); - array.append(0.0f); - QCOMPARE(array.size(), 1); - QVERIFY(array.capacity() > 0); - QCOMPARE(array.at(0), 0.0f); - - array = QArray<float>::fromWritableRawData(contents, 6); - QCOMPARE(array.size(), 6); - QCOMPARE(array.capacity(), 6); - for (int index = 0; index < 6; ++index) - QCOMPARE(array.at(index), contents[index]); - QVERIFY(array.constData() == contents); - - // Modify the raw data in-place. - array[3] = 42.0f; - QVERIFY(array.constData() == contents); - - // Force a copy. - array.append(53.0f); - QVERIFY(array.constData() != contents); - for (int index = 0; index < array.size(); ++index) - QCOMPARE(array.at(index), contentsModified[index]); - - // Resize to smaller should stay within the raw data. - array = QArray<float>::fromWritableRawData(contents, 6); - array.resize(6); - QCOMPARE(array.size(), 6); - array.resize(5); - QCOMPARE(array.size(), 5); - QVERIFY(array.constData() == contents); - for (int index = 0; index < array.size(); ++index) - QCOMPARE(array.at(index), contentsModified[index]); - array.append(6.0f); - QVERIFY(array.constData() == contents); - for (int index = 0; index < array.size(); ++index) - QCOMPARE(array.at(index), contentsModified[index]); - - // Resize to larger should force a copy. - array = QArray<float>::fromWritableRawData(contents, 6); - array.resize(7); - QVERIFY(array.constData() != contents); - for (int index = 0; index < 6; ++index) - QCOMPARE(array.at(index), contentsModified[index]); - QCOMPARE(array.at(6), 0.0f); - - // Reserve to a larger size should force a copy. - array = QArray<float>::fromWritableRawData(contents, 6); - array.reserve(7); - QCOMPARE(array.size(), 6); - QVERIFY(array.capacity() >= 7); - QVERIFY(array.constData() != contents); - for (int index = 0; index < 6; ++index) - QCOMPARE(array.at(index), contentsModified[index]); -} - -void tst_QArray::search() -{ - QArray<float> array; - for (int index = 0; index < 1000; ++index) - array.append(float(index)); - - QCOMPARE(array.indexOf(0.0f), 0); - QCOMPARE(array.indexOf(10.0f), 10); - QCOMPARE(array.indexOf(999.0f), 999); - QCOMPARE(array.indexOf(1000.0f), -1); - QCOMPARE(array.indexOf(10.0f, 9), 10); - QCOMPARE(array.indexOf(10.0f, 10), 10); - QCOMPARE(array.indexOf(10.0f, 11), -1); - QCOMPARE(array.indexOf(999.0f, -1), 999); - QCOMPARE(array.indexOf(998.0f, -1), -1); - QCOMPARE(array.indexOf(998.0f, -2), 998); - QCOMPARE(array.indexOf(998.0f, -3), 998); - QCOMPARE(array.indexOf(998.0f, -2000), 998); - QCOMPARE(array.indexOf(998.0f, 2000), -1); - - QCOMPARE(array.lastIndexOf(0.0f), 0); - QCOMPARE(array.lastIndexOf(10.0f), 10); - QCOMPARE(array.lastIndexOf(999.0f), 999); - QCOMPARE(array.lastIndexOf(1000.0f), -1); - QCOMPARE(array.lastIndexOf(10.0f, 9), -1); - QCOMPARE(array.lastIndexOf(10.0f, 10), 10); - QCOMPARE(array.lastIndexOf(10.0f, 11), 10); - QCOMPARE(array.lastIndexOf(999.0f, -1), 999); - QCOMPARE(array.lastIndexOf(998.0f, -1), 998); - QCOMPARE(array.lastIndexOf(998.0f, -2), 998); - QCOMPARE(array.lastIndexOf(998.0f, -3), -1); - QCOMPARE(array.lastIndexOf(998.0f, -2000), -1); - QCOMPARE(array.lastIndexOf(998.0f, 2000), 998); - - QVERIFY(array.contains(0.0f)); - QVERIFY(array.contains(10.0f)); - QVERIFY(array.contains(999.0f)); - QVERIFY(!array.contains(1000.0f)); - QVERIFY(!array.contains(-1.0f)); - - array.append(500.0f); - QCOMPARE(array.count(0.0f), 1); - QCOMPARE(array.count(10.0f), 1); - QCOMPARE(array.count(500.0f), 2); - QCOMPARE(array.count(999.0f), 1); - QCOMPARE(array.count(1000.0f), 0); - - QVERIFY(array.startsWith(0.0f)); - QVERIFY(!array.startsWith(1.0f)); - - QVERIFY(array.endsWith(500.0f)); - QVERIFY(!array.endsWith(1.0f)); - - QCOMPARE(array.first(), 0.0f); - QCOMPARE(array.last(), 500.0f); -} - -void tst_QArray::fill() -{ - QArray<float> array; - array.fill(1.0f); - QCOMPARE(array.size(), 0); - - array.fill(1.0f, 100); - QCOMPARE(array.size(), 100); - for (int index = 0; index < 100; ++index) - QCOMPARE(array.at(index), 1.0f); - - array.fill(2.0f); - QCOMPARE(array.size(), 100); - for (int index = 0; index < 100; ++index) - QCOMPARE(array.at(index), 2.0f); - - array.fill(3.0f, 20); - QCOMPARE(array.size(), 20); - for (int index = 0; index < 20; ++index) - QCOMPARE(array.at(index), 3.0f); -} - -void tst_QArray::zeroPrealloc() -{ - // Check that the zero-prealloc case actually uses less memory - // by optimizing away the m_prealloc structure. - QArray<float, 0> array; - QArray<float, 1> array2; - QVERIFY(sizeof(array) < sizeof(array2)); - - // Check that zero-prealloc arrays act properly by expanding the - // template on functions that involve preallocation operations. - QVERIFY(array.isEmpty()); - QCOMPARE(array.size(), 0); - QCOMPARE(array.capacity(), 0); - QVERIFY(!array.constData()); // Will be null for PreallocSize == 0. - array.append(1.0f); - QCOMPARE(array.size(), 1); - QCOMPARE(array[0], 1.0f); - QArray<float, 0> array3(array); - QVERIFY(array.constData() == array3.constData()); - - QArray<float, 0> array4(100, 3.0f); - QCOMPARE(array4.size(), 100); - for (int index = 0; index < 100; ++index) - QCOMPARE(array4[index], 3.0f); - array4.clear(); - QCOMPARE(array4.size(), 0); -} - -void tst_QArray::exceptions() -{ -#ifndef QT_NO_EXCEPTIONS - - // Check that an exception thrown during append() will leave - // the array in the pre-append state. - QArray<ComplexValue> array; - try { - array.append(ComplexValue(42, ComplexValue::ThrowOnCopy)); - QFAIL("should not be able to append - A"); - } catch (ComplexValueException *e) { - delete e; - QCOMPARE(array.size(), 0); - } - try { - array.append(ComplexValue(42, ComplexValue::ThrowOnCopy), ComplexValue(24)); - QFAIL("should not be able to append - B"); - } catch (ComplexValueException *e) { - delete e; - QCOMPARE(array.size(), 0); - } - try { - array.append(ComplexValue(24), ComplexValue(42, ComplexValue::ThrowOnCopy)); - QFAIL("should not be able to append - C"); - } catch (ComplexValueException *e) { - delete e; - QCOMPARE(array.size(), 1); - QCOMPARE(array.at(0).value(), 24); - } - array.clear(); - try { - array.append(ComplexValue(42, ComplexValue::ThrowOnCopy), - ComplexValue(24), - ComplexValue(16)); - QFAIL("should not be able to append - D"); - } catch (ComplexValueException *e) { - delete e; - QCOMPARE(array.size(), 0); - } - try { - array.append(ComplexValue(24), - ComplexValue(42, ComplexValue::ThrowOnCopy), - ComplexValue(16)); - QFAIL("should not be able to append - E"); - } catch (ComplexValueException *e) { - delete e; - QCOMPARE(array.size(), 1); - QCOMPARE(array.at(0).value(), 24); - } - array.clear(); - try { - array.append(ComplexValue(24), - ComplexValue(16), - ComplexValue(42, ComplexValue::ThrowOnCopy)); - QFAIL("should not be able to append - F"); - } catch (ComplexValueException *e) { - delete e; - QCOMPARE(array.size(), 2); - QCOMPARE(array.at(0).value(), 24); - QCOMPARE(array.at(1).value(), 16); - } - array.clear(); - try { - array.append(ComplexValue(42, ComplexValue::ThrowOnCopy), - ComplexValue(24), - ComplexValue(82), - ComplexValue(16)); - QFAIL("should not be able to append - G"); - } catch (ComplexValueException *e) { - delete e; - QCOMPARE(array.size(), 0); - } - try { - array.append(ComplexValue(24), - ComplexValue(42, ComplexValue::ThrowOnCopy), - ComplexValue(82), - ComplexValue(16)); - QFAIL("should not be able to append - H"); - } catch (ComplexValueException *e) { - delete e; - QCOMPARE(array.size(), 1); - QCOMPARE(array.at(0).value(), 24); - } - array.clear(); - try { - array.append(ComplexValue(24), - ComplexValue(16), - ComplexValue(42, ComplexValue::ThrowOnCopy), - ComplexValue(82)); - QFAIL("should not be able to append - I"); - } catch (ComplexValueException *e) { - delete e; - QCOMPARE(array.size(), 2); - QCOMPARE(array.at(0).value(), 24); - QCOMPARE(array.at(1).value(), 16); - } - array.clear(); - try { - array.append(ComplexValue(24), - ComplexValue(16), - ComplexValue(82), - ComplexValue(42, ComplexValue::ThrowOnCopy)); - QFAIL("should not be able to append - J"); - } catch (ComplexValueException *e) { - delete e; - QCOMPARE(array.size(), 3); - QCOMPARE(array.at(0).value(), 24); - QCOMPARE(array.at(1).value(), 16); - QCOMPARE(array.at(2).value(), 82); - } - array.clear(); - ComplexValue values[] = { - ComplexValue(1), - ComplexValue(2), - ComplexValue(3, ComplexValue::ThrowOnCopy) - }; - try { - array.append(values, 3); - QFAIL("should not be able to append - K"); - } catch (ComplexValueException *e) { - delete e; - QCOMPARE(array.size(), 2); - QCOMPARE(array.at(0).value(), 1); - QCOMPARE(array.at(1).value(), 2); - } - -#endif -} - -void tst_QArray::dataStream() -{ -#ifndef QT_NO_DATASTREAM - QArray<float> array; - for (int index = 0; index < 1024; ++index) - array.append(float(index)); - - QByteArray data; - { - QDataStream stream(&data, QIODevice::WriteOnly); - stream << array; - } - - QArray<float> array2; - { - QDataStream stream2(data); - stream2 >> array2; - } - - QVERIFY(array == array2); -#endif -} - -QTEST_APPLESS_MAIN(tst_QArray) - -#include "tst_qarray.moc" diff --git a/tests/auto/threed/qbox3d/qbox3d.pro b/tests/auto/threed/qbox3d/qbox3d.pro deleted file mode 100644 index f62181ec..00000000 --- a/tests/auto/threed/qbox3d/qbox3d.pro +++ /dev/null @@ -1,6 +0,0 @@ -load(qttest_p4.prf) -TEMPLATE=app -QT += testlib -CONFIG += unittest warn_on qt3d - -SOURCES += tst_qbox3d.cpp diff --git a/tests/auto/threed/qbox3d/tst_qbox3d.cpp b/tests/auto/threed/qbox3d/tst_qbox3d.cpp deleted file mode 100644 index 65c1cd44..00000000 --- a/tests/auto/threed/qbox3d/tst_qbox3d.cpp +++ /dev/null @@ -1,1302 +0,0 @@ -/**************************************************************************** -** -** 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 QtQuick3D module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** 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. -** -** 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. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include <QtTest/QtTest> -#include "qbox3d.h" -#include <QtGui/qmatrix4x4.h> - -class tst_QBox3D : public QObject -{ - Q_OBJECT -public: - tst_QBox3D() {} - ~tst_QBox3D() {} - -private slots: - void create(); - void modify(); - void compare(); - void fuzzyCompare(); - void size_data(); - void size(); - void center_data(); - void center(); - void containsPoint_data(); - void containsPoint(); - void containsBox_data(); - void containsBox(); - void intersects_data(); - void intersects(); - void intersect_data(); - void intersect(); - void intersected_data(); - void intersected(); - void intersectRay_data(); - void intersectRay(); - void unitePoint_data(); - void unitePoint(); - void uniteBox_data(); - void uniteBox(); - void unitedPoint_data(); - void unitedPoint(); - void unitedBox_data(); - void unitedBox(); - void transform(); - void transformed(); - void dataStream(); - void properties(); - void metaTypes(); -}; - -void tst_QBox3D::create() -{ - QBox3D box1; - QVERIFY(box1.isNull()); - QVERIFY(!box1.isFinite()); - QVERIFY(!box1.isInfinite()); - QVERIFY(box1.minimum() == QVector3D(0, 0, 0)); - QVERIFY(box1.maximum() == QVector3D(0, 0, 0)); - - QBox3D box2; - box2.setToInfinite(); - QVERIFY(!box2.isNull()); - QVERIFY(!box2.isFinite()); - QVERIFY(box2.isInfinite()); - QVERIFY(box2.minimum() == QVector3D(0, 0, 0)); - QVERIFY(box2.maximum() == QVector3D(0, 0, 0)); - - QBox3D box3(QVector3D(1, 2, 3), QVector3D(4, 5, 6)); - QVERIFY(!box3.isNull()); - QVERIFY(box3.isFinite()); - QVERIFY(!box3.isInfinite()); - QVERIFY(box3.minimum() == QVector3D(1, 2, 3)); - QVERIFY(box3.maximum() == QVector3D(4, 5, 6)); - - QBox3D box4(QVector3D(4, 5, 6), QVector3D(1, 2, 3)); - QVERIFY(!box4.isNull()); - QVERIFY(box4.isFinite()); - QVERIFY(!box4.isInfinite()); - QVERIFY(box4.minimum() == QVector3D(1, 2, 3)); - QVERIFY(box4.maximum() == QVector3D(4, 5, 6)); - - QBox3D box5(box4); - QVERIFY(!box5.isNull()); - QVERIFY(box5.isFinite()); - QVERIFY(!box5.isInfinite()); - QVERIFY(box5.minimum() == QVector3D(1, 2, 3)); - QVERIFY(box5.maximum() == QVector3D(4, 5, 6)); - - box5 = box2; - QVERIFY(!box5.isNull()); - QVERIFY(!box5.isFinite()); - QVERIFY(box5.isInfinite()); - QVERIFY(box5.minimum() == QVector3D(0, 0, 0)); - QVERIFY(box5.maximum() == QVector3D(0, 0, 0)); -} - -void tst_QBox3D::modify() -{ - // Use setExtents, which will swap minimum and maximum. - QBox3D box; - box.setExtents(QVector3D(-1, -2, -3), QVector3D(-5, -6, -7)); - QVERIFY(!box.isNull()); - QVERIFY(box.isFinite()); - QVERIFY(!box.isInfinite()); - QVERIFY(box.minimum() == QVector3D(-5, -6, -7)); - QVERIFY(box.maximum() == QVector3D(-1, -2, -3)); - - box.setExtents(QVector3D(1, 2, 3), QVector3D(4, 5, 6)); - QVERIFY(!box.isNull()); - QVERIFY(box.isFinite()); - QVERIFY(!box.isInfinite()); - QVERIFY(box.minimum() == QVector3D(1, 2, 3)); - QVERIFY(box.maximum() == QVector3D(4, 5, 6)); - - box.setToNull(); - QVERIFY(box.isNull()); - QVERIFY(!box.isFinite()); - QVERIFY(!box.isInfinite()); - QVERIFY(box.minimum() == QVector3D(0, 0, 0)); - QVERIFY(box.maximum() == QVector3D(0, 0, 0)); - - // Using setExtents will turn a null box into a finite box. - box.setExtents(QVector3D(-1, -2, -3), QVector3D(-5, -6, -7)); - QVERIFY(!box.isNull()); - QVERIFY(box.isFinite()); - QVERIFY(!box.isInfinite()); - QVERIFY(box.minimum() == QVector3D(-5, -6, -7)); - QVERIFY(box.maximum() == QVector3D(-1, -2, -3)); - - box.setToInfinite(); - QVERIFY(!box.isNull()); - QVERIFY(!box.isFinite()); - QVERIFY(box.isInfinite()); - QVERIFY(box.minimum() == QVector3D(0, 0, 0)); - QVERIFY(box.maximum() == QVector3D(0, 0, 0)); - - // Using setExtents will turn an infinite box into a finite box. - box.setExtents(QVector3D(-1, -2, -3), QVector3D(-5, -6, -7)); - QVERIFY(!box.isNull()); - QVERIFY(box.isFinite()); - QVERIFY(!box.isInfinite()); - QVERIFY(box.minimum() == QVector3D(-5, -6, -7)); - QVERIFY(box.maximum() == QVector3D(-1, -2, -3)); -} - -void tst_QBox3D::compare() -{ - QBox3D box1(QVector3D(-1, -2, -3), QVector3D(-5, -6, -7)); - QBox3D box2(QVector3D(-1, -2, -3), QVector3D(-5, -6, -7)); - QBox3D box3(QVector3D(0, -2, -3), QVector3D(-5, -6, -7)); - QBox3D null1, null2; - QBox3D infinite1, infinite2; - infinite1.setToInfinite(); - infinite2.setToInfinite(); - - QVERIFY(box1 == box2); - QVERIFY(box1 != box3); - QVERIFY(box1 != null1); - QVERIFY(box1 != infinite1); - - QVERIFY(null1 == null2); - QVERIFY(null1 != box1); - QVERIFY(null1 != infinite1); - - QVERIFY(infinite1 == infinite2); - QVERIFY(infinite1 != box1); - QVERIFY(infinite1 != null1); -} - -void tst_QBox3D::fuzzyCompare() -{ - QBox3D box1(QVector3D(-1, -2, -3), QVector3D(-5, -6, -7)); - QBox3D box2(QVector3D(-1, -2, -3), QVector3D(-5, -6, -7)); - QBox3D box3(QVector3D(0, -2, -3), QVector3D(-5, -6, -7)); - QBox3D null1, null2; - QBox3D infinite1, infinite2; - infinite1.setToInfinite(); - infinite2.setToInfinite(); - - QVERIFY(qFuzzyCompare(box1, box2)); - QVERIFY(!qFuzzyCompare(box1, box3)); - QVERIFY(!qFuzzyCompare(box1, null1)); - QVERIFY(!qFuzzyCompare(box1, infinite1)); - - QVERIFY(qFuzzyCompare(null1, null2)); - QVERIFY(!qFuzzyCompare(null1, box1)); - QVERIFY(!qFuzzyCompare(null1, infinite1)); - - QVERIFY(qFuzzyCompare(infinite1, infinite2)); - QVERIFY(!qFuzzyCompare(infinite1, box1)); - QVERIFY(!qFuzzyCompare(infinite1, null1)); -} - -void tst_QBox3D::size_data() -{ - QTest::addColumn<qreal>("x1"); - QTest::addColumn<qreal>("y1"); - QTest::addColumn<qreal>("z1"); - QTest::addColumn<qreal>("x2"); - QTest::addColumn<qreal>("y2"); - QTest::addColumn<qreal>("z2"); - - QTest::newRow("zero") - << (qreal)0.0 << (qreal)0.0 << (qreal)0.0 - << (qreal)0.0 << (qreal)0.0 << (qreal)0.0; - - QTest::newRow("one") - << (qreal)0.0 << (qreal)0.0 << (qreal)0.0 - << (qreal)1.0 << (qreal)1.0 << (qreal)1.0; - - QTest::newRow("empty") - << (qreal)1.0 << (qreal)1.0 << (qreal)1.0 - << (qreal)1.0 << (qreal)1.0 << (qreal)1.0; - - QTest::newRow("complex") - << (qreal)-1.0 << (qreal)-2.0 << (qreal)-3.0 - << (qreal)4.0 << (qreal)5.0 << (qreal)6.0; -} -void tst_QBox3D::size() -{ - QFETCH(qreal, x1); - QFETCH(qreal, y1); - QFETCH(qreal, z1); - QFETCH(qreal, x2); - QFETCH(qreal, y2); - QFETCH(qreal, z2); - - qreal sizex = (x1 < x2) ? (x2 - x1) : (x1 - x2); - qreal sizey = (y1 < y2) ? (y2 - y1) : (y1 - y2); - qreal sizez = (z1 < z2) ? (z2 - z1) : (z1 - z2); - - QBox3D box(QVector3D(x1, y1, z1), QVector3D(x2, y2, z2)); - QVERIFY(box.size() == QVector3D(sizex, sizey, sizez)); - - box.setToNull(); - QVERIFY(box.size() == QVector3D(0, 0, 0)); - - box.setToInfinite(); - QVERIFY(box.size() == QVector3D(0, 0, 0)); -} - -void tst_QBox3D::center_data() -{ - // Use the same test data as the size tests. - size_data(); -} -void tst_QBox3D::center() -{ - QFETCH(qreal, x1); - QFETCH(qreal, y1); - QFETCH(qreal, z1); - QFETCH(qreal, x2); - QFETCH(qreal, y2); - QFETCH(qreal, z2); - - qreal centerx = (x1 + x2) / 2; - qreal centery = (y1 + y2) / 2; - qreal centerz = (z1 + z2) / 2; - - QBox3D box(QVector3D(x1, y1, z1), QVector3D(x2, y2, z2)); - QVERIFY(box.center() == QVector3D(centerx, centery, centerz)); - - box.setToNull(); - QVERIFY(box.center() == QVector3D(0, 0, 0)); - - box.setToInfinite(); - QVERIFY(box.center() == QVector3D(0, 0, 0)); -} - -void tst_QBox3D::containsPoint_data() -{ - QTest::addColumn<qreal>("x"); - QTest::addColumn<qreal>("y"); - QTest::addColumn<qreal>("z"); - QTest::addColumn<bool>("contained"); - - QTest::newRow("zero") - << (qreal)0.0 << (qreal)0.0 << (qreal)0.0 << true; - - QTest::newRow("boundary1") - << (qreal)-1 << (qreal)-2 << (qreal)-3 << true; - QTest::newRow("boundary2") - << (qreal)-1 << (qreal)5 << (qreal)-3 << true; - QTest::newRow("boundary3") - << (qreal)-1 << (qreal)-2 << (qreal)6 << true; - QTest::newRow("boundary4") - << (qreal)-1 << (qreal)5 << (qreal)6 << true; - QTest::newRow("boundary5") - << (qreal)4 << (qreal)-2 << (qreal)-3 << true; - QTest::newRow("boundary6") - << (qreal)4 << (qreal)5 << (qreal)-3 << true; - QTest::newRow("boundary7") - << (qreal)4 << (qreal)-2 << (qreal)6 << true; - QTest::newRow("boundary8") - << (qreal)4 << (qreal)5 << (qreal)6 << true; - - QTest::newRow("outside1") - << (qreal)-2 << (qreal)-2 << (qreal)-3 << false; - QTest::newRow("outside2") - << (qreal)-1 << (qreal)6 << (qreal)-3 << false; - QTest::newRow("outside3") - << (qreal)-1 << (qreal)-2 << (qreal)7 << false; - QTest::newRow("outside4") - << (qreal)-1 << (qreal)-3 << (qreal)6 << false; - QTest::newRow("outside5") - << (qreal)5 << (qreal)-2 << (qreal)-3 << false; - QTest::newRow("outside6") - << (qreal)4 << (qreal)6 << (qreal)-3 << false; - QTest::newRow("outside7") - << (qreal)4 << (qreal)-2 << (qreal)7 << false; - QTest::newRow("outside8") - << (qreal)4 << (qreal)-3 << (qreal)6 << false; -} -void tst_QBox3D::containsPoint() -{ - QFETCH(qreal, x); - QFETCH(qreal, y); - QFETCH(qreal, z); - QFETCH(bool, contained); - - QBox3D box(QVector3D(-1, -2, -3), QVector3D(4, 5, 6)); - - if (contained) - QVERIFY(box.contains(QVector3D(x, y, z))); - else - QVERIFY(!box.contains(QVector3D(x, y, z))); - - QBox3D null; - QVERIFY(!null.contains(QVector3D(x, y, z))); - - QBox3D infinite; - infinite.setToInfinite(); - QVERIFY(infinite.contains(QVector3D(x, y, z))); -} - -void tst_QBox3D::containsBox_data() -{ - QTest::addColumn<qreal>("x1"); - QTest::addColumn<qreal>("y1"); - QTest::addColumn<qreal>("z1"); - QTest::addColumn<qreal>("x2"); - QTest::addColumn<qreal>("y2"); - QTest::addColumn<qreal>("z2"); - QTest::addColumn<bool>("contained"); - QTest::addColumn<bool>("intersects"); - QTest::addColumn<qreal>("ix1"); // Intersection box - QTest::addColumn<qreal>("iy1"); - QTest::addColumn<qreal>("iz1"); - QTest::addColumn<qreal>("ix2"); - QTest::addColumn<qreal>("iy2"); - QTest::addColumn<qreal>("iz2"); - QTest::addColumn<qreal>("ex1"); // Expanded box - QTest::addColumn<qreal>("ey1"); - QTest::addColumn<qreal>("ez1"); - QTest::addColumn<qreal>("ex2"); - QTest::addColumn<qreal>("ey2"); - QTest::addColumn<qreal>("ez2"); - - QTest::newRow("zero") - << (qreal)0.0 << (qreal)0.0 << (qreal)0.0 - << (qreal)0.0 << (qreal)0.0 << (qreal)0.0 - << true << true - << (qreal)0.0 << (qreal)0.0 << (qreal)0.0 - << (qreal)0.0 << (qreal)0.0 << (qreal)0.0 - << (qreal)-1.0 << (qreal)-2.0 << (qreal)-3.0 - << (qreal)1.0 << (qreal)2.0 << (qreal)3.0; - - QTest::newRow("side1") - << (qreal)-1.0 << (qreal)-2.0 << (qreal)-3.0 - << (qreal)1.0 << (qreal)-2.0 << (qreal)3.0 - << true << true - << (qreal)-1.0 << (qreal)-2.0 << (qreal)-3.0 - << (qreal)1.0 << (qreal)-2.0 << (qreal)3.0 - << (qreal)-1.0 << (qreal)-2.0 << (qreal)-3.0 - << (qreal)1.0 << (qreal)2.0 << (qreal)3.0; - QTest::newRow("side2") - << (qreal)-1.0 << (qreal)-2.0 << (qreal)-3.0 - << (qreal)1.0 << (qreal)2.0 << (qreal)-3.0 - << true << true - << (qreal)-1.0 << (qreal)-2.0 << (qreal)-3.0 - << (qreal)1.0 << (qreal)2.0 << (qreal)-3.0 - << (qreal)-1.0 << (qreal)-2.0 << (qreal)-3.0 - << (qreal)1.0 << (qreal)2.0 << (qreal)3.0; - QTest::newRow("side3") - << (qreal)-1.0 << (qreal)-2.0 << (qreal)-3.0 - << (qreal)-1.0 << (qreal)2.0 << (qreal)3.0 - << true << true - << (qreal)-1.0 << (qreal)-2.0 << (qreal)-3.0 - << (qreal)-1.0 << (qreal)2.0 << (qreal)3.0 - << (qreal)-1.0 << (qreal)-2.0 << (qreal)-3.0 - << (qreal)1.0 << (qreal)2.0 << (qreal)3.0; - QTest::newRow("side4") - << (qreal)-1.0 << (qreal)2.0 << (qreal)-3.0 - << (qreal)1.0 << (qreal)2.0 << (qreal)3.0 - << true << true - << (qreal)-1.0 << (qreal)2.0 << (qreal)-3.0 - << (qreal)1.0 << (qreal)2.0 << (qreal)3.0 - << (qreal)-1.0 << (qreal)-2.0 << (qreal)-3.0 - << (qreal)1.0 << (qreal)2.0 << (qreal)3.0; - QTest::newRow("side5") - << (qreal)1.0 << (qreal)-2.0 << (qreal)-3.0 - << (qreal)1.0 << (qreal)2.0 << (qreal)3.0 - << true << true - << (qreal)1.0 << (qreal)-2.0 << (qreal)-3.0 - << (qreal)1.0 << (qreal)2.0 << (qreal)3.0 - << (qreal)-1.0 << (qreal)-2.0 << (qreal)-3.0 - << (qreal)1.0 << (qreal)2.0 << (qreal)3.0; - QTest::newRow("side6") - << (qreal)-1.0 << (qreal)-2.0 << (qreal)3.0 - << (qreal)1.0 << (qreal)2.0 << (qreal)3.0 - << true << true - << (qreal)-1.0 << (qreal)-2.0 << (qreal)3.0 - << (qreal)1.0 << (qreal)2.0 << (qreal)3.0 - << (qreal)-1.0 << (qreal)-2.0 << (qreal)-3.0 - << (qreal)1.0 << (qreal)2.0 << (qreal)3.0; - - QTest::newRow("outside1") - << (qreal)-1.0 << (qreal)-2.5 << (qreal)-3.0 - << (qreal)1.0 << (qreal)-2.5 << (qreal)3.0 - << false << false - << (qreal)0.0 << (qreal)0.0 << (qreal)0.0 - << (qreal)0.0 << (qreal)0.0 << (qreal)0.0 - << (qreal)-1.0 << (qreal)-2.5 << (qreal)-3.0 - << (qreal)1.0 << (qreal)2.0 << (qreal)3.0; - QTest::newRow("outside2") - << (qreal)-1.0 << (qreal)-2.0 << (qreal)-3.5 - << (qreal)1.0 << (qreal)2.0 << (qreal)-3.5 - << false << false - << (qreal)0.0 << (qreal)0.0 << (qreal)0.0 - << (qreal)0.0 << (qreal)0.0 << (qreal)0.0 - << (qreal)-1.0 << (qreal)-2.0 << (qreal)-3.5 - << (qreal)1.0 << (qreal)2.0 << (qreal)3.0; - QTest::newRow("outside3") - << (qreal)-1.5 << (qreal)-2.0 << (qreal)-3.0 - << (qreal)-1.5 << (qreal)2.0 << (qreal)3.0 - << false << false - << (qreal)0.0 << (qreal)0.0 << (qreal)0.0 - << (qreal)0.0 << (qreal)0.0 << (qreal)0.0 - << (qreal)-1.5 << (qreal)-2.0 << (qreal)-3.0 - << (qreal)1.0 << (qreal)2.0 << (qreal)3.0; - QTest::newRow("outside4") - << (qreal)-1.0 << (qreal)2.5 << (qreal)-3.0 - << (qreal)1.0 << (qreal)2.5 << (qreal)3.0 - << false << false - << (qreal)0.0 << (qreal)0.0 << (qreal)0.0 - << (qreal)0.0 << (qreal)0.0 << (qreal)0.0 - << (qreal)-1.0 << (qreal)-2.0 << (qreal)-3.0 - << (qreal)1.0 << (qreal)2.5 << (qreal)3.0; - QTest::newRow("outside5") - << (qreal)1.5 << (qreal)-2.0 << (qreal)-3.0 - << (qreal)1.5 << (qreal)2.0 << (qreal)3.0 - << false << false - << (qreal)0.0 << (qreal)0.0 << (qreal)0.0 - << (qreal)0.0 << (qreal)0.0 << (qreal)0.0 - << (qreal)-1.0 << (qreal)-2.0 << (qreal)-3.0 - << (qreal)1.5 << (qreal)2.0 << (qreal)3.0; - QTest::newRow("outside6") - << (qreal)-1.0 << (qreal)-2.0 << (qreal)3.5 - << (qreal)1.0 << (qreal)2.0 << (qreal)3.5 - << false << false - << (qreal)0.0 << (qreal)0.0 << (qreal)0.0 - << (qreal)0.0 << (qreal)0.0 << (qreal)0.0 - << (qreal)-1.0 << (qreal)-2.0 << (qreal)-3.0 - << (qreal)1.0 << (qreal)2.0 << (qreal)3.5; - - QTest::newRow("overlap1") - << (qreal)-1.0 << (qreal)-2.5 << (qreal)-3.0 - << (qreal)1.0 << (qreal)-1.5 << (qreal)3.0 - << false << true - << (qreal)-1.0 << (qreal)-2.0 << (qreal)-3.0 - << (qreal)1.0 << (qreal)-1.5 << (qreal)3.0 - << (qreal)-1.0 << (qreal)-2.5 << (qreal)-3.0 - << (qreal)1.0 << (qreal)2.0 << (qreal)3.0; - QTest::newRow("overlap2") - << (qreal)-1.0 << (qreal)-2.0 << (qreal)-3.5 - << (qreal)1.0 << (qreal)2.0 << (qreal)-2.5 - << false << true - << (qreal)-1.0 << (qreal)-2.0 << (qreal)-3.0 - << (qreal)1.0 << (qreal)2.0 << (qreal)-2.5 - << (qreal)-1.0 << (qreal)-2.0 << (qreal)-3.5 - << (qreal)1.0 << (qreal)2.0 << (qreal)3.0; - QTest::newRow("overlap3") - << (qreal)-1.5 << (qreal)-2.0 << (qreal)-3.0 - << (qreal)-0.5 << (qreal)2.0 << (qreal)3.0 - << false << true - << (qreal)-1.0 << (qreal)-2.0 << (qreal)-3.0 - << (qreal)-0.5 << (qreal)2.0 << (qreal)3.0 - << (qreal)-1.5 << (qreal)-2.0 << (qreal)-3.0 - << (qreal)1.0 << (qreal)2.0 << (qreal)3.0; - QTest::newRow("overlap4") - << (qreal)-1.0 << (qreal)2.5 << (qreal)-3.0 - << (qreal)1.0 << (qreal)1.5 << (qreal)3.0 - << false << true - << (qreal)-1.0 << (qreal)2.0 << (qreal)-3.0 - << (qreal)1.0 << (qreal)1.5 << (qreal)3.0 - << (qreal)-1.0 << (qreal)-2.0 << (qreal)-3.0 - << (qreal)1.0 << (qreal)2.5 << (qreal)3.0; - QTest::newRow("overlap5") - << (qreal)1.5 << (qreal)-2.0 << (qreal)-3.0 - << (qreal)0.5 << (qreal)2.0 << (qreal)3.0 - << false << true - << (qreal)1.0 << (qreal)-2.0 << (qreal)-3.0 - << (qreal)0.5 << (qreal)2.0 << (qreal)3.0 - << (qreal)-1.0 << (qreal)-2.0 << (qreal)-3.0 - << (qreal)1.5 << (qreal)2.0 << (qreal)3.0; - QTest::newRow("overlap6") - << (qreal)-1.0 << (qreal)-2.0 << (qreal)3.5 - << (qreal)1.0 << (qreal)2.0 << (qreal)2.5 - << false << true - << (qreal)-1.0 << (qreal)-2.0 << (qreal)3.0 - << (qreal)1.0 << (qreal)2.0 << (qreal)2.5 - << (qreal)-1.0 << (qreal)-2.0 << (qreal)-3.0 - << (qreal)1.0 << (qreal)2.0 << (qreal)3.5; - - QTest::newRow("surround") - << (qreal)-2.0 << (qreal)-3.0 << (qreal)-4.0 - << (qreal)2.0 << (qreal)3.0 << (qreal)4.0 - << false << true - << (qreal)-1.0 << (qreal)-2.0 << (qreal)-3.0 - << (qreal)1.0 << (qreal)2.0 << (qreal)3.0 - << (qreal)-2.0 << (qreal)-3.0 << (qreal)-4.0 - << (qreal)2.0 << (qreal)3.0 << (qreal)4.0; -} -void tst_QBox3D::containsBox() -{ - QFETCH(qreal, x1); - QFETCH(qreal, y1); - QFETCH(qreal, z1); - QFETCH(qreal, x2); - QFETCH(qreal, y2); - QFETCH(qreal, z2); - QFETCH(bool, contained); - - QBox3D box(QVector3D(-1, -2, -3), QVector3D(1, 2, 3)); - QBox3D other(QVector3D(x1, y1, z1), QVector3D(x2, y2, z2)); - - if (contained) - QVERIFY(box.contains(other)); - else - QVERIFY(!box.contains(other)); - - QBox3D null; - QVERIFY(!null.contains(other)); - - QBox3D infinite; - infinite.setToInfinite(); - QVERIFY(infinite.contains(other)); - - QVERIFY(!box.contains(null)); - QVERIFY(!box.contains(infinite)); -} - -void tst_QBox3D::intersects_data() -{ - // Use the same test data as containsBox(). - containsBox_data(); -} -void tst_QBox3D::intersects() -{ - QFETCH(qreal, x1); - QFETCH(qreal, y1); - QFETCH(qreal, z1); - QFETCH(qreal, x2); - QFETCH(qreal, y2); - QFETCH(qreal, z2); - QFETCH(bool, contained); - QFETCH(bool, intersects); - - Q_UNUSED(contained); - - QBox3D box(QVector3D(-1, -2, -3), QVector3D(1, 2, 3)); - QBox3D other(QVector3D(x1, y1, z1), QVector3D(x2, y2, z2)); - - if (intersects) - QVERIFY(box.intersects(other)); - else - QVERIFY(!box.intersects(other)); - - QBox3D null; - QVERIFY(!null.intersects(other)); - - QBox3D infinite; - infinite.setToInfinite(); - QVERIFY(infinite.intersects(other)); - - QVERIFY(!box.intersects(null)); - QVERIFY(box.intersects(infinite)); -} - -void tst_QBox3D::intersect_data() -{ - // Use the same test data as containsBox(). - containsBox_data(); -} -void tst_QBox3D::intersect() -{ - QFETCH(qreal, x1); - QFETCH(qreal, y1); - QFETCH(qreal, z1); - QFETCH(qreal, x2); - QFETCH(qreal, y2); - QFETCH(qreal, z2); - QFETCH(bool, contained); - QFETCH(bool, intersects); - QFETCH(qreal, ix1); - QFETCH(qreal, iy1); - QFETCH(qreal, iz1); - QFETCH(qreal, ix2); - QFETCH(qreal, iy2); - QFETCH(qreal, iz2); - - Q_UNUSED(contained); - - QBox3D box(QVector3D(-1, -2, -3), QVector3D(1, 2, 3)); - QBox3D other(QVector3D(x1, y1, z1), QVector3D(x2, y2, z2)); - QBox3D result(QVector3D(ix1, iy1, iz1), QVector3D(ix2, iy2, iz2)); - - QBox3D ibox(box); - ibox.intersect(other); - if (intersects) - QVERIFY(ibox == result); - else - QVERIFY(ibox.isNull()); - - QBox3D null; - null.intersect(other); - QVERIFY(null.isNull()); - - QBox3D infinite; - infinite.setToInfinite(); - infinite.intersect(other); - QVERIFY(infinite == other); - - QBox3D ibox2(box); - QBox3D null2; - ibox2.intersect(null2); - QVERIFY(ibox2.isNull()); - - QBox3D ibox3(box); - QBox3D infinite2; - infinite2.setToInfinite(); - ibox3.intersect(infinite2); - QVERIFY(ibox3 == box); -} - -void tst_QBox3D::intersected_data() -{ - // Use the same test data as containsBox(). - containsBox_data(); -} -void tst_QBox3D::intersected() -{ - QFETCH(qreal, x1); - QFETCH(qreal, y1); - QFETCH(qreal, z1); - QFETCH(qreal, x2); - QFETCH(qreal, y2); - QFETCH(qreal, z2); - QFETCH(bool, contained); - QFETCH(bool, intersects); - QFETCH(qreal, ix1); - QFETCH(qreal, iy1); - QFETCH(qreal, iz1); - QFETCH(qreal, ix2); - QFETCH(qreal, iy2); - QFETCH(qreal, iz2); - - Q_UNUSED(contained); - - QBox3D box(QVector3D(-1, -2, -3), QVector3D(1, 2, 3)); - QBox3D other(QVector3D(x1, y1, z1), QVector3D(x2, y2, z2)); - QBox3D result(QVector3D(ix1, iy1, iz1), QVector3D(ix2, iy2, iz2)); - - QBox3D ibox = box.intersected(other); - if (intersects) - QVERIFY(ibox == result); - else - QVERIFY(ibox.isNull()); - - QBox3D null; - ibox = null.intersected(other); - QVERIFY(ibox.isNull()); - - QBox3D infinite; - infinite.setToInfinite(); - ibox = infinite.intersected(other); - QVERIFY(ibox == other); - - QVERIFY(box.intersected(null).isNull()); - QVERIFY(box.intersected(infinite) == box); -} - -void tst_QBox3D::intersectRay_data() -{ - QTest::addColumn<qreal>("x1"); - QTest::addColumn<qreal>("y1"); - QTest::addColumn<qreal>("z1"); - QTest::addColumn<qreal>("x2"); - QTest::addColumn<qreal>("y2"); - QTest::addColumn<qreal>("z2"); - QTest::addColumn<bool>("intersects"); - QTest::addColumn<qreal>("mint"); - QTest::addColumn<qreal>("maxt"); - QTest::addColumn<qreal>("originx"); - QTest::addColumn<qreal>("originy"); - QTest::addColumn<qreal>("originz"); - QTest::addColumn<qreal>("directionx"); - QTest::addColumn<qreal>("directiony"); - QTest::addColumn<qreal>("directionz"); - - QTest::newRow("zero") - << qreal(0.0) << qreal(0.0) << qreal(0.0) - << qreal(0.0) << qreal(0.0) << qreal(0.0) - << false << qreal(0.0) << qreal(0.0) - << qreal(0.0) << qreal(0.0) << qreal(0.0) - << qreal(0.0) << qreal(0.0) << qreal(0.0); - - QTest::newRow("zero-x") - << qreal(0.0) << qreal(0.0) << qreal(0.0) - << qreal(0.0) << qreal(0.0) << qreal(0.0) - << true << qreal(1.0) << qreal(1.0) - << qreal(-1.0) << qreal(0.0) << qreal(0.0) - << qreal(1.0) << qreal(0.0) << qreal(0.0); - - QTest::newRow("zero-neg-x") - << qreal(0.0) << qreal(0.0) << qreal(0.0) - << qreal(0.0) << qreal(0.0) << qreal(0.0) - << true << qreal(-1.0) << qreal(-1.0) - << qreal(-1.0) << qreal(0.0) << qreal(0.0) - << qreal(-1.0) << qreal(0.0) << qreal(0.0); - - QTest::newRow("zero-x-miss") - << qreal(0.0) << qreal(0.0) << qreal(0.0) - << qreal(0.0) << qreal(0.0) << qreal(0.0) - << false << qreal(0.0) << qreal(0.0) - << qreal(0.0) << qreal(1.0) << qreal(0.0) - << qreal(1.0) << qreal(0.0) << qreal(0.0); - - QTest::newRow("zero-y") - << qreal(0.0) << qreal(0.0) << qreal(0.0) - << qreal(0.0) << qreal(0.0) << qreal(0.0) - << true << qreal(1.0) << qreal(1.0) - << qreal(0.0) << qreal(-1.0) << qreal(0.0) - << qreal(0.0) << qreal(1.0) << qreal(0.0); - - QTest::newRow("zero-neg-y") - << qreal(0.0) << qreal(0.0) << qreal(0.0) - << qreal(0.0) << qreal(0.0) << qreal(0.0) - << true << qreal(-1.0) << qreal(-1.0) - << qreal(0.0) << qreal(-1.0) << qreal(0.0) - << qreal(0.0) << qreal(-1.0) << qreal(0.0); - - QTest::newRow("zero-y-miss") - << qreal(0.0) << qreal(0.0) << qreal(0.0) - << qreal(0.0) << qreal(0.0) << qreal(0.0) - << false << qreal(0.0) << qreal(0.0) - << qreal(1.0) << qreal(0.0) << qreal(0.0) - << qreal(0.0) << qreal(-1.0) << qreal(0.0); - - QTest::newRow("zero-z") - << qreal(0.0) << qreal(0.0) << qreal(0.0) - << qreal(0.0) << qreal(0.0) << qreal(0.0) - << true << qreal(1.0) << qreal(1.0) - << qreal(0.0) << qreal(0.0) << qreal(1.0) - << qreal(0.0) << qreal(0.0) << qreal(-1.0); - - QTest::newRow("zero-neg-z") - << qreal(0.0) << qreal(0.0) << qreal(0.0) - << qreal(0.0) << qreal(0.0) << qreal(0.0) - << true << qreal(-1.0) << qreal(-1.0) - << qreal(0.0) << qreal(0.0) << qreal(1.0) - << qreal(0.0) << qreal(0.0) << qreal(1.0); - - QTest::newRow("zero-z-miss") - << qreal(0.0) << qreal(0.0) << qreal(0.0) - << qreal(0.0) << qreal(0.0) << qreal(0.0) - << false << qreal(0.0) << qreal(0.0) - << qreal(0.0) << qreal(1.0) << qreal(0.0) - << qreal(0.0) << qreal(0.0) << qreal(1.0); - - QTest::newRow("normal-no-ray") - << qreal(-1.0) << qreal(-2.0) << qreal(-3.0) - << qreal(1.0) << qreal(2.0) << qreal(3.0) - << false << qreal(0.0) << qreal(0.0) - << qreal(0.0) << qreal(0.0) << qreal(0.0) - << qreal(0.0) << qreal(0.0) << qreal(0.0); - - QTest::newRow("normal-from-inside-x") - << qreal(-1.0) << qreal(-2.0) << qreal(-3.0) - << qreal(1.0) << qreal(2.0) << qreal(3.0) - << true << qreal(-1.0) << qreal(1.0) - << qreal(0.0) << qreal(0.0) << qreal(0.0) - << qreal(1.0) << qreal(0.0) << qreal(0.0); - - QTest::newRow("normal-from-inside-neg-x") - << qreal(-1.0) << qreal(-2.0) << qreal(-3.0) - << qreal(1.0) << qreal(2.0) << qreal(3.0) - << true << qreal(-2.0) << qreal(2.0) - << qreal(0.0) << qreal(0.0) << qreal(0.0) - << qreal(-0.5) << qreal(0.0) << qreal(0.0); - - QTest::newRow("normal-from-inside-y") - << qreal(-1.0) << qreal(-2.0) << qreal(-3.0) - << qreal(1.0) << qreal(2.0) << qreal(3.0) - << true << qreal(-2.0) << qreal(2.0) - << qreal(0.0) << qreal(0.0) << qreal(0.0) - << qreal(0.0) << qreal(1.0) << qreal(0.0); - - QTest::newRow("normal-from-inside-neg-y") - << qreal(-1.0) << qreal(-2.0) << qreal(-3.0) - << qreal(1.0) << qreal(2.0) << qreal(3.0) - << true << qreal(-4.0) << qreal(4.0) - << qreal(0.0) << qreal(0.0) << qreal(0.0) - << qreal(0.0) << qreal(-0.5) << qreal(0.0); - - QTest::newRow("normal-from-inside-z") - << qreal(-1.0) << qreal(-2.0) << qreal(-3.0) - << qreal(1.0) << qreal(2.0) << qreal(3.0) - << true << qreal(-3.0) << qreal(3.0) - << qreal(0.0) << qreal(0.0) << qreal(0.0) - << qreal(0.0) << qreal(0.0) << qreal(1.0); - - QTest::newRow("normal-from-inside-neg-z") - << qreal(-1.0) << qreal(-2.0) << qreal(-3.0) - << qreal(1.0) << qreal(2.0) << qreal(3.0) - << true << qreal(-6.0) << qreal(6.0) - << qreal(0.0) << qreal(0.0) << qreal(0.0) - << qreal(0.0) << qreal(0.0) << qreal(-0.5); - - QTest::newRow("normal-from-outside-x") - << qreal(-1.0) << qreal(-2.0) << qreal(-3.0) - << qreal(1.0) << qreal(2.0) << qreal(3.0) - << true << qreal(1.0) << qreal(3.0) - << qreal(-2.0) << qreal(0.0) << qreal(0.0) - << qreal(1.0) << qreal(0.0) << qreal(0.0); - - QTest::newRow("normal-from-outside-neg-x") - << qreal(-1.0) << qreal(-2.0) << qreal(-3.0) - << qreal(1.0) << qreal(2.0) << qreal(3.0) - << true << qreal(-6.0) << qreal(-2.0) - << qreal(-2.0) << qreal(0.0) << qreal(0.0) - << qreal(-0.5) << qreal(0.0) << qreal(0.0); - - QTest::newRow("normal-from-outside-miss-x") - << qreal(-1.0) << qreal(-2.0) << qreal(-3.0) - << qreal(1.0) << qreal(2.0) << qreal(3.0) - << false << qreal(0.0) << qreal(0.0) - << qreal(-2.0) << qreal(3.0) << qreal(0.0) - << qreal(1.0) << qreal(0.0) << qreal(0.0); - - QTest::newRow("normal-from-outside-y") - << qreal(-1.0) << qreal(-2.0) << qreal(-3.0) - << qreal(1.0) << qreal(2.0) << qreal(3.0) - << true << qreal(1.0) << qreal(5.0) - << qreal(0.0) << qreal(-3.0) << qreal(0.0) - << qreal(0.0) << qreal(1.0) << qreal(0.0); - - QTest::newRow("normal-from-outside-neg-y") - << qreal(-1.0) << qreal(-2.0) << qreal(-3.0) - << qreal(1.0) << qreal(2.0) << qreal(3.0) - << true << qreal(-10.0) << qreal(-2.0) - << qreal(0.0) << qreal(-3.0) << qreal(0.0) - << qreal(0.0) << qreal(-0.5) << qreal(0.0); - - QTest::newRow("normal-from-outside-miss-y") - << qreal(-1.0) << qreal(-2.0) << qreal(-3.0) - << qreal(1.0) << qreal(2.0) << qreal(3.0) - << false << qreal(0.0) << qreal(0.0) - << qreal(2.0) << qreal(-3.0) << qreal(0.0) - << qreal(0.0) << qreal(1.5) << qreal(0.0); - - QTest::newRow("normal-from-outside-z") - << qreal(-1.0) << qreal(-2.0) << qreal(-3.0) - << qreal(1.0) << qreal(2.0) << qreal(3.0) - << true << qreal(1.0) << qreal(7.0) - << qreal(0.0) << qreal(0.0) << qreal(-4.0) - << qreal(0.0) << qreal(0.0) << qreal(1.0); - - QTest::newRow("normal-from-outside-neg-z") - << qreal(-1.0) << qreal(-2.0) << qreal(-3.0) - << qreal(1.0) << qreal(2.0) << qreal(3.0) - << true << qreal(-14.0) << qreal(-2.0) - << qreal(0.0) << qreal(0.0) << qreal(-4.0) - << qreal(0.0) << qreal(0.0) << qreal(-0.5); - - QTest::newRow("normal-from-outside-miss-z") - << qreal(-1.0) << qreal(-2.0) << qreal(-3.0) - << qreal(1.0) << qreal(2.0) << qreal(3.0) - << false << qreal(0.0) << qreal(0.0) - << qreal(0.0) << qreal(3.0) << qreal(-4.0) - << qreal(0.0) << qreal(0.0) << qreal(1.5); -} - -void tst_QBox3D::intersectRay() -{ - QFETCH(qreal, x1); - QFETCH(qreal, y1); - QFETCH(qreal, z1); - QFETCH(qreal, x2); - QFETCH(qreal, y2); - QFETCH(qreal, z2); - QFETCH(bool, intersects); - QFETCH(qreal, mint); - QFETCH(qreal, maxt); - QFETCH(qreal, originx); - QFETCH(qreal, originy); - QFETCH(qreal, originz); - QFETCH(qreal, directionx); - QFETCH(qreal, directiony); - QFETCH(qreal, directionz); - - QBox3D box(QVector3D(x1, y1, z1), QVector3D(x2, y2, z2)); - QRay3D ray(QVector3D(originx, originy, originz), - QVector3D(directionx, directiony, directionz)); - - qreal minimum_t = -1.0f, maximum_t = -1.0f; - if (intersects) { - QVERIFY(box.intersection(ray, &minimum_t, &maximum_t)); - QCOMPARE(minimum_t, mint); - QCOMPARE(maximum_t, maxt); - QVERIFY(box.intersects(ray)); - qreal t = box.intersection(ray); - if (mint >= 0.0f) - QCOMPARE(t, mint); - else if (maxt >= 0.0f) - QCOMPARE(t, maxt); - else - QVERIFY(qIsNaN(t)); - } else { - QVERIFY(!box.intersection(ray, &minimum_t, &maximum_t)); - QVERIFY(qIsNaN(minimum_t)); - QVERIFY(qIsNaN(maximum_t)); - QVERIFY(!box.intersects(ray)); - QVERIFY(qIsNaN(box.intersection(ray))); - } -} - -void tst_QBox3D::unitePoint_data() -{ - // Use the same test data as containsPoint(). - containsPoint_data(); -} -void tst_QBox3D::unitePoint() -{ - QFETCH(qreal, x); - QFETCH(qreal, y); - QFETCH(qreal, z); - QFETCH(bool, contained); - - QBox3D box(QVector3D(-1, -2, -3), QVector3D(4, 5, 6)); - - QBox3D result(box); - result.unite(QVector3D(x, y, z)); - - if (contained) { - QVERIFY(result == box); - } else { - qreal minx = (x < -1) ? x : -1; - qreal miny = (y < -2) ? y : -2; - qreal minz = (z < -3) ? z : -3; - qreal maxx = (x > 4) ? x : 4; - qreal maxy = (y > 5) ? y : 5; - qreal maxz = (z > 6) ? z : 6; - QBox3D expected(QVector3D(minx, miny, minz), QVector3D(maxx, maxy, maxz)); - QVERIFY(result == expected); - } - - QBox3D null; - null.unite(QVector3D(x, y, z)); - QVERIFY(null == QBox3D(QVector3D(x, y, z), QVector3D(x, y, z))); - - QBox3D infinite; - infinite.setToInfinite(); - infinite.unite(QVector3D(x, y, z)); - QVERIFY(infinite.isInfinite()); -} - -void tst_QBox3D::uniteBox_data() -{ - // Use the same test data as containsBox(). - containsBox_data(); -} -void tst_QBox3D::uniteBox() -{ - QFETCH(qreal, x1); - QFETCH(qreal, y1); - QFETCH(qreal, z1); - QFETCH(qreal, x2); - QFETCH(qreal, y2); - QFETCH(qreal, z2); - QFETCH(bool, contained); - QFETCH(bool, intersects); - QFETCH(qreal, ix1); - QFETCH(qreal, iy1); - QFETCH(qreal, iz1); - QFETCH(qreal, ix2); - QFETCH(qreal, iy2); - QFETCH(qreal, iz2); - QFETCH(qreal, ex1); - QFETCH(qreal, ey1); - QFETCH(qreal, ez1); - QFETCH(qreal, ex2); - QFETCH(qreal, ey2); - QFETCH(qreal, ez2); - - Q_UNUSED(contained); - Q_UNUSED(intersects); - Q_UNUSED(ix1); - Q_UNUSED(iy1); - Q_UNUSED(iz1); - Q_UNUSED(ix2); - Q_UNUSED(iy2); - Q_UNUSED(iz2); - - QBox3D box(QVector3D(-1, -2, -3), QVector3D(1, 2, 3)); - QBox3D other(QVector3D(x1, y1, z1), QVector3D(x2, y2, z2)); - QBox3D result(QVector3D(ex1, ey1, ez1), QVector3D(ex2, ey2, ez2)); - - QBox3D ibox(box); - ibox.unite(other); - QVERIFY(ibox == result); - - QBox3D null; - null.unite(other); - QVERIFY(null == other); - - QBox3D infinite; - infinite.setToInfinite(); - infinite.unite(other); - QVERIFY(infinite.isInfinite()); - - QBox3D ibox2(box); - QBox3D null2; - ibox2.unite(null2); - QVERIFY(ibox2 == box); - - QBox3D ibox3(box); - QBox3D infinite2; - infinite2.setToInfinite(); - ibox3.unite(infinite2); - QVERIFY(ibox3.isInfinite()); -} - -void tst_QBox3D::unitedPoint_data() -{ - // Use the same test data as containsPoint(). - containsPoint_data(); -} -void tst_QBox3D::unitedPoint() -{ - QFETCH(qreal, x); - QFETCH(qreal, y); - QFETCH(qreal, z); - QFETCH(bool, contained); - - QBox3D box(QVector3D(-1, -2, -3), QVector3D(4, 5, 6)); - - QBox3D result = box.united(QVector3D(x, y, z)); - - if (contained) { - QVERIFY(result == box); - } else { - qreal minx = (x < -1) ? x : -1; - qreal miny = (y < -2) ? y : -2; - qreal minz = (z < -3) ? z : -3; - qreal maxx = (x > 4) ? x : 4; - qreal maxy = (y > 5) ? y : 5; - qreal maxz = (z > 6) ? z : 6; - QBox3D expected(QVector3D(minx, miny, minz), QVector3D(maxx, maxy, maxz)); - QVERIFY(result == expected); - } - - QBox3D null; - result = null.united(QVector3D(x, y, z)); - QVERIFY(result == QBox3D(QVector3D(x, y, z), QVector3D(x, y, z))); - - QBox3D infinite; - infinite.setToInfinite(); - result = infinite.united(QVector3D(x, y, z)); - QVERIFY(result.isInfinite()); -} - -void tst_QBox3D::unitedBox_data() -{ - // Use the same test data as containsBox(). - containsBox_data(); -} -void tst_QBox3D::unitedBox() -{ - QFETCH(qreal, x1); - QFETCH(qreal, y1); - QFETCH(qreal, z1); - QFETCH(qreal, x2); - QFETCH(qreal, y2); - QFETCH(qreal, z2); - QFETCH(bool, contained); - QFETCH(bool, intersects); - QFETCH(qreal, ix1); - QFETCH(qreal, iy1); - QFETCH(qreal, iz1); - QFETCH(qreal, ix2); - QFETCH(qreal, iy2); - QFETCH(qreal, iz2); - QFETCH(qreal, ex1); - QFETCH(qreal, ey1); - QFETCH(qreal, ez1); - QFETCH(qreal, ex2); - QFETCH(qreal, ey2); - QFETCH(qreal, ez2); - - Q_UNUSED(contained); - Q_UNUSED(intersects); - Q_UNUSED(ix1); - Q_UNUSED(iy1); - Q_UNUSED(iz1); - Q_UNUSED(ix2); - Q_UNUSED(iy2); - Q_UNUSED(iz2); - - QBox3D box(QVector3D(-1, -2, -3), QVector3D(1, 2, 3)); - QBox3D other(QVector3D(x1, y1, z1), QVector3D(x2, y2, z2)); - QBox3D result(QVector3D(ex1, ey1, ez1), QVector3D(ex2, ey2, ez2)); - - QBox3D ibox = box.united(other); - QVERIFY(ibox == result); - - QBox3D null; - ibox = null.united(other); - QVERIFY(ibox == other); - - QBox3D infinite; - infinite.setToInfinite(); - ibox = infinite.united(other); - QVERIFY(ibox.isInfinite()); - - QBox3D ibox2(box); - QBox3D null2; - ibox = ibox2.united(null2); - QVERIFY(ibox == box); - - QBox3D ibox3(box); - QBox3D infinite2; - infinite2.setToInfinite(); - ibox = ibox3.united(infinite2); - QVERIFY(ibox.isInfinite()); -} - -void tst_QBox3D::transform() -{ - QBox3D box(QVector3D(-1, -2, -3), QVector3D(1, 2, 3)); - QMatrix4x4 m; - m.rotate(90, 0, 1, 0); - box.transform(m); - QVERIFY(box.minimum() == QVector3D(-3, -2, -1)); - QVERIFY(box.maximum() == QVector3D(3, 2, 1)); - - QBox3D null; - null.transform(m); - QVERIFY(null.isNull()); - - QBox3D infinite; - infinite.setToInfinite(); - infinite.transform(m); - QVERIFY(infinite.isInfinite()); -} - -void tst_QBox3D::transformed() -{ - QBox3D box(QVector3D(-1, -2, -3), QVector3D(1, 2, 3)); - QMatrix4x4 m; - m.rotate(90, 0, 1, 0); - QBox3D box2 = box.transformed(m); - QVERIFY(box2.minimum() == QVector3D(-3, -2, -1)); - QVERIFY(box2.maximum() == QVector3D(3, 2, 1)); - - QBox3D null; - box2 = null.transformed(m); - QVERIFY(box2.isNull()); - - QBox3D infinite; - infinite.setToInfinite(); - box2 = infinite.transformed(m); - QVERIFY(box2.isInfinite()); -} - -void tst_QBox3D::dataStream() -{ -#ifndef QT_NO_DATASTREAM - QBox3D box1(QVector3D(1.0f, 2.0f, 3.0f), QVector3D(4.0f, 5.0f, 6.0f)); - QBox3D box2; // null - QBox3D box3; - box3.setToInfinite(); - - QByteArray data; - { - QDataStream stream(&data, QIODevice::WriteOnly); - stream << box1; - stream << box2; - stream << box3; - } - - QBox3D rbox1; - QBox3D rbox2; - QBox3D rbox3; - { - QDataStream stream2(data); - stream2 >> rbox1; - stream2 >> rbox2; - stream2 >> rbox3; - } - - QVERIFY(box1 == rbox1); - QVERIFY(box2 == rbox2); - QVERIFY(box3 == rbox3); -#endif -} - -class tst_QBox3DProperties : public QObject -{ - Q_OBJECT - Q_PROPERTY(QBox3D box READ box WRITE setBox) -public: - tst_QBox3DProperties(QObject *parent = 0) : QObject(parent) {} - - QBox3D box() const { return b; } - void setBox(const QBox3D& value) { b = value; } - -private: - QBox3D b; -}; - -// Test getting and setting properties via the metaobject system. -void tst_QBox3D::properties() -{ - tst_QBox3DProperties obj; - - qRegisterMetaType<QBox3D>(); - - obj.setBox(QBox3D(QVector3D(1, 2, 3), QVector3D(4, 5, 6))); - - QBox3D b = qVariantValue<QBox3D>(obj.property("box")); - QCOMPARE(b.minimum(), QVector3D(1, 2, 3)); - QCOMPARE(b.maximum(), QVector3D(4, 5, 6)); - - obj.setProperty("box", - qVariantFromValue - (QBox3D(QVector3D(-1, -2, -3), QVector3D(-4, -5, -6)))); - - b = qVariantValue<QBox3D>(obj.property("box")); - QCOMPARE(b.minimum(), QVector3D(-4, -5, -6)); - QCOMPARE(b.maximum(), QVector3D(-1, -2, -3)); -} - -void tst_QBox3D::metaTypes() -{ - int id = qMetaTypeId<QBox3D>(); - QVERIFY(QMetaType::type("QBox3D") == id); - QCOMPARE(QByteArray(QMetaType::typeName(id)), QByteArray("QBox3D")); - QVERIFY(QMetaType::isRegistered(id)); -} - -QTEST_APPLESS_MAIN(tst_QBox3D) - -#include "tst_qbox3d.moc" diff --git a/tests/auto/threed/qcolor4ub/qcolor4ub.pro b/tests/auto/threed/qcolor4ub/qcolor4ub.pro deleted file mode 100644 index e5643b5c..00000000 --- a/tests/auto/threed/qcolor4ub/qcolor4ub.pro +++ /dev/null @@ -1,6 +0,0 @@ -load(qttest_p4.prf) -TEMPLATE=app -QT += testlib -CONFIG += unittest warn_on qt3d - -SOURCES += tst_qcolor4ub.cpp diff --git a/tests/auto/threed/qcolor4ub/tst_qcolor4ub.cpp b/tests/auto/threed/qcolor4ub/tst_qcolor4ub.cpp deleted file mode 100644 index 73c625ee..00000000 --- a/tests/auto/threed/qcolor4ub/tst_qcolor4ub.cpp +++ /dev/null @@ -1,341 +0,0 @@ -/**************************************************************************** -** -** 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 QtQuick3D module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** 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. -** -** 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. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include <QtTest/QtTest> -#include "qcolor4ub.h" - -class tst_QColor4ub : public QObject -{ - Q_OBJECT -public: - tst_QColor4ub() {} - ~tst_QColor4ub() {} - -private slots: - void create(); - void modify(); - void copy(); - void compare_data(); - void compare(); - void toColor(); - void checkSize(); -}; - -#define fuzzyCompare(x,y) (qAbs((x) - (y)) < 0.0001) - -void tst_QColor4ub::create() -{ - QColor4ub c1; - QCOMPARE(c1.red(), 0); - QCOMPARE(c1.green(), 0); - QCOMPARE(c1.blue(), 0); - QCOMPARE(c1.alpha(), 255); - QCOMPARE(c1.redF(), qreal(0.0)); - QCOMPARE(c1.greenF(), qreal(0.0)); - QCOMPARE(c1.blueF(), qreal(0.0)); - QCOMPARE(c1.alphaF(), qreal(1.0)); - - QColor4ub c2(162, 54, 39); - QCOMPARE(c2.red(), 162); - QCOMPARE(c2.green(), 54); - QCOMPARE(c2.blue(), 39); - QCOMPARE(c2.alpha(), 255); - QVERIFY(fuzzyCompare(c2.redF(), qreal(162 / 255.0f))); - QVERIFY(fuzzyCompare(c2.greenF(), qreal(54 / 255.0f))); - QVERIFY(fuzzyCompare(c2.blueF(), qreal(39 / 255.0f))); - QVERIFY(fuzzyCompare(c2.alphaF(), qreal(1.0))); - - QColor4ub c3(162, 54, 39, 41); - QCOMPARE(c3.red(), 162); - QCOMPARE(c3.green(), 54); - QCOMPARE(c3.blue(), 39); - QCOMPARE(c3.alpha(), 41); - QVERIFY(fuzzyCompare(c3.redF(), qreal(162 / 255.0f))); - QVERIFY(fuzzyCompare(c3.greenF(), qreal(54 / 255.0f))); - QVERIFY(fuzzyCompare(c3.blueF(), qreal(39 / 255.0f))); - QVERIFY(fuzzyCompare(c3.alphaF(), qreal(41 / 255.0f))); - - QColor4ub c4(QColor(162, 54, 39, 41)); - QCOMPARE(c4.red(), 162); - QCOMPARE(c4.green(), 54); - QCOMPARE(c4.blue(), 39); - QCOMPARE(c4.alpha(), 41); - - QColor4ub c5(Qt::red); - QCOMPARE(c5.red(), 255); - QCOMPARE(c5.green(), 0); - QCOMPARE(c5.blue(), 0); - QCOMPARE(c5.alpha(), 255); - - QColor4ub c6(qRgb(162, 54, 39)); - QCOMPARE(c6.red(), 162); - QCOMPARE(c6.green(), 54); - QCOMPARE(c6.blue(), 39); - QCOMPARE(c6.alpha(), 255); - - QColor4ub c7(qRgba(162, 54, 39, 41)); - QCOMPARE(c7.red(), 162); - QCOMPARE(c7.green(), 54); - QCOMPARE(c7.blue(), 39); - QCOMPARE(c7.alpha(), 41); - - QColor4ub c8(256, -3, 1); // truncates from int to uchar - QCOMPARE(c8.red(), 0); - QCOMPARE(c8.green(), 253); - QCOMPARE(c8.blue(), 1); - QCOMPARE(c8.alpha(), 255); - - QColor4ub c9 = QColor4ub::fromRgb(162, 54, 39); - QCOMPARE(c9.red(), 162); - QCOMPARE(c9.green(), 54); - QCOMPARE(c9.blue(), 39); - QCOMPARE(c9.alpha(), 255); - c9 = QColor4ub::fromRgb(162, 54, 39, 41); - QCOMPARE(c9.red(), 162); - QCOMPARE(c9.green(), 54); - QCOMPARE(c9.blue(), 39); - QCOMPARE(c9.alpha(), 41); - - QColor4ub c10 = QColor4ub::fromRgbF(1.0f, 0.5f, 0.25f); - QCOMPARE(c10.red(), 255); - QCOMPARE(c10.green(), 128); - QCOMPARE(c10.blue(), 64); - QCOMPARE(c10.alpha(), 255); - c10 = QColor4ub::fromRgbF(1.0f, 0.5f, 0.25f, 0.75f); - QCOMPARE(c10.red(), 255); - QCOMPARE(c10.green(), 128); - QCOMPARE(c10.blue(), 64); - QCOMPARE(c10.alpha(), 191); - - static uchar const data[4] = {uchar(162), uchar(54), uchar(39), uchar(255)}; - QColor4ub c11 = QColor4ub::fromRaw(data); - QCOMPARE(c11.red(), 162); - QCOMPARE(c11.green(), 54); - QCOMPARE(c11.blue(), 39); - QCOMPARE(c11.alpha(), 255); -} - -void tst_QColor4ub::modify() -{ - QColor4ub c1(162, 54, 39, 41); - c1.setRed(34); - c1.setGreen(163); - c1.setBlue(2); - c1.setAlpha(200); - QCOMPARE(c1.red(), 34); - QCOMPARE(c1.green(), 163); - QCOMPARE(c1.blue(), 2); - QCOMPARE(c1.alpha(), 200); - QVERIFY(fuzzyCompare(c1.redF(), qreal(34 / 255.0f))); - QVERIFY(fuzzyCompare(c1.greenF(), qreal(163 / 255.0f))); - QVERIFY(fuzzyCompare(c1.blueF(), qreal(2 / 255.0f))); - QVERIFY(fuzzyCompare(c1.alphaF(), qreal(200 / 255.0f))); - - QColor4ub c2; - c2.setRedF(1.0f); - c2.setGreenF(0.5f); - c2.setBlueF(0.25f); - c2.setAlphaF(0.75f); - QCOMPARE(c2.red(), 255); - QCOMPARE(c2.green(), 128); - QCOMPARE(c2.blue(), 64); - QCOMPARE(c2.alpha(), 191); - QVERIFY(fuzzyCompare(c2.redF(), qreal(1.0))); - QVERIFY(fuzzyCompare(c2.greenF(), qreal(128 / 255.0f))); - QVERIFY(fuzzyCompare(c2.blueF(), qreal(64 / 255.0f))); - QVERIFY(fuzzyCompare(c2.alphaF(), qreal(191 / 255.0f))); - - QColor4ub c3; - c3.setRgb(162, 54, 39); - QCOMPARE(c3.red(), 162); - QCOMPARE(c3.green(), 54); - QCOMPARE(c3.blue(), 39); - QCOMPARE(c3.alpha(), 255); - c3.setRgb(162, 54, 39, 41); - QCOMPARE(c3.red(), 162); - QCOMPARE(c3.green(), 54); - QCOMPARE(c3.blue(), 39); - QCOMPARE(c3.alpha(), 41); - - QColor4ub c4; - c4.setRgbF(1.0f, 0.5f, 0.25f); - QCOMPARE(c4.red(), 255); - QCOMPARE(c4.green(), 128); - QCOMPARE(c4.blue(), 64); - QCOMPARE(c4.alpha(), 255); - c4.setRgbF(1.0f, 0.5f, 0.25f, 0.75f); - QCOMPARE(c4.red(), 255); - QCOMPARE(c4.green(), 128); - QCOMPARE(c4.blue(), 64); - QCOMPARE(c4.alpha(), 191); -} - -void tst_QColor4ub::copy() -{ - QColor4ub c1(162, 54, 39, 41); - QColor4ub c2(c1); - QCOMPARE(c2.red(), 162); - QCOMPARE(c2.green(), 54); - QCOMPARE(c2.blue(), 39); - QCOMPARE(c2.alpha(), 41); - - QColor4ub c3; - c3 = c2; - QCOMPARE(c3.red(), 162); - QCOMPARE(c3.green(), 54); - QCOMPARE(c3.blue(), 39); - QCOMPARE(c3.alpha(), 41); - - c1 = Qt::red; - QCOMPARE(c1.red(), 255); - QCOMPARE(c1.green(), 0); - QCOMPARE(c1.blue(), 0); - QCOMPARE(c1.alpha(), 255); - - c2 = QColor(162, 54, 39, 41); - QCOMPARE(c2.red(), 162); - QCOMPARE(c2.green(), 54); - QCOMPARE(c2.blue(), 39); - QCOMPARE(c2.alpha(), 41); - - c1 = c2; - QCOMPARE(c1.red(), 162); - QCOMPARE(c1.green(), 54); - QCOMPARE(c1.blue(), 39); - QCOMPARE(c1.alpha(), 41); -} - -void tst_QColor4ub::compare_data() -{ - QTest::addColumn<int>("red1"); - QTest::addColumn<int>("green1"); - QTest::addColumn<int>("blue1"); - QTest::addColumn<int>("alpha1"); - QTest::addColumn<int>("red2"); - QTest::addColumn<int>("green2"); - QTest::addColumn<int>("blue2"); - QTest::addColumn<int>("alpha2"); - QTest::addColumn<bool>("isEqual"); - - QTest::newRow("black") - << 0 << 0 << 0 << 0 - << 0 << 0 << 0 << 0 - << true; - - QTest::newRow("white") - << 255 << 255 << 255 << 255 - << 255 << 255 << 255 << 255 - << true; - - QTest::newRow("mixed") - << 162 << 54 << 39 << 41 - << 162 << 54 << 39 << 41 - << true; - - QTest::newRow("red-diff") - << 162 << 54 << 39 << 41 - << 161 << 54 << 39 << 41 - << false; - - QTest::newRow("green-diff") - << 162 << 54 << 39 << 41 - << 162 << 53 << 39 << 41 - << false; - - QTest::newRow("blue-diff") - << 162 << 54 << 39 << 41 - << 162 << 54 << 38 << 41 - << false; - - QTest::newRow("alpha-diff") - << 162 << 54 << 39 << 41 - << 162 << 54 << 39 << 40 - << false; - - QTest::newRow("all-diff") - << 162 << 54 << 39 << 41 - << 161 << 53 << 38 << 40 - << false; -} - -void tst_QColor4ub::compare() -{ - QFETCH(int, red1); - QFETCH(int, green1); - QFETCH(int, blue1); - QFETCH(int, alpha1); - QFETCH(int, red2); - QFETCH(int, green2); - QFETCH(int, blue2); - QFETCH(int, alpha2); - QFETCH(bool, isEqual); - - QColor4ub c1(red1, green1, blue1, alpha1); - QColor4ub c2(red2, green2, blue2, alpha2); - - if (isEqual) { - QVERIFY(c1 == c2); - QVERIFY(!(c1 != c2)); - } else { - QVERIFY(!(c1 == c2)); - QVERIFY(c1 != c2); - } -} - -void tst_QColor4ub::toColor() -{ - QColor4ub c1(162, 54, 39, 41); - QColor c2 = c1.toColor(); - QCOMPARE(c2.red(), 162); - QCOMPARE(c2.green(), 54); - QCOMPARE(c2.blue(), 39); - QCOMPARE(c2.alpha(), 41); -} - -void tst_QColor4ub::checkSize() -{ - // We need QColor4ub to be precisely packed as four single-byte values. - QCOMPARE(sizeof(QColor4ub), sizeof(uchar) * 4); -} - -QTEST_APPLESS_MAIN(tst_QColor4ub) - -#include "tst_qcolor4ub.moc" diff --git a/tests/auto/threed/qcustomdataarray/qcustomdataarray.pro b/tests/auto/threed/qcustomdataarray/qcustomdataarray.pro deleted file mode 100644 index 7b5d0495..00000000 --- a/tests/auto/threed/qcustomdataarray/qcustomdataarray.pro +++ /dev/null @@ -1,6 +0,0 @@ -load(qttest_p4.prf) -TEMPLATE=app -QT += testlib -CONFIG += unittest warn_on qt3d - -SOURCES += tst_qcustomdataarray.cpp diff --git a/tests/auto/threed/qcustomdataarray/tst_qcustomdataarray.cpp b/tests/auto/threed/qcustomdataarray/tst_qcustomdataarray.cpp deleted file mode 100644 index f65aa798..00000000 --- a/tests/auto/threed/qcustomdataarray/tst_qcustomdataarray.cpp +++ /dev/null @@ -1,139 +0,0 @@ -/**************************************************************************** -** -** 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 QtQuick3D module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** 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. -** -** 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. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include <QtTest/QtTest> -#include "qcustomdataarray.h" - -class tst_QCustomDataArray : public QObject -{ - Q_OBJECT -public: - tst_QCustomDataArray() {} - ~tst_QCustomDataArray() {} - -private slots: - void create(); -}; - -void tst_QCustomDataArray::create() -{ - QCustomDataArray array1; - QVERIFY(array1.elementType() == QCustomDataArray::Float); - QVERIFY(array1.elementSize() == sizeof(float)); - QCOMPARE(array1.size(), 0); - QCOMPARE(array1.count(), 0); - QVERIFY(array1.isEmpty()); - - array1.setElementType(QCustomDataArray::Vector3D); - QVERIFY(array1.elementType() == QCustomDataArray::Vector3D); - QVERIFY(array1.elementSize() == sizeof(QVector3D)); - QCOMPARE(array1.size(), 0); - QCOMPARE(array1.count(), 0); - QVERIFY(array1.isEmpty()); - - QCustomDataArray array2(QCustomDataArray::Vector2D); - QVERIFY(array2.elementType() == QCustomDataArray::Vector2D); - QVERIFY(array2.elementSize() == sizeof(QVector2D)); - QCOMPARE(array2.size(), 0); - QCOMPARE(array2.count(), 0); - QVERIFY(array2.isEmpty()); - - QCustomDataArray array3(QCustomDataArray::Vector3D, 20); - QVERIFY(array3.elementType() == QCustomDataArray::Vector3D); - QVERIFY(array3.elementSize() == sizeof(QVector3D)); - QCOMPARE(array3.size(), 20); - QCOMPARE(array3.count(), 20); - QVERIFY(!array3.isEmpty()); - QVERIFY(array3.capacity() >= 20); - - QCustomDataArray array4(QCustomDataArray::Vector4D, 20); - QVERIFY(array4.elementType() == QCustomDataArray::Vector4D); - QVERIFY(array4.elementSize() == sizeof(QVector4D)); - QCOMPARE(array4.size(), 20); - QCOMPARE(array4.count(), 20); - QVERIFY(!array4.isEmpty()); - array4.append(QVector4D(1.0f, 2.0f, 3.0f, 4.0f)); - - QCustomDataArray array5(QCustomDataArray::Color, 10); - QVERIFY(array5.elementType() == QCustomDataArray::Color); - QVERIFY(array5.elementSize() == sizeof(QColor4ub)); - QCOMPARE(array5.size(), 10); - QCOMPARE(array5.count(), 10); - QVERIFY(!array5.isEmpty()); - array5.append(Qt::red); - array5.setAt(4, Qt::green); - QVERIFY(array5.colorAt(4) == Qt::green); - - QCustomDataArray array6(array5); - QVERIFY(array6.elementType() == QCustomDataArray::Color); - QVERIFY(array6.elementSize() == sizeof(QColor4ub)); - QCOMPARE(array6.size(), 11); - QCOMPARE(array6.count(), 11); - QVERIFY(!array6.isEmpty()); - QVERIFY(array6.colorAt(10) == Qt::red); - - // Changes element type from Color to Vector4D. - array6 = array4; - QVERIFY(array6.elementType() == QCustomDataArray::Vector4D); - QVERIFY(array6.elementSize() == sizeof(QVector4D)); - QCOMPARE(array6.size(), 21); - QCOMPARE(array6.count(), 21); - QVERIFY(!array6.isEmpty()); - QVERIFY(array6.vector4DAt(20) == QVector4D(1.0f, 2.0f, 3.0f, 4.0f)); - - array6.clear(); - QVERIFY(array6.elementType() == QCustomDataArray::Vector4D); - QVERIFY(array6.elementSize() == sizeof(QVector4D)); - QCOMPARE(array6.size(), 0); - QCOMPARE(array6.count(), 0); - QVERIFY(array6.isEmpty()); - - array6.setElementType(QCustomDataArray::Vector3D); - QVERIFY(array6.elementType() == QCustomDataArray::Vector3D); - QVERIFY(array6.elementSize() == sizeof(QVector3D)); - QCOMPARE(array6.size(), 0); - QCOMPARE(array6.count(), 0); - QVERIFY(array6.isEmpty()); -} - -QTEST_APPLESS_MAIN(tst_QCustomDataArray) - -#include "tst_qcustomdataarray.moc" diff --git a/tests/auto/threed/qgeometrydata/qgeometrydata.pro b/tests/auto/threed/qgeometrydata/qgeometrydata.pro deleted file mode 100644 index a03425bb..00000000 --- a/tests/auto/threed/qgeometrydata/qgeometrydata.pro +++ /dev/null @@ -1,9 +0,0 @@ -load(qttest_p4.prf) -TEMPLATE=app -QT += testlib -CONFIG += unittest warn_on qt3d - -INCLUDEPATH += ../../../shared -INCLUDEPATH += ../../../../src/threed/geometry - -SOURCES += tst_qgeometrydata.cpp diff --git a/tests/auto/threed/qgeometrydata/tst_qgeometrydata.cpp b/tests/auto/threed/qgeometrydata/tst_qgeometrydata.cpp deleted file mode 100644 index 7dd77956..00000000 --- a/tests/auto/threed/qgeometrydata/tst_qgeometrydata.cpp +++ /dev/null @@ -1,629 +0,0 @@ -/**************************************************************************** -** -** 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 QtQuick3D module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** 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. -** -** 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. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include <QtTest/QtTest> -#include <QtCore/qpointer.h> - -#include "qgeometrydata.h" -#include "qvector_utils_p.h" -#include "qtest_helpers.h" -#include "qglpainter.h" - -#include <QtCore/qdebug.h> - -class tst_QGeometryData : public QObject -{ - Q_OBJECT -public: - tst_QGeometryData() {} - ~tst_QGeometryData() {} - -private slots: - void createDefault(); - void appendVertex(); - void appendNormal(); - void appendVertexNormal(); - void copy(); - void interleaveWith(); - void boundingBox(); - void center(); - void normalizeNormals(); - void reversed(); - void translated(); - void generateTextureCoordinates(); - void clear(); - void draw(); -}; - -void tst_QGeometryData::createDefault() -{ - QGeometryData data; - QCOMPARE(data.count(), 0); - QCOMPARE(data.attributes().count(), 0); - QCOMPARE(data.fields(), quint32(0)); - QCOMPARE(data.vertices().count(), 0); - data.normalizeNormals(); - QCOMPARE(data.boundingBox(), QBox3D()); - - // copy constructor on initialization - null default - QGeometryData other = data; - QCOMPARE(other.count(), 0); - QCOMPARE(other.attributes().count(), 0); - QCOMPARE(other.fields(), quint32(0)); - - // copy constructor on default - QGeometryData copy(data); - QCOMPARE(copy.count(), 0); - QCOMPARE(copy.attributes().count(), 0); - QCOMPARE(copy.fields(), quint32(0)); -} - -void tst_QGeometryData::appendVertex() -{ - QVector3D a(1.1, 1.2, 1.3); - QVector3D b(2.1, 2.2, 2.3); - QVector3D c(3.1, 3.2, 3.3); - QVector3D d(4.1, 4.2, 4.3); - { - QGeometryData data; - data.appendVertex(a); - QCOMPARE(data.count(), 1); - QCOMPARE(data.fields(), QGL::fieldMask(QGL::Position)); - QCOMPARE(data.vertices().count(), 1); - QCOMPARE(data.vertices().at(0), a); - } - { - QGeometryData data; - data.appendVertex(a, b); - QCOMPARE(data.count(), 2); - QCOMPARE(data.fields(), QGL::fieldMask(QGL::Position)); - QCOMPARE(data.vertices().count(), 2); - QCOMPARE(data.vertices().at(0), a); - QCOMPARE(data.vertices().at(1), b); - } - { - QGeometryData data; - data.appendVertex(a, b, c); - QCOMPARE(data.count(), 3); - QCOMPARE(data.fields(), QGL::fieldMask(QGL::Position)); - QCOMPARE(data.vertices().count(), 3); - QCOMPARE(data.vertices().at(0), a); - QCOMPARE(data.vertices().at(1), b); - QCOMPARE(data.vertices().at(2), c); - } - { - QGeometryData data; - data.appendVertex(a, b, c, d); - QCOMPARE(data.count(), 4); - QCOMPARE(data.fields(), QGL::fieldMask(QGL::Position)); - QCOMPARE(data.vertices().count(), 4); - QCOMPARE(data.vertices().at(0), a); - QCOMPARE(data.vertices().at(1), b); - QCOMPARE(data.vertices().at(2), c); - QCOMPARE(data.vertices().at(3), d); - } - { - QGeometryData data; - data.appendVertex(a, b, c, d); - data.appendVertex(a, b, c, d); - data.appendVertex(a); - QCOMPARE(data.count(), 9); - QCOMPARE(data.fields(), QGL::fieldMask(QGL::Position)); - QCOMPARE(data.vertices().count(), 9); - QCOMPARE(data.vertices().at(0), a); - QCOMPARE(data.vertices().at(1), b); - QCOMPARE(data.vertices().at(5), b); - QCOMPARE(data.vertices().at(8), a); - } -} - -void tst_QGeometryData::appendNormal() -{ - QVector3D a(1.1, 1.2, 1.3); - QVector3D b(2.1, 2.2, 2.3); - QVector3D c(3.1, 3.2, 3.3); - QVector3D d(4.1, 4.2, 4.3); - { - QGeometryData data; - data.appendNormal(a); - QCOMPARE(data.count(), 1); - QCOMPARE(data.fields(), QGL::fieldMask(QGL::Normal)); - QCOMPARE(data.normals().count(), 1); - QCOMPARE(data.normals().at(0), a); - } - { - QGeometryData data; - data.appendNormal(a, b); - QCOMPARE(data.count(), 2); - QCOMPARE(data.fields(), QGL::fieldMask(QGL::Normal)); - QCOMPARE(data.normals().count(), 2); - QCOMPARE(data.normals().at(0), a); - QCOMPARE(data.normals().at(1), b); - } - { - QGeometryData data; - data.appendNormal(a, b, c); - QCOMPARE(data.count(), 3); - QCOMPARE(data.fields(), QGL::fieldMask(QGL::Normal)); - QCOMPARE(data.normals().count(), 3); - QCOMPARE(data.normals().at(0), a); - QCOMPARE(data.normals().at(1), b); - QCOMPARE(data.normals().at(2), c); - } - { - QGeometryData data; - data.appendNormal(a, b, c, d); - QCOMPARE(data.count(), 4); - QCOMPARE(data.fields(), QGL::fieldMask(QGL::Normal)); - QCOMPARE(data.normals().count(), 4); - QCOMPARE(data.normals().at(0), a); - QCOMPARE(data.normals().at(1), b); - QCOMPARE(data.normals().at(2), c); - QCOMPARE(data.normals().at(3), d); - } - { - QGeometryData data; - data.appendNormal(a, b, c, d); - data.appendNormal(a, b, c, d); - data.appendNormal(a); - QCOMPARE(data.count(), 9); - QCOMPARE(data.fields(), QGL::fieldMask(QGL::Normal)); - QCOMPARE(data.normals().count(), 9); - QCOMPARE(data.normals().at(0), a); - QCOMPARE(data.normals().at(1), b); - QCOMPARE(data.normals().at(5), b); - QCOMPARE(data.normals().at(8), a); - } -} - -void tst_QGeometryData::appendVertexNormal() -{ - QVector3D a(1.1, 1.2, 1.3); - QVector3D b(2.1, 2.2, 2.3); - QVector3D c(3.1, 3.2, 3.3); - QVector3D d(4.1, 4.2, 4.3); - QVector3D an(5.1, 5.2, 5.3); - QVector3D bn(6.1, 6.2, 6.3); - QVector3D cn(7.1, 7.2, 7.3); - QVector3D dn(8.1, 8.2, 8.3); - { - QGeometryData data; - data.appendVertex(a); - data.appendNormal(an); - QCOMPARE(data.count(), 1); - QCOMPARE(data.fields(), QGL::fieldMask(QGL::Position) | QGL::fieldMask(QGL::Normal)); - QCOMPARE(data.vertices().count(), 1); - QCOMPARE(data.vertices().at(0), a); - } - { - QGeometryData data; - data.appendVertex(a, b); - data.appendNormal(an, bn); - QCOMPARE(data.count(), 2); - QCOMPARE(data.fields(), QGL::fieldMask(QGL::Position) | QGL::fieldMask(QGL::Normal)); - QCOMPARE(data.vertices().count(), 2); - QCOMPARE(data.vertices().at(0), a); - QCOMPARE(data.vertex(1), b); - QCOMPARE(data.normals().count(), 2); - QCOMPARE(data.normal(0), an); - QCOMPARE(data.normals().at(1), bn); - } - { - QGeometryData data; - data.appendVertex(a, b, c); - data.appendNormal(an, bn, cn); - QCOMPARE(data.count(), 3); - QCOMPARE(data.fields(), QGL::fieldMask(QGL::Position) | QGL::fieldMask(QGL::Normal)); - QCOMPARE(data.vertices().count(), 3); - QCOMPARE(data.vertices().at(0), a); - QCOMPARE(data.vertices().at(1), b); - QCOMPARE(data.vertices().at(2), c); - QCOMPARE(data.normals().count(), 3); - QCOMPARE(data.normal(0), an); - QCOMPARE(data.normals().at(1), bn); - QCOMPARE(data.normal(2), cn); - } - { - QGeometryData data; - data.appendVertex(a, b, c, d); - data.appendNormal(an, bn, cn, dn); - QCOMPARE(data.count(), 4); - QCOMPARE(data.fields(), QGL::fieldMask(QGL::Position) | QGL::fieldMask(QGL::Normal)); - QCOMPARE(data.vertices().count(), 4); - QCOMPARE(data.vertices().at(0), a); - QCOMPARE(data.vertices().at(1), b); - QCOMPARE(data.vertices().at(2), c); - QCOMPARE(data.vertices().at(3), d); - QCOMPARE(data.normals().count(), 4); - QCOMPARE(data.normals().at(0), an); - QCOMPARE(data.normals().at(1), bn); - QCOMPARE(data.normals().at(2), cn); - QCOMPARE(data.normals().at(3), dn); - } - { - QGeometryData data; - data.appendVertex(a, b, c, d); - data.appendNormal(an, bn, cn, dn); - data.appendVertex(a, b, c, d); - data.appendNormal(an, bn, cn, dn); - data.appendVertex(a); - data.appendNormal(an); - QCOMPARE(data.count(), 9); - QCOMPARE(data.fields(), QGL::fieldMask(QGL::Position) | QGL::fieldMask(QGL::Normal)); - QCOMPARE(data.vertices().count(), 9); - QCOMPARE(data.vertices().at(0), a); - QCOMPARE(data.vertices().at(1), b); - QCOMPARE(data.vertices().at(5), b); - QCOMPARE(data.vertices().at(8), a); - QCOMPARE(data.normals().count(), 9); - QCOMPARE(data.normals().at(0), an); - QCOMPARE(data.normals().at(1), bn); - QCOMPARE(data.normals().at(5), bn); - QCOMPARE(data.normals().at(8), an); - } -} - - -QVector3D avec(99.1, 99.2, 99.3); - -static QGeometryData aFunc(const QGeometryData& g) // not a copy but a ref -{ - QGeometryData d = g; // copy constructor - d.appendVertex(avec); - return d; // assingment operator -} - -void tst_QGeometryData::copy() -{ - QVector3D a(1.1, 1.2, 1.3); - QVector3D b(2.1, 2.2, 2.3); - QVector3D c(3.1, 3.2, 3.3); - QVector3D d(4.1, 4.2, 4.3); - { - QGeometryData data; - QCOMPARE(data.count(), 0); - QCOMPARE(data.fields(), (quint32)0); - QGeometryData other; - other.appendVertex(QVector3D()); - QCOMPARE(other.count(), 1); - QCOMPARE(other.fields(), QGL::fieldMask(QGL::Position)); - other = aFunc(data); // assignment op - throw away previous d - QCOMPARE(other.count(), 1); - QCOMPARE(other.fields(), QGL::fieldMask(QGL::Position)); - QVector3D res = other.vertices().at(0); - QCOMPARE(res, avec); - } - { - QGeometryData data; - data.appendVertex(a, b, c, d); - QGeometryData other; - QCOMPARE(other.count(), 0); - QCOMPARE(other.fields(), (quint32)0); - other = aFunc(data); // assignment operator - other.appendVertex(a); - QCOMPARE(other.count(), 6); - QCOMPARE(other.fields(), QGL::fieldMask(QGL::Position)); - QCOMPARE(other.vertices().count(), 6); - QCOMPARE(other.vertices().at(0), a); - QCOMPARE(other.vertices().at(1), b); - QCOMPARE(other.vertices().at(4), avec); - QCOMPARE(other.vertices().at(5), a); - } -} - -void tst_QGeometryData::interleaveWith() -{ - QVector3D a(1.1, 1.2, 1.3); - QVector3D b(2.1, 2.2, 2.3); - QVector3D c(3.1, 3.2, 3.3); - QVector3D d(4.1, 4.2, 4.3); - QVector3D vx(0.7071, 0.7071, 0.0); - QVector2D at(0.11, 0.12); - QVector2D bt(0.21, 0.22); - QVector2D ct(0.31, 0.32); - QVector2D dt(0.41, 0.42); - QVector2D tx(1.0, 1.0); - - QGeometryData data; - data.appendVertex(a, b, c, d); - data.appendTexCoord(at, bt, ct, dt); - QGeometryData dat2; - - // count is the smaller of the two - nothing in this null case - // also make sure the argument does not somehow change - its a const - // so it shouldn't... - dat2.interleaveWith(data); - QCOMPARE(data.count(), 4); - QCOMPARE(data.vertex(0), a); - QCOMPARE(dat2.count(), 0); - QCOMPARE(dat2.count(QGL::Position), 0); - QCOMPARE(dat2.fields(), quint32(0)); - - // dat2 is smaller and has less fields - dat2.appendVertex(a + vx, b + vx); - dat2.interleaveWith(data); - QCOMPARE(data.count(), 4); - QCOMPARE(data.vertex(0), a); - QCOMPARE(dat2.count(), 4); - QCOMPARE(dat2.count(QGL::Position), 4); - QCOMPARE(dat2.count(QGL::TextureCoord0), 0); - QCOMPARE(dat2.fields(), QGL::fieldMask(QGL::Position)); - QCOMPARE(dat2.vertex(0), a + vx); - QCOMPARE(dat2.vertex(1), a); - QCOMPARE(dat2.vertex(2), b + vx); - QCOMPARE(dat2.vertex(3), b); - - // full zip with both sides have 4 verts & textures - dat2.clear(); - for (int i = 0; i < data.count(); ++i) - { - dat2.appendVertex(data.vertex(i) + vx); - dat2.appendTexCoord(data.texCoord(i) + tx); - } - dat2.interleaveWith(data); - QCOMPARE(dat2.count(), 8); - QCOMPARE(dat2.count(QGL::Position), 8); - QCOMPARE(dat2.count(QGL::TextureCoord0), 8); - QCOMPARE(dat2.fields(), QGL::fieldMask(QGL::Position) | - QGL::fieldMask(QGL::TextureCoord0)); - QCOMPARE(dat2.vertex(0), a + vx); - QCOMPARE(dat2.vertex(1), a); - QCOMPARE(dat2.vertex(4), c + vx); - QCOMPARE(dat2.vertex(7), d); - QCOMPARE(dat2.texCoord(0), at + tx); - QCOMPARE(dat2.texCoord(3), bt); - QCOMPARE(dat2.texCoord(7), dt); -} - -void tst_QGeometryData::boundingBox() -{ - QVector3D a(1.1, 1.2, 1.3); - QVector3D b(2.1, 2.2, 2.3); - QVector3D c(3.1, 3.2, 3.3); - QVector3D d(4.1, 4.2, 4.3); - - QGeometryData data; - data.appendVertex(a, b, c, d); - - QBox3D bb = data.boundingBox(); - QCOMPARE(bb.maximum(), d); - QCOMPARE(bb.minimum(), a); -} - -void tst_QGeometryData::center() -{ - QVector3D a(1.1, 1.2, 1.3); - QVector3D b(2.1, 2.2, 2.3); - QVector3D c(3.1, 3.2, 3.3); - QVector3D d(4.1, 4.2, 4.3); - - QGeometryData data; - data.appendVertex(a, b, c, d); - - QVector3D center = data.center(); - QCOMPARE(center, QVector3D(2.6, 2.7, 2.8)); -} - -void tst_QGeometryData::normalizeNormals() -{ - QVector3D a(1.1, 1.2, 1.3); - QVector3D b(2.1, 2.2, 2.3); - QVector3D c(3.1, 3.2, 3.3); - QVector3D d(4.1, 4.2, 4.3); - QVector3D an(5.1, 5.2, 5.3); - QVector3D bn(6.1, 6.2, 6.3); - QVector3D cn(7.1, 7.2, 7.3); - QVector3D dn(8.1, 8.2, 8.3); - - QGeometryData data; - data.appendVertex(a, b, c, d); - data.appendNormal(an, bn, cn, dn); - - data.normalizeNormals(); - QVector3D n = data.normalAt(1); - QVERIFY(qFskCompare(data.normalAt(0), QVector3D(0.566178, 0.577279, 0.588381))); - QVERIFY(qFskCompare(data.normalAt(1), QVector3D(0.567989, 0.577300, 0.586612))); - QVERIFY(qFskCompare(data.normalAt(2), QVector3D(0.569295, 0.577313, 0.585331))); - QVERIFY(qFskCompare(data.normalAt(3), QVector3D(0.570281, 0.577322, 0.584362))); - QVERIFY(qFskCompare(data.normalAt(0).lengthSquared(), qreal(1.0f))); - QVERIFY(qFskCompare(data.normalAt(1).lengthSquared(), qreal(1.0f))); - QVERIFY(qFskCompare(data.normalAt(2).lengthSquared(), qreal(1.0f))); - QVERIFY(qFskCompare(data.normalAt(3).lengthSquared(), qreal(1.0f))); -} - -void tst_QGeometryData::reversed() -{ - QVector3D a(1.1, 1.2, 1.3); - QVector3D b(2.1, 2.2, 2.3); - QVector3D c(3.1, 3.2, 3.3); - QVector3D d(4.1, 4.2, 4.3); - QVector3D an(5.1, 5.2, 5.3); - QVector3D bn(6.1, 6.2, 6.3); - QVector3D cn(7.1, 7.2, 7.3); - QVector3D dn(8.1, 8.2, 8.3); - - QGeometryData data; - data.appendVertex(a, b, c, d); - data.appendNormal(an, bn, cn, dn); - - QGeometryData reversed = data.reversed(); - - QCOMPARE(data.vertexAt(0), reversed.vertexAt(3)); - QCOMPARE(data.vertexAt(1), reversed.vertexAt(2)); - QCOMPARE(data.vertexAt(2), reversed.vertexAt(1)); - QCOMPARE(data.vertexAt(3), reversed.vertexAt(0)); - QCOMPARE(data.normalAt(0), reversed.normalAt(3)); - QCOMPARE(data.normalAt(1), reversed.normalAt(2)); - QCOMPARE(data.normalAt(2), reversed.normalAt(1)); - QCOMPARE(data.normalAt(3), reversed.normalAt(0)); -} - -void tst_QGeometryData::translated() -{ - QVector3D a(1.1, 1.2, 1.3); - QVector3D b(2.1, 2.2, 2.3); - QVector3D c(3.1, 3.2, 3.3); - QVector3D d(4.1, 4.2, 4.3); - QVector3D an(5.1, 5.2, 5.3); - QVector3D bn(6.1, 6.2, 6.3); - QVector3D cn(7.1, 7.2, 7.3); - QVector3D dn(8.1, 8.2, 8.3); - - QGeometryData data; - data.appendVertex(a, b, c, d); - data.appendNormal(an, bn, cn, dn); - - QVector3D t(0.5, -0.5, -0.5); - QGeometryData translated = data.translated(t); - - QVector3D at = a + t; - QVector3D bt = b + t; - QVector3D ct = c + t; - QVector3D dt = d + t; - - QCOMPARE(at, translated.vertexAt(0)); - QCOMPARE(bt, translated.vertexAt(1)); - QCOMPARE(ct, translated.vertexAt(2)); - QCOMPARE(dt, translated.vertexAt(3)); - QCOMPARE(an, translated.normalAt(0)); - QCOMPARE(bn, translated.normalAt(1)); - QCOMPARE(cn, translated.normalAt(2)); - QCOMPARE(dn, translated.normalAt(3)); -} - -void tst_QGeometryData::generateTextureCoordinates() -{ - QGeometryData top; - - top.appendVertex(QVector3D(0.0, 0.0, 0.0)); - top.appendVertex(QVector3D(6.0, 3.6, 0.0)); // (v1 - v0).length() = 7.0 - top.appendVertex(QVector3D(10.0, 0.6, 0.0)); // (v2 - v1).length() = 5.0 - top.appendVertex(QVector3D(13.0, 3.24, 0.0)); // (v3 - v2).length() = 4.0 - - // generate x (Qt::Horizontal) texture coordinates - top.generateTextureCoordinates(); // spread over 7 + 5 + 4 = 16 - - QVERIFY(qFskCompare(top.texCoordAt(0), QVector2D())); - QVERIFY(qFskCompare(top.texCoordAt(1), QVector2D(0.43750349, 0.0))); - QVERIFY(qFskCompare(top.texCoordAt(2), QVector2D(0.75013363, 0.0))); - QVERIFY(qFskCompare(top.texCoordAt(3), QVector2D(1.0, 0.0))); - - QGeometryData side; - - side.appendVertex(QVector3D(0.0, 0.0, 0.0)); - side.appendVertex(QVector3D(3.6, 6.0, 0.0)); // (v1 - v0).length() = 7.0 - side.appendVertex(QVector3D(0.6, 10.0, 0.0)); // (v2 - v1).length() = 5.0 - side.appendVertex(QVector3D(3.24, 13.0, 0.0)); // (v3 - v2).length() = 4.0 - - // generate x (Qt::Vertical) texture coordinates - side.generateTextureCoordinates(Qt::Vertical); // spread over 7 + 5 + 4 = 16 - - QVERIFY(qFskCompare(side.texCoordAt(0), QVector2D())); - QVERIFY(qFskCompare(side.texCoordAt(1), QVector2D(0.0, 0.43750349))); - QVERIFY(qFskCompare(side.texCoordAt(2), QVector2D(0.0, 0.75013363))); - QVERIFY(qFskCompare(side.texCoordAt(3), QVector2D(0.0, 1.0))); -} - -void tst_QGeometryData::clear() -{ - QVector3D a(1.1, 1.2, 1.3); - QVector3D b(2.1, 2.2, 2.3); - QVector3D c(3.1, 3.2, 3.3); - QVector3D d(4.1, 4.2, 4.3); - QVector3D an(5.1, 5.2, 5.3); - QVector3D bn(6.1, 6.2, 6.3); - QVector3D cn(7.1, 7.2, 7.3); - QVector3D dn(8.1, 8.2, 8.3); - - QGeometryData data; - data.appendVertex(a, b, c, d); - data.appendNormal(an, bn, cn, dn); - - quint32 f = data.fields(); - quint32 expectedFields = QGL::fieldMask(QGL::Normal) | QGL::fieldMask(QGL::Position); - QCOMPARE(f, expectedFields); - QCOMPARE(data.count(), 4); - QCOMPARE(data.count(QGL::Normal), 4); - QCOMPARE(data.count(QGL::Position), 4); - - data.clear(); - QCOMPARE(f, expectedFields); - QCOMPARE(data.count(), 0); - QCOMPARE(data.count(QGL::Normal), 0); - QCOMPARE(data.count(QGL::Position), 0); - - data.appendVertex(a, b, c, d); - data.appendNormal(an, bn, cn, dn); - - data.clear(QGL::Normal); - - f = data.fields(); - expectedFields = QGL::fieldMask(QGL::Position); - QCOMPARE(f, expectedFields); - QCOMPARE(data.count(), 4); - QCOMPARE(data.count(QGL::Normal), 0); - QCOMPARE(data.count(QGL::Position), 4); -} - -void tst_QGeometryData::draw() -{ - QVector3D a(1.1, 1.2, 1.3); - QVector3D b(2.1, 2.2, 2.3); - QVector3D c(3.1, 3.2, 3.3); - QVector3D d(4.1, 4.2, 4.3); - QVector3D an(5.1, 5.2, 5.3); - QVector3D bn(6.1, 6.2, 6.3); - QVector3D cn(7.1, 7.2, 7.3); - QVector3D dn(8.1, 8.2, 8.3); - - QGeometryData data; - data.appendVertex(a, b, c, d); - data.appendNormal(an, bn, cn, dn); - - QGLWidget w; - QGLPainter p(&w); - data.draw(&p, 0, 4); -} - - -QTEST_MAIN(tst_QGeometryData) - -#include "tst_qgeometrydata.moc" diff --git a/tests/auto/threed/qglabstractsurface/qglabstractsurface.pro b/tests/auto/threed/qglabstractsurface/qglabstractsurface.pro deleted file mode 100644 index 8cd363ea..00000000 --- a/tests/auto/threed/qglabstractsurface/qglabstractsurface.pro +++ /dev/null @@ -1,6 +0,0 @@ -load(qttest_p4.prf) -TEMPLATE=app -QT += testlib -CONFIG += unittest warn_on qt3d - -SOURCES += tst_qglabstractsurface.cpp diff --git a/tests/auto/threed/qglabstractsurface/tst_qglabstractsurface.cpp b/tests/auto/threed/qglabstractsurface/tst_qglabstractsurface.cpp deleted file mode 100644 index 66a6dafc..00000000 --- a/tests/auto/threed/qglabstractsurface/tst_qglabstractsurface.cpp +++ /dev/null @@ -1,333 +0,0 @@ -/**************************************************************************** -** -** 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 QtQuick3D module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** 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. -** -** 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. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include <QtTest/QtTest> -#include "qglabstractsurface.h" -#include "qglwidgetsurface.h" -#include "qglframebufferobjectsurface.h" -#include "qglpixelbuffersurface.h" -#include "qglsubsurface.h" -#include "qopenglfunctions.h" - -class tst_QGLAbstractSurface : public QObject -{ - Q_OBJECT -public: - tst_QGLAbstractSurface() {} - ~tst_QGLAbstractSurface() {} - -private slots: - void glWidgetSurface(); - void fboSurface(); - void pbufferSurface(); - void subSurface(); - -private: - bool isFboCurrent(QGLFramebufferObject *fbo); -}; - -bool tst_QGLAbstractSurface::isFboCurrent(QGLFramebufferObject *fbo) -{ - GLint currentFbo = -1; - glGetIntegerv(GL_FRAMEBUFFER_BINDING, ¤tFbo); - if (currentFbo == -1) - return true; // XXX: Mesa 7.0.3 bug? - if (fbo) - return fbo->handle() == GLuint(currentFbo); - else - return currentFbo == 0; -} - -void tst_QGLAbstractSurface::glWidgetSurface() -{ - QGLWidget glw; - if (!glw.isValid()) - QSKIP("GL Implementation not valid", SkipSingle); - - - QGLWidgetSurface surface1; - QVERIFY(surface1.surfaceType() == QGLAbstractSurface::Widget); - QVERIFY(surface1.widget() == 0); - surface1.setWidget(&glw); - QVERIFY(surface1.widget() == &glw); - QVERIFY(surface1.device() == &glw); - QCOMPARE(surface1.viewportRect(), glw.rect()); - - QVERIFY(surface1.activate()); - QVERIFY(QGLContext::currentContext() == glw.context()); - QCOMPARE(surface1.viewportGL(), QRect(0, 0, glw.width(), glw.height())); - - surface1.deactivate(); - QVERIFY(QGLContext::currentContext() == glw.context()); // Left current. - - QGLWidget glw2; - - QGLWidgetSurface surface2(&glw2); - QVERIFY(surface2.surfaceType() == QGLAbstractSurface::Widget); - QVERIFY(surface2.widget() == &glw2); - QVERIFY(surface2.device() == &glw2); - - QVERIFY(surface1.activate()); - QVERIFY(surface1.switchTo(&surface2)); - - QVERIFY(QGLContext::currentContext() == glw2.context()); - - QVERIFY(surface2.switchTo(&surface1)); - QVERIFY(QGLContext::currentContext() == glw.context()); -} - -void tst_QGLAbstractSurface::fboSurface() -{ - if (!QGLFramebufferObject::hasOpenGLFramebufferObjects()) - QSKIP("fbo's are not supported", SkipSingle); - - QGLWidget glw; - if (!glw.isValid()) - QSKIP("GL Implementation not valid", SkipSingle); - - QGLWidgetSurface surface1(&glw); - QVERIFY(surface1.activate()); - QCOMPARE(surface1.viewportGL(), QRect(0, 0, glw.width(), glw.height())); - - QGLFramebufferObject fbo1(128, 128); - QVERIFY(fbo1.handle() != 0); - - QGLFramebufferObjectSurface surface2(&fbo1); - QVERIFY(surface2.surfaceType() == QGLAbstractSurface::FramebufferObject); - QVERIFY(surface2.framebufferObject() == &fbo1); - QVERIFY(surface2.device() == &fbo1); - - QVERIFY(isFboCurrent(0)); - - QVERIFY(surface2.activate()); - QVERIFY(QGLContext::currentContext() == glw.context()); - QVERIFY(isFboCurrent(&fbo1)); - QCOMPARE(surface2.viewportGL(), QRect(QPoint(0, 0), fbo1.size())); - - surface2.deactivate(); - QVERIFY(isFboCurrent(0)); - QVERIFY(QGLContext::currentContext() == glw.context()); - - surface2.setContext(glw.context()); - - QGLWidget glw2; - QGLWidgetSurface surface3(&glw2); - QVERIFY(surface3.activate()); - QVERIFY(QGLContext::currentContext() == glw2.context()); - QCOMPARE(surface3.viewportGL(), QRect(0, 0, glw2.width(), glw2.height())); - - QVERIFY(surface3.switchTo(&surface2)); - QVERIFY(isFboCurrent(&fbo1)); - QVERIFY(QGLContext::currentContext() == glw.context()); - QCOMPARE(surface2.viewportGL(), QRect(QPoint(0, 0), fbo1.size())); - - QVERIFY(surface2.switchTo(&surface3)); - QVERIFY(isFboCurrent(0)); - QVERIFY(QGLContext::currentContext() == glw2.context()); - QCOMPARE(surface3.viewportGL(), QRect(0, 0, glw2.width(), glw2.height())); - - surface3.deactivate(); - - surface1.activate(); - QCOMPARE(surface1.viewportGL(), QRect(0, 0, glw.width(), glw.height())); - - QGLFramebufferObject fbo2(256, 256); - QVERIFY(fbo2.handle() != 0); - - QGLFramebufferObjectSurface surface4; - QVERIFY(surface4.surfaceType() == QGLAbstractSurface::FramebufferObject); - QVERIFY(surface4.framebufferObject() == 0); - QVERIFY(surface4.device() == 0); - QVERIFY(!surface4.activate(0)); - QVERIFY(surface4.viewportGL().isNull()); - surface4.setFramebufferObject(&fbo2); - QVERIFY(surface4.framebufferObject() == &fbo2); - QVERIFY(surface4.device() == &fbo2); - surface4.setContext(glw.context()); - - QVERIFY(surface1.switchTo(&surface2)); - QVERIFY(QGLContext::currentContext() == glw.context()); - QVERIFY(isFboCurrent(&fbo1)); - QCOMPARE(surface2.viewportGL(), QRect(QPoint(0, 0), fbo1.size())); - - QVERIFY(surface2.switchTo(&surface4)); - QVERIFY(QGLContext::currentContext() == glw.context()); - QVERIFY(isFboCurrent(&fbo2)); - QCOMPARE(surface4.viewportGL(), QRect(QPoint(0, 0), fbo2.size())); - - QVERIFY(surface3.switchTo(&surface2)); - QVERIFY(QGLContext::currentContext() == glw.context()); - QVERIFY(isFboCurrent(&fbo1)); - QCOMPARE(surface2.viewportGL(), QRect(QPoint(0, 0), fbo1.size())); - - QVERIFY(surface2.switchTo(&surface1)); - QVERIFY(QGLContext::currentContext() == glw.context()); - QVERIFY(isFboCurrent(0)); - QCOMPARE(surface1.viewportGL(), QRect(0, 0, glw.width(), glw.height())); -} - -void tst_QGLAbstractSurface::pbufferSurface() -{ - if (!QGLPixelBuffer::hasOpenGLPbuffers()) - QSKIP("pbuffer's are not supported", SkipSingle); - - QGLWidget glw; - if (!glw.isValid()) - QSKIP("GL Implementation not valid", SkipSingle); - - QGLWidgetSurface surface1(&glw); - QVERIFY(surface1.activate()); - QCOMPARE(surface1.viewportGL(), QRect(0, 0, glw.width(), glw.height())); - - QGLPixelBuffer pbuffer1(128, 128); - QVERIFY(pbuffer1.handle() != 0); - - QGLPixelBufferSurface surface2(&pbuffer1); - QVERIFY(surface2.surfaceType() == QGLAbstractSurface::PixelBuffer); - QVERIFY(surface2.pixelBuffer() == &pbuffer1); - QVERIFY(surface2.device() == &pbuffer1); - - QVERIFY(surface2.activate()); - QVERIFY(QGLContext::currentContext() != glw.context()); - const QGLContext *surface2ctx = QGLContext::currentContext(); - QCOMPARE(surface2.viewportGL(), QRect(QPoint(0, 0), pbuffer1.size())); - - surface2.deactivate(); - QVERIFY(QGLContext::currentContext() == surface2ctx); // Left current. - - QGLWidget glw2; - QGLWidgetSurface surface3(&glw2); - QVERIFY(surface3.activate()); - QVERIFY(QGLContext::currentContext() == glw2.context()); - QCOMPARE(surface3.viewportGL(), QRect(0, 0, glw2.width(), glw2.height())); - - QVERIFY(surface3.switchTo(&surface2)); - QVERIFY(QGLContext::currentContext() == surface2ctx); - QCOMPARE(surface2.viewportGL(), QRect(QPoint(0, 0), pbuffer1.size())); - - QVERIFY(surface2.switchTo(&surface3)); - QVERIFY(QGLContext::currentContext() == glw2.context()); - QCOMPARE(surface3.viewportGL(), QRect(0, 0, glw2.width(), glw2.height())); - - surface3.deactivate(); - - surface1.activate(); - QCOMPARE(surface1.viewportGL(), QRect(0, 0, glw.width(), glw.height())); - - QGLPixelBuffer pbuffer2(256, 256); - QVERIFY(pbuffer2.handle() != 0); - - QGLPixelBufferSurface surface4; - QVERIFY(surface4.surfaceType() == QGLAbstractSurface::PixelBuffer); - QVERIFY(surface4.pixelBuffer() == 0); - QVERIFY(surface4.device() == 0); - QVERIFY(!surface4.activate(0)); - QVERIFY(surface4.viewportGL().isNull()); - surface4.setPixelBuffer(&pbuffer2); - QVERIFY(surface4.pixelBuffer() == &pbuffer2); - QVERIFY(surface4.device() == &pbuffer2); - - QVERIFY(surface1.switchTo(&surface2)); - QVERIFY(QGLContext::currentContext() == surface2ctx); - QCOMPARE(surface2.viewportGL(), QRect(QPoint(0, 0), pbuffer1.size())); - - QVERIFY(surface2.switchTo(&surface4)); - const QGLContext *surface4ctx = QGLContext::currentContext(); - QVERIFY(surface4ctx != glw.context()); - QVERIFY(surface4ctx != surface2ctx); - QCOMPARE(surface4.viewportGL(), QRect(QPoint(0, 0), pbuffer2.size())); - - QVERIFY(surface4.switchTo(&surface2)); - QVERIFY(QGLContext::currentContext() == surface2ctx); - QCOMPARE(surface2.viewportGL(), QRect(QPoint(0, 0), pbuffer1.size())); - - QVERIFY(surface2.switchTo(&surface1)); - QVERIFY(QGLContext::currentContext() == glw.context()); - QCOMPARE(surface1.viewportGL(), QRect(0, 0, glw.width(), glw.height())); -} - -void tst_QGLAbstractSurface::subSurface() -{ - QGLWidget glw; - if (!glw.isValid()) - QSKIP("GL Implementation not valid", SkipSingle); - - QGLWidgetSurface surface1(&glw); - - QGLSubsurface surface2(&surface1, QRect(0, 0, 32, 16)); - QVERIFY(surface2.surfaceType() == QGLAbstractSurface::Subsurface); - QVERIFY(surface2.surface() == &surface1); - QVERIFY(surface2.device() == &glw); - QCOMPARE(surface2.region(), QRect(0, 0, 32, 16)); - - QVERIFY(surface2.activate()); - QVERIFY(QGLContext::currentContext() == glw.context()); - QCOMPARE(surface2.viewportGL(), QRect(0, glw.height() - 16, 32, 16)); - - QGLSubsurface surface3(&surface1, QRect(16, 8, 32, 16)); - QVERIFY(surface3.surfaceType() == QGLAbstractSurface::Subsurface); - QVERIFY(surface3.surface() == &surface1); - QCOMPARE(surface3.region(), QRect(16, 8, 32, 16)); - - QVERIFY(surface2.switchTo(&surface3)); - QVERIFY(QGLContext::currentContext() == glw.context()); - QCOMPARE(surface3.viewportGL(), QRect(16, glw.height() - (8 + 16), 32, 16)); - - QGLSubsurface surface4; - QVERIFY(surface4.surfaceType() == QGLAbstractSurface::Subsurface); - QVERIFY(surface4.surface() == 0); - QVERIFY(surface4.device() == 0); - QVERIFY(surface4.region().isNull()); - QVERIFY(!surface4.activate(0)); - surface4.setRegion(QRect(4, 6, 12, 8)); - QCOMPARE(surface4.viewportGL(), QRect(4, 0, 12, 8)); - surface4.setSurface(&surface3); - QVERIFY(surface4.surface() == &surface3); - QCOMPARE(surface4.region(), QRect(4, 6, 12, 8)); - - QVERIFY(surface2.switchTo(&surface4)); - QVERIFY(QGLContext::currentContext() == glw.context()); - QCOMPARE(surface4.viewportGL(), QRect(16 + 4, glw.height() - (6 + 8 + 8), 12, 8)); -} - -QTEST_MAIN(tst_QGLAbstractSurface) - -#include "tst_qglabstractsurface.moc" diff --git a/tests/auto/threed/qglattributedescription/qglattributedescription.pro b/tests/auto/threed/qglattributedescription/qglattributedescription.pro deleted file mode 100644 index 92cb86f3..00000000 --- a/tests/auto/threed/qglattributedescription/qglattributedescription.pro +++ /dev/null @@ -1,9 +0,0 @@ -load(qttest_p4.prf) -TEMPLATE=app -QT += testlib -CONFIG += unittest warn_on qt3d - -INCLUDEPATH += ../../../../threed/viewing -VPATH += ../../../../threed/viewing - -SOURCES += tst_qglattributedescription.cpp diff --git a/tests/auto/threed/qglattributedescription/tst_qglattributedescription.cpp b/tests/auto/threed/qglattributedescription/tst_qglattributedescription.cpp deleted file mode 100644 index b8c92e26..00000000 --- a/tests/auto/threed/qglattributedescription/tst_qglattributedescription.cpp +++ /dev/null @@ -1,137 +0,0 @@ -/**************************************************************************** -** -** 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 QtQuick3D module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** 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. -** -** 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. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include <QtTest/QtTest> -#include "qglattributedescription.h" -#include "qopenglfunctions.h" - -class tst_QGLAttributeDescription : public QObject -{ - Q_OBJECT -public: - tst_QGLAttributeDescription() {} - ~tst_QGLAttributeDescription() {} - -private slots: - void defaultValue(); - void explicitValue(); - void modifyValue(); - void typeSizes(); -}; - -void tst_QGLAttributeDescription::defaultValue() -{ - QGLAttributeDescription desc; - QVERIFY(desc.isNull()); - QVERIFY(desc.attribute() == QGL::Position); - QVERIFY(desc.type() == GL_FLOAT); - QCOMPARE(desc.sizeOfType(), int(sizeof(GLfloat))); - QCOMPARE(desc.tupleSize(), 0); - QCOMPARE(desc.stride(), 0); -} - -void tst_QGLAttributeDescription::explicitValue() -{ - QGLAttributeDescription desc(QGL::Color, 4, GL_UNSIGNED_BYTE, 20); - QVERIFY(!desc.isNull()); - QVERIFY(desc.attribute() == QGL::Color); - QVERIFY(desc.type() == GL_UNSIGNED_BYTE); - QCOMPARE(desc.sizeOfType(), int(sizeof(GLubyte))); - QCOMPARE(desc.tupleSize(), 4); - QCOMPARE(desc.stride(), 20); -} - -void tst_QGLAttributeDescription::modifyValue() -{ - QGLAttributeDescription desc; - desc.setAttribute(QGL::Color); - desc.setType(GL_UNSIGNED_BYTE); - desc.setTupleSize(4); - desc.setStride(20); - QVERIFY(!desc.isNull()); - QVERIFY(desc.attribute() == QGL::Color); - QVERIFY(desc.type() == GL_UNSIGNED_BYTE); - QCOMPARE(desc.sizeOfType(), int(sizeof(GLubyte))); - QCOMPARE(desc.tupleSize(), 4); - QCOMPARE(desc.stride(), 20); -} - -void tst_QGLAttributeDescription::typeSizes() -{ - QGLAttributeDescription desc; - - desc.setType(GL_BYTE); - QCOMPARE(desc.sizeOfType(), int(sizeof(GLbyte))); - - desc.setType(GL_UNSIGNED_BYTE); - QCOMPARE(desc.sizeOfType(), int(sizeof(GLubyte))); - - desc.setType(GL_SHORT); - QCOMPARE(desc.sizeOfType(), int(sizeof(GLshort))); - - desc.setType(GL_UNSIGNED_SHORT); - QCOMPARE(desc.sizeOfType(), int(sizeof(GLushort))); - - desc.setType(GL_INT); - QCOMPARE(desc.sizeOfType(), int(sizeof(GLint))); - - desc.setType(GL_UNSIGNED_INT); - QCOMPARE(desc.sizeOfType(), int(sizeof(GLuint))); - - desc.setType(GL_FLOAT); - QCOMPARE(desc.sizeOfType(), int(sizeof(GLfloat))); - -#if defined(GL_DOUBLE) && !defined(QT_OPENGL_ES) - desc.setType(GL_DOUBLE); - QCOMPARE(desc.sizeOfType(), int(sizeof(GLdouble))); -#endif - - desc.setType(GL_TEXTURE0); // Something that isn't a GL type. - QCOMPARE(desc.sizeOfType(), 0); - - QVERIFY(desc.isNull()); - desc.setTupleSize(3); - QVERIFY(!desc.isNull()); -} - -QTEST_APPLESS_MAIN(tst_QGLAttributeDescription) - -#include "tst_qglattributedescription.moc" diff --git a/tests/auto/threed/qglattributeset/qglattributeset.pro b/tests/auto/threed/qglattributeset/qglattributeset.pro deleted file mode 100644 index 64b4619c..00000000 --- a/tests/auto/threed/qglattributeset/qglattributeset.pro +++ /dev/null @@ -1,6 +0,0 @@ -load(qttest_p4.prf) -TEMPLATE=app -QT += testlib -CONFIG += unittest warn_on qt3d - -SOURCES += tst_qglattributeset.cpp diff --git a/tests/auto/threed/qglattributeset/tst_qglattributeset.cpp b/tests/auto/threed/qglattributeset/tst_qglattributeset.cpp deleted file mode 100644 index 77cfb1fc..00000000 --- a/tests/auto/threed/qglattributeset/tst_qglattributeset.cpp +++ /dev/null @@ -1,211 +0,0 @@ -/**************************************************************************** -** -** 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 QtQuick3D module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** 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. -** -** 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. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include <QtTest/QtTest> -#include "qglattributeset.h" - -class tst_QGLAttributeSet : public QObject -{ - Q_OBJECT -public: - tst_QGLAttributeSet() {} - ~tst_QGLAttributeSet() {} - -private slots: - void defaultValue(); - void clear(); - void insert(); - void remove(); - void list(); - void compare(); - void unite(); - void intersect(); - void subtract(); -}; - -void tst_QGLAttributeSet::defaultValue() -{ - QGLAttributeSet set; - QVERIFY(set.isEmpty()); - for (int index = -50; index <= 50; ++index) - QVERIFY(!set.contains(QGL::VertexAttribute(index))); -} - -void tst_QGLAttributeSet::clear() -{ - QGLAttributeSet set; - set.insert(QGL::TextureCoord0); - QVERIFY(!set.isEmpty()); - QVERIFY(set.contains(QGL::TextureCoord0)); - set.clear(); - QVERIFY(set.isEmpty()); - QVERIFY(!set.contains(QGL::TextureCoord0)); -} - -void tst_QGLAttributeSet::insert() -{ - for (int index = -50; index <= 50; ++index) { - QGLAttributeSet set; - set.insert(QGL::VertexAttribute(index)); - if (index < 0 || index > 31) - QVERIFY(!set.contains(QGL::VertexAttribute(index))); - else - QVERIFY(set.contains(QGL::VertexAttribute(index))); - for (int index2 = -50; index2 <= 50; ++index2) { - if (index2 != index) - QVERIFY(!set.contains(QGL::VertexAttribute(index2))); - } - } -} - -void tst_QGLAttributeSet::remove() -{ - for (int index = -50; index <= 50; ++index) { - QGLAttributeSet set; - for (int index2 = 0; index2 < 32; ++index2) - set.insert(QGL::VertexAttribute(index2)); - set.remove(QGL::VertexAttribute(index)); - for (int index2 = 0; index2 < 32; ++index2) { - if (index == index2) - QVERIFY(!set.contains(QGL::VertexAttribute(index2))); - else - QVERIFY(set.contains(QGL::VertexAttribute(index2))); - } - } -} - -void tst_QGLAttributeSet::list() -{ - QList<QGL::VertexAttribute> list; - QVERIFY(QGLAttributeSet::fromList(list).isEmpty()); - - list.append(QGL::VertexAttribute(-50)); - list.append(QGL::TextureCoord1); - list.append(QGL::VertexAttribute(50)); - - QGLAttributeSet set1 = QGLAttributeSet::fromList(list); - QGLAttributeSet set2; - set2.insert(QGL::TextureCoord1); - QVERIFY(set1 == set2); - - QList<QGL::VertexAttribute> list2 = set1.toList(); - QCOMPARE(list2.count(), 1); - QVERIFY(list2[0] == QGL::TextureCoord1); -} - -void tst_QGLAttributeSet::compare() -{ - QGLAttributeSet set1; - QGLAttributeSet set2; - - QVERIFY(set1 == set2); - QVERIFY(!(set1 != set2)); - - set1.insert(QGL::Position); - QVERIFY(set1 != set2); - QVERIFY(!(set1 == set2)); - - set2.insert(QGL::Position); - QVERIFY(set1 == set2); - QVERIFY(!(set1 != set2)); - - set2.insert(QGL::TextureCoord0); - QVERIFY(set1 != set2); - QVERIFY(!(set1 == set2)); -} - -void tst_QGLAttributeSet::unite() -{ - QGLAttributeSet set1; - QGLAttributeSet set2; - - set1.insert(QGL::Position); - set1.insert(QGL::Color); - - set2.insert(QGL::Position); - set2.insert(QGL::TextureCoord0); - - set1.unite(set2); - QVERIFY(set1.contains(QGL::Position)); - QVERIFY(set1.contains(QGL::Color)); - QVERIFY(set1.contains(QGL::TextureCoord0)); - QVERIFY(!set1.contains(QGL::Normal)); -} - -void tst_QGLAttributeSet::intersect() -{ - QGLAttributeSet set1; - QGLAttributeSet set2; - - set1.insert(QGL::Position); - set1.insert(QGL::Color); - - set2.insert(QGL::Position); - set2.insert(QGL::TextureCoord0); - - set1.intersect(set2); - QVERIFY(set1.contains(QGL::Position)); - QVERIFY(!set1.contains(QGL::Color)); - QVERIFY(!set1.contains(QGL::TextureCoord0)); - QVERIFY(!set1.contains(QGL::Normal)); -} - -void tst_QGLAttributeSet::subtract() -{ - QGLAttributeSet set1; - QGLAttributeSet set2; - - set1.insert(QGL::Position); - set1.insert(QGL::Color); - - set2.insert(QGL::Position); - set2.insert(QGL::TextureCoord0); - - set1.subtract(set2); - QVERIFY(!set1.contains(QGL::Position)); - QVERIFY(set1.contains(QGL::Color)); - QVERIFY(!set1.contains(QGL::TextureCoord0)); - QVERIFY(!set1.contains(QGL::Normal)); -} - -QTEST_APPLESS_MAIN(tst_QGLAttributeSet) - -#include "tst_qglattributeset.moc" diff --git a/tests/auto/threed/qglattributevalue/qglattributevalue.pro b/tests/auto/threed/qglattributevalue/qglattributevalue.pro deleted file mode 100644 index d8e98255..00000000 --- a/tests/auto/threed/qglattributevalue/qglattributevalue.pro +++ /dev/null @@ -1,9 +0,0 @@ -load(qttest_p4.prf) -TEMPLATE=app -QT += testlib -CONFIG += unittest warn_on qt3d - -INCLUDEPATH += ../../../../threed/viewing -VPATH += ../../../../threed/viewing - -SOURCES += tst_qglattributevalue.cpp diff --git a/tests/auto/threed/qglattributevalue/tst_qglattributevalue.cpp b/tests/auto/threed/qglattributevalue/tst_qglattributevalue.cpp deleted file mode 100644 index 69988b48..00000000 --- a/tests/auto/threed/qglattributevalue/tst_qglattributevalue.cpp +++ /dev/null @@ -1,262 +0,0 @@ -/**************************************************************************** -** -** 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 QtQuick3D module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** 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. -** -** 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. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include <QtTest/QtTest> -#include "qglattributevalue.h" -#include "qopenglfunctions.h" - -class tst_QGLAttributeValue : public QObject -{ - Q_OBJECT -public: - tst_QGLAttributeValue() {} - ~tst_QGLAttributeValue() {} - -private slots: - void defaultValue(); - void explicitValue(); - void fromArray(); - void typeSizes_data(); - void typeSizes(); -}; - -void tst_QGLAttributeValue::defaultValue() -{ - QGLAttributeValue value; - QVERIFY(value.isNull()); - QVERIFY(value.description(QGL::Normal).isNull()); - QVERIFY(value.description(QGL::Normal).attribute() == QGL::Normal); - QVERIFY(value.type() == GL_FLOAT); - QCOMPARE(value.sizeOfType(), int(sizeof(GLfloat))); - QCOMPARE(value.tupleSize(), 0); - QCOMPARE(value.stride(), 0); - QVERIFY(value.data() == 0); - QCOMPARE(value.count(), 0); -} - -void tst_QGLAttributeValue::explicitValue() -{ - unsigned char data[4] = {1, 2, 3, 4}; - QGLAttributeValue value(4, GL_UNSIGNED_BYTE, 20, data, 1); - QVERIFY(!value.isNull()); - QVERIFY(value.type() == GL_UNSIGNED_BYTE); - QCOMPARE(value.sizeOfType(), int(sizeof(GLubyte))); - QCOMPARE(value.tupleSize(), 4); - QCOMPARE(value.stride(), 20); - QVERIFY(value.data() == data); - QCOMPARE(value.count(), 1); - QVERIFY(!value.description(QGL::Color).isNull()); - QVERIFY(value.description(QGL::Color).attribute() == QGL::Color); - - QGLAttributeValue value2(4, GL_UNSIGNED_BYTE, 20, 23, 1); - QVERIFY(!value2.isNull()); - QVERIFY(value2.type() == GL_UNSIGNED_BYTE); - QCOMPARE(value2.sizeOfType(), int(sizeof(GLubyte))); - QCOMPARE(value2.tupleSize(), 4); - QCOMPARE(value2.stride(), 20); - QVERIFY(value2.data() == reinterpret_cast<const void *>(23)); - QCOMPARE(value2.count(), 1); - - QGLAttributeDescription desc(QGL::Color, 4, GL_UNSIGNED_BYTE, 20); - QGLAttributeValue value3(desc, data, 1); - QVERIFY(!value3.isNull()); - QVERIFY(value3.type() == GL_UNSIGNED_BYTE); - QCOMPARE(value3.sizeOfType(), int(sizeof(GLubyte))); - QCOMPARE(value3.tupleSize(), 4); - QCOMPARE(value3.stride(), 20); - QVERIFY(value3.data() == data); - QCOMPARE(value3.count(), 1); - - QGLAttributeValue value4(desc, 23, 1); - QVERIFY(!value4.isNull()); - QVERIFY(value4.type() == GL_UNSIGNED_BYTE); - QCOMPARE(value4.sizeOfType(), int(sizeof(GLubyte))); - QCOMPARE(value4.tupleSize(), 4); - QCOMPARE(value4.stride(), 20); - QVERIFY(value4.data() == reinterpret_cast<const void *>(23)); - QCOMPARE(value4.count(), 1); -} - -void tst_QGLAttributeValue::fromArray() -{ - QArray<float> floatArray; - floatArray += 1.0f; - floatArray += 2.0f; - floatArray += 3.0f; - floatArray += 4.0f; - QGLAttributeValue valueFloat(floatArray); - QVERIFY(!valueFloat.isNull()); - QVERIFY(valueFloat.type() == GL_FLOAT); - QCOMPARE(valueFloat.sizeOfType(), int(sizeof(GLfloat))); - QCOMPARE(valueFloat.tupleSize(), 1); - QCOMPARE(valueFloat.stride(), 0); - QVERIFY(valueFloat.data() == floatArray.constData()); - QCOMPARE(valueFloat.count(), floatArray.count()); - - QCustomDataArray floatCustomArray(floatArray); - QGLAttributeValue valueFloatCustom(floatCustomArray); - QVERIFY(!valueFloatCustom.isNull()); - QVERIFY(valueFloatCustom.type() == GL_FLOAT); - QCOMPARE(valueFloatCustom.sizeOfType(), int(sizeof(GLfloat))); - QCOMPARE(valueFloatCustom.tupleSize(), 1); - QCOMPARE(valueFloatCustom.stride(), 0); - QVERIFY(valueFloatCustom.data() == floatCustomArray.data()); - QCOMPARE(valueFloatCustom.count(), floatCustomArray.count()); - - QArray<QVector2D> vec2Array; - vec2Array += QVector2D(1.0f, 2.0f); - vec2Array += QVector2D(2.0f, 3.0f); - QGLAttributeValue valueVec2(vec2Array); - QVERIFY(!valueVec2.isNull()); - QVERIFY(valueVec2.type() == GL_FLOAT); - QCOMPARE(valueVec2.sizeOfType(), int(sizeof(GLfloat))); - QCOMPARE(valueVec2.tupleSize(), 2); - QCOMPARE(valueVec2.stride(), 0); - QVERIFY(valueVec2.data() == vec2Array.constData()); - QCOMPARE(valueVec2.count(), vec2Array.count()); - - QCustomDataArray vec2CustomArray(vec2Array); - QGLAttributeValue valueVec2Custom(vec2CustomArray); - QVERIFY(!valueVec2Custom.isNull()); - QVERIFY(valueVec2Custom.type() == GL_FLOAT); - QCOMPARE(valueVec2Custom.sizeOfType(), int(sizeof(GLfloat))); - QCOMPARE(valueVec2Custom.tupleSize(), 2); - QCOMPARE(valueVec2Custom.stride(), 0); - QVERIFY(valueVec2Custom.data() == vec2CustomArray.data()); - QCOMPARE(valueVec2Custom.count(), vec2CustomArray.count()); - - QArray<QVector3D> vec3Array; - vec3Array += QVector3D(1.0f, 2.0f, 3.0f); - vec3Array += QVector3D(2.0f, 3.0f, 4.0f); - QGLAttributeValue valueVec3(vec3Array); - QVERIFY(!valueVec3.isNull()); - QVERIFY(valueVec3.type() == GL_FLOAT); - QCOMPARE(valueVec3.sizeOfType(), int(sizeof(GLfloat))); - QCOMPARE(valueVec3.tupleSize(), 3); - QCOMPARE(valueVec3.stride(), 0); - QVERIFY(valueVec3.data() == vec3Array.constData()); - QCOMPARE(valueVec3.count(), vec3Array.count()); - - QCustomDataArray vec3CustomArray(vec3Array); - QGLAttributeValue valueVec3Custom(vec3CustomArray); - QVERIFY(!valueVec3Custom.isNull()); - QVERIFY(valueVec3Custom.type() == GL_FLOAT); - QCOMPARE(valueVec3Custom.sizeOfType(), int(sizeof(GLfloat))); - QCOMPARE(valueVec3Custom.tupleSize(), 3); - QCOMPARE(valueVec3Custom.stride(), 0); - QVERIFY(valueVec3Custom.data() == vec3CustomArray.data()); - QCOMPARE(valueVec3Custom.count(), vec3CustomArray.count()); - - QArray<QVector4D> vec4Array; - vec4Array += QVector4D(1.0f, 2.0f, 3.0f, 4.0f); - vec4Array += QVector4D(2.0f, 3.0f, 4.0f, 5.0f); - QGLAttributeValue valueVec4(vec4Array); - QVERIFY(!valueVec4.isNull()); - QVERIFY(valueVec4.type() == GL_FLOAT); - QCOMPARE(valueVec4.sizeOfType(), int(sizeof(GLfloat))); - QCOMPARE(valueVec4.tupleSize(), 4); - QCOMPARE(valueVec4.stride(), 0); - QVERIFY(valueVec4.data() == vec4Array.constData()); - QCOMPARE(valueVec4.count(), vec4Array.count()); - - QCustomDataArray vec4CustomArray(vec4Array); - QGLAttributeValue valueVec4Custom(vec4CustomArray); - QVERIFY(!valueVec4Custom.isNull()); - QVERIFY(valueVec4Custom.type() == GL_FLOAT); - QCOMPARE(valueVec4Custom.sizeOfType(), int(sizeof(GLfloat))); - QCOMPARE(valueVec4Custom.tupleSize(), 4); - QCOMPARE(valueVec4Custom.stride(), 0); - QVERIFY(valueVec4Custom.data() == vec4CustomArray.data()); - QCOMPARE(valueVec4Custom.count(), vec4CustomArray.count()); - - QArray<QColor4ub> colorArray; - colorArray += QColor4ub(1, 2, 3, 4); - colorArray += QColor4ub(2, 3, 4, 5); - QGLAttributeValue valueColor(colorArray); - QVERIFY(!valueColor.isNull()); - QVERIFY(valueColor.type() == GL_UNSIGNED_BYTE); - QCOMPARE(valueColor.sizeOfType(), int(sizeof(GLubyte))); - QCOMPARE(valueColor.tupleSize(), 4); - QCOMPARE(valueColor.stride(), 0); - QVERIFY(valueColor.data() == colorArray.constData()); - QCOMPARE(valueColor.count(), colorArray.count()); - - QCustomDataArray colorCustomArray(colorArray); - QGLAttributeValue valueColorCustom(colorCustomArray); - QVERIFY(!valueColorCustom.isNull()); - QVERIFY(valueColorCustom.type() == GL_UNSIGNED_BYTE); - QCOMPARE(valueColorCustom.sizeOfType(), int(sizeof(GLubyte))); - QCOMPARE(valueColorCustom.tupleSize(), 4); - QCOMPARE(valueColorCustom.stride(), 0); - QVERIFY(valueColorCustom.data() == colorCustomArray.data()); - QCOMPARE(valueColorCustom.count(), colorCustomArray.count()); -} - -void tst_QGLAttributeValue::typeSizes_data() -{ - QTest::addColumn<int>("type"); - QTest::addColumn<int>("size"); - - QTest::newRow("byte") << int(GL_BYTE) << int(sizeof(GLbyte)); - QTest::newRow("ubyte") << int(GL_UNSIGNED_BYTE) << int(sizeof(GLubyte)); - QTest::newRow("short") << int(GL_SHORT) << int(sizeof(GLshort)); - QTest::newRow("ushort") << int(GL_UNSIGNED_SHORT) << int(sizeof(GLushort)); - QTest::newRow("int") << int(GL_INT) << int(sizeof(GLint)); - QTest::newRow("uint") << int(GL_UNSIGNED_INT) << int(sizeof(GLuint)); - QTest::newRow("float") << int(GL_FLOAT) << int(sizeof(GLfloat)); -#if defined(GL_DOUBLE) && !defined(QT_OPENGL_ES) - QTest::newRow("double") << int(GL_DOUBLE) << int(sizeof(GLdouble)); -#endif - QTest::newRow("non-type") << int(GL_TEXTURE0) << int(0); -} - -void tst_QGLAttributeValue::typeSizes() -{ - QFETCH(int, type); - QFETCH(int, size); - - QGLAttributeValue value(4, GLenum(type), 0, 0); - QCOMPARE(value.sizeOfType(), size); -} - -QTEST_APPLESS_MAIN(tst_QGLAttributeValue) - -#include "tst_qglattributevalue.moc" diff --git a/tests/auto/threed/qglbezierpatches/qglbezierpatches.pro b/tests/auto/threed/qglbezierpatches/qglbezierpatches.pro deleted file mode 100644 index d85b77d0..00000000 --- a/tests/auto/threed/qglbezierpatches/qglbezierpatches.pro +++ /dev/null @@ -1,6 +0,0 @@ -load(qttest_p4.prf) -TEMPLATE=app -QT += testlib -CONFIG += unittest warn_on qt3d - -SOURCES += tst_qglbezierpatches.cpp diff --git a/tests/auto/threed/qglbezierpatches/tst_qglbezierpatches.cpp b/tests/auto/threed/qglbezierpatches/tst_qglbezierpatches.cpp deleted file mode 100644 index 089afc84..00000000 --- a/tests/auto/threed/qglbezierpatches/tst_qglbezierpatches.cpp +++ /dev/null @@ -1,214 +0,0 @@ -/**************************************************************************** -** -** 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 QtQuick3D module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** 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. -** -** 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. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include <QtTest/QtTest> -#include "qglbezierpatches.h" -#include "qglbuilder.h" -#include "qglteapot.h" - -class tst_QGLBezierPatches : public QObject -{ - Q_OBJECT -public: - tst_QGLBezierPatches() {} - ~tst_QGLBezierPatches() {} - -private slots: - void defaultValue(); - void modify(); - void teapot(); - void build(); - void transform(); -}; - -void tst_QGLBezierPatches::defaultValue() -{ - QGLBezierPatches patches; - QVERIFY(patches.positions().isEmpty()); - QVERIFY(patches.textureCoords().isEmpty()); - QCOMPARE(patches.subdivisionDepth(), 4); -} - -void tst_QGLBezierPatches::modify() -{ - QVector3DArray positions; - for (int index = 0; index < 32; ++index) - positions.append(index, index + 1, index + 2); - - QVector2DArray texCoords; - texCoords.append(0.0f, 0.5f); - texCoords.append(0.5f, 1.0f); - texCoords.append(0.5f, 0.0f); - texCoords.append(1.0f, 0.5f); - - QGLBezierPatches patches; - patches.setPositions(positions); - patches.setTextureCoords(texCoords); - patches.setSubdivisionDepth(23); - - QCOMPARE(patches.positions().size(), positions.size()); - QVERIFY(patches.positions() == positions); - QCOMPARE(patches.textureCoords().size(), texCoords.size()); - QVERIFY(patches.textureCoords() == texCoords); - QCOMPARE(patches.subdivisionDepth(), 23); - - QGLBezierPatches patches2(patches); - QCOMPARE(patches2.positions().size(), positions.size()); - QVERIFY(patches2.positions() == positions); - QCOMPARE(patches2.textureCoords().size(), texCoords.size()); - QVERIFY(patches2.textureCoords() == texCoords); - QCOMPARE(patches2.subdivisionDepth(), 23); - - patches2.setPositions(QVector3DArray()); - patches2.setTextureCoords(QVector2DArray()); - patches2.setSubdivisionDepth(18); - - QCOMPARE(patches.positions().size(), positions.size()); - QVERIFY(patches.positions() == positions); - QCOMPARE(patches.textureCoords().size(), texCoords.size()); - QVERIFY(patches.textureCoords() == texCoords); - QCOMPARE(patches.subdivisionDepth(), 23); - - QVERIFY(patches2.positions().isEmpty()); - QVERIFY(patches2.textureCoords().isEmpty()); - QCOMPARE(patches2.subdivisionDepth(), 18); - - QGLBezierPatches patches3; - patches3 = patches; - - QCOMPARE(patches3.positions().size(), positions.size()); - QVERIFY(patches3.positions() == positions); - QCOMPARE(patches3.textureCoords().size(), texCoords.size()); - QVERIFY(patches3.textureCoords() == texCoords); - QCOMPARE(patches3.subdivisionDepth(), 23); - - patches3.setPositions(QVector3DArray()); - patches3.setTextureCoords(QVector2DArray()); - patches3.setSubdivisionDepth(18); - - QCOMPARE(patches.positions().size(), positions.size()); - QVERIFY(patches.positions() == positions); - QCOMPARE(patches.textureCoords().size(), texCoords.size()); - QVERIFY(patches.textureCoords() == texCoords); - QCOMPARE(patches.subdivisionDepth(), 23); - - QVERIFY(patches3.positions().isEmpty()); - QVERIFY(patches3.textureCoords().isEmpty()); - QCOMPARE(patches3.subdivisionDepth(), 18); - - patches = QGLBezierPatches(); - QVERIFY(patches.positions().isEmpty()); - QVERIFY(patches.textureCoords().isEmpty()); - QCOMPARE(patches.subdivisionDepth(), 4); -} - -void tst_QGLBezierPatches::teapot() -{ - // Verify that patch data is added by QGLTeapot's constructor, - // but not what that patch data is. - QGLTeapot teapot; - QCOMPARE(teapot.positions().size(), 32 * 16); - QCOMPARE(teapot.textureCoords().size(), 0); - QCOMPARE(teapot.subdivisionDepth(), 4); -} - -void tst_QGLBezierPatches::build() -{ - // Call the build routines with different options. It isn't really - // easy to determine if the correct triangles were generated. Leave - // that up to visual acceptance tests. - - QGLBuilder builder; - - QGLTeapot teapot1; - builder << teapot1; - - QGLTeapot teapot2; - QVector2DArray texCoords; - for (int index = 0; index < 32; ++index) { - texCoords.append(0.0f, 0.5f); - texCoords.append(0.5f, 1.0f); - } - teapot2.setTextureCoords(texCoords); - builder << teapot2; - - delete builder.finalizedSceneNode(); -} - -void tst_QGLBezierPatches::transform() -{ - QVector3DArray positions; - for (int index = 0; index < 32; ++index) - positions.append(index, index + 1, index + 2); - - QMatrix4x4 m; - m.translate(-1.0f, 2.5f, 5.0f); - m.rotate(45.0f, 1.0f, 1.0f, 1.0f); - m.scale(23.5f); - - QVector3DArray positions2 = positions.transformed(m); - - QVector2DArray texCoords; - texCoords.append(0.0f, 0.5f); - texCoords.append(0.5f, 1.0f); - texCoords.append(0.5f, 0.0f); - texCoords.append(1.0f, 0.5f); - - QGLBezierPatches patches; - patches.setPositions(positions); - patches.setTextureCoords(texCoords); - patches.setSubdivisionDepth(18); - - QGLBezierPatches patches2(patches); - patches2.transform(m); - QVERIFY(patches2.positions() == positions2); - QVERIFY(patches2.textureCoords() == texCoords); - QCOMPARE(patches2.subdivisionDepth(), 18); - - QGLBezierPatches patches3 = patches.transformed(m); - QVERIFY(patches3.positions() == positions2); - QVERIFY(patches3.textureCoords() == texCoords); - QCOMPARE(patches3.subdivisionDepth(), 18); -} - -QTEST_APPLESS_MAIN(tst_QGLBezierPatches) - -#include "tst_qglbezierpatches.moc" diff --git a/tests/auto/threed/qglbuilder/qglbuilder.pro b/tests/auto/threed/qglbuilder/qglbuilder.pro deleted file mode 100644 index 0853f935..00000000 --- a/tests/auto/threed/qglbuilder/qglbuilder.pro +++ /dev/null @@ -1,8 +0,0 @@ -load(qttest_p4.prf) -TEMPLATE=app -QT += testlib -CONFIG += unittest warn_on qt3d - -INCLUDEPATH += ../../../shared -SOURCES += tst_qglbuilder.cpp -INCLUDEPATH += ../../../../src/threed/geometry diff --git a/tests/auto/threed/qglbuilder/tst_qglbuilder.cpp b/tests/auto/threed/qglbuilder/tst_qglbuilder.cpp deleted file mode 100644 index dc8e4a45..00000000 --- a/tests/auto/threed/qglbuilder/tst_qglbuilder.cpp +++ /dev/null @@ -1,888 +0,0 @@ -/**************************************************************************** -** -** 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 QtQuick3D module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** 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. -** -** 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. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include <QtTest/QtTest> -#include <QtCore/qpointer.h> -#include "qglbuilder.h" -#include "qvector2darray.h" -#include "qvector3darray.h" -#include "qglsection_p.h" -#include "qglmaterialcollection.h" -#include "qglscenenode.h" -#include "qglabstracteffect.h" -#include "qtest_helpers.h" -#include "qgeometrydata.h" - -class tst_QGLBuilder : public QObject -{ - Q_OBJECT -public: - tst_QGLBuilder() {} - ~tst_QGLBuilder() {} - -private slots: - void createDefault(); - void newSection(); - void newNode(); - void pushNode(); - void popNode(); - void geometryBuild(); - void addTriangles(); - void addQuads(); - void addTriangleFan(); - void addTriangulatedFace(); - void extrude(); - void finalize(); -}; - -// Indices in a QGL::IndexArray are int on desktop, ushort on OpenGL/ES. -// This macro works around the discrepancy to avoid confusing QCOMPARE. -#define QCOMPARE_INDEX(x,y) QCOMPARE(int(x), int(y)) - -class TestBuilder : public QGLBuilder -{ -public: - QGLSection *currentSection() { return QGLBuilder::currentSection(); } - QList<QGLSection*> sections() { return QGLBuilder::sections(); } -}; - -void tst_QGLBuilder::createDefault() -{ - // Test that a newly created builder works with no defaults - TestBuilder builder; - QCOMPARE(builder.currentSection(), (QGLSection*)0); - QCOMPARE(builder.sections().size(), 0); - QVERIFY(builder.currentNode() != 0); - QVERIFY(builder.sceneNode() != 0); - QVERIFY(builder.sceneNode()->geometry().isEmpty()); - QVERIFY(builder.palette() != 0); - QGLSceneNode *root = builder.sceneNode(); - QCOMPARE(builder.finalizedSceneNode(), root); -} - -void tst_QGLBuilder::newSection() -{ - TestBuilder builder; - builder.newSection(); // defaults to smooth - QGLSection *s = builder.currentSection(); - QCOMPARE(s, builder.currentSection()); - QCOMPARE(builder.sections().count(), 1); - QVERIFY(builder.sections().contains(s)); - QCOMPARE(s->smoothing(), QGL::Smooth); - builder.newSection(QGL::Faceted); - QGLSection *s2 = builder.currentSection(); - QCOMPARE(builder.sections().count(), 2); - QVERIFY(builder.sections().contains(s2)); - builder << QGL::Faceted; - QCOMPARE(builder.sections().count(), 3); - QGLSceneNode *root = builder.sceneNode(); - QCOMPARE(builder.finalizedSceneNode(), root); -} - -class TestEffect : public QGLAbstractEffect -{ - void setActive(QGLPainter *, bool) - { - } - void update(QGLPainter *, QGLPainter::Updates) - { - } -}; - -void tst_QGLBuilder::newNode() -{ - TestBuilder builder; - builder.newSection(); // calls new node - QGLSceneNode *node = builder.currentNode(); - - // newly created node works and has all defaults - QCOMPARE(node->effect(), QGL::FlatColor); // flat color is the default - QCOMPARE(node->userEffect(), (QGLAbstractEffect *)0); - QCOMPARE(node->materialIndex(), -1); - QCOMPARE(node->start(), 0); - QCOMPARE(node->count(), 0); - - // add some settings and geometry to the new node - node->setEffect(QGL::LitDecalTexture2D); - QGLAbstractEffect *eff = new TestEffect; - node->setUserEffect(eff); - node->setMaterialIndex(5); - QGeometryData p; - p.appendVertex(QVector3D(), QVector3D(1.0f, 2.0f, 3.0f), QVector3D(4.0f, 5.0f, 6.0f)); - builder.addTriangles(p); - - // now create a new node - QGLSceneNode *node2 = builder.newNode(); - - // the previous node got cleaned up properly, with its count updated - QCOMPARE(node->start(), 0); - QCOMPARE(node->count(), 3); - - // new node counts off from where the previous one finished and has same defaults - QCOMPARE(node2->start(), 3); - QCOMPARE(node2->count(), 0); - QCOMPARE(node2->effect(), QGL::FlatColor); // lit material is the default - QCOMPARE(node2->userEffect(), (QGLAbstractEffect *)0); - QCOMPARE(node2->materialIndex(), -1); - - builder.addTriangles(p); - builder.newNode(); - - // confirm that 2nd and last node in chain was also finished properly - QCOMPARE(node2->start(), 3); - QCOMPARE(node2->count(), 3); - - // suppress warning - builder.finalizedSceneNode(); -} - -void tst_QGLBuilder::pushNode() -{ - TestBuilder builder; - builder.newSection(); - QGLSceneNode *node = builder.newNode(); - node->setEffect(QGL::LitDecalTexture2D); - QGLAbstractEffect *eff = new TestEffect; - node->setUserEffect(eff); - node->setMaterialIndex(5); - QGeometryData p; - p.appendVertex(QVector3D(), QVector3D(1.0f, 2.0f, 3.0f), QVector3D(4.0f, 5.0f, 6.0f)); - builder.addTriangles(p); - - QGLSceneNode *node2 = builder.pushNode(); - QCOMPARE(node->start(), 0); - QCOMPARE(node->count(), 3); - QCOMPARE(builder.currentNode(), node2); - QCOMPARE(node2->start(), 3); - QCOMPARE(node2->count(), 0); - QCOMPARE(node2->parent(), node); - QCOMPARE(node2->effect(), QGL::FlatColor); // lit material is the default - QCOMPARE(node2->userEffect(), (QGLAbstractEffect *)0); - QCOMPARE(node2->materialIndex(), -1); - - // suppress warning - builder.finalizedSceneNode(); -} - -void tst_QGLBuilder::popNode() -{ - TestBuilder builder; - builder.newSection(); - QGLSceneNode *node = builder.newNode(); - node->setEffect(QGL::LitDecalTexture2D); - QGLAbstractEffect *eff = new TestEffect; - QMatrix4x4 mat; - mat.rotate(45.0f, 0.0f, 1.0f, 0.0f); - node->setLocalTransform(mat); - node->setUserEffect(eff); - node->setMaterialIndex(5); - QGeometryData p; - p.appendVertex(QVector3D(), QVector3D(1.0f, 2.0f, 3.0f), QVector3D(4.0f, 5.0f, 6.0f)); - builder.addTriangles(p); - - QGLSceneNode *node2 = builder.pushNode(); - - builder.addTriangles(p); - - QGLSceneNode *node3 = builder.popNode(); - QCOMPARE(node2->start(), 3); - QCOMPARE(node2->count(), 3); - - QCOMPARE(node3->effect(), QGL::LitDecalTexture2D); - QCOMPARE(node3->userEffect(), eff); - QCOMPARE(node3->materialIndex(), 5); - QCOMPARE(node3->localTransform(), mat); - QCOMPARE(node3->start(), 6); - QCOMPARE(node3->count(), 0); - - // suppress warning - builder.finalizedSceneNode(); -} - -void tst_QGLBuilder::geometryBuild() -{ - // here we really just test that the right values get added - // to the underlying QGeometryData - TestBuilder builder; - builder.newSection(); - QGLSection *sec = builder.currentSection(); - QGLSceneNode *node = builder.currentNode(); - - QCOMPARE(sec->count(), 0); // empty to start off with - QCOMPARE(node->count(), 0); - - QVector3D a(-1.0f, -1.0f, 0.0f); - QVector3D b(1.0f, -1.0f, 0.0f); - QVector3D c(1.0f, 1.0f, 0.0f); - QVector3D d(-1.0f, 1.0f, 0.0f); - QVector3D e(1.0f, 2.0f, 0.0f); - QVector3D f(-1.0f, 2.0f, 0.0f); - QVector3D origin; - QVector3D norm(0.0f, 0.0f, 1.0f); - - QGeometryData p; - p.appendVertex(a, b, c); - builder.addTriangles(p); - QCOMPARE(sec->count(), 3); - QCOMPARE(sec->vertex(0), a); - QCOMPARE(sec->vertex(1), b); - QCOMPARE(sec->vertex(2), c); - QCOMPARE(sec->normal(0).normalized(), norm); - QCOMPARE(sec->normal(1).normalized(), norm); - QCOMPARE(sec->normal(2).normalized(), norm); - QCOMPARE(node->count(), 3); - - builder.newSection(); - QGeometryData q; - sec = builder.currentSection(); - node = builder.currentNode(); - QCOMPARE(sec->count(), 0); // empty to start off with - QCOMPARE(node->count(), 0); - QVector3DArray data; - data << a << b << d << c << f << e; - q.appendVertexArray(data); - builder.addTriangleStrip(q); - QCOMPARE(sec->count(), 6); - QCOMPARE(sec->vertex(0), a); - QCOMPARE(sec->vertex(1), b); - QCOMPARE(sec->vertex(2), d); - QCOMPARE(sec->vertex(3), c); - QCOMPARE(sec->vertex(4), f); - QCOMPARE(sec->vertex(5), e); - QCOMPARE(sec->normal(0).normalized(), norm); - QCOMPARE(sec->normal(3).normalized(), norm); - QCOMPARE(sec->normal(5).normalized(), norm); - QCOMPARE(node->count(), 12); // TRIANGLE_STRIP will here draw 4 triangles = 12 indices - - // now go on and test TRIANGLE_FAN - builder.newSection(); - sec = builder.currentSection(); - node = builder.currentNode(); - QGeometryData r; - r.appendVertex(a); - r.appendNormal(norm); - r.appendVertex(b); - r.appendNormal(norm); - r.appendVertex(c); - r.appendNormal(norm); - r.appendVertex(d); - r.appendNormal(norm); - r.appendVertex(e); - r.appendNormal(norm); - builder.addTriangleFan(r); - QCOMPARE(sec->count(), 5); - QCOMPARE(sec->vertex(0), a); - QCOMPARE(sec->vertex(2), c); - QCOMPARE(sec->vertex(4), e); - QCOMPARE(sec->normal(0).normalized(), norm); - QCOMPARE(sec->normal(4).normalized(), norm); - QCOMPARE(node->count(), 9); // TRIANGLE_FAN will here draw 3 triangles = 9 indices - - QGeometryData s; - //builder.begin(QGL::TRIANGULATED_FACE); - builder.newSection(); - sec = builder.currentSection(); - node = builder.currentNode(); - s.appendVertex(a); - s.appendColor(Qt::red); - s.appendVertex(b); - s.appendColor(QColor4ub(Qt::green)); - s.appendVertex(c); - s.appendVertex(d); - s.appendVertex(e); - QArray<QColor4ub> cdata; - cdata.append(Qt::blue, Qt::yellow, Qt::black); - s.appendColorArray(cdata); - builder.addTriangulatedFace(s); - QCOMPARE(sec->count(), 5); - QCOMPARE(sec->vertex(0), a); - QCOMPARE(sec->vertex(4), e); - QCOMPARE(sec->colorAt(0), QColor4ub(Qt::red)); - QCOMPARE(sec->colorAt(1), QColor4ub(Qt::green)); - QCOMPARE(sec->colorAt(2), QColor4ub(Qt::blue)); - QCOMPARE(sec->colorAt(3), QColor4ub(Qt::yellow)); - QCOMPARE(sec->colorAt(4), QColor4ub(Qt::black)); - QCOMPARE(node->count(), 12); // TRIANGLE_FAN will here draw 4 triangles = 12 indices - - // suppress warning - builder.finalizedSceneNode(); -} - -void tst_QGLBuilder::addTriangles() -{ - TestBuilder builder; - builder.newSection(); - QGLSection *sec = builder.currentSection(); - QGLSceneNode *node = builder.currentNode(); - QVector3D a(-1.0f, -1.0f, 0.0f); - QVector3D b(1.0f, -1.0f, 0.0f); - QVector3D c(1.0f, 1.0f, 0.0f); - QVector2D ta(0.0, 0.0); - QVector2D tb(1.0, 0.0); - QVector2D tc(1.0, 1.0); - QVector3D norm(0.0f, 0.0f, 1.0f); - QGeometryData p; - p.appendVertex(a, b, c); - p.appendNormal(norm, norm, norm); - - builder.addTriangles(p); - QCOMPARE(sec->vertices().count(), 3); - QCOMPARE(sec->vertex(0), a); - QCOMPARE(sec->vertex(1), b); - QCOMPARE(sec->vertex(2), c); - QCOMPARE(sec->normals().count(), 3); - QCOMPARE(sec->indices().size(), 3); - QCOMPARE_INDEX(sec->indices()[0], 0); - QCOMPARE_INDEX(sec->indices()[1], 1); - QCOMPARE_INDEX(sec->indices()[2], 2); - QCOMPARE(sec->fields(), QGL::fieldMask(QGL::Position) | QGL::fieldMask(QGL::Normal)); - - QVector3D d(-1.0f, 1.0f, 0.0f); - QVector2D td(0.0f, 1.0f); - QGeometryData q; - q.appendVertex(a, c, d); - p.appendNormal(norm, norm, norm, norm); - builder.addTriangles(q); - QCOMPARE(sec->vertices().count(), 4); - QCOMPARE(sec->vertex(3), d); - QCOMPARE(sec->normals().count(), 4); - QCOMPARE(sec->normal(0).normalized(), norm); - QCOMPARE(sec->normal(1).normalized(), norm); - QCOMPARE(sec->normal(2).normalized(), norm); - QCOMPARE(sec->normal(3).normalized(), norm); - QCOMPARE(sec->indices().size(), 6); - QCOMPARE_INDEX(sec->indices()[3], 0); - QCOMPARE_INDEX(sec->indices()[4], 2); - QCOMPARE_INDEX(sec->indices()[5], 3); - QCOMPARE(sec->fields(), QGL::fieldMask(QGL::Position) | QGL::fieldMask(QGL::Normal)); - - QCOMPARE(node->start(), 0); - QCOMPARE(node->count(), 6); - - builder.newSection(); - sec = builder.currentSection(); - node = builder.currentNode(); - QGeometryData r; - r.appendVertex(a, b, c); - r.appendTexCoord(ta, tb, tc); - builder.addTriangles(r); - QCOMPARE(sec->vertices().count(), 3); - QCOMPARE(sec->vertex(0), a); - QCOMPARE(sec->vertex(1), b); - QCOMPARE(sec->vertex(2), c); - QCOMPARE(sec->normals().count(), 3); - QCOMPARE(sec->normal(0).normalized(), norm); - QCOMPARE(sec->normal(1).normalized(), norm); - QCOMPARE(sec->normal(2).normalized(), norm); - QCOMPARE(sec->texCoords().count(), 3); - QCOMPARE(sec->texCoords().at(0), ta); - QCOMPARE(sec->texCoords().at(1), tb); - QCOMPARE(sec->texCoords().at(2), tc); - QCOMPARE(sec->indices().size(), 3); - QCOMPARE_INDEX(sec->indices()[0], 0); - QCOMPARE_INDEX(sec->indices()[1], 1); - QCOMPARE_INDEX(sec->indices()[2], 2); - QCOMPARE(sec->fields(), - QGL::fieldMask(QGL::Position) | QGL::fieldMask(QGL::Normal) | QGL::fieldMask(QGL::TextureCoord0)); - - QGeometryData s; - s.appendVertex(a, b, d); - s.appendTexCoord(ta, tb, td); - builder.addTriangles(s); - QCOMPARE(sec->vertices().count(), 4); - QCOMPARE(sec->vertex(3), d); - QCOMPARE(sec->normals().count(), 4); - QCOMPARE(sec->normal(0).normalized(), norm); - QCOMPARE(sec->normal(1).normalized(), norm); - QCOMPARE(sec->normal(2).normalized(), norm); - QCOMPARE(sec->normal(3).normalized(), norm); - QCOMPARE(sec->texCoords().count(), 4); - QCOMPARE(sec->texCoords().at(0), QVector2D(0.0f, 0.0f)); - QCOMPARE(sec->texCoords().at(1), QVector2D(1.0f, 0.0f)); - QCOMPARE(sec->texCoords().at(2), QVector2D(1.0f, 1.0f)); - QCOMPARE(sec->texCoords().at(3), QVector2D(0.0f, 1.0f)); - QCOMPARE(sec->indices().size(), 6); - QCOMPARE_INDEX(sec->indices()[3], 0); - QCOMPARE_INDEX(sec->indices()[4], 1); - QCOMPARE_INDEX(sec->indices()[5], 3); - QCOMPARE(sec->fields(), - QGL::fieldMask(QGL::Position) | QGL::fieldMask(QGL::Normal) | QGL::fieldMask(QGL::TextureCoord0)); - - QCOMPARE(node->start(), 0); - QCOMPARE(node->count(), 6); - - // correctly handle not being a multiple of 3 - discard spare ones - builder.newSection(); - sec = builder.currentSection(); - QGeometryData t; - t.appendVertex(a, b, c, d); - builder.addTriangles(t); - QCOMPARE(sec->count(), 3); - QCOMPARE(sec->vertex(0), a); - QCOMPARE(sec->vertex(1), b); - QCOMPARE(sec->vertex(2), c); - - // suppress warning - builder.finalizedSceneNode(); -} - -void tst_QGLBuilder::addQuads() -{ - TestBuilder builder; - builder.newSection(); - QGLSection *sec = builder.currentSection(); - QGLSceneNode *node = builder.currentNode(); - QVector3D a(-1.0f, -1.0f, 0.0f); - QVector3D b(1.0f, -1.0f, 0.0f); - QVector3D c(1.0f, 1.0f, 0.0f); - QVector3D d(-1.0f, 1.0f, 0.0f); - QVector3D norm(0.0f, 0.0f, 1.0f); - QGeometryData p; - p.appendVertex(a, b, c, d); - p.appendNormal(norm, norm, norm, norm); - - builder.addQuads(p); - QCOMPARE(sec->vertices().count(), 4); - QCOMPARE(sec->vertex(0), a); - QCOMPARE(sec->vertex(1), b); - QCOMPARE(sec->vertex(2), c); - QCOMPARE(sec->vertex(3), d); - QCOMPARE(sec->normals().count(), 4); - QCOMPARE(sec->normal(0).normalized(), norm); - QCOMPARE(sec->normal(1).normalized(), norm); - QCOMPARE(sec->normal(2).normalized(), norm); - QCOMPARE(sec->normal(3).normalized(), norm); - QCOMPARE(sec->indices().size(), 6); - QCOMPARE_INDEX(sec->indices()[3], 0); - QCOMPARE_INDEX(sec->indices()[0], 0); - QCOMPARE_INDEX(sec->indices()[1], 1); - QCOMPARE_INDEX(sec->indices()[2], 2); - QCOMPARE_INDEX(sec->indices()[3], 0); - QCOMPARE_INDEX(sec->indices()[4], 2); - QCOMPARE_INDEX(sec->indices()[5], 3); - QCOMPARE(sec->fields(), QGL::fieldMask(QGL::Position) | QGL::fieldMask(QGL::Normal)); - - QCOMPARE(node->start(), 0); - QCOMPARE(node->count(), 6); - - builder.newSection(); - sec = builder.currentSection(); - node = builder.currentNode(); - QVector2D ta(0.0f, 0.0f); - QVector2D tb(1.0f, 0.0f); - QVector2D tc(1.0f, 1.0f); - QVector2D td(0.0f, 1.0f); - QGeometryData q; - q.appendVertex(a, b, c, d); - q.appendTexCoord(ta, tb, tc, td); - builder.addQuads(q); - - QCOMPARE(sec->vertices().count(), 4); - QCOMPARE(sec->vertex(0), a); - QCOMPARE(sec->vertex(1), b); - QCOMPARE(sec->vertex(2), c); - QCOMPARE(sec->vertex(3), d); - QCOMPARE(sec->normals().count(), 4); - QCOMPARE(sec->normal(0).normalized(), norm); - QCOMPARE(sec->normal(1).normalized(), norm); - QCOMPARE(sec->normal(2).normalized(), norm); - QCOMPARE(sec->normal(3).normalized(), norm); - QCOMPARE(sec->texCoords().count(), 4); - QCOMPARE(sec->texCoords().at(0), ta); - QCOMPARE(sec->texCoords().at(1), tb); - QCOMPARE(sec->texCoords().at(2), tc); - QCOMPARE(sec->texCoords().at(3), td); - QCOMPARE(sec->indices().size(), 6); - QCOMPARE_INDEX(sec->indices()[0], 0); - QCOMPARE_INDEX(sec->indices()[1], 1); - QCOMPARE_INDEX(sec->indices()[2], 2); - QCOMPARE_INDEX(sec->indices()[3], 0); - QCOMPARE_INDEX(sec->indices()[4], 2); - QCOMPARE_INDEX(sec->indices()[5], 3); - QCOMPARE(sec->fields(), - QGL::fieldMask(QGL::Position) | QGL::fieldMask(QGL::Normal) | QGL::fieldMask(QGL::TextureCoord0)); - - QCOMPARE(node->start(), 0); - QCOMPARE(node->count(), 6); - - // suppress warning - builder.finalizedSceneNode(); -} - -void tst_QGLBuilder::addTriangleFan() -{ - TestBuilder builder; - builder.newSection(QGL::Faceted); - QGLSection *sec = builder.currentSection(); - QGLSceneNode *node = builder.currentNode(); - QVector3D a(-1.0f, -1.0f, 0.0f); - QVector3D b(1.0f, -1.0f, 0.0f); - QVector3D c(1.0f, 1.0f, 0.0f); - QVector3D d(-1.0f, 1.0f, 0.0f); - qreal one_on_root2 = 1.0f / sqrt(2.0f); - QVector3D n1(0.0f, -one_on_root2, one_on_root2); - QVector3D n2(one_on_root2, 0.0f, one_on_root2); - QVector3D n3(0.0f, one_on_root2, one_on_root2); - QVector3D center(0.0f, 0.0f, 1.0f); - QVector2DArray edges; - - // if edges has length < 2, exit without doing anything - QGeometryData p; - p.appendVertex(center); - builder.addTriangleFan(p); - QCOMPARE(sec->vertices().count(), 0); - QCOMPARE(sec->normals().count(), 0); - QCOMPARE(sec->indices().size(), 0); - - p.appendVertex(a, b, c, d); - - builder.addTriangleFan(p); - sec->normalizeNormals(); - QCOMPARE(sec->vertices().count(), 9); - QCOMPARE(sec->vertex(0), center); - QCOMPARE(sec->vertex(1), a); - QCOMPARE(sec->vertex(2), b); - QCOMPARE(sec->vertex(3), center); - QCOMPARE(sec->vertex(4), b); - QCOMPARE(sec->vertex(5), c); - QCOMPARE(sec->vertex(6), center); - QCOMPARE(sec->vertex(7), c); - QCOMPARE(sec->vertex(8), d); - QCOMPARE(sec->normals().count(), 9); - QCOMPARE(sec->normal(0), n1); - QCOMPARE(sec->normal(1), n1); - QCOMPARE(sec->normal(2), n1); - QCOMPARE(sec->normal(3), n2); - QCOMPARE(sec->normal(4), n2); - QCOMPARE(sec->normal(5), n2); - QCOMPARE(sec->normal(6), n3); - QCOMPARE(sec->normal(7), n3); - QCOMPARE(sec->normal(8), n3); - QCOMPARE(sec->indices().size(), 9); - QCOMPARE_INDEX(sec->indices()[0], 0); - QCOMPARE_INDEX(sec->indices()[1], 1); - QCOMPARE_INDEX(sec->indices()[2], 2); - QCOMPARE_INDEX(sec->indices()[3], 3); - QCOMPARE_INDEX(sec->indices()[4], 4); - QCOMPARE_INDEX(sec->indices()[5], 5); - QCOMPARE_INDEX(sec->indices()[6], 6); - QCOMPARE_INDEX(sec->indices()[7], 7); - QCOMPARE_INDEX(sec->indices()[8], 8); - QCOMPARE(sec->fields(), QGL::fieldMask(QGL::Position) | QGL::fieldMask(QGL::Normal)); - - QCOMPARE(node->start(), 0); - QCOMPARE(node->count(), 9); - - // suppress warning - builder.finalizedSceneNode(); -} - -void tst_QGLBuilder::addTriangulatedFace() -{ - TestBuilder builder; - builder.newSection(QGL::Faceted); - QGLSection *sec = builder.currentSection(); - QGLSceneNode *node = builder.currentNode(); - QVector3D a(-1.0f, -1.0f, 0.0f); - QVector3D b(1.0f, -1.0f, 0.0f); - QVector3D c(1.0f, 1.0f, 0.0f); - QVector3D d(-1.0f, 1.0f, 0.0f); - QVector3D n(0.0f, 0.0f, 1.0f); - QVector3D center(0.0f, 0.0f, 0.0f); - QVector2DArray edges; - - // if edges has length < 2, exit without doing anything - QGeometryData p; - builder.addTriangleFan(p); - QCOMPARE(sec->vertices().count(), 0); - QCOMPARE(sec->normals().count(), 0); - QCOMPARE(sec->indices().size(), 0); - - p.appendVertex(center); - p.appendVertex(a, b, c, d); - - builder.addTriangulatedFace(p); - sec->normalizeNormals(); - QCOMPARE(sec->vertices().count(), 5); - QCOMPARE(sec->vertex(0), center); - QCOMPARE(sec->vertex(1), a); - QCOMPARE(sec->vertex(2), b); - QCOMPARE(sec->vertex(3), c); - QCOMPARE(sec->vertex(4), d); - QCOMPARE(sec->normals().count(), 5); - QCOMPARE(sec->normal(0), n); - QCOMPARE(sec->normal(1), n); - QCOMPARE(sec->normal(2), n); - QCOMPARE(sec->normal(3), n); - QCOMPARE(sec->normal(4), n); - QCOMPARE(sec->indices().size(), 12); - QCOMPARE_INDEX(sec->indices()[0], 0); - QCOMPARE_INDEX(sec->indices()[1], 1); - QCOMPARE_INDEX(sec->indices()[2], 2); - QCOMPARE_INDEX(sec->indices()[3], 0); - QCOMPARE_INDEX(sec->indices()[4], 2); - QCOMPARE_INDEX(sec->indices()[5], 3); - QCOMPARE_INDEX(sec->indices()[6], 0); - QCOMPARE_INDEX(sec->indices()[7], 3); - QCOMPARE_INDEX(sec->indices()[8], 4); - QCOMPARE_INDEX(sec->indices()[9], 0); - QCOMPARE_INDEX(sec->indices()[10], 4); - QCOMPARE_INDEX(sec->indices()[11], 1); - QCOMPARE(sec->fields(), QGL::fieldMask(QGL::Position) | QGL::fieldMask(QGL::Normal)); - - QCOMPARE(node->start(), 0); - QCOMPARE(node->count(), 12); - - // suppress warning - builder.finalizedSceneNode(); -} - -void tst_QGLBuilder::extrude() -{ - TestBuilder builder; - builder.newSection(); - QGLSection *sec = builder.currentSection(); - QGLSceneNode *node = builder.currentNode(); - QVector3D a(-1.0f, -1.0f, 0.0f); - QVector3D b(1.0f, -1.0f, 0.0f); - QVector3D c(1.0f, 1.0f, 0.0f); - QVector3D d(-1.0f, 1.0f, 0.0f); - QVector3D n(0.0f, 0.0f, 1.0f); - QVector3DArray edges; - - // if edges has length < 2, exit without doing anything - QGeometryData p; - QGeometryData q; - builder.addQuadsInterleaved(p, q); - QCOMPARE(sec->vertices().count(), 0); - QCOMPARE(sec->normals().count(), 0); - QCOMPARE(sec->indices().size(), 0); - - p.appendVertex(a, b, c, d); - edges = p.vertices(); - p.appendVertex(a); - q = p.translated(-n); - - qreal one_on_root2 = 1.0f / sqrt(2.0f); - QVector3D n1(-one_on_root2, -one_on_root2, 0.0f); - QVector3D n2(one_on_root2, -one_on_root2, 0.0f); - QVector3D n3(one_on_root2, one_on_root2, 0.0f); - QVector3D n4(-one_on_root2, one_on_root2, 0.0f); - - builder.addQuadsInterleaved(p, q); - //sec->normalizeNormals(); - - QCOMPARE(sec->count(), 8); - QVector3DArray vrts = sec->vertices(); - QVector3DArray nrms = sec->normals(); - QGL::IndexArray inxs = sec->indices(); - - QCOMPARE(vrts.count(), 8); - QCOMPARE(vrts.at(0), edges.at(0) - n); - QCOMPARE(vrts.at(1), edges.at(1) - n); - QCOMPARE(vrts.at(2), edges.at(1)); - QCOMPARE(vrts.at(3), edges.at(0)); - QCOMPARE(vrts.at(4), edges.at(2) - n); - QCOMPARE(vrts.at(5), edges.at(2)); - QCOMPARE(vrts.at(6), edges.at(3) - n); - QCOMPARE(vrts.at(7), edges.at(3)); - - QCOMPARE(nrms.count(), 8); - QCOMPARE(nrms.at(0).normalized(), n1); - QCOMPARE(nrms.at(1).normalized(), n2); - QCOMPARE(nrms.at(2).normalized(), n2); - QCOMPARE(nrms.at(3).normalized(), n1); - QCOMPARE(nrms.at(4).normalized(), n3); - QCOMPARE(nrms.at(5).normalized(), n3); - QCOMPARE(nrms.at(6).normalized(), n4); - QCOMPARE(nrms.at(7).normalized(), n4); - - static int checkIx[] = { - 0, 1, 2, 0, 2, 3, - 1, 4, 5, 1, 5, 2, - 4, 6, 7, 4, 7, 5, - 6, 0, 3, 6, 3, 7 - }; - QCOMPARE(sec->indices().size(), 24); - - QCOMPARE_INDEX(inxs[0], checkIx[0]); - QCOMPARE_INDEX(inxs[1], checkIx[1]); - QCOMPARE_INDEX(inxs[2], checkIx[2]); - QCOMPARE_INDEX(inxs[3], checkIx[3]); - QCOMPARE_INDEX(inxs[4], checkIx[4]); - QCOMPARE_INDEX(inxs[5], checkIx[5]); - QCOMPARE_INDEX(inxs[6], checkIx[6]); - QCOMPARE_INDEX(inxs[7], checkIx[7]); - QCOMPARE_INDEX(inxs[8], checkIx[8]); - QCOMPARE_INDEX(inxs[9], checkIx[9]); - QCOMPARE_INDEX(inxs[10], checkIx[10]); - QCOMPARE_INDEX(inxs[11], checkIx[11]); - QCOMPARE_INDEX(inxs[12], checkIx[12]); - QCOMPARE_INDEX(inxs[13], checkIx[13]); - QCOMPARE_INDEX(inxs[14], checkIx[14]); - QCOMPARE_INDEX(inxs[15], checkIx[15]); - QCOMPARE_INDEX(inxs[16], checkIx[16]); - QCOMPARE_INDEX(inxs[17], checkIx[17]); - QCOMPARE_INDEX(inxs[18], checkIx[18]); - QCOMPARE_INDEX(inxs[19], checkIx[19]); - QCOMPARE_INDEX(inxs[20], checkIx[20]); - QCOMPARE_INDEX(inxs[21], checkIx[21]); - QCOMPARE_INDEX(inxs[22], checkIx[22]); - QCOMPARE_INDEX(inxs[23], checkIx[23]); - - QCOMPARE(sec->fields(), QGL::fieldMask(QGL::Position) | QGL::fieldMask(QGL::Normal)); - - QCOMPARE(node->start(), 0); - QCOMPARE(node->count(), 24); - - // suppress warning - builder.finalizedSceneNode(); -} - -void tst_QGLBuilder::finalize() -{ - QVector3D a(-1.0f, -1.0f, 0.0f); - QVector3D b(1.0f, -1.0f, 0.0f); - QVector3D c(1.0f, 1.0f, 0.0f); - QVector3D d(-1.0f, 1.0f, 0.0f); - QVector3D center(0.0f, 0.0f, 0.0f); - QVector3D n(0.0f, 0.0f, 1.0f); - - // backwards wound triangle - on back face - QVector3D e(1.0f, -1.0f, 1.0f); - QVector3D f(-1.0f, -1.0f, 1.0f); - QVector3D g(-1.0f, 1.0f, 1.0f); - // normal points back - QVector3D n10(0.0f, 0.0f, -1.0f); - - QGeometryData p; - p.appendVertex(center); - p.appendVertex(a, b, c, d); - - qreal one_on_root2 = 1.0f / sqrt(2.0f); - QVector3D n0(0.0f, 0.0f, 1.0f); - QVector3D n1(-one_on_root2, -one_on_root2, 0.0f); - QVector3D n2(one_on_root2, -one_on_root2, 0.0f); - QVector3D n3(one_on_root2, one_on_root2, 0.0f); - QVector3D n4(-one_on_root2, one_on_root2, 0.0f); - - TestBuilder builder; - builder.newSection(); - QGLSceneNode *node = builder.currentNode(); - - builder.addTriangulatedFace(p); - - builder.newSection(); - QGLSceneNode *node2 = builder.currentNode(); - - QGeometryData s; - s.appendVertex(a, b, c, d); - s.appendVertex(a); - builder.addQuadsInterleaved(s, s.translated(-n)); - - QPointer<QGLSceneNode> nodeEmpty0 = builder.newNode(); - - builder.newSection(); - QGLSceneNode *node3 = builder.currentNode(); - - QGeometryData q; - QVector2D ta(0.0f, 0.0f); - QVector2D tb(1.0f, 0.0f); - QVector2D tc(1.0f, 1.0f); - q.appendVertex(e, f, g); - q.appendTexCoord(ta, tb, tc); - // reverse winding, backwards normal == n10 - builder.addTriangles(q); - - QPointer<QGLSceneNode> nodeEmpty1 = builder.pushNode(); - - builder.finalizedSceneNode(); - - QCOMPARE(nodeEmpty0.data(), (QGLSceneNode*)0); - QCOMPARE(nodeEmpty1.data(), (QGLSceneNode*)0); - - QCOMPARE(builder.sections().count(), 0); - - QGeometryData geom = node->geometry(); - QGL::IndexArray ids = geom.indices(); - - QCOMPARE(geom.count(QGL::Position), 13); - QCOMPARE(ids.size(), 36); - - // triangulated face - int tf = ids[node->start()]; // beginning of triangulated face - QCOMPARE(node->count(), 12); - QCOMPARE(geom.vertexAt(tf), center); - QCOMPARE(geom.vertexAt(tf + 2), b); - QCOMPARE(geom.normalAt(tf), n0); - QCOMPARE(geom.normalAt(tf + 2), n0); - - geom = node2->geometry(); - ids = geom.indices(); - - int ext = ids[node2->start()]; // beginning of extrude - int last = ids[node2->start() + (node2->count() - 1)]; - QCOMPARE(node2->count(), 24); - QCOMPARE(geom.vertexAt(ext), a - n); - QCOMPARE(geom.normalAt(ext), n1); - QCOMPARE(geom.vertexAt(last), d); - QCOMPARE(geom.normalAt(last), n4); - - // the first two nodes and the builder itself all reference the same - // geometry object, since they all have the same types: just vertices - // and normals. the last node has geometry with textures, so its in - // a different geometry object. - QVERIFY(node->geometry() == geom); - QVERIFY(node2->geometry() == geom); - QVERIFY(!(node3->geometry() == geom)); - - geom = node3->geometry(); - QGL::IndexArray ids2 = geom.indices(); - - int tri = ids2[node->start()]; - QCOMPARE(geom.vertexAt(tri), e); - QCOMPARE(geom.normalAt(tri), n10); - QCOMPARE(geom.texCoordAt(tri), ta); -} - -QTEST_APPLESS_MAIN(tst_QGLBuilder) - -#include "tst_qglbuilder.moc" diff --git a/tests/auto/threed/qglcamera/qglcamera.pro b/tests/auto/threed/qglcamera/qglcamera.pro deleted file mode 100644 index dfe16b82..00000000 --- a/tests/auto/threed/qglcamera/qglcamera.pro +++ /dev/null @@ -1,10 +0,0 @@ -load(qttest_p4.prf) -TEMPLATE=app -QT += testlib -CONFIG += unittest warn_on qt3d - -INCLUDEPATH += ../../../../threed/viewing -VPATH += ../../../../threed/viewing - -SOURCES += \ - tst_qglcamera.cpp diff --git a/tests/auto/threed/qglcamera/tst_qglcamera.cpp b/tests/auto/threed/qglcamera/tst_qglcamera.cpp deleted file mode 100644 index 2240a1b8..00000000 --- a/tests/auto/threed/qglcamera/tst_qglcamera.cpp +++ /dev/null @@ -1,327 +0,0 @@ -/**************************************************************************** -** -** 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 QtQuick3D module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** 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. -** -** 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. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include <QtTest/QtTest> -#include "qglcamera.h" - -class tst_QGLCamera : public QObject -{ - Q_OBJECT -public: - tst_QGLCamera() {} - ~tst_QGLCamera() {} - -private slots: - void create(); - void modify(); - void minViewSize(); - void translation_data(); - void translation(); - void rotate_data(); - void rotate(); -}; - -void tst_QGLCamera::create() -{ - // Test that a newly created object has the correct defaults. - QGLCamera camera; - QVERIFY(camera.projectionType() == QGLCamera::Perspective); - QCOMPARE(camera.fieldOfView(), (qreal)0.0f); - QCOMPARE(camera.nearPlane(), (qreal)5.0f); - QCOMPARE(camera.farPlane(), (qreal)1000.0f); - QCOMPARE(camera.viewSize(), QSizeF(2.0f, 2.0f)); - QCOMPARE(camera.minViewSize(), QSizeF(0.0001f, 0.0001f)); - QCOMPARE(camera.screenRotation(), 0); - QVERIFY(camera.eye() == QVector3D(0, 0, 10)); - QVERIFY(camera.upVector() == QVector3D(0, 1, 0)); - QVERIFY(camera.center() == QVector3D(0, 0, 0)); - QCOMPARE(camera.eyeSeparation(), (qreal)0.0f); - QVERIFY(camera.motionAdjustment() == QVector3D(0, 0, 1)); - QVERIFY(camera.adjustForAspectRatio()); -} - -void tst_QGLCamera::modify() -{ - // Test modifying each field individually. - QGLCamera camera; - QSignalSpy spy1(&camera, SIGNAL(projectionChanged())); - QSignalSpy spy2(&camera, SIGNAL(viewChanged())); - camera.setProjectionType(QGLCamera::Orthographic); - QVERIFY(camera.projectionType() == QGLCamera::Orthographic); - QCOMPARE(spy1.size(), 1); - camera.setFieldOfView(60.0f); - QCOMPARE(camera.fieldOfView(), (qreal)60.0f); - QCOMPARE(spy1.size(), 2); - camera.setNearPlane(-3.0f); - QCOMPARE(camera.nearPlane(), (qreal)-3.0f); - QCOMPARE(spy1.size(), 3); - camera.setFarPlane(3000.0f); - QCOMPARE(camera.farPlane(), (qreal)3000.0f); - QCOMPARE(spy1.size(), 4); - camera.setViewSize(QSizeF(45.0f, 25.5f)); - QCOMPARE(camera.viewSize(), QSizeF(45.0f, 25.5f)); - QCOMPARE(spy1.size(), 5); - camera.setMinViewSize(QSizeF(0.05f, 0.025f)); - QCOMPARE(camera.minViewSize(), QSizeF(0.05f, 0.025f)); - QCOMPARE(spy1.size(), 6); - camera.setScreenRotation(270); - QCOMPARE(camera.screenRotation(), 270); - QCOMPARE(spy1.size(), 7); - camera.setEye(QVector3D(1.0f, 2.0f, 3.0f)); - QVERIFY(camera.eye() == QVector3D(1.0f, 2.0f, 3.0f)); - QCOMPARE(spy2.size(), 1); - camera.setUpVector(QVector3D(4.0f, 5.0f, 6.0f)); - QVERIFY(camera.upVector() == QVector3D(4.0f, 5.0f, 6.0f)); - QCOMPARE(spy2.size(), 2); - camera.setCenter(QVector3D(7.0f, 8.0f, 9.0f)); - QVERIFY(camera.center() == QVector3D(7.0f, 8.0f, 9.0f)); - QCOMPARE(spy2.size(), 3); - camera.setEyeSeparation(3.0f); - QCOMPARE(camera.eyeSeparation(), (qreal)3.0f); - QCOMPARE(spy2.size(), 4); - camera.setMotionAdjustment(QVector3D(10.0f, 11.0f, 12.0f)); - QVERIFY(camera.motionAdjustment() == QVector3D(10.0f, 11.0f, 12.0f)); - QCOMPARE(spy2.size(), 5); - camera.setAdjustForAspectRatio(false); - QVERIFY(!camera.adjustForAspectRatio()); - QCOMPARE(spy2.size(), 6); - - // Test that we don't get any side effects between properties. - QVERIFY(camera.projectionType() == QGLCamera::Orthographic); - QCOMPARE(camera.fieldOfView(), (qreal)60.0f); - QCOMPARE(camera.nearPlane(), (qreal)-3.0f); - QCOMPARE(camera.farPlane(), (qreal)3000.0f); - QCOMPARE(camera.viewSize(), QSizeF(45.0f, 25.5f)); - QCOMPARE(camera.minViewSize(), QSizeF(0.05f, 0.025f)); - QCOMPARE(camera.screenRotation(), 270); - QVERIFY(camera.eye() == QVector3D(1.0f, 2.0f, 3.0f)); - QVERIFY(camera.upVector() == QVector3D(4.0f, 5.0f, 6.0f)); - QVERIFY(camera.center() == QVector3D(7.0f, 8.0f, 9.0f)); - QCOMPARE(camera.eyeSeparation(), (qreal)3.0f); - QVERIFY(camera.motionAdjustment() == QVector3D(10.0f, 11.0f, 12.0f)); - QVERIFY(!camera.adjustForAspectRatio()); - - // Test that changing to the same values does not emit any signals. - camera.setProjectionType(QGLCamera::Orthographic); - camera.setFieldOfView(60.0f); - camera.setNearPlane(-3.0f); - camera.setFarPlane(3000.0f); - camera.setViewSize(QSizeF(45.0f, 25.5f)); - camera.setMinViewSize(QSizeF(0.05f, 0.025f)); - camera.setScreenRotation(270); - camera.setEye(QVector3D(1.0f, 2.0f, 3.0f)); - camera.setUpVector(QVector3D(4.0f, 5.0f, 6.0f)); - camera.setCenter(QVector3D(7.0f, 8.0f, 9.0f)); - camera.setEyeSeparation(3.0f); - camera.setMotionAdjustment(QVector3D(10.0f, 11.0f, 12.0f)); - camera.setAdjustForAspectRatio(false); - QCOMPARE(spy1.size(), 7); - QCOMPARE(spy2.size(), 6); -} - -// Check that the minimum view size works correctly, including when -// the view size goes negative (e.g. for flipped y co-ordinates). -void tst_QGLCamera::minViewSize() -{ - QGLCamera camera; - camera.setMinViewSize(QSizeF(0.05f, 0.05f)); - QCOMPARE(camera.minViewSize(), QSizeF(0.05f, 0.05f)); - camera.setViewSize(QSizeF(-20.0f, -30.0f)); - QCOMPARE(camera.viewSize(), QSizeF(-20.0f, -30.0f)); - camera.setViewSize(QSizeF(0.0f, 1.0f)); - QCOMPARE(camera.viewSize(), QSizeF(0.05f, 1.0f)); - camera.setViewSize(QSizeF(-0.01f, 1.0f)); - QCOMPARE(camera.viewSize(), QSizeF(-0.05f, 1.0f)); - camera.setViewSize(QSizeF(-1.0f, 0.0f)); - QCOMPARE(camera.viewSize(), QSizeF(-1.0f, 0.05f)); - camera.setViewSize(QSizeF(-1.0f, -0.01f)); - QCOMPARE(camera.viewSize(), QSizeF(-1.0f, -0.05f)); -} - -static bool fuzzyCompare(const QVector3D &v1, const QVector3D &v2) -{ - if (qAbs(v1.x() - v2.x()) <= 0.00001 && - qAbs(v1.y() - v2.y()) <= 0.00001 && - qAbs(v1.z() - v2.z()) <= 0.00001) { - return true; - } - qWarning() << "actual:" << v1 << "expected:" << v2; - return false; -} - -static bool fuzzyCompare(const QQuaternion &q1, const QQuaternion &q2) -{ - if (qAbs(q1.x() - q2.x()) <= 0.00001 && - qAbs(q1.y() - q2.y()) <= 0.00001 && - qAbs(q1.z() - q2.z()) <= 0.00001 && - qAbs(q1.scalar() - q2.scalar()) <= 0.00001) { - return true; - } - qWarning() << "actual:" << q1 << "expected:" << q2; - return false; -} - -void tst_QGLCamera::translation_data() -{ - QTest::addColumn<QVector3D>("eye"); - QTest::addColumn<QVector3D>("upVector"); - QTest::addColumn<QVector3D>("center"); - - QTest::newRow("default") - << QVector3D(0, 0, 10) << QVector3D(0, 1, 0) << QVector3D(0, 0, 0); - QTest::newRow("random") - << QVector3D(2, -3, 5) << QVector3D(1, -1, 1) << QVector3D(-1, 6, -2); -} - -void tst_QGLCamera::translation() -{ - QFETCH(QVector3D, eye); - QFETCH(QVector3D, upVector); - QFETCH(QVector3D, center); - - QGLCamera camera; - camera.setEye(eye); - camera.setUpVector(upVector); - camera.setCenter(center); - - QVector3D viewVector = center - eye; - QVector3D sideVector = QVector3D::crossProduct(viewVector, upVector); - - QVector3D nup = upVector.normalized(); - QVector3D nview = viewVector.normalized(); - QVector3D nside = sideVector.normalized(); - - QVERIFY(fuzzyCompare(camera.translation(0, 0, 0), QVector3D(0, 0, 0))); - - QVERIFY(fuzzyCompare(camera.translation(2.5f, 0, 0), 2.5f * nside)); - QVERIFY(fuzzyCompare(camera.translation(0, -1.5f, 0), -1.5f * nup)); - QVERIFY(fuzzyCompare(camera.translation(0, 0, 2.0f), 2.0f * nview)); - - QVector3D t = camera.translation(2.5f, -1.5f, 2.0f); - QVERIFY(fuzzyCompare(t, 2.5f * nside - 1.5f * nup + 2.0f * nview)); - - camera.translateEye(2.5f, -1.5f, 2.0f); - QVERIFY(fuzzyCompare(camera.eye(), eye + t)); - QVERIFY(fuzzyCompare(camera.center(), center)); - QVERIFY(fuzzyCompare(camera.upVector(), upVector)); - - camera.setEye(eye); - - camera.translateCenter(2.5f, -1.5f, 2.0f); - QVERIFY(fuzzyCompare(camera.eye(), eye)); - QVERIFY(fuzzyCompare(camera.center(), center + t)); - QVERIFY(fuzzyCompare(camera.upVector(), upVector)); -} - -void tst_QGLCamera::rotate_data() -{ - translation_data(); -} - -void tst_QGLCamera::rotate() -{ - QFETCH(QVector3D, eye); - QFETCH(QVector3D, upVector); - QFETCH(QVector3D, center); - - QGLCamera camera; - camera.setEye(eye); - camera.setUpVector(upVector); - camera.setCenter(center); - - QVector3D viewVector = center - eye; - QVector3D sideVector = QVector3D::crossProduct(viewVector, upVector); - - QQuaternion tilt = camera.tilt(-30.0f); - QQuaternion pan = camera.pan(125.0f); - QQuaternion roll = camera.roll(45.0f); - - QVERIFY(fuzzyCompare(tilt, QQuaternion::fromAxisAndAngle(sideVector, -30.0f))); - QVERIFY(fuzzyCompare(pan, QQuaternion::fromAxisAndAngle(upVector, 125.0f))); - QVERIFY(fuzzyCompare(roll, QQuaternion::fromAxisAndAngle(viewVector, 45.0f))); - - QQuaternion combined = tilt * pan * roll; - camera.rotateEye(combined); - - QVERIFY(fuzzyCompare(camera.eye(), eye)); - QVERIFY(fuzzyCompare(camera.upVector(), combined.rotatedVector(upVector))); - QVERIFY(fuzzyCompare(camera.center(), eye + combined.rotatedVector(viewVector))); - - camera.setEye(eye); - camera.setUpVector(upVector); - camera.setCenter(center); - - camera.rotateCenter(combined); - QVERIFY(fuzzyCompare(camera.eye(), center - combined.rotatedVector(viewVector))); - QVERIFY(fuzzyCompare(camera.upVector(), combined.rotatedVector(upVector))); - QVERIFY(fuzzyCompare(camera.center(), center)); - -#define TestTiltPanRoll(order, combine) \ - do { \ - combined = combine; \ - camera.setEye(eye); \ - camera.setUpVector(upVector); \ - camera.setCenter(center); \ - camera.tiltPanRollEye(-30.0f, 125.0f, 45.0f, QGLCamera::order); \ - QVERIFY(fuzzyCompare(camera.eye(), eye)); \ - QVERIFY(fuzzyCompare(camera.upVector(), combined.rotatedVector(upVector))); \ - QVERIFY(fuzzyCompare(camera.center(), eye + combined.rotatedVector(viewVector))); \ - camera.setEye(eye); \ - camera.setUpVector(upVector); \ - camera.setCenter(center); \ - camera.tiltPanRollCenter(-30.0f, 125.0f, 45.0f, QGLCamera::order); \ - QVERIFY(fuzzyCompare(camera.eye(), center - combined.rotatedVector(viewVector))); \ - QVERIFY(fuzzyCompare(camera.upVector(), combined.rotatedVector(upVector))); \ - QVERIFY(fuzzyCompare(camera.center(), center)); \ - } while (0) - - // Quaternions are multiplied in the reverse order of applying them. - TestTiltPanRoll(TiltPanRoll, roll * pan * tilt); - TestTiltPanRoll(TiltRollPan, pan * roll * tilt); - TestTiltPanRoll(PanTiltRoll, roll * tilt * pan); - TestTiltPanRoll(PanRollTilt, tilt * roll * pan); - TestTiltPanRoll(RollTiltPan, pan * tilt * roll); - TestTiltPanRoll(RollPanTilt, tilt * pan * roll); -} - -QTEST_APPLESS_MAIN(tst_QGLCamera) - -#include "tst_qglcamera.moc" diff --git a/tests/auto/threed/qglcameraanimation/qglcameraanimation.pro b/tests/auto/threed/qglcameraanimation/qglcameraanimation.pro deleted file mode 100644 index b197daca..00000000 --- a/tests/auto/threed/qglcameraanimation/qglcameraanimation.pro +++ /dev/null @@ -1,9 +0,0 @@ -load(qttest_p4.prf) -TEMPLATE=app -QT += testlib -CONFIG += unittest warn_on qt3d - -INCLUDEPATH += ../../../../threed/viewing -VPATH += ../../../../threed/viewing - -SOURCES += tst_qglcameraanimation.cpp diff --git a/tests/auto/threed/qglcameraanimation/tst_qglcameraanimation.cpp b/tests/auto/threed/qglcameraanimation/tst_qglcameraanimation.cpp deleted file mode 100644 index 6a589755..00000000 --- a/tests/auto/threed/qglcameraanimation/tst_qglcameraanimation.cpp +++ /dev/null @@ -1,162 +0,0 @@ -/**************************************************************************** -** -** 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 QtQuick3D module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** 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. -** -** 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. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include <QtTest/QtTest> -#include "qglcameraanimation.h" -#include "qglcamera.h" - -class tst_QGLCameraAnimation : public QObject -{ - Q_OBJECT -public: - tst_QGLCameraAnimation() {} - ~tst_QGLCameraAnimation() {} - -private slots: - void properties(); - void animationStartEnd(); -}; - -// Will try to wait for the condition while allowing event processing -#define QTRY_VERIFY(__expr) \ - do { \ - const int __step = 50; \ - const int __timeout = 5000; \ - if (!(__expr)) { \ - QTest::qWait(0); \ - } \ - for (int __i = 0; __i < __timeout && !(__expr); __i+=__step) { \ - QTest::qWait(__step); \ - } \ - QVERIFY(__expr); \ - } while (0) - -// Will try to wait for the condition while allowing event processing -#define QTRY_COMPARE(__expr, __expected) \ - do { \ - const int __step = 50; \ - const int __timeout = 5000; \ - if ((__expr) != (__expected)) { \ - QTest::qWait(0); \ - } \ - for (int __i = 0; __i < __timeout && ((__expr) != (__expected)); __i+=__step) { \ - QTest::qWait(__step); \ - } \ - QCOMPARE(__expr, __expected); \ - } while (0) - -void tst_QGLCameraAnimation::properties() -{ - // Check the default property values. - QGLCameraAnimation anim; - QVERIFY(anim.camera() == 0); - QVERIFY(anim.startEye() == QVector3D(0.0f, 0.0f, 10.0f)); - QVERIFY(anim.startUpVector() == QVector3D(0.0f, 1.0f, 0.0f)); - QVERIFY(anim.startCenter() == QVector3D(0.0f, 0.0f, 0.0f)); - QVERIFY(anim.endEye() == QVector3D(0.0f, 0.0f, 10.0f)); - QVERIFY(anim.endUpVector() == QVector3D(0.0f, 1.0f, 0.0f)); - QVERIFY(anim.endCenter() == QVector3D(0.0f, 0.0f, 0.0f)); - QCOMPARE(anim.duration(), 250); - QVERIFY(anim.easingCurve() == QEasingCurve()); - - // Change the properties. - QGLCamera camera; - anim.setCamera(&camera); - anim.setStartEye(QVector3D(1, -2, 3)); - anim.setStartUpVector(QVector3D(-4, 5, -6)); - anim.setStartCenter(QVector3D(7, -8, 9)); - anim.setEndEye(QVector3D(-1, 2, -3)); - anim.setEndUpVector(QVector3D(4, -5, 6)); - anim.setEndCenter(QVector3D(-7, 8, -9)); - anim.setDuration(500); - anim.setEasingCurve(QEasingCurve::OutQuad); - - // Check that the properties have their new values. - QVERIFY(anim.camera() == &camera); - QVERIFY(anim.startEye() == QVector3D(1, -2, 3)); - QVERIFY(anim.startUpVector() == QVector3D(-4, 5, -6)); - QVERIFY(anim.startCenter() == QVector3D(7, -8, 9)); - QVERIFY(anim.endEye() == QVector3D(-1, 2, -3)); - QVERIFY(anim.endUpVector() == QVector3D(4, -5, 6)); - QVERIFY(anim.endCenter() == QVector3D(-7, 8, -9)); - QCOMPARE(anim.duration(), 500); - QVERIFY(anim.easingCurve() == QEasingCurve(QEasingCurve::OutQuad)); -} - -void tst_QGLCameraAnimation::animationStartEnd() -{ - QGLCameraAnimation anim; - QGLCamera camera; - QGLCamera camera2; - - anim.setCamera(&camera); - anim.setStartEye(QVector3D(1, -2, 3)); - anim.setStartUpVector(QVector3D(-4, 5, -6)); - anim.setStartCenter(QVector3D(7, -8, 9)); - anim.setEndEye(QVector3D(-1, 2, -3)); - anim.setEndUpVector(QVector3D(4, -5, 6)); - anim.setEndCenter(QVector3D(-7, 8, -9)); - anim.setDuration(1); - - // Verify the start state. - anim.start(); - QVERIFY(camera.eye() == anim.startEye()); - QVERIFY(camera.upVector() == anim.startUpVector()); - QVERIFY(camera.center() == anim.startCenter()); - - // Wait for the animation to end - QTRY_COMPARE(anim.state(), QAbstractAnimation::Stopped); - QVERIFY(camera.eye() == anim.endEye()); - QVERIFY(camera.upVector() == anim.endUpVector()); - QVERIFY(camera.center() == anim.endCenter()); - - // Zero duration animation instantly transitions to the end state. - anim.setCamera(&camera2); - anim.setDuration(0); - anim.start(); - QVERIFY(camera2.eye() == anim.endEye()); - QVERIFY(camera2.upVector() == anim.endUpVector()); - QVERIFY(camera2.center() == anim.endCenter()); -} - -QTEST_MAIN(tst_QGLCameraAnimation) - -#include "tst_qglcameraanimation.moc" diff --git a/tests/auto/threed/qglcolladafxeffectfactory/collada_cube.xml b/tests/auto/threed/qglcolladafxeffectfactory/collada_cube.xml deleted file mode 100644 index 85d30d58..00000000 --- a/tests/auto/threed/qglcolladafxeffectfactory/collada_cube.xml +++ /dev/null @@ -1,127 +0,0 @@ -<?xml version="1.0" encoding="utf-8"?> -<COLLADA xmlns="http://www.collada.org/2008/03/COLLADASchema" version="1.5.0"> - <asset> - <created>2005-11-14T02:16:38Z</created> - <modified>2005-11-15T11:36:38Z</modified> - <revision>1.0</revision> - </asset> - <library_effects> - <effect id="whitePhong"> - <profile_COMMON> - <technique sid="phong1"> - <phong> - <emission> - <color>0 0 0.3 1.0</color> - </emission> - <ambient> - <color>1.0 0 0 1.0</color> - </ambient> - <diffuse> - <color>0 1 0 1.0</color> - </diffuse> - <specular> - <color>1.0 1.0 1.0 1.0</color> - </specular> - <shininess> - <float>20.0</float> - </shininess> - <reflective> - <color>1.0 1.0 1.0 1.0</color> - </reflective> - <reflectivity> - <float>0.5</float> - </reflectivity> - <transparent> - <color>1.0 1.0 1.0 1.0</color> - </transparent> - <transparency> - <float>1.0</float> - </transparency> - </phong> - </technique> - </profile_COMMON> - </effect> - </library_effects> - <library_materials> - <material id="whiteMaterial"> - <instance_effect url="#whitePhong"/> - </material> - </library_materials> - <library_geometries> - <geometry id="box" name="box"> - <mesh> - <source id="box-Pos"> - <float_array id="box-Pos-array" count="24"> - -0.5 0.5 0.5 - 0.5 0.5 0.5 - -0.5 -0.5 0.5 - 0.5 -0.5 0.5 - -0.5 0.5 -0.5 - 0.5 0.5 -0.5 - -0.5 -0.5 -0.5 - 0.5 -0.5 -0.5 - </float_array> - <technique_common> - <accessor source="#box-Pos-array" count="8" stride="3"> - <param name="X" type="float" /> - <param name="Y" type="float" /> - <param name="Z" type="float" /> - </accessor> - </technique_common> - </source> - <source id="box-0-Normal"> - <float_array id="box-0-Normal-array" count="18"> - 1.0 0.0 0.0 - -1.0 0.0 0.0 - 0.0 1.0 0.0 - 0.0 -1.0 0.0 - 0.0 0.0 1.0 - 0.0 0.0 -1.0 - </float_array> - <technique_common> - <accessor source="#box-0-Normal-array" count="6" stride="3"> - <param name="X" type="float"/> - <param name="Y" type="float"/> - <param name="Z" type="float"/> - </accessor> - </technique_common> - </source> - <vertices id="box-Vtx"> - <input semantic="POSITION" source="#box-Pos"/> - </vertices> - <polygons count="6" material="WHITE"> - <input semantic="VERTEX" source="#box-Vtx" offset="0"/> - <input semantic="NORMAL" source="#box-0-Normal" offset="1"/> - <p>0 4 2 4 3 4 1 4</p> - <p>0 2 1 2 5 2 4 2</p> - <p>6 3 7 3 3 3 2 3</p> - <p>0 1 4 1 6 1 2 1</p> - <p>3 0 7 0 5 0 1 0</p> - <p>5 5 7 5 6 5 4 5</p> - </polygons> - </mesh> - </geometry> - </library_geometries> - <library_visual_scenes> - <visual_scene id="DefaultScene"> - <node id="Box" name="Box"> - <translate> 0 0 0</translate> - <rotate> 0 0 1 0</rotate> - <rotate> 0 1 0 0</rotate> - <rotate> 1 0 0 0</rotate> - <scale> 1 1 1</scale> - <instance_geometry url="#box"> - <bind_material> - <technique_common> - <instance_material symbol="WHITE" target="#whiteMaterial"/> - </technique_common> - </bind_material> - </instance_geometry> - </node> - </visual_scene> - </library_visual_scenes> - <scene> - <instance_visual_scene url="#DefaultScene"/> - </scene> -</COLLADA> - diff --git a/tests/auto/threed/qglcolladafxeffectfactory/qglcolladafxeffectfactory.pro b/tests/auto/threed/qglcolladafxeffectfactory/qglcolladafxeffectfactory.pro deleted file mode 100644 index 05540601..00000000 --- a/tests/auto/threed/qglcolladafxeffectfactory/qglcolladafxeffectfactory.pro +++ /dev/null @@ -1,13 +0,0 @@ -load(qttest_p4.prf) -TEMPLATE = app -QT += testlib -CONFIG += unittest warn_on qt3d - -INCLUDEPATH += ../../../../demos/shaderwizard/ -VPATH += ../../../../demos/shaderwizard/ - -SOURCES += \ - tst_qglcolladafxeffectfactory.cpp - -OTHER_FILES += collada_cube.xml -RESOURCES += tst_qglcolladafxeffectfactory.qrc diff --git a/tests/auto/threed/qglcolladafxeffectfactory/rose01.jpg b/tests/auto/threed/qglcolladafxeffectfactory/rose01.jpg Binary files differdeleted file mode 100644 index e65d975b..00000000 --- a/tests/auto/threed/qglcolladafxeffectfactory/rose01.jpg +++ /dev/null diff --git a/tests/auto/threed/qglcolladafxeffectfactory/tst_qglcolladafxeffectfactory.cpp b/tests/auto/threed/qglcolladafxeffectfactory/tst_qglcolladafxeffectfactory.cpp deleted file mode 100644 index b60f122b..00000000 --- a/tests/auto/threed/qglcolladafxeffectfactory/tst_qglcolladafxeffectfactory.cpp +++ /dev/null @@ -1,312 +0,0 @@ -/**************************************************************************** -** -** 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 QtQuick3D module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** 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. -** -** 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. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include <QtTest/QtTest> -#include "qglcolladafxeffectfactory.h" -#include <QXmlStreamReader> -#include <QColor> -#include "qgl.h" - -QT_BEGIN_NAMESPACE -class QGLColladaFxEffect; -QT_END_NAMESPACE - -Q_DECLARE_METATYPE(QGLColladaFxEffect*) - -static void cleanupEffectList(QList<QGLColladaFxEffect*> &effects) -{ - while (effects.count()) - { - delete effects.back(); - effects.pop_back(); - } -} - - - -// Inherit from QGLColladaFxEffectFactory to get access to it's innards -class tst_QGLColladaFxEffectFactory : public QObject, QGLColladaFxEffectFactory -{ - Q_OBJECT -public: - tst_QGLColladaFxEffectFactory() {} - ~tst_QGLColladaFxEffectFactory() {} - -private slots: - void create_data(); - void create(); - void processFloatList_data(); - void processFloatList(); - void processFloatListArray_data(); - void processFloatListArray(); - void processColorElement_data(); - void processColorElement(); - void processLibraryImagesElement(); - void loadEffectsFromFile(); - void exportImportEffect_data(); - void exportImportEffect(); -}; - - - -void tst_QGLColladaFxEffectFactory::create_data() -{ - QTest::addColumn<QString>("fileName"); - QTest::addColumn<int>("effectCount"); - - QTest::newRow("null") << "" << 0; - QTest::newRow("nonexistent file") << "nonexistentfile.dae" << 0; - QTest::newRow("collada cube example") << ":/collada_cube.xml" << 1; -} - - - -void tst_QGLColladaFxEffectFactory::create() -{ - QFETCH(QString, fileName); - QFETCH(int, effectCount); - - QList<QGLColladaFxEffect*> effects = QGLColladaFxEffectFactory::loadEffectsFromFile(fileName); - QCOMPARE(effects.count(), effectCount); - cleanupEffectList(effects); -} - - - -void tst_QGLColladaFxEffectFactory::processFloatList_data() -{ - QTest::addColumn<QString>("xmlString"); - QTest::addColumn<QVariant >("expectedResult"); - - QTest::newRow("null") << "" << QVariant(); - - QVariant expectedSingleResult = 0.456f; - QTest::newRow("single_float") << "<floats>0.456</floats>" << expectedSingleResult; - - QVariant expectedPrecisionResult = 1.234567f; - QTest::newRow("seven digit accuracy") << "<floats>1.234567</floats>" << expectedPrecisionResult; - - QVariant expected3Dresult = QVector3D(0.0f, 0.3f, 6.6f); - QTest::newRow("3 floats to vector 3D") << "<floats>0.0 0.3 6.6</floats>" << expected3Dresult; - - QVariant expected4DResult = QVector4D(0.0f, 1.1f, 2.2f, 3.3f); - QTest::newRow("4 floats to vector 4D") << "<floats>0.0 1.1 2.2 3.3</floats>" << expected4DResult; - - QVariant expectedColorResult = QVector4D(0.0f, 1.1f, 2.2f, 3.3f); - QTest::newRow("4 float color to vector 4D") << "<color>0.0 1.1 2.2 3.3</color>" << expectedColorResult; -} - - - -void tst_QGLColladaFxEffectFactory::processFloatList() -{ - QFETCH(QString, xmlString); - QFETCH(QVariant, expectedResult); - - QXmlStreamReader xml(xmlString); - - xml.readNext(); // startDocument - xml.readNext(); - - QVariant result = QGLColladaFxEffectFactory::processFloatList( xml ); - - QCOMPARE(result, expectedResult); -} - -void tst_QGLColladaFxEffectFactory::processFloatListArray_data() -{ - QTest::addColumn<QString>("xmlString"); - QTest::addColumn<QArray<float> >("expectedResult"); - - QArray<float> expectedSevenDigitArray; - expectedSevenDigitArray << 1234567.0f << 1.234567f << 76.54321f << 1111.111f << 22222.22f << 7645213.0f; - QTest::newRow("seven_digits") << "<floats>1234567.0 1.234567 76.54321 1111.111 22222.22 7645213.0</floats>" << expectedSevenDigitArray; - -} - -void tst_QGLColladaFxEffectFactory::processFloatListArray() -{ - QFETCH(QString, xmlString); - QFETCH(QArray<float>, expectedResult); - - QXmlStreamReader xml(xmlString); - - xml.readNext(); // startDocument - xml.readNext(); - - QArray<float> result = QGLColladaFxEffectFactory::processFloatList( xml ).value<QArray<float> >(); - - QCOMPARE(result, expectedResult); - -} - -void tst_QGLColladaFxEffectFactory::processColorElement_data() -{ - QTest::addColumn<QString>("xmlString"); - QTest::addColumn<QColor>("expectedResult"); - - QColor errorColor = QColor(0, 0, 0, 255); - QTest::newRow("null") << "" << errorColor; - - QColor expectedColor3dResult = QColor::fromRgbF(0.0f, 0.4f, 0.8f); - QTest::newRow("color 3 floats") << "<color>0.0 0.4 0.8</color>" << expectedColor3dResult; - - QColor expectedColor4dResult = QColor::fromRgbF(0.0f, 0.2f, 0.4f, 0.8f); - QTest::newRow("color 4 floats") << "<color>0.0 0.2 0.4 0.8</color>" << expectedColor4dResult; - - QTest::newRow("malformed color 1 float") << "<color>0.5</color>" << errorColor; - QTest::newRow("malformed color 2 float") << "<color>0.1 0.7</color>" << errorColor; - QTest::newRow("malformed color 5 float") << "<color>0.1 0.2 0.3 0.4 0.5</color>" << errorColor; -} - - - -void tst_QGLColladaFxEffectFactory::processColorElement() -{ - QFETCH(QString, xmlString); - QFETCH(QColor, expectedResult); - - QXmlStreamReader xml(xmlString); - - xml.readNext(); // startDocument - xml.readNext(); - - QColor result = QGLColladaFxEffectFactory::processColorElement( xml ); - QCOMPARE(result, expectedResult); -} - - -void tst_QGLColladaFxEffectFactory::processLibraryImagesElement() -{ - // Example from Collada Fx 1.4 (escapes and ':' character added): - QXmlStreamReader xml("<library_images>\ - <image name=\"Rose\">\ - <init_from>\ - :../flowers/rose01.jpg\ - </init_from>\ - </image>\ - </library_images>"); - - xml.readNext(); // startDocument - xml.readNext(); - - ResultState state; - QGLColladaFxEffectFactory::processLibraryImagesElement( xml, &state ); - - // The structure is just an implementation detail, but the param and image - // should be well formed: - QVariant param = state.paramNames.values().at(0); - QCOMPARE(param.type(), QVariant::Image); - QCOMPARE(state.paramNames.value(QLatin1String("Rose")), param); - QImage image = param.value<QImage>(); - QCOMPARE(image.size(), QSize(50,75)); -} - -void tst_QGLColladaFxEffectFactory::loadEffectsFromFile() -{ - QList<QGLColladaFxEffect*> cubeResult = - QGLColladaFxEffectFactory::loadEffectsFromFile(QLatin1String(":/collada_cube.xml")); - - QCOMPARE(cubeResult.count(), 1); - - QGLColladaFxEffect* cubeEffect = cubeResult.at(0); - - QEXPECT_FAIL("", "Missing functionality", Continue); - QCOMPARE(cubeEffect->id(), QLatin1String("whitePhong")); - - QCOMPARE(cubeEffect->sid(), QLatin1String("phong1")); - QVERIFY2(cubeEffect->material()->emittedLight() == - QColor::fromRgbF(0.0f, 0.0f, 0.3f, 1.0f), "Emission color doesn't match"); - QVERIFY2(cubeEffect->material()->ambientColor() == - QColor::fromRgbF(1.0f, 0.0f, 0.0f, 1.0f), "Ambient color doesn't match"); - QVERIFY2(cubeEffect->material()->diffuseColor() == QColor::fromRgbF(0.0f, 1.0f, 0.0f, 1.0f), - "Diffuse color doesn't match"); - QVERIFY2(cubeEffect->material()->specularColor() == - QColor::fromRgbF(1.0f, 1.0f, 1.0f, 1.0f), - "Specular color doesn't match"); - QVERIFY2(cubeEffect->material()->shininess() == 20, "Shininess doesn't match"); -} - -void tst_QGLColladaFxEffectFactory::exportImportEffect_data() -{ - QTest::addColumn<QGLColladaFxEffect*>("effect"); - QTest::addColumn<QString>("effectId"); - QTest::addColumn<QString>("techniqueSid"); - - QGLColladaFxEffect* effect = new QGLColladaFxEffect; - QTest::newRow("empty effect") << effect << QString::fromLatin1("EmptyEffect") << QString::fromLatin1("EmptyTechnique"); - - effect = new QGLColladaFxEffect; - effect->setFragmentShader("test fragment shader"); - effect->setVertexShader("Test vertex shader"); - QGLMaterial* material = new QGLMaterial; - material->setAmbientColor(QColor(1,2,3)); - material->setDiffuseColor(QColor(2,3,4)); - material->setEmittedLight(QColor(255,255,255)); - material->setShininess(129); - material->setSpecularColor(QColor(3,4,5)); - effect->setMaterial(material); - - QTest::newRow("Test Effect") << effect << QString::fromLatin1("TestEffect") << QString::fromLatin1("TestTechnique"); -} - -void tst_QGLColladaFxEffectFactory::exportImportEffect() -{ - QFETCH(QGLColladaFxEffect*, effect); - QFETCH(QString, effectId); - QFETCH(QString, techniqueSid); - QString colladaEffectString = QGLColladaFxEffectFactory::exportEffect(effect, effectId, techniqueSid); - QXmlStreamReader xml(colladaEffectString); - - QList<QGLColladaFxEffect*> importedEffects = QGLColladaFxEffectFactory::loadEffectsFromXml(xml); - QCOMPARE(importedEffects.count(), 1); - - QGLColladaFxEffect* importedEffect = importedEffects[0]; - QCOMPARE(effect->fragmentShader(), importedEffect->fragmentShader()); - QCOMPARE(effect->vertexShader(), importedEffect->vertexShader()); - QEXPECT_FAIL("Test Effect", "QGLColladaFxEffect import/export does not respect materials", Continue); - QCOMPARE(effect->material(), importedEffect->material()); - QCOMPARE(effect->supportsPicking(), importedEffect->supportsPicking()); -} - -QTEST_APPLESS_MAIN(tst_QGLColladaFxEffectFactory) - -#include "tst_qglcolladafxeffectfactory.moc" diff --git a/tests/auto/threed/qglcolladafxeffectfactory/tst_qglcolladafxeffectfactory.qrc b/tests/auto/threed/qglcolladafxeffectfactory/tst_qglcolladafxeffectfactory.qrc deleted file mode 100644 index 8d4efc40..00000000 --- a/tests/auto/threed/qglcolladafxeffectfactory/tst_qglcolladafxeffectfactory.qrc +++ /dev/null @@ -1,8 +0,0 @@ -<RCC> - <qresource prefix="/"> - <file>collada_cube.xml</file> - </qresource> - <qresource prefix="/../flowers"> - <file>rose01.jpg</file> - </qresource> -</RCC> diff --git a/tests/auto/threed/qglcube/qglcube.pro b/tests/auto/threed/qglcube/qglcube.pro deleted file mode 100644 index 4153abf2..00000000 --- a/tests/auto/threed/qglcube/qglcube.pro +++ /dev/null @@ -1,7 +0,0 @@ -load(qttest_p4.prf) -TEMPLATE=app -QT += testlib -CONFIG += unittest warn_on qt3d - -INCLUDEPATH += ../../../shared -SOURCES += tst_qglcube.cpp diff --git a/tests/auto/threed/qglcube/tst_qglcube.cpp b/tests/auto/threed/qglcube/tst_qglcube.cpp deleted file mode 100644 index d43fb44c..00000000 --- a/tests/auto/threed/qglcube/tst_qglcube.cpp +++ /dev/null @@ -1,185 +0,0 @@ -/**************************************************************************** -** -** 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 QtQuick3D module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** 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. -** -** 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. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include <QtTest/QtTest> - -#include "qglcube.h" -#include "qglbuilder.h" -#include "qtest_helpers.h" - -class tst_QGLCube : public QObject -{ - Q_OBJECT -public: - tst_QGLCube() {} - ~tst_QGLCube() {} - -private slots: - void create(); - void size(); -}; - -#define QGL_CUBE_SIZE (6 * 6 * (3 + 3 + 2)) -static float const cubeVertices[QGL_CUBE_SIZE] = { - -0.5f, -0.5f, -0.5f, -1.0f, 0.0f, 0.0f, 0.0f, 0.0f, - -0.5f, -0.5f, 0.5f, -1.0f, 0.0f, 0.0f, 1.0f, 0.0f, - -0.5f, 0.5f, 0.5f, -1.0f, 0.0f, 0.0f, 1.0f, 1.0f, - -0.5f, -0.5f, -0.5f, -1.0f, 0.0f, 0.0f, 0.0f, 0.0f, - -0.5f, 0.5f, 0.5f, -1.0f, 0.0f, 0.0f, 1.0f, 1.0f, - -0.5f, 0.5f, -0.5f, -1.0f, 0.0f, 0.0f, 0.0f, 1.0f, - - -0.5f, 0.5f, -0.5f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, - -0.5f, 0.5f, 0.5f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, - 0.5f, 0.5f, 0.5f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f, - -0.5f, 0.5f, -0.5f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, - 0.5f, 0.5f, 0.5f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f, - 0.5f, 0.5f, -0.5f, 0.0f, 1.0f, 0.0f, 1.0f, 1.0f, - - 0.5f, 0.5f, -0.5f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f, - 0.5f, 0.5f, 0.5f, 1.0f, 0.0f, 0.0f, 0.0f, 1.0f, - 0.5f, -0.5f, 0.5f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, - 0.5f, 0.5f, -0.5f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f, - 0.5f, -0.5f, 0.5f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, - 0.5f, -0.5f, -0.5f, 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, - - 0.5f, -0.5f, -0.5f, 0.0f, -1.0f, 0.0f, 1.0f, 0.0f, - 0.5f, -0.5f, 0.5f, 0.0f, -1.0f, 0.0f, 1.0f, 1.0f, - -0.5f, -0.5f, 0.5f, 0.0f, -1.0f, 0.0f, 0.0f, 1.0f, - 0.5f, -0.5f, -0.5f, 0.0f, -1.0f, 0.0f, 1.0f, 0.0f, - -0.5f, -0.5f, 0.5f, 0.0f, -1.0f, 0.0f, 0.0f, 1.0f, - -0.5f, -0.5f, -0.5f, 0.0f, -1.0f, 0.0f, 0.0f, 0.0f, - - 0.5f, -0.5f, 0.5f, 0.0f, 0.0f, 1.0f, 1.0f, 0.0f, - 0.5f, 0.5f, 0.5f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f, - -0.5f, 0.5f, 0.5f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, - 0.5f, -0.5f, 0.5f, 0.0f, 0.0f, 1.0f, 1.0f, 0.0f, - -0.5f, 0.5f, 0.5f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, - -0.5f, -0.5f, 0.5f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, - - 0.5f, 0.5f, -0.5f, 0.0f, 0.0f, -1.0f, 0.0f, 1.0f, - 0.5f, -0.5f, -0.5f, 0.0f, 0.0f, -1.0f, 0.0f, 0.0f, - -0.5f, -0.5f, -0.5f, 0.0f, 0.0f, -1.0f, 1.0f, 0.0f, - 0.5f, 0.5f, -0.5f, 0.0f, 0.0f, -1.0f, 0.0f, 1.0f, - -0.5f, -0.5f, -0.5f, 0.0f, 0.0f, -1.0f, 1.0f, 0.0f, - -0.5f, 0.5f, -0.5f, 0.0f, 0.0f, -1.0f, 1.0f, 1.0f -}; - -static int findVertex(const QGeometryData &ary, const QVector3D &v, const QVector3D &n) -{ - int result = -1; - for (int i = 0; i < ary.count() && result == -1; ++i) - { - if (qFuzzyCompare(v, ary.vertexAt(i)) && qFuzzyCompare(n, ary.normalAt(i))) - result = i; - } - if (result == -1) - { - qDebug() << "Could not find expected vertex" << v << "with normal" << n; - } - return result; -} - -void tst_QGLCube::create() -{ - QGLCube cube; - QGLBuilder list; - list.newSection(QGL::Faceted); - QGLSceneNode *node = list.currentNode(); - list << cube; - QGLSceneNode *root = list.finalizedSceneNode(); - QGeometryData ary = node->geometry(); - for (int i = 0; i < QGL_CUBE_SIZE; i += 8) - { - const QVector3D *vdata = reinterpret_cast<const QVector3D*>(cubeVertices + i); - const QVector2D *tdata = reinterpret_cast<const QVector2D*>(cubeVertices + i + 6); - int ix = findVertex(ary, vdata[0], vdata[1]); - QVERIFY(ix != -1); - QCOMPARE(ary.texCoordAt(ix), tdata[0]); - } - delete root; -} - -void tst_QGLCube::size() -{ - qreal size0 = 3.2f; - qreal size1 = 5.2f; - QGLCube cube(size0); - QCOMPARE(cube.size(), size0); - { - QGLBuilder list; - list.newSection(QGL::Faceted); - QGLSceneNode *node = list.currentNode(); - list << cube; - QGLSceneNode *root = list.finalizedSceneNode(); - QGeometryData ary = node->geometry(); - for (int i = 0, v = 0; i < QGL_CUBE_SIZE; ++v, i += 8) - { - const QVector3D *vdata = reinterpret_cast<const QVector3D*>(cubeVertices + i); - const QVector2D *tdata = reinterpret_cast<const QVector2D*>(cubeVertices + i + 6); - int ix = findVertex(ary, vdata[0] * size0, vdata[1]); - QVERIFY(ix != -1); - QCOMPARE(ary.texCoordAt(ix), tdata[0]); - } - delete root; - } - cube.setSize(size1); - { - QGLBuilder list; - list.newSection(QGL::Faceted); - QGLSceneNode *node = list.currentNode(); - list << cube; - QGLSceneNode *root = list.finalizedSceneNode(); - QGeometryData ary = node->geometry(); - for (int i = 0, v = 0; i < QGL_CUBE_SIZE; ++v, i += 8) - { - const QVector3D *vdata = reinterpret_cast<const QVector3D*>(cubeVertices + i); - const QVector2D *tdata = reinterpret_cast<const QVector2D*>(cubeVertices + i + 6); - int ix = findVertex(ary, vdata[0] * size1, vdata[1]); - QVERIFY(ix != -1); - QCOMPARE(ary.texCoordAt(ix), tdata[0]); - } - delete root; - } -} - -QTEST_APPLESS_MAIN(tst_QGLCube) - -#include "tst_qglcube.moc" diff --git a/tests/auto/threed/qglcylinder/qglcylinder.pro b/tests/auto/threed/qglcylinder/qglcylinder.pro deleted file mode 100644 index c8f6e42f..00000000 --- a/tests/auto/threed/qglcylinder/qglcylinder.pro +++ /dev/null @@ -1,7 +0,0 @@ -load(qttest_p4.prf) -TEMPLATE=app -QT += testlib -CONFIG += unittest warn_on qt3d - -INCLUDEPATH += ../../../shared -SOURCES += tst_qglcylinder.cpp diff --git a/tests/auto/threed/qglcylinder/tst_qglcylinder.cpp b/tests/auto/threed/qglcylinder/tst_qglcylinder.cpp deleted file mode 100644 index ba6da836..00000000 --- a/tests/auto/threed/qglcylinder/tst_qglcylinder.cpp +++ /dev/null @@ -1,283 +0,0 @@ -/**************************************************************************** -** -** 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 QtQuick3D module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** 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. -** -** 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. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include <QtTest/QtTest> - -#include "qglcylinder.h" -#include "qglbuilder.h" - -class tst_QGLCylinder : public QObject -{ - Q_OBJECT -public: - tst_QGLCylinder() {} - ~tst_QGLCylinder() {} - -private slots: - void create(); - void modify(); - void build(); - -private: - bool validateCylinder(QGLSceneNode *node, qreal topDiameter, qreal baseDiameter, qreal height, bool top, bool base); -}; - -void tst_QGLCylinder::create() -{ - //Test all possible constructor parameters to ensure they are actually - //setting the correct values. - - //Defaults - QGLCylinder cylinder1; - QCOMPARE(cylinder1.diameterTop(), qreal(1.0f)); - QCOMPARE(cylinder1.diameterBottom(), qreal(1.0f)); - QCOMPARE(cylinder1.height(), qreal(1.0f)); - QCOMPARE(cylinder1.slices(), 6); - QCOMPARE(cylinder1.layers(), 3); - QCOMPARE(cylinder1.topEnabled(), true); - QCOMPARE(cylinder1.baseEnabled(), true); - - //Top diameter - QGLCylinder cylinder2(0.5f); - QCOMPARE(cylinder2.diameterTop(), qreal(0.5f)); - QCOMPARE(cylinder2.diameterBottom(), qreal(1.0f)); - QCOMPARE(cylinder2.height(), qreal(1.0f)); - QCOMPARE(cylinder2.slices(), 6); - QCOMPARE(cylinder2.layers(), 3); - QCOMPARE(cylinder2.topEnabled(), true); - QCOMPARE(cylinder2.baseEnabled(), true); - - //Top and Bottom diameter - QGLCylinder cylinder3(0.5f, 1.5f); - QCOMPARE(cylinder3.diameterTop(), qreal(0.5f)); - QCOMPARE(cylinder3.diameterBottom(), qreal(1.5f)); - QCOMPARE(cylinder3.height(), qreal(1.0f)); - QCOMPARE(cylinder3.slices(), 6); - QCOMPARE(cylinder3.layers(), 3); - QCOMPARE(cylinder3.topEnabled(), true); - QCOMPARE(cylinder3.baseEnabled(), true); - - //Top & Bottom diameter, Height - QGLCylinder cylinder4(0.5f, 1.5f, 3.0f); - QCOMPARE(cylinder4.diameterTop(), qreal(0.5f)); - QCOMPARE(cylinder4.diameterBottom(), qreal(1.5f)); - QCOMPARE(cylinder4.height(), qreal(3.0f)); - QCOMPARE(cylinder4.slices(), 6); - QCOMPARE(cylinder4.layers(), 3); - QCOMPARE(cylinder4.topEnabled(), true); - QCOMPARE(cylinder4.baseEnabled(), true); - - //Top & Bottom diameter, Height, Slices - QGLCylinder cylinder5(0.5f, 1.5f, 3.0f, 10); - QCOMPARE(cylinder5.diameterTop(), qreal(0.5f)); - QCOMPARE(cylinder5.diameterBottom(), qreal(1.5f)); - QCOMPARE(cylinder5.height(), qreal(3.0f)); - QCOMPARE(cylinder5.slices(), 10); - QCOMPARE(cylinder5.layers(), 3); - QCOMPARE(cylinder5.topEnabled(), true); - QCOMPARE(cylinder5.baseEnabled(), true); - - //Top & Bottom diameter, Height, Slices, Layers - QGLCylinder cylinder6(0.5f, 1.5f, 3.0f, 10, 5); - QCOMPARE(cylinder6.diameterTop(), qreal(0.5f)); - QCOMPARE(cylinder6.diameterBottom(), qreal(1.5f)); - QCOMPARE(cylinder6.height(), qreal(3.0f)); - QCOMPARE(cylinder6.slices(), 10); - QCOMPARE(cylinder6.layers(), 5); - QCOMPARE(cylinder6.topEnabled(), true); - QCOMPARE(cylinder6.baseEnabled(), true); - - //Top & Bottom diameter, Height, Slices, Layers, Top disabled - QGLCylinder cylinder7(0.5f, 1.5f, 3.0f, 10, 5, false); - QCOMPARE(cylinder7.diameterTop(), qreal(0.5f)); - QCOMPARE(cylinder7.diameterBottom(), qreal(1.5f)); - QCOMPARE(cylinder7.height(), qreal(3.0f)); - QCOMPARE(cylinder7.slices(), 10); - QCOMPARE(cylinder7.layers(), 5); - QCOMPARE(cylinder7.topEnabled(), false); - QCOMPARE(cylinder7.baseEnabled(), true); - - //Top & Bottom diameter, Height, Slices, Layers, Top disabled, Bottom disabled. - QGLCylinder cylinder8(0.5f, 1.5f, 3.0f, 10, 5, false, false); - QCOMPARE(cylinder8.diameterTop(), qreal(0.5f)); - QCOMPARE(cylinder8.diameterBottom(), qreal(1.5f)); - QCOMPARE(cylinder8.height(), qreal(3.0f)); - QCOMPARE(cylinder8.slices(), 10); - QCOMPARE(cylinder8.layers(), 5); - QCOMPARE(cylinder8.topEnabled(), false); - QCOMPARE(cylinder8.baseEnabled(), false); -} - -void tst_QGLCylinder::modify() -{ - //Modify all sphere parameters to ensure they're working. - QGLCylinder cylinder1; - - cylinder1.setDiameterTop(0.5f); - QCOMPARE(cylinder1.diameterTop(), qreal(0.5f)); - - cylinder1.setDiameterBottom(1.5f); - QCOMPARE(cylinder1.diameterBottom(), qreal(1.5f)); - - cylinder1.setHeight(3.0f); - QCOMPARE(cylinder1.height(), qreal(3.0f)); - - cylinder1.setSlices(10); - QCOMPARE(cylinder1.slices(), 10); - - cylinder1.setLayers(5); - QCOMPARE(cylinder1.layers(), 5); - - cylinder1.setTopEnabled(false); - QCOMPARE(cylinder1.topEnabled(), false); - - cylinder1.setBaseEnabled(false); - QCOMPARE(cylinder1.baseEnabled(), false); -} - -// Validates the geometry in a cylinder node to check that all vertices -// on the top and bottom are at the correct height, and that all normals -// are of length 1. It also ensures that all points are within the defined -// top and bottom diameters for the cylinder. -bool tst_QGLCylinder::validateCylinder(QGLSceneNode *node, qreal topDiameter, qreal baseDiameter, qreal height, bool topAttached, bool baseAttached) -{ - QGLSceneNode *lid = node->findChild<QGLSceneNode *>("Cylinder Top"); - QGLSceneNode *sides = node->findChild<QGLSceneNode *>("Cylinder Sides"); - QGLSceneNode *base = node->findChild<QGLSceneNode *>("Cylinder Base"); - - //Top of the cylinder - test the normals and vertical position - if (topAttached) - { - if (!lid) { - return false; - } - - QGeometryData dataTop = lid->geometry(); - int start = lid->start(); - int count = lid->count(); - - if (count <= 0) { - return false; - } - QGL::IndexArray indices = dataTop.indices(); - - for (int index = 0; index < count; ++index) { - QVector3D v = dataTop.vertexAt(indices.at(index + start)); - QVector3D n = dataTop.normalAt(indices.at(index + start)); - if (v.z()!=height) { - return false; - } - QVector2D p(v.x(), v.y()); - if (qAbs(p.length())>(topDiameter/2.0)) { - return false; - } - if (qAbs(n.length() - 1.0f) >= 0.0001) { - return false; - } - } - } - - //Base of the cylinder - test the normals and vertical position - if (baseAttached) - { - if (!base) - return false; - QGeometryData dataBase = sides->geometry(); - int start = sides->start(); - int count = sides->count(); - if (count <= 0) - return false; - QGL::IndexArray indices = dataBase.indices(); - for (int index = 0; index < count; ++index) { - QVector3D v = dataBase.vertexAt(indices.at(index + start)); - QVector3D n = dataBase.normalAt(indices.at(index + start)); - QVector2D p(v.x(), v.y()); - if (qAbs(p.length())>(baseDiameter/2.0)) { - return false; - } - if (qAbs(n.length() - 1.0f) >= 0.0001) { - return false; - } - } - } - - //Sides of the cylinder - just a basic test of the normals here. - if (!sides) { - return false; - } - QGeometryData dataSides = sides->geometry(); - int start = sides->start(); - int count = sides->count(); - - if (count <= 0) { - return false; - } - QGL::IndexArray indices = dataSides.indices(); - for (int index = 0; index < count; ++index) { - QVector3D n = dataSides.normalAt(indices.at(index + start)); - if (qAbs(n.length() - 1.0f) >= 0.0001) { - return false; - } - } - - //If we've made it this far, we must have passed the test. - return true; - -} - -void tst_QGLCylinder::build() -{ - QGLBuilder builder1; - builder1 << QGLCylinder(0.5f, 1.5f, 3.0f); - QGLSceneNode *root1 = builder1.finalizedSceneNode(); - QVERIFY(validateCylinder(root1, 0.5f, 1.5f, 3.0f, true, true)); - delete root1; - - QGLBuilder builder2; - builder2 << QGLCylinder(0.5f, 1.5f, 3.0f, 6,3,false, false); - QGLSceneNode *root2 = builder2.finalizedSceneNode(); - QVERIFY(validateCylinder(root2, 0.5f, 1.5f, 3.0f, false, false)); - delete root2; -} - -QTEST_APPLESS_MAIN(tst_QGLCylinder) - -#include "tst_qglcylinder.moc" diff --git a/tests/auto/threed/qglindexbuffer/qglindexbuffer.pro b/tests/auto/threed/qglindexbuffer/qglindexbuffer.pro deleted file mode 100644 index ede0e40c..00000000 --- a/tests/auto/threed/qglindexbuffer/qglindexbuffer.pro +++ /dev/null @@ -1,6 +0,0 @@ -load(qttest_p4.prf) -TEMPLATE=app -QT += testlib -CONFIG += unittest warn_on qt3d - -SOURCES += tst_qglindexbuffer.cpp diff --git a/tests/auto/threed/qglindexbuffer/tst_qglindexbuffer.cpp b/tests/auto/threed/qglindexbuffer/tst_qglindexbuffer.cpp deleted file mode 100644 index a7083762..00000000 --- a/tests/auto/threed/qglindexbuffer/tst_qglindexbuffer.cpp +++ /dev/null @@ -1,478 +0,0 @@ -/**************************************************************************** -** -** 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 QtQuick3D module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** 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. -** -** 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. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include <QtTest/QtTest> -#include <QtOpenGL/qgl.h> -#include "qglindexbuffer.h" -#include "qopenglfunctions.h" - -class tst_QGLIndexBuffer : public QObject -{ - Q_OBJECT -public: - tst_QGLIndexBuffer() {} - ~tst_QGLIndexBuffer() {} - -private slots: - void initTestCase(); - void create(); - void replaceIndexes(); - void appendSimple_data(); - void appendSimple(); - void appendCombined_data(); - void appendCombined(); - -private: - QArray<ushort> indexesUShort1024; - QArray<uint> indexesUInt1024; - QArray<ushort> indexesUShort1024Rev; - QArray<uint> indexesUInt1024Rev; -}; - -void tst_QGLIndexBuffer::initTestCase() -{ - for (uint index = 0; index < 1024; ++index) { - indexesUShort1024.append(ushort(index)); - indexesUInt1024.append(index); - indexesUShort1024Rev.append(ushort(1024 - index)); - indexesUInt1024Rev.append(1024 - index); - } -} - -void tst_QGLIndexBuffer::create() -{ - QGLIndexBuffer buf1; - QVERIFY(buf1.usagePattern() == QGLBuffer::StaticDraw); - QVERIFY(buf1.elementType() == GL_UNSIGNED_SHORT); - QVERIFY(buf1.indexesUShort().isEmpty()); - QVERIFY(buf1.indexesUInt().isEmpty()); - QVERIFY(buf1.isEmpty()); - QCOMPARE(buf1.indexCount(), 0); - QVERIFY(!buf1.buffer().isCreated()); - QVERIFY(!buf1.isUploaded()); - - // Setting an index array as ushort must stay ushort. - buf1.setIndexes(indexesUShort1024); - QVERIFY(buf1.usagePattern() == QGLBuffer::StaticDraw); - QVERIFY(buf1.elementType() == GL_UNSIGNED_SHORT); - QVERIFY(buf1.indexesUShort() == indexesUShort1024); - QVERIFY(buf1.indexesUInt().isEmpty()); - QVERIFY(!buf1.isEmpty()); - QCOMPARE(buf1.indexCount(), 1024); - QVERIFY(!buf1.buffer().isCreated()); - QVERIFY(!buf1.isUploaded()); - - // Setting an index array as uint may convert to ushort on - // embedded systems that don't have GL_OES_element_index_uint. - buf1.setIndexes(indexesUInt1024); - QVERIFY(buf1.usagePattern() == QGLBuffer::StaticDraw); - if (buf1.elementType() == GL_UNSIGNED_SHORT) { - QVERIFY(buf1.elementType() == GL_UNSIGNED_SHORT); - QVERIFY(buf1.indexesUShort() == indexesUShort1024); - QVERIFY(buf1.indexesUInt().isEmpty()); - } else { - QVERIFY(buf1.elementType() == GL_UNSIGNED_INT); - QVERIFY(buf1.indexesUShort().isEmpty()); - QVERIFY(buf1.indexesUInt() == indexesUInt1024); - } - QVERIFY(!buf1.isEmpty()); - QCOMPARE(buf1.indexCount(), 1024); - QVERIFY(!buf1.buffer().isCreated()); - QVERIFY(!buf1.isUploaded()); - - // Set back to ushort again. - buf1.setIndexes(indexesUShort1024); - QVERIFY(buf1.usagePattern() == QGLBuffer::StaticDraw); - QVERIFY(buf1.elementType() == GL_UNSIGNED_SHORT); - QVERIFY(buf1.indexesUShort() == indexesUShort1024); - QVERIFY(buf1.indexesUInt().isEmpty()); - QVERIFY(!buf1.isEmpty()); - QCOMPARE(buf1.indexCount(), 1024); - QVERIFY(!buf1.buffer().isCreated()); - QVERIFY(!buf1.isUploaded()); -} - -void tst_QGLIndexBuffer::replaceIndexes() -{ - QGLIndexBuffer buf1; - buf1.setIndexes(indexesUShort1024); - buf1.replaceIndexes(0, indexesUShort1024Rev); - QCOMPARE(buf1.indexCount(), indexesUShort1024Rev.size()); - QVERIFY(buf1.indexesUShort() == indexesUShort1024Rev); - - QArray<ushort> result1(indexesUShort1024Rev); - result1.replace(512, indexesUShort1024.constData(), indexesUShort1024.size()); - buf1.replaceIndexes(512, indexesUShort1024); - QVERIFY(buf1.indexesUShort() == result1); - QCOMPARE(buf1.indexCount(), result1.size()); - - QGLIndexBuffer buf2; - buf2.setIndexes(indexesUInt1024); - buf2.replaceIndexes(0, indexesUInt1024Rev); - QCOMPARE(buf2.indexCount(), indexesUShort1024Rev.size()); - if (buf2.elementType() == GL_UNSIGNED_SHORT) { - QVERIFY(buf2.indexesUShort() == indexesUShort1024Rev); - buf2.replaceIndexes(512, indexesUInt1024); - QVERIFY(buf2.indexesUShort() == result1); - QCOMPARE(buf2.indexCount(), result1.size()); - } else { - QVERIFY(buf2.indexesUInt() == indexesUInt1024Rev); - QArray<uint> result2(indexesUInt1024Rev); - result2.replace(512, indexesUInt1024.constData(), indexesUInt1024.size()); - buf2.replaceIndexes(512, indexesUInt1024); - QVERIFY(buf2.indexesUInt() == result2); - QCOMPARE(buf2.indexCount(), result2.size()); - } -} - -void tst_QGLIndexBuffer::appendSimple_data() -{ - QTest::addColumn<int>("buf1Type"); - QTest::addColumn<int>("buf2Type"); - - QTest::newRow("ushort, ushort") - << int(GL_UNSIGNED_SHORT) << int(GL_UNSIGNED_SHORT); - QTest::newRow("ushort, uint") - << int(GL_UNSIGNED_SHORT) << int(GL_UNSIGNED_INT); - QTest::newRow("uint, ushort") - << int(GL_UNSIGNED_INT) << int(GL_UNSIGNED_SHORT); - QTest::newRow("uint, uint") - << int(GL_UNSIGNED_INT) << int(GL_UNSIGNED_INT); -} - -void tst_QGLIndexBuffer::appendSimple() -{ - QFETCH(int, buf1Type); - QFETCH(int, buf2Type); - - QGLIndexBuffer buf1; - QGLIndexBuffer buf2; - if (buf1Type == GL_UNSIGNED_SHORT) - buf1.setIndexes(indexesUShort1024); - else - buf1.setIndexes(indexesUInt1024); - if (buf2Type == GL_UNSIGNED_SHORT) - buf2.setIndexes(indexesUShort1024Rev); - else - buf2.setIndexes(indexesUInt1024Rev); - buf1.append(buf2, 23); - - if (buf1.elementType() == GL_UNSIGNED_SHORT) { - QArray<ushort> result1(indexesUShort1024); - for (int index = 0; index < indexesUShort1024Rev.size(); ++index) - result1.append(indexesUShort1024Rev[index] + 23); - QVERIFY(buf1.indexesUShort() == result1); - QCOMPARE(buf1.indexCount(), result1.size()); - } else { - QArray<uint> result2(indexesUInt1024); - for (int index = 0; index < indexesUInt1024Rev.size(); ++index) - result2.append(indexesUInt1024Rev[index] + 23); - QVERIFY(buf1.indexesUInt() == result2); - QCOMPARE(buf1.indexCount(), result2.size()); - } -} - -void tst_QGLIndexBuffer::appendCombined_data() -{ - QTest::addColumn<int>("combineMode"); - QTest::addColumn<int>("offset"); - QTest::addColumn<QString>("buf1Values"); - QTest::addColumn<QString>("buf2Values"); - QTest::addColumn<QString>("resultValues"); - - QTest::newRow("triangles") - << int(QGL::Triangles) << 0 - << "0 1 2 3 4 5" - << "4 5 6 7 8 9" - << "0 1 2 3 4 5 4 5 6 7 8 9"; - - QTest::newRow("triangles, empty A") - << int(QGL::Triangles) << 20 - << "" - << "4 5 6 7 8" - << "24 25 26 27 28"; - - QTest::newRow("triangles, empty B") - << int(QGL::Triangles) << 10 - << "0 1 2 3 4 5" - << "" - << "0 1 2 3 4 5"; - - QTest::newRow("triangle strip, even") - << int(QGL::TriangleStrip) << 2 - << "0 1 2 3" - << "0 1 2 3" - << "0 1 2 3 4 5"; - - QTest::newRow("triangle strip, odd") - << int(QGL::TriangleStrip) << 0 - << "0 1 2" - << "1 2 3 4 5" - << "0 1 2 3 4 5"; - - QTest::newRow("triangle strip, odd reversed") - << int(QGL::TriangleStrip) << 0 - << "0 1 2" - << "2 1 3 4 5" - << "0 1 2 3 4 5"; - - QTest::newRow("triangle strip, no common") - << int(QGL::TriangleStrip) << 0 - << "0 1 2" - << "3 4 5" - << "0 1 2 3 4 5"; - - QTest::newRow("triangle strip, empty A") - << int(QGL::TriangleStrip) << 0 - << "0 1 2" - << "" - << "0 1 2"; - - QTest::newRow("triangle strip, empty B") - << int(QGL::TriangleStrip) << 0 - << "" - << "0 1 2" - << "0 1 2"; - - QTest::newRow("line strip") - << int(QGL::LineStrip) << 0 - << "0 1 2" - << "2 3 4" - << "0 1 2 3 4"; - - QTest::newRow("line strip, offset") - << int(QGL::LineStrip) << 2 - << "0 1 2" - << "0 1 2" - << "0 1 2 3 4"; - - QTest::newRow("line strip, no common") - << int(QGL::LineStrip) << 0 - << "0 1 2" - << "3 4" - << "0 1 2 3 4"; - - QTest::newRow("line strip, empty A") - << int(QGL::LineStrip) << 0 - << "" - << "0 1 2" - << "0 1 2"; - - QTest::newRow("line strip, empty B") - << int(QGL::LineStrip) << 0 - << "0 1 2" - << "" - << "0 1 2"; - - QTest::newRow("quad strip") - << int(0x0008) << 0 - << "0 1 2 3" - << "2 3 4 5" - << "0 1 2 3 4 5"; - - QTest::newRow("quad strip, offset") - << int(0x0008) << 2 - << "0 1 2 3" - << "0 1 2 3" - << "0 1 2 3 4 5"; - - QTest::newRow("quad strip, no common") - << int(0x0008) << 0 - << "0 1 2 3" - << "3 2 4 5" - << "0 1 2 3 3 2 4 5"; - - QTest::newRow("triangle fan") - << int(QGL::TriangleFan) << 0 - << "0 1 2 3" - << "0 3 4 5" - << "0 1 2 3 4 5"; - - QTest::newRow("triangle fan, offset") - << int(QGL::TriangleFan) << 10 - << "10 11 12 13" - << "0 3 4 5" - << "10 11 12 13 14 15"; - - QTest::newRow("triangle fan, no common") - << int(QGL::TriangleFan) << 0 - << "0 1 2 3" - << "1 3 4 5" - << "0 1 2 3 1 3 4 5"; - - QTest::newRow("triangle fan, no common 2") - << int(QGL::TriangleFan) << 0 - << "0 1 2 3" - << "0 2 4 5" - << "0 1 2 3 0 2 4 5"; - - QTest::newRow("line strip adjacency") - << int(QGL::LineStripAdjacency) << 0 - << "0 1 2 3" - << "1 2 3 4" - << "0 1 2 3 4"; - - QTest::newRow("line strip adjacency, offset") - << int(QGL::LineStripAdjacency) << 10 - << "10 11 12 13" - << "1 2 3 4" - << "10 11 12 13 14"; - - QTest::newRow("line strip adjacency, no common") - << int(QGL::LineStripAdjacency) << 0 - << "0 1 2 3" - << "2 3 4 5" - << "0 1 2 3 2 3 4 5"; - - QTest::newRow("triangle strip adjacency, even") - << int(QGL::TriangleStripAdjacency) << 0 - << "1 2 3 4 5 6" - << "3 1 5 6 7 8" - << "1 2 3 4 5 6 7 8"; - - QTest::newRow("triangle strip adjacency, odd") - << int(QGL::TriangleStripAdjacency) << 0 - << "1 2 3 4 5 6 7 8" - << "5 3 7 8 9 10" - << "1 2 3 4 5 6 7 8 9 10"; - - QTest::newRow("triangle strip adjacency, even again") - << int(QGL::TriangleStripAdjacency) << 0 - << "1 2 3 4 5 6 7 8 9 10" - << "7 5 9 10 11 12" - << "1 2 3 4 5 6 7 8 9 10 11 12"; - - QTest::newRow("triangle strip adjacency, no common") - << int(QGL::TriangleStripAdjacency) << 0 - << "1 2 3 4 5 6 7 8 9 10" - << "5 7 9 10 11 12" - << "1 2 3 4 5 6 7 8 9 10 5 7 9 10 11 12"; - - QTest::newRow("triangle strip adjacency, offset") - << int(QGL::TriangleStripAdjacency) << 100 - << "101 102 103 104 105 106 107 108 109 110" - << "7 5 9 10 11 12" - << "101 102 103 104 105 106 107 108 109 110 111 112"; -} - -static QArray<ushort> stringToUShortArray(const QString &str) -{ - QStringList list = str.split(QLatin1String(" ")); - QArray<ushort> array; - if (str.isEmpty()) - return array; - foreach (QString s, list) - array.append(ushort(s.toInt())); - return array; -} - -static QArray<uint> stringToUIntArray(const QString &str) -{ - QStringList list = str.split(QLatin1String(" ")); - QArray<uint> array; - if (str.isEmpty()) - return array; - foreach (QString s, list) - array.append(s.toUInt()); - return array; -} - -static bool sameIndexes(const QGLIndexBuffer &buf, const QArray<ushort> &result) -{ - if (buf.elementType() == GL_UNSIGNED_SHORT) { - return buf.indexesUShort() == result; - } else { - QArray<uint> result2; - for (int index = 0; index < result.size(); ++index) - result2.append(result[index]); - return buf.indexesUInt() == result2; - } -} - -void tst_QGLIndexBuffer::appendCombined() -{ - QFETCH(int, combineMode); - QFETCH(int, offset); - QFETCH(QString, buf1Values); - QFETCH(QString, buf2Values); - QFETCH(QString, resultValues); - - // Test ushort, ushort appends. - QGLIndexBuffer buf1, buf2; - buf1.setIndexes(stringToUShortArray(buf1Values)); - buf2.setIndexes(stringToUShortArray(buf2Values)); - buf1.append(buf2, uint(offset), QGL::DrawingMode(combineMode)); - - QArray<ushort> result = stringToUShortArray(resultValues); - QVERIFY(buf1.indexesUShort() == result); - QCOMPARE(buf1.indexCount(), result.size()); - - // Test ushort, uint appends. - QGLIndexBuffer buf3, buf4; - buf3.setIndexes(stringToUShortArray(buf1Values)); - buf4.setIndexes(stringToUIntArray(buf2Values)); - buf3.append(buf4, uint(offset), QGL::DrawingMode(combineMode)); - - QVERIFY(sameIndexes(buf3, result)); - QCOMPARE(buf3.indexCount(), result.size()); - - // Test uint, ushort appends. - QGLIndexBuffer buf5, buf6; - buf5.setIndexes(stringToUIntArray(buf1Values)); - buf6.setIndexes(stringToUShortArray(buf2Values)); - buf5.append(buf6, uint(offset), QGL::DrawingMode(combineMode)); - - QVERIFY(sameIndexes(buf5, result)); - QCOMPARE(buf5.indexCount(), result.size()); - - // Test uint, uint appends. - QGLIndexBuffer buf7, buf8; - buf7.setIndexes(stringToUIntArray(buf1Values)); - buf8.setIndexes(stringToUIntArray(buf2Values)); - buf7.append(buf8, uint(offset), QGL::DrawingMode(combineMode)); - - QVERIFY(sameIndexes(buf7, result)); - QCOMPARE(buf7.indexCount(), result.size()); -} - -QTEST_MAIN(tst_QGLIndexBuffer) - -#include "tst_qglindexbuffer.moc" diff --git a/tests/auto/threed/qgllightmodel/qgllightmodel.pro b/tests/auto/threed/qgllightmodel/qgllightmodel.pro deleted file mode 100644 index 19f78ca0..00000000 --- a/tests/auto/threed/qgllightmodel/qgllightmodel.pro +++ /dev/null @@ -1,6 +0,0 @@ -load(qttest_p4.prf) -TEMPLATE=app -QT += testlib -CONFIG += unittest warn_on qt3d - -SOURCES += tst_qgllightmodel.cpp diff --git a/tests/auto/threed/qgllightmodel/tst_qgllightmodel.cpp b/tests/auto/threed/qgllightmodel/tst_qgllightmodel.cpp deleted file mode 100644 index b0b90af1..00000000 --- a/tests/auto/threed/qgllightmodel/tst_qgllightmodel.cpp +++ /dev/null @@ -1,122 +0,0 @@ -/**************************************************************************** -** -** 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 QtQuick3D module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** 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. -** -** 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. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include <QtTest/QtTest> -#include "qgllightmodel.h" - -class tst_QGLLightModel : public QObject -{ - Q_OBJECT -public: - tst_QGLLightModel() {} - ~tst_QGLLightModel() {} - -private slots: - void create(); - void modify(); -}; - -void tst_QGLLightModel::create() -{ - // Test that a newly created object has the correct defaults. - QGLLightModel model; - QVERIFY(model.model() == QGLLightModel::OneSided); - QVERIFY(model.colorControl() == QGLLightModel::SingleColor); - QVERIFY(model.viewerPosition() == QGLLightModel::ViewerAtInfinity); - QCOMPARE(model.ambientSceneColor().redF(), 0.2); - QCOMPARE(model.ambientSceneColor().greenF(), 0.2); - QCOMPARE(model.ambientSceneColor().blueF(), 0.2); - QCOMPARE(model.ambientSceneColor().alphaF(), 1.0); -} - -void tst_QGLLightModel::modify() -{ - // Test modifying each field individually. - QGLLightModel model; - QSignalSpy modelSpy(&model, SIGNAL(modelChanged())); - QSignalSpy controlSpy(&model, SIGNAL(colorControlChanged())); - QSignalSpy viewerSpy(&model, SIGNAL(viewerPositionChanged())); - QSignalSpy ambientSpy(&model, SIGNAL(ambientSceneColorChanged())); - QSignalSpy objectSpy(&model, SIGNAL(lightModelChanged())); - - model.setModel(QGLLightModel::TwoSided); - QVERIFY(model.model() == QGLLightModel::TwoSided); - QCOMPARE(modelSpy.size(), 1); - QCOMPARE(objectSpy.size(), 1); - - model.setColorControl(QGLLightModel::SeparateSpecularColor); - QVERIFY(model.colorControl() == QGLLightModel::SeparateSpecularColor); - QCOMPARE(controlSpy.size(), 1); - QCOMPARE(objectSpy.size(), 2); - - model.setViewerPosition(QGLLightModel::LocalViewer); - QVERIFY(model.viewerPosition() == QGLLightModel::LocalViewer); - QCOMPARE(viewerSpy.size(), 1); - QCOMPARE(objectSpy.size(), 3); - - model.setAmbientSceneColor(Qt::red); - QCOMPARE(model.ambientSceneColor().red(), 255); - QCOMPARE(model.ambientSceneColor().green(), 0); - QCOMPARE(model.ambientSceneColor().blue(), 0); - QCOMPARE(model.ambientSceneColor().alpha(), 255); - QCOMPARE(ambientSpy.size(), 1); - QCOMPARE(objectSpy.size(), 4); - - // Test that we don't get any side effects between properties. - QVERIFY(model.model() == QGLLightModel::TwoSided); - QVERIFY(model.colorControl() == QGLLightModel::SeparateSpecularColor); - QVERIFY(model.viewerPosition() == QGLLightModel::LocalViewer); - - // Set the properties to same values and check for no further signals. - model.setModel(QGLLightModel::TwoSided); - model.setColorControl(QGLLightModel::SeparateSpecularColor); - model.setViewerPosition(QGLLightModel::LocalViewer); - model.setAmbientSceneColor(Qt::red); - QCOMPARE(modelSpy.size(), 1); - QCOMPARE(controlSpy.size(), 1); - QCOMPARE(viewerSpy.size(), 1); - QCOMPARE(ambientSpy.size(), 1); - QCOMPARE(objectSpy.size(), 4); -} - -QTEST_APPLESS_MAIN(tst_QGLLightModel) - -#include "tst_qgllightmodel.moc" diff --git a/tests/auto/threed/qgllightparameters/qgllightparameters.pro b/tests/auto/threed/qgllightparameters/qgllightparameters.pro deleted file mode 100644 index 0cd20a44..00000000 --- a/tests/auto/threed/qgllightparameters/qgllightparameters.pro +++ /dev/null @@ -1,6 +0,0 @@ -load(qttest_p4.prf) -TEMPLATE=app -QT += testlib -CONFIG += unittest warn_on qt3d - -SOURCES += tst_qgllightparameters.cpp diff --git a/tests/auto/threed/qgllightparameters/tst_qgllightparameters.cpp b/tests/auto/threed/qgllightparameters/tst_qgllightparameters.cpp deleted file mode 100644 index 387e78d3..00000000 --- a/tests/auto/threed/qgllightparameters/tst_qgllightparameters.cpp +++ /dev/null @@ -1,275 +0,0 @@ -/**************************************************************************** -** -** 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 QtQuick3D module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** 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. -** -** 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. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include <QtTest/QtTest> -#include "qgllightparameters.h" -#include <QtGui/qmatrix4x4.h> - -class tst_QGLLightParameters : public QObject -{ - Q_OBJECT -public: - tst_QGLLightParameters() {} - ~tst_QGLLightParameters() {} - -private slots: - void create(); - void modify(); - void type(); - void transform(); -}; - -void tst_QGLLightParameters::create() -{ - // Test that a newly created object has the correct defaults. - QGLLightParameters params; - QVERIFY(params.type() == QGLLightParameters::Directional); - QVERIFY(params.position() == QVector3D(0, 0, 0)); - QVERIFY(params.direction() == QVector3D(0, 0, 1)); - QVERIFY(params.ambientColor() == QColor(0, 0, 0, 255)); - QVERIFY(params.diffuseColor() == QColor(255, 255, 255, 255)); - QVERIFY(params.specularColor() == QColor(255, 255, 255, 255)); - QVERIFY(params.spotDirection() == QVector3D(0, 0, -1)); - QCOMPARE(params.spotExponent(), (qreal)0.0f); - QCOMPARE(params.spotAngle(), (qreal)180.0f); - QCOMPARE(params.spotCosAngle(), (qreal)-1.0f); - QCOMPARE(params.constantAttenuation(), (qreal)1.0f); - QCOMPARE(params.linearAttenuation(), (qreal)0.0f); - QCOMPARE(params.quadraticAttenuation(), (qreal)0.0f); -} - -void tst_QGLLightParameters::modify() -{ - // Test modifying each field individually. - QGLLightParameters params; - QSignalSpy positionSpy(¶ms, SIGNAL(positionChanged())); - QSignalSpy directionSpy(¶ms, SIGNAL(directionChanged())); - QSignalSpy ambientSpy(¶ms, SIGNAL(ambientColorChanged())); - QSignalSpy diffuseSpy(¶ms, SIGNAL(diffuseColorChanged())); - QSignalSpy specularSpy(¶ms, SIGNAL(specularColorChanged())); - QSignalSpy spotDirectionSpy(¶ms, SIGNAL(spotDirectionChanged())); - QSignalSpy spotExponentSpy(¶ms, SIGNAL(spotExponentChanged())); - QSignalSpy spotAngleSpy(¶ms, SIGNAL(spotAngleChanged())); - QSignalSpy constSpy(¶ms, SIGNAL(constantAttenuationChanged())); - QSignalSpy linearSpy(¶ms, SIGNAL(linearAttenuationChanged())); - QSignalSpy quadSpy(¶ms, SIGNAL(quadraticAttenuationChanged())); - QSignalSpy lightSpy(¶ms, SIGNAL(lightChanged())); - - params.setPosition(QVector3D(1, 2, -3)); - QVERIFY(params.position() == QVector3D(1.0f, 2.0f, -3.0f)); - QVERIFY(params.direction() == QVector3D(0, 0, 0)); - QVERIFY(params.type() == QGLLightParameters::Positional); - QCOMPARE(positionSpy.size(), 1); - QCOMPARE(directionSpy.size(), 1); - QCOMPARE(lightSpy.size(), 1); - - params.setDirection(QVector3D(-1, -2, 3)); - QVERIFY(params.position() == QVector3D(0, 0, 0)); - QVERIFY(params.direction() == QVector3D(-1.0f, -2.0f, 3.0f)); - QVERIFY(params.type() == QGLLightParameters::Directional); - QCOMPARE(positionSpy.size(), 2); - QCOMPARE(directionSpy.size(), 2); - QCOMPARE(lightSpy.size(), 2); - - params.setAmbientColor(Qt::red); - QCOMPARE(params.ambientColor().red(), 255); - QCOMPARE(params.ambientColor().green(), 0); - QCOMPARE(params.ambientColor().blue(), 0); - QCOMPARE(params.ambientColor().alpha(), 255); - QCOMPARE(ambientSpy.size(), 1); - QCOMPARE(lightSpy.size(), 3); - - params.setDiffuseColor(Qt::green); - QCOMPARE(params.diffuseColor().red(), 0); - QCOMPARE(params.diffuseColor().green(), 255); - QCOMPARE(params.diffuseColor().blue(), 0); - QCOMPARE(params.diffuseColor().alpha(), 255); - QCOMPARE(diffuseSpy.size(), 1); - QCOMPARE(lightSpy.size(), 4); - - params.setSpecularColor(Qt::black); - QCOMPARE(params.specularColor().red(), 0); - QCOMPARE(params.specularColor().green(), 0); - QCOMPARE(params.specularColor().blue(), 0); - QCOMPARE(params.specularColor().alpha(), 255); - QCOMPARE(specularSpy.size(), 1); - QCOMPARE(lightSpy.size(), 5); - - params.setSpotDirection(QVector3D(0, 1, 0)); - QVERIFY(params.spotDirection() == QVector3D(0.0f, 1.0f, 0.0f)); - QCOMPARE(spotDirectionSpy.size(), 1); - QCOMPARE(lightSpy.size(), 6); - - params.setSpotExponent(23.5f); - QCOMPARE(params.spotExponent(), (qreal)23.5f); - QCOMPARE(spotExponentSpy.size(), 1); - QCOMPARE(lightSpy.size(), 7); - - params.setSpotAngle(90.0f); - QCOMPARE(params.spotAngle(), (qreal)90.0f); - QVERIFY(params.spotCosAngle() <= 0.000001f); // Fuzzy compare is not fuzzy enough! - QCOMPARE(spotAngleSpy.size(), 1); - QCOMPARE(lightSpy.size(), 8); - - params.setSpotAngle(180.0f); - QCOMPARE(params.spotCosAngle(), (qreal)-1.0f); - QCOMPARE(spotAngleSpy.size(), 2); - QCOMPARE(lightSpy.size(), 9); - - params.setConstantAttenuation(16.0f); - QCOMPARE(params.constantAttenuation(), (qreal)16.0f); - QCOMPARE(constSpy.size(), 1); - QCOMPARE(lightSpy.size(), 10); - - params.setLinearAttenuation(-3.5f); - QCOMPARE(params.linearAttenuation(), (qreal)-3.5f); - QCOMPARE(linearSpy.size(), 1); - QCOMPARE(lightSpy.size(), 11); - - params.setQuadraticAttenuation(4.0f); - QCOMPARE(params.quadraticAttenuation(), (qreal)4.0f); - QCOMPARE(quadSpy.size(), 1); - QCOMPARE(lightSpy.size(), 12); - - // Test that we don't get any side effects between properties. - QVERIFY(params.position() == QVector3D(0, 0, 0)); - QVERIFY(params.direction() == QVector3D(-1.0f, -2.0f, 3.0f)); - QVERIFY(params.type() == QGLLightParameters::Directional); - QCOMPARE(params.ambientColor().red(), 255); - QCOMPARE(params.ambientColor().green(), 0); - QCOMPARE(params.ambientColor().blue(), 0); - QCOMPARE(params.ambientColor().alpha(), 255); - QCOMPARE(params.diffuseColor().red(), 0); - QCOMPARE(params.diffuseColor().green(), 255); - QCOMPARE(params.diffuseColor().blue(), 0); - QCOMPARE(params.diffuseColor().alpha(), 255); - QCOMPARE(params.specularColor().red(), 0); - QCOMPARE(params.specularColor().green(), 0); - QCOMPARE(params.specularColor().blue(), 0); - QCOMPARE(params.specularColor().alpha(), 255); - QVERIFY(params.spotDirection() == QVector3D(0.0f, 1.0f, 0.0f)); - QCOMPARE(params.spotExponent(), (qreal)23.5f); - QCOMPARE(params.spotAngle(), (qreal)180.0f); - QCOMPARE(params.spotCosAngle(), (qreal)-1.0f); - QCOMPARE(params.constantAttenuation(), (qreal)16.0f); - QCOMPARE(params.linearAttenuation(), (qreal)-3.5f); - QCOMPARE(params.quadraticAttenuation(), (qreal)4.0f); - - // Set the properties to same values and check for no further signals. - params.setDirection(QVector3D(-1, -2, 3)); - params.setAmbientColor(Qt::red); - params.setDiffuseColor(Qt::green); - params.setSpecularColor(Qt::black); - params.setSpotDirection(QVector3D(0, 1, 0)); - params.setSpotExponent(23.5f); - params.setSpotAngle(180.0f); - params.setConstantAttenuation(16.0f); - params.setLinearAttenuation(-3.5f); - params.setQuadraticAttenuation(4.0f); - QCOMPARE(positionSpy.size(), 2); - QCOMPARE(directionSpy.size(), 2); - QCOMPARE(ambientSpy.size(), 1); - QCOMPARE(diffuseSpy.size(), 1); - QCOMPARE(specularSpy.size(), 1); - QCOMPARE(spotDirectionSpy.size(), 1); - QCOMPARE(spotExponentSpy.size(), 1); - QCOMPARE(spotAngleSpy.size(), 2); - QCOMPARE(constSpy.size(), 1); - QCOMPARE(linearSpy.size(), 1); - QCOMPARE(quadSpy.size(), 1); - QCOMPARE(lightSpy.size(), 12); - - // Check signal emission when changing from positional to positional. - params.setPosition(QVector3D(1, 2, -3)); - QCOMPARE(positionSpy.size(), 3); - QCOMPARE(directionSpy.size(), 3); - QCOMPARE(lightSpy.size(), 13); - params.setPosition(QVector3D(1, 2, -3)); - QVERIFY(params.position() == QVector3D(1.0f, 2.0f, -3.0f)); - QVERIFY(params.direction() == QVector3D(0, 0, 0)); - QCOMPARE(positionSpy.size(), 3); - QCOMPARE(directionSpy.size(), 3); - QCOMPARE(lightSpy.size(), 13); - params.setPosition(QVector3D(4, 1, -2)); - QCOMPARE(positionSpy.size(), 4); - QCOMPARE(directionSpy.size(), 3); - QCOMPARE(lightSpy.size(), 14); - QVERIFY(params.position() == QVector3D(4.0f, 1.0f, -2.0f)); - QVERIFY(params.direction() == QVector3D(0, 0, 0)); -} - -void tst_QGLLightParameters::type() -{ - QGLLightParameters params; - QVERIFY(params.type() == QGLLightParameters::Directional); - QCOMPARE(params.position(), QVector3D(0.0f, 0.0f, 0.0f)); - QCOMPARE(params.direction(), QVector3D(0.0f, 0.0f, 1.0f)); - params.setDirection(QVector3D(1.0f, 0.0f, 1.0f)); - QVERIFY(params.type() == QGLLightParameters::Directional); - QCOMPARE(params.position(), QVector3D(0.0f, 0.0f, 0.0f)); - QCOMPARE(params.direction(), QVector3D(1.0f, 0.0f, 1.0f)); - params.setPosition(QVector3D(2.0f, 0.0f, 2.0f)); - QVERIFY(params.type() == QGLLightParameters::Positional); - QCOMPARE(params.position(), QVector3D(2.0f, 0.0f, 2.0f)); - QCOMPARE(params.direction(), QVector3D(0.0f, 0.0f, 0.0f)); -} - -void tst_QGLLightParameters::transform() -{ - QGLLightParameters params; - params.setPosition(QVector3D(1, 2, -3)); - params.setSpotDirection(QVector3D(-5, 1, 3)); - - QMatrix4x4 m; - m.translate(-5.0f, 1.5f, 0.5f); - m.rotate(45.0f, 1.0f, 1.0f, 1.0f); - m.scale(2.0f); - - QCOMPARE(params.eyePosition(m), m * QVector4D(1, 2, -3, 1)); - QCOMPARE(params.eyeSpotDirection(m), m.mapVector(QVector3D(-5, 1, 3))); - - params.setDirection(QVector3D(-1, -2, 3)); - QCOMPARE(params.eyePosition(m), m * QVector4D(-1, -2, 3, 0)); -} - -QTEST_APPLESS_MAIN(tst_QGLLightParameters) - -#include "tst_qgllightparameters.moc" diff --git a/tests/auto/threed/qglmaterial/qglmaterial.pro b/tests/auto/threed/qglmaterial/qglmaterial.pro deleted file mode 100644 index 2ed58123..00000000 --- a/tests/auto/threed/qglmaterial/qglmaterial.pro +++ /dev/null @@ -1,6 +0,0 @@ -load(qttest_p4.prf) -TEMPLATE=app -QT += testlib -CONFIG += unittest warn_on qt3d - -SOURCES += tst_qglmaterial.cpp diff --git a/tests/auto/threed/qglmaterial/tst_qglmaterial.cpp b/tests/auto/threed/qglmaterial/tst_qglmaterial.cpp deleted file mode 100644 index ea6c50b0..00000000 --- a/tests/auto/threed/qglmaterial/tst_qglmaterial.cpp +++ /dev/null @@ -1,714 +0,0 @@ -/**************************************************************************** -** -** 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 QtQuick3D module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** 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. -** -** 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. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include <QtTest/QtTest> -#include "qglmaterial.h" -#include "qglcolormaterial.h" -#include "qgltwosidedmaterial.h" -#include "qgllightparameters.h" -#include "qgllightmodel.h" -#include "qgltexture2d.h" -#include "qglcamera.h" -#include "qglpainter.h" -#include "qglvertexbundle.h" -#include "qvector2darray.h" -#include "qvector3darray.h" -#include <QtCore/qeventloop.h> -#include <QtGui/qvector3d.h> -#include <QtGui/qvector4d.h> - -class TestWidget; - -class tst_QGLMaterial : public QObject -{ - Q_OBJECT -public: - tst_QGLMaterial() : widget(0) {} - ~tst_QGLMaterial() {} - -private slots: - void initTestCase(); - - void standardMaterial(); - void textureLayers(); - void colorMaterial(); - void twoSidedMaterial(); - - void standardMaterialDraw(); - void colorMaterialDraw(); - - void cleanupTestCase(); - -private: - TestWidget *widget; -}; - -class TestWidget : public QGLWidget -{ - Q_OBJECT -public: - TestWidget(QWidget *parent = 0); - ~TestWidget(); - - bool runTest(QGLAbstractMaterial *mat, int timeout = 5000); - bool sameColor(const QColor &color) const; - - void setClearColor(const QColor &color) { clearColor = color; } - -protected: - void initializeGL(); - void paintGL(); - -private: - QGLCamera camera; - QGLVertexBundle bundle; - QGLAbstractMaterial *material; - QEventLoop *eventLoop; - bool paintDone; - QColor pixel; - QColor clearColor; -}; - -TestWidget::TestWidget(QWidget *parent) - : QGLWidget(parent) - , material(0) - , eventLoop(0) - , paintDone(false) - , clearColor(Qt::black) -{ - QVector3DArray positions; - QVector3DArray normals; - QVector2DArray texCoords; - - positions.append(QVector3D(-0.5, -0.5, 0.0)); - positions.append(QVector3D(0.5, -0.5, 0.0)); - positions.append(QVector3D(0.5, 0.5, 0.0)); - positions.append(QVector3D(-0.5, 0.5, 0.0)); - - normals.append(QVector3D(0, 0, 1)); - normals.append(QVector3D(0, 0, 1)); - normals.append(QVector3D(0, 0, 1)); - normals.append(QVector3D(0, 0, 1)); - - texCoords.append(QVector2D(0.0f, 0.0f)); - texCoords.append(QVector2D(1.0f, 0.0f)); - texCoords.append(QVector2D(1.0f, 1.0f)); - texCoords.append(QVector2D(0.0f, 1.0f)); - - bundle.addAttribute(QGL::Position, positions); - bundle.addAttribute(QGL::Normal, normals); - bundle.addAttribute(QGL::TextureCoord0, texCoords); -} - -TestWidget::~TestWidget() -{ -} - -bool TestWidget::runTest(QGLAbstractMaterial *mat, int timeout) -{ - material = mat; - paintDone = false; - pixel = QColor(); - eventLoop = new QEventLoop(this); - QTimer::singleShot(timeout, eventLoop, SLOT(quit())); - if (!isVisible()) { - show(); -#ifdef Q_WS_X11 - qt_x11_wait_for_window_manager(this); -#endif - } else { - updateGL(); - } - if (!paintDone) - eventLoop->exec(); - delete eventLoop; - material = 0; - eventLoop = 0; - return paintDone; -} - -bool TestWidget::sameColor(const QColor &color) const -{ - if (!pixel.isValid()) { - qWarning("did not get a valid pixel"); - return false; - } - if (qAbs(pixel.red() - color.red()) <= 16 && - qAbs(pixel.green() - color.green()) <= 16 && - qAbs(pixel.blue() - color.blue()) <= 16) - return true; - qWarning() << "pixel color does not match, actual:" - << pixel.name() << "expected:" << color.name(); - return false; -} - -void TestWidget::initializeGL() -{ - bundle.upload(); - - QGLPainter painter(this); - if (painter.hasOpenGLFeature(QOpenGLFunctions::BlendColor)) - painter.glBlendColor(0, 0, 0, 0); - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - if (painter.hasOpenGLFeature(QOpenGLFunctions::BlendEquation)) - painter.glBlendEquation(GL_FUNC_ADD); - else if (painter.hasOpenGLFeature(QOpenGLFunctions::BlendEquationSeparate)) - painter.glBlendEquationSeparate(GL_FUNC_ADD, GL_FUNC_ADD); -} - -void TestWidget::paintGL() -{ - QGLPainter painter(this); - painter.setClearColor(clearColor); - glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); - - painter.setCamera(&camera); - - painter.clearAttributes(); - painter.setVertexBundle(bundle); - - if (material) { - material->bind(&painter); - material->prepareToDraw(&painter, painter.attributes()); - painter.draw(QGL::TriangleFan, 4); - material->release(&painter, 0); - } - - QImage capture = grabFrameBuffer(); - if (capture.width() > 0 && capture.height() > 0) - pixel = QColor(capture.pixel(capture.width() / 2, capture.height() / 2)); - - if (!paintDone && eventLoop) { - paintDone = true; - eventLoop->quit(); - } -} - -void tst_QGLMaterial::initTestCase() -{ - widget = new TestWidget(); -} - -void tst_QGLMaterial::cleanupTestCase() -{ - delete widget; -} - -static inline bool fuzzyCompare(qreal x, qreal y) -{ - return qAbs(x - y) <= 0.00001; -} - -void tst_QGLMaterial::standardMaterial() -{ - // Test that a newly created object has the correct defaults. - QGLMaterial mat1; - QVERIFY(fuzzyCompare(mat1.ambientColor().redF(), qreal(0.2f))); - QVERIFY(fuzzyCompare(mat1.ambientColor().greenF(), qreal(0.2f))); - QVERIFY(fuzzyCompare(mat1.ambientColor().blueF(), qreal(0.2f))); - QVERIFY(fuzzyCompare(mat1.ambientColor().alphaF(), qreal(1.0f))); - QVERIFY(fuzzyCompare(mat1.diffuseColor().redF(), qreal(0.8f))); - QVERIFY(fuzzyCompare(mat1.diffuseColor().greenF(), qreal(0.8f))); - QVERIFY(fuzzyCompare(mat1.diffuseColor().blueF(), qreal(0.8f))); - QVERIFY(fuzzyCompare(mat1.diffuseColor().alphaF(), qreal(1.0f))); - QCOMPARE(mat1.specularColor().red(), 0); - QCOMPARE(mat1.specularColor().green(), 0); - QCOMPARE(mat1.specularColor().blue(), 0); - QCOMPARE(mat1.specularColor().alpha(), 255); - QCOMPARE(mat1.emittedLight().red(), 0); - QCOMPARE(mat1.emittedLight().green(), 0); - QCOMPARE(mat1.emittedLight().blue(), 0); - QCOMPARE(mat1.emittedLight().alpha(), 255); - QCOMPARE(mat1.shininess(), qreal(0)); - QVERIFY(!mat1.isTransparent()); - - // Test modifying each field individually, including expected signals. - QGLMaterial mat2; - QSignalSpy ambientSpy(&mat2, SIGNAL(ambientColorChanged())); - QSignalSpy diffuseSpy(&mat2, SIGNAL(diffuseColorChanged())); - QSignalSpy specularSpy(&mat2, SIGNAL(specularColorChanged())); - QSignalSpy emittedSpy(&mat2, SIGNAL(emittedLightChanged())); - QSignalSpy shininessSpy(&mat2, SIGNAL(shininessChanged())); - QSignalSpy texturesSpy(&mat2, SIGNAL(texturesChanged())); - QSignalSpy materialSpy(&mat2, SIGNAL(materialChanged())); - mat2.setAmbientColor(Qt::green); - QCOMPARE(mat2.ambientColor().red(), 0); - QCOMPARE(mat2.ambientColor().green(), 255); - QCOMPARE(mat2.ambientColor().blue(), 0); - QCOMPARE(mat2.ambientColor().alpha(), 255); - QCOMPARE(ambientSpy.count(), 1); - QCOMPARE(diffuseSpy.count(), 0); - QCOMPARE(specularSpy.count(), 0); - QCOMPARE(emittedSpy.count(), 0); - QCOMPARE(shininessSpy.count(), 0); - QCOMPARE(texturesSpy.count(), 0); - QCOMPARE(materialSpy.count(), 1); - mat2.setDiffuseColor(Qt::blue); - QCOMPARE(mat2.diffuseColor().red(), 0); - QCOMPARE(mat2.diffuseColor().green(), 0); - QCOMPARE(mat2.diffuseColor().blue(), 255); - QCOMPARE(mat2.diffuseColor().alpha(), 255); - QCOMPARE(ambientSpy.count(), 1); - QCOMPARE(diffuseSpy.count(), 1); - QCOMPARE(specularSpy.count(), 0); - QCOMPARE(emittedSpy.count(), 0); - QCOMPARE(shininessSpy.count(), 0); - QCOMPARE(texturesSpy.count(), 0); - QCOMPARE(materialSpy.count(), 2); - mat2.setSpecularColor(Qt::cyan); - QCOMPARE(mat2.specularColor().red(), 0); - QCOMPARE(mat2.specularColor().green(), 255); - QCOMPARE(mat2.specularColor().blue(), 255); - QCOMPARE(mat2.specularColor().alpha(), 255); - QCOMPARE(ambientSpy.count(), 1); - QCOMPARE(diffuseSpy.count(), 1); - QCOMPARE(specularSpy.count(), 1); - QCOMPARE(emittedSpy.count(), 0); - QCOMPARE(shininessSpy.count(), 0); - QCOMPARE(texturesSpy.count(), 0); - QCOMPARE(materialSpy.count(), 3); - mat2.setEmittedLight(Qt::white); - QCOMPARE(mat2.emittedLight().red(), 255); - QCOMPARE(mat2.emittedLight().green(), 255); - QCOMPARE(mat2.emittedLight().blue(), 255); - QCOMPARE(mat2.emittedLight().alpha(), 255); - QCOMPARE(ambientSpy.count(), 1); - QCOMPARE(diffuseSpy.count(), 1); - QCOMPARE(specularSpy.count(), 1); - QCOMPARE(emittedSpy.count(), 1); - QCOMPARE(shininessSpy.count(), 0); - QCOMPARE(texturesSpy.count(), 0); - QCOMPARE(materialSpy.count(), 4); - mat2.setShininess(128); - QCOMPARE(mat2.shininess(), qreal(128)); - QCOMPARE(ambientSpy.count(), 1); - QCOMPARE(diffuseSpy.count(), 1); - QCOMPARE(specularSpy.count(), 1); - QCOMPARE(emittedSpy.count(), 1); - QCOMPARE(shininessSpy.count(), 1); - QCOMPARE(texturesSpy.count(), 0); - QCOMPARE(materialSpy.count(), 5); - - // Modify to the same values and check for no further signals. - mat2.setAmbientColor(Qt::green); - mat2.setDiffuseColor(Qt::blue); - mat2.setSpecularColor(Qt::cyan); - mat2.setEmittedLight(Qt::white); - mat2.setShininess(128); - QCOMPARE(ambientSpy.count(), 1); - QCOMPARE(diffuseSpy.count(), 1); - QCOMPARE(specularSpy.count(), 1); - QCOMPARE(emittedSpy.count(), 1); - QCOMPARE(shininessSpy.count(), 1); - QCOMPARE(texturesSpy.count(), 0); - QCOMPARE(materialSpy.count(), 5); - - // Check clamping of shininess to the range 0..128. - mat1.setShininess(-0.5f); - QCOMPARE(mat1.shininess(), qreal(0.0f)); - mat1.setShininess(128.5f); - QCOMPARE(mat1.shininess(), qreal(128.0f)); - - // Test that we don't get any side effects between properties. - QCOMPARE(mat2.ambientColor().red(), 0); - QCOMPARE(mat2.ambientColor().green(), 255); - QCOMPARE(mat2.ambientColor().blue(), 0); - QCOMPARE(mat2.ambientColor().alpha(), 255); - QCOMPARE(mat2.diffuseColor().red(), 0); - QCOMPARE(mat2.diffuseColor().green(), 0); - QCOMPARE(mat2.diffuseColor().blue(), 255); - QCOMPARE(mat2.diffuseColor().alpha(), 255); - QCOMPARE(mat2.specularColor().red(), 0); - QCOMPARE(mat2.specularColor().green(), 255); - QCOMPARE(mat2.specularColor().blue(), 255); - QCOMPARE(mat2.specularColor().alpha(), 255); - QCOMPARE(mat2.emittedLight().red(), 255); - QCOMPARE(mat2.emittedLight().green(), 255); - QCOMPARE(mat2.emittedLight().blue(), 255); - QCOMPARE(mat2.emittedLight().alpha(), 255); - QCOMPARE(mat2.shininess(), qreal(128)); - - // Test the material fetch functions from QGLAbstractMaterial. - QVERIFY(mat1.front() == &mat1); - QVERIFY(mat1.back() == 0); - QVERIFY(mat2.front() == &mat2); - QVERIFY(mat2.back() == 0); - - // Test setting a pseudo-flat color via QGLMaterial::setColor(). - mat2.setColor(QColor::fromRgbF(0.2f, 0.8f, 0.5f, 0.7f)); - QVERIFY(fuzzyCompare(mat2.ambientColor().redF(), qreal(0.2f * 0.2f))); - QVERIFY(fuzzyCompare(mat2.ambientColor().greenF(), qreal(0.2f * 0.8f))); - QVERIFY(fuzzyCompare(mat2.ambientColor().blueF(), qreal(0.2f * 0.5f))); - QVERIFY(fuzzyCompare(mat2.ambientColor().alphaF(), qreal(0.7f))); - QVERIFY(fuzzyCompare(mat2.diffuseColor().redF(), qreal(0.8f * 0.2f))); - QVERIFY(fuzzyCompare(mat2.diffuseColor().greenF(), qreal(0.8f * 0.8f))); - QVERIFY(fuzzyCompare(mat2.diffuseColor().blueF(), qreal(0.8f * 0.5f))); - QVERIFY(fuzzyCompare(mat2.diffuseColor().alphaF(), qreal(0.7f))); - QCOMPARE(ambientSpy.count(), 2); - QCOMPARE(diffuseSpy.count(), 2); - QCOMPARE(specularSpy.count(), 1); - QCOMPARE(emittedSpy.count(), 1); - QCOMPARE(shininessSpy.count(), 1); - QCOMPARE(texturesSpy.count(), 0); - QCOMPARE(materialSpy.count(), 6); -} - -void tst_QGLMaterial::textureLayers() -{ - QGLMaterial mat1; - QCOMPARE(mat1.textureLayerCount(), 0); - QVERIFY(mat1.texture() == 0); - QVERIFY(mat1.texture(3) == 0); - - QSignalSpy texturesSpy(&mat1, SIGNAL(texturesChanged())); - QSignalSpy materialSpy(&mat1, SIGNAL(materialChanged())); - - QGLTexture2D *tex1 = new QGLTexture2D(this); - QSignalSpy tex1Spy(tex1, SIGNAL(destroyed())); - mat1.setTexture(tex1); - QCOMPARE(texturesSpy.count(), 1); - QCOMPARE(materialSpy.count(), 1); - QCOMPARE(mat1.textureLayerCount(), 1); - QVERIFY(mat1.texture() == tex1); - - QGLTexture2D *tex2 = new QGLTexture2D(this); - mat1.setTexture(tex2, 3); - QCOMPARE(texturesSpy.count(), 2); - QCOMPARE(materialSpy.count(), 2); - QCOMPARE(mat1.textureLayerCount(), 4); - QVERIFY(mat1.texture() == tex1); - QVERIFY(mat1.texture(1) == 0); - QVERIFY(mat1.texture(2) == 0); - QVERIFY(mat1.texture(3) == tex2); - - QVERIFY(mat1.textureCombineMode() == QGLMaterial::Modulate); - QVERIFY(mat1.textureCombineMode(2) == QGLMaterial::Modulate); - QVERIFY(mat1.textureCombineMode(3) == QGLMaterial::Modulate); - QVERIFY(mat1.textureCombineMode(-32) == QGLMaterial::Modulate); - - mat1.setTextureCombineMode(QGLMaterial::Decal); - QCOMPARE(texturesSpy.count(), 3); - QCOMPARE(materialSpy.count(), 3); - - QVERIFY(mat1.textureCombineMode() == QGLMaterial::Decal); - QVERIFY(mat1.textureCombineMode(2) == QGLMaterial::Modulate); - QVERIFY(mat1.textureCombineMode(3) == QGLMaterial::Modulate); - - mat1.setTextureCombineMode(QGLMaterial::Replace, 3); - QCOMPARE(texturesSpy.count(), 4); - QCOMPARE(materialSpy.count(), 4); - - QVERIFY(mat1.textureCombineMode() == QGLMaterial::Decal); - QVERIFY(mat1.textureCombineMode(2) == QGLMaterial::Modulate); - QVERIFY(mat1.textureCombineMode(3) == QGLMaterial::Replace); - - mat1.setTextureCombineMode(QGLMaterial::Modulate, 0); - QCOMPARE(texturesSpy.count(), 5); - QCOMPARE(materialSpy.count(), 5); - - QVERIFY(mat1.textureCombineMode() == QGLMaterial::Modulate); - QVERIFY(mat1.textureCombineMode(2) == QGLMaterial::Modulate); - QVERIFY(mat1.textureCombineMode(3) == QGLMaterial::Replace); - - QVERIFY(!mat1.textureUrl().isValid()); - QVERIFY(!mat1.textureUrl(2).isValid()); - QVERIFY(!mat1.textureUrl(3).isValid()); - - // This will delete the texture object and replace it with a new one. - // This texture is not intended to actually "load" as such, but rather - // to simply test the setting of notional textures. - mat1.setTextureUrl(QUrl(QLatin1String("foo://bar.com/texture.png"))); - QCOMPARE(tex1Spy.count(), 1); - QCOMPARE(texturesSpy.count(), 6); - QCOMPARE(materialSpy.count(), 6); - QVERIFY(mat1.texture() != 0); - QVERIFY(mat1.texture()->url() == QUrl(QLatin1String("foo://bar.com/texture.png"))); - - // Setting the url to empty will delete the texture object entirely. - QSignalSpy tex3Spy(mat1.texture(), SIGNAL(destroyed())); - mat1.setTextureUrl(QUrl()); - QCOMPARE(tex3Spy.count(), 1); - QCOMPARE(texturesSpy.count(), 7); - QCOMPARE(materialSpy.count(), 7); - QVERIFY(mat1.texture() == 0); - - // Changing properties to the same thing should do nothing. - mat1.setTexture(tex2, 3); - mat1.setTextureCombineMode(QGLMaterial::Replace, 3); - mat1.setTextureUrl(QUrl()); - - // Check final texture assignments and properties. - QVERIFY(mat1.texture() == 0); - QVERIFY(mat1.texture(1) == 0); - QVERIFY(mat1.texture(2) == 0); - QVERIFY(mat1.texture(3) == tex2); - QVERIFY(mat1.textureCombineMode() == QGLMaterial::Modulate); - QVERIFY(mat1.textureCombineMode(2) == QGLMaterial::Modulate); - QVERIFY(mat1.textureCombineMode(3) == QGLMaterial::Replace); - QCOMPARE(mat1.textureLayerCount(), 4); -} - -void tst_QGLMaterial::colorMaterial() -{ - QGLColorMaterial mat1; - QVERIFY(mat1.color() == QColor(Qt::white)); - QVERIFY(!mat1.isTransparent()); - - QSignalSpy colorSpy(&mat1, SIGNAL(colorChanged())); - QSignalSpy materialSpy(&mat1, SIGNAL(materialChanged())); - - mat1.setColor(Qt::red); - QCOMPARE(colorSpy.count(), 1); - QCOMPARE(materialSpy.count(), 1); - QVERIFY(mat1.color() == QColor(Qt::red)); - - mat1.setColor(Qt::red); - QCOMPARE(colorSpy.count(), 1); - QCOMPARE(materialSpy.count(), 1); - - mat1.setColor(QColor(24, 56, 98, 43)); - QVERIFY(mat1.isTransparent()); -} - -void tst_QGLMaterial::twoSidedMaterial() -{ - QGLTwoSidedMaterial mat1; - QVERIFY(mat1.front() == 0); - QVERIFY(mat1.back() == 0); - - QSignalSpy frontSpy(&mat1, SIGNAL(frontChanged())); - QSignalSpy backSpy(&mat1, SIGNAL(backChanged())); - QSignalSpy materialSpy(&mat1, SIGNAL(materialChanged())); - - QGLMaterial mat2; - QGLMaterial mat3; - mat1.setFront(&mat2); - QCOMPARE(frontSpy.count(), 1); - QCOMPARE(backSpy.count(), 0); - QCOMPARE(materialSpy.count(), 1); - mat1.setBack(&mat3); - QCOMPARE(frontSpy.count(), 1); - QCOMPARE(backSpy.count(), 1); - QCOMPARE(materialSpy.count(), 2); - QVERIFY(mat1.front() == &mat2); - QVERIFY(mat1.back() == &mat3); - - mat2.setAmbientColor(Qt::red); - QCOMPARE(materialSpy.count(), 3); - - mat3.setAmbientColor(Qt::green); - QCOMPARE(materialSpy.count(), 4); - - QGLMaterial mat4; - QGLMaterial mat5; - - mat1.setFront(&mat4); - QCOMPARE(frontSpy.count(), 2); - QCOMPARE(backSpy.count(), 1); - QCOMPARE(materialSpy.count(), 5); - - mat2.setAmbientColor(Qt::blue); - QCOMPARE(materialSpy.count(), 5); - - mat1.setBack(&mat5); - QCOMPARE(frontSpy.count(), 2); - QCOMPARE(backSpy.count(), 2); - QCOMPARE(materialSpy.count(), 6); - QVERIFY(mat1.front() == &mat4); - QVERIFY(mat1.back() == &mat5); - - mat3.setAmbientColor(Qt::cyan); - QCOMPARE(materialSpy.count(), 6); - - mat1.setFront(&mat4); - mat1.setBack(&mat5); - QCOMPARE(frontSpy.count(), 2); - QCOMPARE(backSpy.count(), 2); - QCOMPARE(materialSpy.count(), 6); - - mat1.setFront(0); - QCOMPARE(frontSpy.count(), 3); - QCOMPARE(backSpy.count(), 2); - QCOMPARE(materialSpy.count(), 7); - mat1.setBack(0); - QCOMPARE(frontSpy.count(), 3); - QCOMPARE(backSpy.count(), 3); - QCOMPARE(materialSpy.count(), 8); - QVERIFY(mat1.front() == 0); - QVERIFY(mat1.back() == 0); - - mat1.setFront(&mat2); - mat1.setBack(&mat2); - QCOMPARE(frontSpy.count(), 4); - QCOMPARE(backSpy.count(), 4); - QCOMPARE(materialSpy.count(), 10); - - mat2.setAmbientColor(Qt::white); - QCOMPARE(materialSpy.count(), 11); -} - -static inline QVector4D colorToVector4D(const QColor &color) -{ - return QVector4D(color.redF(), color.greenF(), - color.blueF(), color.alphaF()); -} - -static inline qreal clampRange(qreal value) -{ - if (value < 0.0f) - return 0.0f; - else if (value > 1.0f) - return 1.0f; - else - return value; -} - -static inline QColor vector4DToColor(const QVector4D &value, qreal alpha) -{ - return QColor::fromRgbF(clampRange(value.x()), - clampRange(value.y()), - clampRange(value.z()), - alpha); -} - -// Evaluate the standard GL lighting algorithm to determine what the -// lit pixel on the screen will be with the supplied parameters. -static QColor litColor(const QGLMaterial &material) -{ - QGLLightParameters light; - QGLLightModel model; - - QVector4D color = colorToVector4D(material.emittedLight()); - color += colorToVector4D(material.ambientColor()) * - colorToVector4D(model.ambientSceneColor()); - QVector4D scolor(0, 0, 0, 0); - - QVector3D normal(0, 0, 1); - QVector3D vertex(-0.5f, -0.5f, 0.0f); - - QVector3D toEye; - if (model.viewerPosition() == QGLLightModel::ViewerAtInfinity) - toEye = QVector3D(0, 0, 1); - else - toEye = (-vertex).normalized(); - - QVector3D toLight; - QVector4D pli = light.eyePosition(QMatrix4x4()); - if (pli.w() == 0.0f) - toLight = pli.toVector3D().normalized(); - else - toLight = (pli.toVector3D() - vertex).normalized(); - - qreal angle = qMax(QVector3D::dotProduct(normal, toLight), qreal(0.0f)); - - QVector4D adcomponent = colorToVector4D(material.ambientColor()) * - colorToVector4D(light.ambientColor()); - adcomponent += angle * colorToVector4D(material.diffuseColor()) * - colorToVector4D(light.diffuseColor()); - - QVector4D scomponent; - if (angle != 0.0f) { - QVector3D h = (toLight + toEye).normalized(); - angle = qMax(QVector3D::dotProduct(normal, h), qreal(0.0f)); - if (material.shininess() != 0.0f) { - scomponent = qPow(angle, material.shininess()) * - colorToVector4D(material.specularColor()) * - colorToVector4D(light.specularColor()); - } else { - scomponent = colorToVector4D(material.specularColor()) * - colorToVector4D(light.specularColor()); - } - } else { - scomponent = QVector4D(0, 0, 0, 0); - } - - if (light.spotAngle() != 180.0f) { - qreal spot = qMax(QVector3D::dotProduct - (vertex - pli.toVector3D(), light.spotDirection()), qreal(0.0f)); - if (spot < light.spotCosAngle()) { - adcomponent = QVector4D(0, 0, 0, 0); - scomponent = QVector4D(0, 0, 0, 0); - } else { - spot = qPow(spot, light.spotExponent()); - adcomponent *= spot; - scomponent *= spot; - } - } - - if (pli.w() != 0.0f) { - qreal attenuation = light.constantAttenuation(); - qreal len = (pli.toVector3D() - vertex).length(); - attenuation += light.linearAttenuation() * len; - attenuation += light.quadraticAttenuation() * len * len; - color += adcomponent / attenuation; - scolor += scomponent / attenuation; - } else { - color += adcomponent; - scolor += scomponent; - } - - return vector4DToColor(color + scolor, material.diffuseColor().alphaF()); -} - -void tst_QGLMaterial::standardMaterialDraw() -{ - if (!widget->isValid()) - QSKIP("GL Implementation not valid", SkipSingle); - - QGLMaterial mat1; - QVERIFY(widget->runTest(&mat1)); - QVERIFY(widget->sameColor(litColor(mat1))); -} - -void tst_QGLMaterial::colorMaterialDraw() -{ - if (!widget->isValid()) - QSKIP("GL Implementation not valid", SkipSingle); - - QGLColorMaterial mat1; - mat1.setColor(Qt::blue); - QVERIFY(widget->runTest(&mat1)); - QVERIFY(widget->sameColor(Qt::blue)); -} - -QTEST_MAIN(tst_QGLMaterial) - -#include "tst_qglmaterial.moc" diff --git a/tests/auto/threed/qglmaterialcollection/qglmaterialcollection.pro b/tests/auto/threed/qglmaterialcollection/qglmaterialcollection.pro deleted file mode 100644 index dddbfca3..00000000 --- a/tests/auto/threed/qglmaterialcollection/qglmaterialcollection.pro +++ /dev/null @@ -1,6 +0,0 @@ -load(qttest_p4.prf) -TEMPLATE=app -QT += testlib -CONFIG += unittest warn_on qt3d - -SOURCES += tst_qglmaterialcollection.cpp diff --git a/tests/auto/threed/qglmaterialcollection/tst_qglmaterialcollection.cpp b/tests/auto/threed/qglmaterialcollection/tst_qglmaterialcollection.cpp deleted file mode 100644 index 24ecacb1..00000000 --- a/tests/auto/threed/qglmaterialcollection/tst_qglmaterialcollection.cpp +++ /dev/null @@ -1,236 +0,0 @@ -/**************************************************************************** -** -** 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 QtQuick3D module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** 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. -** -** 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. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include <QtTest/QtTest> -#include "qglmaterialcollection.h" - -class tst_QGLMaterialCollection : public QObject -{ - Q_OBJECT -public: - tst_QGLMaterialCollection() : destroyCount(0) {} - ~tst_QGLMaterialCollection() {} - -private slots: - void simple(); - void addMaterial(); - void ownership(); - void markUsed(); - -public slots: - void materialDestroyed() { ++destroyCount; } - -private: - int destroyCount; -}; - -// Simple sanity check on the collection. -void tst_QGLMaterialCollection::simple() -{ - QGLMaterialCollection *coll = new QGLMaterialCollection(); - QVERIFY(coll->isEmpty()); - QCOMPARE(coll->size(), 0); - QVERIFY(!coll->material(0)); - QCOMPARE(coll->indexOf(QLatin1String("foo")), -1); - - destroyCount = 0; - - QGLMaterial *mat = new QGLMaterial(this); - mat->setObjectName(QLatin1String("foo")); - connect(mat, SIGNAL(destroyed()), this, SLOT(materialDestroyed())); - QCOMPARE(coll->addMaterial(mat), 0); - QVERIFY(mat->parent() == coll); // Ownership transfers to collection. - - QVERIFY(!coll->isEmpty()); - QCOMPARE(coll->size(), 1); - QVERIFY(coll->material(0) == mat); - QCOMPARE(coll->indexOf(QLatin1String("foo")), 0); - QCOMPARE(coll->indexOf(QLatin1String("bar")), -1); - - QCOMPARE(destroyCount, 0); - delete coll; - QCOMPARE(destroyCount, 1); // Check that the material was destroyed. -} - -// Test adding lots of materials and then looking them up. -// Also acts as a torture test for the underlying data structures. -void tst_QGLMaterialCollection::addMaterial() -{ - QGLMaterialCollection *coll = new QGLMaterialCollection(); - - const int Size = 2048; - - QGLMaterial **materials = new QGLMaterial *[Size]; - for (int index = 0; index < Size; ++index) { - QGLMaterial *mat = new QGLMaterial(); - mat->setObjectName(QString::number(index)); - connect(mat, SIGNAL(destroyed()), this, SLOT(materialDestroyed())); - materials[index] = mat; - QCOMPARE(coll->addMaterial(mat), index); - } - QCOMPARE(coll->size(), Size); - QVERIFY(!coll->isEmpty()); - - for (int index = 0; index < Size; ++index) { - QString name = QString::number(index); - QVERIFY(coll->material(index) == materials[index]); - QVERIFY(coll->material(name) == materials[index]); - QVERIFY(coll->contains(materials[index])); - QVERIFY(coll->contains(name)); - QCOMPARE(coll->indexOf(materials[index]), index); - QCOMPARE(coll->indexOf(name), index); - QCOMPARE(coll->materialName(index), name); - } - - QGLMaterial *mat = new QGLMaterial(); - - QVERIFY(!coll->material(-1)); - QVERIFY(!coll->material(coll->size())); - QVERIFY(!coll->contains(0)); - QVERIFY(!coll->contains(mat)); - QVERIFY(!coll->contains(QLatin1String("foo"))); - QCOMPARE(coll->indexOf(0), -1); - QCOMPARE(coll->indexOf(mat), -1); - QCOMPARE(coll->indexOf(QLatin1String("foo")), -1); - - delete mat; - - destroyCount = 0; - delete coll; - QCOMPARE(destroyCount, Size); -} - -// Test collection ownership. -void tst_QGLMaterialCollection::ownership() -{ - QGLMaterialCollection coll; - - QGLMaterial *mat = new QGLMaterial(this); - mat->setObjectName(QLatin1String("foo")); - - QGLMaterial *mat2 = new QGLMaterial(this); - mat2->setObjectName(QLatin1String("bar")); - - // Adding the same material multiple times returns the same index. - QCOMPARE(coll.addMaterial(mat), 0); - QCOMPARE(coll.addMaterial(mat2), 1); - QCOMPARE(coll.addMaterial(mat), 0); - QVERIFY(coll.material(0) == mat); - QVERIFY(coll.material(1) == mat2); - QCOMPARE(coll.indexOf(QLatin1String("foo")), 0); - QCOMPARE(coll.indexOf(QLatin1String("bar")), 1); - QCOMPARE(coll.size(), 2); - - // Shouldn't be able to add to another collection yet. - QGLMaterialCollection coll2; - QCOMPARE(coll2.addMaterial(mat), -1); - QVERIFY(coll2.isEmpty()); - - // Remove a material from the first collection and add it to the second. - QVERIFY(mat->parent() == &coll); - coll.removeMaterial(mat); - QVERIFY(!mat->parent()); // Parent should revert to null when removed. - QCOMPARE(coll.size(), 2); // Still two elements, one is null. - QVERIFY(coll.material(0) == 0); - QVERIFY(coll.material(1) == mat2); - QCOMPARE(coll.indexOf(QLatin1String("foo")), -1); - QCOMPARE(coll.indexOf(QLatin1String("bar")), 1); - QCOMPARE(coll2.addMaterial(mat), 0); - QVERIFY(mat->parent() == &coll2); - QCOMPARE(coll2.size(), 1); - QVERIFY(coll2.material(0) == mat); - QCOMPARE(coll2.indexOf(QLatin1String("foo")), 0); -} - -// Test material marking. -void tst_QGLMaterialCollection::markUsed() -{ - QGLMaterialCollection coll; - - QGLMaterial *mat = new QGLMaterial(this); - mat->setObjectName(QLatin1String("foo")); - connect(mat, SIGNAL(destroyed()), this, SLOT(materialDestroyed())); - - QGLMaterial *mat2 = new QGLMaterial(this); - mat2->setObjectName(QLatin1String("bar")); - connect(mat2, SIGNAL(destroyed()), this, SLOT(materialDestroyed())); - - QGLMaterial *mat3 = new QGLMaterial(this); - mat3->setObjectName(QLatin1String("baz")); - connect(mat3, SIGNAL(destroyed()), this, SLOT(materialDestroyed())); - - coll.addMaterial(mat); - coll.addMaterial(mat2); - coll.addMaterial(mat3); - - QVERIFY(!coll.isMaterialUsed(0)); - QVERIFY(!coll.isMaterialUsed(1)); - QVERIFY(!coll.isMaterialUsed(2)); - - coll.markMaterialAsUsed(1); - QVERIFY(!coll.isMaterialUsed(0)); - QVERIFY(coll.isMaterialUsed(1)); - QVERIFY(!coll.isMaterialUsed(2)); - - QVERIFY(coll.material(0) == mat); - QVERIFY(coll.material(1) == mat2); - QVERIFY(coll.material(2) == mat3); - - destroyCount = 0; - coll.removeUnusedMaterials(); - QCOMPARE(destroyCount, 2); - - QVERIFY(coll.material(0) == 0); - QVERIFY(coll.material(1) == mat2); - QVERIFY(coll.material(2) == 0); - - QVERIFY(!coll.contains(QLatin1String("foo"))); - QVERIFY(coll.contains(QLatin1String("bar"))); - QVERIFY(!coll.contains(QLatin1String("baz"))); - - // Bounds checks. - QVERIFY(!coll.isMaterialUsed(-1)); - QVERIFY(!coll.isMaterialUsed(3)); -} - -QTEST_APPLESS_MAIN(tst_QGLMaterialCollection) - -#include "tst_qglmaterialcollection.moc" diff --git a/tests/auto/threed/qglpainter/qglpainter.pro b/tests/auto/threed/qglpainter/qglpainter.pro deleted file mode 100644 index 0f195dcf..00000000 --- a/tests/auto/threed/qglpainter/qglpainter.pro +++ /dev/null @@ -1,15 +0,0 @@ -load(qttest_p4.prf) -TEMPLATE=app -QT += testlib -CONFIG += unittest warn_on qt3d - -INCLUDEPATH += ../../../shared -VPATH += ../../../shared - -SOURCES += tst_qglpainter.cpp \ - qgltestwidget.cpp \ - compareimage.cpp \ - qglsimulator.cpp -HEADERS += qgltestwidget.h \ - compareimage.h \ - qglsimulator.h diff --git a/tests/auto/threed/qglpainter/qglsimulator.cpp b/tests/auto/threed/qglpainter/qglsimulator.cpp deleted file mode 100644 index 80cf4d60..00000000 --- a/tests/auto/threed/qglpainter/qglsimulator.cpp +++ /dev/null @@ -1,129 +0,0 @@ -/**************************************************************************** -** -** 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 QtQuick3D module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** 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. -** -** 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. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qglsimulator.h" - -QGLSimulator::QGLSimulator(QPainter *painter, const QSize& size) - : m_painter(painter), - m_size(size), - m_clearColor(Qt::black), - m_viewport(0, 0, size.width(), size.height()) -{ -} - -QGLSimulator::~QGLSimulator() -{ -} - -void QGLSimulator::clear() -{ - m_painter->fillRect(0, 0, m_size.width(), m_size.height(), m_clearColor); -} - -void QGLSimulator::setScissor(const QRect& rect) -{ - m_scissor = rect; - m_painter->setClipRect(rect); -} - -void QGLSimulator::intersectScissor(const QRect& rect) -{ - m_scissor = rect.intersected(m_scissor); - m_painter->setClipRect(m_scissor); -} - -void QGLSimulator::expandScissor(const QRect& rect) -{ - m_scissor = rect.united(m_scissor); - m_painter->setClipRect(m_scissor); -} - -void QGLSimulator::clearScissor() -{ - m_painter->setClipping(false); -} - -void QGLSimulator::setViewport(int x, int y, int width, int height) -{ - m_viewport = QRect(x, y, width, height); -} - -// Set the flat color for drawing triangles. -void QGLSimulator::setColor(const QColor& color) -{ - m_painter->setBrush(QBrush(color)); - m_painter->setPen(QPen()); -} - -// Draw a set of triangles from a vertex array. -void QGLSimulator::drawTriangles(const QVector2DArray& array) -{ - QVector<QPointF> points; - - for (int index = 0; index < array.count(); ++index) { - QVector3D v = array[index]; - points.append(project(v)); - } - - m_painter->drawPolygon(points); -} - -void QGLSimulator::drawTriangles(const QVector3DArray& array) -{ - QVector<QPointF> points; - - for (int index = 0; index < array.count(); ++index) { - QVector3D v = array[index]; - points.append(project(v)); - } - - m_painter->drawPolygon(points); -} - -// Project a 3D point to 2D and convert to left-handed QPainter co-ordinates. -QPointF QGLSimulator::project(const QVector3D& vector) const -{ - QVector3D pt = (m_projectionMatrix * m_modelViewMatrix) * vector; - qreal x = (pt.x() + 1.0f) * m_viewport.width() * 0.5f + m_viewport.x(); - qreal y = (pt.y() + 1.0f) * m_viewport.height() * 0.5f + m_viewport.y(); - y = (m_viewport.height() - 1) - y; - return QPointF(x, y); -} diff --git a/tests/auto/threed/qglpainter/qglsimulator.h b/tests/auto/threed/qglpainter/qglsimulator.h deleted file mode 100644 index dc4a4439..00000000 --- a/tests/auto/threed/qglpainter/qglsimulator.h +++ /dev/null @@ -1,91 +0,0 @@ -/**************************************************************************** -** -** 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 QtQuick3D module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** 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. -** -** 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. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QGLSIMULATOR_H -#define QGLSIMULATOR_H - -#include <QtGui/qpainter.h> -#include <QtGui/qcolor.h> -#include <QtGui/qmatrix4x4.h> -#include <QtGui/qvector3d.h> -#include "qvector2darray.h" -#include "qvector3darray.h" - -class QGLSimulator -{ -public: - QGLSimulator(QPainter *painter, const QSize& size); - ~QGLSimulator(); - - void setClearColor(const QColor& color) { m_clearColor = color; } - void clear(); - - void setScissor(const QRect& rect); - void intersectScissor(const QRect& rect); - void expandScissor(const QRect& rect); - void clearScissor(); - - void setViewport(int x, int y, int width, int height); - - QMatrix4x4 projectionMatrix() const { return m_projectionMatrix; } - void setProjectionMatrix(const QMatrix4x4& m) { m_projectionMatrix = m; } - - QMatrix4x4 modelViewMatrix() const { return m_modelViewMatrix; } - void setModelViewMatrix(const QMatrix4x4& m) { m_modelViewMatrix = m; } - - void setColor(const QColor& color); - - void drawTriangles(const QVector2DArray& array); - void drawTriangles(const QVector3DArray& array); - -private: - QPainter *m_painter; - QSize m_size; - QColor m_clearColor; - QRect m_viewport; - QMatrix4x4 m_projectionMatrix; - QMatrix4x4 m_modelViewMatrix; - QRect m_scissor; - - QPointF project(const QVector3D& vector) const; -}; - -#endif diff --git a/tests/auto/threed/qglpainter/qgltestwidget.cpp b/tests/auto/threed/qglpainter/qgltestwidget.cpp deleted file mode 100644 index b54976df..00000000 --- a/tests/auto/threed/qglpainter/qgltestwidget.cpp +++ /dev/null @@ -1,121 +0,0 @@ -/**************************************************************************** -** -** 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 QtQuick3D module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** 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. -** -** 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. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include <QtTest/QtTest> -#include "qgltestwidget.h" -#include "compareimage.h" -#include <QtCore/qeventloop.h> -#include <QtCore/qtimer.h> -#include <QtGui/qpainter.h> - -QGLTestWidget::QGLTestWidget(QWidget *parent) - : QGLWidget(parent) -{ - eventLoop = 0; - paintDone = false; - target = 0; - method = 0; -} - -QGLTestWidget::~QGLTestWidget() -{ - delete eventLoop; -} - -bool QGLTestWidget::runTest(QObject *target, const char *method, int timeout) -{ - if (eventLoop) - delete eventLoop; - paintDone = false; - capture = QImage(); - simulated = QImage(); - this->target = target; - this->method = method; - eventLoop = new QEventLoop(this); - QTimer::singleShot(timeout, eventLoop, SLOT(quit())); - if (!isVisible()) { - show(); -#ifdef Q_WS_X11 - qt_x11_wait_for_window_manager(this); -#endif - } else { - updateGL(); - } - if (!paintDone) - eventLoop->exec(); - delete eventLoop; - eventLoop = 0; - this->target = 0; - this->method = 0; - if (!paintDone) { - qWarning("timed out"); - return false; - } - if (!qFuzzyCompare(capture, simulated)) { - qWarning("output is not as expected"); - return false; - } - return true; -} - -void QGLTestWidget::paintGL() -{ - if (target && method) - QMetaObject::invokeMethod(target, method, Qt::DirectConnection); - capture = grabFrameBuffer(); - if (target && method) { - QSize sz = size(); - simulated = QImage(sz, QImage::Format_RGB32); - QPainter painter; - painter.begin(&simulated); - QByteArray meth(method); - meth.append('Q'); - QMetaObject::invokeMethod - (target, meth.constData(), Qt::DirectConnection, - Q_ARG(QPainter *, &painter), Q_ARG(const QSize, sz)); - painter.end(); - } - if (!paintDone) { - paintDone = true; - if (eventLoop) - eventLoop->quit(); - } -} diff --git a/tests/auto/threed/qglpainter/qgltestwidget.h b/tests/auto/threed/qglpainter/qgltestwidget.h deleted file mode 100644 index 7fb17e6a..00000000 --- a/tests/auto/threed/qglpainter/qgltestwidget.h +++ /dev/null @@ -1,75 +0,0 @@ -/**************************************************************************** -** -** 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 QtQuick3D module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** 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. -** -** 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. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QGLTESTWIDGET_H -#define QGLTESTWIDGET_H - -#include <QtOpenGL/qgl.h> - -QT_BEGIN_NAMESPACE -class QEventLoop; -QT_END_NAMESPACE - -class QGLTestWidget : public QGLWidget -{ - Q_OBJECT -public: - QGLTestWidget(QWidget *parent = 0); - ~QGLTestWidget(); - - bool runTest(QObject *target, const char *method, int timeout = 5000); - - QImage actualOutput() const { return capture; } - QImage simulatedOutput() const { return simulated; } - -protected: - void paintGL(); - -private: - QEventLoop *eventLoop; - bool paintDone; - QImage capture; - QImage simulated; - QObject *target; - const char *method; -}; - -#endif diff --git a/tests/auto/threed/qglpainter/tst_qglpainter.cpp b/tests/auto/threed/qglpainter/tst_qglpainter.cpp deleted file mode 100644 index 82ee6521..00000000 --- a/tests/auto/threed/qglpainter/tst_qglpainter.cpp +++ /dev/null @@ -1,874 +0,0 @@ -/**************************************************************************** -** -** 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 QtQuick3D module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** 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. -** -** 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. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include <QtTest/QtTest> -#include <QtOpenGL/qgl.h> -#include <QtGui/qpainter.h> -#include "qgltestwidget.h" -#include "qglpainter.h" -#include "qglsimulator.h" - -class tst_QGLPainter : public QObject -{ - Q_OBJECT -public: - tst_QGLPainter() : widget(0) {} - ~tst_QGLPainter() {} - -private slots: - void initTestCase(); - void cleanupTestCase(); - void clear(); - void drawTriangle(); - void scissor(); - void userMatrixStack(); - void projectionMatrixStack(); - void modelViewMatrixStack(); - void worldMatrix(); - void basicCullable(); - void isCullable_data(); - void isCullable(); - void isCullableVert_data(); - void isCullableVert(); - void lights(); - void nextPowerOfTwo_data(); - void nextPowerOfTwo(); - -public slots: - void clearPaint(); - void clearPaintQ(QPainter *painter, const QSize& size); - void drawTrianglePaint(); - void drawTrianglePaintQ(QPainter *painter, const QSize& size); - void scissorPaint(); - void scissorPaintQ(QPainter *painter, const QSize& size); - -private: - QGLTestWidget *widget; -}; - -void tst_QGLPainter::initTestCase() -{ - widget = new QGLTestWidget(); -} - -void tst_QGLPainter::cleanupTestCase() -{ - delete widget; -} - -void tst_QGLPainter::clear() -{ - if (!widget->isValid()) - QSKIP("GL Implementation not valid", SkipSingle); - - QVERIFY(widget->runTest(this, "clearPaint")); -} - -void tst_QGLPainter::clearPaint() -{ - QGLPainter painter; - painter.begin(); - painter.setClearColor(Qt::blue); - glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); -} - -void tst_QGLPainter::clearPaintQ(QPainter *painter, const QSize& size) -{ - QGLSimulator sim(painter, size); - sim.setClearColor(Qt::blue); - sim.clear(); -} - -void tst_QGLPainter::drawTriangle() -{ - if (!widget->isValid()) - QSKIP("GL Implementation not valid", SkipSingle); - - QVERIFY(widget->runTest(this, "drawTrianglePaint")); -} - -void tst_QGLPainter::drawTrianglePaint() -{ - QGLPainter painter; - painter.begin(); - painter.setClearColor(Qt::black); - glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); - - QMatrix4x4 projm; - projm.ortho(widget->rect()); - painter.projectionMatrix() = projm; - painter.modelViewMatrix().setToIdentity(); - - QVector2DArray vertices; - vertices.append(10, 100); - vertices.append(500, 100); - vertices.append(500, 500); - - painter.clearAttributes(); - painter.setStandardEffect(QGL::FlatColor); - painter.setColor(Qt::green); - painter.setVertexAttribute(QGL::Position, vertices); - painter.draw(QGL::Triangles, 3); -} - -void tst_QGLPainter::drawTrianglePaintQ(QPainter *painter, const QSize& size) -{ - QGLSimulator sim(painter, size); - - sim.clear(); - sim.setColor(Qt::green); - - QMatrix4x4 proj; - proj.ortho(widget->rect()); - sim.setProjectionMatrix(proj); - - QVector2DArray vertices; - vertices.append(10, 100); - vertices.append(500, 100); - vertices.append(500, 500); - - sim.drawTriangles(vertices); -} - -static QRect fetchGLScissor(const QRect& windowRect) -{ - GLint scissor[4]; - glGetIntegerv(GL_SCISSOR_BOX, scissor); - if (scissor[2] != 0 && scissor[3] != 0) { - return QRect(scissor[0], - windowRect.height() - (scissor[1] + scissor[3]), - scissor[2], scissor[3]); - } else { - // Normally should be (0, 0, 0, 0) - don't adjust for window height. - return QRect(scissor[0], scissor[1], scissor[2], scissor[3]); - } -} - -void tst_QGLPainter::scissor() -{ - if (!widget->isValid()) - QSKIP("GL Implementation not valid", SkipSingle); - - // Run a painting test to check that the scissor works. - QVERIFY(widget->runTest(this, "scissorPaint")); - - // Perform some lower level tests to ensure that the - // GL state is updated properly as the scissor changes. - QGLPainter painter; - painter.begin(widget); - QRect windowRect = widget->rect(); - - QVERIFY(!glIsEnabled(GL_SCISSOR_TEST)); - - painter.setScissor(windowRect); - QCOMPARE(fetchGLScissor(windowRect), windowRect); - - QRect subRect(windowRect.width() / 3, - windowRect.height() / 3, - 2 * windowRect.width() / 3, - 2 * windowRect.height() / 3); - painter.setScissor(subRect); - QCOMPARE(fetchGLScissor(windowRect), subRect); - - // Empty rectangles should result in glScissor(0, 0, 0, 0). - painter.setScissor(QRect(0, 0, -2, -2)); - QCOMPARE(fetchGLScissor(windowRect), QRect(0, 0, 0, 0)); - painter.setScissor(QRect(27, 42, 0, 0)); - QCOMPARE(fetchGLScissor(windowRect), QRect(0, 0, 0, 0)); -} - -void tst_QGLPainter::scissorPaint() -{ - QGLPainter painter; - painter.begin(); - painter.setClearColor(Qt::black); - glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); - - QMatrix4x4 projm; - projm.ortho(widget->rect()); - painter.projectionMatrix() = projm; - painter.modelViewMatrix().setToIdentity(); - - QVector2DArray vertices; - vertices.append(10, 100); - vertices.append(500, 100); - vertices.append(500, 500); - - // Paint a green triangle. - painter.clearAttributes(); - painter.setStandardEffect(QGL::FlatColor); - painter.setColor(Qt::green); - painter.setVertexAttribute(QGL::Position, vertices); - painter.draw(QGL::Triangles, 3); - - // Change the top part of the triangle to blue. - QRect scissor(0, 0, widget->width(), qMin(widget->height() / 2, 200)); - painter.setScissor(scissor); - glEnable(GL_SCISSOR_TEST); - painter.setColor(Qt::blue); - painter.draw(QGL::Triangles, 3); - - // Intersect and draw red over the blue section. - painter.setScissor(scissor.intersected - (QRect(0, 0, widget->width(), qMin(widget->height() / 4, 150)))); - painter.setColor(Qt::red); - painter.draw(QGL::Triangles, 3); - - // Change the bottom part of the triangle to yellow. - int y = qMin(widget->height() / 2, 350); - scissor = QRect(0, y, 400, widget->height() - y); - painter.setScissor(scissor); - painter.setColor(Qt::yellow); - painter.draw(QGL::Triangles, 3); - - // Intersect and expand, to extend the yellow region. - scissor &= QRect(0, y + 20, 400, widget->height() - y - 20); - scissor |= QRect(0, y + 20, 450, widget->height() - y - 20); - painter.setScissor(scissor); - painter.setColor(Qt::yellow); - painter.draw(QGL::Triangles, 3); - - glDisable(GL_SCISSOR_TEST); -} - -void tst_QGLPainter::scissorPaintQ(QPainter *painter, const QSize& size) -{ - QGLSimulator sim(painter, size); - - sim.clear(); - - QMatrix4x4 proj; - proj.ortho(widget->rect()); - sim.setProjectionMatrix(proj); - - QVector2DArray vertices; - vertices.append(10, 100); - vertices.append(500, 100); - vertices.append(500, 500); - - // Paint a green triangle. - sim.setColor(Qt::green); - sim.drawTriangles(vertices); - - // Change the top part of the triangle to blue. - sim.setScissor - (QRect(0, 0, widget->width(), qMin(widget->height() / 2, 200))); - sim.setColor(Qt::blue); - sim.drawTriangles(vertices); - - // Intersect and draw red over the blue section. - sim.intersectScissor - (QRect(0, 0, widget->width(), qMin(widget->height() / 4, 150))); - sim.setColor(Qt::red); - sim.drawTriangles(vertices); - - // Change the bottom part of the triangle to yellow. - int y = qMin(widget->height() / 2, 350); - sim.setScissor - (QRect(0, y, 400, widget->height() - y)); - sim.setColor(Qt::yellow); - sim.drawTriangles(vertices); - - // Intersect and expand, to extend the yellow region. - sim.intersectScissor - (QRect(0, y + 20, 400, widget->height() - y - 20)); - sim.expandScissor - (QRect(0, y + 20, 450, widget->height() - y - 20)); - sim.setColor(Qt::yellow); - sim.drawTriangles(vertices); -} - -// Test the mathematical correctness of matrix stacks on a user stack. -// We assume that QMatrix4x4 works and we can use it as an oracle. -void tst_QGLPainter::userMatrixStack() -{ - QMatrix4x4Stack stack; - - QVERIFY(stack.top().isIdentity()); - QVERIFY(QMatrix4x4(stack).isIdentity()); - - QMatrix4x4 m; - m.translate(1, 2, 3); - m.scale(4, 5, 6); - m.rotate(90, 0, 1, 0); - - stack.translate(1, 2, 3); - stack.scale(4, 5, 6); - stack.rotate(90, 0, 1, 0); - QVERIFY(qFuzzyCompare(m, stack.top())); - QVERIFY(qFuzzyCompare(m, QMatrix4x4(stack))); - - stack.push(); - QVERIFY(qFuzzyCompare(m, stack.top())); - QVERIFY(qFuzzyCompare(m, QMatrix4x4(stack))); - - stack.setToIdentity(); - QVERIFY(stack.top().isIdentity()); - - stack.translate(QVector3D(1, 2, 3)); - stack.scale(QVector3D(4, 5, 6)); - stack.rotate(90, QVector3D(0, 1, 0)); - QVERIFY(qFuzzyCompare(m, stack.top())); - QVERIFY(qFuzzyCompare(m, QMatrix4x4(stack))); - - QMatrix4x4 m2(m); - m2.scale(-3); - - stack.scale(-3); - QVERIFY(qFuzzyCompare(m2, stack.top())); - QVERIFY(qFuzzyCompare(m2, QMatrix4x4(stack))); - - stack.pop(); - - QVERIFY(qFuzzyCompare(m, stack.top())); - QVERIFY(qFuzzyCompare(m, QMatrix4x4(stack))); - - stack.pop(); // at bottom of stack - no change - - QVERIFY(qFuzzyCompare(m, stack.top())); - QVERIFY(qFuzzyCompare(m, QMatrix4x4(stack))); - - stack = m2; - QVERIFY(qFuzzyCompare(m2, stack.top())); - QVERIFY(qFuzzyCompare(m2, QMatrix4x4(stack))); - - QMatrix4x4 m3 = m2 * m; - stack *= m; - QVERIFY(qFuzzyCompare(m3, stack.top())); - QVERIFY(qFuzzyCompare(m3, QMatrix4x4(stack))); - - m3.rotate(QQuaternion::fromAxisAndAngle(QVector3D(1, 0, 0), -90)); - stack.rotate(QQuaternion::fromAxisAndAngle(QVector3D(1, 0, 0), -90)); - - QVERIFY(qFuzzyCompare(m3, stack.top())); - QVERIFY(qFuzzyCompare(m3, QMatrix4x4(stack))); - - QMatrix4x4 m4; - - m4.setToIdentity(); - m4.ortho(QRect(2, 3, 4, 5)); - stack.setToIdentity(); - QMatrix4x4 projm; - projm.ortho(QRect(2, 3, 4, 5)); - stack = projm; - QVERIFY(qFuzzyCompare(m4, stack.top())); - QVERIFY(qFuzzyCompare(m4, QMatrix4x4(stack))); -} - -#if defined(QT_OPENGL_ES_2) -#define QGL_NO_MATRIX_FETCH 1 -#endif - -#ifndef QGL_NO_MATRIX_FETCH - -static void clearGLMatrix(GLenum type) -{ - glMatrixMode(type); - glLoadIdentity(); -} - -static bool checkGLMatrix(GLenum type, const QMatrix4x4& expected) -{ - QMatrix4x4 actual; - int index; - GLfloat mat[16]; - glGetFloatv(type, mat); - qreal *m = actual.data(); - for (index = 0; index < 16; ++index) - m[index] = mat[index]; - for (index = 0; index < 16; ++index) { - // Introduce some fuzziness for GL servers that - // use a different precision from QMatrix4x4. - if (qAbs(actual.constData()[index] - expected.constData()[index]) - >= 0.001) - return false; - } - return true; -} - -#else - -#ifndef GL_PROJECTION -#define GL_PROJECTION 0 -#endif -#ifndef GL_PROJECTION_MATRIX -#define GL_PROJECTION_MATRIX 0 -#endif -#ifndef GL_MODELVIEW -#define GL_MODELVIEW 0 -#endif -#ifndef GL_MODELVIEW_MATRIX -#define GL_MODELVIEW_MATRIX 0 -#endif - -// OpenGL/ES 2.0 does not have server-side matrices. -// For such platforms, we stub out the checks and just hope that they work. -static void clearGLMatrix(GLenum) {} -static bool checkGLMatrix(GLenum, const QMatrix4x4&) { return true; } - -#endif - -void tst_QGLPainter::projectionMatrixStack() -{ - if (!widget->isValid()) - QSKIP("GL Implementation not valid", SkipSingle); - - QGLPainter painter(widget); - - painter.projectionMatrix().setToIdentity(); - QVERIFY(painter.projectionMatrix().top().isIdentity()); - QVERIFY(QMatrix4x4(painter.projectionMatrix()).isIdentity()); - - // Clear the matrix in the GL server. - clearGLMatrix(GL_PROJECTION); - - QMatrix4x4 m; - m.ortho(2, 4, 3, 1, 10, 50); - painter.projectionMatrix() = m; - QVERIFY(qFuzzyCompare(m, painter.projectionMatrix().top())); - QVERIFY(qFuzzyCompare(m, QMatrix4x4(painter.projectionMatrix()))); - - // The matrix in the GL server should still be the identity. - QVERIFY(checkGLMatrix(GL_PROJECTION_MATRIX, QMatrix4x4())); - - // Force an update to the GL server. - painter.updateFixedFunction(QGLPainter::UpdateProjectionMatrix); - - // Check that the server received the value we set. - QVERIFY(checkGLMatrix(GL_PROJECTION_MATRIX, m)); -} - -void tst_QGLPainter::modelViewMatrixStack() -{ - if (!widget->isValid()) - QSKIP("GL Implementation not valid", SkipSingle); - - QGLPainter painter(widget); - - painter.modelViewMatrix().setToIdentity(); - QVERIFY(painter.modelViewMatrix().top().isIdentity()); - QVERIFY(QMatrix4x4(painter.modelViewMatrix()).isIdentity()); - - // Clear the matrix in the GL server. - clearGLMatrix(GL_MODELVIEW); - - QMatrix4x4 m; - m.translate(1, 2, 3); - m.scale(4, 5, 6); - m.rotate(90, 0, 1, 0); - painter.modelViewMatrix().translate(1, 2, 3); - painter.modelViewMatrix().scale(4, 5, 6); - painter.modelViewMatrix().rotate(90, 0, 1, 0); - QVERIFY(qFuzzyCompare(m, painter.modelViewMatrix().top())); - QVERIFY(qFuzzyCompare(m, QMatrix4x4(painter.modelViewMatrix()))); - - // The matrix in the GL server should still be the identity. - QVERIFY(checkGLMatrix(GL_MODELVIEW_MATRIX, QMatrix4x4())); - - // Force an update to the GL server. - painter.updateFixedFunction(QGLPainter::UpdateModelViewMatrix); - - // Check that the server received the value we set. - QVERIFY(checkGLMatrix(GL_MODELVIEW_MATRIX, m)); -} - -static bool fuzzyCompare(const QMatrix4x4 &m1, const QMatrix4x4 &m2) -{ - for (int row = 0; row < 4; ++row) { - for (int col = 0; col < 4; ++col) { - if (qAbs(m1(row, col) - m2(row, col)) >= 0.00001f) - return false; - } - } - return true; -} - -void tst_QGLPainter::worldMatrix() -{ - QGLPainter painter(widget); - - QGLCamera camera; - camera.setEye(QVector3D(1, 2, 10)); - camera.setCenter(QVector3D(20, 3, -4)); - camera.setUpVector(QVector3D(1, 1, 1)); - painter.setCamera(&camera); - - // The modelview matrix should be the eye look-at component. - QMatrix4x4 mv; - mv.lookAt(camera.eye(), camera.center(), camera.upVector()); - QVERIFY(fuzzyCompare(painter.modelViewMatrix(), mv)); - - // The world matrix should currently be the identity. - QVERIFY(fuzzyCompare(painter.worldMatrix(), QMatrix4x4())); - - // Change the modelview. - painter.modelViewMatrix().translate(0.0f, 5.0f, 0.0f); - painter.modelViewMatrix().scale(1.5f); - - // Check the modelview and world matrices against their expected values. - QMatrix4x4 world; - world.translate(0.0f, 5.0f, 0.0f); - world.scale(1.5f); - QVERIFY(fuzzyCompare(painter.modelViewMatrix(), mv * world)); - QVERIFY(fuzzyCompare(painter.worldMatrix(), world)); -} - -void tst_QGLPainter::basicCullable() -{ - QGLWidget w; - QGLPainter painter(&w); - painter.modelViewMatrix().setToIdentity(); - - // Default values for the camera have - // eye = (0, 0, 10) - so eye at positive 10 on z-axis - // center = (0, 0, 0) - looking at the origin, in a negative z-direction - // viewport = 2 x 2 - ideal square view frustum - // near = 5 - distance from eye to near plane - // far = 1000 - distance from eye to far plane - // far plane is a z = -990 - QGLCamera camera; - painter.setCamera(&camera); - - // origin itself and a point 10 further down the view vector - // both must be visible - QVERIFY(!painter.isCullable(QVector3D(0, 0, 0))); - QVERIFY(!painter.isCullable(QVector3D(0, 0, -10))); - - // the position of the eye itself, is behind the near plane, so culled. - QVERIFY(painter.isCullable(QVector3D(0, 0, 10))); - // Reset the camera and then check boxes in front of the camera - // that are close to the near and far planes and the eye. - QGLCamera camera2; - painter.setCamera(&camera2); - - // Box around the eye, but in front of the near plane. - QBox3D box2(QVector3D(-1, -1, 11), QVector3D(1, 1, 9)); - QVERIFY(painter.isCullable(box2)); - - // Box that surrounds the near plane. - QBox3D box3(QVector3D(-1, -1, 6), QVector3D(1, 1, 4)); - QVERIFY(!painter.isCullable(box3)); - - // Box between the near plane and the eye. - QBox3D box4(QVector3D(-1, -1, 7), QVector3D(1, 1, 6)); - QVERIFY(painter.isCullable(box4)); - - // Box extending from behind the eye to inside the viewing cube. - // Not cullable because it is partially visible. - QBox3D box5(QVector3D(-1, -1, 11), QVector3D(1, 1, 0)); - QVERIFY(!painter.isCullable(box5)); - - // Box that surrounds the far plane. - QBox3D box6(QVector3D(-1, -1, -989), QVector3D(1, 1, -991)); - QVERIFY(!painter.isCullable(box6)); - - // Box that is between the near and far planes, but close to far plane. - QBox3D box7(QVector3D(-1, -1, -988), QVector3D(1, 1, -989)); - QVERIFY(!painter.isCullable(box7)); - - // Box that is beyond the far plane. - QBox3D box8(QVector3D(-1, -1, -1000), QVector3D(1, 1, -1001)); - QVERIFY(painter.isCullable(box8)); -} - -static void setupTestCamera(QGLCamera &camera, float distance) -{ - // These values are based on the special camera as per the images in - // doc/src/images/view-frustum* - - // Check the cullability of a box at 10 degree increments of rotation. - // It should be visible between -20 and 20 degrees but otherwise not. - // Also check the center point of the box. - - camera.setNearPlane(2.2f); - camera.setFarPlane(14.0f); - - // This value comes from the ratio of the far plane size 8 x 8 to the - // far plane distance, multiplied by the near plane, to give the near - // plane size: 2.2 x (4 / 14) = 1.257 - camera.setViewSize(QSizeF(1.257f, 1.257f)); - - // as shown in the images, we use a camera at -z instead of the default +z - // but the center remains the same at 0, 0, 0 - camera.setEye(QVector3D(0, 0, distance)); - - // if the distance would push the camera eye past the view center - // move the view center away - if (distance > 0.0f) - camera.setCenter(QVector3D(0.0f, 0.0f, distance + 2)); -} - -void tst_QGLPainter::isCullable_data() -{ - QTest::addColumn<float>("angle"); - QTest::addColumn<float>("distance"); - QTest::addColumn<bool>("culled"); - QTest::addColumn<bool>("center_culled"); - - // Check the cullability of a box at 10 degree increments of rotation. - // It should be visible between -20 and 20 degrees but otherwise not. - // Also check the point at the center of the box. - - QTest::newRow("culled-neg40") << -40.0f << -8.0f << true << true; - QTest::newRow("culled-neg30") << -30.0f << -8.0f << true << true; - QTest::newRow("part-vis-neg20") << -20.0f << -8.0f << false << false; - QTest::newRow("part-vis-neg10") << -10.0f << -8.0f << false << false; - QTest::newRow("all-vis-00") << 0.0f << -8.0f << false << false; - QTest::newRow("part-vis-pos10") << 10.0f << -8.0f << false << false; - QTest::newRow("part-vis-pos20") << 20.0f << -8.0f << false << false; - QTest::newRow("culled-pos30") << 30.0f << -8.0f << true << true; - QTest::newRow("culled-pos40") << 40.0f << -8.0f << true << true; - - // Check when the eye is at varying distances from the box, with - // (in one case with an angle for good measure) so that it needs - // testing against the near and far planes. - - QTest::newRow("culled-eye-z+2") << 0.0f << 2.0f << true << true; - QTest::newRow("culled-eye-z+0") << 0.0f << 0.0f << true << true; - QTest::newRow("part-vis-eye-z-2-around-np") << 0.0f << -2.0f << false << true; - QTest::newRow("part-vis-eye-z-3-around-np") << 0.0f << -3.0f << false << false; - QTest::newRow("part-vis-eye-z-4-close-np") << 0.0f << -4.0f << false << false; - QTest::newRow("part-vis-eye-z-14.5") << 0.0f << -14.5f << false << true; - QTest::newRow("part-vis-eye-z-14-angle-20") << 20.0f << -14.0f << false << false; - QTest::newRow("culled-eye-z-20") << 0.0f << -20.0f << true << true; -} - -void tst_QGLPainter::isCullable() -{ - QGLWidget w; - QGLPainter painter(&w); - painter.modelViewMatrix().setToIdentity(); - - QGLCamera camera; - - QFETCH(float, angle); - QFETCH(float, distance); - QFETCH(bool, culled); - QFETCH(bool, center_culled); - - setupTestCamera(camera, distance); - if (angle != 0.0f) - camera.rotateEye(camera.pan(angle)); - - painter.setCamera(&camera); - - QBox3D box(QVector3D(-1, -1, -1), QVector3D(1, 1, 1)); - QCOMPARE(painter.isCullable(box), culled); - QCOMPARE(painter.isCullable(box.center()), center_culled); -} - -void tst_QGLPainter::isCullableVert_data() -{ - QTest::addColumn<float>("angle"); - QTest::addColumn<float>("distance"); - QTest::addColumn<bool>("culled"); - QTest::addColumn<bool>("center_culled"); - - // Check the cullability of a box at 10 degree increments of rotation. - // It should be visible between -20 and 20 degrees but otherwise not. - // Also check the point at the center of the box. - - QTest::newRow("culled-neg40") << -40.0f << -8.0f << true << true; - QTest::newRow("culled-neg30") << -30.0f << -8.0f << true << true; - QTest::newRow("part-vis-neg20") << -20.0f << -8.0f << false << true; - QTest::newRow("part-vis-neg10") << -10.0f << -8.0f << false << false; - QTest::newRow("all-vis-00") << 0.0f << -8.0f << false << false; - QTest::newRow("part-vis-pos10") << 10.0f << -8.0f << false << false; - QTest::newRow("part-vis-pos20") << 20.0f << -8.0f << false << true; - QTest::newRow("culled-pos30") << 30.0f << -8.0f << true << true; - QTest::newRow("culled-pos40") << 40.0f << -8.0f << true << true; - - QTest::newRow("culled-eye-z+2") << 0.0f << 2.0f << true << true; - QTest::newRow("culled-eye-z+0") << 0.0f << 0.0f << true << true; - QTest::newRow("part-vis-eye-z-2-around-np") << 0.0f << -2.0f << false << true; - QTest::newRow("part-vis-eye-z-3-around-np") << 0.0f << -3.0f << false << false; - QTest::newRow("part-vis-eye-z-4-close-np") << 0.0f << -4.0f << false << false; - QTest::newRow("part-vis-eye-z-14.2") << 0.0f << -14.2f << false << true; - QTest::newRow("part-vis-eye-z-14-angle-20") << 20.0f << -14.0f << false << true; - QTest::newRow("culled-eye-z-20") << 0.0f << -20.0f << true << true; -} - -void tst_QGLPainter::isCullableVert() -{ - //QSKIP("isCullableVert not passing currently", SkipAll); - // same test as isCullable, except we tilt the camera forward - // and back instead of rotating it from side to side - // since the view frustum is typically not square in section - // as it depends on the surface, this will give different results. - QGLWidget w; - QGLPainter painter(&w); - painter.modelViewMatrix().setToIdentity(); - - QGLCamera camera; - - QFETCH(float, angle); - QFETCH(float, distance); - QFETCH(bool, culled); - QFETCH(bool, center_culled); - - setupTestCamera(camera, distance); - if (angle != 0.0f) - camera.rotateEye(camera.tilt(angle)); - - painter.setCamera(&camera); - - QBox3D box(QVector3D(-1, -1, -1), QVector3D(1, 1, 1)); - QCOMPARE(painter.isCullable(box), culled); - QCOMPARE(painter.isCullable(box.center()), center_culled); -} - -void tst_QGLPainter::lights() -{ - QGLPainter painter(widget); - - // Make sure the mainLight() is not present before we start these tests. - painter.removeLight(0); - - QCOMPARE(painter.maximumLightId(), -1); - QVERIFY(painter.light(0) == 0); - QVERIFY(painter.lightTransform(0).isIdentity()); - QVERIFY(painter.light(-1) == 0); - QVERIFY(painter.lightTransform(-1).isIdentity()); - - QGLLightParameters lparams1; - QGLLightParameters lparams2; - QGLLightParameters lparams3; - - int lightId1 = painter.addLight(&lparams1); - QCOMPARE(lightId1, 0); - QCOMPARE(painter.maximumLightId(), 0); - QVERIFY(painter.light(lightId1) == &lparams1); - QVERIFY(painter.lightTransform(lightId1) == painter.modelViewMatrix()); - - QMatrix4x4 m(painter.modelViewMatrix()); - m.translate(-1, 2, -5); - - int lightId2 = painter.addLight(&lparams2, m); - QCOMPARE(lightId2, 1); - QCOMPARE(painter.maximumLightId(), 1); - QVERIFY(painter.light(lightId1) == &lparams1); - QVERIFY(painter.lightTransform(lightId1) == painter.modelViewMatrix()); - QVERIFY(painter.light(lightId2) == &lparams2); - QVERIFY(painter.lightTransform(lightId2) == m); - - painter.removeLight(lightId1); - QCOMPARE(painter.maximumLightId(), 1); - QVERIFY(painter.light(lightId1) == 0); - QVERIFY(painter.lightTransform(lightId1).isIdentity()); - QVERIFY(painter.light(lightId2) == &lparams2); - QVERIFY(painter.lightTransform(lightId2) == m); - - int lightId3 = painter.addLight(&lparams3); - QCOMPARE(lightId3, 0); - QCOMPARE(painter.maximumLightId(), 1); - QVERIFY(painter.light(lightId3) == &lparams3); - QVERIFY(painter.lightTransform(lightId3) == painter.modelViewMatrix()); - QVERIFY(painter.light(lightId2) == &lparams2); - QVERIFY(painter.lightTransform(lightId2) == m); - - painter.removeLight(lightId2); - QCOMPARE(painter.maximumLightId(), 0); - QVERIFY(painter.light(lightId3) == &lparams3); - QVERIFY(painter.lightTransform(lightId3) == painter.modelViewMatrix()); - QVERIFY(painter.light(lightId2) == 0); - QVERIFY(painter.lightTransform(lightId2).isIdentity()); - - painter.removeLight(lightId3); - QCOMPARE(painter.maximumLightId(), -1); - QVERIFY(painter.light(lightId3) == 0); - QVERIFY(painter.lightTransform(lightId3).isIdentity()); - QVERIFY(painter.light(lightId2) == 0); - QVERIFY(painter.lightTransform(lightId2).isIdentity()); - - // Check default construction of the main light. - const QGLLightParameters *mainLight = painter.mainLight(); - QVERIFY(mainLight != 0); - QCOMPARE(painter.maximumLightId(), 0); - QVERIFY(painter.light(0) == mainLight); - QVERIFY(painter.lightTransform(0).isIdentity()); -} - -void tst_QGLPainter::nextPowerOfTwo_data() -{ - QTest::addColumn<int>("value"); - QTest::addColumn<int>("result"); - - QTest::newRow("0") << 0 << 0; - QTest::newRow("1") << 1 << 1; - QTest::newRow("2") << 2 << 2; - QTest::newRow("3") << 3 << 4; - QTest::newRow("4") << 4 << 4; - QTest::newRow("5") << 5 << 8; - QTest::newRow("6") << 6 << 8; - QTest::newRow("7") << 7 << 8; - QTest::newRow("13") << 13 << 16; - QTest::newRow("16") << 16 << 16; - QTest::newRow("23") << 23 << 32; - QTest::newRow("32") << 32 << 32; - QTest::newRow("63") << 63 << 64; - QTest::newRow("64") << 64 << 64; - QTest::newRow("65") << 65 << 128; - QTest::newRow("120") << 120 << 128; - QTest::newRow("128") << 128 << 128; - QTest::newRow("129") << 129 << 256; - - for (int bit = 8; bit <= 30; ++bit) { - int value = (1 << bit); - QByteArray str; - str = QByteArray::number(value); - QTest::newRow(str.constData()) << (value - 23) << value; - QTest::newRow(str.constData()) << value << value; - } -} - -void tst_QGLPainter::nextPowerOfTwo() -{ - QFETCH(int, value); - QFETCH(int, result); - - QCOMPARE(QGL::nextPowerOfTwo(value), result); - QCOMPARE(QGL::nextPowerOfTwo(QSize(value, 0)), QSize(result, 0)); - QCOMPARE(QGL::nextPowerOfTwo(QSize(0, value)), QSize(0, result)); -} - -QTEST_MAIN(tst_QGLPainter) - -#include "tst_qglpainter.moc" diff --git a/tests/auto/threed/qglpickcolors/qglpickcolors.pro b/tests/auto/threed/qglpickcolors/qglpickcolors.pro deleted file mode 100644 index 1394e282..00000000 --- a/tests/auto/threed/qglpickcolors/qglpickcolors.pro +++ /dev/null @@ -1,14 +0,0 @@ -load(qttest_p4.prf) -TEMPLATE=app -QT += testlib -CONFIG += unittest warn_on - -INCLUDEPATH += ../../../../src/threed/painting -VPATH += ../../../../src/threed/painting - -SOURCES += \ - tst_qglpickcolors.cpp \ - qglpickcolors.cpp - -HEADERS += \ - qglpickcolors_p.h diff --git a/tests/auto/threed/qglpickcolors/tst_qglpickcolors.cpp b/tests/auto/threed/qglpickcolors/tst_qglpickcolors.cpp deleted file mode 100644 index 795cf8fe..00000000 --- a/tests/auto/threed/qglpickcolors/tst_qglpickcolors.cpp +++ /dev/null @@ -1,299 +0,0 @@ -/**************************************************************************** -** -** 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 QtQuick3D module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** 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. -** -** 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. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include <QtTest/QtTest> -#include <QtCore/qset.h> -#include "qglpickcolors_p.h" - -class tst_QGLPickColors : public QObject -{ - Q_OBJECT -public: - tst_QGLPickColors() {} - ~tst_QGLPickColors() {} - -private slots: - void distinctColors(); - void colorSpread(); - - // Round-trip tests check various kinds of ways in which GPU's - // may take the incoming RGB888 value for the pick color and turn - // it into a value in the framebuffer, and then convert that - // back into an RGB888 value later. - // - // For example, converting RGB888 -> RGB565 -> RGB888 will lose some - // precision. The amount of lost precision will depend upon the - // specific way in which the GPU does the conversion. The function - // qt_qgl_normalize_pick_color() corrects for this and must always - // return to the same value irrespective of how the GPU works. - void roundTripExact(); - void roundTripTrunc565(); - void roundTripScale565(); - void roundTripDup565(); - void roundTripTrunc555(); - void roundTripScale555(); - void roundTripDup555(); - void roundTripScale444(); // Trunc doesn't work well with 444. - void roundTripDup444(); -}; - -// Check that all pick colors are distinct, opaque, and not black. -void tst_QGLPickColors::distinctColors() -{ - QSet<QRgb> used; - int index = 0; - QRgb rgb; - while ((rgb = qt_qgl_pick_color(index)) != 0) { - QVERIFY(!used.contains(rgb)); - used += rgb; - QVERIFY(qAlpha(rgb) == 255); // Opaque. - QVERIFY(qRed(rgb) || qGreen(rgb) || qBlue(rgb)); // Not black. - ++index; - } - QCOMPARE(rgb, QRgb(0)); - QCOMPARE(qt_qgl_pick_color(-1), QRgb(0)); - QVERIFY(index >= 1024); -} - -// Check that the colors are well spread out so that accidental -// mismatches will not occur. -void tst_QGLPickColors::colorSpread() -{ - int index1 = 0; - int index2; - QRgb rgb1, rgb2; - while ((rgb1 = qt_qgl_pick_color(index1)) != 0) { - index2 = qMax(index1 - 50, 0); - while (index2 < index1) { - rgb2 = qt_qgl_pick_color(index2); - int rdiff = qRed(rgb1) - qRed(rgb2); - int gdiff = qGreen(rgb1) - qGreen(rgb2); - int bdiff = qBlue(rgb1) - qBlue(rgb2); - int dist = rdiff * rdiff + gdiff * gdiff + bdiff * bdiff; - if (dist < 15 * 15) { // FIXME: need more distance. - qDebug() << index1 << index2 << dist - << QString::number(rgb1, 16) - << QString::number(rgb2, 16); - } - QVERIFY(dist >= 15 * 15); - ++index2; - } - ++index1; - } -} - -// Check that round-tripping a color via exact representation works. -void tst_QGLPickColors::roundTripExact() -{ - int index = 0; - QRgb rgb; - while ((rgb = qt_qgl_pick_color(index++)) != 0) - QVERIFY(qt_qgl_normalize_pick_color(rgb) == rgb); -} - -// Check round-tripping when RGB888 -> RGB565 uses truncation. -void tst_QGLPickColors::roundTripTrunc565() -{ - int index = 0; - QRgb rgb; - while ((rgb = qt_qgl_pick_color(index++)) != 0) { - QRgb truncrgb = qRgb(qRed(rgb) & 0xF8, - qGreen(rgb) & 0xFC, - qBlue(rgb) & 0xF8); - - QVERIFY(qt_qgl_normalize_pick_color(truncrgb) == rgb); - } -} - -// Check round-tripping when RGB888 -> RGB565 scales with floating point. -void tst_QGLPickColors::roundTripScale565() -{ - int index = 0; - QRgb rgb; - while ((rgb = qt_qgl_pick_color(index++)) != 0) { - int r, g, b; - r = int(qRed(rgb) * 31.0f / 255.0f); - g = int(qGreen(rgb) * 63.0f / 255.0f); - b = int(qBlue(rgb) * 31.0f / 255.0f); - - QRgb scalergb = qRgb(r * 255.0f / 31.0f, - g * 255.0f / 63.0f, - b * 255.0f / 31.0f); - - QVERIFY(qt_qgl_normalize_pick_color(scalergb) == rgb); - - // Scale up, but duplicate down. - QRgb duprgb = qRgb((r << 3) | (r >> 2), - (g << 2) | (g >> 4), - (b << 3) | (b >> 2)); - - QVERIFY(qt_qgl_normalize_pick_color(duprgb) == rgb); - } -} - -// Check round-tripping when RGB565 -> RGB888 uses bit-duplication. -void tst_QGLPickColors::roundTripDup565() -{ - int index = 0; - QRgb rgb; - while ((rgb = qt_qgl_pick_color(index++)) != 0) { - int r, g, b; - r = qRed(rgb) & 0xF8; - r = r | (r >> 5); - g = qGreen(rgb) & 0xFC; - g = g | (g >> 6); - b = qBlue(rgb) & 0xF8; - b = b | (b >> 5); - - QRgb duprgb = qRgb(r, g, b); - - QVERIFY(qt_qgl_normalize_pick_color(duprgb) == rgb); - } -} - -// Check round-tripping when RGB888 -> RGB555 uses truncation. -void tst_QGLPickColors::roundTripTrunc555() -{ - int index = 0; - QRgb rgb; - while ((rgb = qt_qgl_pick_color(index++)) != 0) { - QRgb truncrgb = qRgb(qRed(rgb) & 0xF8, - qGreen(rgb) & 0xF8, - qBlue(rgb) & 0xF8); - - QVERIFY(qt_qgl_normalize_pick_color(truncrgb) == rgb); - } -} - -// Check round-tripping when RGB888 -> RGB555 scales with floating point. -void tst_QGLPickColors::roundTripScale555() -{ - int index = 0; - QRgb rgb; - while ((rgb = qt_qgl_pick_color(index++)) != 0) { - int r, g, b; - r = int(qRed(rgb) * 31.0f / 255.0f); - g = int(qGreen(rgb) * 31.0f / 255.0f); - b = int(qBlue(rgb) * 31.0f / 255.0f); - - QRgb scalergb = qRgb(r * 255.0f / 31.0f, - g * 255.0f / 31.0f, - b * 255.0f / 31.0f); - - QVERIFY(qt_qgl_normalize_pick_color(scalergb) == rgb); - - // Scale up, but duplicate down. - QRgb duprgb = qRgb((r << 3) | (r >> 2), - (g << 3) | (g >> 2), - (b << 3) | (b >> 2)); - - QVERIFY(qt_qgl_normalize_pick_color(duprgb) == rgb); - } -} - -// Check round-tripping when RGB555 -> RGB888 uses bit-duplication. -void tst_QGLPickColors::roundTripDup555() -{ - int index = 0; - QRgb rgb; - while ((rgb = qt_qgl_pick_color(index++)) != 0) { - int r, g, b; - r = qRed(rgb) & 0xF8; - r = r | (r >> 5); - g = qGreen(rgb) & 0xF8; - g = g | (g >> 5); - b = qBlue(rgb) & 0xF8; - b = b | (b >> 5); - - QRgb duprgb = qRgb(r, g, b); - - QVERIFY(qt_qgl_normalize_pick_color(duprgb) == rgb); - } -} - -// Note: the RGB444 conversion falls apart after 1330 entries -// in the table. It is no longer possible to distinguish the -// colors while retaining stability in the face of GPU differences. -#define RGB_444_LIMIT 1330 - -// Check round-tripping when RGB888 -> RGB444 scales with floating point. -void tst_QGLPickColors::roundTripScale444() -{ - int index = 0; - QRgb rgb; - while (index < RGB_444_LIMIT && (rgb = qt_qgl_pick_color(index++)) != 0) { - int r, g, b; - r = int(qRed(rgb) * 15.0f / 255.0f); - g = int(qGreen(rgb) * 15.0f / 255.0f); - b = int(qBlue(rgb) * 15.0f / 255.0f); - - QRgb scalergb = qRgb(r * 255.0f / 15.0f, - g * 255.0f / 15.0f, - b * 255.0f / 15.0f); - - QVERIFY(qt_qgl_normalize_pick_color(scalergb, true) == rgb); - } -} - -// Check round-tripping when RGB444 -> RGB888 uses bit-duplication. -// We assume that the values are scaled up, but duplicated down. -void tst_QGLPickColors::roundTripDup444() -{ - int index = 0; - QRgb rgb; - while (index < RGB_444_LIMIT && (rgb = qt_qgl_pick_color(index++)) != 0) { - int r, g, b; - r = int(qRed(rgb) * 15.0f / 255.0f); - r = r | (r << 4); - g = int(qGreen(rgb) * 15.0f / 255.0f); - g = g | (g << 4); - b = int(qBlue(rgb) * 15.0f / 255.0f); - b = b | (b << 4); - - QRgb duprgb = qRgb(r, g, b); - - QVERIFY(qt_qgl_normalize_pick_color(duprgb, true) == rgb); - } -} - -QTEST_APPLESS_MAIN(tst_QGLPickColors) - -#include "tst_qglpickcolors.moc" diff --git a/tests/auto/threed/qglrender/qglrender.pro b/tests/auto/threed/qglrender/qglrender.pro deleted file mode 100644 index 547eff30..00000000 --- a/tests/auto/threed/qglrender/qglrender.pro +++ /dev/null @@ -1,6 +0,0 @@ -load(qttest_p4.prf) -TEMPLATE=app -QT += testlib -CONFIG += unittest warn_on qt3d - -SOURCES += tst_qglrender.cpp diff --git a/tests/auto/threed/qglrender/tst_qglrender.cpp b/tests/auto/threed/qglrender/tst_qglrender.cpp deleted file mode 100644 index 150396d5..00000000 --- a/tests/auto/threed/qglrender/tst_qglrender.cpp +++ /dev/null @@ -1,259 +0,0 @@ -/**************************************************************************** -** -** 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 QtQuick3D module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** 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. -** -** 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. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include <QtTest/QtTest> - -#include "qglrenderorder.h" -#include "qglrendersequencer.h" -#include "qglrenderordercomparator.h" -#include "qglscenenode.h" -#include "qglpainter.h" -#include "qglbuilder.h" -#include "qglview.h" - -class tst_QGLRender : public QObject -{ - Q_OBJECT -public: - tst_QGLRender() {} - ~tst_QGLRender() {} - -private slots: - void create(); - void values(); - void repo(); - void sequence(); -}; - -void tst_QGLRender::create() -{ - QGLSceneNode node; - QGLSceneNode node2; - QGLMaterialCollection pal; - node.setPalette(&pal); - node2.setPalette(&pal); - - QGLRenderState s; - QGLRenderOrder order(&node, s); - QGLRenderOrder other(order); // copy constructor - QCOMPARE(order.node(), &node); - QCOMPARE(order.node(), other.node()); - QGLRenderOrderComparator cmp; - QVERIFY(cmp.isEqualTo(order, other)); // operator== - - QGLRenderOrder other2(&node2, s); - QVERIFY(cmp.isEqualTo(other2, order)); // same because nodes have same values - other2 = order; // operator= - QVERIFY(cmp.isEqualTo(other2, order)); // same again - - QGLRenderState state0; - QGLRenderOrder other3(&node2, state0); - QVERIFY(cmp.isEqualTo(other2, other3)); -} - -void tst_QGLRender::values() -{ - QGLSceneNode node; // by default has QGL::FlatColor - QGLSceneNode node2; - QGLMaterialCollection pal; - node.setPalette(&pal); - node2.setPalette(&pal); - node2.setEffect(QGL::LitMaterial); - - QGLRenderState s; - QGLRenderOrder order(&node, s); - QGLRenderOrder other(&node2, s); - QGLRenderOrderComparator cmp; - QVERIFY(!cmp.isEqualTo(other, order)); - QVERIFY(cmp.isLessThan(order, other)); - - QGLRenderState state; - QGLMaterial *mat = new QGLMaterial; - mat->setAmbientColor(Qt::blue); - int ix = pal.addMaterial(mat); - QGLSceneNode node3; - node3.setPalette(&pal); - node3.setMaterialIndex(ix); - node3.setEffect(QGL::LitMaterial); - state.updateFrom(&node3); - QGLRenderOrder other2(&node, state); - QVERIFY(other2.effectiveHasEffect()); - QCOMPARE(other2.effectiveMaterial(), mat); - QCOMPARE(other2.effectiveStandardEffect(), QGL::LitMaterial); - QCOMPARE(other2.effectiveUserEffect(), (QGLAbstractEffect*)0); - QVERIFY(cmp.isLessThan(order, other2)); - QVERIFY(cmp.isLessThan(other, other2)); -} - -void tst_QGLRender::repo() -{ - QGLSceneNode node; // by default has QGL::FlatColor - QGLSceneNode node2; - QGLMaterialCollection pal; - node.setPalette(&pal); - node2.setPalette(&pal); - node2.setEffect(QGL::LitDecalTexture2D); - - QGLRenderState s; - QGLRenderOrder order(&node, s); - QGLRenderOrder other(&node2, s); - QGLRenderOrder order2(&node, s); - QGLRenderOrderComparator cmp; - QVERIFY(!cmp.isEqualTo(other, order)); - QVERIFY(cmp.isLessThan(order, other)); - QVERIFY(cmp.isEqualTo(order2, order)); - QCOMPARE(order2.node(), order.node()); -} - -class TestPainter : public QGLPainter -{ -public: - TestPainter(QGLWidget *w) : QGLPainter(w) {} - void draw(QGL::DrawingMode mode, const QGLIndexBuffer& indices, - int offset, int count) - { - m_starts.append(offset); - m_counts.append(count); - QGLPainter::draw(mode, indices, offset, count); - } - QList<int> starts() const { return m_starts; } - QList<int> counts() const { return m_counts; } -private: - QList<int> m_starts; - QList<int> m_counts; -}; - -class TestView : public QGLView -{ -public: - TestView(QGLSceneNode *node) - : m_node(node) - {} - void paintGL(QGLPainter *painter) - { - painter->setEye(QGL::NoEye); - painter->setCamera(camera()); - m_node->draw(painter); - } -private: - QGLSceneNode *m_node; -}; - -void tst_QGLRender::sequence() -{ - QGLMaterialCollection *palette = new QGLMaterialCollection; - - // create a yellow lit material - QGLMaterial *mat = new QGLMaterial; - mat->setAmbientColor(Qt::yellow); - int ix0 = palette->addMaterial(mat); - - // create a blue lit material - mat = new QGLMaterial; - mat->setAmbientColor(Qt::blue); - int ix1 = palette->addMaterial(mat); - - // create a grey textured material - int tx0; - { - QImage uv(1024, 1024, QImage::Format_ARGB32); - uv.fill(qRgba(196, 196, 196, 196)); - mat = new QGLMaterial; - mat->setAmbientColor(Qt::gray); - QGLTexture2D *tex = new QGLTexture2D; - tex->setImage(uv); - mat->setTexture(tex); - tx0 = palette->addMaterial(mat); - } - - QGLSceneNode *scene = new QGLSceneNode; - scene->setPalette(palette); - QGLSceneNode *node = 0; - QGLSceneNode *prim; - { - QGLBuilder builder(palette); - QVector3D a(-1.0f, -1.0f, 0.0f); - QVector3D b(1.0f, -1.0f, 0.0f); - QVector3D c(1.0f, 1.0f, 0.0f); - QGeometryData p; - p.appendVertex(a, b, c); - p.generateTextureCoordinates(); - builder.addTriangles(p); - prim = builder.currentNode(); - prim->setMaterialIndex(ix0); - builder.newSection(); - QVector3D d(-1.2f, -1.2f, 0.0f); - QVector3D e(1.2f, -1.2f, 0.0f); - QVector3D f(1.2f, 1.2f, 0.0f); - QVector3D g(-1.2f, 1.2f, 0.0f); - QGeometryData q; - q.appendVertex(d, e, f, g); - q.generateTextureCoordinates(); - builder.addQuads(q); - prim = builder.currentNode(); - prim->setMaterialIndex(ix1); - node = builder.finalizedSceneNode(); - } - - scene->addNode(node); - QGLSceneNode *cl = prim->clone(scene); - cl->setMaterialIndex(tx0); - cl->setEffect(QGL::LitDecalTexture2D); - - TestView widget(scene); - if (!widget.isValid()) - QSKIP("GL Implementation not valid", SkipSingle); - - TestPainter *ptr = new TestPainter(&widget); - - widget.paintGL(ptr); - - QList<int> starts = ptr->starts(); - QList<int> counts = ptr->counts(); - QCOMPARE(starts.at(0), 0); - QCOMPARE(counts.at(0), 3); - QCOMPARE(starts.at(1), 3); - QCOMPARE(counts.at(1), 6); -} - -QTEST_MAIN(tst_QGLRender) - -#include "tst_qglrender.moc" diff --git a/tests/auto/threed/qglscenenode/qglscenenode.pro b/tests/auto/threed/qglscenenode/qglscenenode.pro deleted file mode 100644 index 511f83c0..00000000 --- a/tests/auto/threed/qglscenenode/qglscenenode.pro +++ /dev/null @@ -1,7 +0,0 @@ -load(qttest_p4.prf) -TEMPLATE=app -QT += testlib -CONFIG += unittest warn_on qt3d - -INCLUDEPATH += ../../../shared -SOURCES += tst_qglscenenode.cpp diff --git a/tests/auto/threed/qglscenenode/tst_qglscenenode.cpp b/tests/auto/threed/qglscenenode/tst_qglscenenode.cpp deleted file mode 100644 index f87f77b5..00000000 --- a/tests/auto/threed/qglscenenode/tst_qglscenenode.cpp +++ /dev/null @@ -1,751 +0,0 @@ -/**************************************************************************** -** -** 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 QtQuick3D module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** 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. -** -** 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. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include <QtTest/QtTest> -#include "qglscenenode.h" -#include "qglpainter.h" -#include "qglabstracteffect.h" -#include "qglpicknode.h" -#include "qgraphicstransform3d.h" -#include "qgraphicsscale3d.h" -#include "qgraphicsrotation3d.h" -#include "qglbuilder.h" - -#include "qtest_helpers.h" - -class tst_QGLSceneNode : public QObject -{ - Q_OBJECT -public: - tst_QGLSceneNode() {} - ~tst_QGLSceneNode() {} - -private slots: - void defaultValues(); - void modify(); - void addNode(); - void removeNode(); - void clone(); - void boundingBox_data(); - void boundingBox(); - void position_QTBUG_17279(); -}; - -// Check that all properties have their expected defaults. -void tst_QGLSceneNode::defaultValues() -{ - QGLSceneNode node; - QVERIFY(node.options() == QGLSceneNode::NoOptions); - QVERIFY(node.geometry().isNull()); - QVERIFY(node.boundingBox().isNull()); - QVERIFY(node.localTransform().isIdentity()); - - QVERIFY(node.position() == QVector3D(0, 0, 0)); - QCOMPARE(node.x(), qreal(0.0f)); - QCOMPARE(node.y(), qreal(0.0f)); - QCOMPARE(node.z(), qreal(0.0f)); - - QVERIFY(node.transforms().isEmpty()); - - QVERIFY(node.drawingMode() == QGL::Triangles); - QVERIFY(node.effect() == QGL::FlatColor); - QVERIFY(node.userEffect() == 0); - QVERIFY(!node.hasEffect()); - - QCOMPARE(node.start(), 0); - QCOMPARE(node.count(), 0); - - QCOMPARE(node.materialIndex(), -1); - QCOMPARE(node.backMaterialIndex(), -1); - - QVERIFY(node.material() == 0); - QVERIFY(node.backMaterial() == 0); - QVERIFY(node.palette() == 0); - QVERIFY(node.pickNode() == 0); - - QVERIFY(node.allChildren().isEmpty()); - QVERIFY(node.children().isEmpty()); -} - -class TestEffect : public QGLAbstractEffect -{ -public: - void setActive(QGLPainter *, bool) {} - void update(QGLPainter *, QGLPainter::Updates) {} -}; - -// Modify properties and check that the modifications propagate. -void tst_QGLSceneNode::modify() -{ - QGLSceneNode node; - - QSignalSpy updatedSpy(&node, SIGNAL(updated())); - - node.setOptions(QGLSceneNode::ViewNormals); - QCOMPARE(updatedSpy.count(), 1); - QVERIFY(node.options() == QGLSceneNode::ViewNormals); - - QMatrix4x4 m; - m.translate(-1.0f, 2.5f, 5.0f); - m.rotate(45.0f, 1.0f, 1.0f, 1.0f); - m.scale(23.5f); - - node.setLocalTransform(m); - QCOMPARE(updatedSpy.count(), 2); - QVERIFY(node.localTransform() == m); - - node.setPosition(QVector3D(1, -2, 3)); - QCOMPARE(updatedSpy.count(), 3); - QVERIFY(node.position() == QVector3D(1, -2, 3)); - - node.setX(-45.0f); - QCOMPARE(updatedSpy.count(), 4); - QVERIFY(node.position() == QVector3D(-45.0f, -2, 3)); - - node.setY(67.0f); - QCOMPARE(updatedSpy.count(), 5); - QVERIFY(node.position() == QVector3D(-45.0f, 67.0f, 3)); - - node.setZ(-23.5f); - QCOMPARE(updatedSpy.count(), 6); - QVERIFY(node.position() == QVector3D(-45.0f, 67.0f, -23.5f)); - - QList<QGraphicsTransform3D *> transforms; - transforms.append(new QGraphicsScale3D(this)); - transforms.append(new QGraphicsRotation3D(this)); - node.setTransforms(transforms); - QCOMPARE(updatedSpy.count(), 7); - QVERIFY(node.transforms() == transforms); - - QGraphicsScale3D *scale = new QGraphicsScale3D(this); - transforms.append(scale); - node.addTransform(scale); - QCOMPARE(updatedSpy.count(), 8); - QVERIFY(node.transforms() == transforms); - - node.setDrawingMode(QGL::Points); - QCOMPARE(updatedSpy.count(), 9); - QVERIFY(node.drawingMode() == QGL::Points); - - node.setEffect(QGL::LitMaterial); - QCOMPARE(updatedSpy.count(), 10); - QVERIFY(node.effect() == QGL::LitMaterial); - QVERIFY(node.hasEffect()); - - node.setEffectEnabled(false); - QCOMPARE(updatedSpy.count(), 11); - QVERIFY(node.effect() == QGL::LitMaterial); - QVERIFY(!node.hasEffect()); - - TestEffect userEffect; - node.setUserEffect(&userEffect); - QCOMPARE(updatedSpy.count(), 12); - QVERIFY(node.effect() == QGL::LitMaterial); - QVERIFY(node.userEffect() == &userEffect); - QVERIFY(node.hasEffect()); - - node.setMaterialIndex(3); - QCOMPARE(updatedSpy.count(), 13); - QCOMPARE(node.materialIndex(), 3); - QVERIFY(node.material() == 0); // material index is out of range - - node.setBackMaterialIndex(5); - QCOMPARE(updatedSpy.count(), 14); - QCOMPARE(node.backMaterialIndex(), 5); - QVERIFY(node.backMaterial() == 0); // material index is out of range - - QVERIFY(node.palette() == 0); - - QGLMaterial *mat1 = new QGLMaterial(); - node.setMaterial(mat1); - QCOMPARE(updatedSpy.count(), 15); - QCOMPARE(node.materialIndex(), 0); - QCOMPARE(node.backMaterialIndex(), 5); - QVERIFY(node.material() == mat1); - QVERIFY(node.backMaterial() == 0); - QVERIFY(node.palette() != 0); - - QGLMaterial *mat2 = new QGLMaterial(); - node.setBackMaterial(mat2); - QCOMPARE(updatedSpy.count(), 16); - QCOMPARE(node.materialIndex(), 0); - QCOMPARE(node.backMaterialIndex(), 1); - QVERIFY(node.material() == mat1); - QVERIFY(node.backMaterial() == mat2); - - QGLMaterial *mat3 = new QGLMaterial(); - node.setMaterial(mat3); - QCOMPARE(updatedSpy.count(), 17); - QCOMPARE(node.materialIndex(), 2); - QCOMPARE(node.backMaterialIndex(), 1); - QVERIFY(node.material() == mat3); - QVERIFY(node.backMaterial() == mat2); - - node.setMaterial(mat1); - QCOMPARE(updatedSpy.count(), 18); - QCOMPARE(node.materialIndex(), 0); - QCOMPARE(node.backMaterialIndex(), 1); - QVERIFY(node.material() == mat1); - QVERIFY(node.backMaterial() == mat2); - - QVERIFY(node.palette()->material(0) == mat1); - QVERIFY(node.palette()->material(1) == mat2); - QVERIFY(node.palette()->material(2) == mat3); - QCOMPARE(node.palette()->size(), 3); - - QGLPickNode pick; - QVERIFY(pick.target() == 0); - QCOMPARE(pick.id(), -1); - node.setPickNode(&pick); - QVERIFY(node.pickNode() == &pick); - QVERIFY(pick.target() == &node); - QCOMPARE(pick.id(), -1); - pick.setId(4); - QCOMPARE(pick.id(), 4); - - // One last check to make sure there are no leaks between properties. - // e.g. the position actually changing the rotation, etc. - QVERIFY(node.options() == QGLSceneNode::ViewNormals); - QVERIFY(node.localTransform() == m); - QVERIFY(node.position() == QVector3D(-45.0f, 67.0f, -23.5f)); - QVERIFY(node.transforms() == transforms); - QVERIFY(node.drawingMode() == QGL::Points); - QVERIFY(node.effect() == QGL::LitMaterial); - QVERIFY(node.userEffect() == &userEffect); - QVERIFY(node.hasEffect()); - QCOMPARE(node.materialIndex(), 0); - QCOMPARE(node.backMaterialIndex(), 1); - QVERIFY(node.pickNode() == &pick); -} - -// Add nodes to build a scene graph. -void tst_QGLSceneNode::addNode() -{ - QGLSceneNode *node1 = new QGLSceneNode(); - - // Add a node via the constructor. - QGLSceneNode *node2 = new QGLSceneNode(node1); - QVERIFY(node2->parent() == node1); - QCOMPARE(node1->children().count(), 1); - QVERIFY(node1->children()[0] == node2); - - // Add a node explicitly, not parented into the graph yet. - // Because node3's parent is null, it will be parented in. - QGLSceneNode *node3 = new QGLSceneNode(); - node1->addNode(node3); - QVERIFY(node3->parent() == node1); - QCOMPARE(node1->children().count(), 2); - QVERIFY(node1->children()[0] == node2); - QVERIFY(node1->children()[1] == node3); - - // Add a node explicily that is parented elsewhere. Because - // node4's parent is not null, it will *not* be parented in. - QGLSceneNode *node4 = new QGLSceneNode(this); - node1->addNode(node4); - QVERIFY(node4->parent() == this); - QCOMPARE(node1->children().count(), 3); - QVERIFY(node1->children()[0] == node2); - QVERIFY(node1->children()[1] == node3); - QVERIFY(node1->children()[2] == node4); - - // Try adding node4 again (should do nothing). - node1->addNode(node4); - QVERIFY(node4->parent() == this); - QCOMPARE(node1->children().count(), 3); - QVERIFY(node1->children()[0] == node2); - QVERIFY(node1->children()[1] == node3); - QVERIFY(node1->children()[2] == node4); - - // Add a null child (should do nothing). - node1->addNode(0); - QCOMPARE(node1->children().count(), 3); - QVERIFY(node1->children()[0] == node2); - QVERIFY(node1->children()[1] == node3); - QVERIFY(node1->children()[2] == node4); - - // Add node3 under node2 as well so that it has multiple parents. - node2->addNode(node3); - QVERIFY(node3->parent() == node1); // parent is unchanged - QCOMPARE(node1->children().count(), 3); - QVERIFY(node1->children()[0] == node2); - QVERIFY(node1->children()[1] == node3); - QVERIFY(node1->children()[2] == node4); - QCOMPARE(node2->children().count(), 1); - QVERIFY(node2->children()[0] == node3); - - // Recursively fetch all children. - QList<QGLSceneNode *> children = node1->allChildren(); - QCOMPARE(children.count(), 3); - QVERIFY(children[0] == node2); - QVERIFY(children[1] == node3); - QVERIFY(children[2] == node4); - children = node2->allChildren(); - QCOMPARE(children.count(), 1); - QVERIFY(children[0] == node3); - QVERIFY(node3->allChildren().isEmpty()); - QVERIFY(node4->allChildren().isEmpty()); - - // Delete the top node and ensure that the right objects are destroyed. - QSignalSpy node1Spy(node1, SIGNAL(destroyed())); - QSignalSpy node2Spy(node2, SIGNAL(destroyed())); - QSignalSpy node3Spy(node3, SIGNAL(destroyed())); - QSignalSpy node4Spy(node4, SIGNAL(destroyed())); - delete node1; - QCOMPARE(node1Spy.count(), 1); - QCOMPARE(node2Spy.count(), 1); - QCOMPARE(node3Spy.count(), 1); - QCOMPARE(node4Spy.count(), 0); - - // Clean up the separate node. - delete node4; - QCOMPARE(node4Spy.count(), 1); -} - -// Remove nodes from an existing scene graph. -void tst_QGLSceneNode::removeNode() -{ - QGLSceneNode *node1 = new QGLSceneNode(); - QGLSceneNode *node2 = new QGLSceneNode(); - QGLSceneNode *node3 = new QGLSceneNode(); - QGLSceneNode *node4 = new QGLSceneNode(); - QGLSceneNode *node5 = new QGLSceneNode(this); - - node1->addNode(node2); - node1->addNode(node3); - node1->addNode(node4); - node2->addNode(node3); - node2->addNode(node5); - - QSignalSpy node1Spy(node1, SIGNAL(destroyed())); - QSignalSpy node2Spy(node2, SIGNAL(destroyed())); - QSignalSpy node3Spy(node3, SIGNAL(destroyed())); - QSignalSpy node4Spy(node4, SIGNAL(destroyed())); - QSignalSpy node5Spy(node5, SIGNAL(destroyed())); - - // Removing a node will set its parent pointer back to null - // if it was removed from its last parent. - QVERIFY(node4->parent() == node1); - node1->removeNode(node4); - QVERIFY(node4->parent() == 0); - - // The node should still exist, just detached. - QCOMPARE(node4Spy.count(), 0); - delete node4; - QCOMPARE(node4Spy.count(), 1); - - // Remove node3, which should transfer ownership. - QVERIFY(node3->parent() == node1); - node1->removeNode(node3); - QVERIFY(node3->parent() == node2); - - // Add node3 back, and check non-transfer of ownership. - node1->addNode(node3); - QVERIFY(node3->parent() == node2); - node1->removeNode(node3); - QVERIFY(node3->parent() == node2); - - // Remove a node that wasn't parented to the scene graph. - node2->removeNode(node5); - QVERIFY(node5->parent() == this); - - // Clean up the rest of the graph. - QCOMPARE(node1Spy.count(), 0); - QCOMPARE(node2Spy.count(), 0); - QCOMPARE(node3Spy.count(), 0); - QCOMPARE(node4Spy.count(), 1); - QCOMPARE(node5Spy.count(), 0); - delete node1; - QCOMPARE(node1Spy.count(), 1); - QCOMPARE(node2Spy.count(), 1); - QCOMPARE(node3Spy.count(), 1); - QCOMPARE(node4Spy.count(), 1); - QCOMPARE(node5Spy.count(), 0); - delete node5; - QCOMPARE(node5Spy.count(), 1); -} - -static bool sameTransforms(const QList<QGraphicsTransform3D *> &transforms1, - const QList<QGraphicsTransform3D *> &transforms2) -{ - if (transforms1.size() != transforms2.size()) - return false; - for (int index = 0; index < transforms1.size(); ++index) { - // We only check the meta object at the moment, and assume - // that the clone() worked properly. - if (transforms1.at(index)->metaObject() != - transforms2.at(index)->metaObject()) - return false; - } - return true; -} - -void tst_QGLSceneNode::clone() -{ - QGLSceneNode nodeParent; - QGLSceneNode node1(&nodeParent); - - QGLSceneNode *node2 = node1.clone(); - QVERIFY(node2 != 0 && node2 != &node1); - QVERIFY(node2->parent() == &nodeParent); - QVERIFY(node2->options() == node1.options()); - QVERIFY(node2->geometry().isEmpty()); - QVERIFY(node2->localTransform().isIdentity()); - QVERIFY(node2->position() == QVector3D(0, 0, 0)); - QVERIFY(node2->transforms().isEmpty()); - QVERIFY(node2->drawingMode() == QGL::Triangles); - QVERIFY(node2->effect() == QGL::FlatColor); - QVERIFY(!node2->userEffect()); - QVERIFY(!node2->hasEffect()); - QCOMPARE(node2->start(), 0); - QCOMPARE(node2->count(), 0); - QCOMPARE(node2->materialIndex(), -1); - QCOMPARE(node2->backMaterialIndex(), -1); - QVERIFY(!node2->palette()); - QVERIFY(!node2->pickNode()); - QVERIFY(node2->children().isEmpty()); - delete node2; - - QGeometryData data1; - data1.appendVertex(QVector3D(1, -2, 3)); - QMatrix4x4 m; - m.translate(-1.0f, 2.5f, 5.0f); - m.rotate(45.0f, 1.0f, 1.0f, 1.0f); - m.scale(23.5f); - TestEffect userEffect; - QGLPickNode pick; - QList<QGraphicsTransform3D *> transforms; - transforms.append(new QGraphicsScale3D(this)); - transforms.append(new QGraphicsRotation3D(this)); - - node1.setOptions(QGLSceneNode::ViewNormals); - node1.setGeometry(data1); - node1.setLocalTransform(m); - node1.setPosition(QVector3D(1, -2, 3)); - node1.setTransforms(transforms); - node1.setDrawingMode(QGL::Points); - node1.setEffect(QGL::LitMaterial); - node1.setUserEffect(&userEffect); - node1.setStart(10); - node1.setCount(20); - QGLMaterial *mat1 = new QGLMaterial(); - QGLMaterial *mat2 = new QGLMaterial(); - node1.setMaterial(mat1); - node1.setBackMaterial(mat2); - node1.setPickNode(&pick); - QGLSceneNode *node3 = new QGLSceneNode(); - QGLSceneNode *node4 = new QGLSceneNode(); - node1.addNode(node3); - node1.addNode(node4); - - // Clone onto the same parent. - node2 = node1.clone(); - QVERIFY(node2 != 0 && node2 != &node1); - QVERIFY(node2->parent() == &nodeParent); - QVERIFY(node2->options() == node1.options()); - QCOMPARE(node2->geometry().count(), 1); - QVERIFY(node2->localTransform() == m); - QVERIFY(node2->position() == QVector3D(1, -2, 3)); - QVERIFY(sameTransforms(node2->transforms(), transforms)); - QVERIFY(node2->drawingMode() == QGL::Points); - QVERIFY(node2->effect() == QGL::LitMaterial); - QVERIFY(node2->userEffect() == &userEffect); - QVERIFY(node2->hasEffect()); - QCOMPARE(node2->start(), 10); - QCOMPARE(node2->count(), 20); - QCOMPARE(node2->materialIndex(), 0); - QCOMPARE(node2->backMaterialIndex(), 1); - QVERIFY(node2->material() == mat1); - QVERIFY(node2->backMaterial() == mat2); - QVERIFY(node2->palette() != 0); - QVERIFY(node2->palette() == node1.palette()); - QVERIFY(!node2->pickNode()); // Pick node should not be cloned - QCOMPARE(node2->children().count(), 2); - QVERIFY(node2->children()[0] == node3); - QVERIFY(node2->children()[1] == node4); - delete node2; - - // Clone onto a different parent. - QGLSceneNode node2Parent; - node2 = node1.clone(&node2Parent); - QVERIFY(node2->parent() == &node2Parent); - QCOMPARE(node2Parent.children().count(), 1); - QVERIFY(node2Parent.children()[0] == node2); - delete node2; -} - -void tst_QGLSceneNode::boundingBox_data() -{ - QTest::addColumn<QVector3D>("bottomLeftFront"); - QTest::addColumn<QVector3D>("bottomRightFront"); - QTest::addColumn<QVector3D>("topRightFront"); - QTest::addColumn<QVector3D>("topLeftFront"); - QTest::addColumn<QVector3D>("scale"); - QTest::addColumn<QVector3D>("translation"); - QTest::addColumn<QVector3D>("rotation"); - QTest::addColumn<QVector3D>("boxMin"); - QTest::addColumn<QVector3D>("boxMax"); - - QTest::newRow("cube-2x2x2-at-origin-no-xform") - << QVector3D(-1, -1, -1) - << QVector3D(1, -1, -1) - << QVector3D(1, 1, -1) - << QVector3D(-1, 1, -1) - << QVector3D(0, 0, 0) - << QVector3D(0, 0, 0) - << QVector3D(0, 0, 0) - << QVector3D(-1, -1, -1) - << QVector3D(1, 1, 1); - - QTest::newRow("cube-2x2x2-offset-no-xform") - << QVector3D(3, -1, -1) - << QVector3D(5, -1, -1) - << QVector3D(5, 1, -1) - << QVector3D(3, 1, -1) - << QVector3D(0, 0, 0) - << QVector3D(0, 0, 0) - << QVector3D(0, 0, 0) - << QVector3D(3, -1, -1) - << QVector3D(5, 1, 1); - - QTest::newRow("cube-2x2x2-at-origin-positioned") - << QVector3D(-1, -1, -1) - << QVector3D(1, -1, -1) - << QVector3D(1, 1, -1) - << QVector3D(-1, 1, -1) - << QVector3D(0, 0, 0) - << QVector3D(-4, -4, -4) - << QVector3D(0, 0, 0) - << QVector3D(-5, -5, -5) - << QVector3D(-3, -3, -3); - - QTest::newRow("cube-2x2x2-offset-positioned") - << QVector3D(3, -1, -1) - << QVector3D(5, -1, -1) - << QVector3D(5, 1, -1) - << QVector3D(3, 1, -1) - << QVector3D(0, 0, 0) - << QVector3D(-4, -4, -4) - << QVector3D(0, 0, 0) - << QVector3D(-1, -5, -5) - << QVector3D(1, -3, -3); - - QTest::newRow("cube-2x2x2-at-origin-positioned-scaled") - << QVector3D(-1, -1, -1) - << QVector3D(1, -1, -1) - << QVector3D(1, 1, -1) - << QVector3D(-1, 1, -1) - << QVector3D(4, 4, 4) - << QVector3D(-4, -4, -4) - << QVector3D(0, 0, 0) - << QVector3D(-20, -20, -20) - << QVector3D(-12, -12, -12); - - QTest::newRow("cube-2x2x2-offset-positioned-scaled-rotated") - << QVector3D(3, -1, -1) - << QVector3D(5, -1, -1) - << QVector3D(5, 1, -1) - << QVector3D(3, 1, -1) - << QVector3D(4, 4, 4) - << QVector3D(-4, -4, -4) - << QVector3D(0, 0, 45) - << QVector3D(-4, -20, -20) - << QVector3D(4, -12, -12); -} - -void tst_QGLSceneNode::boundingBox() -{ - QFETCH(QVector3D, bottomLeftFront); - QFETCH(QVector3D, bottomRightFront); - QFETCH(QVector3D, topRightFront); - QFETCH(QVector3D, topLeftFront); - QFETCH(QVector3D, scale); - QFETCH(QVector3D, translation); - QFETCH(QVector3D, rotation); - QFETCH(QVector3D, boxMin); - QFETCH(QVector3D, boxMax); - - QBox3D expBox(boxMin, boxMax); - QGLSceneNode *node = new QGLSceneNode; - node->setObjectName(QLatin1String("Root node")); - QGLSceneNode *geoNode = 0; - QGeometryData data; - QGLBuilder builder; - - data.appendVertex(bottomLeftFront, bottomRightFront, topRightFront, topLeftFront); - builder.addQuads(data); // top of cube - builder.addQuadsInterleaved(data, data.translated(QVector3D(0, 0, 2))); // sides of cube - builder.addQuads(data.reversed()); // bottom of cube - - geoNode = builder.finalizedSceneNode(); - geoNode->setObjectName("Geometry node"); - node->addNode(geoNode); - - if (!scale.isNull()) - { - QMatrix4x4 m = node->localTransform(); - m.scale(scale); - node->setLocalTransform(m); - } - - if (!translation.isNull()) - { - QMatrix4x4 m = node->localTransform(); - m.translate(translation); - node->setLocalTransform(m); - } - - if (!rotation.isNull()) - { - QMatrix4x4 m = node->localTransform(); - if (qIsNull(rotation.x())) - m.rotate(rotation.x(), 1.0, 0.0, 0.0); - if (qIsNull(rotation.y())) - m.rotate(rotation.y(), 0.0, 1.0, 0.0); - if (qIsNull(rotation.z())) - m.rotate(rotation.z(), 0.0, 0.0, 1.0); - node->setLocalTransform(m); - } - - QBox3D gotBox = node->boundingBox(); - QCOMPARE(gotBox.minimum(), expBox.minimum()); - QCOMPARE(gotBox.maximum(), expBox.maximum()); - - - // now clear out the root nodes transform and apply the same transform - // to the child node - should be exactly the same - - QMatrix4x4 saveMat = node->localTransform(); - node->setLocalTransform(QMatrix4x4()); // set back to identity - geoNode->setLocalTransform(saveMat); - - gotBox = node->boundingBox(); - QCOMPARE(gotBox.minimum(), expBox.minimum()); - QCOMPARE(gotBox.maximum(), expBox.maximum()); - - delete node; -} - -class TestSceneNode : public QGLSceneNode -{ -public: - QMatrix4x4 resultingModelView; - QMatrix4x4 transformMatrix; - - TestSceneNode() - : QGLSceneNode() - { - // - } - -protected: - virtual void drawGeometry(QGLPainter *painter) - { - resultingModelView = painter->modelViewMatrix().top(); - - // basically reimplement the private function "transform()" here to get the value of the transforms - QMatrix4x4 m; - if (!position().isNull()) - m.translate(position()); - if (!localTransform().isIdentity()) - m *= localTransform(); - QList<QGraphicsTransform3D *> tx = transforms(); - for (int index = tx.size() - 1; index >= 0; --index) - tx.at(index)->applyTo(&m); - - transformMatrix = m; - } - -}; - -void tst_QGLSceneNode::position_QTBUG_17279() -{ - QGeometryData geom; - geom.appendVertex(QVector3D(0, 0, 0), - QVector3D(1.414, 1.414, 0), - QVector3D(2, 0, 0)); - TestSceneNode *node = new TestSceneNode; - - QVERIFY(node->resultingModelView.isIdentity()); - QVERIFY(node->transformMatrix.isIdentity()); - - node->setGeometry(geom); - node->setCount(3); - node->setPosition(QVector3D(0.f, 0.f, -5.f)); - - QVERIFY(node->localTransform().isIdentity()); - QCOMPARE(node->position().z(), -5.0); - - QGLWidget w; - QGLPainter p(&w); - QGLCamera cam; - p.setCamera(&cam); - - QMatrix4x4 m = p.modelViewMatrix().top(); - - node->draw(&p); - - QVERIFY(m == p.modelViewMatrix().top()); - - QCOMPARE(node->resultingModelView(2, 3), -15.0); - QCOMPARE(node->transformMatrix(2, 3), -5.0); - - QGeometryData geom2; - geom2.appendVertex(QVector3D(0, 0, 0), - QVector3D(-1.414, 1.414, 0), - QVector3D(-2, 0, 0)); - TestSceneNode *node2 = new TestSceneNode; - node2->setGeometry(geom2); - node2->setCount(3); - node2->setPosition(QVector3D(0.f, -1.f, -5.f)); - - node2->draw(&p); - - QVERIFY(m == p.modelViewMatrix().top()); - - QCOMPARE(node2->resultingModelView(1, 3), -1.0); - QCOMPARE(node2->transformMatrix(1, 3), -1.0); - QCOMPARE(node2->resultingModelView(2, 3), -15.0); - QCOMPARE(node2->transformMatrix(2, 3), -5.0); -} - -QTEST_MAIN(tst_QGLSceneNode) - -#include "tst_qglscenenode.moc" diff --git a/tests/auto/threed/qglsection/qglsection.pro b/tests/auto/threed/qglsection/qglsection.pro deleted file mode 100644 index 37f1a3c1..00000000 --- a/tests/auto/threed/qglsection/qglsection.pro +++ /dev/null @@ -1,8 +0,0 @@ -load(qttest_p4.prf) -TEMPLATE=app -QT += testlib -CONFIG += unittest warn_on qt3d - -INCLUDEPATH += ../../../shared -SOURCES += tst_qglsection.cpp -INCLUDEPATH += ../../../../src/threed/geometry diff --git a/tests/auto/threed/qglsection/tst_qglsection.cpp b/tests/auto/threed/qglsection/tst_qglsection.cpp deleted file mode 100644 index 726a995b..00000000 --- a/tests/auto/threed/qglsection/tst_qglsection.cpp +++ /dev/null @@ -1,674 +0,0 @@ -/**************************************************************************** -** -** 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 QtQuick3D module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** 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. -** -** 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. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include <QtTest/QtTest> -#include "qglsection_p.h" -#include "qglbuilder.h" -#include "qgeometrydata.h" -#include "qtest_helpers.h" -#include "qvector3darray.h" - -class tst_QGLSection : public QObject -{ - Q_OBJECT -public: - tst_QGLSection() {} - ~tst_QGLSection() {} - void testSmooth(QGLSection *sec, QGLBuilder *builder); - void testFaceted(QGLSection *sec, QGLBuilder *builder); - -private slots: - void create(); - void modify(); - void append(); - void appendSmooth(); - void appendSmoothMap(); - void appendFaceted(); - void appendFacetedMap(); - void accumNormals(); - void normalizedNormals(); - void appendTexCoord(); - void appendColor(); - void accessors(); -}; - -// Indices in a QGLIndexArray are int on desktop, ushort on OpenGL/ES. -// This macro works around the discrepancy to avoid confusing QCOMPARE. -#define QCOMPARE_INDEX(x,y) QCOMPARE(int(x), int(y)) - -class QGLSectionTest : public QGLSection -{ -public: - QGLSectionTest(QGLBuilder *builder, QGL::Smoothing s = QGL::Smooth) - : QGLSection(builder, s) {} - - void appendSmooth(const QLogicalVertex &vertex) - { - QGLSection::appendSmooth(vertex); - } - - void appendFaceted(const QLogicalVertex &vertex) - { - QGLSection::appendFaceted(vertex); - } - - void append(const QLogicalVertex &vertex) - { - QGLSection::append(vertex); - } -}; - -class TestBuilder : public QGLBuilder -{ -public: - QGLSection *currentSection() { return QGLBuilder::currentSection(); } - QList<QGLSection*> sections() { return QGLBuilder::sections(); } -}; - -static void addGeometry(TestBuilder &builder) -{ - QVector3D va(-1.0f, -1.0f, 0.0f); - QVector3D vb(1.0f, -1.0f, 0.0f); - QVector3D vc(1.0f, 1.0f, 0.0f); - QGeometryData p; - p.appendVertex(va, vb, vc); - builder.addTriangles(p); -} - -void tst_QGLSection::create() -{ - // Test that a newly created object has the correct defaults. - TestBuilder builder; - builder.newSection(); - QGLSection *section = builder.currentSection(); - QVERIFY(section->hasField(QGL::Position)); // need this initially now - QCOMPARE(section->fields(), (quint32)1); - QCOMPARE(section->smoothing(), QGL::Smooth); - QCOMPARE(section->count(), 0); - QCOMPARE(section->boundingBox(), QBox3D()); - QCOMPARE(section->mapThreshold(), 5); - - // suppress warning - addGeometry(builder); - builder.finalizedSceneNode(); -} - -void tst_QGLSection::modify() -{ - TestBuilder builder; - builder.newSection(); - QGLSection *section = builder.currentSection(); - - QVector3D va(-1.0f, -1.0f, 0.0f); - QVector3D vb(1.0f, -1.0f, 0.0f); - QVector3D vc(1.0f, 1.0f, 0.0f); - QVector3D n(0.0f, 0.0f, 1.0f); - QGeometryData p; - p.appendVertex(va, vb, vc); - p.appendNormal(n, n, n); - section->setMapThreshold(30); - QCOMPARE(section->mapThreshold(), 30); - builder.addTriangles(p); - QCOMPARE(section->count(), 3); - builder.newSection(); - QGLSection *section2 = builder.currentSection(); - builder.addTriangles(p); - QCOMPARE(section2->count(), 3); - - // suppress warning - builder.finalizedSceneNode(); -} - -void tst_QGLSection::append() -{ - TestBuilder builder; - builder.newSection(); - QGLSection *section = builder.currentSection(); - - QVector3D testVertex(1.234f, 2.345f, 3.456f); - QVector3D testNormal(1.0f, 0.0f, 0.0f); - QLogicalVertex vx(testVertex, testNormal); - section->append(vx); - QCOMPARE(section->vertices().count(), 1); - QCOMPARE(section->vertices().at(0), testVertex); - QCOMPARE(section->normals().count(), 1); - QCOMPARE(section->normals().at(0), testNormal); - QCOMPARE(section->indices().size(), 1); - QCOMPARE(section->texCoords().count(), 0); - QCOMPARE(section->colors().count(), 0); - - // suppress warning - builder.finalizedSceneNode(); -} - -void tst_QGLSection::appendSmooth() -{ - TestBuilder builder; - QGLSectionTest *section = new QGLSectionTest(&builder); - testSmooth(section, &builder); - - // suppress warning - builder.finalizedSceneNode(); -} - -void tst_QGLSection::appendSmoothMap() -{ - TestBuilder builder; - QGLSectionTest *section = new QGLSectionTest(&builder); - int t = section->mapThreshold(); - QVector3D testVertex(-12.34f, -23.45f, -34.56f); - QVector3D incrVector(0.02, 0.02, 0.02); - QVector3D testNormal(1.0f, 0.0f, 0.0f); - for (int i = 0; i < (t - 2); ++i) - { - section->appendSmooth(QLogicalVertex(testVertex, testNormal)); - testVertex += incrVector; - } - testSmooth(section, &builder); - - // suppress warning - builder.finalizedSceneNode(); -} - -void tst_QGLSection::testSmooth(QGLSection *section, QGLBuilder *builder) -{ - int poffset = section->count(QGL::Position); - int noffset = section->count(QGL::Normal); - - // append a vertex - check it appears in the data along with its normal - QVector3D testVertex(1.234f, 2.345f, 3.456f); - QVector3D testNormal(4.321f, 5.432f, 6.543f); - section->appendSmooth(QLogicalVertex(testVertex, testNormal)); - QCOMPARE(section->vertices().count(), poffset + 1); - QCOMPARE(section->vertices().at(poffset + 0), testVertex); - QCOMPARE(section->normals().count(), noffset + 1); - QCOMPARE(section->normals().at(noffset + 0), testNormal); - QCOMPARE(section->indices().size(), poffset + 1); - QCOMPARE_INDEX(section->indices()[poffset + 0], poffset + 0); - - // append a vertex equal to one already appended - check it was coalesced - QVector3D testNormal2(0.0f, 0.0f, 1.0f); - QVector3D result = testNormal + testNormal2; // QVector3D(0.0f, 0.0f, 7.543f); - section->appendSmooth(QLogicalVertex(testVertex, testNormal2)); - QCOMPARE(section->vertices().count(), poffset + 1); - QCOMPARE(section->vertices().at(poffset + 0), testVertex); - QCOMPARE(section->normals().count(), noffset + 1); - QCOMPARE(section->normals().at(noffset + 0), result); - QCOMPARE(section->indices().size(), poffset + 2); - QCOMPARE_INDEX(section->indices()[poffset + 1], poffset + 0); - - // append a new different vertex - check it is not coalesced - QVector3D testVertex2(-1.234f, -2.345f, -3.456f); - QVector3D testNormal3(-4.321f, -5.432f, -6.543f); - section->appendSmooth(QLogicalVertex(testVertex2, testNormal3)); - QCOMPARE(section->vertices().count(), poffset + 2); - QCOMPARE(section->vertices().at(poffset + 1), testVertex2); - QCOMPARE(section->normals().count(), noffset + 2); - QCOMPARE(section->normals().at(noffset + 1), testNormal3); - QCOMPARE(section->indices().size(), poffset + 3); - QCOMPARE_INDEX(section->indices()[poffset + 2], poffset + 1); - - // append a vertex equal to one already appended, but inside a new section - check its not coalesced - section = new QGLSectionTest(builder); - section->appendSmooth(QLogicalVertex(testVertex2, testNormal3)); - QCOMPARE(section->vertices().count(), 1); - QCOMPARE(section->vertices().at(0), testVertex2); - QCOMPARE(section->normals().count(), 1); - QCOMPARE(section->normals().at(0), testNormal3); - QCOMPARE(section->indices().size(), 1); - QCOMPARE_INDEX(section->indices()[0], 0); -} - -void tst_QGLSection::appendFaceted() -{ - TestBuilder builder; - QGLSectionTest *section = new QGLSectionTest(&builder); - // test the part where its only using the QArray - testFaceted(section, &builder); - - // suppress warning - builder.finalizedSceneNode(); -} - -void tst_QGLSection::appendFacetedMap() -{ - TestBuilder builder; - QGLSectionTest *section = new QGLSectionTest(&builder); - // now create a new section and fill to just below the threshold for QMap - int t = section->mapThreshold(); - QVector3D testVertex(-12.34f, -23.45f, -34.56f); - QVector3D incrVector(0.02, 0.02, 0.02); - QVector3D testNormal(1.0f, 0.0f, 0.0f); - for (int i = 0; i < (t - 2); ++i) - { - section->appendSmooth(QLogicalVertex(testVertex, testNormal)); - testVertex += incrVector; - } - testFaceted(section, &builder); - - // suppress warning - builder.finalizedSceneNode(); -} - -void tst_QGLSection::accumNormals() -{ - /* - This mesh is a cap that could be the top of a sphere - its a central - quad in the z = 1 plane, with x = 1, y = 1 as the bottom-left corner; - with four more quads above, below, to the left and to the right, as - viewed looking down the -ve z axis (plan view). The four quads around - the central one join one one edge (in the z = 1 plane) and on the opp. - edge slope down to the z = 0 plane. The four corners are filled in - with triangles, so that the whole figure looks like an octagon in plan. - - plan view - x/y plane: - ^ ---------- - | / | | \ - y / | | \ - /___|_____|____\ - | | | | - | | | | - |____|_____|_____| - \ |* | / - \ | | / - \ | | / - ---------- --> x - - side view - x/z plane: - ________ z = 1 - / |* | \ - / | | \ - / | | \ - ----------------- z = 0 - - The normals smoothing should make this as "round" as possible. - - Each quad of course, is actually divided from bottom-left to top-right - into two triangles (not shown in the ascii art for clarity). The total - number of triangles in the rendered result should be 14. - - At the vertex marked with the asterisk - #3 in the data below - there - are 5 triangular faces contributing normals to the smoothed sum. The - quad on the top has two co-planar triangles, and _each_ of those has - a normal equal to (0, 0, 1) - only one of these should be summed. - The other triangles are 1/2 of the two neighbouring quads - one has a - normal of (-1, 0, 1) the other (0, -1, 1) - and the corner triangle - which has a normal of (-1, -1, 1). - - The normalized sum of these is roughly (-0.4, -0.4, 0.8). - - If the normal from the extra triangle is erroneously included then - the normalized sum is roughly (-0.35, -0.35, 0.87). - - The resulting normal is pulled more in the z-direction. - - In general if a a flat plane is broken up into a large number of - triangles, they can bias the normal calculation. In a model often - this can occur where triangulation algorithms produce degenerate - solutions with many triangles converging on a point. - - This test is to cover this problem. - */ - TestBuilder builder; - builder.newSection(QGL::Smooth); // default - but making the point - //QGLSection *section = builder.currentSection(); - QGLSceneNode *node = builder.currentNode(); - static float data[12*3] = { - 1.0f, 0.0f, 0.0f, - 2.0f, 0.0f, 0.0f, - 0.0f, 1.0f, 0.0f, - 1.0f, 1.0f, 1.0f, - 2.0f, 1.0f, 1.0f, - 3.0f, 1.0f, 0.0f, - 0.0f, 2.0f, 0.0f, - 1.0f, 2.0f, 1.0f, - 2.0f, 2.0f, 1.0f, - 3.0f, 2.0f, 0.0f, - 1.0f, 3.0f, 0.0f, - 2.0f, 3.0f, 0.0f - }; - QVector3DArray v = QVector3DArray::fromRawData((const QVector3D *)data, 12); - QGeometryData quads; - quads.appendVertex(v[0], v[1], v[4], v[3]); // 0 - quads.appendVertex(v[2], v[3], v[7], v[6]); // 1 - quads.appendVertex(v[3], v[4], v[8], v[7]); // 2 - quads.appendVertex(v[4], v[5], v[9], v[8]); // 3 - quads.appendVertex(v[7], v[8], v[11], v[10]); // 4 - builder.addQuads(quads); - QGeometryData triangles; - triangles.appendVertex(v[0], v[3], v[2]); // 5 - triangles.appendVertex(v[1], v[5], v[4]); // 6 - triangles.appendVertex(v[6], v[7], v[10]); // 7 - triangles.appendVertex(v[8], v[9], v[11]); // 8 - builder.addTriangles(triangles); - builder.finalizedSceneNode(); - - // There are 9 faces as shown above - here are their normals - QVector3DArray face_norms; - face_norms.extend(9); - face_norms[0] = QVector3D(0, -1, 1); - face_norms[1] = QVector3D(-1, 0, 1); - face_norms[2] = QVector3D(0, 0, 1); - face_norms[3] = QVector3D(1, 0, 1); - face_norms[4] = QVector3D(0, 1, 1); - face_norms[5] = QVector3D(-1, -1, 1); - face_norms[6] = QVector3D(1, -1, 1); - face_norms[7] = QVector3D(-1, 1, 1); - face_norms[8] = QVector3D(1, 1, 1); - //for (int i = 0; i < 9; ++i) - // face_norms[i].normalize(); - - QVector3DArray expected; - expected.extend(12); - expected[0] = face_norms[0] + face_norms[5]; - expected[1] = face_norms[0] + face_norms[6]; - expected[4] = face_norms[1] + face_norms[5]; - expected[3] = face_norms[0] + face_norms[1] + face_norms[2] + face_norms[5]; - expected[2] = face_norms[0] + face_norms[2] + face_norms[3] + face_norms[6]; - expected[8] = face_norms[3] + face_norms[6]; - expected[6] = face_norms[1] + face_norms[7]; - expected[5] = face_norms[1] + face_norms[2] + face_norms[4] + face_norms[7]; - expected[7] = face_norms[2] + face_norms[3] + face_norms[4] + face_norms[8]; - expected[9] = face_norms[3] + face_norms[8]; - expected[11] = face_norms[4] + face_norms[7]; - expected[10] = face_norms[4] + face_norms[8]; - for (int i = 0; i < 12; ++i) - expected[i].normalize(); - - QGeometryData res = node->geometry(); - QCOMPARE(res.count(QGL::Position), 12); - QCOMPARE(res.count(QGL::Normal), 12); - QCOMPARE(res.indexCount(), 14 * 3); - QCOMPARE(res.vertexAt(0), v[0]); - QCOMPARE(res.vertexAt(4), v[2]); - QCOMPARE(res.vertexAt(7), v[8]); - QCOMPARE(res.vertexAt(11), v[10]); - QCOMPARE(res.normalAt(0), expected.at(0)); - QCOMPARE(res.normalAt(1), expected.at(1)); - QCOMPARE(res.normalAt(2), expected.at(2)); - QCOMPARE(res.normalAt(3), expected.at(3)); - QCOMPARE(res.normalAt(4), expected.at(4)); - QCOMPARE(res.normalAt(5), expected.at(5)); - QCOMPARE(res.normalAt(6), expected.at(6)); - QCOMPARE(res.normalAt(7), expected.at(7)); - QCOMPARE(res.normalAt(8), expected.at(8)); - QCOMPARE(res.normalAt(9), expected.at(9)); - QCOMPARE(res.normalAt(10), expected.at(10)); - QCOMPARE(res.normalAt(11), expected.at(11)); -} - -void tst_QGLSection::normalizedNormals() -{ - const qreal qRadius = 1.0f; - const qreal qHeight = 0.6f; - const qreal qThickness = 0.4f; - const int qNumSlices = 16; - - TestBuilder builder; - builder.newSection(QGL::Smooth); // default - but making the point - //QGLSection *section = builder.currentSection(); - QGLSceneNode *node = builder.currentNode(); - - // draw two 90 degree arcs, qThickness apart radially, and qHeight apart - // in the z dimension. the points on the two arcs are joined into quads - // but all the points on the high arc are joined to one single point in - // the same z plane. - QVector3D ap(qRadius, 0.0f, 0.0f); - QVector3D bp(qRadius + qThickness, 0.0f, qHeight); - QVector3D anc(qRadius * 2.0f, qRadius *2.0f, qHeight); - for (int slice = 1; slice < qNumSlices; ++slice) - { - const qreal pi2 = 2.0 * M_PI; - qreal angle = (slice * pi2) / (4 * qNumSlices); - qreal cs = qCos(angle); - qreal sn = qSin(angle); - QVector3D a(cs * qRadius, sn * qRadius, 0.0f); - QVector3D b(cs * (qRadius + qThickness), sn * (qRadius + qThickness), qHeight); - QGeometryData quad; - quad.appendVertex(ap, bp, b, a); - builder.addQuads(quad); - QGeometryData tri; - tri.appendVertex(b, bp, anc); - builder.addTriangles(tri); - ap = a; - bp = b; - } - builder.finalizedSceneNode(); - QGeometryData data = node->geometry(); - QVERIFY(!data.isNull()); - QCOMPARE(data.count(QGL::Position), 33); -} - -void tst_QGLSection::testFaceted(QGLSection *section, QGLBuilder *builder) -{ - int poffset = section->count(QGL::Position); - int noffset = section->count(QGL::Normal); - - // append a vertex - check it appears in the data along with its normal - QVector3D testVertex(1.234f, 2.345f, 3.456f); - QVector3D testNormal(4.321f, 5.432f, 6.543f); - section->appendFaceted(QLogicalVertex(testVertex, testNormal)); - QCOMPARE(section->vertices().count(), poffset + 1); - QCOMPARE(section->vertices().at(poffset + 0), testVertex); - QCOMPARE(section->normals().count(), noffset + 1); - QCOMPARE(section->normals().at(noffset + 0), testNormal); - QCOMPARE(section->indices().size(), poffset + 1); - QCOMPARE_INDEX(section->indices()[poffset + 0], poffset + 0); - - // append a vertex equal to one already appended, but with different normal - check it was NOT coalesced - QVector3D testNormal2(0.0f, 0.0f, 1.0f); - section->appendFaceted(QLogicalVertex(testVertex, testNormal2)); - QCOMPARE(section->vertices().count(), poffset + 2); - QCOMPARE(section->vertices().at(poffset + 1), testVertex); - QCOMPARE(section->normals().count(), noffset + 2); - QCOMPARE(section->normals().at(noffset + 1), testNormal2); - QCOMPARE(section->indices().size(), poffset + 2); - QCOMPARE_INDEX(section->indices()[poffset + 1], poffset + 1); - - // append a vertex equal to one already appended, but with same normal - check it WAS coalesced - section->appendFaceted(QLogicalVertex(testVertex, testNormal2)); - QCOMPARE(section->vertices().count(), poffset + 2); - QCOMPARE(section->vertices().at(poffset + 1), testVertex); - QCOMPARE(section->normals().count(), noffset + 2); - QCOMPARE(section->normals().at(noffset + 1), testNormal2); - QCOMPARE(section->indices().size(), poffset + 3); - QCOMPARE_INDEX(section->indices()[poffset + 2], poffset + 1); - - // append a vertex equal to one already appended, with same normal, BUT in a new section - check it was NOT coalesced - section = new QGLSectionTest(builder); - section->appendFaceted(QLogicalVertex(testVertex, testNormal2)); - QCOMPARE(section->vertices().count(), 1); - QCOMPARE(section->vertices().at(0), testVertex); - QCOMPARE(section->normals().count(), 1); - QCOMPARE(section->normals().at(0), testNormal2); - QCOMPARE(section->indices().size(), 1); - QCOMPARE_INDEX(section->indices()[0], 0); -} - -void tst_QGLSection::appendTexCoord() -{ - TestBuilder builder; - QGLSectionTest *section = new QGLSectionTest(&builder); - - // note that the tests above do the case of texCoord, InvalidTexCoord - - // append a texture - check it appears in the data at the correct index - QVector3D testVertex(1.234f, 2.345f, 3.456f); - QVector3D testNormal(4.321f, 5.432f, 6.543f); - QVector2D testTexCoord(0.0f, 0.0f); - section->appendSmooth(QLogicalVertex(testVertex, testNormal, testTexCoord)); - QCOMPARE(section->vertices().count(), 1); - QCOMPARE(section->vertices().at(0), testVertex); - QCOMPARE(section->normals().count(), 1); - QCOMPARE(section->normals().at(0), testNormal); - QCOMPARE(section->texCoords().count(), 1); - QCOMPARE(section->texCoords().at(0), testTexCoord); - QCOMPARE(section->indices().size(), 1); - QCOMPARE_INDEX(section->indices()[0], 0); - - // append same texture - will coalesce and index the vert - section->appendSmooth(QLogicalVertex(testVertex, testNormal, testTexCoord)); - QCOMPARE(section->vertices().count(), 1); - QCOMPARE(section->vertices().at(0), testVertex); - QCOMPARE(section->normals().count(), 1); - QCOMPARE(section->normals().at(0), testNormal); - QCOMPARE(section->texCoords().count(), 1); - QCOMPARE(section->texCoords().at(0), testTexCoord); - QCOMPARE(section->indices().size(), 2); - QCOMPARE_INDEX(section->indices()[1], 0); - - // new vertex created to carry the updated texture coord, even though - // the normal and vertex are the same and thus the logical vert would - // otherwise coalesced - the new vert is a copy (same vert and normal) - QVector2D testTexCoord2(1.0, 1.0); - section->appendSmooth(QLogicalVertex(testVertex, testNormal, testTexCoord2)); - QCOMPARE(section->vertices().count(), 2); - QCOMPARE(section->vertices().at(1), testVertex); - QCOMPARE(section->normals().count(), 2); - QCOMPARE(section->normals().at(1), testNormal); - QCOMPARE(section->texCoords().count(), 2); - QCOMPARE(section->texCoords().at(1), testTexCoord2); - QCOMPARE(section->indices().size(), 3); - QCOMPARE_INDEX(section->indices()[2], 1); - - section = new QGLSectionTest(&builder); - - // append a faceted vertex with a tex coord check it appears in the data - // in a new section now, so the same vert and normal wont be coalesced - section->appendFaceted(QLogicalVertex(testVertex, testNormal, testTexCoord)); - QCOMPARE(section->vertices().count(), 1); - QCOMPARE(section->vertices().at(0), testVertex); - QCOMPARE(section->normals().count(), 1); - QCOMPARE(section->normals().at(0), testNormal); - QCOMPARE(section->texCoords().count(), 1); - QCOMPARE(section->texCoords().at(0), testTexCoord); - QCOMPARE(section->indices().size(), 1); - QCOMPARE_INDEX(section->indices()[0], 0); - - // append a vertex & normal equal to one already appended, but with different tex coord - // check it was NOT coalesced, dup vert created - section->appendFaceted(QLogicalVertex(testVertex, testNormal, testTexCoord2)); - QCOMPARE(section->vertices().count(), 2); - QCOMPARE(section->vertices().at(1), testVertex); - QCOMPARE(section->normals().count(), 2); - QCOMPARE(section->normals().at(1), testNormal); - QCOMPARE(section->texCoords().count(), 2); - QCOMPARE(section->texCoords().at(1), testTexCoord2); - QCOMPARE(section->indices().size(), 2); - QCOMPARE_INDEX(section->indices()[1], 1); - - // append a vertex equal to first one appended above, with same normal, and - // same texture - check it WAS coalesced to index 0 - section->appendFaceted(QLogicalVertex(testVertex, testNormal, testTexCoord)); - QCOMPARE(section->vertices().count(), 2); - QCOMPARE(section->vertices().at(1), testVertex); - QCOMPARE(section->normals().count(), 2); - QCOMPARE(section->normals().at(1), testNormal); - QCOMPARE(section->texCoords().count(), 2); - QCOMPARE(section->texCoords().at(1), testTexCoord2); - QCOMPARE(section->indices().size(), 3); - QCOMPARE_INDEX(section->indices()[2], 0); - - QVERIFY(section->hasField(QGL::Normal)); - QVERIFY(section->hasField(QGL::TextureCoord0)); - QVERIFY(!section->hasField(QGL::Color)); - - // suppress warning - builder.finalizedSceneNode(); -} - -void tst_QGLSection::appendColor() -{ - TestBuilder builder; - QGLSectionTest *section = new QGLSectionTest(&builder); - - QColor4ub color(32, 64, 128, 255); - QVector3D testVertex(1.234f, 2.345f, 3.456f); - section->append(QLogicalVertex(testVertex, color)); - QCOMPARE(section->vertices().count(), 1); - QCOMPARE(section->vertices().at(0), testVertex); - QCOMPARE(section->colors().count(), 1); - QCOMPARE(section->colors().at(0), color); - - QVERIFY(section->hasField(QGL::Color)); - QVERIFY(!section->hasField(QGL::TextureCoord0)); - QVERIFY(!section->hasField(QGL::Normal)); - - section = new QGLSectionTest(&builder); - - QVector2D testTexCoord(0.0f, 0.0f); - QLogicalVertex lv; - lv.setVertex(testVertex); - lv.setColor(color); - lv.setTexCoord(testTexCoord); - section->append(lv); - QCOMPARE(section->vertices().count(), 1); - QCOMPARE(section->vertices().at(0), testVertex); - QCOMPARE(section->colors().count(), 1); - QCOMPARE(section->colors().at(0), color); - QCOMPARE(section->texCoords().count(), 1); - QCOMPARE(section->texCoords().at(0), testTexCoord); - - QVERIFY(section->hasField(QGL::Color)); - QVERIFY(section->hasField(QGL::TextureCoord0)); - QVERIFY(!section->hasField(QGL::Normal)); - - // suppress warning - builder.finalizedSceneNode(); -} - -void tst_QGLSection::accessors() -{ - TestBuilder builder; - QGLSectionTest *section = new QGLSectionTest(&builder); - - QCOMPARE(section->smoothing(), QGL::Smooth); - - QGLSectionTest *section2 = new QGLSectionTest(&builder, QGL::Faceted); - QCOMPARE(section2->smoothing(), QGL::Faceted); - - // suppress warning - builder.finalizedSceneNode(); -} - -QTEST_APPLESS_MAIN(tst_QGLSection) - -#include "tst_qglsection.moc" diff --git a/tests/auto/threed/qglsharedresource/qglsharedresource.pro b/tests/auto/threed/qglsharedresource/qglsharedresource.pro deleted file mode 100644 index e551288c..00000000 --- a/tests/auto/threed/qglsharedresource/qglsharedresource.pro +++ /dev/null @@ -1,10 +0,0 @@ -load(qttest_p4.prf) -TEMPLATE=app -QT += testlib -CONFIG += unittest warn_on qt3d - -INCLUDEPATH += ../../../../src/threed/textures -VPATH += ../../../../src/threed/textures - -HEADERS += qglsharedresource_p.h -SOURCES += tst_qglsharedresource.cpp qglsharedresource.cpp diff --git a/tests/auto/threed/qglsharedresource/tst_qglsharedresource.cpp b/tests/auto/threed/qglsharedresource/tst_qglsharedresource.cpp deleted file mode 100644 index b889d550..00000000 --- a/tests/auto/threed/qglsharedresource/tst_qglsharedresource.cpp +++ /dev/null @@ -1,158 +0,0 @@ -/**************************************************************************** -** -** 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 QtQuick3D module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** 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. -** -** 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. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include <QtTest/QtTest> -#include "qglsharedresource_p.h" - -class tst_QGLSharedResource : public QObject -{ -Q_OBJECT - -public: - tst_QGLSharedResource() {} - ~tst_QGLSharedResource() {} - -private slots: - void resourceSharing(); -}; - -static int dummyDestroyCount = 0; - -static void destroyDummyResource(GLuint id) -{ - QVERIFY(id != 0); - QVERIFY(QGLContext::currentContext() != 0); - ++dummyDestroyCount; -} - -void tst_QGLSharedResource::resourceSharing() -{ - dummyDestroyCount = 0; - - // Create a context. - QGLWidget *glw1 = new QGLWidget(); - glw1->makeCurrent(); - - // Nothing should be sharing with glw1's context yet. - QVERIFY(!glw1->isSharing()); - - // Create a guard for the first context. - QGLSharedResource guard(destroyDummyResource); - QVERIFY(guard.context() == 0); - QVERIFY(guard.id() == 0); - guard.attach(glw1->context(), 3); - QVERIFY(guard.context() == glw1->context()); - QVERIFY(guard.id() == 3); - - // Create another context that shares with the first. - QVERIFY(!glw1->isSharing()); - QGLWidget *glw2 = new QGLWidget(0, glw1); - if (!glw2->isSharing()) { - delete glw2; - delete glw1; - QSKIP("Context sharing is not supported", SkipSingle); - } - QVERIFY(glw1->isSharing()); - QVERIFY(glw1->context() != glw2->context()); - - // Guard should still be the same. - QVERIFY(guard.context() == glw1->context()); - QVERIFY(guard.id() == 3); - - // Create some guards and then destroy them while the context is active. - { - QGLSharedResource guard2(destroyDummyResource); - guard2.attach(glw1->context(), 4); - QVERIFY(guard2.context() == glw1->context()); - QVERIFY(guard2.id() == 4); - } - QCOMPARE(dummyDestroyCount, 1); - QGLSharedResource guard3(destroyDummyResource); - guard3.attach(glw1->context(), 6); - QVERIFY(guard3.context() == glw1->context()); - QVERIFY(guard3.id() == 6); - guard3.destroy(); - QVERIFY(guard3.context() == 0); - QVERIFY(guard3.id() == 0); - QCOMPARE(dummyDestroyCount, 2); - - // Create a third context, not sharing with the others. - QGLWidget *glw3 = new QGLWidget(); - QVERIFY(!glw3->isSharing()); - - // Create a guard on the standalone context. - QGLSharedResource guard4(destroyDummyResource); - guard4.attach(glw3->context(), 5); - QVERIFY(guard4.context() == glw3->context()); - QVERIFY(guard4.id() == 5); - - // Shared guard should still be the same. - QVERIFY(guard.context() == glw1->context()); - QVERIFY(guard.id() == 3); - - // Delete the first context. - delete glw1; - - // The second context should no longer register as sharing. - QVERIFY(!glw2->isSharing()); - - // Shared guard should now be the second context, with the id the same. - QVERIFY(guard.context() == glw2->context()); - QVERIFY(guard.id() == 3); - QVERIFY(guard4.context() == glw3->context()); - QVERIFY(guard4.id() == 5); - - // Clean up the other contexts. - delete glw2; - delete glw3; - - // Guards should now be null and the id zero, but no extra calls to - // the dummy destroy function. - QVERIFY(guard.context() == 0); - QVERIFY(guard.id() == 0); - QVERIFY(guard4.context() == 0); - QVERIFY(guard4.id() == 0); - QCOMPARE(dummyDestroyCount, 2); -} - -QTEST_MAIN(tst_QGLSharedResource) - -#include "tst_qglsharedresource.moc" diff --git a/tests/auto/threed/qglsphere/qglsphere.pro b/tests/auto/threed/qglsphere/qglsphere.pro deleted file mode 100644 index d30ed784..00000000 --- a/tests/auto/threed/qglsphere/qglsphere.pro +++ /dev/null @@ -1,7 +0,0 @@ -load(qttest_p4.prf) -TEMPLATE=app -QT += testlib -CONFIG += unittest warn_on qt3d - -INCLUDEPATH += ../../../shared -SOURCES += tst_qglsphere.cpp diff --git a/tests/auto/threed/qglsphere/tst_qglsphere.cpp b/tests/auto/threed/qglsphere/tst_qglsphere.cpp deleted file mode 100644 index 7aaaa3fe..00000000 --- a/tests/auto/threed/qglsphere/tst_qglsphere.cpp +++ /dev/null @@ -1,125 +0,0 @@ -/**************************************************************************** -** -** 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 QtQuick3D module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** 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. -** -** 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. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include <QtTest/QtTest> - -#include "qglsphere.h" -#include "qglbuilder.h" - -class tst_QGLSphere : public QObject -{ - Q_OBJECT -public: - tst_QGLSphere() {} - ~tst_QGLSphere() {} - -private slots: - void create(); - void modify(); - void build(); - -private: - bool validateSphere(QGLSceneNode *node, qreal size); -}; - -void tst_QGLSphere::create() -{ - QGLSphere sphere1; - QCOMPARE(sphere1.diameter(), qreal(1.0f)); - QCOMPARE(sphere1.subdivisionDepth(), 5); - - QGLSphere sphere2(27.5f); - QCOMPARE(sphere2.diameter(), qreal(27.5f)); - QCOMPARE(sphere2.subdivisionDepth(), 5); - - QGLSphere sphere3(20.5f, 4); - QCOMPARE(sphere3.diameter(), qreal(20.5f)); - QCOMPARE(sphere3.subdivisionDepth(), 4); -} - -void tst_QGLSphere::modify() -{ - QGLSphere sphere1; - sphere1.setDiameter(5.0f); - sphere1.setSubdivisionDepth(4); - QCOMPARE(sphere1.diameter(), qreal(5.0f)); - QCOMPARE(sphere1.subdivisionDepth(), 4); -} - -// Validates the geometry in a sphere node to check that all vertices -// are on the surface of a sphere of diameter "size" and all normals -// are of length 1 and point directly out from the center. -bool tst_QGLSphere::validateSphere(QGLSceneNode *node, qreal size) -{ - QGeometryData data = node->geometry(); - int start = node->start(); - int count = node->count(); - if (count <= 0) - return false; - QGL::IndexArray indices = data.indices(); - for (int index = 0; index < count; ++index) { - QVector3D v = data.vertexAt(indices.at(index + start)); - QVector3D n = data.normalAt(indices.at(index + start)); - if (qAbs(n.length() - 1.0f) >= 0.0001) - return false; - QVector3D v2 = n * size / 2.0f; - if (qAbs(v.x() - v2.x()) >= 0.0001 || - qAbs(v.y() - v2.y()) >= 0.0001 || - qAbs(v.z() - v2.z()) >= 0.0001) - return false; - } - return true; -} - -void tst_QGLSphere::build() -{ - QGLBuilder builder; - builder.newSection(QGL::Faceted); - QGLSceneNode *node1 = builder.newNode(); - builder << QGLSphere(5.0f, 5); - QGLSceneNode *root = builder.finalizedSceneNode(); - QVERIFY(validateSphere(node1, 5.0f)); - delete root; -} - -QTEST_APPLESS_MAIN(tst_QGLSphere) - -#include "tst_qglsphere.moc" diff --git a/tests/auto/threed/qglvertexbundle/qglvertexbundle.pro b/tests/auto/threed/qglvertexbundle/qglvertexbundle.pro deleted file mode 100644 index 89cf0f17..00000000 --- a/tests/auto/threed/qglvertexbundle/qglvertexbundle.pro +++ /dev/null @@ -1,6 +0,0 @@ -load(qttest_p4.prf) -TEMPLATE=app -QT += testlib -CONFIG += unittest warn_on qt3d - -SOURCES += tst_qglvertexbundle.cpp diff --git a/tests/auto/threed/qglvertexbundle/tst_qglvertexbundle.cpp b/tests/auto/threed/qglvertexbundle/tst_qglvertexbundle.cpp deleted file mode 100644 index 07965914..00000000 --- a/tests/auto/threed/qglvertexbundle/tst_qglvertexbundle.cpp +++ /dev/null @@ -1,282 +0,0 @@ -/**************************************************************************** -** -** 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 QtQuick3D module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** 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. -** -** 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. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include <QtTest/QtTest> -#include <QtOpenGL/qgl.h> -#include "qglvertexbundle.h" -#include "qvector2darray.h" -#include "qvector3darray.h" -#include "qvector4darray.h" -#include "qcolor4ub.h" - -class tst_QGLVertexBundle : public QObject -{ - Q_OBJECT -public: - tst_QGLVertexBundle() {} - ~tst_QGLVertexBundle() {} - -private slots: - void interleaved(); - void singleAttribute(); - void large(); - void otherAttributes(); -}; - -void tst_QGLVertexBundle::interleaved() -{ - // Interleave 4 positions and texture co-ordinates, which will - // result in the numbers 1..20 ending up in the GL server's buffer. - QVector3DArray positions; - positions.append(1.0f, 2.0f, 3.0f); - positions.append(6.0f, 7.0f, 8.0f); - positions.append(11.0f, 12.0f, 13.0f); - positions.append(16.0f, 17.0f, 18.0f); - - QVector2DArray texCoords; - texCoords.append(4.0f, 5.0f); - texCoords.append(9.0f, 10.0f); - texCoords.append(14.0f, 15.0f); - texCoords.append(19.0f, 20.0f); - - QGLVertexBundle bundle; - - // Cannot upload an empty bundle. - QVERIFY(!bundle.upload()); - - QVERIFY(bundle.attributes().isEmpty()); - - bundle.addAttribute(QGL::Position, positions); - bundle.addAttribute(QGL::TextureCoord0, texCoords); - - QGLAttributeSet set = bundle.attributes(); - QVERIFY(set.contains(QGL::Position)); - QVERIFY(set.contains(QGL::TextureCoord0)); - QVERIFY(!set.contains(QGL::TextureCoord1)); - - QVERIFY(!bundle.isUploaded()); - QCOMPARE(bundle.vertexCount(), 4); - - // Create a context to upload into. We populate the QGLVertexBundle - // with data before doing this to ensure that the client-side part of - // the buffers can be created at application startup time before an - // actual OpenGL context exists. - QGLWidget glw; - glw.makeCurrent(); - - // Upload the bundle and bail out if we couldn't upload it - // (i.e. vertex buffers are not supported in the GL server). - if (!bundle.upload()) { - QVERIFY(!bundle.isUploaded()); - return; - } - QVERIFY(bundle.isUploaded()); - - // Uploading again should do nothing - just succeed. - QVERIFY(bundle.upload()); - - // Verify the contents of the buffer in the GL server if we can map it. - QVERIFY(bundle.bind()); - QCOMPARE(bundle.buffer().size(), int(sizeof(float) * 20)); - float *mapped = reinterpret_cast<float *> - (bundle.buffer().map(QGLBuffer::ReadOnly)); - if (mapped) { - for (int index = 0; index < 20; ++index) - QCOMPARE(mapped[index], float(index + 1)); - } - bundle.release(); - - // Make copies of the bundle, to test ref-counting. - QGLVertexBundle bundle2(bundle); - QGLVertexBundle bundle3; - QCOMPARE(bundle2.buffer().bufferId(), bundle.buffer().bufferId()); - QVERIFY(!bundle3.buffer().bufferId()); - bundle3 = bundle; - QCOMPARE(bundle3.buffer().bufferId(), bundle.buffer().bufferId()); -} - -// Single attribute uploads take a quicker path, which this function tests. -void tst_QGLVertexBundle::singleAttribute() -{ - QVector3DArray positions; - positions.append(1.0f, 2.0f, 3.0f); - positions.append(4.0f, 5.0f, 6.0f); - positions.append(7.0f, 8.0f, 9.0f); - positions.append(10.0f, 11.0f, 12.0f); - - QGLVertexBundle bundle; - bundle.addAttribute(QGL::Position, positions); - - QVERIFY(!bundle.isUploaded()); - QCOMPARE(bundle.vertexCount(), 4); - - QGLWidget glw; - glw.makeCurrent(); - - if (!bundle.upload()) { - QVERIFY(!bundle.isUploaded()); - return; - } - QVERIFY(bundle.isUploaded()); - - QVERIFY(bundle.bind()); - QCOMPARE(bundle.buffer().size(), int(sizeof(float) * 12)); - float *mapped = reinterpret_cast<float *> - (bundle.buffer().map(QGLBuffer::ReadOnly)); - if (mapped) { - for (int index = 0; index < 12; ++index) - QCOMPARE(mapped[index], float(index + 1)); - } - bundle.release(); -} - -void tst_QGLVertexBundle::large() -{ - QVector3DArray positions; - QVector2DArray texCoords; - for (int index = 0; index < 2048; ++index) { - positions.append(index * 5, index * 5 + 1, index * 5 + 2); - texCoords.append(index * 5 + 3, index * 5 + 4); - } - QGLWidget glw; - glw.makeCurrent(); - QGLVertexBundle bundle; - bundle.addAttribute(QGL::Position, positions); - bundle.addAttribute(QGL::TextureCoord0, texCoords); - if (!bundle.upload()) { - QVERIFY(!bundle.isUploaded()); - return; - } - QCOMPARE(bundle.vertexCount(), 2048); - QVERIFY(bundle.bind()); - QCOMPARE(bundle.buffer().size(), int(sizeof(float) * 2048 * 5)); - float *mapped = reinterpret_cast<float *> - (bundle.buffer().map(QGLBuffer::ReadOnly)); - if (mapped) { - for (int index = 0; index < 2048 * 5; ++index) - QCOMPARE(mapped[index], float(index)); - } - bundle.release(); -} - -void tst_QGLVertexBundle::otherAttributes() -{ - QVector4DArray positions; - positions.append(1.0f, 2.0f, 3.0f, 4.0f); - positions.append(6.0f, 7.0f, 8.0f, 9.0f); - positions.append(11.0f, 12.0f, 13.0f, 14.0f); - positions.append(16.0f, 17.0f, 18.0f, 19.0f); - - QArray<float> texCoords; - texCoords.append(5.0f); - texCoords.append(10.0f); - texCoords.append(15.0f); - texCoords.append(20.0f); - - QGLWidget glw; - glw.makeCurrent(); - - QGLVertexBundle bundle; - bundle.addAttribute(QGL::Position, positions); - bundle.addAttribute(QGL::TextureCoord0, texCoords); - if (!bundle.upload()) { - QVERIFY(!bundle.isUploaded()); - return; - } - QCOMPARE(bundle.vertexCount(), 4); - QVERIFY(bundle.bind()); - QCOMPARE(bundle.buffer().size(), int(sizeof(float) * 20)); - float *mapped = reinterpret_cast<float *> - (bundle.buffer().map(QGLBuffer::ReadOnly)); - if (mapped) { - for (int index = 0; index < 20; ++index) - QCOMPARE(mapped[index], float(index + 1)); - } - bundle.release(); - - bundle = QGLVertexBundle(); - QVERIFY(!bundle.isUploaded()); - - QArray<QColor4ub> colors; - for (int index = 0; index < 64; ++index) { - colors.append(QColor4ub(index * 4, index * 4 + 1, - index * 4 + 2, index * 4 + 3)); - } - bundle.addAttribute(QGL::Color, colors); - if (!bundle.upload()) { - QVERIFY(!bundle.isUploaded()); - return; - } - QCOMPARE(bundle.vertexCount(), 64); - QVERIFY(bundle.bind()); - QCOMPARE(bundle.buffer().size(), int(sizeof(uchar) * 256)); - uchar *mapuchar = reinterpret_cast<uchar *> - (bundle.buffer().map(QGLBuffer::ReadOnly)); - if (mapuchar) { - for (int index = 0; index < 256; ++index) - QCOMPARE(mapuchar[index], uchar(index)); - } - bundle.release(); - - bundle = QGLVertexBundle(); - QVERIFY(!bundle.isUploaded()); - - QCustomDataArray custom(texCoords); - bundle.addAttribute(QGL::TextureCoord1, custom); - if (!bundle.upload()) { - QVERIFY(!bundle.isUploaded()); - return; - } - QCOMPARE(bundle.vertexCount(), 4); - QVERIFY(bundle.bind()); - QCOMPARE(bundle.buffer().size(), int(sizeof(float) * 4)); - mapped = reinterpret_cast<float *> - (bundle.buffer().map(QGLBuffer::ReadOnly)); - if (mapped) { - for (int index = 0; index < 4; ++index) - QCOMPARE(mapped[index], float((index + 1) * 5)); - } - bundle.release(); -} - -QTEST_MAIN(tst_QGLVertexBundle) - -#include "tst_qglvertexbundle.moc" diff --git a/tests/auto/threed/qgraphicstransform3d/qgraphicstransform3d.pro b/tests/auto/threed/qgraphicstransform3d/qgraphicstransform3d.pro deleted file mode 100644 index 4cc0791c..00000000 --- a/tests/auto/threed/qgraphicstransform3d/qgraphicstransform3d.pro +++ /dev/null @@ -1,6 +0,0 @@ -load(qttest_p4.prf) -TEMPLATE=app -QT += testlib -CONFIG += unittest warn_on qt3d - -SOURCES += tst_qgraphicstransform3d.cpp diff --git a/tests/auto/threed/qgraphicstransform3d/tst_qgraphicstransform3d.cpp b/tests/auto/threed/qgraphicstransform3d/tst_qgraphicstransform3d.cpp deleted file mode 100644 index 2f42a202..00000000 --- a/tests/auto/threed/qgraphicstransform3d/tst_qgraphicstransform3d.cpp +++ /dev/null @@ -1,280 +0,0 @@ -/**************************************************************************** -** -** 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 QtQuick3D module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** 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. -** -** 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. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include <QtTest/QtTest> -#include "qgraphicsrotation3d.h" -#include "qgraphicsscale3d.h" -#include "qgraphicstranslation3d.h" -#include "qgraphicsbillboardtransform.h" - -class tst_QGraphicsTransform3D : public QObject -{ - Q_OBJECT -public: - tst_QGraphicsTransform3D() {} - ~tst_QGraphicsTransform3D() {} - -private slots: - void rotation3D(); - void scale3D(); - void translation3D(); - void billboard(); -}; - -static bool isSameMatrix(const QMatrix4x4 &m1, const QMatrix4x4 &m2) -{ - for (int row = 0; row < 4; ++row) { - for (int col = 0; col < 4; ++col) { - if (!qFuzzyIsNull(float(m1(row, col) - m2(row, col)))) - return false; - } - } - return true; -} - -void tst_QGraphicsTransform3D::rotation3D() -{ - QGraphicsRotation3D rot1; - QVERIFY(rot1.origin() == QVector3D(0, 0, 0)); - QVERIFY(rot1.axis() == QVector3D(0, 0, 1)); - QCOMPARE(rot1.angle(), qreal(0.0f)); - - QSignalSpy spy1(&rot1, SIGNAL(originChanged())); - QSignalSpy spy2(&rot1, SIGNAL(axisChanged())); - QSignalSpy spy3(&rot1, SIGNAL(angleChanged())); - QSignalSpy spy4(&rot1, SIGNAL(transformChanged())); - - rot1.setOrigin(QVector3D(1, 2, 3)); - rot1.setAxis(QVector3D(4, -5, 6)); - rot1.setAngle(45.0f); - QVERIFY(rot1.origin() == QVector3D(1, 2, 3)); - QVERIFY(rot1.axis() == QVector3D(4, -5, 6)); - QCOMPARE(rot1.angle(), qreal(45.0f)); - - QCOMPARE(spy1.size(), 1); - QCOMPARE(spy2.size(), 1); - QCOMPARE(spy3.size(), 1); - QCOMPARE(spy4.size(), 3); - - // Change to same values should not result in any extra signals. - rot1.setOrigin(QVector3D(1, 2, 3)); - rot1.setAxis(QVector3D(4, -5, 6)); - rot1.setAngle(45.0f); - QCOMPARE(spy1.size(), 1); - QCOMPARE(spy2.size(), 1); - QCOMPARE(spy3.size(), 1); - QCOMPARE(spy4.size(), 3); - - QMatrix4x4 m1; - rot1.applyTo(&m1); - - QMatrix4x4 m2; - m2.translate(1, 2, 3); - m2.rotate(45.0f, QVector3D(4, -5, 6)); - m2.translate(-1, -2, -3); - QVERIFY(isSameMatrix(m1, m2)); - - QGraphicsRotation3D *rot2 = qobject_cast<QGraphicsRotation3D *> - (rot1.clone(this)); - QVERIFY(rot2 != 0); - QVERIFY(rot2 != &rot1); - QVERIFY(rot2->parent() == this); - QVERIFY(rot2->origin() == rot1.origin()); - QVERIFY(rot2->axis() == rot1.axis()); - QVERIFY(rot2->angle() == rot1.angle()); - delete rot2; -} - -void tst_QGraphicsTransform3D::scale3D() -{ - QGraphicsScale3D scale1; - QVERIFY(scale1.origin() == QVector3D(0, 0, 0)); - QVERIFY(scale1.scale() == QVector3D(1, 1, 1)); - - QSignalSpy spy1(&scale1, SIGNAL(originChanged())); - QSignalSpy spy2(&scale1, SIGNAL(scaleChanged())); - QSignalSpy spy3(&scale1, SIGNAL(transformChanged())); - - scale1.setOrigin(QVector3D(1, 2, 3)); - scale1.setScale(QVector3D(4, -6, 0.5f)); - QVERIFY(scale1.origin() == QVector3D(1, 2, 3)); - QVERIFY(scale1.scale() == QVector3D(4, -6, 0.5f)); - - QCOMPARE(spy1.size(), 1); - QCOMPARE(spy2.size(), 1); - QCOMPARE(spy3.size(), 2); - - // Change to same values should not result in any extra signals. - scale1.setOrigin(QVector3D(1, 2, 3)); - scale1.setScale(QVector3D(4, -6, 0.5f)); - QCOMPARE(spy1.size(), 1); - QCOMPARE(spy2.size(), 1); - QCOMPARE(spy3.size(), 2); - - QMatrix4x4 m1; - scale1.applyTo(&m1); - - QMatrix4x4 m2; - m2.translate(1, 2, 3); - m2.scale(QVector3D(4, -6, 0.5f)); - m2.translate(-1, -2, -3); - QVERIFY(isSameMatrix(m1, m2)); - - scale1.setScale(QVector3D(20, -4, 42)); - QCOMPARE(spy2.size(), 2); - QCOMPARE(spy3.size(), 3); - - QVERIFY(scale1.scale() == QVector3D(20, -4, 42)); - - QVERIFY(scale1.origin() == QVector3D(1, 2, 3)); - QCOMPARE(spy1.size(), 1); - - QGraphicsScale3D *scale2 = qobject_cast<QGraphicsScale3D *> - (scale1.clone(this)); - QVERIFY(scale2 != 0); - QVERIFY(scale2 != &scale1); - QVERIFY(scale2->parent() == this); - QVERIFY(scale2->origin() == scale1.origin()); - QVERIFY(scale2->scale() == scale1.scale()); - delete scale2; -} - -void tst_QGraphicsTransform3D::translation3D() -{ - QGraphicsTranslation3D translate1; - QVERIFY(translate1.translate() == QVector3D(0, 0, 0)); - QCOMPARE(translate1.progress(), qreal(1.0f)); - - QSignalSpy spy1(&translate1, SIGNAL(translateChanged())); - QSignalSpy spy2(&translate1, SIGNAL(progressChanged())); - QSignalSpy spy3(&translate1, SIGNAL(transformChanged())); - - translate1.setTranslate(QVector3D(4, -6, 0.5f)); - translate1.setProgress(2.0f); - QVERIFY(translate1.translate() == QVector3D(4, -6, 0.5f)); - QCOMPARE(translate1.progress(), qreal(2.0f)); - - QCOMPARE(spy1.size(), 1); - QCOMPARE(spy2.size(), 1); - QCOMPARE(spy3.size(), 2); - - // Change to same values should not result in any extra signals. - translate1.setTranslate(QVector3D(4, -6, 0.5f)); - translate1.setProgress(2.0f); - QCOMPARE(spy1.size(), 1); - QCOMPARE(spy2.size(), 1); - QCOMPARE(spy3.size(), 2); - - QMatrix4x4 m1; - translate1.applyTo(&m1); - - QMatrix4x4 m2; - m2.translate(QVector3D(8, -12, 1)); - QVERIFY(isSameMatrix(m1, m2)); - - QGraphicsTranslation3D *translate2 = qobject_cast<QGraphicsTranslation3D *> - (translate1.clone(this)); - QVERIFY(translate2 != 0); - QVERIFY(translate2 != &translate1); - QVERIFY(translate2->parent() == this); - QVERIFY(translate2->translate() == translate1.translate()); - QVERIFY(translate2->progress() == translate1.progress()); - delete translate2; -} - -void tst_QGraphicsTransform3D::billboard() -{ - QGraphicsBillboardTransform billboard1; - QVERIFY(!billboard1.preserveUpVector()); - - QSignalSpy spy1(&billboard1, SIGNAL(preserveUpVectorChanged())); - QSignalSpy spy2(&billboard1, SIGNAL(transformChanged())); - - billboard1.setPreserveUpVector(true); - QVERIFY(billboard1.preserveUpVector()); - - QCOMPARE(spy1.size(), 1); - QCOMPARE(spy2.size(), 1); - - // Change to same value should not result in any extra signals. - billboard1.setPreserveUpVector(true); - QCOMPARE(spy1.size(), 1); - QCOMPARE(spy2.size(), 1); - - QMatrix4x4 m1; - billboard1.applyTo(&m1); - QVERIFY(m1.isIdentity()); - - QMatrix4x4 m2(2.0f, 3.0f, 4.0f, 5.0f, - 6.0f, 7.0f, 8.0f, 9.0f, - 10.0f, 11.0f, 12.0f, 13.0f, - 14.0f, 15.0f, 16.0f, 17.0f); - QMatrix4x4 m3(1.0f, 0.0f, 0.0f, 5.0f, - 0.0f, 1.0f, 0.0f, 9.0f, - 0.0f, 0.0f, 1.0f, 13.0f, - 14.0f, 15.0f, 16.0f, 17.0f); - QMatrix4x4 m4(1.0f, 3.0f, 0.0f, 5.0f, - 0.0f, 7.0f, 0.0f, 9.0f, - 0.0f, 11.0f, 1.0f, 13.0f, - 14.0f, 15.0f, 16.0f, 17.0f); - - QMatrix4x4 m5(m2); - billboard1.setPreserveUpVector(false); - billboard1.applyTo(&m5); - QVERIFY(m5 == m3); - - QMatrix4x4 m6(m2); - billboard1.setPreserveUpVector(true); - billboard1.applyTo(&m6); - QVERIFY(m6 == m4); - - QGraphicsBillboardTransform *billboard2 = qobject_cast<QGraphicsBillboardTransform *> - (billboard1.clone(this)); - QVERIFY(billboard2 != 0); - QVERIFY(billboard2 != &billboard1); - QVERIFY(billboard2->parent() == this); - QVERIFY(billboard2->preserveUpVector() == billboard1.preserveUpVector()); - delete billboard2; -} - -QTEST_APPLESS_MAIN(tst_QGraphicsTransform3D) - -#include "tst_qgraphicstransform3d.moc" diff --git a/tests/auto/threed/qopenglfunctions/qopenglfunctions.pro b/tests/auto/threed/qopenglfunctions/qopenglfunctions.pro deleted file mode 100644 index c830ff37..00000000 --- a/tests/auto/threed/qopenglfunctions/qopenglfunctions.pro +++ /dev/null @@ -1,6 +0,0 @@ -load(qttest_p4.prf) -TEMPLATE=app -QT += testlib -CONFIG += unittest warn_on qt3d - -SOURCES += tst_qopenglfunctions.cpp diff --git a/tests/auto/threed/qopenglfunctions/tst_qopenglfunctions.cpp b/tests/auto/threed/qopenglfunctions/tst_qopenglfunctions.cpp deleted file mode 100644 index 0ef53909..00000000 --- a/tests/auto/threed/qopenglfunctions/tst_qopenglfunctions.cpp +++ /dev/null @@ -1,245 +0,0 @@ -/**************************************************************************** -** -** 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 QtQuick3D module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** 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. -** -** 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. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include <QtTest/QtTest> -#include "qopenglfunctions.h" - -class tst_QOpenGLFunctions : public QObject -{ - Q_OBJECT -public: - tst_QOpenGLFunctions() {} - ~tst_QOpenGLFunctions() {} - -private slots: - void features(); - void multitexture(); - void blendColor(); - -private: - static bool hasExtension(const char *name); -}; - -bool tst_QOpenGLFunctions::hasExtension(const char *name) -{ - QString extensions = - QString::fromLatin1 - (reinterpret_cast<const char *>(glGetString(GL_EXTENSIONS))); - return extensions.split(QLatin1Char(' ')).contains - (QString::fromLatin1(name)); -} - -// Check that the reported features are consistent with the platform. -void tst_QOpenGLFunctions::features() -{ - // Before being associated with a context, there should be - // no features enabled. - QOpenGLFunctions funcs; - QVERIFY(!funcs.openGLFeatures()); - QVERIFY(!funcs.hasOpenGLFeature(QOpenGLFunctions::Multitexture)); - QVERIFY(!funcs.hasOpenGLFeature(QOpenGLFunctions::Shaders)); - QVERIFY(!funcs.hasOpenGLFeature(QOpenGLFunctions::Buffers)); - QVERIFY(!funcs.hasOpenGLFeature(QOpenGLFunctions::Framebuffers)); - QVERIFY(!funcs.hasOpenGLFeature(QOpenGLFunctions::BlendColor)); - QVERIFY(!funcs.hasOpenGLFeature(QOpenGLFunctions::BlendEquation)); - QVERIFY(!funcs.hasOpenGLFeature(QOpenGLFunctions::BlendEquationSeparate)); - QVERIFY(!funcs.hasOpenGLFeature(QOpenGLFunctions::BlendFuncSeparate)); - QVERIFY(!funcs.hasOpenGLFeature(QOpenGLFunctions::BlendSubtract)); - QVERIFY(!funcs.hasOpenGLFeature(QOpenGLFunctions::CompressedTextures)); - QVERIFY(!funcs.hasOpenGLFeature(QOpenGLFunctions::Multisample)); - QVERIFY(!funcs.hasOpenGLFeature(QOpenGLFunctions::StencilSeparate)); - QVERIFY(!funcs.hasOpenGLFeature(QOpenGLFunctions::NPOTTextures)); - - // Make a context current. - QGLWidget glw; - if (!glw.isValid()) - QSKIP("GL Implementation not valid", SkipSingle); - - glw.makeCurrent(); - funcs.initializeGLFunctions(); - - // Validate the features against what we expect for this platform. -#if defined(QT_OPENGL_ES_2) - QOpenGLFunctions::OpenGLFeatures allFeatures = - (QOpenGLFunctions::Multitexture | - QOpenGLFunctions::Shaders | - QOpenGLFunctions::Buffers | - QOpenGLFunctions::Framebuffers | - QOpenGLFunctions::BlendColor | - QOpenGLFunctions::BlendEquation | - QOpenGLFunctions::BlendEquationSeparate | - QOpenGLFunctions::BlendFuncSeparate | - QOpenGLFunctions::BlendSubtract | - QOpenGLFunctions::CompressedTextures | - QOpenGLFunctions::Multisample | - QOpenGLFunctions::StencilSeparate | - QOpenGLFunctions::NPOTTextures); - QVERIFY((funcs.openGLFeatures() & allFeatures) == allFeatures); - QVERIFY(funcs.hasOpenGLFeature(QOpenGLFunctions::Multitexture)); - QVERIFY(funcs.hasOpenGLFeature(QOpenGLFunctions::Shaders)); - QVERIFY(funcs.hasOpenGLFeature(QOpenGLFunctions::Buffers)); - QVERIFY(funcs.hasOpenGLFeature(QOpenGLFunctions::Framebuffers)); - QVERIFY(funcs.hasOpenGLFeature(QOpenGLFunctions::BlendColor)); - QVERIFY(funcs.hasOpenGLFeature(QOpenGLFunctions::BlendEquation)); - QVERIFY(funcs.hasOpenGLFeature(QOpenGLFunctions::BlendEquationSeparate)); - QVERIFY(funcs.hasOpenGLFeature(QOpenGLFunctions::BlendFuncSeparate)); - QVERIFY(funcs.hasOpenGLFeature(QOpenGLFunctions::BlendSubtract)); - QVERIFY(funcs.hasOpenGLFeature(QOpenGLFunctions::CompressedTextures)); - QVERIFY(funcs.hasOpenGLFeature(QOpenGLFunctions::Multisample)); - QVERIFY(funcs.hasOpenGLFeature(QOpenGLFunctions::StencilSeparate)); - QVERIFY(funcs.hasOpenGLFeature(QOpenGLFunctions::NPOTTextures)); -#elif defined(QT_OPENGL_ES) - QVERIFY(funcs.hasOpenGLFeature(QOpenGLFunctions::Multitexture)); - QVERIFY(funcs.hasOpenGLFeature(QOpenGLFunctions::Buffers)); - QVERIFY(funcs.hasOpenGLFeature(QOpenGLFunctions::CompressedTextures)); - QVERIFY(funcs.hasOpenGLFeature(QOpenGLFunctions::Multisample)); - - QVERIFY(!funcs.hasOpenGLFeature(QOpenGLFunctions::Shaders)); - QVERIFY(!funcs.hasOpenGLFeature(QOpenGLFunctions::BlendColor)); - QVERIFY(!funcs.hasOpenGLFeature(QOpenGLFunctions::StencilSeparate)); - - QCOMPARE(funcs.hasOpenGLFeature(QOpenGLFunctions::Framebuffers), - hasExtension("GL_OES_framebuffer_object")); - QCOMPARE(funcs.hasOpenGLFeature(QOpenGLFunctions::BlendEquationSeparate), - hasExtension("GL_OES_blend_equation_separate")); - QCOMPARE(funcs.hasOpenGLFeature(QOpenGLFunctions::BlendFuncSeparate), - hasExtension("GL_OES_blend_func_separate")); - QCOMPARE(funcs.hasOpenGLFeature(QOpenGLFunctions::BlendSubtract), - hasExtension("GL_OES_blend_subtract")); - QCOMPARE(funcs.hasOpenGLFeature(QOpenGLFunctions::NPOTTextures), - hasExtension("GL_OES_texture_npot")); -#else - // We check for both the extension name and the minimum OpenGL version - // for the feature. This will help us catch situations where a platform - // doesn't list an extension by name but does have the feature by virtue - // of its version number. - QGLFormat::OpenGLVersionFlags versions = QGLFormat::openGLVersionFlags(); - QCOMPARE(funcs.hasOpenGLFeature(QOpenGLFunctions::Multitexture), - hasExtension("GL_ARB_multitexture") || - (versions & QGLFormat::OpenGL_Version_1_3) != 0); - QCOMPARE(funcs.hasOpenGLFeature(QOpenGLFunctions::Shaders), - hasExtension("GL_ARB_shader_objects") || - (versions & QGLFormat::OpenGL_Version_2_0) != 0); - QCOMPARE(funcs.hasOpenGLFeature(QOpenGLFunctions::Buffers), - (versions & QGLFormat::OpenGL_Version_1_5) != 0); - QCOMPARE(funcs.hasOpenGLFeature(QOpenGLFunctions::Framebuffers), - hasExtension("GL_EXT_framebuffer_object") || - hasExtension("GL_ARB_framebuffer_object")); - QCOMPARE(funcs.hasOpenGLFeature(QOpenGLFunctions::BlendColor), - hasExtension("GL_EXT_blend_color") || - (versions & QGLFormat::OpenGL_Version_1_2) != 0); - QCOMPARE(funcs.hasOpenGLFeature(QOpenGLFunctions::BlendEquation), - (versions & QGLFormat::OpenGL_Version_1_2) != 0); - QCOMPARE(funcs.hasOpenGLFeature(QOpenGLFunctions::BlendEquationSeparate), - hasExtension("GL_EXT_blend_equation_separate") || - (versions & QGLFormat::OpenGL_Version_2_0) != 0); - QCOMPARE(funcs.hasOpenGLFeature(QOpenGLFunctions::BlendFuncSeparate), - hasExtension("GL_EXT_blend_func_separate") || - (versions & QGLFormat::OpenGL_Version_1_4) != 0); - QCOMPARE(funcs.hasOpenGLFeature(QOpenGLFunctions::BlendSubtract), - hasExtension("GL_EXT_blend_subtract")); - QCOMPARE(funcs.hasOpenGLFeature(QOpenGLFunctions::CompressedTextures), - hasExtension("GL_ARB_texture_compression") || - (versions & QGLFormat::OpenGL_Version_1_3) != 0); - QCOMPARE(funcs.hasOpenGLFeature(QOpenGLFunctions::Multisample), - hasExtension("GL_ARB_multisample") || - (versions & QGLFormat::OpenGL_Version_1_3) != 0); - QCOMPARE(funcs.hasOpenGLFeature(QOpenGLFunctions::StencilSeparate), - (versions & QGLFormat::OpenGL_Version_2_0) != 0); - QCOMPARE(funcs.hasOpenGLFeature(QOpenGLFunctions::NPOTTextures), - hasExtension("GL_ARB_texture_non_power_of_two") || - (versions & QGLFormat::OpenGL_Version_2_0) != 0); -#endif -} - -// Verify that the multitexture functions appear to resolve and work. -void tst_QOpenGLFunctions::multitexture() -{ - QOpenGLFunctions funcs; - QGLWidget glw; - if (!glw.isValid()) - QSKIP("GL Implementation not valid", SkipSingle); - glw.makeCurrent(); - funcs.initializeGLFunctions(); - - if (!funcs.hasOpenGLFeature(QOpenGLFunctions::Multitexture)) - QSKIP("Multitexture functions are not supported", SkipSingle); - - funcs.glActiveTexture(GL_TEXTURE1); - - GLint active = 0; - glGetIntegerv(GL_ACTIVE_TEXTURE, &active); - QVERIFY(active == GL_TEXTURE1); - - funcs.glActiveTexture(GL_TEXTURE0); - - active = 0; - glGetIntegerv(GL_ACTIVE_TEXTURE, &active); - QVERIFY(active == GL_TEXTURE0); -} - -// Verify that the glBlendColor() function appears to resolve and work. -void tst_QOpenGLFunctions::blendColor() -{ - QOpenGLFunctions funcs; - QGLWidget glw; - if (!glw.isValid()) - QSKIP("GL Implementation not valid", SkipSingle); - glw.makeCurrent(); - funcs.initializeGLFunctions(); - - if (!funcs.hasOpenGLFeature(QOpenGLFunctions::BlendColor)) - QSKIP("glBlendColor() is not supported", SkipSingle); - - funcs.glBlendColor(0.0f, 1.0f, 0.0f, 1.0f); - - GLfloat colors[4] = {0.5f, 0.5f, 0.5f, 0.5f}; - glGetFloatv(GL_BLEND_COLOR, colors); - - QCOMPARE(colors[0], 0.0f); - QCOMPARE(colors[1], 1.0f); - QCOMPARE(colors[2], 0.0f); - QCOMPARE(colors[3], 1.0f); -} - -QTEST_MAIN(tst_QOpenGLFunctions) - -#include "tst_qopenglfunctions.moc" diff --git a/tests/auto/threed/qplane3d/qplane3d.pro b/tests/auto/threed/qplane3d/qplane3d.pro deleted file mode 100644 index 008251ec..00000000 --- a/tests/auto/threed/qplane3d/qplane3d.pro +++ /dev/null @@ -1,6 +0,0 @@ -load(qttest_p4.prf) -TEMPLATE=app -QT += testlib -CONFIG += unittest warn_on qt3d - -SOURCES += tst_qplane3d.cpp diff --git a/tests/auto/threed/qplane3d/tst_qplane3d.cpp b/tests/auto/threed/qplane3d/tst_qplane3d.cpp deleted file mode 100644 index 17f14164..00000000 --- a/tests/auto/threed/qplane3d/tst_qplane3d.cpp +++ /dev/null @@ -1,450 +0,0 @@ -/**************************************************************************** -** -** 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 QtQuick3D module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** 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. -** -** 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. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include <QtTest/QtTest> - -#include "qplane3d.h" -#include "qray3d.h" - -class tst_QPlane3D : public QObject -{ - Q_OBJECT -public: - tst_QPlane3D() {} - ~tst_QPlane3D() {} - -private slots: - void create_data(); - void create(); - void intersection_data(); - void intersection(); - void noIntersection_data(); - void noIntersection(); - void contains_data(); - void contains(); - void distanceTo_data(); - void distanceTo(); - void compare(); - void transform_data(); - void transform(); - void dataStream(); - void properties(); - void metaTypes(); -}; - -// since all calculations involved QVector3D are producing values with only -// float precision those calculations can at best be float precision -// if you assign the results of the calculation to a qreal then qFuzzyCompare -// will quite happily use a much higher standard of precision than it is -// possible to acheive - hence redefine it here to always use the float -// Also while on the job fix the problem where a compared value happens -// to be zero (and you cannot always predict this, and should not predict it -// since then you produce self-fulling prophecies instead of tests). -// In that case qFuzzyCompare has a completely strict criterion since -// it finds the "fudge factor" by multiplying by zero... -static inline bool fuzzyCompare(qreal p1, qreal p2) -{ - float fac = qMin(qAbs(p1), qAbs(p2)); - return (qAbs(p1 - p2) <= (qIsNull(fac) ? 0.00001f : 0.00001f * fac)); -} - -static inline bool fuzzyCompare(const QVector3D &lhs, const QVector3D &rhs) -{ - if (fuzzyCompare(lhs.x(), rhs.x()) && - fuzzyCompare(lhs.y(), rhs.y()) && - fuzzyCompare(lhs.z(), rhs.z())) - return true; -#ifndef QT_NO_DEBUG_STREAM - qWarning() << "actual:" << lhs; - qWarning() << "expected:" << rhs; -#endif - return false; -} - -static inline bool fuzzyIsNull(const QVector3D &v) -{ - return fuzzyCompare(v.x(), 0.0f) && - fuzzyCompare(v.y(), 0.0f) && - fuzzyCompare(v.z(), 0.0f); -} - -void tst_QPlane3D::create_data() -{ - QTest::addColumn<QVector3D>("point"); - QTest::addColumn<QVector3D>("normal"); - - // normalized vectors for the normals. - QTest::newRow("line on x-axis from origin") - << QVector3D() - << QVector3D(1.0f, 0.0f, 0.0f); - - QTest::newRow("line paralell -z-axis from 3,3,3") - << QVector3D(3.0f, 3.0f, 3.0f) - << QVector3D(0.0f, 0.0f, -1.0f); - - QTest::newRow("vertical line (paralell to y-axis)") - << QVector3D(0.5f, 0.0f, 0.5f) - << QVector3D(0.0f, 1.0f, 0.0f); - - QTest::newRow("equidistant from all 3 axes") - << QVector3D(0.5f, 0.0f, 0.5f) - << QVector3D(0.57735026919f, 0.57735026919f, 0.57735026919f); - - // Unnormalized vectors for the normals. - QTest::newRow("line on x-axis from origin") - << QVector3D() - << QVector3D(2.0f, 0.0f, 0.0f); - - QTest::newRow("line paralell -z-axis from 3,3,3") - << QVector3D(3.0f, 3.0f, 3.0f) - << QVector3D(0.0f, 0.0f, -0.7f); - - QTest::newRow("vertical line (paralell to y-axis)") - << QVector3D(0.5f, 0.0f, 0.5f) - << QVector3D(0.0f, 5.3f, 0.0f); - - QTest::newRow("equidistant from all 3 axes") - << QVector3D(0.5f, 0.0f, 0.5f) - << QVector3D(1.0f, 1.0f, 1.0f); - - QTest::newRow("negative direction") - << QVector3D(-3.0f, -3.0f, -3.0f) - << QVector3D(-1.2f, -1.8f, -2.4f); -} - -void tst_QPlane3D::create() -{ - QFETCH(QVector3D, point); - QFETCH(QVector3D, normal); - QPlane3D plane(point, normal); - QVERIFY(fuzzyCompare(plane.normal(), normal)); - QVERIFY(fuzzyCompare(plane.origin(), point)); - - QPlane3D plane2; - QVERIFY(plane2.origin() == QVector3D(0, 0, 0)); - QVERIFY(plane2.normal() == QVector3D(1, 0, 0)); - plane2.setOrigin(point); - plane2.setNormal(normal); - QVERIFY(fuzzyCompare(plane2.normal(), normal)); - QVERIFY(fuzzyCompare(plane2.origin(), point)); -} - -void tst_QPlane3D::intersection_data() -{ - // Line - QTest::addColumn<QVector3D>("point1"); - QTest::addColumn<QVector3D>("direction"); - - // Plane - QTest::addColumn<QVector3D>("point2"); - QTest::addColumn<QVector3D>("normal"); - - // Resulting intersection - QTest::addColumn<QVector3D>("intersection"); - - // These direction vectors will get normalized - QTest::newRow("line on x-axis, plane in z-y") - << QVector3D() - << QVector3D(2.0f, 0.0f, 0.0f) - << QVector3D(4.0f, 1.0f, 1.0f) - << QVector3D(1.0f, 0.0f, 0.0f) - << QVector3D(4.0f, 0.0f, 0.0f); - - QTest::newRow("line -z-axis, plane in x-y") - << QVector3D(3.0f, 3.0f, 3.0f) - << QVector3D(0.0f, 0.0f, -0.7f) - << QVector3D(1.0f, 1.0f, -2.4f) - << QVector3D(0.0f, 0.0f, -1.0f) - << QVector3D(3.0f, 3.0f, -2.4f); - - QTest::newRow("line y-axis, plane in x-z") - << QVector3D(0.5f, 0.0f, 0.5f) - << QVector3D(0.0f, 5.3f, 0.0f) - << QVector3D(1.5f, 0.6f, 1.5f) - << QVector3D(0.0f, -7.2f, 0.0f) - << QVector3D(0.5f, 0.6f, 0.5f); - - QTest::newRow("line equidistant from axes, plane in y-z") - << QVector3D(0.5f, 0.0f, 0.5f) - << QVector3D(1.0f, 1.0f, 1.0f) - << QVector3D(5.0f, 3.0f, 3.0f) - << QVector3D(1.0f, 1.0f, 1.0f) - << QVector3D(3.8333332539f, 3.3333332539f, 3.8333332539f); - - QTest::newRow("negative direction") - << QVector3D(-3.0f, -3.0f, -3.0f) - << QVector3D(-1.2f, -1.8f, -2.4f) - << QVector3D(5.0f, 3.0f, 3.0f) - << QVector3D(1.0f, 1.0f, 1.0f) - << QVector3D( 1.4444446564f, 3.6666665077f, 5.8888893127f); -} - -void tst_QPlane3D::intersection() -{ - QFETCH(QVector3D, point1); - QFETCH(QVector3D, direction); - QFETCH(QVector3D, point2); - QFETCH(QVector3D, normal); - QFETCH(QVector3D, intersection); - - QRay3D line(point1, direction); - QPlane3D plane(point2, normal); - - qreal t = plane.intersection(line); - QVERIFY(!qIsNaN(t)); - QVERIFY(fuzzyCompare(line.point(t), intersection)); - QVERIFY(plane.intersects(line)); -} - -void tst_QPlane3D::noIntersection_data() -{ - QTest::addColumn<QVector3D>("point1"); - QTest::addColumn<QVector3D>("normal"); - QTest::addColumn<QVector3D>("point2"); - QTest::addColumn<QVector3D>("direction"); - QTest::addColumn<QVector3D>("intersection"); - - // These direction vectors will get normalized - QTest::newRow("line on x-axis, plane in z-x") - << QVector3D() - << QVector3D(2.0f, 0.0f, 0.0f) - << QVector3D(4.0f, 1.0f, 1.0f) - << QVector3D(0.0f, 1.0f, 0.0f); - - QTest::newRow("line -z-axis, lies on plane in z-x") - << QVector3D(3.0f, 3.0f, 3.0f) - << QVector3D(0.0f, 0.0f, -0.7f) - << QVector3D(1.0f, 3.0f, 1.0f) - << QVector3D(0.0f, -0.7f, 0.0f); - - QTest::newRow("line on an angle, never meets plane on angle") - << QVector3D(3.0f, 3.0f, 3.0f) - << QVector3D(0.1f, 0.0f, 0.0f) - << QVector3D(1.0f, 1.0f, 3.0f) - << QVector3D(0.0f, 1.0f, 0.0f); -} - -void tst_QPlane3D::noIntersection() -{ - QFETCH(QVector3D, point1); - QFETCH(QVector3D, direction); - QFETCH(QVector3D, point2); - QFETCH(QVector3D, normal); - - QPlane3D plane(point1, normal); - QRay3D line(point2, direction); - - qreal t = plane.intersection(line); - QVERIFY(qIsNaN(t)); - QVERIFY(!plane.intersects(line)); -} - -// Find a vector that lies perpendicular to the normal, and in the plane. -static QVector3D vectorInPlane(const QPlane3D &plane) -{ - QVector3D v = QVector3D::crossProduct(plane.normal(), QVector3D(1, 0, 0)); - if (fuzzyIsNull(v)) - v = QVector3D::crossProduct(plane.normal(), QVector3D(0, 1, 0)); - if (fuzzyIsNull(v)) - v = QVector3D::crossProduct(plane.normal(), QVector3D(0, 0, 1)); - v = QVector3D::dotProduct(v, plane.normal()) * plane.normal() / - plane.normal().lengthSquared(); - Q_ASSERT(fuzzyCompare(QVector3D::dotProduct(v, plane.normal()), 0.0f)); - return v; -} - -void tst_QPlane3D::contains_data() -{ - create_data(); -} - -void tst_QPlane3D::contains() -{ - QFETCH(QVector3D, point); - QFETCH(QVector3D, normal); - QPlane3D plane(point, normal); - - QVERIFY(plane.contains(point)); - QVERIFY(!plane.contains(point + normal)); - QVERIFY(!plane.contains(point - normal)); - - QVector3D v = vectorInPlane(plane); - QVERIFY(plane.contains(QRay3D(point, v))); - QVERIFY(plane.contains(QRay3D(point - v, v))); - QVERIFY(!plane.contains(QRay3D(point + normal, v))); - QVERIFY(!plane.contains(QRay3D(point, normal))); -} - -void tst_QPlane3D::distanceTo_data() -{ - create_data(); -} - -void tst_QPlane3D::distanceTo() -{ - QFETCH(QVector3D, point); - QFETCH(QVector3D, normal); - QPlane3D plane(point, normal); - - QVERIFY(fuzzyCompare(plane.distanceTo(point), 0.0f)); - QVERIFY(fuzzyCompare(plane.distanceTo(point + normal), normal.length())); - QVERIFY(fuzzyCompare(plane.distanceTo(point - normal), -normal.length())); - - QVector3D v = vectorInPlane(plane); - QVERIFY(fuzzyCompare(plane.distanceTo(point + v), 0.0f)); - QVERIFY(fuzzyCompare(plane.distanceTo(point + normal + v), normal.length())); - QVERIFY(fuzzyCompare(plane.distanceTo(point - normal + v), -normal.length())); -} - -void tst_QPlane3D::compare() -{ - QPlane3D plane1(QVector3D(10, 20, 30), QVector3D(-1, 2, 4)); - QPlane3D plane2(QVector3D(10, 20, 30), QVector3D(1, -2, -4)); - QPlane3D plane3(QVector3D(0, 20, 30), QVector3D(-1, 2, 4)); - QVERIFY(plane1 == plane1); - QVERIFY(!(plane1 != plane1)); - QVERIFY(qFuzzyCompare(plane1, plane1)); - QVERIFY(plane1 != plane2); - QVERIFY(!(plane1 == plane2)); - QVERIFY(!qFuzzyCompare(plane1, plane2)); - QVERIFY(plane1 != plane3); - QVERIFY(!(plane1 == plane3)); - QVERIFY(!qFuzzyCompare(plane1, plane3)); -} - -void tst_QPlane3D::transform_data() -{ - create_data(); -} - -void tst_QPlane3D::transform() -{ - QFETCH(QVector3D, point); - QFETCH(QVector3D, normal); - - QMatrix4x4 m; - m.translate(-1.0f, 2.5f, 5.0f); - m.rotate(45.0f, 1.0f, 1.0f, 1.0f); - m.scale(23.5f); - - QPlane3D plane1(point, normal); - QPlane3D plane2(plane1); - QPlane3D plane3; - - plane1.transform(m); - plane3 = plane2.transformed(m); - - QVERIFY(fuzzyCompare(plane1.origin(), plane3.origin())); - QVERIFY(fuzzyCompare(plane1.normal(), plane3.normal())); - - QVERIFY(fuzzyCompare(plane1.origin(), m * point)); - QVERIFY(fuzzyCompare(plane1.normal(), m.mapVector(normal))); -} - -void tst_QPlane3D::dataStream() -{ -#ifndef QT_NO_DATASTREAM - QPlane3D plane(QVector3D(1.0f, 2.0f, 3.0f), - QVector3D(4.0f, 5.0f, 6.0f)); - - QByteArray data; - { - QDataStream stream(&data, QIODevice::WriteOnly); - stream << plane; - } - - QPlane3D plane2; - { - QDataStream stream2(data); - stream2 >> plane2; - } - - QVERIFY(plane == plane2); -#endif -} - -class tst_QPlane3DProperties : public QObject -{ - Q_OBJECT - Q_PROPERTY(QPlane3D plane READ plane WRITE setPlane) -public: - tst_QPlane3DProperties(QObject *parent = 0) : QObject(parent) {} - - QPlane3D plane() const { return p; } - void setPlane(const QPlane3D& value) { p = value; } - -private: - QPlane3D p; -}; - -// Test getting and setting properties via the metaobject system. -void tst_QPlane3D::properties() -{ - tst_QPlane3DProperties obj; - - qRegisterMetaType<QPlane3D>(); - - obj.setPlane(QPlane3D(QVector3D(1, 2, 3), QVector3D(4, 5, 6))); - - QPlane3D p = qVariantValue<QPlane3D>(obj.property("plane")); - QCOMPARE(p.origin(), QVector3D(1, 2, 3)); - QCOMPARE(p.normal(), QVector3D(4, 5, 6)); - - obj.setProperty("plane", - qVariantFromValue - (QPlane3D(QVector3D(-1, -2, -3), QVector3D(-4, -5, -6)))); - - p = qVariantValue<QPlane3D>(obj.property("plane")); - QCOMPARE(p.origin(), QVector3D(-1, -2, -3)); - QCOMPARE(p.normal(), QVector3D(-4, -5, -6)); -} - -void tst_QPlane3D::metaTypes() -{ - int id = qMetaTypeId<QPlane3D>(); - QVERIFY(QMetaType::type("QPlane3D") == id); - QCOMPARE(QByteArray(QMetaType::typeName(id)), QByteArray("QPlane3D")); - QVERIFY(QMetaType::isRegistered(id)); -} - -QTEST_APPLESS_MAIN(tst_QPlane3D) - -#include "tst_qplane3d.moc" diff --git a/tests/auto/threed/qray3d/qray3d.pro b/tests/auto/threed/qray3d/qray3d.pro deleted file mode 100644 index ba7deee4..00000000 --- a/tests/auto/threed/qray3d/qray3d.pro +++ /dev/null @@ -1,5 +0,0 @@ -load(qttest_p4.prf) -TEMPLATE = app -QT += testlib -CONFIG += unittest warn_on qt3d -SOURCES += tst_qray3d.cpp diff --git a/tests/auto/threed/qray3d/tst_qray3d.cpp b/tests/auto/threed/qray3d/tst_qray3d.cpp deleted file mode 100644 index 97263c99..00000000 --- a/tests/auto/threed/qray3d/tst_qray3d.cpp +++ /dev/null @@ -1,540 +0,0 @@ -/**************************************************************************** -** -** 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 QtQuick3D module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** 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. -** -** 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. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include <QtTest/QtTest> -#include "qray3d.h" -#include "../../../shared/qtest_helpers.h" - -class tst_QRay3D : public QObject -{ - Q_OBJECT -public: - tst_QRay3D() {} - ~tst_QRay3D() {} - -private slots: - void create_data(); - void create(); - void projection_data(); - void projection(); - void point_data(); - void point(); - void contains_point_data(); - void contains_point(); - void contains_ray_data(); - void contains_ray(); - void distanceTo_data(); - void distanceTo(); - void compare(); - void dataStream(); - void transform_data(); - void transform(); - void properties(); - void metaTypes(); -}; - -// since all calculations involved QVector3D are producing values with only -// float precision those calculations can at best be float precision -// if you assign the results of the calculation to a qreal then qFuzzyCompare -// will quite happily use a much higher standard of precision than it is -// possible to acheive - hence redefine it here to always use the float -// Also while on the job fix the problem where a compared value happens -// to be zero (and you cannot always predict this, and should not predict it -// since then you produce self-fulling prophecies instead of tests). -// In that case qFuzzyCompare has a completely strict criterion since -// it finds the "fudge factor" by multiplying by zero... -static inline bool fuzzyCompare(qreal p1, qreal p2) -{ - float fac = qMin(qAbs(p1), qAbs(p2)); - return (qAbs(p1 - p2) <= (qIsNull(fac) ? 0.00001f : 0.00001f * fac)); -} - -static inline bool fuzzyCompare(const QVector3D &lhs, const QVector3D &rhs) -{ - if (fuzzyCompare(lhs.x(), rhs.x()) && - fuzzyCompare(lhs.y(), rhs.y()) && - fuzzyCompare(lhs.z(), rhs.z())) - return true; -#ifndef QT_NO_DEBUG_STREAM - qWarning() << "actual:" << lhs; - qWarning() << "expected:" << rhs; -#endif - return false; -} - -void tst_QRay3D::create_data() -{ - QTest::addColumn<QVector3D>("point"); - QTest::addColumn<QVector3D>("direction"); - - // normalized direction vectors - QTest::newRow("line on x-axis from origin") - << QVector3D() - << QVector3D(1.0f, 0.0f, 0.0f); - - QTest::newRow("line parallel -z-axis from 3,3,3") - << QVector3D(3.0f, 3.0f, 3.0f) - << QVector3D(0.0f, 0.0f, -1.0f); - - QTest::newRow("vertical line (parallel to y-axis)") - << QVector3D(0.5f, 0.0f, 0.5f) - << QVector3D(0.0f, 1.0f, 0.0f); - - QTest::newRow("equidistant from all 3 axes") - << QVector3D(0.5f, 0.0f, 0.5f) - << QVector3D(0.57735026919f, 0.57735026919f, 0.57735026919f); - - // non-normalized direction vectors - QTest::newRow("line on x-axis from origin - B") - << QVector3D() - << QVector3D(2.0f, 0.0f, 0.0f); - - QTest::newRow("line parallel -z-axis from 3,3,3 - B") - << QVector3D(3.0f, 3.0f, 3.0f) - << QVector3D(0.0f, 0.0f, -0.7f); - - QTest::newRow("vertical line (parallel to y-axis) - B") - << QVector3D(0.5f, 0.0f, 0.5f) - << QVector3D(0.0f, 5.3f, 0.0f); - - QTest::newRow("equidistant from all 3 axes - B") - << QVector3D(0.5f, 0.0f, 0.5f) - << QVector3D(1.0f, 1.0f, 1.0f); - - QTest::newRow("negative direction") - << QVector3D(-3.0f, -3.0f, -3.0f) - << QVector3D(-1.2f, -1.8f, -2.4f); -} - -void tst_QRay3D::create() -{ - QFETCH(QVector3D, point); - QFETCH(QVector3D, direction); - QRay3D ray(point, direction); - QVERIFY(fuzzyCompare(ray.direction(), direction)); - QVERIFY(fuzzyCompare(ray.origin(), point)); - - QRay3D ray2; - QCOMPARE(ray2.origin(), QVector3D(0, 0, 0)); - QCOMPARE(ray2.direction(), QVector3D(1, 0, 0)); - ray2.setOrigin(point); - ray2.setDirection(direction); - QVERIFY(fuzzyCompare(ray.direction(), direction)); - QVERIFY(fuzzyCompare(ray.origin(), point)); -} - -void tst_QRay3D::projection_data() -{ - QTest::addColumn<QVector3D>("point"); - QTest::addColumn<QVector3D>("direction"); - QTest::addColumn<QVector3D>("vector"); - QTest::addColumn<QVector3D>("expected"); - - QTest::newRow("line on x-axis from origin") - << QVector3D() - << QVector3D(2.0f, 0.0f, 0.0f) - << QVector3D(0.6f, 0.0f, 0.0f) - << QVector3D(0.6f, 0.0f, 0.0f); - - QTest::newRow("line parallel -z-axis from 3,3,3") - << QVector3D(3.0f, 3.0f, 3.0f) - << QVector3D(0.0f, 0.0f, -0.7f) - << QVector3D(3.0f, 3.0f, 2.4f) - << QVector3D(0.0f, 0.0f, 2.4f); - - QTest::newRow("vertical line (parallel to y-axis)") - << QVector3D(0.5f, 0.0f, 0.5f) - << QVector3D(0.0f, 5.3f, 0.0f) - << QVector3D(0.5f, 0.6f, 0.5f) - << QVector3D(0.0f, 0.6f, 0.0f); - - QTest::newRow("equidistant from all 3 axes, project y-axis (with some z & x)") - << QVector3D(0.5f, 0.0f, 0.5f) - << QVector3D(1.0f, 1.0f, 1.0f) - << QVector3D(0.5f, 5.0f, 0.5f) - << QVector3D(2.0f, 2.0f, 2.0f); - - QTest::newRow("negative direction line, project +ve y-axis (with some z & x)") - << QVector3D(-3.0f, -3.0f, -3.0f) - << QVector3D(-1.2f, -1.8f, -2.4f) - << QVector3D(0.5f, 5.0f, 0.5f) - << QVector3D(1.241379261016846f, 1.862068772315979f, 2.48275852203369f); -} - -void tst_QRay3D::projection() -{ - QFETCH(QVector3D, point); - QFETCH(QVector3D, direction); - QFETCH(QVector3D, vector); - QFETCH(QVector3D, expected); - QRay3D line(point, direction); - QVector3D result = line.project(vector); - QVERIFY(fuzzyCompare(result, expected)); -} - -void tst_QRay3D::point_data() -{ - QTest::addColumn<QVector3D>("point"); - QTest::addColumn<QVector3D>("direction"); - QTest::addColumn<QVector3D>("point_on_line_pos_0_6"); - QTest::addColumn<QVector3D>("point_on_line_neg_7_2"); - - QTest::newRow("line on x-axis from origin") - << QVector3D() - << QVector3D(2.0f, 0.0f, 0.0f) - << QVector3D(1.2f, 0.0f, 0.0f) - << QVector3D(-14.4f, 0.0f, 0.0f); - - QTest::newRow("line parallel -z-axis from 3,3,3") - << QVector3D(3.0f, 3.0f, 3.0f) - << QVector3D(0.0f, 0.0f, -0.7f) - << QVector3D(3.0f, 3.0f, 2.58f) - << QVector3D(3.0f, 3.0f, 8.04f); - - QTest::newRow("vertical line (parallel to y-axis)") - << QVector3D(0.5f, 0.0f, 0.5f) - << QVector3D(0.0f, 5.3f, 0.0f) - << QVector3D(0.5f, 3.18f, 0.5f) - << QVector3D(0.5f, -38.16f, 0.5f); - - QTest::newRow("equidistant from all 3 axes") - << QVector3D(0.5f, 0.0f, 0.5f) - << QVector3D(1.0f, 1.0f, 1.0f) - << QVector3D(1.1f, 0.6f, 1.1f) - << QVector3D(-6.7f, -7.2f, -6.7f); - - QTest::newRow("negative direction") - << QVector3D(-3.0f, -3.0f, -3.0f) - << QVector3D(-1.2f, -1.8f, -2.4f) - << QVector3D(-3.72f, -4.08f, -4.44f) - << QVector3D(5.64f, 9.96f, 14.28f); -} - -void tst_QRay3D::point() -{ - QFETCH(QVector3D, point); - QFETCH(QVector3D, direction); - QFETCH(QVector3D, point_on_line_pos_0_6); - QFETCH(QVector3D, point_on_line_neg_7_2); - QRay3D line(point, direction); - QVERIFY(fuzzyCompare(line.point(0.6), point_on_line_pos_0_6)); - QVERIFY(fuzzyCompare(line.point(-7.2), point_on_line_neg_7_2)); - QVERIFY(fuzzyCompare(line.fromPoint(point_on_line_pos_0_6), 0.6)); - QVERIFY(fuzzyCompare(line.fromPoint(point_on_line_neg_7_2), -7.2)); -} - -void tst_QRay3D::contains_point_data() -{ - QTest::addColumn<QVector3D>("origin"); - QTest::addColumn<QVector3D>("direction"); - QTest::addColumn<QVector3D>("point"); - QTest::addColumn<bool>("contains"); - - QTest::newRow("bogus this line with null direction") - << QVector3D(1.0, 3.0, 3.0) - << QVector3D(0.0, 0.0, 0.0) - << QVector3D(1.0, 2.0, 4.0) - << false; - - QTest::newRow("point at the origin") - << QVector3D(0.0, 0.0, 0.0) - << QVector3D(1.0, 3.0, 3.0) - << QVector3D(0.0, 0.0, 0.0) - << true; - - QTest::newRow("close to the origin") - << QVector3D(1.0, 1.0, 1.0) - << QVector3D(1.0, 3.0, 3.0) - << QVector3D(1.0005, 1.0005, 1.0) - << false; - - QTest::newRow("45 line line in plane x=1") - << QVector3D(1.0, 3.0, 3.0) - << QVector3D(0.0, -1.0, -1.0) - << QVector3D(1.0, 4.0, 4.0) - << true; - { - // This is to prove that the constructed approach give the - // same results - QVector3D p(1.0, 3.0, 3.0); - QVector3D v(0.0, -1.0, -1.0); - - QTest::newRow("constructed 45 line line in plane x=1") - << p - << v - << p + v - << true; - } - - QTest::newRow("intersection with negative s in plane z=-1") - << QVector3D(1.0f, 2.0f, -1.0f) - << QVector3D(1.0f, 1.0f, 0.0f) - << QVector3D(2.0f, 1.0f, 0.0f) - << false; - - QTest::newRow("45 angled line") - << QVector3D(3.0f, 0.0f, -1.0f) - << QVector3D(1.0f, -1.0f, 1.0f) - << QVector3D(6.0f, -3.0f, 2.0f) - << true; - - { - QVector3D p(-10.0, 3.0, 3.0); - QVector3D v(0.0, 20.0, -1.0); - QTest::newRow("constructed vector close to axis") - << p - << v - << p + v * 3.0 - << true; - } - - { - QVector3D p(1.0, 3.0, 3.0); - QVector3D v(40.0, 500.0, -1.0); - QTest::newRow("constructed larger values close to axis") - << p - << v - << p + v - << true; - } -} - -void tst_QRay3D::contains_point() -{ - QFETCH(QVector3D, origin); - QFETCH(QVector3D, direction); - QFETCH(QVector3D, point); - QFETCH(bool, contains); - - QRay3D line(origin, direction); - QCOMPARE(line.contains(point), contains); -} - -void tst_QRay3D::contains_ray_data() -{ - contains_point_data(); -} - -void tst_QRay3D::contains_ray() -{ - QFETCH(QVector3D, origin); - QFETCH(QVector3D, direction); - QFETCH(QVector3D, point); - QFETCH(bool, contains); - - QRay3D line(origin, direction); - if (contains) { - QRay3D line2(point, direction); - QVERIFY(line.contains(line2)); - QVERIFY(line2.contains(line)); - - // Reversed direction is also contained. - QRay3D line3(point, -direction); - QVERIFY(line.contains(line2)); - QVERIFY(line2.contains(line)); - - // Different direction. - QRay3D line4(point, QVector3D(direction.y(), direction.x(), direction.z())); - QVERIFY(!line.contains(line4)); - QVERIFY(!line4.contains(line)); - } else { - QRay3D line2(point, direction); - QVERIFY(!line.contains(line2)); - QVERIFY(!line2.contains(line)); - } -} - -void tst_QRay3D::distanceTo_data() -{ - QTest::addColumn<QVector3D>("origin"); - QTest::addColumn<QVector3D>("direction"); - QTest::addColumn<QVector3D>("point"); - QTest::addColumn<qreal>("distance"); - - QTest::newRow("axis-x") - << QVector3D(6.0f, 0.0f, 0.0f) - << QVector3D(1.0f, 0.0f, 0.0f) - << QVector3D(0.0f, 0.0f, 0.0f) - << qreal(0.0f); - - QTest::newRow("axis-x to 1") - << QVector3D(6.0f, 0.0f, 0.0f) - << QVector3D(1.0f, 0.0f, 0.0f) - << QVector3D(0.0f, 1.0f, 0.0f) - << qreal(1.0f); - - QTest::newRow("neg-axis-y") - << QVector3D(0.0f, 6.0f, 0.0f) - << QVector3D(0.0f, -1.5f, 0.0f) - << QVector3D(0.0f, 100.0f, 0.0f) - << qreal(0.0f); - - QTest::newRow("neg-axis-y to 2") - << QVector3D(0.0f, 6.0f, 0.0f) - << QVector3D(0.0f, -1.5f, 0.0f) - << QVector3D(2.0f, 0.0f, 0.0f) - << qreal(2.0f); -} - -void tst_QRay3D::distanceTo() -{ - QFETCH(QVector3D, origin); - QFETCH(QVector3D, direction); - QFETCH(QVector3D, point); - QFETCH(qreal, distance); - - QRay3D line(origin, direction); - QCOMPARE(line.distanceTo(point), distance); -} - -void tst_QRay3D::compare() -{ - QRay3D ray1(QVector3D(10, 20, 30), QVector3D(-3, -4, -5)); - QRay3D ray2(QVector3D(10, 20, 30), QVector3D(1.5f, 2.0f, 2.5f)); - QRay3D ray3(QVector3D(0, 20, 30), QVector3D(-3, -4, -5)); - QVERIFY(ray1 == ray1); - QVERIFY(!(ray1 != ray1)); - QVERIFY(qFuzzyCompare(ray1, ray1)); - QVERIFY(ray1 != ray2); - QVERIFY(!(ray1 == ray2)); - QVERIFY(!qFuzzyCompare(ray1, ray2)); - QVERIFY(ray1 != ray3); - QVERIFY(!(ray1 == ray3)); - QVERIFY(!qFuzzyCompare(ray1, ray3)); -} - -void tst_QRay3D::dataStream() -{ -#ifndef QT_NO_DATASTREAM - QRay3D ray(QVector3D(1.0f, 2.0f, 3.0f), QVector3D(4.0f, 5.0f, 6.0f)); - - QByteArray data; - { - QDataStream stream(&data, QIODevice::WriteOnly); - stream << ray; - } - - QRay3D ray2; - { - QDataStream stream2(data); - stream2 >> ray2; - } - - QVERIFY(ray == ray2); -#endif -} - -void tst_QRay3D::transform_data() -{ - create_data(); -} - -void tst_QRay3D::transform() -{ - QFETCH(QVector3D, point); - QFETCH(QVector3D, direction); - - QMatrix4x4 m; - m.translate(-1.0f, 2.5f, 5.0f); - m.rotate(45.0f, 1.0f, 1.0f, 1.0f); - m.scale(23.5f); - - QRay3D ray1(point, direction); - QRay3D ray2(ray1); - QRay3D ray3; - - ray1.transform(m); - ray3 = ray2.transformed(m); - - QCOMPARE(ray1.origin(), ray3.origin()); - QCOMPARE(ray1.direction(), ray3.direction()); - - QCOMPARE(ray1.origin(), m * point); - QCOMPARE(ray1.direction(), m.mapVector(direction)); -} - -class tst_QRay3DProperties : public QObject -{ - Q_OBJECT - Q_PROPERTY(QRay3D ray READ ray WRITE setRay) -public: - tst_QRay3DProperties(QObject *parent = 0) : QObject(parent) {} - - QRay3D ray() const { return r; } - void setRay(const QRay3D& value) { r = value; } - -private: - QRay3D r; -}; - -// Test getting and setting properties via the metaobject system. -void tst_QRay3D::properties() -{ - tst_QRay3DProperties obj; - - qRegisterMetaType<QRay3D>(); - - obj.setRay(QRay3D(QVector3D(1, 2, 3), QVector3D(4, 5, 6))); - - QRay3D r = qVariantValue<QRay3D>(obj.property("ray")); - QCOMPARE(r.origin(), QVector3D(1, 2, 3)); - QCOMPARE(r.direction(), QVector3D(4, 5, 6)); - - obj.setProperty("ray", - qVariantFromValue - (QRay3D(QVector3D(-1, -2, -3), QVector3D(-4, -5, -6)))); - - r = qVariantValue<QRay3D>(obj.property("ray")); - QCOMPARE(r.origin(), QVector3D(-1, -2, -3)); - QCOMPARE(r.direction(), QVector3D(-4, -5, -6)); -} - -void tst_QRay3D::metaTypes() -{ - int id = qMetaTypeId<QRay3D>(); - QVERIFY(QMetaType::type("QRay3D") == id); - QCOMPARE(QByteArray(QMetaType::typeName(id)), QByteArray("QRay3D")); - QVERIFY(QMetaType::isRegistered(id)); -} - -QTEST_APPLESS_MAIN(tst_QRay3D) - -#include "tst_qray3d.moc" diff --git a/tests/auto/threed/qsphere3d/qsphere3d.pro b/tests/auto/threed/qsphere3d/qsphere3d.pro deleted file mode 100644 index d758dcf1..00000000 --- a/tests/auto/threed/qsphere3d/qsphere3d.pro +++ /dev/null @@ -1,5 +0,0 @@ -load(qttest_p4.prf) -TEMPLATE=app -QT += testlib -CONFIG += unittest warn_on qt3d -SOURCES += tst_qsphere3d.cpp diff --git a/tests/auto/threed/qsphere3d/tst_qsphere3d.cpp b/tests/auto/threed/qsphere3d/tst_qsphere3d.cpp deleted file mode 100644 index 1cea5449..00000000 --- a/tests/auto/threed/qsphere3d/tst_qsphere3d.cpp +++ /dev/null @@ -1,238 +0,0 @@ -/**************************************************************************** -** -** 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 QtQuick3D module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** 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. -** -** 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. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include <QtTest/QtTest> -#include "qsphere3d.h" -#include <QtGui/qmatrix4x4.h> - -class tst_QSphere3D : public QObject -{ - Q_OBJECT -public: - tst_QSphere3D() {} - ~tst_QSphere3D() {} - -private slots: - void create(); - void contains_data(); - void contains(); - void compare(); - void dataStream(); - void transform(); - void properties(); - void metaTypes(); -}; - -void tst_QSphere3D::create() -{ - QSphere3D sphere1; - QCOMPARE(sphere1.center(), QVector3D(0, 0, 0)); - QCOMPARE(sphere1.radius(), qreal(1.0f)); - - QSphere3D sphere2(QVector3D(1.0, 2.5f, -4.0f), 5.25f); - QCOMPARE(sphere2.center(), QVector3D(1.0f, 2.5f, -4.0f)); - QCOMPARE(sphere2.radius(), qreal(5.25f)); - - sphere2.setCenter(QVector3D(-1.0, -2.5f, 4.0f)); - sphere2.setRadius(10.0f); - QCOMPARE(sphere2.center(), QVector3D(-1.0f, -2.5f, 4.0f)); - QCOMPARE(sphere2.radius(), qreal(10.0f)); -} - -void tst_QSphere3D::contains_data() -{ - QTest::addColumn<QVector3D>("center"); - QTest::addColumn<qreal>("radius"); - QTest::addColumn<QVector3D>("point"); - QTest::addColumn<bool>("contained"); - - QTest::newRow("origin-inside") - << QVector3D(0, 0, 0) << qreal(0) - << QVector3D(0, 0, 0) << true; - QTest::newRow("origin-outside") - << QVector3D(0, 0, 0) << qreal(0) - << QVector3D(0, 0.25f, 0) << false; - - QTest::newRow("general-inside") - << QVector3D(1, 2, 3) << qreal(5) - << QVector3D(1, 2, 3) << true; - - QTest::newRow("general-edge-x") - << QVector3D(1, 2, 3) << qreal(5) - << QVector3D(6, 2, 3) << true; - QTest::newRow("general-edge-y") - << QVector3D(1, 2, 3) << qreal(5) - << QVector3D(1, -3, 3) << true; - QTest::newRow("general-edge-z") - << QVector3D(1, 2, 3) << qreal(5) - << QVector3D(1, 2, 8) << true; - - QTest::newRow("general-outside-x") - << QVector3D(1, 2, 3) << qreal(5) - << QVector3D(6.25f, 2, 3) << false; - QTest::newRow("general-outside-y") - << QVector3D(1, 2, 3) << qreal(5) - << QVector3D(1, -3.5f, 3) << false; - QTest::newRow("general-outside-z") - << QVector3D(1, 2, 3) << qreal(5) - << QVector3D(1, 2, 8.25f) << false; -} - -void tst_QSphere3D::contains() -{ - QFETCH(QVector3D, center); - QFETCH(qreal, radius); - QFETCH(QVector3D, point); - QFETCH(bool, contained); - - QSphere3D sphere(center, radius); - QCOMPARE(sphere.contains(point), contained); -} - -void tst_QSphere3D::compare() -{ - QSphere3D sphere1(QVector3D(10, 20, 30), 5.25f); - QSphere3D sphere2(QVector3D(10, 20, 30), 1.0f); - QSphere3D sphere3(QVector3D(0, 20, 30), 5.25f); - QVERIFY(sphere1 == sphere1); - QVERIFY(!(sphere1 != sphere1)); - QVERIFY(qFuzzyCompare(sphere1, sphere1)); - QVERIFY(sphere1 != sphere2); - QVERIFY(!(sphere1 == sphere2)); - QVERIFY(!qFuzzyCompare(sphere1, sphere2)); - QVERIFY(sphere1 != sphere3); - QVERIFY(!(sphere1 == sphere3)); - QVERIFY(!qFuzzyCompare(sphere1, sphere3)); -} - -void tst_QSphere3D::dataStream() -{ -#ifndef QT_NO_DATASTREAM - QSphere3D sphere(QVector3D(1.0f, 2.0f, 3.0f), 4.0f); - - QByteArray data; - { - QDataStream stream(&data, QIODevice::WriteOnly); - stream << sphere; - } - - QSphere3D sphere2; - { - QDataStream stream2(data); - stream2 >> sphere2; - } - - QVERIFY(sphere == sphere2); -#endif -} - -void tst_QSphere3D::transform() -{ - QVector3D center(1, 2, 3); - qreal radius = 5.25f; - - QMatrix4x4 m; - m.translate(-1.0f, 2.5f, 5.0f); - m.rotate(45.0f, 1.0f, 1.0f, 1.0f); - m.scale(23.5f); - - QSphere3D sphere1(center, radius); - QSphere3D sphere2(sphere1); - QSphere3D sphere3; - - sphere1.transform(m); - sphere3 = sphere2.transformed(m); - - QCOMPARE(sphere1.center(), sphere3.center()); - QCOMPARE(sphere1.radius(), sphere3.radius()); - - qreal tradius = m.mapVector(QVector3D(0, radius, 0)).length(); - - QCOMPARE(sphere1.center(), m * center); - QCOMPARE(float(sphere1.radius()), float(tradius)); -} - -class tst_QSphere3DProperties : public QObject -{ - Q_OBJECT - Q_PROPERTY(QSphere3D sphere READ sphere WRITE setSphere) -public: - tst_QSphere3DProperties(QObject *parent = 0) : QObject(parent) {} - - QSphere3D sphere() const { return s; } - void setSphere(const QSphere3D& value) { s = value; } - -private: - QSphere3D s; -}; - -// Test getting and setting properties via the metaobject system. -void tst_QSphere3D::properties() -{ - tst_QSphere3DProperties obj; - - qRegisterMetaType<QSphere3D>(); - - obj.setSphere(QSphere3D(QVector3D(1, 2, 3), 4)); - - QSphere3D s = qVariantValue<QSphere3D>(obj.property("sphere")); - QCOMPARE(s.center(), QVector3D(1, 2, 3)); - QCOMPARE(s.radius(), qreal(4.0f)); - - obj.setProperty("sphere", - qVariantFromValue(QSphere3D(QVector3D(-1, -2, -3), -4))); - - s = qVariantValue<QSphere3D>(obj.property("sphere")); - QCOMPARE(s.center(), QVector3D(-1, -2, -3)); - QCOMPARE(s.radius(), qreal(-4.0f)); -} - -void tst_QSphere3D::metaTypes() -{ - int id = qMetaTypeId<QSphere3D>(); - QVERIFY(QMetaType::type("QSphere3D") == id); - QCOMPARE(QByteArray(QMetaType::typeName(id)), QByteArray("QSphere3D")); - QVERIFY(QMetaType::isRegistered(id)); -} - -QTEST_APPLESS_MAIN(tst_QSphere3D) - -#include "tst_qsphere3d.moc" diff --git a/tests/auto/threed/qstereoimage/qstereoimage.pro b/tests/auto/threed/qstereoimage/qstereoimage.pro deleted file mode 100644 index 6691805d..00000000 --- a/tests/auto/threed/qstereoimage/qstereoimage.pro +++ /dev/null @@ -1,10 +0,0 @@ -load(qttest_p4.prf) -TEMPLATE=app -QT += testlib -CONFIG += unittest warn_on - -INCLUDEPATH += ../../../../examples/stereophoto -VPATH += ../../../../examples/stereophoto - -HEADERS += qstereoimage.h -SOURCES += tst_qstereoimage.cpp qstereoimage.cpp diff --git a/tests/auto/threed/qstereoimage/tst_qstereoimage.cpp b/tests/auto/threed/qstereoimage/tst_qstereoimage.cpp deleted file mode 100644 index 72281296..00000000 --- a/tests/auto/threed/qstereoimage/tst_qstereoimage.cpp +++ /dev/null @@ -1,428 +0,0 @@ -/**************************************************************************** -** -** 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 QtQuick3D module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** 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. -** -** 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. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include <QtTest/QtTest> -#include "qstereoimage.h" -#include <QtGui/qpainter.h> - -class tst_QStereoImage : public QObject -{ - Q_OBJECT -public: - tst_QStereoImage() {} - ~tst_QStereoImage() {} - -private slots: - void separateNonEqual_data(); - void separateNonEqual(); - void createAndConvert_data(); - void createAndConvert(); - void painting_data(); - void painting(); - -private: - static QImage generateImage - (int width, int height, const QColor &color, - QImage::Format format = QImage::Format_RGB32); - static QImage generateStereoPair - (int width, int height, const QColor &lcolor, const QColor &rcolor, - QStereoImage::Layout layout = QStereoImage::LeftRight, - QImage::Format format = QImage::Format_RGB32); -}; - -QImage tst_QStereoImage::generateImage - (int width, int height, const QColor &color, QImage::Format format) -{ - QImage image(width, height, format); - image.fill(color.rgba()); - return image; -} - -QImage tst_QStereoImage::generateStereoPair - (int width, int height, const QColor &lcolor, const QColor &rcolor, - QStereoImage::Layout layout, QImage::Format format) -{ - QImage image; - QPoint left, right; - - switch (layout) { - default: - case QStereoImage::LeftRight: - image = QImage(width * 2, height, format); - left = QPoint(0, 0); - right = QPoint(width, 0); - break; - - case QStereoImage::RightLeft: - image = QImage(width * 2, height, format); - left = QPoint(width, 0); - right = QPoint(0, 0); - break; - - case QStereoImage::TopBottom: - image = QImage(width, height * 2, format); - left = QPoint(0, 0); - right = QPoint(0, height); - break; - - case QStereoImage::BottomTop: - image = QImage(width, height * 2, format); - left = QPoint(0, height); - right = QPoint(0, 0); - break; - } - - uint lpixel = lcolor.rgba(); - uint rpixel = rcolor.rgba(); - for (int y = 0; y < height; ++y) { - for (int x = 0; x < width; ++x) { - image.setPixel(x + left.x(), y + left.y(), lpixel); - image.setPixel(x + right.x(), y + right.y(), rpixel); - } - } - - return image; -} - -// Test creation of a separate image with non-equal sizes for left -// and right images, and check that conversions do what we expect. -void tst_QStereoImage::separateNonEqual_data() -{ - QTest::addColumn<int>("toLayout"); - - QTest::newRow("Separate -> LeftRight") - << int(QStereoImage::LeftRight); - QTest::newRow("Separate -> RightLeft") - << int(QStereoImage::RightLeft); - QTest::newRow("Separate -> TopBottom") - << int(QStereoImage::TopBottom); - QTest::newRow("Separate -> BottomTop") - << int(QStereoImage::BottomTop); -} -void tst_QStereoImage::separateNonEqual() -{ - QFETCH(int, toLayout); - - QStereoImage::Layout to = QStereoImage::Layout(toLayout); - - QStereoImage image1; - QVERIFY(image1.isNull()); - QCOMPARE(image1.size(), QSize(0, 0)); - QCOMPARE(image1.width(), 0); - QCOMPARE(image1.height(), 0); - QVERIFY(image1.layout() == QStereoImage::Separate); - - QImage left(generateImage(120, 100, Qt::red)); - QImage right(generateImage(125, 90, Qt::blue)); - - image1.setLeftImage(left); - - QVERIFY(!image1.isNull()); - QCOMPARE(image1.size(), QSize(120, 100)); - QCOMPARE(image1.width(), 120); - QCOMPARE(image1.height(), 100); - QVERIFY(image1.layout() == QStereoImage::Separate); - QCOMPARE(image1.leftImage(), left); - QVERIFY(image1.rightImage().isNull()); - QVERIFY(image1.wholeImage().isNull()); - - QStereoImage image2(image1); - - image1.setRightImage(right); - - QVERIFY(!image1.isNull()); - QCOMPARE(image1.size(), QSize(125, 100)); // Expands to max(left,right). - QCOMPARE(image1.width(), 125); - QCOMPARE(image1.height(), 100); - QVERIFY(image1.layout() == QStereoImage::Separate); - QCOMPARE(image1.leftImage(), left); - QCOMPARE(image1.rightImage(), right); - QVERIFY(image1.wholeImage().isNull()); - - QVERIFY(!image2.isNull()); - QCOMPARE(image2.size(), QSize(120, 100)); - QCOMPARE(image2.width(), 120); - QCOMPARE(image2.height(), 100); - QVERIFY(image2.layout() == QStereoImage::Separate); - QCOMPARE(image2.leftImage(), left); - QVERIFY(image2.rightImage().isNull()); - QVERIFY(image2.wholeImage().isNull()); - - QImage wholeTo(generateStereoPair(125, 100, Qt::red, Qt::blue, to)); - - image1.setLayout(to); - QVERIFY(!image1.isNull()); - QCOMPARE(image1.size(), QSize(125, 100)); - QCOMPARE(image1.width(), 125); - QCOMPARE(image1.height(), 100); - QVERIFY(image1.layout() == to); - QCOMPARE(image1.leftImage().size(), QSize(125, 100)); - QCOMPARE(image1.leftImage().copy(0, 0, 120, 100), left); - QCOMPARE(image1.rightImage().size(), QSize(125, 100)); - QCOMPARE(image1.rightImage().copy(0, 0, 125, 90), right); - QCOMPARE(image1.wholeImage().size(), wholeTo.size()); -} - -// Test creating stereo images in various formats and converting -// them to all other possible formats. -void tst_QStereoImage::createAndConvert_data() -{ - QTest::addColumn<int>("fromLayout"); - QTest::addColumn<int>("toLayout"); - - // Foo -> Separate is handled in createAndConvert() below, so we - // don't need to explicitly list it here. - - QTest::newRow("Separate -> LeftRight") - << int(QStereoImage::Separate) - << int(QStereoImage::LeftRight); - QTest::newRow("Separate -> RightLeft") - << int(QStereoImage::Separate) - << int(QStereoImage::RightLeft); - QTest::newRow("Separate -> TopBottom") - << int(QStereoImage::Separate) - << int(QStereoImage::TopBottom); - QTest::newRow("Separate -> BottomTop") - << int(QStereoImage::Separate) - << int(QStereoImage::BottomTop); - - QTest::newRow("LeftRight -> LeftRight") - << int(QStereoImage::LeftRight) - << int(QStereoImage::LeftRight); - QTest::newRow("LeftRight -> RightLeft") - << int(QStereoImage::LeftRight) - << int(QStereoImage::RightLeft); - QTest::newRow("LeftRight -> TopBottom") - << int(QStereoImage::LeftRight) - << int(QStereoImage::TopBottom); - QTest::newRow("LeftRight -> BottomTop") - << int(QStereoImage::LeftRight) - << int(QStereoImage::BottomTop); - - QTest::newRow("RightLeft -> LeftRight") - << int(QStereoImage::RightLeft) - << int(QStereoImage::LeftRight); - QTest::newRow("RightLeft -> RightLeft") - << int(QStereoImage::RightLeft) - << int(QStereoImage::RightLeft); - QTest::newRow("RightLeft -> TopBottom") - << int(QStereoImage::RightLeft) - << int(QStereoImage::TopBottom); - QTest::newRow("RightLeft -> BottomTop") - << int(QStereoImage::RightLeft) - << int(QStereoImage::BottomTop); - - QTest::newRow("TopBottom -> LeftRight") - << int(QStereoImage::TopBottom) - << int(QStereoImage::LeftRight); - QTest::newRow("TopBottom -> RightLeft") - << int(QStereoImage::TopBottom) - << int(QStereoImage::RightLeft); - QTest::newRow("TopBottom -> TopBottom") - << int(QStereoImage::TopBottom) - << int(QStereoImage::TopBottom); - QTest::newRow("TopBottom -> BottomTop") - << int(QStereoImage::TopBottom) - << int(QStereoImage::BottomTop); - - QTest::newRow("BottomTop -> LeftRight") - << int(QStereoImage::BottomTop) - << int(QStereoImage::LeftRight); - QTest::newRow("BottomTop -> RightLeft") - << int(QStereoImage::BottomTop) - << int(QStereoImage::RightLeft); - QTest::newRow("BottomTop -> TopBottom") - << int(QStereoImage::BottomTop) - << int(QStereoImage::TopBottom); - QTest::newRow("BottomTop -> BottomTop") - << int(QStereoImage::BottomTop) - << int(QStereoImage::BottomTop); -} - -void tst_QStereoImage::createAndConvert() -{ - QFETCH(int, fromLayout); - QFETCH(int, toLayout); - - QStereoImage::Layout from = QStereoImage::Layout(fromLayout); - QStereoImage::Layout to = QStereoImage::Layout(toLayout); - - QStereoImage image2; - - QStereoImage image1(QSize(120, 100), QImage::Format_RGB32, from); - QVERIFY(!image1.isNull()); - QCOMPARE(image1.size(), QSize(120, 100)); - QCOMPARE(image1.width(), 120); - QCOMPARE(image1.height(), 100); - QVERIFY(image1.layout() == from); - QCOMPARE(image1.leftImage().size(), QSize(120, 100)); - QCOMPARE(image1.rightImage().size(), QSize(120, 100)); - if (from == QStereoImage::Separate) - QVERIFY(image1.wholeImage().isNull()); - else if (from == QStereoImage::LeftRight || from == QStereoImage::RightLeft) - QCOMPARE(image1.wholeImage().size(), QSize(240, 100)); - else - QCOMPARE(image1.wholeImage().size(), QSize(120, 200)); - - QImage left(generateImage(120, 100, Qt::red)); - QImage right(generateImage(120, 100, Qt::blue)); - QImage whole(generateStereoPair(120, 100, Qt::red, Qt::blue, from)); - QImage wholeTo(generateStereoPair(120, 100, Qt::red, Qt::blue, to)); - - image1.setLeftImage(left); - image1.setRightImage(right); - - QCOMPARE(image1.leftImage(), left); - QCOMPARE(image1.rightImage(), right); - if (from == QStereoImage::Separate) - QVERIFY(image1.wholeImage().isNull()); - else - QCOMPARE(image1.wholeImage(), whole); - - image2 = image1; - - // Check separate conversion, which will also test copy-on-write. - image1.setLayout(QStereoImage::Separate); - - QCOMPARE(image1.leftImage(), left); - QCOMPARE(image1.rightImage(), right); - QVERIFY(image1.wholeImage().isNull()); - QVERIFY(!image1.isNull()); - QCOMPARE(image1.size(), QSize(120, 100)); - QCOMPARE(image1.width(), 120); - QCOMPARE(image1.height(), 100); - QVERIFY(image1.layout() == QStereoImage::Separate); - - QVERIFY(image2.layout() == from); - - image2.setLayout(to); - QVERIFY(!image2.isNull()); - QCOMPARE(image2.size(), QSize(120, 100)); - QCOMPARE(image2.width(), 120); - QCOMPARE(image2.height(), 100); - QVERIFY(image2.layout() == to); - QCOMPARE(image2.leftImage(), left); - QCOMPARE(image2.rightImage(), right); - QCOMPARE(image2.wholeImage(), wholeTo); - - // Test creation with width and height instead of QSize. - QStereoImage image3(120, 100, QImage::Format_RGB32, from); - QVERIFY(!image3.isNull()); - QCOMPARE(image3.size(), QSize(120, 100)); - QCOMPARE(image3.width(), 120); - QCOMPARE(image3.height(), 100); - QVERIFY(image3.layout() == from); - image3.setLeftImage(left); - image3.setRightImage(right); - QCOMPARE(image3.leftImage(), left); - QCOMPARE(image3.rightImage(), right); - if (from == QStereoImage::Separate) - QVERIFY(image3.wholeImage().isNull()); - else - QCOMPARE(image3.wholeImage(), whole); -} - -// Test painting into the two halves of a stereo image. -void tst_QStereoImage::painting_data() -{ - QTest::addColumn<int>("layoutValue"); - - QTest::newRow("Separate") - << int(QStereoImage::Separate); - QTest::newRow("LeftRight") - << int(QStereoImage::LeftRight); - QTest::newRow("RightLeft") - << int(QStereoImage::RightLeft); - QTest::newRow("TopBottom") - << int(QStereoImage::TopBottom); - QTest::newRow("BottomTop") - << int(QStereoImage::BottomTop); -} -void tst_QStereoImage::painting() -{ - QFETCH(int, layoutValue); - - QStereoImage::Layout layout = QStereoImage::Layout(layoutValue); - - QStereoImage image1(QSize(120, 100), QImage::Format_ARGB32, layout); - QVERIFY(image1.layout() == layout); - - QImage left(generateImage(120, 100, Qt::red, QImage::Format_ARGB32)); - QImage right(generateImage(120, 100, Qt::blue, QImage::Format_ARGB32)); - QImage leftTo(generateImage(120, 100, Qt::green, QImage::Format_ARGB32)); - QImage rightTo(generateImage(120, 100, Qt::yellow, QImage::Format_ARGB32)); - - image1.setLeftImage(left); - image1.setRightImage(right); - - // Fill a rectangle that is partially out of bounds to check - // that painting is actually being constrained by a clip region. - QPainter leftPainter; - image1.beginPaintingLeft(&leftPainter); - leftPainter.fillRect(-10, -10, 600, 300, Qt::green); - leftPainter.end(); - - QCOMPARE(image1.leftImage(), leftTo); - QCOMPARE(image1.rightImage(), right); - - QPainter rightPainter; - image1.beginPaintingRight(&rightPainter); - rightPainter.fillRect(-10, -10, 600, 300, Qt::yellow); - rightPainter.end(); - - QCOMPARE(image1.leftImage(), leftTo); - QCOMPARE(image1.rightImage(), rightTo); - - // Draw the left and right halves into a different painter. - QImage whole(generateStereoPair(120, 100, Qt::green, Qt::yellow, - QStereoImage::LeftRight, - QImage::Format_ARGB32)); - QImage image2(240, 100, QImage::Format_ARGB32); - QPainter painter(&image2); - image1.drawLeft(&painter, QRectF(0, 0, 120, 100)); - image1.drawRight(&painter, QRectF(120, 0, 120, 100)); - painter.end(); - QCOMPARE(image2, whole); -} - -QTEST_APPLESS_MAIN(tst_QStereoImage) - -#include "tst_qstereoimage.moc" diff --git a/tests/auto/threed/qtriangle3d/qtriangle3d.pro b/tests/auto/threed/qtriangle3d/qtriangle3d.pro deleted file mode 100644 index 06997373..00000000 --- a/tests/auto/threed/qtriangle3d/qtriangle3d.pro +++ /dev/null @@ -1,6 +0,0 @@ -load(qttest_p4.prf) -TEMPLATE=app -QT += testlib -CONFIG += unittest warn_on qt3d - -SOURCES += tst_qtriangle3d.cpp diff --git a/tests/auto/threed/qtriangle3d/tst_qtriangle3d.cpp b/tests/auto/threed/qtriangle3d/tst_qtriangle3d.cpp deleted file mode 100644 index e9df6abe..00000000 --- a/tests/auto/threed/qtriangle3d/tst_qtriangle3d.cpp +++ /dev/null @@ -1,714 +0,0 @@ -/**************************************************************************** -** -** 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 QtQuick3D module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** 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. -** -** 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. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include <QtTest/QtTest> -#include "qtriangle3d.h" -#include "qplane3d.h" - -class tst_QTriangle3D : public QObject -{ - Q_OBJECT -public: - tst_QTriangle3D() {} - ~tst_QTriangle3D() {} - -private slots: - void defaultTriangle(); - - void create_data(); - void create(); - - void contains_data(); - void contains(); - - void intersect_data(); - void intersect(); - - void uv_data(); - void uv(); - - void transform_data(); - void transform(); - - void compare(); - - void dataStream(); - - void properties(); - void metaTypes(); -}; - -void tst_QTriangle3D::defaultTriangle() -{ - QTriangle3D triangle; - QCOMPARE(triangle.p(), QVector3D(0.0f, 0.0f, 0.0f)); - QCOMPARE(triangle.q(), QVector3D(1.0f, 0.0f, 0.0f)); - QCOMPARE(triangle.r(), QVector3D(0.0f, 1.0f, 0.0f)); -} - -void tst_QTriangle3D::create_data() -{ - QTest::addColumn<QVector3D>("p"); - QTest::addColumn<QVector3D>("q"); - QTest::addColumn<QVector3D>("r"); - QTest::addColumn<bool>("isDegenerate"); - QTest::addColumn<QPlane3D>("plane"); - QTest::addColumn<QVector3D>("centroid"); - - QTest::newRow("minimal at null") - << QVector3D(0.0f, 0.0f, 0.0f) // p - << QVector3D(0.0f, 0.0f, 0.0f) // q - << QVector3D(0.0f, 0.0f, 0.0f) // r - << true // degenerate - << QPlane3D() // plane (degenerate, meaning meaningless) - << QVector3D(0.0f, 0.0f, 0.0f); - QTest::newRow("minimal at offset") - << QVector3D(2.0f, 2.0f, 2.0f) // p - << QVector3D(2.0f, 2.0f, 2.0f) // q - << QVector3D(2.0f, 2.0f, 2.0f) // r - << true // degenerate - << QPlane3D() // plane (degenerate, meaning meaningless) - << QVector3D(2.0f, 2.0f, 2.0f); // centroid - QTest::newRow("line from 0(p) [a]") - << QVector3D(0.0f, 0.0f, 0.0f) // p - << QVector3D(0.0f, 0.0f, 0.5f) // q - << QVector3D(0.0f, 0.0f, 2.0f) // r - << true // degenerate - << QPlane3D() // plane (degenerate, meaning meaningless) - << QVector3D(0.0f, 0.0f, 2.5f/3.0f); // centroid - QTest::newRow("line from 0(p) [b]") - << QVector3D(0.0f, 0.0f, 0.0f) // p - << QVector3D(0.0f, 0.0f, 1.0f) // q - << QVector3D(0.0f, 0.0f, 2.0f) // r - << true // degenerate - << QPlane3D() // plane (degenerate, meaning meaningless) - << QVector3D(0.0f, 0.0f, 1.0f); // centroid - QTest::newRow("line from 0(p) [c]") - << QVector3D(0.0f, 0.0f, 0.0f) // p - << QVector3D(0.0f, 0.0f, 1.5f) // q - << QVector3D(0.0f, 0.0f, 2.0f) // r - << true // degenerate - << QPlane3D() // plane (degenerate, meaning meaningless) - << QVector3D(0.0f, 0.0f, 3.5f/3.0f); // centroid - QTest::newRow("line from 0(q) [a]") - << QVector3D(0.0f, 0.0f, 0.5f) // p - << QVector3D(0.0f, 0.0f, 0.0f) // q - << QVector3D(0.0f, 0.0f, 2.0f) // r - << true // degenerate - << QPlane3D() // plane (degenerate, meaning meaningless) - << QVector3D(0.0f, 0.0f, 2.5f/3.0f); // centroid - QTest::newRow("line from 0(q) [b]") - << QVector3D(0.0f, 0.0f, 1.0f) // p - << QVector3D(0.0f, 0.0f, 0.0f) // q - << QVector3D(0.0f, 0.0f, 2.0f) // r - << true // degenerate - << QPlane3D() // plane (degenerate, meaning meaningless) - << QVector3D(0.0f, 0.0f, 1.0f); // centroid - QTest::newRow("line from 0(q) [c]") - << QVector3D(0.0f, 0.0f, 1.5f) // p - << QVector3D(0.0f, 0.0f, 0.0f) // q - << QVector3D(0.0f, 0.0f, 2.0f) // r - << true // degenerate - << QPlane3D() // plane (degenerate, meaning meaningless) - << QVector3D(0.0f, 0.0f, 3.5f/3.0f); // centroid - QTest::newRow("line from 0(r) [a]") - << QVector3D(0.0f, 0.0f, 0.5f) // p - << QVector3D(0.0f, 0.0f, 2.0f) // q - << QVector3D(0.0f, 0.0f, 0.0f) // r - << true // degenerate - << QPlane3D() // plane (degenerate, meaning meaningless) - << QVector3D(0.0f, 0.0f, 2.5f/3.0f); // centroid - QTest::newRow("line from 0(r) [b]") - << QVector3D(0.0f, 0.0f, 1.0f) // p - << QVector3D(0.0f, 0.0f, 2.0f) // q - << QVector3D(0.0f, 0.0f, 0.0f) // r - << true // degenerate - << QPlane3D() // plane (degenerate, meaning meaningless) - << QVector3D(0.0f, 0.0f, 1.0f); // centroid - QTest::newRow("line from 0(r) [c]") - << QVector3D(0.0f, 0.0f, 1.5f) // p - << QVector3D(0.0f, 0.0f, 2.0f) // q - << QVector3D(0.0f, 0.0f, 0.0f) // r - << true // degenerate - << QPlane3D() // plane (degenerate, meaning meaningless) - << QVector3D(0.0f, 0.0f, 3.5f/3.0f); // centroid - QTest::newRow("width 0 [a]") - << QVector3D(0.0f, 0.0f, 2.0f) // p - << QVector3D(0.0f, 0.0f, 2.0f) // q - << QVector3D(0.0f, 0.0f, 0.0f) // r - << true // degenerate - << QPlane3D() // plane (degenerate, meaning meaningless) - << QVector3D(0.0f, 0.0f, 4.0f/3.0f); // centroid - QTest::newRow("width 0 [b]") - << QVector3D(0.0f, 0.0f, 0.0f) // p - << QVector3D(0.0f, 0.0f, 0.0f) // q - << QVector3D(0.0f, 0.0f, 2.0f) // r - << true // degenerate - << QPlane3D() // plane (degenerate, meaning meaningless) - << QVector3D(0.0f, 0.0f, 2.0f/3.0f); // centroid - QTest::newRow("width 0 [c]") - << QVector3D(0.0f, 0.0f, 2.0f) // p - << QVector3D(0.0f, 0.0f, 2.0f) // q - << QVector3D(0.0f, 0.0f, 4.0f) // r - << true // degenerate - << QPlane3D() // plane (degenerate, meaning meaningless) - << QVector3D(0.0f, 0.0f, 8.0f/3.0f); // centroid - - /* The above only tests degenerate triangles colinear with the z axis. - May also want to tests degenerate triangles offset from origin and - degenerate triangles on other angles (e.g. x axis, y axis, not colinear - with any axis) - */ - - QTest::newRow("simple at origin") - << QVector3D(0.0f, 0.0f, 0.0f) // p - << QVector3D(0.0f, 4.0f, 0.0f) // q - << QVector3D(0.0f, 2.0f, 5.0f) // r - << false // degenerate - << QPlane3D(QVector3D(0.0f, 0.0f, 0.0f), QVector3D(1.0f, 0.0f, 0.0f)) // plane - << QVector3D(0.0f, 6.0f/3.0f, 5.0f/3.0f); // centroid - - QTest::newRow("simple offset from origin") - << QVector3D(1.0f, 1.0f, 0.0f) // p - << QVector3D(1.0f, 5.0f, 0.0f) // q - << QVector3D(1.0f, 3.0f, 5.0f) // r - << false // degenerate - << QPlane3D(QVector3D(1.0f, 0.0f, 0.0f), QVector3D(1.0f, 0.0f, 0.0f)) // plane - << QVector3D(1.0f, 3.0f, 5.0f/3.0f); // centroid -} - -void tst_QTriangle3D::create() -{ - QFETCH(QVector3D, p); - QFETCH(QVector3D, q); - QFETCH(QVector3D, r); - QFETCH(bool, isDegenerate); - QFETCH(QPlane3D, plane); - QFETCH(QVector3D, centroid); - - QTriangle3D triangle(p, q, r); - - QCOMPARE(triangle.p(), p); - QCOMPARE(triangle.q(), q); - QCOMPARE(triangle.r(), r); - - QCOMPARE(triangle.faceNormal(), QVector3D::crossProduct(q - p, r - q)); - - if (!isDegenerate) { - QPlane3D trianglePlane = triangle.plane(); - QVERIFY(plane.contains(trianglePlane.origin())); - QCOMPARE(plane.normal().normalized(), - trianglePlane.normal().normalized()); - } - QCOMPARE(triangle.center(), centroid); - - QTriangle3D triangle2; - triangle2.setP(p); - triangle2.setQ(q); - triangle2.setR(r); - QCOMPARE(triangle2.p(), p); - QCOMPARE(triangle2.q(), q); - QCOMPARE(triangle2.r(), r); - QVERIFY(triangle == triangle2); -} - -void tst_QTriangle3D::contains_data() -{ - QTest::addColumn<QVector3D>("p"); - QTest::addColumn<QVector3D>("q"); - QTest::addColumn<QVector3D>("r"); - QTest::addColumn<QVector3D>("point"); - QTest::addColumn<bool>("contains"); - - QTest::newRow("minimal at null, same") - << QVector3D(0.0f, 0.0f, 0.0f) // p - << QVector3D(0.0f, 0.0f, 0.0f) // q - << QVector3D(0.0f, 0.0f, 0.0f) // r - << QVector3D(0.0f, 0.0f, 0.0f) // point - << false; // contains - QTest::newRow("acute at p") - << QVector3D(1.0f, 2.0f, 2.0f) // p - << QVector3D(1.0f, 2.0f, 4.0f) // q - << QVector3D(1.0f, 3.0f, 3.0f) // r - << QVector3D(1.0f, 2.0f, 2.0f) // point - << true; // contains - QTest::newRow("acute at q") - << QVector3D(1.0f, 2.0f, 2.0f) // p - << QVector3D(1.0f, 2.0f, 4.0f) // q - << QVector3D(1.0f, 3.0f, 3.0f) // r - << QVector3D(1.0f, 2.0f, 4.0f) // point - << true; // contains - QTest::newRow("acute at r") - << QVector3D(1.0f, 2.0f, 2.0f) // p - << QVector3D(1.0f, 2.0f, 4.0f) // q - << QVector3D(1.0f, 3.0f, 3.0f) // r - << QVector3D(1.0f, 3.0f, 3.0f) // point - << true; // contains - QTest::newRow("acute at p-q") - << QVector3D(1.0f, 2.0f, 2.0f) // p - << QVector3D(1.0f, 2.0f, 4.0f) // q - << QVector3D(1.0f, 3.0f, 3.0f) // r - << QVector3D(1.0f, 2.0f, 3.0f) // point - << true; // contains - QTest::newRow("acute at p-r") - << QVector3D(1.0f, 2.0f, 2.0f) // p - << QVector3D(1.0f, 2.0f, 4.0f) // q - << QVector3D(1.0f, 3.0f, 3.0f) // r - << QVector3D(1.0f, 2.5f, 2.5f) // point - << true; // contains - QTest::newRow("acute at q-r") - << QVector3D(1.0f, 2.0f, 2.0f) // p - << QVector3D(1.0f, 2.0f, 4.0f) // q - << QVector3D(1.0f, 3.0f, 3.0f) // r - << QVector3D(1.0f, 2.5f, 3.5f) // point - << true; // contains - QTest::newRow("acute internal") - << QVector3D(1.0f, 2.0f, 2.0f) // p - << QVector3D(1.0f, 2.0f, 4.0f) // q - << QVector3D(1.0f, 3.0f, 3.0f) // r - << QVector3D(1.0f, 2.5f, 3.0f) // point - << true; // contains - QTest::newRow("acute external a") - << QVector3D(1.0f, 2.0f, 2.0f) // p - << QVector3D(1.0f, 2.0f, 4.0f) // q - << QVector3D(1.0f, 3.0f, 3.0f) // r - << QVector3D(1.0f, 2.8f, 2.0f) // point - << false; // contains - QTest::newRow("acute external b") - << QVector3D(1.0f, 2.0f, 2.0f) // p - << QVector3D(1.0f, 2.0f, 4.0f) // q - << QVector3D(1.0f, 3.0f, 3.0f) // r - << QVector3D(1.0f, 2.8f, 4.0f) // point - << false; // contains - QTest::newRow("acute external c") - << QVector3D(1.0f, 2.0f, 2.0f) // p - << QVector3D(1.0f, 2.0f, 4.0f) // q - << QVector3D(1.0f, 3.0f, 3.0f) // r - << QVector3D(1.0f, 1.4f, 3.0f) // point - << false; // contains - QTest::newRow("acute above plane") - << QVector3D(1.0f, 2.0f, 2.0f) // p - << QVector3D(1.0f, 2.0f, 4.0f) // q - << QVector3D(1.0f, 3.0f, 3.0f) // r - << QVector3D(1.3f, 2.5f, 3.0f) // point - << false; // contains - QTest::newRow("acute below plane") - << QVector3D(1.0f, 2.0f, 2.0f) // p - << QVector3D(1.0f, 2.0f, 4.0f) // q - << QVector3D(1.0f, 3.0f, 3.0f) // r - << QVector3D(0.8f, 2.5f, 3.0f) // point - << false; // contains - QTest::newRow("obtuse a") - << QVector3D(1.0f, 2.0f, 2.0f) // p - << QVector3D(1.0f, 2.0f, 4.0f) // q - << QVector3D(1.0f, 3.0f, 5.0f) // r - << QVector3D(1.0f, 2.5f, 4.8f) // point - << false; // contains - QTest::newRow("obtuse b") - << QVector3D(1.0f, 2.0f, 2.0f) // p - << QVector3D(1.0f, 2.0f, 4.0f) // q - << QVector3D(1.0f, 3.0f, 5.0f) // r - << QVector3D(1.0f, 2.5f, 4.3f) // point - << true; // contains - QTest::newRow("obtuse c") - << QVector3D(1.0f, 2.0f, 2.0f) // p - << QVector3D(1.0f, 2.0f, 4.0f) // q - << QVector3D(1.0f, 3.0f, 5.0f) // r - << QVector3D(1.0f, 2.5f, 4.5f) // point - << true; // contains - QTest::newRow("obtuse d") - << QVector3D(1.0f, 2.0f, 2.0f) // p - << QVector3D(1.0f, 2.0f, 4.0f) // q - << QVector3D(1.0f, 3.0f, 5.0f) // r - << QVector3D(1.2f, 2.5f, 4.3f) // point - << false; // contains - QTest::newRow("obtuse e") - << QVector3D(1.0f, 2.0f, 2.0f) // p - << QVector3D(1.0f, 2.0f, 4.0f) // q - << QVector3D(1.0f, 3.0f, 5.0f) // r - << QVector3D(0.8f, 2.5f, 4.3f) // point - << false; // contains -} - -void tst_QTriangle3D::contains() -{ - QFETCH(QVector3D, p); - QFETCH(QVector3D, q); - QFETCH(QVector3D, r); - QFETCH(QVector3D, point); - QFETCH(bool, contains); - // qDebug("Triangle: P(%0.10f, %0.10f, %0.10f) Q(%0.10f, %0.10f, %0.10f) R(%0.10f, %0.10f, %0.10f)", - // p.x(), p.y(), p.z(), q.x(), q.y(), q.z(), r.x(), r.y(), r.z()); - // qDebug("Point: (%0.10f, %0.10f, %0.10f)", point.x(), point.y(), point.z()); - QCOMPARE(QTriangle3D(p, q, r).contains(point), contains); -} - -void tst_QTriangle3D::intersect_data() -{ - QTest::addColumn<QVector3D>("p"); - QTest::addColumn<QVector3D>("q"); - QTest::addColumn<QVector3D>("r"); - QTest::addColumn<QVector3D>("origin"); - QTest::addColumn<QVector3D>("direction"); - QTest::addColumn<QVector3D>("intersection"); - QTest::addColumn<bool>("doesIntersect"); - - QTest::newRow("minimal at null, same") - << QVector3D(0.0f, 0.0f, 0.0f) // p - << QVector3D(0.0f, 0.0f, 0.0f) // q - << QVector3D(0.0f, 0.0f, 0.0f) // r - << QVector3D(0.0f, 0.0f, 0.0f) // origin - << QVector3D(0.0f, 0.0f, 1.0f) // direction - << QVector3D(0.0f, 0.0f, 0.0f) // intersection - << false; // degenerate triangles cannot intersect - - /* - lines perpendicular to triangle plane. - */ - QTest::newRow("acute at p") - << QVector3D(1.0f, 2.0f, 2.0f) // p - << QVector3D(1.0f, 2.0f, 4.0f) // q - << QVector3D(1.0f, 3.0f, 3.0f) // r - << QVector3D(0.0f, 2.0f, 2.0f) // origin - << QVector3D(1.0f, 0.0f, 0.0f) // direction - << QVector3D(1.0f, 2.0f, 2.0f) // intersection - << true; // intersects - QTest::newRow("acute at q") - << QVector3D(1.0f, 2.0f, 2.0f) // p - << QVector3D(1.0f, 2.0f, 4.0f) // q - << QVector3D(1.0f, 3.0f, 3.0f) // r - << QVector3D(0.0f, 2.0f, 4.0f) // origin - << QVector3D(1.0f, 0.0f, 0.0f) // direction - << QVector3D(1.0f, 2.0f, 4.0f) // intersection - << true; // intersects - QTest::newRow("acute at r") - << QVector3D(1.0f, 2.0f, 2.0f) // p - << QVector3D(1.0f, 2.0f, 4.0f) // q - << QVector3D(1.0f, 3.0f, 3.0f) // r - << QVector3D(0.0f, 3.0f, 3.0f) // origin - << QVector3D(1.0f, 0.0f, 0.0f) // direction - << QVector3D(1.0f, 3.0f, 3.0f) // intersection - << true; // intersects - QTest::newRow("acute at p-q") - << QVector3D(1.0f, 2.0f, 2.0f) // p - << QVector3D(1.0f, 2.0f, 4.0f) // q - << QVector3D(1.0f, 3.0f, 3.0f) // r - << QVector3D(0.0f, 2.0f, 3.0f) // origin - << QVector3D(1.0f, 0.0f, 0.0f) // direction - << QVector3D(1.0f, 2.0f, 3.0f) // intersection - << true; // intersects - QTest::newRow("acute at p-r") - << QVector3D(1.0f, 2.0f, 2.0f) // p - << QVector3D(1.0f, 2.0f, 4.0f) // q - << QVector3D(1.0f, 3.0f, 3.0f) // r - << QVector3D(0.0f, 2.5f, 2.5f) // origin - << QVector3D(1.0f, 0.0f, 0.0f) // direction - << QVector3D(1.0f, 2.5f, 2.5f) // intersection - << true; // intersects - QTest::newRow("acute at q-r") - << QVector3D(1.0f, 2.0f, 2.0f) // p - << QVector3D(1.0f, 2.0f, 4.0f) // q - << QVector3D(1.0f, 3.0f, 3.0f) // r - << QVector3D(0.0f, 2.5f, 3.5f) // origin - << QVector3D(1.0f, 0.0f, 0.0f) // direction - << QVector3D(1.0f, 2.5f, 3.5f) // intersection - << true; // intersects - QTest::newRow("acute internal") - << QVector3D(1.0f, 2.0f, 2.0f) // p - << QVector3D(1.0f, 2.0f, 4.0f) // q - << QVector3D(1.0f, 3.0f, 3.0f) // r - << QVector3D(0.0f, 2.5f, 3.0f) // origin - << QVector3D(1.0f, 0.0f, 0.0f) // direction - << QVector3D(1.0f, 2.5f, 3.0f) // intersection - << true; // intersects - QTest::newRow("acute external a") - << QVector3D(1.0f, 2.0f, 2.0f) // p - << QVector3D(1.0f, 2.0f, 4.0f) // q - << QVector3D(1.0f, 3.0f, 3.0f) // r - << QVector3D(0.0f, 2.8f, 2.0f) // origin - << QVector3D(1.0f, 0.0f, 0.0f) // direction - << QVector3D(0.0f, 0.0f, 0.0f) // intersection - << false; // intersects - QTest::newRow("acute external b") - << QVector3D(1.0f, 2.0f, 2.0f) // p - << QVector3D(1.0f, 2.0f, 4.0f) // q - << QVector3D(1.0f, 3.0f, 3.0f) // r - << QVector3D(0.0f, 2.8f, 4.0f) // origin - << QVector3D(1.0f, 0.0f, 0.0f) // direction - << QVector3D(0.0f, 0.0f, 0.0f) // intersection - << false; // intersects - QTest::newRow("acute external c") - << QVector3D(1.0f, 2.0f, 2.0f) // p - << QVector3D(1.0f, 2.0f, 4.0f) // q - << QVector3D(1.0f, 3.0f, 3.0f) // r - << QVector3D(0.0f, 1.4f, 3.0f) // origin - << QVector3D(1.0f, 0.0f, 0.0f) // direction - << QVector3D(0.0f, 0.0f, 0.0f) // intersection - << false; // intersects - QTest::newRow("obtuse a") - << QVector3D(1.0f, 2.0f, 2.0f) // p - << QVector3D(1.0f, 2.0f, 4.0f) // q - << QVector3D(1.0f, 3.0f, 5.0f) // r - << QVector3D(0.0f, 2.5f, 4.8f) // origin - << QVector3D(1.0f, 0.0f, 0.0f) // direction - << QVector3D(0.0f, 0.0f, 0.0f) // intersection - << false; // intersects - QTest::newRow("obtuse b") - << QVector3D(1.0f, 2.0f, 2.0f) // p - << QVector3D(1.0f, 2.0f, 4.0f) // q - << QVector3D(1.0f, 3.0f, 5.0f) // r - << QVector3D(0.0f, 2.5f, 4.3f) // origin - << QVector3D(1.0f, 0.0f, 0.0f) // direction - << QVector3D(1.0f, 2.5f, 4.3f) // intersection - << true; // intersects - QTest::newRow("obtuse c") - << QVector3D(1.0f, 2.0f, 2.0f) // p - << QVector3D(1.0f, 2.0f, 4.0f) // q - << QVector3D(1.0f, 3.0f, 5.0f) // r - << QVector3D(0.0f, 2.5f, 4.5f) // origin - << QVector3D(1.0f, 0.0f, 0.0f) // direction - << QVector3D(1.0f, 2.5f, 4.5f) // intersection - << true; // intersects - - QTest::newRow("in-triangle-plane") - << QVector3D(1.0f, 2.0f, 2.0f) // p - << QVector3D(1.0f, 2.0f, 4.0f) // q - << QVector3D(1.0f, 3.0f, 5.0f) // r - << QVector3D(1.0f, 2.0f, 2.0f) // origin (p) - << QVector3D(0.0f, 0.0f, 2.0f) // direction (q - p) - << QVector3D(0.0f, 0.0f, 0.0f) // intersection - << false; // intersects -} - -void tst_QTriangle3D::intersect() -{ - QFETCH(QVector3D, p); - QFETCH(QVector3D, q); - QFETCH(QVector3D, r); - QFETCH(QVector3D, origin); - QFETCH(QVector3D, direction); - QFETCH(QVector3D, intersection); - QFETCH(bool, doesIntersect); - - QTriangle3D triangle(p, q, r); - QRay3D line(origin, direction); - QCOMPARE(triangle.intersects(line), doesIntersect); - - qreal result = triangle.intersection(line); - if (doesIntersect) - QCOMPARE(line.point(result), intersection); - else - QVERIFY(qIsNaN(result)); -} - -void tst_QTriangle3D::uv_data() -{ - contains_data(); -} - -void tst_QTriangle3D::uv() -{ - QFETCH(QVector3D, p); - QFETCH(QVector3D, q); - QFETCH(QVector3D, r); - - if (p == q || p == r || q == r) - return; // Ignore degenerate triangles for this test. - - QTriangle3D triangle(p, q, r); - - QCOMPARE(triangle.uv(p), QVector2D(1, 0)); - QCOMPARE(triangle.uv(q), QVector2D(0, 1)); - QCOMPARE(triangle.uv(r), QVector2D(0, 0)); - - QCOMPARE(triangle.uv((p + q) / 2.0f), QVector2D(0.5f, 0.5f)); - QCOMPARE(triangle.uv((p + r) / 2.0f), QVector2D(0.5f, 0.0f)); - QCOMPARE(triangle.uv((q + r) / 2.0f), QVector2D(0.0f, 0.5f)); - - QVector2D v1(triangle.uv((p + q + r) / 3.0f)); - QVector2D v2(1.0f / 3.0f, 1.0f / 3.0f); - QVERIFY(qFuzzyCompare(float(v1.x()), float(v2.x()))); - QVERIFY(qFuzzyCompare(float(v1.y()), float(v2.y()))); -} - -void tst_QTriangle3D::transform_data() -{ - create_data(); -} - -void tst_QTriangle3D::transform() -{ - QFETCH(QVector3D, p); - QFETCH(QVector3D, q); - QFETCH(QVector3D, r); - - QMatrix4x4 m; - m.translate(-1.0f, 2.5f, 5.0f); - m.rotate(45.0f, 1.0f, 1.0f, 1.0f); - m.scale(23.5f); - - QTriangle3D tri1(p, q, r); - QTriangle3D tri2(tri1); - QTriangle3D tri3; - - tri1.transform(m); - tri3 = tri2.transformed(m); - - QCOMPARE(tri1.p(), tri3.p()); - QCOMPARE(tri1.q(), tri3.q()); - QCOMPARE(tri1.r(), tri3.r()); - - QCOMPARE(tri1.p(), m * p); - QCOMPARE(tri1.q(), m * q); - QCOMPARE(tri1.r(), m * r); -} - -void tst_QTriangle3D::compare() -{ - QVector3D p1(1.0f, 2.0f, 3.0f); - QVector3D q1(4.0f, 5.0f, 6.0f); - QVector3D r1(7.0f, 8.0f, 9.0f); - QVector3D p2(-1.0f, -2.0f, -3.0f); - QVector3D q2(-4.0f, -5.0f, -6.0f); - QVector3D r2(-7.0f, -8.0f, -9.0f); - - QTriangle3D tri1(p1, q1, r1); - QTriangle3D tri2(p1, q1, r1); - QVERIFY(tri1 == tri2); - QVERIFY(!(tri1 != tri2)); - QVERIFY(qFuzzyCompare(tri1, tri2)); - - QTriangle3D tri3(p2, q1, r1); - QVERIFY(tri1 != tri3); - QVERIFY(!(tri1 == tri3)); - QVERIFY(!qFuzzyCompare(tri1, tri3)); - - QTriangle3D tri4(p1, q2, r1); - QVERIFY(tri1 != tri4); - QVERIFY(!(tri1 == tri4)); - QVERIFY(!qFuzzyCompare(tri1, tri4)); - - QTriangle3D tri5(p1, q1, r2); - QVERIFY(tri1 != tri5); - QVERIFY(!(tri1 == tri5)); - QVERIFY(!qFuzzyCompare(tri1, tri5)); - - QTriangle3D tri6(p2, q2, r2); - QVERIFY(tri1 != tri6); - QVERIFY(!(tri1 == tri6)); - QVERIFY(!qFuzzyCompare(tri1, tri6)); -} - -void tst_QTriangle3D::dataStream() -{ -#ifndef QT_NO_DATASTREAM - QTriangle3D triangle(QVector3D(1.0f, 2.0f, 3.0f), - QVector3D(4.0f, 5.0f, 6.0f), - QVector3D(7.0f, 8.0f, 9.0f)); - - QByteArray data; - { - QDataStream stream(&data, QIODevice::WriteOnly); - stream << triangle; - } - - QTriangle3D triangle2; - { - QDataStream stream2(data); - stream2 >> triangle2; - } - - QVERIFY(triangle == triangle2); -#endif -} - -class tst_QTriangle3DProperties : public QObject -{ - Q_OBJECT - Q_PROPERTY(QTriangle3D triangle READ triangle WRITE setTriangle) -public: - tst_QTriangle3DProperties(QObject *parent = 0) : QObject(parent) {} - - QTriangle3D triangle() const { return t; } - void setTriangle(const QTriangle3D& value) { t = value; } - -private: - QTriangle3D t; -}; - -// Test getting and setting properties via the metaobject system. -void tst_QTriangle3D::properties() -{ - tst_QTriangle3DProperties obj; - - qRegisterMetaType<QTriangle3D>(); - - obj.setTriangle(QTriangle3D(QVector3D(1, 2, 3), QVector3D(4, 5, 6), - QVector3D(7, 8, 9))); - - QTriangle3D t = qVariantValue<QTriangle3D>(obj.property("triangle")); - QCOMPARE(t.p(), QVector3D(1, 2, 3)); - QCOMPARE(t.q(), QVector3D(4, 5, 6)); - QCOMPARE(t.r(), QVector3D(7, 8, 9)); - - obj.setProperty("triangle", - qVariantFromValue - (QTriangle3D(QVector3D(-1, -2, -3), - QVector3D(-4, -5, -6), - QVector3D(-7, -8, -9)))); - - t = qVariantValue<QTriangle3D>(obj.property("triangle")); - QCOMPARE(t.p(), QVector3D(-1, -2, -3)); - QCOMPARE(t.q(), QVector3D(-4, -5, -6)); - QCOMPARE(t.r(), QVector3D(-7, -8, -9)); -} - -void tst_QTriangle3D::metaTypes() -{ - int id = qMetaTypeId<QTriangle3D>(); - QVERIFY(QMetaType::type("QTriangle3D") == id); - QCOMPARE(QByteArray(QMetaType::typeName(id)), QByteArray("QTriangle3D")); - QVERIFY(QMetaType::isRegistered(id)); -} - -QTEST_APPLESS_MAIN(tst_QTriangle3D) - -#include "tst_qtriangle3d.moc" diff --git a/tests/auto/threed/qvectorarray/qvectorarray.pro b/tests/auto/threed/qvectorarray/qvectorarray.pro deleted file mode 100644 index 07677159..00000000 --- a/tests/auto/threed/qvectorarray/qvectorarray.pro +++ /dev/null @@ -1,7 +0,0 @@ -load(qttest_p4.prf) -TEMPLATE=app -QT += testlib -CONFIG += unittest warn_on qt3d - -INCLUDEPATH += ../../../shared -SOURCES += tst_qvectorarray.cpp diff --git a/tests/auto/threed/qvectorarray/tst_qvectorarray.cpp b/tests/auto/threed/qvectorarray/tst_qvectorarray.cpp deleted file mode 100644 index 74c6e389..00000000 --- a/tests/auto/threed/qvectorarray/tst_qvectorarray.cpp +++ /dev/null @@ -1,664 +0,0 @@ -/**************************************************************************** -** -** 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 QtQuick3D module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** 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. -** -** 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. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include <QtTest/QtTest> -#include <QtGui/qmatrix4x4.h> -#include "qvector2darray.h" -#include "qvector3darray.h" -#include "qvector4darray.h" -#include "qtest_helpers.h" - -class tst_QVectorArray : public QObject -{ - Q_OBJECT -public: - tst_QVectorArray() {} - ~tst_QVectorArray() {} - -private slots: - void create2DArray(); - void create3DArray(); - void create4DArray(); - - void scale_data(); - void scale(); - - void translateVector_data(); - void translateVector(); - - void translateExplicit_data(); - void translateExplicit(); - - void transform(); -}; - -void tst_QVectorArray::create2DArray() -{ - QVector2DArray array; - QVERIFY(array.isEmpty()); - - array.append(1.0f, 2.0f); - array.append(3.0f, 4.0f); - array.append(QVector2D(5.0f, 6.0f)); - array.append(QPointF(7.0f, 8.0f)); - array.append(QPoint(9, 10)); - - QCOMPARE(array.size(), 5); - QVERIFY(array[0] == QVector2D(1.0f, 2.0f)); - QVERIFY(array[1] == QVector2D(3.0f, 4.0f)); - QVERIFY(array[2] == QVector2D(5.0f, 6.0f)); - QVERIFY(array[3] == QVector2D(7.0f, 8.0f)); - QVERIFY(array[4] == QVector2D(9.0f, 10.0f)); - - array.append(QVector2D(11.0f, 12.0f), QVector2D(13.0f, 14.0f)); - array.append(QVector2D(15.0f, 16.0f), QVector2D(17.0f, 18.0f), - QVector2D(19.0f, 20.0f)); - array.append(QVector2D(21.0f, 22.0f), QVector2D(23.0f, 24.0f), - QVector2D(25.0f, 26.0f)); - - for (int index = 0; index < array.size(); ++index) - QVERIFY(array[index] == QVector2D(index * 2 + 1, index * 2 + 2)); - - QVector2DArray array2(34); - QCOMPARE(array2.size(), 34); - for (int index = 0; index < array2.size(); ++index) - QCOMPARE(array2[index], QVector2D(0.0f, 0.0f)); - - QVector2DArray array3(15, QVector2D(1.0f, 2.0f)); - QCOMPARE(array3.size(), 15); - for (int index = 0; index < array3.size(); ++index) - QCOMPARE(array3[index], QVector2D(1.0f, 2.0f)); -} - -void tst_QVectorArray::create3DArray() -{ - QVector3DArray array; - QVERIFY(array.isEmpty()); - - array.append(1.0f, 2.0f, 3.0f); - array.append(3.0f, 4.0f, 5.0f); - array.append(QVector3D(5.0f, 6.0f, 7.0f)); - - QCOMPARE(array.size(), 3); - QVERIFY(array[0] == QVector3D(1.0f, 2.0f, 3.0f)); - QVERIFY(array[1] == QVector3D(3.0f, 4.0f, 5.0f)); - QVERIFY(array[2] == QVector3D(5.0f, 6.0f, 7.0f)); - - array.append(QVector3D(7.0f, 8.0f, 9.0f), - QVector3D(9.0f, 10.0f, 11.0f)); - array.append(QVector3D(11.0f, 12.0f, 13.0f), - QVector3D(13.0f, 14.0f, 15.0f), - QVector3D(15.0f, 16.0f, 17.0f)); - array.append(QVector3D(17.0f, 18.0f, 19.0f), - QVector3D(19.0f, 20.0f, 21.0f), - QVector3D(21.0f, 22.0f, 23.0f)); - - for (int index = 0; index < array.size(); ++index) { - QVERIFY(array[index] == QVector3D(index * 2 + 1, - index * 2 + 2, - index * 2 + 3)); - } - - QVector3DArray array2(34); - QCOMPARE(array2.size(), 34); - for (int index = 0; index < array2.size(); ++index) - QCOMPARE(array2[index], QVector3D(0.0f, 0.0f, 0.0f)); - - QVector3DArray array3(15, QVector3D(1.0f, 2.0f, 3.0f)); - QCOMPARE(array3.size(), 15); - for (int index = 0; index < array3.size(); ++index) - QCOMPARE(array3[index], QVector3D(1.0f, 2.0f, 3.0f)); -} - -void tst_QVectorArray::create4DArray() -{ - QVector4DArray array; - QVERIFY(array.isEmpty()); - - array.append(1.0f, 2.0f, 3.0f, 4.0f); - array.append(3.0f, 4.0f, 5.0f, 6.0f); - array.append(QVector4D(5.0f, 6.0f, 7.0f, 8.0f)); - - QCOMPARE(array.size(), 3); - QVERIFY(array[0] == QVector4D(1.0f, 2.0f, 3.0f, 4.0f)); - QVERIFY(array[1] == QVector4D(3.0f, 4.0f, 5.0f, 6.0f)); - QVERIFY(array[2] == QVector4D(5.0f, 6.0f, 7.0f, 8.0f)); - - array.append(QVector4D(7.0f, 8.0f, 9.0f, 10.0f), - QVector4D(9.0f, 10.0f, 11.0f, 12.0f)); - array.append(QVector4D(11.0f, 12.0f, 13.0f, 14.0f), - QVector4D(13.0f, 14.0f, 15.0f, 16.0f), - QVector4D(15.0f, 16.0f, 17.0f, 18.0f)); - array.append(QVector4D(17.0f, 18.0f, 19.0f, 20.0f), - QVector4D(19.0f, 20.0f, 21.0f, 22.0f), - QVector4D(21.0f, 22.0f, 23.0f, 24.0f)); - - for (int index = 0; index < array.size(); ++index) { - QVERIFY(array[index] == QVector4D(index * 2 + 1, - index * 2 + 2, - index * 2 + 3, - index * 2 + 4)); - } - - QVector4DArray array2(34); - QCOMPARE(array2.size(), 34); - for (int index = 0; index < array2.size(); ++index) - QCOMPARE(array2[index], QVector4D(0.0f, 0.0f, 0.0f, 0.0f)); - - QVector4DArray array3(15, QVector4D(1.0f, 2.0f, 3.0f, 4.0f)); - QCOMPARE(array3.size(), 15); - for (int index = 0; index < array3.size(); ++index) - QCOMPARE(array3[index], QVector4D(1.0f, 2.0f, 3.0f, 4.0f)); -} - -void tst_QVectorArray::scale_data() -{ - QTest::addColumn<qreal>("scale"); - - QTest::newRow("zero") << qreal(0.0f); - QTest::newRow("one") << qreal(1.0f); - QTest::newRow("neg-one") << qreal(-1.0f); - QTest::newRow("two") << qreal(2.0f); - QTest::newRow("neg-two-point-five") << qreal(-2.5f); - QTest::newRow("half") << qreal(0.5f); -} - -void tst_QVectorArray::scale() -{ - QFETCH(qreal, scale); - - QVector2DArray v2array; - QVector3DArray v3array; - QVector4DArray v4array; - QVector2DArray v2arrayb; - QVector3DArray v3arrayb; - QVector4DArray v4arrayb; - - for (int index = 0; index < 64; ++index) { - v2array.append(index * 4, index * 4 + 1); - v3array.append(index * 4, index * 4 + 1, index * 4 + 2); - v4array.append(index * 4, index * 4 + 1, index * 4 + 2, - index * 4 + 3); - v2arrayb.append(index * 4, index * 4 + 1); - v3arrayb.append(index * 4, index * 4 + 1, index * 4 + 2); - v4arrayb.append(index * 4, index * 4 + 1, index * 4 + 2, - index * 4 + 3); - } - - // Perform a simple in-place scale. - - v2array.scale(scale); - v3array.scale(scale); - v4array.scale(scale); - - QCOMPARE(v2array.size(), 64); - QCOMPARE(v3array.size(), 64); - QCOMPARE(v4array.size(), 64); - - for (int index = 0; index < 64; ++index) { - QCOMPARE(v2array[index], - QVector2D((index * 4) * scale, (index * 4 + 1) * scale)); - QCOMPARE(v3array[index], - QVector3D((index * 4) * scale, (index * 4 + 1) * scale, - (index * 4 + 2) * scale)); - QCOMPARE(v4array[index], - QVector4D((index * 4) * scale, (index * 4 + 1) * scale, - (index * 4 + 2) * scale, (index * 4 + 3) * scale)); - } - - // Increase ref-count on an array and check that detach occurs. - - v2array = v2arrayb; - v3array = v3arrayb; - v4array = v4arrayb; - - QVERIFY(v2array.constData() == v2arrayb.constData()); - QVERIFY(v3array.constData() == v3arrayb.constData()); - QVERIFY(v4array.constData() == v4arrayb.constData()); - - v2array.scale(scale); - v3array.scale(scale); - v4array.scale(scale); - - QVERIFY(v2array.constData() != v2arrayb.constData()); - QVERIFY(v3array.constData() != v3arrayb.constData()); - QVERIFY(v4array.constData() != v4arrayb.constData()); - - QCOMPARE(v2array.size(), 64); - QCOMPARE(v3array.size(), 64); - QCOMPARE(v4array.size(), 64); - - for (int index = 0; index < 64; ++index) { - QCOMPARE(v2array[index], - QVector2D((index * 4) * scale, (index * 4 + 1) * scale)); - QCOMPARE(v3array[index], - QVector3D((index * 4) * scale, (index * 4 + 1) * scale, - (index * 4 + 2) * scale)); - QCOMPARE(v4array[index], - QVector4D((index * 4) * scale, (index * 4 + 1) * scale, - (index * 4 + 2) * scale, (index * 4 + 3) * scale)); - QCOMPARE(v2arrayb[index], - QVector2D(index * 4, index * 4 + 1)); - QCOMPARE(v3arrayb[index], - QVector3D(index * 4, index * 4 + 1, index * 4 + 2)); - QCOMPARE(v4arrayb[index], - QVector4D(index * 4, index * 4 + 1, - index * 4 + 2, index * 4 + 3)); - } - - // Perform the test again, with scaled() this time. - - v2array = v2arrayb.scaled(scale); - v3array = v3arrayb.scaled(scale); - v4array = v4arrayb.scaled(scale); - - QCOMPARE(v2array.size(), 64); - QCOMPARE(v3array.size(), 64); - QCOMPARE(v4array.size(), 64); - - for (int index = 0; index < 64; ++index) { - QCOMPARE(v2array[index], - QVector2D((index * 4) * scale, (index * 4 + 1) * scale)); - QCOMPARE(v3array[index], - QVector3D((index * 4) * scale, (index * 4 + 1) * scale, - (index * 4 + 2) * scale)); - QCOMPARE(v4array[index], - QVector4D((index * 4) * scale, (index * 4 + 1) * scale, - (index * 4 + 2) * scale, (index * 4 + 3) * scale)); - QCOMPARE(v2arrayb[index], - QVector2D(index * 4, index * 4 + 1)); - QCOMPARE(v3arrayb[index], - QVector3D(index * 4, index * 4 + 1, index * 4 + 2)); - QCOMPARE(v4arrayb[index], - QVector4D(index * 4, index * 4 + 1, - index * 4 + 2, index * 4 + 3)); - } -} - -void tst_QVectorArray::translateVector_data() -{ - QTest::addColumn<QVector4D>("translation"); - - QTest::newRow("zero") << QVector4D(0.0f, 0.0f, 0.0f, 0.0f); - QTest::newRow("x-axis") << QVector4D(1.0f, 0.0f, 0.0f, 0.0f); - QTest::newRow("y-axis") << QVector4D(0.0f, 1.0f, 0.0f, 0.0f); - QTest::newRow("z-axis") << QVector4D(0.0f, 0.0f, 1.0f, 0.0f); - QTest::newRow("w-axis") << QVector4D(0.0f, 0.0f, 0.0f, 1.0f); - QTest::newRow("all-axes") << QVector4D(1.0f, -2.0f, 3.5f, -1.5f); -} - -void tst_QVectorArray::translateVector() -{ - QFETCH(QVector4D, translation); - - QVector2DArray v2array; - QVector3DArray v3array; - QVector4DArray v4array; - QVector2DArray v2arrayb; - QVector3DArray v3arrayb; - QVector4DArray v4arrayb; - - for (int index = 0; index < 64; ++index) { - v2array.append(index * 4, index * 4 + 1); - v3array.append(index * 4, index * 4 + 1, index * 4 + 2); - v4array.append(index * 4, index * 4 + 1, index * 4 + 2, - index * 4 + 3); - v2arrayb.append(index * 4, index * 4 + 1); - v3arrayb.append(index * 4, index * 4 + 1, index * 4 + 2); - v4arrayb.append(index * 4, index * 4 + 1, index * 4 + 2, - index * 4 + 3); - } - - // Perform a simple in-place translate. - - v2array.translate(translation.toVector2D()); - v3array.translate(translation.toVector3D()); - v4array.translate(translation); - - QCOMPARE(v2array.size(), 64); - QCOMPARE(v3array.size(), 64); - QCOMPARE(v4array.size(), 64); - - for (int index = 0; index < 64; ++index) { - QCOMPARE(v2array[index], - QVector2D((index * 4) + translation.x(), - (index * 4 + 1) + translation.y())); - QCOMPARE(v3array[index], - QVector3D((index * 4) + translation.x(), - (index * 4 + 1) + translation.y(), - (index * 4 + 2) + translation.z())); - QCOMPARE(v4array[index], - QVector4D((index * 4) + translation.x(), - (index * 4 + 1) + translation.y(), - (index * 4 + 2) + translation.z(), - (index * 4 + 3) + translation.w())); - } - - // Increase ref-count on an array and check that detach occurs. - - v2array = v2arrayb; - v3array = v3arrayb; - v4array = v4arrayb; - - QVERIFY(v2array.constData() == v2arrayb.constData()); - QVERIFY(v3array.constData() == v3arrayb.constData()); - QVERIFY(v4array.constData() == v4arrayb.constData()); - - v2array.translate(translation.toVector2D()); - v3array.translate(translation.toVector3D()); - v4array.translate(translation); - - QVERIFY(v2array.constData() != v2arrayb.constData()); - QVERIFY(v3array.constData() != v3arrayb.constData()); - QVERIFY(v4array.constData() != v4arrayb.constData()); - - QCOMPARE(v2array.size(), 64); - QCOMPARE(v3array.size(), 64); - QCOMPARE(v4array.size(), 64); - - for (int index = 0; index < 64; ++index) { - QCOMPARE(v2array[index], - QVector2D((index * 4) + translation.x(), - (index * 4 + 1) + translation.y())); - QCOMPARE(v3array[index], - QVector3D((index * 4) + translation.x(), - (index * 4 + 1) + translation.y(), - (index * 4 + 2) + translation.z())); - QCOMPARE(v4array[index], - QVector4D((index * 4) + translation.x(), - (index * 4 + 1) + translation.y(), - (index * 4 + 2) + translation.z(), - (index * 4 + 3) + translation.w())); - QCOMPARE(v2arrayb[index], - QVector2D(index * 4, index * 4 + 1)); - QCOMPARE(v3arrayb[index], - QVector3D(index * 4, index * 4 + 1, index * 4 + 2)); - QCOMPARE(v4arrayb[index], - QVector4D(index * 4, index * 4 + 1, - index * 4 + 2, index * 4 + 3)); - } - - // Perform the test again, with translated() this time. - - v2array = v2arrayb.translated(translation.toVector2D()); - v3array = v3arrayb.translated(translation.toVector3D()); - v4array = v4arrayb.translated(translation); - - QCOMPARE(v2array.size(), 64); - QCOMPARE(v3array.size(), 64); - QCOMPARE(v4array.size(), 64); - - for (int index = 0; index < 64; ++index) { - QCOMPARE(v2array[index], - QVector2D((index * 4) + translation.x(), - (index * 4 + 1) + translation.y())); - QCOMPARE(v3array[index], - QVector3D((index * 4) + translation.x(), - (index * 4 + 1) + translation.y(), - (index * 4 + 2) + translation.z())); - QCOMPARE(v4array[index], - QVector4D((index * 4) + translation.x(), - (index * 4 + 1) + translation.y(), - (index * 4 + 2) + translation.z(), - (index * 4 + 3) + translation.w())); - QCOMPARE(v2arrayb[index], - QVector2D(index * 4, index * 4 + 1)); - QCOMPARE(v3arrayb[index], - QVector3D(index * 4, index * 4 + 1, index * 4 + 2)); - QCOMPARE(v4arrayb[index], - QVector4D(index * 4, index * 4 + 1, - index * 4 + 2, index * 4 + 3)); - } -} - -void tst_QVectorArray::translateExplicit_data() -{ - translateVector_data(); -} - -void tst_QVectorArray::translateExplicit() -{ - QFETCH(QVector4D, translation); - - QVector2DArray v2array; - QVector3DArray v3array; - QVector4DArray v4array; - QVector2DArray v2arrayb; - QVector3DArray v3arrayb; - QVector4DArray v4arrayb; - - for (int index = 0; index < 64; ++index) { - v2array.append(index * 4, index * 4 + 1); - v3array.append(index * 4, index * 4 + 1, index * 4 + 2); - v4array.append(index * 4, index * 4 + 1, index * 4 + 2, - index * 4 + 3); - v2arrayb.append(index * 4, index * 4 + 1); - v3arrayb.append(index * 4, index * 4 + 1, index * 4 + 2); - v4arrayb.append(index * 4, index * 4 + 1, index * 4 + 2, - index * 4 + 3); - } - - // Perform a simple in-place translate. - - v2array.translate(translation.x(), translation.y()); - v3array.translate(translation.x(), translation.y(), translation.z()); - v4array.translate(translation.x(), translation.y(), - translation.z(), translation.w()); - - QCOMPARE(v2array.size(), 64); - QCOMPARE(v3array.size(), 64); - QCOMPARE(v4array.size(), 64); - - for (int index = 0; index < 64; ++index) { - QCOMPARE(v2array[index], - QVector2D((index * 4) + translation.x(), - (index * 4 + 1) + translation.y())); - QCOMPARE(v3array[index], - QVector3D((index * 4) + translation.x(), - (index * 4 + 1) + translation.y(), - (index * 4 + 2) + translation.z())); - QCOMPARE(v4array[index], - QVector4D((index * 4) + translation.x(), - (index * 4 + 1) + translation.y(), - (index * 4 + 2) + translation.z(), - (index * 4 + 3) + translation.w())); - } - - // Perform the test again, with translated() this time. - - v2array = v2arrayb.translated(translation.x(), translation.y()); - v3array = v3arrayb.translated(translation.x(), translation.y(), - translation.z()); - v4array = v4arrayb.translated(translation.x(), translation.y(), - translation.z(), translation.w()); - - QCOMPARE(v2array.size(), 64); - QCOMPARE(v3array.size(), 64); - QCOMPARE(v4array.size(), 64); - - for (int index = 0; index < 64; ++index) { - QCOMPARE(v2array[index], - QVector2D((index * 4) + translation.x(), - (index * 4 + 1) + translation.y())); - QCOMPARE(v3array[index], - QVector3D((index * 4) + translation.x(), - (index * 4 + 1) + translation.y(), - (index * 4 + 2) + translation.z())); - QCOMPARE(v4array[index], - QVector4D((index * 4) + translation.x(), - (index * 4 + 1) + translation.y(), - (index * 4 + 2) + translation.z(), - (index * 4 + 3) + translation.w())); - QCOMPARE(v2arrayb[index], - QVector2D(index * 4, index * 4 + 1)); - QCOMPARE(v3arrayb[index], - QVector3D(index * 4, index * 4 + 1, index * 4 + 2)); - QCOMPARE(v4arrayb[index], - QVector4D(index * 4, index * 4 + 1, - index * 4 + 2, index * 4 + 3)); - } -} - -static bool fuzzyCompare(const QVector2D &v1, const QVector2D &v2) -{ - return qAbs(v1.x() - v2.x()) <= 0.00001 && - qAbs(v1.y() - v2.y()) <= 0.00001; -} - -static bool fuzzyCompare(const QVector3D &v1, const QVector3D &v2) -{ - return qAbs(v1.x() - v2.x()) <= 0.00001 && - qAbs(v1.y() - v2.y()) <= 0.00001 && - qAbs(v1.z() - v2.z()) <= 0.00001; -} - -static bool fuzzyCompare(const QVector4D &v1, const QVector4D &v2) -{ - return qAbs(v1.x() - v2.x()) <= 0.00001 && - qAbs(v1.y() - v2.y()) <= 0.00001 && - qAbs(v1.z() - v2.z()) <= 0.00001 && - qAbs(v1.w() - v2.w()) <= 0.00001; -} - -void tst_QVectorArray::transform() -{ - QMatrix4x4 m; - m.translate(-1.0f, 2.5f, 5.0f); - m.rotate(45.0f, 1.0f, 1.0f, 1.0f); - m.scale(23.5f); - - QVector2DArray v2array; - QVector3DArray v3array; - QVector4DArray v4array; - QVector2DArray v2arrayb; - QVector3DArray v3arrayb; - QVector4DArray v4arrayb; - - for (int index = 0; index < 64; ++index) { - v2array.append(index * 4, index * 4 + 1); - v3array.append(index * 4, index * 4 + 1, index * 4 + 2); - v4array.append(index * 4, index * 4 + 1, index * 4 + 2, - index * 4 + 3); - v2arrayb.append(index * 4, index * 4 + 1); - v3arrayb.append(index * 4, index * 4 + 1, index * 4 + 2); - v4arrayb.append(index * 4, index * 4 + 1, index * 4 + 2, - index * 4 + 3); - } - - // Perform a simple in-place transform. - - v2array.transform(m); - v3array.transform(m); - v4array.transform(m); - - QCOMPARE(v2array.size(), 64); - QCOMPARE(v3array.size(), 64); - QCOMPARE(v4array.size(), 64); - - for (int index = 0; index < 64; ++index) { - QVector2D v2(index * 4, index * 4 + 1); - QVector3D v3(index * 4, index * 4 + 1, index * 4 + 2); - QVector4D v4(index * 4, index * 4 + 1, index * 4 + 2, index * 4 + 3); - QVERIFY(fuzzyCompare(v2array[index], (m * QVector3D(v2)).toVector2D())); - QVERIFY(fuzzyCompare(v3array[index], m * v3)); - QVERIFY(fuzzyCompare(v4array[index], m * v4)); - } - - // Increase ref-count on an array and check that detach occurs. - - v2array = v2arrayb; - v3array = v3arrayb; - v4array = v4arrayb; - - QVERIFY(v2array.constData() == v2arrayb.constData()); - QVERIFY(v3array.constData() == v3arrayb.constData()); - QVERIFY(v4array.constData() == v4arrayb.constData()); - - v2array.transform(m); - v3array.transform(m); - v4array.transform(m); - - QVERIFY(v2array.constData() != v2arrayb.constData()); - QVERIFY(v3array.constData() != v3arrayb.constData()); - QVERIFY(v4array.constData() != v4arrayb.constData()); - - QCOMPARE(v2array.size(), 64); - QCOMPARE(v3array.size(), 64); - QCOMPARE(v4array.size(), 64); - - for (int index = 0; index < 64; ++index) { - QVector2D v2(index * 4, index * 4 + 1); - QVector3D v3(index * 4, index * 4 + 1, index * 4 + 2); - QVector4D v4(index * 4, index * 4 + 1, index * 4 + 2, index * 4 + 3); - QVERIFY(fuzzyCompare(v2array[index], (m * QVector3D(v2)).toVector2D())); - QVERIFY(fuzzyCompare(v3array[index], m * v3)); - QVERIFY(fuzzyCompare(v4array[index], m * v4)); - QVERIFY(fuzzyCompare(v2arrayb[index], v2)); - QVERIFY(fuzzyCompare(v3arrayb[index], v3)); - QVERIFY(fuzzyCompare(v4arrayb[index], v4)); - } - - // Perform the test again, with translated() this time. - - v2array = v2arrayb.transformed(m); - v3array = v3arrayb.transformed(m); - v4array = v4arrayb.transformed(m); - - QCOMPARE(v2array.size(), 64); - QCOMPARE(v3array.size(), 64); - QCOMPARE(v4array.size(), 64); - - for (int index = 0; index < 64; ++index) { - QVector2D v2(index * 4, index * 4 + 1); - QVector3D v3(index * 4, index * 4 + 1, index * 4 + 2); - QVector4D v4(index * 4, index * 4 + 1, index * 4 + 2, index * 4 + 3); - QVERIFY(fuzzyCompare(v2array[index], (m * QVector3D(v2)).toVector2D())); - QVERIFY(fuzzyCompare(v3array[index], m * v3)); - QVERIFY(fuzzyCompare(v4array[index], m * v4)); - QVERIFY(fuzzyCompare(v2arrayb[index], v2)); - QVERIFY(fuzzyCompare(v3arrayb[index], v3)); - QVERIFY(fuzzyCompare(v4arrayb[index], v4)); - } -} - -QTEST_APPLESS_MAIN(tst_QVectorArray) - -#include "tst_qvectorarray.moc" diff --git a/tests/auto/threed/threed.pro b/tests/auto/threed/threed.pro deleted file mode 100644 index 7e029ae1..00000000 --- a/tests/auto/threed/threed.pro +++ /dev/null @@ -1,40 +0,0 @@ -TEMPLATE = subdirs -SUBDIRS = \ - qareaallocator \ - qarray \ - qbox3d \ - qcolor4ub \ - qcustomdataarray \ - qgeometrydata \ - qglabstractsurface \ - qglattributedescription \ - qglattributeset \ - qglattributevalue \ - qglbezierpatches \ - qglbuilder \ - qglcamera \ - qglcameraanimation \ - qglcube \ - qglindexbuffer \ - qgllightmodel \ - qgllightparameters \ - qglmaterial \ - qglmaterialcollection \ - qglpainter \ - qglpickcolors \ - qglrender \ - qglscenenode \ - qglsection \ - qglsharedresource \ - qglsphere \ - qglvertexbundle \ - qgraphicstransform3d \ - qopenglfunctions \ - qplane3d \ - qray3d \ - qglcylinder \ - qsphere3d \ - qtriangle3d \ - qvectorarray \ - load_model \ - qglcolladafxeffectfactory |