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.
21 #include <dali/public-api/dali-core.h>
22 #include <dali-test-suite-utils.h>
25 #include "mesh-builder.h"
30 static std::string gModelFile = "blah";
33 // Functor to test whether a Finish signal is emitted
34 struct AnimationFinishCheck
36 AnimationFinishCheck(bool& signalReceived)
37 : mSignalReceived(signalReceived)
41 void operator()(Animation& animation)
43 mSignalReceived = true;
48 mSignalReceived = false;
51 void CheckSignalReceived()
55 tet_printf("Expected Finish signal was not received\n");
64 void CheckSignalNotReceived()
68 tet_printf("Unexpected Finish signal was received\n");
77 bool& mSignalReceived; // owned by individual tests
83 int UtcDaliModelConstructorVoid(void)
85 TestApplication application;
86 tet_infoline("Testing Dali::Model::Model()");
90 DALI_TEST_CHECK(!model);
94 int UtcDaliModelNew(void)
96 TestApplication application;
97 TestPlatformAbstraction& platform = application.GetPlatform();
99 tet_infoline("Testing Dali::Model::New()");
101 Model model = Model::New(gModelFile);
102 application.SendNotification();
103 application.Render();
104 application.Render();
105 application.SendNotification();
107 DALI_TEST_CHECK(platform.WasCalled(TestPlatformAbstraction::LoadResourceFunc));
108 DALI_TEST_CHECK(model);
112 int UtcDaliModelDownCast(void)
114 TestApplication application;
115 tet_infoline("Testing Dali::Model::DownCast()");
117 Model model = Model::New(gModelFile);
119 BaseHandle object(model);
121 Model model2 = Model::DownCast(object);
122 DALI_TEST_CHECK(model2);
124 Model model3 = DownCast< Model >(object);
125 DALI_TEST_CHECK(model3);
127 BaseHandle unInitializedObject;
128 Model model4 = Model::DownCast(unInitializedObject);
129 DALI_TEST_CHECK(!model4);
131 Model model5 = DownCast< Model >(unInitializedObject);
132 DALI_TEST_CHECK(!model5);
137 int UtcDaliModelGetLoadingState01(void)
139 TestApplication application;
140 TestPlatformAbstraction& platform = application.GetPlatform();
142 tet_infoline("Testing Dali::Model::New()");
143 Model model = Model::New(gModelFile);
144 application.SendNotification();
145 application.Render();
146 Integration::ResourceRequest* request = platform.GetRequest();
147 DALI_TEST_CHECK(model.GetLoadingState() == ResourceLoading);
148 DALI_TEST_EQUALS(request->GetPath(), gModelFile, TEST_LOCATION);
149 DALI_TEST_EQUALS(request->GetType()->id, Integration::ResourceModel, TEST_LOCATION);
153 int UtcDaliModelGetLoadingState02(void)
155 TestApplication application;
156 TestPlatformAbstraction& platform = application.GetPlatform();
158 tet_infoline("Testing Dali::Model::New()");
159 Dali::ModelData modelData = BuildTreeModel();
160 Model model = Model::New(gModelFile);
161 application.SendNotification();
162 application.Render();
163 Integration::ResourceRequest* request = platform.GetRequest();
166 platform.SetResourceLoaded(request->GetId(), request->GetType()->id, Integration::ResourcePointer(&(modelData.GetBaseObject())));
169 // Get resources into resource cache
170 application.Render();
171 application.SendNotification();
173 DALI_TEST_CHECK(model.GetLoadingState() == ResourceLoadingSucceeded);
177 int UtcDaliModelGetLoadingState03(void)
179 TestApplication application;
180 TestPlatformAbstraction& platform = application.GetPlatform();
182 tet_infoline("Testing Dali::Model::New()");
183 Model model = Model::New(gModelFile);
184 application.SendNotification();
185 application.Render();
186 Integration::ResourceRequest* request = platform.GetRequest();
189 platform.SetResourceLoadFailed(request->GetId(), Integration::FailureFileNotFound);
191 application.Render();
192 application.SendNotification();
194 DALI_TEST_CHECK(model.GetLoadingState() == ResourceLoadingFailed);
199 // Could probably test the signals, too!
201 int UtcDaliModelNumberOfAnimations(void)
203 TestApplication application;
204 tet_infoline("Testing Dali::Model::NumberOfAnimations()");
206 int animationCount = -1;
207 Model model = Model::New("Blah"); // Probably need to create a real model...
208 animationCount = model.NumberOfAnimations();
210 DALI_TEST_CHECK( -1 != animationCount );
214 int UtcDaliModelActorFactory(void)
216 TestApplication application;
217 TestPlatformAbstraction& platform = application.GetPlatform();
219 tet_infoline("Testing Dali::ModelActorFactory");
221 Dali::ModelData modelData = BuildTreeModel();
224 Model model = Model::New("Tree");
226 application.SendNotification();
227 application.Render();
228 Integration::ResourceRequest* request = platform.GetRequest(); // Return modelData
231 platform.SetResourceLoaded(request->GetId(), request->GetType()->id, Integration::ResourcePointer(&(modelData.GetBaseObject())));
233 application.Render();
234 application.SendNotification();
236 Actor modelRootActor = ModelActorFactory::BuildActorTree(model, ""); // model should be loaded
238 DALI_TEST_CHECK(model.GetLoadingState() == ResourceLoadingSucceeded);
239 DALI_TEST_CHECK(modelRootActor);
240 DALI_TEST_CHECK(modelRootActor.GetName().compare("root") == 0);
242 Actor trunk = modelRootActor.FindChildByName("trunk");
243 DALI_TEST_CHECK(trunk);
244 Actor branch = modelRootActor.FindChildByName("branch");
245 DALI_TEST_CHECK(branch);
246 Actor twig = modelRootActor.FindChildByName("twig");
247 DALI_TEST_CHECK(twig);
248 MeshActor twigMeshActor = MeshActor::DownCast(twig);
249 DALI_TEST_CHECK(!twigMeshActor);
250 Actor leaf = modelRootActor.FindChildByName("leaf");
251 DALI_TEST_CHECK(leaf);
252 MeshActor leafMeshActor = MeshActor::DownCast(leaf);
253 DALI_TEST_CHECK(leafMeshActor);
255 Material leafMaterial = leafMeshActor.GetMaterial();
256 DALI_TEST_CHECK(leafMaterial);
260 int UtcDaliModelActorFactoryTwoMesh(void)
262 TestApplication application;
263 TestPlatformAbstraction& platform = application.GetPlatform();
265 tet_infoline("Testing Dali::ModelActorFactory with 2 meshes in an entity");
267 Dali::ModelData modelData = BuildTreeModel();
268 Dali::Entity twoMeshEntity = Dali::Entity::New("2Mesh");
270 CreateMeshData(meshData);
272 CreateMeshData(meshData2);
273 unsigned int meshIndex = modelData.NumberOfMeshes();
274 modelData.AddMesh(meshData);
275 modelData.AddMesh(meshData2);
276 twoMeshEntity.AddMeshIndex(meshIndex);
277 twoMeshEntity.AddMeshIndex(meshIndex+1);
278 modelData.GetRootEntity().Add(twoMeshEntity);
281 Model model = Model::New("Tree");
283 application.SendNotification();
284 application.Render();
285 Integration::ResourceRequest* request = platform.GetRequest(); // Return modelData
288 platform.SetResourceLoaded(request->GetId(), request->GetType()->id, Integration::ResourcePointer(&(modelData.GetBaseObject())));
290 application.Render();
291 application.SendNotification();
296 actor = ModelActorFactory::BuildActorTree(model, ""); // model should be loaded
298 catch( Dali::DaliException& e )
300 DALI_TEST_PRINT_ASSERT( e );
301 DALI_TEST_ASSERT(e, "entity.NumberOfMeshes() == 1", TEST_LOCATION);
302 DALI_TEST_CHECK( !actor );
307 int UtcDaliModelBuildAnimation01(void)
309 TestApplication application;
310 TestPlatformAbstraction& platform = application.GetPlatform();
312 tet_infoline("Testing Dali::MeshActor::New()");
314 Dali::ModelData modelData = BuildTreeModel();
317 Model model = Model::New("Tree");
319 application.SendNotification();
320 application.Render();
321 Integration::ResourceRequest* request = platform.GetRequest(); // Return modelData
324 platform.SetResourceLoaded(request->GetId(), request->GetType()->id, Integration::ResourcePointer(&(modelData.GetBaseObject())));
326 application.Render();
327 application.SendNotification();
329 Actor actor = ModelActorFactory::BuildActorTree(model, ""); // model should be loaded
330 Stage::GetCurrent().Add(actor);
332 DALI_TEST_CHECK(model.GetLoadingState() == ResourceLoadingSucceeded);
333 DALI_TEST_CHECK(actor);
334 DALI_TEST_CHECK(actor.GetName().compare("root") == 0);
336 DALI_TEST_EQUALS(model.NumberOfAnimations(), static_cast<size_t>(1), TEST_LOCATION);
337 unsigned int animIndex=0;
338 bool found = model.FindAnimation("Anim1", animIndex);
339 DALI_TEST_CHECK(found);
341 Animation twigAnim = ModelActorFactory::BuildAnimation(model, actor, animIndex);
342 DALI_TEST_CHECK(twigAnim);
343 DALI_TEST_EQUALS(twigAnim.GetDuration(), 10.0f, 0.001, TEST_LOCATION);
344 DALI_TEST_CHECK(twigAnim.GetDefaultAlphaFunction() == Dali::AlphaFunctions::Linear);
346 Actor twigActor = actor.FindChildByName("twig");
347 DALI_TEST_CHECK(twigActor);
349 // Start the animation
352 float durationSeconds = 10.0f;
354 bool signalReceived(false);
355 AnimationFinishCheck finishCheck(signalReceived);
356 twigAnim.FinishedSignal().Connect(&application, finishCheck);
357 application.SendNotification();
358 application.Render();
359 finishCheck.CheckSignalNotReceived();
360 DALI_TEST_EQUALS( twigActor.GetCurrentPosition(), Vector3(2.0f, 1.0f, 0.0f), 0.01f, TEST_LOCATION );
362 application.Render(static_cast<unsigned int>(durationSeconds*250.0f)/* 25% progress */);
363 application.SendNotification();
364 DALI_TEST_EQUALS( twigActor.GetCurrentPosition(), Vector3(2.5f, 1.0f, 2.5f), 0.01f, TEST_LOCATION );
366 application.Render(static_cast<unsigned int>(durationSeconds*500.0f)/* 75% progress */);
367 application.SendNotification();
368 DALI_TEST_EQUALS( twigActor.GetCurrentPosition(), Vector3(3.5f, 1.0f, 7.5f), 0.01f, TEST_LOCATION );
370 application.Render(static_cast<unsigned int>(durationSeconds*500.0f)/* Past Finished */);
371 application.SendNotification();
372 DALI_TEST_EQUALS( twigActor.GetCurrentPosition(), Vector3(4.0f, 1.0f, 10.0f), 0.01f, TEST_LOCATION );
374 finishCheck.CheckSignalReceived();
380 int UtcDaliModelBuildAnimation02(void)
382 TestApplication application;
383 TestPlatformAbstraction& platform = application.GetPlatform();
385 tet_infoline("Testing Dali::MeshActor::New()");
387 Dali::ModelData modelData = BuildTreeModel();
390 Model model = Model::New("Tree");
392 application.SendNotification();
393 application.Render();
394 Integration::ResourceRequest* request = platform.GetRequest(); // Return modelData
397 platform.SetResourceLoaded(request->GetId(), request->GetType()->id, Integration::ResourcePointer(&(modelData.GetBaseObject())));
399 application.Render();
400 application.SendNotification();
402 Actor actor = ModelActorFactory::BuildActorTree(model, ""); // model should be loaded
404 DALI_TEST_CHECK(model.GetLoadingState() == ResourceLoadingSucceeded);
405 DALI_TEST_CHECK(actor);
406 DALI_TEST_CHECK(actor.GetName().compare("root") == 0);
408 DALI_TEST_EQUALS(model.NumberOfAnimations(), static_cast<size_t>(1), TEST_LOCATION);
409 unsigned int animIndex=0;
410 bool found = model.FindAnimation("Anim1", animIndex);
411 DALI_TEST_CHECK(found);
412 Animation twigAnim = ModelActorFactory::BuildAnimation(model, actor, animIndex, 5.0f);
413 DALI_TEST_CHECK(twigAnim);
414 DALI_TEST_EQUALS(twigAnim.GetDuration(), 5.0f, 0.001, TEST_LOCATION);
415 DALI_TEST_CHECK(twigAnim.GetDefaultAlphaFunction() == Dali::AlphaFunctions::Linear);
420 int UtcDaliModelBuildAnimation03(void)
422 TestApplication application;
423 TestPlatformAbstraction& platform = application.GetPlatform();
425 tet_infoline("Testing Dali::MeshActor::New()");
427 Dali::ModelData modelData = BuildTreeModel();
430 Model model = Model::New("Tree");
432 application.SendNotification();
433 application.Render();
434 Integration::ResourceRequest* request = platform.GetRequest(); // Return modelData
437 platform.SetResourceLoaded(request->GetId(), request->GetType()->id, Integration::ResourcePointer(&(modelData.GetBaseObject())));
439 application.Render();
440 application.SendNotification();
442 Actor actor = ModelActorFactory::BuildActorTree(model, ""); // model should be loaded
444 DALI_TEST_CHECK(model.GetLoadingState() == ResourceLoadingSucceeded);
445 DALI_TEST_CHECK(actor);
446 DALI_TEST_CHECK(actor.GetName().compare("root") == 0);
448 DALI_TEST_EQUALS(model.NumberOfAnimations(), static_cast<size_t>(1), TEST_LOCATION);
449 unsigned int animIndex=0;
450 bool found = model.FindAnimation("Anim1", animIndex);
451 DALI_TEST_CHECK(found);
453 Animation twigAnim = ModelActorFactory::BuildAnimation(model, actor, animIndex, Dali::AlphaFunctions::EaseInOut, 5.0f);
454 DALI_TEST_CHECK(twigAnim);
455 DALI_TEST_EQUALS(twigAnim.GetDuration(), 5.0f, 0.001, TEST_LOCATION);
456 DALI_TEST_CHECK(twigAnim.GetDefaultAlphaFunction() == Dali::AlphaFunctions::EaseInOut);
461 int UtcDaliModelBuildAnimation04(void)
463 TestApplication application;
464 TestPlatformAbstraction& platform = application.GetPlatform();
466 tet_infoline("Testing Dali::MeshActor::New()");
468 Dali::ModelData modelData = BuildTreeModel();
471 Model model = Model::New("Tree");
473 application.SendNotification();
474 application.Render();
475 Integration::ResourceRequest* request = platform.GetRequest(); // Return modelData
478 platform.SetResourceLoaded(request->GetId(), request->GetType()->id, Integration::ResourcePointer(&(modelData.GetBaseObject())));
480 application.Render();
481 application.SendNotification();
483 Actor actor = ModelActorFactory::BuildActorTree(model, ""); // model should be loaded
485 DALI_TEST_CHECK(model.GetLoadingState() == ResourceLoadingSucceeded);
486 DALI_TEST_CHECK(actor);
487 DALI_TEST_CHECK(actor.GetName().compare("root") == 0);
489 DALI_TEST_EQUALS(model.NumberOfAnimations(), static_cast<size_t>(1), TEST_LOCATION);
491 unsigned int animIndex=0;
492 bool found = model.FindAnimation("Fred", animIndex);
493 DALI_TEST_CHECK(!found);
498 int UtcDaliModelBuildAnimation05(void)
500 TestApplication application;
501 TestPlatformAbstraction& platform = application.GetPlatform();
503 tet_infoline("Testing Dali::MeshActor::New()");
505 Dali::ModelData modelData = BuildTreeModel();
508 Model model = Model::New("Tree");
510 // Run Core - will query using TestPlatformAbstraction::GetResources().
511 application.SendNotification();
512 application.Render();
513 Integration::ResourceRequest* request = platform.GetRequest(); // Return modelData
516 platform.SetResourceLoaded(request->GetId(), request->GetType()->id, Integration::ResourcePointer(&(modelData.GetBaseObject())));
518 application.Render();
519 application.SendNotification();
521 Actor actor = ModelActorFactory::BuildActorTree(model, ""); // model should be loaded
523 DALI_TEST_CHECK(model.GetLoadingState() == ResourceLoadingSucceeded);
524 DALI_TEST_CHECK(actor);
525 DALI_TEST_CHECK(actor.GetName().compare("root") == 0);
527 DALI_TEST_EQUALS(model.NumberOfAnimations(), static_cast<size_t>(1), TEST_LOCATION);
528 Animation twigAnim = ModelActorFactory::BuildAnimation(model, actor, 0);
529 DALI_TEST_CHECK(twigAnim);
530 DALI_TEST_EQUALS(twigAnim.GetDuration(), 10.0f, 0.001, TEST_LOCATION);
531 DALI_TEST_CHECK(twigAnim.GetDefaultAlphaFunction() == Dali::AlphaFunctions::Linear);
536 int UtcDaliModelBuildAnimation06(void)
538 TestApplication application;
539 TestPlatformAbstraction& platform = application.GetPlatform();
541 tet_infoline("Testing Dali::MeshActor::New()");
543 Dali::ModelData modelData = BuildTreeModel();
546 Model model = Model::New("Tree");
548 application.SendNotification();
549 application.Render();
550 Integration::ResourceRequest* request = platform.GetRequest(); // Return modelData
553 platform.SetResourceLoaded(request->GetId(), request->GetType()->id, Integration::ResourcePointer(&(modelData.GetBaseObject())));
555 application.Render();
556 application.SendNotification();
558 Actor actor = ModelActorFactory::BuildActorTree(model, ""); // model should be loaded
560 DALI_TEST_CHECK(model.GetLoadingState() == ResourceLoadingSucceeded);
561 DALI_TEST_CHECK(actor);
562 DALI_TEST_CHECK(actor.GetName().compare("root") == 0);
564 DALI_TEST_EQUALS(model.NumberOfAnimations(), static_cast<size_t>(1), TEST_LOCATION);
565 Animation twigAnim = ModelActorFactory::BuildAnimation(model, actor, 0, 5.0f);
566 DALI_TEST_CHECK(twigAnim);
567 DALI_TEST_EQUALS(twigAnim.GetDuration(), 5.0f, 0.001, TEST_LOCATION);
568 DALI_TEST_CHECK(twigAnim.GetDefaultAlphaFunction() == Dali::AlphaFunctions::Linear);
573 int UtcDaliModelBuildAnimation07(void)
575 TestApplication application;
576 TestPlatformAbstraction& platform = application.GetPlatform();
578 tet_infoline("Testing Dali::MeshActor::New()");
580 Dali::ModelData modelData = BuildTreeModel();
583 Model model = Model::New("Tree");
585 application.SendNotification();
586 application.Render();
587 Integration::ResourceRequest* request = platform.GetRequest(); // Return modelData
590 platform.SetResourceLoaded(request->GetId(), request->GetType()->id, Integration::ResourcePointer(&(modelData.GetBaseObject())));
592 application.Render();
593 application.SendNotification();
595 Actor actor = ModelActorFactory::BuildActorTree(model, ""); // model should be loaded
597 DALI_TEST_CHECK(model.GetLoadingState() == ResourceLoadingSucceeded);
598 DALI_TEST_CHECK(actor);
599 DALI_TEST_CHECK(actor.GetName().compare("root") == 0);
601 DALI_TEST_EQUALS(model.NumberOfAnimations(), static_cast<size_t>(1), TEST_LOCATION);
602 Animation twigAnim = ModelActorFactory::BuildAnimation(model, actor, 0, Dali::AlphaFunctions::Bounce);
603 DALI_TEST_CHECK(twigAnim);
604 DALI_TEST_EQUALS(twigAnim.GetDuration(), 10.0f, 0.001, TEST_LOCATION);
605 DALI_TEST_CHECK(twigAnim.GetDefaultAlphaFunction() == Dali::AlphaFunctions::Bounce);
609 int UtcDaliModelBuildAnimation08(void)
611 TestApplication application;
612 TestPlatformAbstraction& platform = application.GetPlatform();
614 tet_infoline("Testing Dali::MeshActor::New()");
616 Dali::ModelData modelData = BuildTreeModel();
619 Model model = Model::New("Tree");
621 application.SendNotification();
622 application.Render();
623 Integration::ResourceRequest* request = platform.GetRequest(); // Return modelData
626 platform.SetResourceLoaded(request->GetId(), request->GetType()->id, Integration::ResourcePointer(&(modelData.GetBaseObject())));
628 application.Render();
629 application.SendNotification();
631 Actor actor = ModelActorFactory::BuildActorTree(model, ""); // model should be loaded
633 DALI_TEST_CHECK(model.GetLoadingState() == ResourceLoadingSucceeded);
634 DALI_TEST_CHECK(actor);
635 DALI_TEST_CHECK(actor.GetName().compare("root") == 0);
637 DALI_TEST_EQUALS(model.NumberOfAnimations(), static_cast<size_t>(1), TEST_LOCATION);
639 Animation twigAnim = ModelActorFactory::BuildAnimation(model, actor, 10);
640 DALI_TEST_CHECK(!twigAnim);