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>
26 void utc_dali_animatable_mesh_startup(void)
28 test_return_value = TET_UNDEF;
31 void utc_dali_animatable_mesh_cleanup(void)
33 test_return_value = TET_PASS;
39 void CreateFaces(Dali::AnimatableMesh::Faces& faces, int numVerts)
41 for(int i=0; i<numVerts-3; i++)
49 void CreateOutOfRangeFaces(Dali::AnimatableMesh::Faces& faces, int numVerts)
51 for(int i=numVerts; i<numVerts*2-3; i++)
59 AnimatableMesh CreateMesh()
61 AnimatableMesh::Faces faces;
62 CreateFaces(faces, 10);
63 AnimatableMesh mesh = AnimatableMesh::New(10, faces);
69 // Negative test case for a method
70 int UtcDaliAnimatableMeshConstructor01(void)
72 TestApplication application;
76 DALI_TEST_CHECK( ! mesh );
80 int UtcDaliAnimatableMeshConstructor02(void)
82 TestApplication application;
84 Dali::AnimatableMesh::Faces faces;
85 CreateFaces(faces, 10);
87 AnimatableMesh mesh = AnimatableMesh::New(10, faces);
88 DALI_TEST_CHECK( mesh );
90 AnimatableMesh mesh2 = mesh;
91 DALI_TEST_CHECK( mesh2 );
93 AnimatableMesh mesh3 ( mesh2 );
94 DALI_TEST_CHECK( mesh3 );
98 int UtcDaliAnimatableMeshConstructor03(void)
100 TestApplication application;
102 // Heap allocate a handle. Don't do this in real code!
103 AnimatableMesh* mesh = new AnimatableMesh();
104 DALI_TEST_CHECK( ! *mesh );
110 // Positive test case for a method
111 int UtcDaliAnimatableMeshNew01(void)
113 TestApplication application;
115 Dali::AnimatableMesh::Faces faces;
116 CreateFaces(faces, 10);
118 AnimatableMesh mesh = AnimatableMesh::New(10, faces);
119 DALI_TEST_CHECK( mesh );
123 // Positive test case for a method
124 int UtcDaliAnimatableMeshNew02(void)
126 TestApplication application;
128 Dali::AnimatableMesh::Faces faces;
129 CreateFaces(faces, 10);
131 Dali::Material mat = Dali::Material::New("dummy mat");
132 AnimatableMesh mesh = AnimatableMesh::New(10, faces, mat);
133 DALI_TEST_CHECK( mesh );
138 // Negative test case for a method
139 int UtcDaliAnimatableMeshNew03(void)
141 TestApplication application;
142 Dali::AnimatableMesh::Faces faces;
145 AnimatableMesh mesh = AnimatableMesh::New(0, faces);
146 DALI_TEST_CHECK( !mesh );
148 catch (Dali::DaliException& e)
150 tet_printf("Assertion %s failed at %s\n", e.mCondition.c_str(), e.mLocation.c_str());
151 DALI_TEST_ASSERT(e, "numVertices > 0", TEST_LOCATION);
156 // Negative test case for a method
157 int UtcDaliAnimatableMeshNew04(void)
159 TestApplication application;
161 Dali::AnimatableMesh::Faces faces;
165 AnimatableMesh mesh = AnimatableMesh::New(10, faces);
166 DALI_TEST_CHECK( !mesh );
168 catch (Dali::DaliException& e)
170 tet_printf("Assertion %s failed at %s\n", e.mCondition.c_str(), e.mLocation.c_str());
171 DALI_TEST_ASSERT(e, "faceIndices.size() > 0", TEST_LOCATION);
176 // Negative test case for a method
177 int UtcDaliAnimatableMeshNew05(void)
179 TestApplication application;
181 Dali::AnimatableMesh::Faces faces;
182 CreateOutOfRangeFaces(faces, 10);
186 AnimatableMesh mesh = AnimatableMesh::New(10, faces);
187 DALI_TEST_CHECK( !mesh );
189 catch (Dali::DaliException& e)
191 tet_printf("Assertion %s failed at %s\n", e.mCondition.c_str(), e.mLocation.c_str());
192 DALI_TEST_ASSERT(e, "faceIndex < numVertices", TEST_LOCATION);
197 // Negative test case for a method
198 int UtcDaliAnimatableMeshNew06(void)
200 TestApplication application;
202 Dali::AnimatableMesh::Faces faces;
203 CreateFaces(faces, 10);
207 AnimatableMesh mesh = AnimatableMesh::New(10, faces, Dali::Material() );
208 DALI_TEST_CHECK( !mesh );
210 catch (Dali::DaliException& e)
212 tet_printf("Assertion %s failed at %s\n", e.mCondition.c_str(), e.mLocation.c_str());
213 DALI_TEST_ASSERT(e, "material", TEST_LOCATION);
218 int UtcDaliAnimatableMeshDownCast01(void)
220 TestApplication application;
221 tet_infoline("Testing Dali::AnimatableMesh::DownCast()");
223 Dali::AnimatableMesh::Faces faces;
224 CreateFaces(faces, 10);
226 AnimatableMesh mesh = AnimatableMesh::New(10, faces);
227 BaseHandle* bh = &mesh;
229 AnimatableMesh mesh2 = AnimatableMesh::DownCast(*bh);
230 DALI_TEST_CHECK( mesh2 );
234 int UtcDaliAnimatableMeshGetPropertyIndex01(void)
236 TestApplication application;
237 tet_infoline("Testing Dali::AnimatableMesh::operator[]");
238 AnimatableMesh mesh = CreateMesh();
240 Property::Index i = mesh.GetPropertyIndex(0, AnimatableVertex::POSITION );
241 DALI_TEST_EQUALS( i, 0*3+0, TEST_LOCATION );
243 i = mesh.GetPropertyIndex(5, AnimatableVertex::POSITION );
244 DALI_TEST_EQUALS( i, 5*3+0, TEST_LOCATION );
246 i = mesh.GetPropertyIndex(7, AnimatableVertex::COLOR );
247 DALI_TEST_EQUALS( i, 7*3+1, TEST_LOCATION );
249 i = mesh.GetPropertyIndex(9, AnimatableVertex::TEXTURE_COORDS );
250 DALI_TEST_EQUALS( i, 9*3+2, TEST_LOCATION );
254 int UtcDaliAnimatableMeshGetPropertyIndex02(void)
256 TestApplication application;
257 tet_infoline("Testing Dali::AnimatableMesh::GetPropertyIndex");
259 AnimatableMesh mesh = CreateMesh();
262 Property::Index i = mesh.GetPropertyIndex(12, AnimatableVertex::POSITION );
263 DALI_TEST_CHECK( i==0 );
265 catch (Dali::DaliException& e)
267 tet_printf("Assertion %s failed at %s\n", e.mCondition.c_str(), e.mLocation.c_str());
268 DALI_TEST_ASSERT(e, "index < GetNumberOfVertices()", TEST_LOCATION);
273 int UtcDaliAnimatableMeshGetPropertyIndex03(void)
275 TestApplication application;
276 tet_infoline("Testing Dali::AnimatableMesh::GetPropertyIndex");
278 AnimatableMesh mesh = CreateMesh();
281 Property::Index i = mesh.GetPropertyIndex(12, AnimatableVertex::COLOR );
282 DALI_TEST_CHECK( i==0 );
284 catch (Dali::DaliException& e)
286 tet_printf("Assertion %s failed at %s\n", e.mCondition.c_str(), e.mLocation.c_str());
287 DALI_TEST_ASSERT(e, "index < GetNumberOfVertices()", TEST_LOCATION);
292 int UtcDaliAnimatableMeshGetPropertyIndex04(void)
294 TestApplication application;
295 tet_infoline("Testing Dali::AnimatableMesh::GetPropertyIndexa");
297 AnimatableMesh mesh = CreateMesh();
300 Property::Index i = mesh.GetPropertyIndex(12342343, AnimatableVertex::TEXTURE_COORDS );
301 DALI_TEST_CHECK( i==0 );
303 catch (Dali::DaliException& e)
305 tet_printf("Assertion %s failed at %s\n", e.mCondition.c_str(), e.mLocation.c_str());
306 DALI_TEST_ASSERT(e, "index < GetNumberOfVertices()", TEST_LOCATION);
311 int UtcDaliAnimatableMeshOperatorArray01(void)
313 TestApplication application;
314 tet_infoline("Testing Dali::AnimatableMesh::operator[]");
316 AnimatableMesh mesh = CreateMesh();
318 Vector3 initialPos1(0.0f, 200.0f, 0.0f);
319 Vector3 initialPos2(100.0f, 300.0f, 0.0f);
321 mesh[1].SetPosition(initialPos1);
322 mesh[3].SetPosition(initialPos2);
324 application.Render(0);
325 application.SendNotification();
326 application.Render(16);
327 application.SendNotification();
328 DALI_TEST_EQUALS( mesh[1].GetCurrentPosition(), initialPos1, TEST_LOCATION );
330 Vector3 pos = mesh[3].GetCurrentPosition();
331 DALI_TEST_EQUALS( pos, initialPos2, TEST_LOCATION );
336 int UtcDaliAnimatableMeshOperatorArray02(void)
338 TestApplication application;
339 tet_infoline("Testing Dali::AnimatableMesh::operator[]");
341 AnimatableMesh mesh = CreateMesh();
344 mesh[20].SetPosition(Vector3(0.0f, 0.0f, 0.0f));
346 catch (Dali::DaliException& e)
348 tet_printf("Assertion %s failed at %s\n", e.mCondition.c_str(), e.mLocation.c_str());
349 DALI_TEST_ASSERT(e, "index < GetNumberOfVertices()", TEST_LOCATION);
354 int UtcDaliAnimatableMeshAnimateVertex01(void)
356 TestApplication application;
357 tet_infoline("Testing Dali::AnimatableMesh Animating properties");
359 AnimatableMesh mesh = CreateMesh();
360 MeshActor meshActor = MeshActor::New(mesh);
361 Stage::GetCurrent().Add(meshActor);
363 mesh[0].SetPosition(Vector3(0.0f, 200.0f, 0.0f));
364 mesh[1].SetPosition(Vector3(100.0f, 300.0f, 0.0f));
366 Animation anim = Animation::New(1);
367 anim.AnimateBy(mesh.GetVertexProperty(0, AnimatableVertex::POSITION), Vector3( 0.0f, 100.0f, 0.0f));
368 anim.AnimateTo(mesh.GetVertexProperty(1, AnimatableVertex::POSITION), Vector3(100.0f, 0.0f, 0.0f));
371 application.SendNotification();
372 application.Render(0);
373 application.Render(500);
374 application.SendNotification();
377 DALI_TEST_EQUALS( mesh[0].GetCurrentPosition(), Vector3( 0.0f, 250.0f, 0.0f), TEST_LOCATION );
378 DALI_TEST_EQUALS( mesh[1].GetCurrentPosition(), Vector3(100.0f, 150.0f, 0.0f), TEST_LOCATION );
380 application.SendNotification();
381 application.Render(501);
382 application.SendNotification();
384 DALI_TEST_EQUALS( mesh[0].GetCurrentPosition(), Vector3( 0.0f, 300.0f, 0.0f), TEST_LOCATION );
385 DALI_TEST_EQUALS( mesh[1].GetCurrentPosition(), Vector3(100.0f, 0.0f, 0.0f), TEST_LOCATION );
390 int UtcDaliAnimatableVertexSettersAndGetters(void)
392 TestApplication application;
393 tet_infoline("Testing Dali::AnimatableVertex constructors");
394 AnimatableMesh mesh = CreateMesh();
395 Vector3 v1Pos(0.0f, 200.0f, 0.0f);
396 Vector3 v2Pos(100.0f, 300.0f, 0.0f);
397 Vector2 uvs(0.1f, 0.2f);
398 mesh[0].SetPosition(v1Pos);
399 mesh[1].SetPosition(v2Pos);
400 mesh[2].SetColor(Color::BLACK);
401 mesh[3].SetTextureCoords(uvs);
403 application.SendNotification();
404 application.Render(16);
405 application.SendNotification();
406 application.Render(16);
407 application.SendNotification();
409 DALI_TEST_EQUALS(mesh[0].GetCurrentPosition(), v1Pos, TEST_LOCATION);
410 DALI_TEST_EQUALS(mesh[1].GetCurrentPosition(), v2Pos, TEST_LOCATION);
411 DALI_TEST_EQUALS(mesh[2].GetCurrentColor(), Color::BLACK, TEST_LOCATION);
412 DALI_TEST_EQUALS(mesh[3].GetCurrentTextureCoords(), uvs, TEST_LOCATION);
416 int UtcDaliAnimatableMeshProperties(void)
418 TestApplication application;
419 AnimatableMesh mesh = CreateMesh();
421 Property::IndexContainer indices;
422 mesh.GetPropertyIndices( indices );
423 DALI_TEST_CHECK( ! indices.empty() );
424 DALI_TEST_EQUALS( indices.size(), mesh.GetPropertyCount(), TEST_LOCATION );
428 int UtcDaliAnimatableMeshExceedVertices(void)
430 TestApplication application;
432 AnimatableMesh::Faces faces;
433 CreateFaces(faces, 10);
437 AnimatableMesh mesh = AnimatableMesh::New(3333334, faces);
438 tet_result( TET_FAIL );
440 catch ( DaliException& e )
442 DALI_TEST_ASSERT_CONDITION_STARTS_WITH_SUBSTRING( e, "( numVertices * 3 ) < DEFAULT_PROPERTY_MAX_COUNT", TEST_LOCATION );