2 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
4 // Licensed under the Flora License, Version 1.0 (the License);
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
8 // http://floralicense.org/license/
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an AS IS BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
22 #include <dali/public-api/dali-core.h>
24 #include <dali-test-suite-utils.h>
28 #include <mesh-builder.h>
30 static void Startup();
31 static void Cleanup();
34 void (*tet_startup)() = Startup;
35 void (*tet_cleanup)() = Cleanup;
39 POSITIVE_TC_IDX = 0x01,
43 #define MAX_NUMBER_OF_TESTS 10000
45 struct tet_testlist tet_testlist[MAX_NUMBER_OF_TESTS];
48 // Add test functionality for all APIs in the class (Positive and Negative)
49 TEST_FUNCTION( UtcDaliMeshDataNew, POSITIVE_TC_IDX );
50 TEST_FUNCTION( UtcDaliMeshDataSetData, POSITIVE_TC_IDX );
51 TEST_FUNCTION( UtcDaliMeshDataAddToBoundingVolume, POSITIVE_TC_IDX );
52 TEST_FUNCTION( UtcDaliMeshDataBoundingBox, POSITIVE_TC_IDX );
53 TEST_FUNCTION( UtcDaliMeshDataGetVertexCount, POSITIVE_TC_IDX );
54 TEST_FUNCTION( UtcDaliMeshDataGetVertices, POSITIVE_TC_IDX );
55 TEST_FUNCTION( UtcDaliMeshDataGetFaceCount, POSITIVE_TC_IDX );
56 TEST_FUNCTION( UtcDaliMeshDataGetFaces, POSITIVE_TC_IDX );
57 TEST_FUNCTION( UtcDaliMeshDataTextureCoords, POSITIVE_TC_IDX );
58 TEST_FUNCTION( UtcDaliMeshDataNormals, POSITIVE_TC_IDX );
59 TEST_FUNCTION( UtcDaliMeshDataGetMaterial, POSITIVE_TC_IDX );
60 TEST_FUNCTION( UtcDaliMeshDataSetMaterial, POSITIVE_TC_IDX );
61 TEST_FUNCTION( UtcDaliMeshDataGetBoneCount, POSITIVE_TC_IDX );
62 TEST_FUNCTION( UtcDaliMeshDataGetBones, POSITIVE_TC_IDX );
64 // Called only once before first test is run.
69 // Called only once after last test is run
76 static void UtcDaliMeshDataNew()
78 TestApplication application;
81 DALI_TEST_EQUALS(meshData.HasNormals(), false, TEST_LOCATION);
82 DALI_TEST_EQUALS(meshData.HasTextureCoords(), false, TEST_LOCATION);
86 static void UtcDaliMeshDataSetData()
88 TestApplication application;
91 MeshData::VertexContainer vertices;
92 MeshData::FaceIndices faces;
94 ConstructVertices(vertices, 60);
95 ConstructFaces(vertices, faces);
96 Material customMaterial = ConstructMaterial();
97 meshData.SetData(vertices, faces, bones, customMaterial);
99 DALI_TEST_GREATER(meshData.GetVertexCount(), 0u, TEST_LOCATION);
100 DALI_TEST_GREATER(meshData.GetFaceCount(), 0u, TEST_LOCATION);
102 const MeshData::FaceIndices& faces2 = meshData.GetFaces();
103 const MeshData::VertexContainer& verts2 = meshData.GetVertices();
104 DALI_TEST_EQUALS(faces.at(0), faces2.at(0), TEST_LOCATION);
105 DALI_TEST_EQUALS(vertices.at(1).y, verts2.at(1).y, TEST_LOCATION);
106 DALI_TEST_EQUALS(meshData.GetBoneCount(), static_cast<size_t>(0), TEST_LOCATION);
109 static void UtcDaliMeshDataAddToBoundingVolume()
111 TestApplication application;
116 MeshData::VertexContainer vertices;
117 MeshData::FaceIndices faces;
119 ConstructVertices(vertices, sz);
120 ConstructFaces(vertices, faces);
121 Material customMaterial = ConstructMaterial();
122 meshData.SetData(vertices, faces, bones, customMaterial);
124 Vector4 upper(-1e10f, -1e10f, -1e10f, 0.0f);
125 Vector4 lower(1e10f, 1e10f, 1e10f, 0.0f);
127 f.SetIdentityAndScale(Vector3(2.0f, 2.0f, 2.0f));
128 meshData.AddToBoundingVolume(lower, upper, f);
130 Vector4 min(-sz*0.5f, -sz, -sz*0.7f, 0.0f);
131 Vector4 max( sz*0.5f, sz*0.3f, sz*0.5f, 0.0f);
133 // Test that upper and lower bounds are set and transformed
134 DALI_TEST_EQUALS(lower, min*2.0f, 0.001, TEST_LOCATION);
135 DALI_TEST_EQUALS(upper, max*2.0f, 0.001, TEST_LOCATION);
137 // Test that mesh's upper and lower bounds are set and not transformed
138 DALI_TEST_EQUALS(meshData.GetBoundingBoxMin(), min, 0.001, TEST_LOCATION);
139 DALI_TEST_EQUALS(meshData.GetBoundingBoxMax(), max, 0.001, TEST_LOCATION);
142 static void UtcDaliMeshDataBoundingBox()
144 TestApplication application;
148 Vector4 min(-1.0f, -2.0f, -3.0f, 0.0f);
149 Vector4 max(1.0f, 2.0f, 3.0f, 0.0f);
150 meshData.SetBoundingBoxMin(min);
151 meshData.SetBoundingBoxMax(max);
152 DALI_TEST_EQUALS(meshData.GetBoundingBoxMin(), min, 0.001, TEST_LOCATION);
153 DALI_TEST_EQUALS(meshData.GetBoundingBoxMax(), max, 0.001, TEST_LOCATION);
155 MeshData::VertexContainer vertices;
156 MeshData::FaceIndices faces;
158 ConstructVertices(vertices, sz);
159 ConstructFaces(vertices, faces);
160 Material customMaterial = ConstructMaterial();
161 meshData.SetData(vertices, faces, bones, customMaterial);
163 // Check bounding box hasn't changed
164 DALI_TEST_EQUALS(meshData.GetBoundingBoxMin(), min, 0.001, TEST_LOCATION);
165 DALI_TEST_EQUALS(meshData.GetBoundingBoxMax(), max, 0.001, TEST_LOCATION);
167 Vector4 upper(-1e10f, -1e10f, -1e10f, 0.0f);
168 Vector4 lower(1e10f, 1e10f, 1e10f, 0.0f);
169 meshData.AddToBoundingVolume(lower, upper, Matrix::IDENTITY);
171 // Bounding box should have been update
172 Vector4 bbMin(-sz*0.5f, -sz, -sz*0.7f, 0.0f);
173 Vector4 bbMax( sz*0.5f, sz*0.3f, sz*0.5f, 0.0f);
175 // Test that upper and lower bounds are set and transformed
176 DALI_TEST_EQUALS(lower, bbMin, 0.001, TEST_LOCATION);
177 DALI_TEST_EQUALS(upper, bbMax, 0.001, TEST_LOCATION);
179 // Test that mesh's upper and lower bounds are set and not transformed
180 DALI_TEST_EQUALS(meshData.GetBoundingBoxMin(), bbMin, 0.001, TEST_LOCATION);
181 DALI_TEST_EQUALS(meshData.GetBoundingBoxMax(), bbMax, 0.001, TEST_LOCATION);
184 static void UtcDaliMeshDataGetVertexCount ()
186 TestApplication application;
189 MeshData::VertexContainer vertices;
190 MeshData::FaceIndices faces;
192 ConstructVertices(vertices, 30);
193 ConstructFaces(vertices, faces);
194 Material customMaterial = ConstructMaterial();
196 DALI_TEST_EQUALS(meshData.GetVertexCount(), static_cast<size_t>(0), TEST_LOCATION);
198 meshData.SetData(vertices, faces, bones, customMaterial);
199 DALI_TEST_EQUALS(meshData.GetVertexCount(), vertices.size(), TEST_LOCATION);
203 static void UtcDaliMeshDataGetVertices ()
205 TestApplication application;
207 const Dali::MeshData::VertexContainer& verts1 = meshData.GetVertices();
208 DALI_TEST_CHECK(verts1.size() == 0);
210 MeshData::VertexContainer vertices;
211 MeshData::FaceIndices faces;
213 ConstructVertices(vertices, 30);
214 ConstructFaces(vertices, faces);
215 Material customMaterial = ConstructMaterial();
216 meshData.SetData(vertices, faces, bones, customMaterial);
218 const Dali::MeshData::VertexContainer& verts2 = meshData.GetVertices();
219 DALI_TEST_CHECK(verts2.size() != 0);
220 DALI_TEST_CHECK(verts2.size() == meshData.GetVertexCount());
223 static void UtcDaliMeshDataGetFaceCount ()
225 TestApplication application;
227 DALI_TEST_EQUALS(meshData.GetFaceCount(), static_cast<size_t>(0), TEST_LOCATION);
229 MeshData::VertexContainer vertices;
230 MeshData::FaceIndices faces;
232 ConstructVertices(vertices, 30);
233 ConstructFaces(vertices, faces);
234 Material customMaterial = ConstructMaterial();
235 meshData.SetData(vertices, faces, bones, customMaterial);
237 DALI_TEST_EQUALS(meshData.GetFaceCount(), faces.size() / 3, TEST_LOCATION);
240 static void UtcDaliMeshDataGetFaces ()
242 TestApplication application;
244 const Dali::MeshData::FaceIndices& faces1 = meshData.GetFaces();
245 DALI_TEST_CHECK(faces1.size() == 0);
247 MeshData::VertexContainer vertices;
248 MeshData::FaceIndices faces;
250 ConstructVertices(vertices, 30);
251 ConstructFaces(vertices, faces);
252 Material customMaterial = ConstructMaterial();
253 meshData.SetData(vertices, faces, bones, customMaterial);
255 const Dali::MeshData::FaceIndices& faces2 = meshData.GetFaces();
256 DALI_TEST_CHECK(faces2.size() != 0);
259 static void UtcDaliMeshDataTextureCoords ()
261 TestApplication application;
263 DALI_TEST_EQUALS(meshData.HasTextureCoords(), false, TEST_LOCATION);
264 meshData.SetHasTextureCoords(true);
265 DALI_TEST_EQUALS(meshData.HasTextureCoords(), true, TEST_LOCATION);
268 static void UtcDaliMeshDataNormals ()
270 TestApplication application;
272 DALI_TEST_EQUALS(meshData.HasNormals(), false, TEST_LOCATION);
273 meshData.SetHasNormals(true);
274 DALI_TEST_EQUALS(meshData.HasNormals(), true, TEST_LOCATION);
277 static void UtcDaliMeshDataGetMaterial ()
279 TestApplication application;
281 Material aMat = meshData.GetMaterial();
282 DALI_TEST_CHECK(!aMat);
284 MeshData::VertexContainer vertices;
285 MeshData::FaceIndices faces;
287 ConstructVertices(vertices, 30);
288 ConstructFaces(vertices, faces);
289 Material customMaterial = ConstructMaterial();
290 meshData.SetData(vertices, faces, bones, customMaterial);
292 aMat = meshData.GetMaterial();
293 DALI_TEST_CHECK(aMat);
296 static void UtcDaliMeshDataSetMaterial ()
298 TestApplication application;
301 Material aMat = meshData.GetMaterial();
302 DALI_TEST_CHECK(!aMat);
304 Material mat1 = ConstructMaterial();
305 meshData.SetMaterial(mat1);
306 aMat = meshData.GetMaterial();
307 DALI_TEST_CHECK(mat1 == aMat);
309 MeshData::VertexContainer vertices;
310 MeshData::FaceIndices faces;
312 ConstructVertices(vertices, 30);
313 ConstructFaces(vertices, faces);
314 Material customMaterial = ConstructMaterial();
315 meshData.SetData(vertices, faces, bones, customMaterial);
317 aMat = meshData.GetMaterial();
319 DALI_TEST_CHECK(aMat == customMaterial);
320 DALI_TEST_CHECK(aMat != mat1);
324 static void UtcDaliMeshDataGetBoneCount ()
326 TestApplication application;
328 DALI_TEST_EQUALS(meshData.GetBoneCount(), static_cast<size_t>(0), TEST_LOCATION);
329 DALI_TEST_EQUALS(meshData.HasBones(), false, TEST_LOCATION);
331 MeshData::VertexContainer vertices;
332 MeshData::FaceIndices faces;
334 ConstructVertices(vertices, 30);
335 ConstructFaces(vertices, faces);
336 ConstructBones(bones);
337 Material customMaterial = ConstructMaterial();
338 meshData.SetData(vertices, faces, bones, customMaterial);
340 DALI_TEST_EQUALS(meshData.GetBoneCount(), static_cast<size_t>(3), TEST_LOCATION);
341 DALI_TEST_EQUALS(meshData.HasBones(), true, TEST_LOCATION);
345 static void UtcDaliMeshDataGetBones ()
347 TestApplication application;
349 DALI_TEST_EQUALS(meshData.GetBoneCount(), static_cast<size_t>(0), TEST_LOCATION);
350 const BoneContainer& bones1 = meshData.GetBones();
351 DALI_TEST_CHECK(bones1.empty());
353 MeshData::VertexContainer vertices;
354 MeshData::FaceIndices faces;
356 ConstructVertices(vertices, 30);
357 ConstructFaces(vertices, faces);
358 ConstructBones(bones);
359 Material customMaterial = ConstructMaterial();
360 meshData.SetData(vertices, faces, bones, customMaterial);
361 const BoneContainer& bones3 = meshData.GetBones();
362 DALI_TEST_CHECK( ! bones3.empty() );