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.
21 #include <dali/public-api/dali-core.h>
23 #include <dali-test-suite-utils.h>
27 #include <mesh-builder.h>
29 static void Startup();
30 static void Cleanup();
33 void (*tet_startup)() = Startup;
34 void (*tet_cleanup)() = Cleanup;
38 POSITIVE_TC_IDX = 0x01,
42 #define MAX_NUMBER_OF_TESTS 10000
44 struct tet_testlist tet_testlist[MAX_NUMBER_OF_TESTS];
47 TEST_FUNCTION( UtcDaliAnimatableMeshConstructor01, NEGATIVE_TC_IDX );
48 TEST_FUNCTION( UtcDaliAnimatableMeshConstructor02, NEGATIVE_TC_IDX );
49 TEST_FUNCTION( UtcDaliAnimatableMeshConstructor03, NEGATIVE_TC_IDX );
50 TEST_FUNCTION( UtcDaliAnimatableMeshNew01, POSITIVE_TC_IDX );
51 TEST_FUNCTION( UtcDaliAnimatableMeshNew02, POSITIVE_TC_IDX );
52 TEST_FUNCTION( UtcDaliAnimatableMeshNew03, NEGATIVE_TC_IDX );
53 TEST_FUNCTION( UtcDaliAnimatableMeshNew04, NEGATIVE_TC_IDX );
54 TEST_FUNCTION( UtcDaliAnimatableMeshNew05, NEGATIVE_TC_IDX );
55 TEST_FUNCTION( UtcDaliAnimatableMeshNew06, NEGATIVE_TC_IDX );
56 TEST_FUNCTION( UtcDaliAnimatableMeshDownCast01, POSITIVE_TC_IDX );
57 TEST_FUNCTION( UtcDaliAnimatableMeshDownCast02, NEGATIVE_TC_IDX );
58 TEST_FUNCTION( UtcDaliAnimatableMeshGetPropertyIndex01, POSITIVE_TC_IDX );
59 TEST_FUNCTION( UtcDaliAnimatableMeshGetPropertyIndex02, NEGATIVE_TC_IDX );
60 TEST_FUNCTION( UtcDaliAnimatableMeshGetPropertyIndex03, NEGATIVE_TC_IDX );
61 TEST_FUNCTION( UtcDaliAnimatableMeshGetPropertyIndex04, NEGATIVE_TC_IDX );
62 TEST_FUNCTION( UtcDaliAnimatableMeshOperatorArray01, POSITIVE_TC_IDX );
63 TEST_FUNCTION( UtcDaliAnimatableMeshOperatorArray02, NEGATIVE_TC_IDX );
64 TEST_FUNCTION( UtcDaliAnimatableMeshAnimateVertex01, POSITIVE_TC_IDX );
65 TEST_FUNCTION( UtcDaliAnimatableVertexSettersAndGetters, POSITIVE_TC_IDX );
66 TEST_FUNCTION( UtcDaliAnimatableMeshProperties, POSITIVE_TC_IDX );
67 TEST_FUNCTION( UtcDaliAnimatableMeshExceedVertices, NEGATIVE_TC_IDX );
69 // Called only once before first test is run.
74 // Called only once after last test is run
79 void CreateFaces(Dali::AnimatableMesh::Faces& faces, int numVerts)
81 for(int i=0; i<numVerts-3; i++)
89 void CreateOutOfRangeFaces(Dali::AnimatableMesh::Faces& faces, int numVerts)
91 for(int i=numVerts; i<numVerts*2-3; i++)
99 AnimatableMesh CreateMesh()
101 AnimatableMesh::Faces faces;
102 CreateFaces(faces, 10);
103 AnimatableMesh mesh = AnimatableMesh::New(10, faces);
107 // Negative test case for a method
108 static void UtcDaliAnimatableMeshConstructor01()
110 TestApplication application;
114 DALI_TEST_CHECK( ! mesh );
117 static void UtcDaliAnimatableMeshConstructor02()
119 TestApplication application;
121 Dali::AnimatableMesh::Faces faces;
122 CreateFaces(faces, 10);
124 AnimatableMesh mesh = AnimatableMesh::New(10, faces);
125 DALI_TEST_CHECK( mesh );
127 AnimatableMesh mesh2 = mesh;
128 DALI_TEST_CHECK( mesh2 );
130 AnimatableMesh mesh3 ( mesh2 );
131 DALI_TEST_CHECK( mesh3 );
134 static void UtcDaliAnimatableMeshConstructor03()
136 TestApplication application;
138 // Heap allocate a handle. Don't do this in real code!
139 AnimatableMesh* mesh = new AnimatableMesh();
140 DALI_TEST_CHECK( ! *mesh );
145 // Positive test case for a method
146 static void UtcDaliAnimatableMeshNew01()
148 TestApplication application;
150 Dali::AnimatableMesh::Faces faces;
151 CreateFaces(faces, 10);
153 AnimatableMesh mesh = AnimatableMesh::New(10, faces);
154 DALI_TEST_CHECK( mesh );
157 // Positive test case for a method
158 static void UtcDaliAnimatableMeshNew02()
160 TestApplication application;
162 Dali::AnimatableMesh::Faces faces;
163 CreateFaces(faces, 10);
165 Dali::Material mat = Dali::Material::New("dummy mat");
166 AnimatableMesh mesh = AnimatableMesh::New(10, faces, mat);
167 DALI_TEST_CHECK( mesh );
171 // Negative test case for a method
172 static void UtcDaliAnimatableMeshNew03()
174 TestApplication application;
175 Dali::AnimatableMesh::Faces faces;
178 AnimatableMesh mesh = AnimatableMesh::New(0, faces);
179 DALI_TEST_CHECK( !mesh );
181 catch (Dali::DaliException& e)
183 tet_printf("Assertion %s failed at %s\n", e.mCondition.c_str(), e.mLocation.c_str());
184 DALI_TEST_ASSERT(e, "numVertices > 0", TEST_LOCATION);
188 // Negative test case for a method
189 static void UtcDaliAnimatableMeshNew04()
191 TestApplication application;
193 Dali::AnimatableMesh::Faces faces;
197 AnimatableMesh mesh = AnimatableMesh::New(10, faces);
198 DALI_TEST_CHECK( !mesh );
200 catch (Dali::DaliException& e)
202 tet_printf("Assertion %s failed at %s\n", e.mCondition.c_str(), e.mLocation.c_str());
203 DALI_TEST_ASSERT(e, "faceIndices.size() > 0", TEST_LOCATION);
207 // Negative test case for a method
208 static void UtcDaliAnimatableMeshNew05()
210 TestApplication application;
212 Dali::AnimatableMesh::Faces faces;
213 CreateOutOfRangeFaces(faces, 10);
217 AnimatableMesh mesh = AnimatableMesh::New(10, faces);
218 DALI_TEST_CHECK( !mesh );
220 catch (Dali::DaliException& e)
222 tet_printf("Assertion %s failed at %s\n", e.mCondition.c_str(), e.mLocation.c_str());
223 DALI_TEST_ASSERT(e, "faceIndex < numVertices", TEST_LOCATION);
227 // Negative test case for a method
228 static void UtcDaliAnimatableMeshNew06()
230 TestApplication application;
232 Dali::AnimatableMesh::Faces faces;
233 CreateFaces(faces, 10);
237 AnimatableMesh mesh = AnimatableMesh::New(10, faces, Dali::Material() );
238 DALI_TEST_CHECK( !mesh );
240 catch (Dali::DaliException& e)
242 tet_printf("Assertion %s failed at %s\n", e.mCondition.c_str(), e.mLocation.c_str());
243 DALI_TEST_ASSERT(e, "material", TEST_LOCATION);
247 static void UtcDaliAnimatableMeshDownCast01()
249 TestApplication application;
250 tet_infoline("Testing Dali::AnimatableMesh::DownCast()");
252 Dali::AnimatableMesh::Faces faces;
253 CreateFaces(faces, 10);
255 AnimatableMesh mesh = AnimatableMesh::New(10, faces);
256 BaseHandle* bh = &mesh;
258 AnimatableMesh mesh2 = AnimatableMesh::DownCast(*bh);
259 DALI_TEST_CHECK( mesh2 );
262 static void UtcDaliAnimatableMeshDownCast02()
264 TestApplication application;
265 tet_infoline("Testing Dali::AnimatableMesh::DownCast()");
268 CreateMeshData(meshData);
269 Mesh mesh = Mesh::New(meshData);
270 BaseHandle* bh = &mesh;
272 AnimatableMesh mesh2 = AnimatableMesh::DownCast(*bh);
273 DALI_TEST_CHECK( ! mesh2 );
276 static void UtcDaliAnimatableMeshGetPropertyIndex01()
278 TestApplication application;
279 tet_infoline("Testing Dali::AnimatableMesh::operator[]");
280 AnimatableMesh mesh = CreateMesh();
282 Property::Index i = mesh.GetPropertyIndex(0, AnimatableVertex::POSITION );
283 DALI_TEST_EQUALS( i, 0*3+0, TEST_LOCATION );
285 i = mesh.GetPropertyIndex(5, AnimatableVertex::POSITION );
286 DALI_TEST_EQUALS( i, 5*3+0, TEST_LOCATION );
288 i = mesh.GetPropertyIndex(7, AnimatableVertex::COLOR );
289 DALI_TEST_EQUALS( i, 7*3+1, TEST_LOCATION );
291 i = mesh.GetPropertyIndex(9, AnimatableVertex::TEXTURE_COORDS );
292 DALI_TEST_EQUALS( i, 9*3+2, TEST_LOCATION );
295 static void UtcDaliAnimatableMeshGetPropertyIndex02()
297 TestApplication application;
298 tet_infoline("Testing Dali::AnimatableMesh::GetPropertyIndexa");
300 AnimatableMesh mesh = CreateMesh();
303 Property::Index i = mesh.GetPropertyIndex(12, AnimatableVertex::POSITION );
304 DALI_TEST_CHECK( i==0 );
306 catch (Dali::DaliException& e)
308 tet_printf("Assertion %s failed at %s\n", e.mCondition.c_str(), e.mLocation.c_str());
309 DALI_TEST_ASSERT(e, "index < GetNumberOfVertices()", TEST_LOCATION);
313 static void UtcDaliAnimatableMeshGetPropertyIndex03()
315 TestApplication application;
316 tet_infoline("Testing Dali::AnimatableMesh::GetPropertyIndexa");
318 AnimatableMesh mesh = CreateMesh();
321 Property::Index i = mesh.GetPropertyIndex(12, AnimatableVertex::COLOR );
322 DALI_TEST_CHECK( i==0 );
324 catch (Dali::DaliException& e)
326 tet_printf("Assertion %s failed at %s\n", e.mCondition.c_str(), e.mLocation.c_str());
327 DALI_TEST_ASSERT(e, "index < GetNumberOfVertices()", TEST_LOCATION);
331 static void UtcDaliAnimatableMeshGetPropertyIndex04()
333 TestApplication application;
334 tet_infoline("Testing Dali::AnimatableMesh::GetPropertyIndexa");
336 AnimatableMesh mesh = CreateMesh();
339 Property::Index i = mesh.GetPropertyIndex(12342343, AnimatableVertex::TEXTURE_COORDS );
340 DALI_TEST_CHECK( i==0 );
342 catch (Dali::DaliException& e)
344 tet_printf("Assertion %s failed at %s\n", e.mCondition.c_str(), e.mLocation.c_str());
345 DALI_TEST_ASSERT(e, "index < GetNumberOfVertices()", TEST_LOCATION);
349 static void UtcDaliAnimatableMeshOperatorArray01()
351 TestApplication application;
352 tet_infoline("Testing Dali::AnimatableMesh::operator[]");
354 AnimatableMesh mesh = CreateMesh();
356 Vector3 initialPos1(0.0f, 200.0f, 0.0f);
357 Vector3 initialPos2(100.0f, 300.0f, 0.0f);
359 mesh[1].SetPosition(initialPos1);
360 mesh[3].SetPosition(initialPos2);
362 application.Render(0);
363 application.SendNotification();
364 application.Render(16);
365 application.SendNotification();
366 DALI_TEST_EQUALS( mesh[1].GetCurrentPosition(), initialPos1, TEST_LOCATION );
368 Vector3 pos = mesh[3].GetCurrentPosition();
369 DALI_TEST_EQUALS( pos, initialPos2, TEST_LOCATION );
373 static void UtcDaliAnimatableMeshOperatorArray02()
375 TestApplication application;
376 tet_infoline("Testing Dali::AnimatableMesh::operator[]");
378 AnimatableMesh mesh = CreateMesh();
381 mesh[20].SetPosition(Vector3(0.0f, 0.0f, 0.0f));
383 catch (Dali::DaliException& e)
385 tet_printf("Assertion %s failed at %s\n", e.mCondition.c_str(), e.mLocation.c_str());
386 DALI_TEST_ASSERT(e, "index < GetNumberOfVertices()", TEST_LOCATION);
390 static void UtcDaliAnimatableMeshAnimateVertex01()
392 TestApplication application;
393 tet_infoline("Testing Dali::AnimatableMesh Animating properties");
395 AnimatableMesh mesh = CreateMesh();
396 MeshActor meshActor = MeshActor::New(mesh);
397 Stage::GetCurrent().Add(meshActor);
399 mesh[0].SetPosition(Vector3(0.0f, 200.0f, 0.0f));
400 mesh[1].SetPosition(Vector3(100.0f, 300.0f, 0.0f));
402 Animation anim = Animation::New(1);
403 anim.AnimateBy(mesh.GetVertexProperty(0, AnimatableVertex::POSITION), Vector3( 0.0f, 100.0f, 0.0f));
404 anim.AnimateTo(mesh.GetVertexProperty(1, AnimatableVertex::POSITION), Vector3(100.0f, 0.0f, 0.0f));
407 application.SendNotification();
408 application.Render(0);
409 application.Render(500);
410 application.SendNotification();
413 DALI_TEST_EQUALS( mesh[0].GetCurrentPosition(), Vector3( 0.0f, 250.0f, 0.0f), TEST_LOCATION );
414 DALI_TEST_EQUALS( mesh[1].GetCurrentPosition(), Vector3(100.0f, 150.0f, 0.0f), TEST_LOCATION );
416 application.SendNotification();
417 application.Render(501);
418 application.SendNotification();
420 DALI_TEST_EQUALS( mesh[0].GetCurrentPosition(), Vector3( 0.0f, 300.0f, 0.0f), TEST_LOCATION );
421 DALI_TEST_EQUALS( mesh[1].GetCurrentPosition(), Vector3(100.0f, 0.0f, 0.0f), TEST_LOCATION );
425 static void UtcDaliAnimatableVertexSettersAndGetters()
427 TestApplication application;
428 tet_infoline("Testing Dali::AnimatableVertex constructors");
429 AnimatableMesh mesh = CreateMesh();
430 Vector3 v1Pos(0.0f, 200.0f, 0.0f);
431 Vector3 v2Pos(100.0f, 300.0f, 0.0f);
432 Vector2 uvs(0.1f, 0.2f);
433 mesh[0].SetPosition(v1Pos);
434 mesh[1].SetPosition(v2Pos);
435 mesh[2].SetColor(Color::BLACK);
436 mesh[3].SetTextureCoords(uvs);
438 application.SendNotification();
439 application.Render(16);
440 application.SendNotification();
441 application.Render(16);
442 application.SendNotification();
444 DALI_TEST_EQUALS(mesh[0].GetCurrentPosition(), v1Pos, TEST_LOCATION);
445 DALI_TEST_EQUALS(mesh[1].GetCurrentPosition(), v2Pos, TEST_LOCATION);
446 DALI_TEST_EQUALS(mesh[2].GetCurrentColor(), Color::BLACK, TEST_LOCATION);
447 DALI_TEST_EQUALS(mesh[3].GetCurrentTextureCoords(), uvs, TEST_LOCATION);
450 void UtcDaliAnimatableMeshProperties()
452 TestApplication application;
453 AnimatableMesh mesh = CreateMesh();
455 Property::IndexContainer indices;
456 mesh.GetPropertyIndices( indices );
457 DALI_TEST_CHECK( ! indices.empty() );
458 DALI_TEST_EQUALS( indices.size(), mesh.GetPropertyCount(), TEST_LOCATION );
461 void UtcDaliAnimatableMeshExceedVertices()
463 TestApplication application;
465 AnimatableMesh::Faces faces;
466 CreateFaces(faces, 10);
470 AnimatableMesh mesh = AnimatableMesh::New(3333334, faces);
471 tet_result( TET_FAIL );
473 catch ( DaliException& e )
475 DALI_TEST_ASSERT_CONDITION_STARTS_WITH_SUBSTRING( e, "( numVertices * 3 ) < DEFAULT_PROPERTY_MAX_COUNT", TEST_LOCATION );