2 * Copyright (c) 2014 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
20 #include <dali/public-api/dali-core.h>
21 #include <dali-test-suite-utils.h>
22 #include <mesh-builder.h>
27 void utc_dali_animatable_mesh_startup(void)
29 test_return_value = TET_UNDEF;
32 void utc_dali_animatable_mesh_cleanup(void)
34 test_return_value = TET_PASS;
40 void CreateFaces(Dali::AnimatableMesh::Faces& faces, int numVerts)
42 for(int i=0; i<numVerts-3; i++)
50 void CreateOutOfRangeFaces(Dali::AnimatableMesh::Faces& faces, int numVerts)
52 for(int i=numVerts; i<numVerts*2-3; i++)
60 AnimatableMesh CreateMesh()
62 AnimatableMesh::Faces faces;
63 CreateFaces(faces, 10);
64 AnimatableMesh mesh = AnimatableMesh::New(10, faces);
70 // Negative test case for a method
71 int UtcDaliAnimatableMeshConstructor01(void)
73 TestApplication application;
77 DALI_TEST_CHECK( ! mesh );
81 int UtcDaliAnimatableMeshConstructor02(void)
83 TestApplication application;
85 Dali::AnimatableMesh::Faces faces;
86 CreateFaces(faces, 10);
88 AnimatableMesh mesh = AnimatableMesh::New(10, faces);
89 DALI_TEST_CHECK( mesh );
91 AnimatableMesh mesh2 = mesh;
92 DALI_TEST_CHECK( mesh2 );
94 AnimatableMesh mesh3 ( mesh2 );
95 DALI_TEST_CHECK( mesh3 );
99 int UtcDaliAnimatableMeshConstructor03(void)
101 TestApplication application;
103 // Heap allocate a handle. Don't do this in real code!
104 AnimatableMesh* mesh = new AnimatableMesh();
105 DALI_TEST_CHECK( ! *mesh );
111 // Positive test case for a method
112 int UtcDaliAnimatableMeshNew01(void)
114 TestApplication application;
116 Dali::AnimatableMesh::Faces faces;
117 CreateFaces(faces, 10);
119 AnimatableMesh mesh = AnimatableMesh::New(10, faces);
120 DALI_TEST_CHECK( mesh );
124 // Positive test case for a method
125 int UtcDaliAnimatableMeshNew02(void)
127 TestApplication application;
129 Dali::AnimatableMesh::Faces faces;
130 CreateFaces(faces, 10);
132 Dali::Material mat = Dali::Material::New("dummy mat");
133 AnimatableMesh mesh = AnimatableMesh::New(10, faces, mat);
134 DALI_TEST_CHECK( mesh );
139 // Negative test case for a method
140 int UtcDaliAnimatableMeshNew03(void)
142 TestApplication application;
143 Dali::AnimatableMesh::Faces faces;
146 AnimatableMesh mesh = AnimatableMesh::New(0, faces);
147 DALI_TEST_CHECK( !mesh );
149 catch (Dali::DaliException& e)
151 DALI_TEST_PRINT_ASSERT( e );
152 DALI_TEST_ASSERT(e, "numVertices > 0", TEST_LOCATION);
157 // Negative test case for a method
158 int UtcDaliAnimatableMeshNew04(void)
160 TestApplication application;
162 Dali::AnimatableMesh::Faces faces;
166 AnimatableMesh mesh = AnimatableMesh::New(10, faces);
167 DALI_TEST_CHECK( !mesh );
169 catch (Dali::DaliException& e)
171 DALI_TEST_PRINT_ASSERT( e );
172 DALI_TEST_ASSERT(e, "faceIndices.size() > 0", TEST_LOCATION);
177 // Negative test case for a method
178 int UtcDaliAnimatableMeshNew05(void)
180 TestApplication application;
182 Dali::AnimatableMesh::Faces faces;
183 CreateOutOfRangeFaces(faces, 10);
187 AnimatableMesh mesh = AnimatableMesh::New(10, faces);
188 DALI_TEST_CHECK( !mesh );
190 catch (Dali::DaliException& e)
192 DALI_TEST_PRINT_ASSERT( e );
193 DALI_TEST_ASSERT(e, "faceIndex < numVertices", TEST_LOCATION);
198 // Negative test case for a method
199 int UtcDaliAnimatableMeshNew06(void)
201 TestApplication application;
203 Dali::AnimatableMesh::Faces faces;
204 CreateFaces(faces, 10);
208 AnimatableMesh mesh = AnimatableMesh::New(10, faces, Dali::Material() );
209 DALI_TEST_CHECK( !mesh );
211 catch (Dali::DaliException& e)
213 DALI_TEST_PRINT_ASSERT( e );
214 DALI_TEST_ASSERT(e, "material", TEST_LOCATION);
219 int UtcDaliAnimatableMeshDownCast01(void)
221 TestApplication application;
222 tet_infoline("Testing Dali::AnimatableMesh::DownCast()");
224 Dali::AnimatableMesh::Faces faces;
225 CreateFaces(faces, 10);
227 AnimatableMesh mesh = AnimatableMesh::New(10, faces);
228 BaseHandle* bh = &mesh;
230 AnimatableMesh mesh2 = AnimatableMesh::DownCast(*bh);
231 DALI_TEST_CHECK( mesh2 );
235 int UtcDaliAnimatableMeshDownCast02(void)
237 TestApplication application;
238 tet_infoline("Testing Dali::AnimatableMesh::DownCast()");
241 CreateMeshData(meshData);
242 Mesh mesh = Mesh::New(meshData);
243 BaseHandle* bh = &mesh;
245 AnimatableMesh mesh2 = AnimatableMesh::DownCast(*bh);
246 DALI_TEST_CHECK( ! mesh2 );
250 int UtcDaliAnimatableMeshGetPropertyIndex01(void)
252 TestApplication application;
253 tet_infoline("Testing Dali::AnimatableMesh::operator[]");
254 AnimatableMesh mesh = CreateMesh();
256 Property::Index i = mesh.GetPropertyIndex(0, AnimatableVertex::POSITION );
257 DALI_TEST_EQUALS( i, 0*3+0, TEST_LOCATION );
259 i = mesh.GetPropertyIndex(5, AnimatableVertex::POSITION );
260 DALI_TEST_EQUALS( i, 5*3+0, TEST_LOCATION );
262 i = mesh.GetPropertyIndex(7, AnimatableVertex::COLOR );
263 DALI_TEST_EQUALS( i, 7*3+1, TEST_LOCATION );
265 i = mesh.GetPropertyIndex(9, AnimatableVertex::TEXTURE_COORDS );
266 DALI_TEST_EQUALS( i, 9*3+2, TEST_LOCATION );
270 int UtcDaliAnimatableMeshGetPropertyIndex02(void)
272 TestApplication application;
273 tet_infoline("Testing Dali::AnimatableMesh::GetPropertyIndex");
275 AnimatableMesh mesh = CreateMesh();
278 Property::Index i = mesh.GetPropertyIndex(12, AnimatableVertex::POSITION );
279 DALI_TEST_CHECK( i==0 );
281 catch (Dali::DaliException& e)
283 DALI_TEST_PRINT_ASSERT( e );
284 DALI_TEST_ASSERT(e, "index < GetNumberOfVertices()", TEST_LOCATION);
289 int UtcDaliAnimatableMeshGetPropertyIndex03(void)
291 TestApplication application;
292 tet_infoline("Testing Dali::AnimatableMesh::GetPropertyIndex");
294 AnimatableMesh mesh = CreateMesh();
297 Property::Index i = mesh.GetPropertyIndex(12, AnimatableVertex::COLOR );
298 DALI_TEST_CHECK( i==0 );
300 catch (Dali::DaliException& e)
302 DALI_TEST_PRINT_ASSERT( e );
303 DALI_TEST_ASSERT(e, "index < GetNumberOfVertices()", TEST_LOCATION);
308 int UtcDaliAnimatableMeshGetPropertyIndex04(void)
310 TestApplication application;
311 tet_infoline("Testing Dali::AnimatableMesh::GetPropertyIndexa");
313 AnimatableMesh mesh = CreateMesh();
316 Property::Index i = mesh.GetPropertyIndex(12342343, AnimatableVertex::TEXTURE_COORDS );
317 DALI_TEST_CHECK( i==0 );
319 catch (Dali::DaliException& e)
321 DALI_TEST_PRINT_ASSERT( e );
322 DALI_TEST_ASSERT(e, "index < GetNumberOfVertices()", TEST_LOCATION);
327 int UtcDaliAnimatableMeshOperatorArray01(void)
329 TestApplication application;
330 tet_infoline("Testing Dali::AnimatableMesh::operator[]");
332 AnimatableMesh mesh = CreateMesh();
334 Vector3 initialPos1(0.0f, 200.0f, 0.0f);
335 Vector3 initialPos2(100.0f, 300.0f, 0.0f);
337 mesh[1].SetPosition(initialPos1);
338 mesh[3].SetPosition(initialPos2);
340 application.Render(0);
341 application.SendNotification();
342 application.Render(16);
343 application.SendNotification();
344 DALI_TEST_EQUALS( mesh[1].GetCurrentPosition(), initialPos1, TEST_LOCATION );
346 Vector3 pos = mesh[3].GetCurrentPosition();
347 DALI_TEST_EQUALS( pos, initialPos2, TEST_LOCATION );
352 int UtcDaliAnimatableMeshOperatorArray02(void)
354 TestApplication application;
355 tet_infoline("Testing Dali::AnimatableMesh::operator[]");
357 AnimatableMesh mesh = CreateMesh();
360 mesh[20].SetPosition(Vector3(0.0f, 0.0f, 0.0f));
362 catch (Dali::DaliException& e)
364 DALI_TEST_PRINT_ASSERT( e );
365 DALI_TEST_ASSERT(e, "index < GetNumberOfVertices()", TEST_LOCATION);
370 int UtcDaliAnimatableMeshAnimateVertex01(void)
372 TestApplication application;
373 tet_infoline("Testing Dali::AnimatableMesh Animating properties");
375 AnimatableMesh mesh = CreateMesh();
376 MeshActor meshActor = MeshActor::New(mesh);
377 Stage::GetCurrent().Add(meshActor);
379 mesh[0].SetPosition(Vector3(0.0f, 200.0f, 0.0f));
380 mesh[1].SetPosition(Vector3(100.0f, 300.0f, 0.0f));
382 Animation anim = Animation::New(1);
383 anim.AnimateBy(mesh.GetVertexProperty(0, AnimatableVertex::POSITION), Vector3( 0.0f, 100.0f, 0.0f));
384 anim.AnimateTo(mesh.GetVertexProperty(1, AnimatableVertex::POSITION), Vector3(100.0f, 0.0f, 0.0f));
387 application.SendNotification();
388 application.Render(0);
389 application.Render(500);
390 application.SendNotification();
393 DALI_TEST_EQUALS( mesh[0].GetCurrentPosition(), Vector3( 0.0f, 250.0f, 0.0f), TEST_LOCATION );
394 DALI_TEST_EQUALS( mesh[1].GetCurrentPosition(), Vector3(100.0f, 150.0f, 0.0f), TEST_LOCATION );
396 application.SendNotification();
397 application.Render(501);
398 application.SendNotification();
400 DALI_TEST_EQUALS( mesh[0].GetCurrentPosition(), Vector3( 0.0f, 300.0f, 0.0f), TEST_LOCATION );
401 DALI_TEST_EQUALS( mesh[1].GetCurrentPosition(), Vector3(100.0f, 0.0f, 0.0f), TEST_LOCATION );
406 int UtcDaliAnimatableVertexSettersAndGetters(void)
408 TestApplication application;
409 tet_infoline("Testing Dali::AnimatableVertex constructors");
410 AnimatableMesh mesh = CreateMesh();
411 Vector3 v1Pos(0.0f, 200.0f, 0.0f);
412 Vector3 v2Pos(100.0f, 300.0f, 0.0f);
413 Vector2 uvs(0.1f, 0.2f);
414 mesh[0].SetPosition(v1Pos);
415 mesh[1].SetPosition(v2Pos);
416 mesh[2].SetColor(Color::BLACK);
417 mesh[3].SetTextureCoords(uvs);
419 application.SendNotification();
420 application.Render(16);
421 application.SendNotification();
422 application.Render(16);
423 application.SendNotification();
425 DALI_TEST_EQUALS(mesh[0].GetCurrentPosition(), v1Pos, TEST_LOCATION);
426 DALI_TEST_EQUALS(mesh[1].GetCurrentPosition(), v2Pos, TEST_LOCATION);
427 DALI_TEST_EQUALS(mesh[2].GetCurrentColor(), Color::BLACK, TEST_LOCATION);
428 DALI_TEST_EQUALS(mesh[3].GetCurrentTextureCoords(), uvs, TEST_LOCATION);
432 int UtcDaliAnimatableMeshProperties(void)
434 TestApplication application;
435 AnimatableMesh mesh = CreateMesh();
437 Property::IndexContainer indices;
438 mesh.GetPropertyIndices( indices );
439 DALI_TEST_CHECK( ! indices.empty() );
440 DALI_TEST_EQUALS( indices.size(), mesh.GetPropertyCount(), TEST_LOCATION );
444 int UtcDaliAnimatableMeshExceedVertices(void)
446 TestApplication application;
448 AnimatableMesh::Faces faces;
449 CreateFaces(faces, 10);
453 AnimatableMesh mesh = AnimatableMesh::New(3333334, faces);
454 tet_result( TET_FAIL );
456 catch ( DaliException& e )
458 DALI_TEST_ASSERT( e, "( numVertices * 3 ) < DEFAULT_PROPERTY_MAX_COUNT", TEST_LOCATION );