(AutomatedTests) Merged managed & unmanaged tests
[platform/core/uifw/dali-core.git] / automated-tests / src / dali / utc-Dali-MeshData.cpp
1 /*
2  * Copyright (c) 2014 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  *
16  */
17
18 #include <iostream>
19
20 #include <stdlib.h>
21 #include <dali/public-api/dali-core.h>
22 #include <dali-test-suite-utils.h>
23
24 using namespace Dali;
25
26 #include "mesh-builder.h"
27
28
29
30 int UtcDaliMeshDataNew(void)
31 {
32   TestApplication application;
33   MeshData meshData;
34
35   DALI_TEST_EQUALS(meshData.HasNormals(), false, TEST_LOCATION);
36   DALI_TEST_EQUALS(meshData.HasTextureCoords(), false, TEST_LOCATION);
37   END_TEST;
38 }
39
40
41 int UtcDaliMeshDataSetData(void)
42 {
43   TestApplication application;
44
45   MeshData meshData;
46   MeshData::VertexContainer    vertices;
47   MeshData::FaceIndices        faces;
48   BoneContainer                bones;
49   ConstructVertices(vertices, 60);
50   ConstructFaces(vertices, faces);
51   Material customMaterial = ConstructMaterial();
52   meshData.SetData(vertices, faces, bones, customMaterial);
53
54   DALI_TEST_GREATER(meshData.GetVertexCount(), 0u, TEST_LOCATION);
55   DALI_TEST_GREATER(meshData.GetFaceCount(), 0u, TEST_LOCATION);
56
57   const MeshData::FaceIndices& faces2 = meshData.GetFaces();
58   const MeshData::VertexContainer& verts2 = meshData.GetVertices();
59   DALI_TEST_EQUALS(faces.at(0), faces2.at(0), TEST_LOCATION);
60   DALI_TEST_EQUALS(vertices.at(1).y, verts2.at(1).y, TEST_LOCATION);
61   DALI_TEST_EQUALS(meshData.GetBoneCount(), static_cast<size_t>(0), TEST_LOCATION);
62   END_TEST;
63 }
64
65 int UtcDaliMeshDataAddToBoundingVolume(void)
66 {
67   TestApplication application;
68
69   float sz=40.0f;
70
71   MeshData meshData;
72   MeshData::VertexContainer    vertices;
73   MeshData::FaceIndices        faces;
74   BoneContainer                bones;
75   ConstructVertices(vertices, sz);
76   ConstructFaces(vertices, faces);
77   Material customMaterial = ConstructMaterial();
78   meshData.SetData(vertices, faces, bones, customMaterial);
79
80   Vector4 upper(-1e10f, -1e10f, -1e10f, 0.0f);
81   Vector4 lower(1e10f, 1e10f, 1e10f, 0.0f);
82   Matrix f(false);
83   f.SetIdentityAndScale(Vector3(2.0f, 2.0f, 2.0f));
84   meshData.AddToBoundingVolume(lower, upper, f);
85
86   Vector4 min(-sz*0.5f, -sz,      -sz*0.7f, 0.0f);
87   Vector4 max( sz*0.5f,  sz*0.3f,  sz*0.5f, 0.0f);
88
89   // Test that upper and lower bounds are set and transformed
90   DALI_TEST_EQUALS(lower, min*2.0f, 0.001, TEST_LOCATION);
91   DALI_TEST_EQUALS(upper, max*2.0f, 0.001, TEST_LOCATION);
92
93   // Test that mesh's upper and lower bounds are set and not transformed
94   DALI_TEST_EQUALS(meshData.GetBoundingBoxMin(), min, 0.001, TEST_LOCATION);
95   DALI_TEST_EQUALS(meshData.GetBoundingBoxMax(), max, 0.001, TEST_LOCATION);
96   END_TEST;
97 }
98
99 int UtcDaliMeshDataBoundingBox(void)
100 {
101   TestApplication application;
102
103   float sz=40.0f;
104   MeshData meshData;
105   Vector4 min(-1.0f, -2.0f, -3.0f, 0.0f);
106   Vector4 max(1.0f, 2.0f, 3.0f, 0.0f);
107   meshData.SetBoundingBoxMin(min);
108   meshData.SetBoundingBoxMax(max);
109   DALI_TEST_EQUALS(meshData.GetBoundingBoxMin(), min, 0.001, TEST_LOCATION);
110   DALI_TEST_EQUALS(meshData.GetBoundingBoxMax(), max, 0.001, TEST_LOCATION);
111
112   MeshData::VertexContainer    vertices;
113   MeshData::FaceIndices        faces;
114   BoneContainer                bones;
115   ConstructVertices(vertices, sz);
116   ConstructFaces(vertices, faces);
117   Material customMaterial = ConstructMaterial();
118   meshData.SetData(vertices, faces, bones, customMaterial);
119
120   // Check bounding box hasn't changed
121   DALI_TEST_EQUALS(meshData.GetBoundingBoxMin(), min, 0.001, TEST_LOCATION);
122   DALI_TEST_EQUALS(meshData.GetBoundingBoxMax(), max, 0.001, TEST_LOCATION);
123
124   Vector4 upper(-1e10f, -1e10f, -1e10f, 0.0f);
125   Vector4 lower(1e10f, 1e10f, 1e10f, 0.0f);
126   meshData.AddToBoundingVolume(lower, upper, Matrix::IDENTITY);
127
128   // Bounding box should have been update
129   Vector4 bbMin(-sz*0.5f, -sz,      -sz*0.7f, 0.0f);
130   Vector4 bbMax( sz*0.5f,  sz*0.3f,  sz*0.5f, 0.0f);
131
132   // Test that upper and lower bounds are set and transformed
133   DALI_TEST_EQUALS(lower, bbMin, 0.001, TEST_LOCATION);
134   DALI_TEST_EQUALS(upper, bbMax, 0.001, TEST_LOCATION);
135
136   // Test that mesh's upper and lower bounds are set and not transformed
137   DALI_TEST_EQUALS(meshData.GetBoundingBoxMin(), bbMin, 0.001, TEST_LOCATION);
138   DALI_TEST_EQUALS(meshData.GetBoundingBoxMax(), bbMax, 0.001, TEST_LOCATION);
139   END_TEST;
140 }
141
142 int UtcDaliMeshDataGetVertexCount(void)
143 {
144   TestApplication application;
145
146   MeshData meshData;
147   MeshData::VertexContainer    vertices;
148   MeshData::FaceIndices        faces;
149   BoneContainer                bones;
150   ConstructVertices(vertices, 30);
151   ConstructFaces(vertices, faces);
152   Material customMaterial = ConstructMaterial();
153
154   DALI_TEST_EQUALS(meshData.GetVertexCount(), static_cast<size_t>(0), TEST_LOCATION);
155
156   meshData.SetData(vertices, faces, bones, customMaterial);
157   DALI_TEST_EQUALS(meshData.GetVertexCount(), vertices.size(), TEST_LOCATION);
158
159   END_TEST;
160 }
161
162 int UtcDaliMeshDataGetVertices(void)
163 {
164   TestApplication application;
165   MeshData meshData;
166   const Dali::MeshData::VertexContainer& verts1 = meshData.GetVertices();
167   DALI_TEST_CHECK(verts1.size() == 0);
168
169   MeshData::VertexContainer    vertices;
170   MeshData::FaceIndices        faces;
171   BoneContainer                bones;
172   ConstructVertices(vertices, 30);
173   ConstructFaces(vertices, faces);
174   Material customMaterial = ConstructMaterial();
175   meshData.SetData(vertices, faces, bones, customMaterial);
176
177   const Dali::MeshData::VertexContainer& verts2 = meshData.GetVertices();
178   DALI_TEST_CHECK(verts2.size() != 0);
179   DALI_TEST_CHECK(verts2.size() == meshData.GetVertexCount());
180   END_TEST;
181 }
182
183 int UtcDaliMeshDataGetFaceCount(void)
184 {
185   TestApplication application;
186   MeshData meshData;
187   DALI_TEST_EQUALS(meshData.GetFaceCount(), static_cast<size_t>(0), TEST_LOCATION);
188
189   MeshData::VertexContainer    vertices;
190   MeshData::FaceIndices        faces;
191   BoneContainer                bones;
192   ConstructVertices(vertices, 30);
193   ConstructFaces(vertices, faces);
194   Material customMaterial = ConstructMaterial();
195   meshData.SetData(vertices, faces, bones, customMaterial);
196
197   DALI_TEST_EQUALS(meshData.GetFaceCount(), faces.size() / 3, TEST_LOCATION);
198   END_TEST;
199 }
200
201 int UtcDaliMeshDataGetFaces(void)
202 {
203   TestApplication application;
204   MeshData meshData;
205   const Dali::MeshData::FaceIndices& faces1 = meshData.GetFaces();
206   DALI_TEST_CHECK(faces1.size() == 0);
207
208   MeshData::VertexContainer    vertices;
209   MeshData::FaceIndices        faces;
210   BoneContainer                bones;
211   ConstructVertices(vertices, 30);
212   ConstructFaces(vertices, faces);
213   Material customMaterial = ConstructMaterial();
214   meshData.SetData(vertices, faces, bones, customMaterial);
215
216   const Dali::MeshData::FaceIndices& faces2 = meshData.GetFaces();
217   DALI_TEST_CHECK(faces2.size() != 0);
218   END_TEST;
219 }
220
221 int UtcDaliMeshDataTextureCoords(void)
222 {
223   TestApplication application;
224   MeshData meshData;
225   DALI_TEST_EQUALS(meshData.HasTextureCoords(), false, TEST_LOCATION);
226   meshData.SetHasTextureCoords(true);
227   DALI_TEST_EQUALS(meshData.HasTextureCoords(), true, TEST_LOCATION);
228   END_TEST;
229 }
230
231 int UtcDaliMeshDataNormals(void)
232 {
233   TestApplication application;
234   MeshData meshData;
235   DALI_TEST_EQUALS(meshData.HasNormals(), false, TEST_LOCATION);
236   meshData.SetHasNormals(true);
237   DALI_TEST_EQUALS(meshData.HasNormals(), true, TEST_LOCATION);
238   END_TEST;
239 }
240
241 int UtcDaliMeshDataGetMaterial(void)
242 {
243   TestApplication application;
244   MeshData meshData;
245   Material aMat = meshData.GetMaterial();
246   DALI_TEST_CHECK(!aMat);
247
248   MeshData::VertexContainer    vertices;
249   MeshData::FaceIndices        faces;
250   BoneContainer                bones;
251   ConstructVertices(vertices, 30);
252   ConstructFaces(vertices, faces);
253   Material customMaterial = ConstructMaterial();
254   meshData.SetData(vertices, faces, bones, customMaterial);
255
256   aMat = meshData.GetMaterial();
257   DALI_TEST_CHECK(aMat);
258   END_TEST;
259 }
260
261 int UtcDaliMeshDataSetMaterial(void)
262 {
263   TestApplication application;
264   MeshData meshData;
265
266   Material aMat = meshData.GetMaterial();
267   DALI_TEST_CHECK(!aMat);
268
269   Material mat1 = ConstructMaterial();
270   meshData.SetMaterial(mat1);
271   aMat = meshData.GetMaterial();
272   DALI_TEST_CHECK(mat1 == aMat);
273
274   MeshData::VertexContainer    vertices;
275   MeshData::FaceIndices        faces;
276   BoneContainer                bones;
277   ConstructVertices(vertices, 30);
278   ConstructFaces(vertices, faces);
279   Material customMaterial = ConstructMaterial();
280   meshData.SetData(vertices, faces, bones, customMaterial);
281
282   aMat = meshData.GetMaterial();
283
284   DALI_TEST_CHECK(aMat == customMaterial);
285   DALI_TEST_CHECK(aMat != mat1);
286
287   END_TEST;
288 }
289
290 int UtcDaliMeshDataGetBoneCount(void)
291 {
292   TestApplication application;
293   MeshData meshData;
294   DALI_TEST_EQUALS(meshData.GetBoneCount(), static_cast<size_t>(0), TEST_LOCATION);
295   DALI_TEST_EQUALS(meshData.HasBones(), false, TEST_LOCATION);
296
297   MeshData::VertexContainer    vertices;
298   MeshData::FaceIndices        faces;
299   BoneContainer                bones;
300   ConstructVertices(vertices, 30);
301   ConstructFaces(vertices, faces);
302   ConstructBones(bones);
303   Material customMaterial = ConstructMaterial();
304   meshData.SetData(vertices, faces, bones, customMaterial);
305
306   DALI_TEST_EQUALS(meshData.GetBoneCount(), static_cast<size_t>(3), TEST_LOCATION);
307   DALI_TEST_EQUALS(meshData.HasBones(), true, TEST_LOCATION);
308   END_TEST;
309 }
310
311
312 int UtcDaliMeshDataGetBones(void)
313 {
314   TestApplication application;
315   MeshData meshData;
316   DALI_TEST_EQUALS(meshData.GetBoneCount(), static_cast<size_t>(0), TEST_LOCATION);
317   const BoneContainer& bones1 = meshData.GetBones();
318   DALI_TEST_CHECK(bones1.empty());
319
320   MeshData::VertexContainer    vertices;
321   MeshData::FaceIndices        faces;
322   BoneContainer                bones;
323   ConstructVertices(vertices, 30);
324   ConstructFaces(vertices, faces);
325   ConstructBones(bones);
326   Material customMaterial = ConstructMaterial();
327   meshData.SetData(vertices, faces, bones, customMaterial);
328   const BoneContainer& bones3 = meshData.GetBones();
329   DALI_TEST_CHECK( ! bones3.empty() );
330   END_TEST;
331 }