2 * Copyright (c) 2023 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.
18 #include <dali-toolkit-test-suite-utils.h>
19 #include <dali-toolkit/dali-toolkit.h>
20 #include <dali/devel-api/common/map-wrapper.h>
24 #include <dali-toolkit/devel-api/focus-manager/keyboard-focus-manager-devel.h>
25 #include <dali/integration-api/events/touch-event-integ.h>
26 #include <toolkit-event-thread-callback.h>
28 #include <dali-scene3d/public-api/controls/model/model.h>
29 #include <dali-scene3d/public-api/model-components/model-node.h>
31 #include <dali-scene3d/public-api/model-motion/motion-data.h>
32 #include <dali-scene3d/public-api/model-motion/motion-index/blend-shape-index.h>
33 #include <dali-scene3d/public-api/model-motion/motion-index/motion-transform-index.h>
35 #include <dali/devel-api/actors/camera-actor-devel.h>
38 using namespace Dali::Toolkit;
40 void model_startup(void)
42 test_return_value = TET_UNDEF;
45 void model_cleanup(void)
47 test_return_value = TET_PASS;
52 const bool DEFAULT_MODEL_CHILDREN_SENSITIVE = false;
53 const bool DEFAULT_MODEL_CHILDREN_FOCUSABLE = false;
55 * For the AnimatedCube.gltf and its Assets
56 * Donated by Norbert Nopper for glTF testing.
57 * Take from https://github.com/KhronosGroup/glTF-Sample-Models/tree/master/2.0/AnimatedCube
59 const char* TEST_GLTF_FILE_NAME = TEST_RESOURCE_DIR "/AnimatedCube.gltf";
60 const char* TEST_GLTF_ANIMATION_TEST_FILE_NAME = TEST_RESOURCE_DIR "/animationTest.gltf";
61 const char* TEST_GLTF_EXTRAS_FILE_NAME = TEST_RESOURCE_DIR "/AnimatedMorphCubeAnimateNonZeroFrame.gltf";
62 const char* TEST_GLTF_MULTIPLE_PRIMITIVE_FILE_NAME = TEST_RESOURCE_DIR "/simpleMultiplePrimitiveTest.gltf";
63 const char* TEST_GLTF_MORPH_FILE_NAME = TEST_RESOURCE_DIR "/AnimatedMorphCube.gltf";
64 const char* TEST_DLI_FILE_NAME = TEST_RESOURCE_DIR "/arc.dli";
65 const char* TEST_DLI_EXERCISE_FILE_NAME = TEST_RESOURCE_DIR "/exercise.dli";
68 * For the diffuse and specular cube map texture.
69 * These textures are based off version of Wave engine sample
70 * Take from https://github.com/WaveEngine/Samples
72 * Copyright (c) 2023 Wave Coorporation
74 * Permission is hereby granted, free of charge, to any person obtaining a copy
75 * of this software and associated documentation files (the "Software"), to
76 * deal in the Software without restriction, including without limitation the
77 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
78 * sell copies of the Software, and to permit persons to whom the Software is
79 * furnished to do so, subject to the following conditions:
81 * The above copyright notice and this permission notice shall be included in
82 * all copies or substantial portions of the Software.
84 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
85 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
86 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
87 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
88 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
89 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
92 const char* TEST_DIFFUSE_TEXTURE = TEST_RESOURCE_DIR "/forest_irradiance.ktx";
93 const char* TEST_SPECULAR_TEXTURE = TEST_RESOURCE_DIR "/forest_radiance.ktx";
95 bool gTouchCallBackCalled = false;
96 bool TestTouchCallback(Actor, const TouchEvent&)
98 gTouchCallBackCalled = true;
102 bool gFocusChangedCallBackCalled = false;
103 void TestFocusChangedCallback(Actor, Actor)
105 gFocusChangedCallBackCalled = true;
109 static bool gOnRelayoutCallBackCalled = false;
110 void OnRelayoutCallback(Actor actor)
112 gOnRelayoutCallBackCalled = true;
115 static bool gResourceReadyCalled = false;
116 void OnResourceReady(Control control)
118 gResourceReadyCalled = true;
123 // Negative test case for a method
124 int UtcDaliModelUninitialized(void)
126 ToolkitTestApplication application;
127 tet_infoline(" UtcDaliModelUninitialized");
129 Scene3D::Model model;
133 // New() must be called to create a Model or it wont be valid.
134 Actor a = Actor::New();
136 DALI_TEST_CHECK(false);
138 catch(Dali::DaliException& e)
140 // Tests that a negative test of an assertion succeeds
141 DALI_TEST_PRINT_ASSERT(e);
142 DALI_TEST_CHECK(!model);
147 // Positive test case for a method
148 int UtcDaliModelNew(void)
150 ToolkitTestApplication application;
151 tet_infoline(" UtcDaliModelNew");
153 Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
154 DALI_TEST_CHECK(model);
158 // Positive test case for a method
159 int UtcDaliModelNewP2(void)
161 ToolkitTestApplication application;
162 tet_infoline(" UtcDaliModelNew without url");
164 Scene3D::Model model = Scene3D::Model::New();
165 DALI_TEST_CHECK(model);
167 application.GetScene().Add(model);
169 DALI_TEST_CHECK(model.GetProperty<bool>(Actor::Property::CONNECTED_TO_SCENE));
171 application.GetScene().Remove(model);
173 DALI_TEST_CHECK(!model.GetProperty<bool>(Actor::Property::CONNECTED_TO_SCENE));
178 // Positive test case for a method
179 int UtcDaliModelDownCast(void)
181 ToolkitTestApplication application;
182 tet_infoline(" UtcDaliModelDownCast");
184 Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
185 BaseHandle handle(model);
187 Scene3D::Model model2 = Scene3D::Model::DownCast(handle);
188 DALI_TEST_CHECK(model);
189 DALI_TEST_CHECK(model2);
190 DALI_TEST_CHECK(model2 == model);
194 int UtcDaliModelTypeRegistry(void)
196 ToolkitTestApplication application;
198 TypeRegistry typeRegistry = TypeRegistry::Get();
199 DALI_TEST_CHECK(typeRegistry);
201 TypeInfo typeInfo = typeRegistry.GetTypeInfo("Model");
202 DALI_TEST_CHECK(typeInfo);
204 BaseHandle handle = typeInfo.CreateInstance();
205 DALI_TEST_CHECK(handle);
207 Scene3D::Model model = Scene3D::Model::DownCast(handle);
208 DALI_TEST_CHECK(model);
213 // Positive test case for a method
214 int UtcDaliModelAddRemove(void)
216 ToolkitTestApplication application;
217 tet_infoline(" UtcDaliModelAddRemove");
219 Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
220 DALI_TEST_CHECK(model);
222 Actor actor = Actor::New();
223 DALI_TEST_CHECK(!actor.GetProperty<bool>(Actor::Property::CONNECTED_TO_SCENE));
225 model.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
226 model.SetProperty(Actor::Property::SIZE, application.GetScene().GetSize());
228 application.GetScene().Add(model);
230 DALI_TEST_CHECK(actor.GetProperty<bool>(Actor::Property::CONNECTED_TO_SCENE));
234 DALI_TEST_CHECK(!actor.GetProperty<bool>(Actor::Property::CONNECTED_TO_SCENE));
238 int UtcDaliModelCopyAndAssignment(void)
240 ToolkitTestApplication application;
242 Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
243 DALI_TEST_CHECK(model);
245 Scene3D::Model copy(model);
246 DALI_TEST_CHECK(model == copy);
248 Scene3D::Model assign;
249 DALI_TEST_CHECK(!assign);
252 DALI_TEST_CHECK(assign == model);
257 int UtcDaliModelMoveConstructor(void)
259 ToolkitTestApplication application;
261 Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
262 DALI_TEST_EQUALS(1, model.GetBaseObject().ReferenceCount(), TEST_LOCATION);
263 model.SetProperty(Actor::Property::SENSITIVE, false);
264 DALI_TEST_CHECK(false == model.GetProperty<bool>(Actor::Property::SENSITIVE));
266 Scene3D::Model moved = std::move(model);
267 DALI_TEST_CHECK(moved);
268 DALI_TEST_EQUALS(1, moved.GetBaseObject().ReferenceCount(), TEST_LOCATION);
269 DALI_TEST_CHECK(false == moved.GetProperty<bool>(Actor::Property::SENSITIVE));
270 DALI_TEST_CHECK(!model);
275 int UtcDaliModelMoveAssignment(void)
277 ToolkitTestApplication application;
279 Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
280 DALI_TEST_EQUALS(1, model.GetBaseObject().ReferenceCount(), TEST_LOCATION);
281 model.SetProperty(Actor::Property::SENSITIVE, false);
282 DALI_TEST_CHECK(false == model.GetProperty<bool>(Actor::Property::SENSITIVE));
284 Scene3D::Model moved;
285 moved = std::move(model);
286 DALI_TEST_CHECK(moved);
287 DALI_TEST_EQUALS(1, moved.GetBaseObject().ReferenceCount(), TEST_LOCATION);
288 DALI_TEST_CHECK(false == moved.GetProperty<bool>(Actor::Property::SENSITIVE));
289 DALI_TEST_CHECK(!model);
294 int UtcDaliModelOnScene01(void)
296 ToolkitTestApplication application;
298 Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
299 application.GetScene().Add(model);
301 gResourceReadyCalled = false;
302 model.ResourceReadySignal().Connect(&OnResourceReady);
303 DALI_TEST_EQUALS(gResourceReadyCalled, false, TEST_LOCATION);
305 application.SendNotification();
306 application.Render();
308 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
309 application.SendNotification();
310 application.Render();
312 DALI_TEST_EQUALS(gResourceReadyCalled, true, TEST_LOCATION);
314 uint32_t modelCount = model.GetModelRoot().GetChildCount();
315 DALI_TEST_EQUALS(1, modelCount, TEST_LOCATION);
319 int UtcDaliModelOnScene02(void)
321 ToolkitTestApplication application;
323 Scene3D::Model model = Scene3D::Model::New(TEST_DLI_FILE_NAME);
324 application.GetScene().Add(model);
326 gResourceReadyCalled = false;
327 model.ResourceReadySignal().Connect(&OnResourceReady);
328 DALI_TEST_EQUALS(gResourceReadyCalled, false, TEST_LOCATION);
330 application.SendNotification();
331 application.Render();
333 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
334 application.SendNotification();
335 application.Render();
337 DALI_TEST_EQUALS(gResourceReadyCalled, true, TEST_LOCATION);
339 uint32_t modelCount = model.GetModelRoot().GetChildCount();
340 DALI_TEST_EQUALS(1, modelCount, TEST_LOCATION);
342 Scene3D::ModelNode rootNode = model.GetModelRoot();
343 Vector3 rootSize = rootNode.GetProperty<Vector3>(Dali::Actor::Property::SIZE);
344 DALI_TEST_EQUALS(Vector3(2, 2, 1), rootSize, TEST_LOCATION);
349 int UtcDaliModelOnSizeSet(void)
351 ToolkitTestApplication application;
353 Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
355 application.GetScene().Add(model);
357 application.SendNotification();
358 application.Render();
360 Vector2 size(200.0f, 300.0f);
361 model.SetProperty(Actor::Property::SIZE, size);
363 application.SendNotification();
364 application.Render();
366 DALI_TEST_EQUALS(model.GetCurrentProperty<Vector2>(Actor::Property::SIZE), size, TEST_LOCATION);
371 int UtcDaliModelGetNaturalSize(void)
373 ToolkitTestApplication application;
375 Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
377 Vector3 naturalSize = model.GetNaturalSize();
378 DALI_TEST_EQUALS(Vector3::ZERO, naturalSize, TEST_LOCATION);
380 application.GetScene().Add(model);
382 gResourceReadyCalled = false;
383 model.ResourceReadySignal().Connect(&OnResourceReady);
384 DALI_TEST_EQUALS(gResourceReadyCalled, false, TEST_LOCATION);
386 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
387 application.SendNotification();
389 DALI_TEST_EQUALS(gResourceReadyCalled, true, TEST_LOCATION);
391 naturalSize = model.GetNaturalSize();
392 DALI_TEST_EQUALS(Vector3(2, 2, 2), naturalSize, TEST_LOCATION);
394 Scene3D::ModelNode rootNode = model.GetModelRoot();
395 DALI_TEST_CHECK(rootNode);
400 int UtcDaliModelSetImageBasedLightSource01(void)
402 ToolkitTestApplication application;
404 Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
405 application.GetScene().Add(model);
407 gResourceReadyCalled = false;
408 model.ResourceReadySignal().Connect(&OnResourceReady);
409 DALI_TEST_EQUALS(gResourceReadyCalled, false, TEST_LOCATION);
411 application.SendNotification();
412 application.Render();
414 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
415 application.SendNotification();
416 application.Render();
418 DALI_TEST_EQUALS(gResourceReadyCalled, true, TEST_LOCATION);
420 Actor meshActor = model.FindChildByName("AnimatedCube");
421 DALI_TEST_CHECK(meshActor);
423 Renderer renderer = meshActor.GetRendererAt(0u);
424 DALI_TEST_CHECK(renderer);
426 TextureSet textureSet = renderer.GetTextures();
427 DALI_TEST_EQUALS(textureSet.GetTextureCount(), 9u, TEST_LOCATION);
429 Texture diffuseTexture = textureSet.GetTexture(7u);
430 Texture specularTexture = textureSet.GetTexture(8u);
432 gResourceReadyCalled = false;
433 DALI_TEST_EQUALS(gResourceReadyCalled, false, TEST_LOCATION);
434 model.SetImageBasedLightSource(TEST_DIFFUSE_TEXTURE, TEST_SPECULAR_TEXTURE);
436 application.SendNotification();
437 application.Render();
439 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
440 application.SendNotification();
441 application.Render();
443 DALI_TEST_EQUALS(gResourceReadyCalled, true, TEST_LOCATION);
445 TextureSet newTextureSet = renderer.GetTextures();
446 Texture newDiffuseTexture = newTextureSet.GetTexture(7u);
447 Texture newSpecularTexture = newTextureSet.GetTexture(8u);
449 DALI_TEST_NOT_EQUALS(diffuseTexture, newDiffuseTexture, 0.0f, TEST_LOCATION);
450 DALI_TEST_NOT_EQUALS(specularTexture, newSpecularTexture, 0.0f, TEST_LOCATION);
457 int UtcDaliModelSetImageBasedLightSource02(void)
459 ToolkitTestApplication application;
461 Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
462 application.GetScene().Add(model);
464 gResourceReadyCalled = false;
465 model.ResourceReadySignal().Connect(&OnResourceReady);
466 DALI_TEST_EQUALS(gResourceReadyCalled, false, TEST_LOCATION);
468 application.SendNotification();
469 application.Render();
471 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
472 application.SendNotification();
473 application.Render();
475 DALI_TEST_EQUALS(gResourceReadyCalled, true, TEST_LOCATION);
477 Actor meshActor = model.FindChildByName("AnimatedCube");
478 DALI_TEST_CHECK(meshActor);
480 Renderer renderer = meshActor.GetRendererAt(0u);
481 DALI_TEST_CHECK(renderer);
483 TextureSet textureSet = renderer.GetTextures();
484 DALI_TEST_EQUALS(textureSet.GetTextureCount(), 9u, TEST_LOCATION);
486 Texture diffuseTexture = textureSet.GetTexture(7u);
487 Texture specularTexture = textureSet.GetTexture(8u);
489 // if url is empty, loading is not requested.
490 model.SetImageBasedLightSource("", "");
492 Texture newDiffuseTexture = textureSet.GetTexture(7u);
493 Texture newSpecularTexture = textureSet.GetTexture(8u);
495 DALI_TEST_EQUALS(diffuseTexture, newDiffuseTexture, TEST_LOCATION);
496 DALI_TEST_EQUALS(specularTexture, newSpecularTexture, TEST_LOCATION);
501 int UtcDaliModelSetImageBasedLightSource03(void)
503 ToolkitTestApplication application;
505 Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
506 application.GetScene().Add(model);
508 gResourceReadyCalled = false;
509 model.ResourceReadySignal().Connect(&OnResourceReady);
510 DALI_TEST_EQUALS(gResourceReadyCalled, false, TEST_LOCATION);
512 application.SendNotification();
513 application.Render();
515 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
516 application.SendNotification();
517 application.Render();
519 DALI_TEST_EQUALS(gResourceReadyCalled, true, TEST_LOCATION);
521 Actor meshActor = model.FindChildByName("AnimatedCube");
522 DALI_TEST_CHECK(meshActor);
524 Renderer renderer = meshActor.GetRendererAt(0u);
525 DALI_TEST_CHECK(renderer);
527 TextureSet textureSet = renderer.GetTextures();
528 DALI_TEST_EQUALS(textureSet.GetTextureCount(), 9u, TEST_LOCATION);
530 Texture diffuseTexture = textureSet.GetTexture(7u);
531 Texture specularTexture = textureSet.GetTexture(8u);
533 gResourceReadyCalled = false;
534 DALI_TEST_EQUALS(gResourceReadyCalled, false, TEST_LOCATION);
535 model.SetImageBasedLightSource("dummy.ktx", "dummy.ktx");
537 application.SendNotification();
538 application.Render();
540 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
541 application.SendNotification();
542 application.Render();
544 DALI_TEST_EQUALS(gResourceReadyCalled, true, TEST_LOCATION);
546 Texture newDiffuseTexture = textureSet.GetTexture(7u);
547 Texture newSpecularTexture = textureSet.GetTexture(8u);
549 DALI_TEST_EQUALS(diffuseTexture, newDiffuseTexture, TEST_LOCATION);
550 DALI_TEST_EQUALS(specularTexture, newSpecularTexture, TEST_LOCATION);
555 int UtcDaliModelSetImageBasedLightSource04(void)
557 ToolkitTestApplication application;
559 Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
560 model.SetImageBasedLightSource(TEST_DIFFUSE_TEXTURE, TEST_SPECULAR_TEXTURE);
561 application.GetScene().Add(model);
563 gResourceReadyCalled = false;
564 model.ResourceReadySignal().Connect(&OnResourceReady);
565 DALI_TEST_EQUALS(gResourceReadyCalled, false, TEST_LOCATION);
567 application.SendNotification();
568 application.Render();
570 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(3), true, TEST_LOCATION);
571 application.SendNotification();
572 application.Render();
574 DALI_TEST_EQUALS(gResourceReadyCalled, true, TEST_LOCATION);
578 int UtcDaliModelImageBasedFactor(void)
580 ToolkitTestApplication application;
582 Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
584 DALI_TEST_EQUALS(model.GetImageBasedLightScaleFactor(), 1.0f, TEST_LOCATION);
586 model.SetImageBasedLightScaleFactor(0.5f);
587 DALI_TEST_EQUALS(model.GetImageBasedLightScaleFactor(), 0.5f, TEST_LOCATION);
591 int UtcDaliModelChildrenSensitive01(void)
593 ToolkitTestApplication application;
595 Scene3D::Model view = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
596 view.SetProperty(Dali::Actor::Property::SIZE, Vector3(100, 100, 100));
597 view.SetProperty(Dali::Actor::Property::POSITION, Vector3(0, 0, 0));
598 view.SetProperty(Dali::Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER);
599 view.SetProperty(Dali::Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
601 // Get default vaule.
602 DALI_TEST_EQUALS(view.GetChildrenSensitive(), DEFAULT_MODEL_CHILDREN_SENSITIVE, TEST_LOCATION);
604 // Allow children actor's event before on scene.
605 view.SetChildrenSensitive(true);
606 DALI_TEST_EQUALS(view.GetChildrenSensitive(), true, TEST_LOCATION);
607 application.GetScene().Add(view);
609 gResourceReadyCalled = false;
610 view.ResourceReadySignal().Connect(&OnResourceReady);
611 DALI_TEST_EQUALS(gResourceReadyCalled, false, TEST_LOCATION);
613 application.SendNotification();
614 application.Render();
616 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
617 application.SendNotification();
618 application.Render();
620 DALI_TEST_EQUALS(gResourceReadyCalled, true, TEST_LOCATION);
622 Actor meshActor = view.FindChildByName("AnimatedCube");
623 DALI_TEST_CHECK(meshActor);
625 // connect hit-test signal
626 gTouchCallBackCalled = false;
627 meshActor.TouchedSignal().Connect(TestTouchCallback);
629 Vector2 sceneSize = application.GetScene().GetSize();
631 // Try to touch center of scene.
632 Dali::Integration::Point point;
633 point.SetState(PointState::DOWN);
634 point.SetScreenPosition(sceneSize * 0.5f);
635 Dali::Integration::TouchEvent event;
636 event.AddPoint(point);
638 // flush the queue and render once
639 application.SendNotification();
640 application.Render();
643 DALI_TEST_CHECK(!gTouchCallBackCalled);
644 application.ProcessEvent(event);
646 DALI_TEST_CHECK(gTouchCallBackCalled);
649 gTouchCallBackCalled = false;
651 // Block children actor's event
652 view.SetChildrenSensitive(false);
653 DALI_TEST_EQUALS(view.GetChildrenSensitive(), false, TEST_LOCATION);
655 // flush the queue and render once
656 application.SendNotification();
657 application.Render();
660 DALI_TEST_CHECK(!gTouchCallBackCalled);
661 application.ProcessEvent(event);
663 DALI_TEST_CHECK(!gTouchCallBackCalled);
666 gTouchCallBackCalled = false;
669 view.SetChildrenSensitive(true);
670 DALI_TEST_EQUALS(view.GetChildrenSensitive(), true, TEST_LOCATION);
672 // flush the queue and render once
673 application.SendNotification();
674 application.Render();
677 DALI_TEST_CHECK(!gTouchCallBackCalled);
678 application.ProcessEvent(event);
680 DALI_TEST_CHECK(gTouchCallBackCalled);
683 gTouchCallBackCalled = false;
688 int UtcDaliModelChildrenSensitive02(void)
690 ToolkitTestApplication application;
692 Scene3D::Model view = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
693 view.SetProperty(Dali::Actor::Property::SIZE, Vector3(100, 100, 100));
694 view.SetProperty(Dali::Actor::Property::POSITION, Vector3(0, 0, 0));
695 view.SetProperty(Dali::Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER);
696 view.SetProperty(Dali::Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
699 DALI_TEST_EQUALS(view.GetChildrenSensitive(), DEFAULT_MODEL_CHILDREN_SENSITIVE, TEST_LOCATION);
701 // Block children actor's event before on scene.
702 view.SetChildrenSensitive(false);
703 DALI_TEST_EQUALS(view.GetChildrenSensitive(), false, TEST_LOCATION);
704 application.GetScene().Add(view);
706 gResourceReadyCalled = false;
707 view.ResourceReadySignal().Connect(&OnResourceReady);
708 DALI_TEST_EQUALS(gResourceReadyCalled, false, TEST_LOCATION);
710 application.SendNotification();
711 application.Render();
713 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
714 application.SendNotification();
715 application.Render();
717 DALI_TEST_EQUALS(gResourceReadyCalled, true, TEST_LOCATION);
719 Actor meshActor = view.FindChildByName("AnimatedCube");
720 DALI_TEST_CHECK(meshActor);
722 // connect hit-test signal
723 gTouchCallBackCalled = false;
724 meshActor.TouchedSignal().Connect(TestTouchCallback);
726 Vector2 sceneSize = application.GetScene().GetSize();
728 // Try to touch center of scene.
729 Dali::Integration::Point point;
730 point.SetState(PointState::DOWN);
731 point.SetScreenPosition(sceneSize * 0.5f);
732 Dali::Integration::TouchEvent event;
733 event.AddPoint(point);
735 // flush the queue and render once
736 application.SendNotification();
737 application.Render();
740 DALI_TEST_CHECK(!gTouchCallBackCalled);
741 application.ProcessEvent(event);
743 DALI_TEST_CHECK(!gTouchCallBackCalled);
746 gTouchCallBackCalled = false;
749 view.SetChildrenSensitive(true);
750 DALI_TEST_EQUALS(view.GetChildrenSensitive(), true, TEST_LOCATION);
752 // flush the queue and render once
753 application.SendNotification();
754 application.Render();
757 DALI_TEST_CHECK(!gTouchCallBackCalled);
758 application.ProcessEvent(event);
760 DALI_TEST_CHECK(gTouchCallBackCalled);
763 gTouchCallBackCalled = false;
768 int UtcDaliModelChildrenFocusable01(void)
770 ToolkitTestApplication application;
772 Scene3D::Model view = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
773 view.SetProperty(Dali::Actor::Property::SIZE, Vector3(100, 100, 100));
774 view.SetProperty(Dali::Actor::Property::POSITION, Vector3(0, 0, 0));
775 view.SetProperty(Dali::Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER);
776 view.SetProperty(Dali::Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
778 // Get vaule. Default is false.
779 DALI_TEST_EQUALS(view.GetChildrenFocusable(), DEFAULT_MODEL_CHILDREN_FOCUSABLE, TEST_LOCATION);
781 // Allow children actor's focus before on scene.
782 view.SetChildrenFocusable(true);
783 DALI_TEST_EQUALS(view.GetChildrenFocusable(), true, TEST_LOCATION);
784 application.GetScene().Add(view);
786 gResourceReadyCalled = false;
787 view.ResourceReadySignal().Connect(&OnResourceReady);
788 DALI_TEST_EQUALS(gResourceReadyCalled, false, TEST_LOCATION);
790 application.SendNotification();
791 application.Render();
793 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
794 application.SendNotification();
795 application.Render();
797 DALI_TEST_EQUALS(gResourceReadyCalled, true, TEST_LOCATION);
799 Actor meshActor = view.FindChildByName("AnimatedCube");
800 DALI_TEST_CHECK(meshActor);
802 // Enable the default algorithm
803 KeyboardFocusManager manager = KeyboardFocusManager::Get();
804 DALI_TEST_CHECK(manager);
805 Dali::Toolkit::DevelKeyboardFocusManager::EnableDefaultAlgorithm(manager, true);
807 // connect focusable signal
808 gFocusChangedCallBackCalled = false;
809 meshActor.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true);
810 manager.FocusChangedSignal().Connect(TestFocusChangedCallback);
812 // Initialize with some left-positioned actor
813 Control focusStartActor = Control::New();
814 focusStartActor.SetProperty(Dali::Actor::Property::SIZE, Vector3(100, 100, 100));
815 focusStartActor.SetProperty(Dali::Actor::Property::POSITION, Vector3(-200, 0, 0));
816 focusStartActor.SetProperty(Dali::Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER);
817 focusStartActor.SetProperty(Dali::Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
818 focusStartActor.SetProperty(Dali::Actor::Property::KEYBOARD_FOCUSABLE, true);
819 application.GetScene().Add(focusStartActor);
822 manager.ClearFocus();
823 manager.SetCurrentFocusActor(focusStartActor);
824 gFocusChangedCallBackCalled = false;
826 // flush the queue and render once
827 application.SendNotification();
828 application.Render();
830 // Focusable view find success
831 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::RIGHT) == true);
832 DALI_TEST_CHECK(gFocusChangedCallBackCalled);
835 manager.ClearFocus();
836 manager.SetCurrentFocusActor(focusStartActor);
837 gFocusChangedCallBackCalled = false;
839 // Block children actor's focus
840 view.SetChildrenFocusable(false);
841 DALI_TEST_EQUALS(view.GetChildrenFocusable(), false, TEST_LOCATION);
843 // flush the queue and render once
844 application.SendNotification();
845 application.Render();
847 // Focusable view find failed
848 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::RIGHT) == false);
849 DALI_TEST_CHECK(!gFocusChangedCallBackCalled);
852 manager.ClearFocus();
853 manager.SetCurrentFocusActor(focusStartActor);
854 gFocusChangedCallBackCalled = false;
857 view.SetChildrenFocusable(true);
858 DALI_TEST_EQUALS(view.GetChildrenFocusable(), true, TEST_LOCATION);
860 // flush the queue and render once
861 application.SendNotification();
862 application.Render();
864 // Focusable view find success
865 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::RIGHT) == true);
866 DALI_TEST_CHECK(gFocusChangedCallBackCalled);
869 manager.ClearFocus();
870 manager.SetCurrentFocusActor(focusStartActor);
871 gFocusChangedCallBackCalled = false;
876 int UtcDaliModelModelChildrenFocusable02(void)
878 ToolkitTestApplication application;
880 Scene3D::Model view = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
881 view.SetProperty(Dali::Actor::Property::SIZE, Vector3(100, 100, 100));
882 view.SetProperty(Dali::Actor::Property::POSITION, Vector3(0, 0, 0));
883 view.SetProperty(Dali::Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER);
884 view.SetProperty(Dali::Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
886 // Get vaule. Default is true.
887 DALI_TEST_EQUALS(view.GetChildrenFocusable(), DEFAULT_MODEL_CHILDREN_FOCUSABLE, TEST_LOCATION);
889 // Block children actor's focus before on scene.
890 view.SetChildrenFocusable(false);
891 DALI_TEST_EQUALS(view.GetChildrenFocusable(), false, TEST_LOCATION);
892 application.GetScene().Add(view);
894 gResourceReadyCalled = false;
895 view.ResourceReadySignal().Connect(&OnResourceReady);
896 DALI_TEST_EQUALS(gResourceReadyCalled, false, TEST_LOCATION);
898 application.SendNotification();
899 application.Render();
901 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
902 application.SendNotification();
903 application.Render();
905 DALI_TEST_EQUALS(gResourceReadyCalled, true, TEST_LOCATION);
907 Actor meshActor = view.FindChildByName("AnimatedCube");
908 DALI_TEST_CHECK(meshActor);
910 // Enable the default algorithm
911 KeyboardFocusManager manager = KeyboardFocusManager::Get();
912 DALI_TEST_CHECK(manager);
913 Dali::Toolkit::DevelKeyboardFocusManager::EnableDefaultAlgorithm(manager, true);
915 // connect focusable signal
916 gFocusChangedCallBackCalled = false;
917 meshActor.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true);
918 manager.FocusChangedSignal().Connect(TestFocusChangedCallback);
920 // Initialize with some left-positioned actor
921 Control focusStartActor = Control::New();
922 focusStartActor.SetProperty(Dali::Actor::Property::SIZE, Vector3(100, 100, 100));
923 focusStartActor.SetProperty(Dali::Actor::Property::POSITION, Vector3(-200, 0, 0));
924 focusStartActor.SetProperty(Dali::Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER);
925 focusStartActor.SetProperty(Dali::Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
926 focusStartActor.SetProperty(Dali::Actor::Property::KEYBOARD_FOCUSABLE, true);
927 application.GetScene().Add(focusStartActor);
930 manager.ClearFocus();
931 manager.SetCurrentFocusActor(focusStartActor);
932 gFocusChangedCallBackCalled = false;
934 // flush the queue and render once
935 application.SendNotification();
936 application.Render();
938 // Focusable view find failed
939 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::RIGHT) == false);
940 DALI_TEST_CHECK(!gFocusChangedCallBackCalled);
943 manager.ClearFocus();
944 manager.SetCurrentFocusActor(focusStartActor);
945 gFocusChangedCallBackCalled = false;
948 view.SetChildrenFocusable(true);
949 DALI_TEST_EQUALS(view.GetChildrenFocusable(), true, TEST_LOCATION);
951 // flush the queue and render once
952 application.SendNotification();
953 application.Render();
955 // Focusable view find success
956 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::RIGHT) == true);
957 DALI_TEST_CHECK(gFocusChangedCallBackCalled);
960 manager.ClearFocus();
961 manager.SetCurrentFocusActor(focusStartActor);
962 gFocusChangedCallBackCalled = false;
967 int UtcDaliModelAnimation01(void)
969 ToolkitTestApplication application;
971 Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
972 model.SetProperty(Dali::Actor::Property::SIZE, Vector2(50, 50));
973 application.GetScene().Add(model);
975 gResourceReadyCalled = false;
976 model.ResourceReadySignal().Connect(&OnResourceReady);
977 DALI_TEST_EQUALS(gResourceReadyCalled, false, TEST_LOCATION);
979 application.SendNotification();
980 application.Render();
982 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
983 application.SendNotification();
984 application.Render();
986 DALI_TEST_EQUALS(gResourceReadyCalled, true, TEST_LOCATION);
988 uint32_t animationCount = model.GetAnimationCount();
989 DALI_TEST_EQUALS(1, animationCount, TEST_LOCATION);
991 Animation animationByIndex = model.GetAnimation(0u);
992 DALI_TEST_CHECK(animationByIndex);
994 Animation animationByName = model.GetAnimation("animation_AnimatedCube");
995 DALI_TEST_CHECK(animationByName);
996 DALI_TEST_EQUALS(animationByIndex, animationByName, TEST_LOCATION);
1001 int UtcDaliModelAnimation02(void)
1003 ToolkitTestApplication application;
1005 Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_ANIMATION_TEST_FILE_NAME);
1006 model.SetProperty(Dali::Actor::Property::SIZE, Vector2(50, 50));
1007 application.GetScene().Add(model);
1009 gResourceReadyCalled = false;
1010 model.ResourceReadySignal().Connect(&OnResourceReady);
1011 DALI_TEST_EQUALS(gResourceReadyCalled, false, TEST_LOCATION);
1013 application.SendNotification();
1014 application.Render();
1016 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1017 application.SendNotification();
1018 application.Render();
1020 uint32_t animationCount = model.GetAnimationCount();
1021 DALI_TEST_EQUALS(9, animationCount, TEST_LOCATION);
1023 Animation animation1 = model.GetAnimation("Step Scale");
1024 DALI_TEST_CHECK(animation1);
1025 DALI_TEST_EQUALS(1.66667f, animation1.GetDuration(), 0.001f, TEST_LOCATION);
1027 Animation animation2 = model.GetAnimation("CubicSpline Scale");
1028 DALI_TEST_CHECK(animation2);
1029 DALI_TEST_EQUALS(1.66667f, animation2.GetDuration(), 0.001f, TEST_LOCATION);
1031 DALI_TEST_NOT_EQUALS(animation1, animation2, 0.0f, TEST_LOCATION);
1036 int UtcDaliModelAnimation03(void)
1038 ToolkitTestApplication application;
1040 Scene3D::Model model = Scene3D::Model::New(TEST_DLI_EXERCISE_FILE_NAME);
1041 model.SetProperty(Dali::Actor::Property::SIZE, Vector2(50, 50));
1042 application.GetScene().Add(model);
1044 gResourceReadyCalled = false;
1045 model.ResourceReadySignal().Connect(&OnResourceReady);
1046 DALI_TEST_EQUALS(gResourceReadyCalled, false, TEST_LOCATION);
1048 application.SendNotification();
1049 application.Render();
1051 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1052 application.SendNotification();
1053 application.Render();
1055 DALI_TEST_EQUALS(gResourceReadyCalled, true, TEST_LOCATION);
1057 uint32_t animationCount = model.GetAnimationCount();
1058 DALI_TEST_EQUALS(18, animationCount, TEST_LOCATION);
1060 Animation animationByIndex = model.GetAnimation(0u);
1061 DALI_TEST_CHECK(animationByIndex);
1063 Animation animationByName = model.GetAnimation("idleClip");
1064 DALI_TEST_CHECK(animationByName);
1065 DALI_TEST_EQUALS(animationByIndex, animationByName, TEST_LOCATION);
1070 int UtcDaliModelCameraGenerate01(void)
1072 ToolkitTestApplication application;
1074 Scene3D::Model model = Scene3D::Model::New(TEST_DLI_EXERCISE_FILE_NAME);
1075 model.SetProperty(Dali::Actor::Property::SIZE, Vector2(50, 50));
1076 application.GetScene().Add(model);
1078 gResourceReadyCalled = false;
1079 model.ResourceReadySignal().Connect(&OnResourceReady);
1080 DALI_TEST_EQUALS(gResourceReadyCalled, false, TEST_LOCATION);
1082 application.SendNotification();
1083 application.Render();
1085 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1086 application.SendNotification();
1087 application.Render();
1089 DALI_TEST_EQUALS(gResourceReadyCalled, true, TEST_LOCATION);
1091 uint32_t cameraCount = model.GetCameraCount();
1092 DALI_TEST_EQUALS(1, cameraCount, TEST_LOCATION);
1094 CameraActor generatedCamera = model.GenerateCamera(0u);
1095 DALI_TEST_CHECK(generatedCamera);
1097 generatedCamera = model.GenerateCamera(1u); // Fail to generate camera
1098 DALI_TEST_CHECK(!generatedCamera);
1103 int UtcDaliModelCameraGenerate02(void)
1105 ToolkitTestApplication application;
1107 Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
1108 model.SetProperty(Dali::Actor::Property::SIZE, Vector2(50, 50));
1109 application.GetScene().Add(model);
1111 gResourceReadyCalled = false;
1112 model.ResourceReadySignal().Connect(&OnResourceReady);
1113 DALI_TEST_EQUALS(gResourceReadyCalled, false, TEST_LOCATION);
1115 application.SendNotification();
1116 application.Render();
1118 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1119 application.SendNotification();
1120 application.Render();
1122 DALI_TEST_EQUALS(gResourceReadyCalled, true, TEST_LOCATION);
1124 uint32_t cameraCount = model.GetCameraCount();
1125 DALI_TEST_EQUALS(6, cameraCount, TEST_LOCATION);
1127 CameraActor generatedCamera0 = model.GenerateCamera(0u);
1128 DALI_TEST_CHECK(generatedCamera0);
1129 CameraActor generatedCamera1 = model.GenerateCamera(1u);
1130 DALI_TEST_CHECK(generatedCamera1);
1131 CameraActor generatedCamera2 = model.GenerateCamera(2u);
1132 DALI_TEST_CHECK(generatedCamera2);
1133 CameraActor generatedCamera3 = model.GenerateCamera(3u); // Infinity far camera
1134 DALI_TEST_CHECK(generatedCamera3);
1135 CameraActor generatedCamera4 = model.GenerateCamera(4u); // Broken camera 1
1136 DALI_TEST_CHECK(!generatedCamera4);
1137 CameraActor generatedCamera5 = model.GenerateCamera(5u); // Broken camera 2
1138 DALI_TEST_CHECK(!generatedCamera5);
1139 CameraActor generatedCamera6 = model.GenerateCamera(6u); // Out of bound
1140 DALI_TEST_CHECK(!generatedCamera6);
1142 CameraActor appliedCamera;
1143 DALI_TEST_EQUALS(model.ApplyCamera(0u, appliedCamera), false, TEST_LOCATION); // Cannot apply into empty camera.
1145 auto CompareCameraProperties = [](CameraActor lhs, CameraActor rhs, const char* location) {
1146 DALI_TEST_EQUALS(lhs.GetProperty<int>(Dali::CameraActor::Property::PROJECTION_MODE), rhs.GetProperty<int>(Dali::CameraActor::Property::PROJECTION_MODE), TEST_LOCATION);
1147 DALI_TEST_EQUALS(lhs.GetProperty<float>(Dali::CameraActor::Property::NEAR_PLANE_DISTANCE), rhs.GetProperty<float>(Dali::CameraActor::Property::NEAR_PLANE_DISTANCE), TEST_LOCATION);
1149 if(lhs.GetProperty<int>(Dali::CameraActor::Property::PROJECTION_MODE) == static_cast<int>(Dali::Camera::ProjectionMode::PERSPECTIVE_PROJECTION))
1151 DALI_TEST_EQUALS(lhs.GetProperty<float>(Dali::CameraActor::Property::FIELD_OF_VIEW), rhs.GetProperty<float>(Dali::CameraActor::Property::FIELD_OF_VIEW), TEST_LOCATION);
1152 // TODO : Open this test when infinity far projection implement.
1153 // DALI_TEST_EQUALS(lhs.GetProperty<float>(Dali::CameraActor::Property::FAR_PLANE_DISTANCE), rhs.GetProperty<float>(Dali::CameraActor::Property::FAR_PLANE_DISTANCE), TEST_LOCATION);
1157 DALI_TEST_EQUALS(lhs.GetProperty<float>(Dali::DevelCameraActor::Property::ORTHOGRAPHIC_SIZE), rhs.GetProperty<float>(Dali::DevelCameraActor::Property::ORTHOGRAPHIC_SIZE), TEST_LOCATION);
1158 DALI_TEST_EQUALS(lhs.GetProperty<float>(Dali::CameraActor::Property::FAR_PLANE_DISTANCE), rhs.GetProperty<float>(Dali::CameraActor::Property::FAR_PLANE_DISTANCE), TEST_LOCATION);
1162 appliedCamera = CameraActor::New();
1163 DALI_TEST_EQUALS(model.ApplyCamera(0u, appliedCamera), true, TEST_LOCATION);
1164 CompareCameraProperties(generatedCamera0, appliedCamera, TEST_LOCATION);
1165 DALI_TEST_EQUALS(model.ApplyCamera(1u, appliedCamera), true, TEST_LOCATION);
1166 CompareCameraProperties(generatedCamera1, appliedCamera, TEST_LOCATION);
1167 DALI_TEST_EQUALS(model.ApplyCamera(2u, appliedCamera), true, TEST_LOCATION);
1168 CompareCameraProperties(generatedCamera2, appliedCamera, TEST_LOCATION);
1169 DALI_TEST_EQUALS(model.ApplyCamera(3u, appliedCamera), true, TEST_LOCATION);
1170 CompareCameraProperties(generatedCamera3, appliedCamera, TEST_LOCATION);
1171 DALI_TEST_EQUALS(model.ApplyCamera(4u, appliedCamera), false, TEST_LOCATION); // Broken camera 1
1172 DALI_TEST_EQUALS(model.ApplyCamera(5u, appliedCamera), false, TEST_LOCATION); // Broken camera 2
1173 DALI_TEST_EQUALS(model.ApplyCamera(6u, appliedCamera), false, TEST_LOCATION); // Cannot apply over the index.
1178 int UtcDaliModelMultiplePrimitives(void)
1180 ToolkitTestApplication application;
1182 Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_MULTIPLE_PRIMITIVE_FILE_NAME);
1183 model.SetProperty(Dali::Actor::Property::SIZE, Vector2(50, 50));
1184 application.GetScene().Add(model);
1186 gResourceReadyCalled = false;
1187 model.ResourceReadySignal().Connect(&OnResourceReady);
1188 DALI_TEST_EQUALS(gResourceReadyCalled, false, TEST_LOCATION);
1190 application.SendNotification();
1191 application.Render();
1193 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1194 application.SendNotification();
1195 application.Render();
1197 Actor actor = model.FindChildByName("rootNode");
1199 DALI_TEST_EQUALS(0, actor.GetChildCount(), TEST_LOCATION);
1200 DALI_TEST_EQUALS(2, actor.GetRendererCount(), TEST_LOCATION);
1205 int UtcDaliModelColorMode(void)
1207 ToolkitTestApplication application;
1209 Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
1210 model.SetProperty(Dali::Actor::Property::SIZE, Vector2(50, 50));
1211 model.SetProperty(Dali::Actor::Property::COLOR, Color::RED);
1212 application.GetScene().Add(model);
1214 gResourceReadyCalled = false;
1215 model.ResourceReadySignal().Connect(&OnResourceReady);
1216 DALI_TEST_EQUALS(gResourceReadyCalled, false, TEST_LOCATION);
1218 application.SendNotification();
1219 application.Render();
1221 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1222 application.SendNotification();
1223 application.Render();
1225 Actor actor = model.FindChildByName("AnimatedCube");
1226 Vector4 childColor = actor[Dali::Actor::Property::COLOR];
1227 Vector4 childWorldColor = actor[Dali::Actor::Property::WORLD_COLOR];
1229 DALI_TEST_EQUALS(childColor, Color::WHITE, TEST_LOCATION);
1230 DALI_TEST_EQUALS(childWorldColor, Color::RED, TEST_LOCATION);
1235 int UtcDaliModelResourceReady(void)
1237 ToolkitTestApplication application;
1239 gOnRelayoutCallBackCalled = false;
1240 gResourceReadyCalled = false;
1241 Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_ANIMATION_TEST_FILE_NAME);
1242 model.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
1243 model.OnRelayoutSignal().Connect(OnRelayoutCallback);
1244 model.ResourceReadySignal().Connect(OnResourceReady);
1245 DALI_TEST_EQUALS(model.IsResourceReady(), false, TEST_LOCATION);
1248 DALI_TEST_CHECK(!gOnRelayoutCallBackCalled);
1249 DALI_TEST_CHECK(!gResourceReadyCalled);
1251 application.GetScene().Add(model);
1253 application.SendNotification();
1254 application.Render();
1256 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1257 application.SendNotification();
1258 application.Render();
1260 DALI_TEST_EQUALS(gOnRelayoutCallBackCalled, false, TEST_LOCATION);
1261 DALI_TEST_EQUALS(model.IsResourceReady(), true, TEST_LOCATION);
1262 DALI_TEST_EQUALS(gResourceReadyCalled, true, TEST_LOCATION);
1267 int UtcDaliModelResourceCacheCheck(void)
1269 ToolkitTestApplication application;
1271 // Load three instances of the same model and add them to the scene
1272 Scene3D::Model model1 = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
1273 Scene3D::Model model2 = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
1274 Scene3D::Model model3 = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
1276 application.GetScene().Add(model1);
1277 application.GetScene().Add(model2);
1278 application.GetScene().Add(model3);
1280 gResourceReadyCalled = false;
1281 model1.ResourceReadySignal().Connect(&OnResourceReady);
1282 model2.ResourceReadySignal().Connect(&OnResourceReady);
1283 model3.ResourceReadySignal().Connect(&OnResourceReady);
1284 DALI_TEST_EQUALS(gResourceReadyCalled, false, TEST_LOCATION);
1286 application.SendNotification();
1287 application.Render();
1289 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(3), true, TEST_LOCATION);
1290 application.SendNotification();
1291 application.Render();
1293 // Check that the loading has finished for all the three instances
1294 DALI_TEST_EQUALS(gResourceReadyCalled, true, TEST_LOCATION);
1296 Actor meshActor1 = model1.FindChildByName("AnimatedCube");
1297 Actor meshActor2 = model2.FindChildByName("AnimatedCube");
1298 Actor meshActor3 = model3.FindChildByName("AnimatedCube");
1299 DALI_TEST_CHECK(meshActor1);
1300 DALI_TEST_CHECK(meshActor2);
1301 DALI_TEST_CHECK(meshActor3);
1303 Renderer renderer1 = meshActor1.GetRendererAt(0u);
1304 Renderer renderer2 = meshActor2.GetRendererAt(0u);
1305 Renderer renderer3 = meshActor3.GetRendererAt(0u);
1306 DALI_TEST_CHECK(renderer1);
1307 DALI_TEST_CHECK(renderer2);
1308 DALI_TEST_CHECK(renderer3);
1310 // Check that all the three instances use the shared textures and geometries from the cache
1311 // but have their own shader objects
1312 DALI_TEST_EQUALS(renderer1.GetTextures(), renderer2.GetTextures(), TEST_LOCATION);
1313 DALI_TEST_EQUALS(renderer1.GetTextures(), renderer3.GetTextures(), TEST_LOCATION);
1314 DALI_TEST_EQUALS(renderer1.GetGeometry(), renderer2.GetGeometry(), TEST_LOCATION);
1315 DALI_TEST_EQUALS(renderer1.GetGeometry(), renderer3.GetGeometry(), TEST_LOCATION);
1316 DALI_TEST_NOT_EQUALS(renderer1.GetShader(), renderer2.GetShader(), 0.0f, TEST_LOCATION);
1317 DALI_TEST_NOT_EQUALS(renderer1.GetShader(), renderer3.GetShader(), 0.0f, TEST_LOCATION);
1318 DALI_TEST_NOT_EQUALS(renderer2.GetShader(), renderer3.GetShader(), 0.0f, TEST_LOCATION);
1324 // Check that all the other two instances still use the shared textures and geometries from the cache
1325 // but have their own shader objects
1326 DALI_TEST_EQUALS(renderer2.GetTextures(), renderer3.GetTextures(), TEST_LOCATION);
1327 DALI_TEST_EQUALS(renderer2.GetGeometry(), renderer3.GetGeometry(), TEST_LOCATION);
1328 DALI_TEST_NOT_EQUALS(renderer2.GetShader(), renderer3.GetShader(), 0.0f, TEST_LOCATION);
1330 // Set new IBL textures for model2, and this should apply to model2 instance only
1331 gResourceReadyCalled = false;
1332 DALI_TEST_EQUALS(gResourceReadyCalled, false, TEST_LOCATION);
1333 model2.SetImageBasedLightSource(TEST_DIFFUSE_TEXTURE, TEST_SPECULAR_TEXTURE);
1335 application.SendNotification();
1336 application.Render();
1338 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1339 application.SendNotification();
1340 application.Render();
1342 // Check that the new IBL textures are loaded for model2
1343 DALI_TEST_EQUALS(gResourceReadyCalled, true, TEST_LOCATION);
1345 // Check that the two instances still use the shared geometries from the cache
1346 // but now have their own shader objects and different texture set
1347 DALI_TEST_NOT_EQUALS(renderer2.GetTextures(), renderer3.GetTextures(), 0.0f, TEST_LOCATION);
1348 DALI_TEST_EQUALS(renderer2.GetGeometry(), renderer3.GetGeometry(), TEST_LOCATION);
1349 DALI_TEST_NOT_EQUALS(renderer2.GetShader(), renderer3.GetShader(), 0.0f, TEST_LOCATION);
1351 // Check that the two instances now have their own diffuse texture and specular texture,
1352 // but all the other textures are still the same
1353 TextureSet textureSet2 = renderer2.GetTextures();
1354 TextureSet textureSet3 = renderer3.GetTextures();
1355 DALI_TEST_EQUALS(textureSet2.GetTextureCount(), 9u, TEST_LOCATION);
1356 DALI_TEST_EQUALS(textureSet3.GetTextureCount(), 9u, TEST_LOCATION);
1358 for(uint32_t i = 0; i < 7u; i++)
1360 DALI_TEST_EQUALS(textureSet2.GetTexture(i), textureSet3.GetTexture(i), TEST_LOCATION);
1363 DALI_TEST_NOT_EQUALS(textureSet2.GetTexture(7u), textureSet3.GetTexture(7u), 0.0f, TEST_LOCATION);
1364 DALI_TEST_NOT_EQUALS(textureSet2.GetTexture(8u), textureSet3.GetTexture(8u), 0.0f, TEST_LOCATION);
1369 int UtcDaliModelAddRemoveModelNode(void)
1371 ToolkitTestApplication application;
1373 Scene3D::Model model = Scene3D::Model::New();
1374 model.SetProperty(Dali::Actor::Property::SIZE, Vector2(50, 50));
1376 Scene3D::ModelNode node1 = Scene3D::ModelNode::New();
1377 Scene3D::ModelNode node2 = Scene3D::ModelNode::New();
1378 Scene3D::ModelNode node3 = Scene3D::ModelNode::New();
1379 Scene3D::ModelNode node4 = Scene3D::ModelNode::New();
1381 model.AddModelNode(node1);
1382 model.AddModelNode(node2);
1383 model.AddModelNode(node3);
1384 model.RemoveModelNode(node1); // Remove node before scene on
1386 application.GetScene().Add(model);
1388 Dali::Scene3D::ModelNode root = model.GetModelRoot();
1389 DALI_TEST_CHECK(root);
1390 DALI_TEST_EQUALS(2, root.GetChildCount(), TEST_LOCATION);
1392 model.RemoveModelNode(node2); // Remove node after scene on
1394 DALI_TEST_EQUALS(1, root.GetChildCount(), TEST_LOCATION);
1396 model.AddModelNode(node4); // Add during scene on
1398 DALI_TEST_EQUALS(2, root.GetChildCount(), TEST_LOCATION);
1400 application.GetScene().Remove(model);
1402 model.RemoveModelNode(node3); // Remove node after scene off
1407 int UtcDaliModelFindChildModelNodeByName(void)
1409 tet_infoline(" UtcDaliModelNodeFindChildModelNodeByName.");
1411 ToolkitTestApplication application;
1413 Scene3D::Model model = Scene3D::Model::New();
1414 application.GetScene().Add(model);
1416 Scene3D::ModelNode modelNode1 = Scene3D::ModelNode::New();
1417 Scene3D::ModelNode modelNode2 = Scene3D::ModelNode::New();
1419 modelNode1.SetProperty(Dali::Actor::Property::NAME, "modelNode1");
1420 modelNode2.SetProperty(Dali::Actor::Property::NAME, "modelNode2");
1421 model.AddModelNode(modelNode1);
1422 model.AddModelNode(modelNode2);
1424 Scene3D::ModelNode child1 = model.FindChildModelNodeByName("modelNode1");
1425 DALI_TEST_CHECK(child1);
1426 DALI_TEST_EQUALS(child1, modelNode1, TEST_LOCATION);
1428 Scene3D::ModelNode child2 = model.FindChildModelNodeByName("modelNode2");
1429 DALI_TEST_CHECK(child2);
1430 DALI_TEST_EQUALS(child2, modelNode2, TEST_LOCATION);
1435 int UtcDaliModelSizeChange(void)
1437 tet_infoline(" UtcDaliModelSizeChange.");
1439 ToolkitTestApplication application;
1441 Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
1442 model.SetProperty(Dali::Actor::Property::SIZE, Vector3(300, 300, 300));
1443 application.GetScene().Add(model);
1445 application.SendNotification();
1446 application.Render();
1448 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1449 application.SendNotification();
1450 application.Render();
1452 DALI_TEST_EQUALS(model.GetChildCount(), 1u, TEST_LOCATION);
1453 Vector3 scale = model.GetChildAt(0u).GetProperty<Vector3>(Dali::Actor::Property::SCALE);
1455 model.SetProperty(Dali::Actor::Property::SIZE, Vector3(600, 600, 600));
1456 Vector3 scale2 = model.GetChildAt(0u).GetProperty<Vector3>(Dali::Actor::Property::SCALE);
1458 DALI_TEST_NOT_EQUALS(scale, scale2, 0.1f, TEST_LOCATION);
1463 int UtcDaliModelSizeChange2(void)
1465 tet_infoline(" UtcDaliModelSizeChange2.");
1467 ToolkitTestApplication application;
1469 Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
1470 model.SetProperty(Dali::Actor::Property::SIZE, Vector3(300, 300, 300));
1471 application.GetScene().Add(model);
1473 application.SendNotification();
1474 application.Render();
1476 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1477 application.SendNotification();
1478 application.Render();
1480 DALI_TEST_EQUALS(model.GetChildCount(), 1u, TEST_LOCATION);
1481 Vector3 scale = model.GetChildAt(0u).GetProperty<Vector3>(Dali::Actor::Property::SCALE);
1483 Animation animation = Animation::New(0.5f);
1484 animation.AnimateTo(Dali::Property(model, Dali::Actor::Property::SIZE), Vector3(600, 600, 600));
1487 application.SendNotification();
1488 application.Render(250);
1490 application.SendNotification();
1492 Vector3 scale2 = model.GetChildAt(0u).GetProperty<Vector3>(Dali::Actor::Property::SCALE);
1493 DALI_TEST_NOT_EQUALS(scale, scale2, 0.1f, TEST_LOCATION);
1498 int UtcDaliModelRetrieveBlendShapeNames(void)
1500 tet_infoline(" UtcDaliModelRetrieveBlendShapeByName.");
1502 ToolkitTestApplication application;
1504 Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_EXTRAS_FILE_NAME);
1505 model.SetProperty(Dali::Actor::Property::SIZE, Vector3(300, 300, 300));
1506 application.GetScene().Add(model);
1508 application.SendNotification();
1509 application.Render();
1511 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1512 application.SendNotification();
1513 application.Render();
1515 DALI_TEST_EQUALS(model.GetChildCount(), 1u, TEST_LOCATION);
1517 // Get target ModelNode that has extras
1518 Scene3D::ModelNode expectNode = model.FindChildModelNodeByName("AnimatedMorphCube");
1520 // Pair of expected blend shape index from expectNode.
1521 std::map<std::string, Scene3D::Loader::BlendShapes::Index> expectBlendShapeNames = {
1526 std::vector<std::string> blendShapeNameList;
1527 model.RetrieveBlendShapeNames(blendShapeNameList);
1529 DALI_TEST_EQUALS(blendShapeNameList.size(), expectBlendShapeNames.size(), TEST_LOCATION);
1530 for(auto i = 0u; i < blendShapeNameList.size(); ++i)
1532 const auto& name = blendShapeNameList[i];
1533 tet_printf("Check retrieved blendshape name : %s\n", name.c_str());
1535 const auto& iter = expectBlendShapeNames.find(name);
1536 DALI_TEST_CHECK(iter != expectBlendShapeNames.end());
1538 std::vector<Scene3D::ModelNode> nodeList;
1539 model.RetrieveModelNodesByBlendShapeName(name, nodeList);
1540 DALI_TEST_EQUALS(nodeList.size(), 1u, TEST_LOCATION);
1541 DALI_TEST_EQUALS(nodeList[0], expectNode, TEST_LOCATION);
1542 DALI_TEST_EQUALS(nodeList[0].GetBlendShapeIndexByName(name), iter->second, TEST_LOCATION);
1548 int UtcDaliModelGenerateMotionDataAnimation01(void)
1550 ToolkitTestApplication application;
1552 Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_MORPH_FILE_NAME);
1553 model.SetProperty(Dali::Actor::Property::SIZE, Vector2(50, 50));
1554 application.GetScene().Add(model);
1556 gResourceReadyCalled = false;
1557 model.ResourceReadySignal().Connect(&OnResourceReady);
1558 DALI_TEST_EQUALS(gResourceReadyCalled, false, TEST_LOCATION);
1560 application.SendNotification();
1561 application.Render();
1563 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1564 application.SendNotification();
1565 application.Render();
1567 DALI_TEST_EQUALS(gResourceReadyCalled, true, TEST_LOCATION);
1569 KeyFrames floatKeyFrames = KeyFrames::New();
1570 floatKeyFrames.Add(0.0f, 1.0f);
1571 floatKeyFrames.Add(1.0f, 0.5f);
1573 float duration = 3.0f;
1574 Scene3D::MotionData motionData = Scene3D::MotionData::New(duration);
1575 motionData.Add(Scene3D::MotionTransformIndex::New("AnimatedMorphCube", Scene3D::MotionTransformIndex::TransformType::SCALE_Y), Scene3D::MotionValue::New(2.0f));
1576 motionData.Add(Scene3D::MotionTransformIndex::New("AnimatedMorphCube", Scene3D::MotionTransformIndex::TransformType::SCALE_Z), Scene3D::MotionValue::New(floatKeyFrames));
1577 motionData.Add(Scene3D::BlendShapeIndex::New("AnimatedMorphCube", 0), Scene3D::MotionValue::New(0.5f));
1578 motionData.Add(Scene3D::BlendShapeIndex::New("AnimatedMorphCube", 1), Scene3D::MotionValue::New(floatKeyFrames));
1580 Animation generatedAnimation = model.GenerateMotionDataAnimation(motionData);
1581 DALI_TEST_CHECK(generatedAnimation);
1582 DALI_TEST_EQUALS(generatedAnimation.GetDuration(), duration, TEST_LOCATION);
1584 Scene3D::MotionData invalidMotionData = Scene3D::MotionData::New(duration);
1585 invalidMotionData.Add(Scene3D::MotionTransformIndex::New("NotAnimatedMorphCube", Scene3D::MotionTransformIndex::TransformType::SCALE_Y), Scene3D::MotionValue::New(2.0f));
1586 invalidMotionData.Add(Scene3D::MotionTransformIndex::New("NotAnimatedMorphCube", Scene3D::MotionTransformIndex::TransformType::SCALE_Z), Scene3D::MotionValue::New(floatKeyFrames));
1587 invalidMotionData.Add(Scene3D::BlendShapeIndex::New("NotAnimatedMorphCube", 0), Scene3D::MotionValue::New(0.5f));
1588 invalidMotionData.Add(Scene3D::BlendShapeIndex::New("NotAnimatedMorphCube", 1), Scene3D::MotionValue::New(floatKeyFrames));
1590 generatedAnimation = model.GenerateMotionDataAnimation(invalidMotionData);
1591 DALI_TEST_CHECK(!generatedAnimation); // Animation should be empty if motion data have invalid index.
1596 int UtcDaliModelSetMotionData(void)
1598 ToolkitTestApplication application;
1600 Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_MORPH_FILE_NAME);
1601 model.SetProperty(Dali::Actor::Property::SIZE, Vector2(50, 50));
1602 application.GetScene().Add(model);
1604 gResourceReadyCalled = false;
1605 model.ResourceReadySignal().Connect(&OnResourceReady);
1606 DALI_TEST_EQUALS(gResourceReadyCalled, false, TEST_LOCATION);
1608 application.SendNotification();
1609 application.Render();
1611 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1612 application.SendNotification();
1613 application.Render();
1615 DALI_TEST_EQUALS(gResourceReadyCalled, true, TEST_LOCATION);
1617 KeyFrames floatKeyFrames = KeyFrames::New();
1618 floatKeyFrames.Add(0.0f, 1.0f);
1619 floatKeyFrames.Add(1.0f, 0.5f);
1621 float duration = 3.0f;
1622 Scene3D::MotionData motionData = Scene3D::MotionData::New(duration);
1623 motionData.Add(Scene3D::MotionTransformIndex::New("AnimatedMorphCube", Scene3D::MotionTransformIndex::TransformType::SCALE_Y), Scene3D::MotionValue::New(2.0f));
1624 motionData.Add(Scene3D::MotionTransformIndex::New("AnimatedMorphCube", Scene3D::MotionTransformIndex::TransformType::SCALE_Z), Scene3D::MotionValue::New(floatKeyFrames));
1625 motionData.Add(Scene3D::BlendShapeIndex::New("AnimatedMorphCube", 0), Scene3D::MotionValue::New(0.5f));
1626 motionData.Add(Scene3D::BlendShapeIndex::New("AnimatedMorphCube", 1), Scene3D::MotionValue::New(floatKeyFrames));
1628 auto cubeModelNode = model.FindChildModelNodeByName("AnimatedMorphCube");
1630 float expectScaleX = cubeModelNode.GetProperty<float>(Actor::Property::SCALE_X);
1632 model.SetMotionData(motionData);
1634 DALI_TEST_EQUALS(cubeModelNode.GetProperty<float>(Actor::Property::SCALE_X), expectScaleX, TEST_LOCATION);
1635 DALI_TEST_EQUALS(cubeModelNode.GetProperty<float>(Actor::Property::SCALE_Y), 2.0f, TEST_LOCATION);
1636 DALI_TEST_EQUALS(cubeModelNode.GetProperty<float>(Actor::Property::SCALE_Z), 0.5f, TEST_LOCATION); ///< Last value of keyframes
1641 int UtcDaliModelBlendShapeMotionDataByName(void)
1643 ToolkitTestApplication application;
1645 Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_EXTRAS_FILE_NAME);
1646 model.SetProperty(Dali::Actor::Property::SIZE, Vector2(50, 50));
1647 application.GetScene().Add(model);
1649 gResourceReadyCalled = false;
1650 model.ResourceReadySignal().Connect(&OnResourceReady);
1651 DALI_TEST_EQUALS(gResourceReadyCalled, false, TEST_LOCATION);
1653 application.SendNotification();
1654 application.Render();
1656 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1657 application.SendNotification();
1658 application.Render();
1660 DALI_TEST_EQUALS(gResourceReadyCalled, true, TEST_LOCATION);
1662 KeyFrames floatKeyFrames = KeyFrames::New();
1663 floatKeyFrames.Add(0.0f, 0.5f);
1664 floatKeyFrames.Add(1.0f, 1.0f);
1666 float duration = 3.0f;
1667 Scene3D::MotionData motionData = Scene3D::MotionData::New(duration);
1668 motionData.Add(Scene3D::BlendShapeIndex::New("Target_0"), Scene3D::MotionValue::New(0.5f));
1669 motionData.Add(Scene3D::BlendShapeIndex::New("Target_1"), Scene3D::MotionValue::New(floatKeyFrames));
1671 Animation generatedAnimation = model.GenerateMotionDataAnimation(motionData);
1672 DALI_TEST_CHECK(generatedAnimation);
1673 DALI_TEST_EQUALS(generatedAnimation.GetDuration(), duration, TEST_LOCATION);
1675 model.SetMotionData(motionData);
1677 // Get target ModelNode that has extras
1678 Scene3D::ModelNode expectNode = model.FindChildModelNodeByName("AnimatedMorphCube");
1679 auto propertyIndex = expectNode.GetPropertyIndex(motionData.GetIndex(0u).GetPropertyName(expectNode));
1681 DALI_TEST_CHECK(propertyIndex != Property::INVALID_INDEX);
1682 DALI_TEST_EQUALS(expectNode.GetProperty<float>(propertyIndex), 0.5f, TEST_LOCATION);
1684 propertyIndex = expectNode.GetPropertyIndex(motionData.GetIndex(1u).GetPropertyName(expectNode));
1685 DALI_TEST_CHECK(propertyIndex != Property::INVALID_INDEX);
1686 DALI_TEST_EQUALS(expectNode.GetProperty<float>(propertyIndex), 1.0f, TEST_LOCATION);