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/devel-api/actors/camera-actor-devel.h>
34 using namespace Dali::Toolkit;
36 void model_startup(void)
38 test_return_value = TET_UNDEF;
41 void model_cleanup(void)
43 test_return_value = TET_PASS;
48 const bool DEFAULT_MODEL_CHILDREN_SENSITIVE = false;
49 const bool DEFAULT_MODEL_CHILDREN_FOCUSABLE = false;
51 * For the AnimatedCube.gltf and its Assets
52 * Donated by Norbert Nopper for glTF testing.
53 * Take from https://github.com/KhronosGroup/glTF-Sample-Models/tree/master/2.0/AnimatedCube
55 const char* TEST_GLTF_FILE_NAME = TEST_RESOURCE_DIR "/AnimatedCube.gltf";
56 const char* TEST_GLTF_ANIMATION_TEST_FILE_NAME = TEST_RESOURCE_DIR "/animationTest.gltf";
57 const char* TEST_GLTF_EXTRAS_FILE_NAME = TEST_RESOURCE_DIR "/AnimatedMorphCubeAnimateNonZeroFrame.gltf";
58 const char* TEST_GLTF_MULTIPLE_PRIMITIVE_FILE_NAME = TEST_RESOURCE_DIR "/simpleMultiplePrimitiveTest.gltf";
59 const char* TEST_DLI_FILE_NAME = TEST_RESOURCE_DIR "/arc.dli";
60 const char* TEST_DLI_EXERCISE_FILE_NAME = TEST_RESOURCE_DIR "/exercise.dli";
63 * For the diffuse and specular cube map texture.
64 * These textures are based off version of Wave engine sample
65 * Take from https://github.com/WaveEngine/Samples
67 * Copyright (c) 2023 Wave Coorporation
69 * Permission is hereby granted, free of charge, to any person obtaining a copy
70 * of this software and associated documentation files (the "Software"), to
71 * deal in the Software without restriction, including without limitation the
72 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
73 * sell copies of the Software, and to permit persons to whom the Software is
74 * furnished to do so, subject to the following conditions:
76 * The above copyright notice and this permission notice shall be included in
77 * all copies or substantial portions of the Software.
79 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
80 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
81 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
82 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
83 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
84 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
87 const char* TEST_DIFFUSE_TEXTURE = TEST_RESOURCE_DIR "/forest_irradiance.ktx";
88 const char* TEST_SPECULAR_TEXTURE = TEST_RESOURCE_DIR "/forest_radiance.ktx";
90 bool gTouchCallBackCalled = false;
91 bool TestTouchCallback(Actor, const TouchEvent&)
93 gTouchCallBackCalled = true;
97 bool gFocusChangedCallBackCalled = false;
98 void TestFocusChangedCallback(Actor, Actor)
100 gFocusChangedCallBackCalled = true;
104 static bool gOnRelayoutCallBackCalled = false;
105 void OnRelayoutCallback(Actor actor)
107 gOnRelayoutCallBackCalled = true;
110 static bool gResourceReadyCalled = false;
111 void OnResourceReady(Control control)
113 gResourceReadyCalled = true;
118 // Negative test case for a method
119 int UtcDaliModelUninitialized(void)
121 ToolkitTestApplication application;
122 tet_infoline(" UtcDaliModelUninitialized");
124 Scene3D::Model model;
128 // New() must be called to create a Model or it wont be valid.
129 Actor a = Actor::New();
131 DALI_TEST_CHECK(false);
133 catch(Dali::DaliException& e)
135 // Tests that a negative test of an assertion succeeds
136 DALI_TEST_PRINT_ASSERT(e);
137 DALI_TEST_CHECK(!model);
142 // Positive test case for a method
143 int UtcDaliModelNew(void)
145 ToolkitTestApplication application;
146 tet_infoline(" UtcDaliModelNew");
148 Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
149 DALI_TEST_CHECK(model);
153 // Positive test case for a method
154 int UtcDaliModelNewP2(void)
156 ToolkitTestApplication application;
157 tet_infoline(" UtcDaliModelNew without url");
159 Scene3D::Model model = Scene3D::Model::New();
160 DALI_TEST_CHECK(model);
162 application.GetScene().Add(model);
164 DALI_TEST_CHECK(model.GetProperty<bool>(Actor::Property::CONNECTED_TO_SCENE));
166 application.GetScene().Remove(model);
168 DALI_TEST_CHECK(!model.GetProperty<bool>(Actor::Property::CONNECTED_TO_SCENE));
173 // Positive test case for a method
174 int UtcDaliModelDownCast(void)
176 ToolkitTestApplication application;
177 tet_infoline(" UtcDaliModelDownCast");
179 Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
180 BaseHandle handle(model);
182 Scene3D::Model model2 = Scene3D::Model::DownCast(handle);
183 DALI_TEST_CHECK(model);
184 DALI_TEST_CHECK(model2);
185 DALI_TEST_CHECK(model2 == model);
189 int UtcDaliModelTypeRegistry(void)
191 ToolkitTestApplication application;
193 TypeRegistry typeRegistry = TypeRegistry::Get();
194 DALI_TEST_CHECK(typeRegistry);
196 TypeInfo typeInfo = typeRegistry.GetTypeInfo("Model");
197 DALI_TEST_CHECK(typeInfo);
199 BaseHandle handle = typeInfo.CreateInstance();
200 DALI_TEST_CHECK(handle);
202 Scene3D::Model model = Scene3D::Model::DownCast(handle);
203 DALI_TEST_CHECK(model);
208 // Positive test case for a method
209 int UtcDaliModelAddRemove(void)
211 ToolkitTestApplication application;
212 tet_infoline(" UtcDaliModelAddRemove");
214 Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
215 DALI_TEST_CHECK(model);
217 Actor actor = Actor::New();
218 DALI_TEST_CHECK(!actor.GetProperty<bool>(Actor::Property::CONNECTED_TO_SCENE));
220 model.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
221 model.SetProperty(Actor::Property::SIZE, application.GetScene().GetSize());
223 application.GetScene().Add(model);
225 DALI_TEST_CHECK(actor.GetProperty<bool>(Actor::Property::CONNECTED_TO_SCENE));
229 DALI_TEST_CHECK(!actor.GetProperty<bool>(Actor::Property::CONNECTED_TO_SCENE));
233 int UtcDaliModelCopyAndAssignment(void)
235 ToolkitTestApplication application;
237 Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
238 DALI_TEST_CHECK(model);
240 Scene3D::Model copy(model);
241 DALI_TEST_CHECK(model == copy);
243 Scene3D::Model assign;
244 DALI_TEST_CHECK(!assign);
247 DALI_TEST_CHECK(assign == model);
252 int UtcDaliModelMoveConstructor(void)
254 ToolkitTestApplication application;
256 Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
257 DALI_TEST_EQUALS(1, model.GetBaseObject().ReferenceCount(), TEST_LOCATION);
258 model.SetProperty(Actor::Property::SENSITIVE, false);
259 DALI_TEST_CHECK(false == model.GetProperty<bool>(Actor::Property::SENSITIVE));
261 Scene3D::Model moved = std::move(model);
262 DALI_TEST_CHECK(moved);
263 DALI_TEST_EQUALS(1, moved.GetBaseObject().ReferenceCount(), TEST_LOCATION);
264 DALI_TEST_CHECK(false == moved.GetProperty<bool>(Actor::Property::SENSITIVE));
265 DALI_TEST_CHECK(!model);
270 int UtcDaliModelMoveAssignment(void)
272 ToolkitTestApplication application;
274 Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
275 DALI_TEST_EQUALS(1, model.GetBaseObject().ReferenceCount(), TEST_LOCATION);
276 model.SetProperty(Actor::Property::SENSITIVE, false);
277 DALI_TEST_CHECK(false == model.GetProperty<bool>(Actor::Property::SENSITIVE));
279 Scene3D::Model moved;
280 moved = std::move(model);
281 DALI_TEST_CHECK(moved);
282 DALI_TEST_EQUALS(1, moved.GetBaseObject().ReferenceCount(), TEST_LOCATION);
283 DALI_TEST_CHECK(false == moved.GetProperty<bool>(Actor::Property::SENSITIVE));
284 DALI_TEST_CHECK(!model);
289 int UtcDaliModelOnScene01(void)
291 ToolkitTestApplication application;
293 Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
294 application.GetScene().Add(model);
296 gResourceReadyCalled = false;
297 model.ResourceReadySignal().Connect(&OnResourceReady);
298 DALI_TEST_EQUALS(gResourceReadyCalled, false, TEST_LOCATION);
300 application.SendNotification();
301 application.Render();
303 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
304 application.SendNotification();
305 application.Render();
307 DALI_TEST_EQUALS(gResourceReadyCalled, true, TEST_LOCATION);
309 uint32_t modelCount = model.GetModelRoot().GetChildCount();
310 DALI_TEST_EQUALS(1, modelCount, TEST_LOCATION);
314 int UtcDaliModelOnScene02(void)
316 ToolkitTestApplication application;
318 Scene3D::Model model = Scene3D::Model::New(TEST_DLI_FILE_NAME);
319 application.GetScene().Add(model);
321 gResourceReadyCalled = false;
322 model.ResourceReadySignal().Connect(&OnResourceReady);
323 DALI_TEST_EQUALS(gResourceReadyCalled, false, TEST_LOCATION);
325 application.SendNotification();
326 application.Render();
328 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
329 application.SendNotification();
330 application.Render();
332 DALI_TEST_EQUALS(gResourceReadyCalled, true, TEST_LOCATION);
334 uint32_t modelCount = model.GetModelRoot().GetChildCount();
335 DALI_TEST_EQUALS(1, modelCount, TEST_LOCATION);
337 Scene3D::ModelNode rootNode = model.GetModelRoot();
338 Vector3 rootSize = rootNode.GetProperty<Vector3>(Dali::Actor::Property::SIZE);
339 DALI_TEST_EQUALS(Vector3(2, 2, 1), rootSize, TEST_LOCATION);
344 int UtcDaliModelOnSizeSet(void)
346 ToolkitTestApplication application;
348 Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
350 application.GetScene().Add(model);
352 application.SendNotification();
353 application.Render();
355 Vector2 size(200.0f, 300.0f);
356 model.SetProperty(Actor::Property::SIZE, size);
358 application.SendNotification();
359 application.Render();
361 DALI_TEST_EQUALS(model.GetCurrentProperty<Vector2>(Actor::Property::SIZE), size, TEST_LOCATION);
366 int UtcDaliModelGetNaturalSize(void)
368 ToolkitTestApplication application;
370 Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
372 Vector3 naturalSize = model.GetNaturalSize();
373 DALI_TEST_EQUALS(Vector3::ZERO, naturalSize, TEST_LOCATION);
375 application.GetScene().Add(model);
377 gResourceReadyCalled = false;
378 model.ResourceReadySignal().Connect(&OnResourceReady);
379 DALI_TEST_EQUALS(gResourceReadyCalled, false, TEST_LOCATION);
381 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
382 application.SendNotification();
384 DALI_TEST_EQUALS(gResourceReadyCalled, true, TEST_LOCATION);
386 naturalSize = model.GetNaturalSize();
387 DALI_TEST_EQUALS(Vector3(2, 2, 2), naturalSize, TEST_LOCATION);
389 Scene3D::ModelNode rootNode = model.GetModelRoot();
390 DALI_TEST_CHECK(rootNode);
395 int UtcDaliModelSetImageBasedLightSource01(void)
397 ToolkitTestApplication application;
399 Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
400 application.GetScene().Add(model);
402 gResourceReadyCalled = false;
403 model.ResourceReadySignal().Connect(&OnResourceReady);
404 DALI_TEST_EQUALS(gResourceReadyCalled, false, TEST_LOCATION);
406 application.SendNotification();
407 application.Render();
409 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
410 application.SendNotification();
411 application.Render();
413 DALI_TEST_EQUALS(gResourceReadyCalled, true, TEST_LOCATION);
415 Actor meshActor = model.FindChildByName("AnimatedCube");
416 DALI_TEST_CHECK(meshActor);
418 Renderer renderer = meshActor.GetRendererAt(0u);
419 DALI_TEST_CHECK(renderer);
421 TextureSet textureSet = renderer.GetTextures();
422 DALI_TEST_EQUALS(textureSet.GetTextureCount(), 9u, TEST_LOCATION);
424 Texture diffuseTexture = textureSet.GetTexture(7u);
425 Texture specularTexture = textureSet.GetTexture(8u);
427 gResourceReadyCalled = false;
428 DALI_TEST_EQUALS(gResourceReadyCalled, false, TEST_LOCATION);
429 model.SetImageBasedLightSource(TEST_DIFFUSE_TEXTURE, TEST_SPECULAR_TEXTURE);
431 application.SendNotification();
432 application.Render();
434 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
435 application.SendNotification();
436 application.Render();
438 DALI_TEST_EQUALS(gResourceReadyCalled, true, TEST_LOCATION);
440 TextureSet newTextureSet = renderer.GetTextures();
441 Texture newDiffuseTexture = newTextureSet.GetTexture(7u);
442 Texture newSpecularTexture = newTextureSet.GetTexture(8u);
444 DALI_TEST_NOT_EQUALS(diffuseTexture, newDiffuseTexture, 0.0f, TEST_LOCATION);
445 DALI_TEST_NOT_EQUALS(specularTexture, newSpecularTexture, 0.0f, TEST_LOCATION);
452 int UtcDaliModelSetImageBasedLightSource02(void)
454 ToolkitTestApplication application;
456 Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
457 application.GetScene().Add(model);
459 gResourceReadyCalled = false;
460 model.ResourceReadySignal().Connect(&OnResourceReady);
461 DALI_TEST_EQUALS(gResourceReadyCalled, false, TEST_LOCATION);
463 application.SendNotification();
464 application.Render();
466 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
467 application.SendNotification();
468 application.Render();
470 DALI_TEST_EQUALS(gResourceReadyCalled, true, TEST_LOCATION);
472 Actor meshActor = model.FindChildByName("AnimatedCube");
473 DALI_TEST_CHECK(meshActor);
475 Renderer renderer = meshActor.GetRendererAt(0u);
476 DALI_TEST_CHECK(renderer);
478 TextureSet textureSet = renderer.GetTextures();
479 DALI_TEST_EQUALS(textureSet.GetTextureCount(), 9u, TEST_LOCATION);
481 Texture diffuseTexture = textureSet.GetTexture(7u);
482 Texture specularTexture = textureSet.GetTexture(8u);
484 // if url is empty, loading is not requested.
485 model.SetImageBasedLightSource("", "");
487 Texture newDiffuseTexture = textureSet.GetTexture(7u);
488 Texture newSpecularTexture = textureSet.GetTexture(8u);
490 DALI_TEST_EQUALS(diffuseTexture, newDiffuseTexture, TEST_LOCATION);
491 DALI_TEST_EQUALS(specularTexture, newSpecularTexture, TEST_LOCATION);
496 int UtcDaliModelSetImageBasedLightSource03(void)
498 ToolkitTestApplication application;
500 Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
501 application.GetScene().Add(model);
503 gResourceReadyCalled = false;
504 model.ResourceReadySignal().Connect(&OnResourceReady);
505 DALI_TEST_EQUALS(gResourceReadyCalled, false, TEST_LOCATION);
507 application.SendNotification();
508 application.Render();
510 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
511 application.SendNotification();
512 application.Render();
514 DALI_TEST_EQUALS(gResourceReadyCalled, true, TEST_LOCATION);
516 Actor meshActor = model.FindChildByName("AnimatedCube");
517 DALI_TEST_CHECK(meshActor);
519 Renderer renderer = meshActor.GetRendererAt(0u);
520 DALI_TEST_CHECK(renderer);
522 TextureSet textureSet = renderer.GetTextures();
523 DALI_TEST_EQUALS(textureSet.GetTextureCount(), 9u, TEST_LOCATION);
525 Texture diffuseTexture = textureSet.GetTexture(7u);
526 Texture specularTexture = textureSet.GetTexture(8u);
528 gResourceReadyCalled = false;
529 DALI_TEST_EQUALS(gResourceReadyCalled, false, TEST_LOCATION);
530 model.SetImageBasedLightSource("dummy.ktx", "dummy.ktx");
532 application.SendNotification();
533 application.Render();
535 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
536 application.SendNotification();
537 application.Render();
539 DALI_TEST_EQUALS(gResourceReadyCalled, true, TEST_LOCATION);
541 Texture newDiffuseTexture = textureSet.GetTexture(7u);
542 Texture newSpecularTexture = textureSet.GetTexture(8u);
544 DALI_TEST_EQUALS(diffuseTexture, newDiffuseTexture, TEST_LOCATION);
545 DALI_TEST_EQUALS(specularTexture, newSpecularTexture, TEST_LOCATION);
550 int UtcDaliModelSetImageBasedLightSource04(void)
552 ToolkitTestApplication application;
554 Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
555 model.SetImageBasedLightSource(TEST_DIFFUSE_TEXTURE, TEST_SPECULAR_TEXTURE);
556 application.GetScene().Add(model);
558 gResourceReadyCalled = false;
559 model.ResourceReadySignal().Connect(&OnResourceReady);
560 DALI_TEST_EQUALS(gResourceReadyCalled, false, TEST_LOCATION);
562 application.SendNotification();
563 application.Render();
565 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(3), true, TEST_LOCATION);
566 application.SendNotification();
567 application.Render();
569 DALI_TEST_EQUALS(gResourceReadyCalled, true, TEST_LOCATION);
573 int UtcDaliModelImageBasedFactor(void)
575 ToolkitTestApplication application;
577 Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
579 DALI_TEST_EQUALS(model.GetImageBasedLightScaleFactor(), 1.0f, TEST_LOCATION);
581 model.SetImageBasedLightScaleFactor(0.5f);
582 DALI_TEST_EQUALS(model.GetImageBasedLightScaleFactor(), 0.5f, TEST_LOCATION);
586 int UtcDaliModelChildrenSensitive01(void)
588 ToolkitTestApplication application;
590 Scene3D::Model view = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
591 view.SetProperty(Dali::Actor::Property::SIZE, Vector3(100, 100, 100));
592 view.SetProperty(Dali::Actor::Property::POSITION, Vector3(0, 0, 0));
593 view.SetProperty(Dali::Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER);
594 view.SetProperty(Dali::Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
596 // Get default vaule.
597 DALI_TEST_EQUALS(view.GetChildrenSensitive(), DEFAULT_MODEL_CHILDREN_SENSITIVE, TEST_LOCATION);
599 // Allow children actor's event before on scene.
600 view.SetChildrenSensitive(true);
601 DALI_TEST_EQUALS(view.GetChildrenSensitive(), true, TEST_LOCATION);
602 application.GetScene().Add(view);
604 gResourceReadyCalled = false;
605 view.ResourceReadySignal().Connect(&OnResourceReady);
606 DALI_TEST_EQUALS(gResourceReadyCalled, false, TEST_LOCATION);
608 application.SendNotification();
609 application.Render();
611 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
612 application.SendNotification();
613 application.Render();
615 DALI_TEST_EQUALS(gResourceReadyCalled, true, TEST_LOCATION);
617 Actor meshActor = view.FindChildByName("AnimatedCube");
618 DALI_TEST_CHECK(meshActor);
620 // connect hit-test signal
621 gTouchCallBackCalled = false;
622 meshActor.TouchedSignal().Connect(TestTouchCallback);
624 Vector2 sceneSize = application.GetScene().GetSize();
626 // Try to touch center of scene.
627 Dali::Integration::Point point;
628 point.SetState(PointState::DOWN);
629 point.SetScreenPosition(sceneSize * 0.5f);
630 Dali::Integration::TouchEvent event;
631 event.AddPoint(point);
633 // flush the queue and render once
634 application.SendNotification();
635 application.Render();
638 DALI_TEST_CHECK(!gTouchCallBackCalled);
639 application.ProcessEvent(event);
641 DALI_TEST_CHECK(gTouchCallBackCalled);
644 gTouchCallBackCalled = false;
646 // Block children actor's event
647 view.SetChildrenSensitive(false);
648 DALI_TEST_EQUALS(view.GetChildrenSensitive(), false, TEST_LOCATION);
650 // flush the queue and render once
651 application.SendNotification();
652 application.Render();
655 DALI_TEST_CHECK(!gTouchCallBackCalled);
656 application.ProcessEvent(event);
658 DALI_TEST_CHECK(!gTouchCallBackCalled);
661 gTouchCallBackCalled = false;
664 view.SetChildrenSensitive(true);
665 DALI_TEST_EQUALS(view.GetChildrenSensitive(), true, TEST_LOCATION);
667 // flush the queue and render once
668 application.SendNotification();
669 application.Render();
672 DALI_TEST_CHECK(!gTouchCallBackCalled);
673 application.ProcessEvent(event);
675 DALI_TEST_CHECK(gTouchCallBackCalled);
678 gTouchCallBackCalled = false;
683 int UtcDaliModelChildrenSensitive02(void)
685 ToolkitTestApplication application;
687 Scene3D::Model view = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
688 view.SetProperty(Dali::Actor::Property::SIZE, Vector3(100, 100, 100));
689 view.SetProperty(Dali::Actor::Property::POSITION, Vector3(0, 0, 0));
690 view.SetProperty(Dali::Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER);
691 view.SetProperty(Dali::Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
694 DALI_TEST_EQUALS(view.GetChildrenSensitive(), DEFAULT_MODEL_CHILDREN_SENSITIVE, TEST_LOCATION);
696 // Block children actor's event before on scene.
697 view.SetChildrenSensitive(false);
698 DALI_TEST_EQUALS(view.GetChildrenSensitive(), false, TEST_LOCATION);
699 application.GetScene().Add(view);
701 gResourceReadyCalled = false;
702 view.ResourceReadySignal().Connect(&OnResourceReady);
703 DALI_TEST_EQUALS(gResourceReadyCalled, false, TEST_LOCATION);
705 application.SendNotification();
706 application.Render();
708 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
709 application.SendNotification();
710 application.Render();
712 DALI_TEST_EQUALS(gResourceReadyCalled, true, TEST_LOCATION);
714 Actor meshActor = view.FindChildByName("AnimatedCube");
715 DALI_TEST_CHECK(meshActor);
717 // connect hit-test signal
718 gTouchCallBackCalled = false;
719 meshActor.TouchedSignal().Connect(TestTouchCallback);
721 Vector2 sceneSize = application.GetScene().GetSize();
723 // Try to touch center of scene.
724 Dali::Integration::Point point;
725 point.SetState(PointState::DOWN);
726 point.SetScreenPosition(sceneSize * 0.5f);
727 Dali::Integration::TouchEvent event;
728 event.AddPoint(point);
730 // flush the queue and render once
731 application.SendNotification();
732 application.Render();
735 DALI_TEST_CHECK(!gTouchCallBackCalled);
736 application.ProcessEvent(event);
738 DALI_TEST_CHECK(!gTouchCallBackCalled);
741 gTouchCallBackCalled = false;
744 view.SetChildrenSensitive(true);
745 DALI_TEST_EQUALS(view.GetChildrenSensitive(), true, TEST_LOCATION);
747 // flush the queue and render once
748 application.SendNotification();
749 application.Render();
752 DALI_TEST_CHECK(!gTouchCallBackCalled);
753 application.ProcessEvent(event);
755 DALI_TEST_CHECK(gTouchCallBackCalled);
758 gTouchCallBackCalled = false;
763 int UtcDaliModelChildrenFocusable01(void)
765 ToolkitTestApplication application;
767 Scene3D::Model view = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
768 view.SetProperty(Dali::Actor::Property::SIZE, Vector3(100, 100, 100));
769 view.SetProperty(Dali::Actor::Property::POSITION, Vector3(0, 0, 0));
770 view.SetProperty(Dali::Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER);
771 view.SetProperty(Dali::Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
773 // Get vaule. Default is false.
774 DALI_TEST_EQUALS(view.GetChildrenFocusable(), DEFAULT_MODEL_CHILDREN_FOCUSABLE, TEST_LOCATION);
776 // Allow children actor's focus before on scene.
777 view.SetChildrenFocusable(true);
778 DALI_TEST_EQUALS(view.GetChildrenFocusable(), true, TEST_LOCATION);
779 application.GetScene().Add(view);
781 gResourceReadyCalled = false;
782 view.ResourceReadySignal().Connect(&OnResourceReady);
783 DALI_TEST_EQUALS(gResourceReadyCalled, false, TEST_LOCATION);
785 application.SendNotification();
786 application.Render();
788 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
789 application.SendNotification();
790 application.Render();
792 DALI_TEST_EQUALS(gResourceReadyCalled, true, TEST_LOCATION);
794 Actor meshActor = view.FindChildByName("AnimatedCube");
795 DALI_TEST_CHECK(meshActor);
797 // Enable the default algorithm
798 KeyboardFocusManager manager = KeyboardFocusManager::Get();
799 DALI_TEST_CHECK(manager);
800 Dali::Toolkit::DevelKeyboardFocusManager::EnableDefaultAlgorithm(manager, true);
802 // connect focusable signal
803 gFocusChangedCallBackCalled = false;
804 meshActor.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true);
805 manager.FocusChangedSignal().Connect(TestFocusChangedCallback);
807 // Initialize with some left-positioned actor
808 Control focusStartActor = Control::New();
809 focusStartActor.SetProperty(Dali::Actor::Property::SIZE, Vector3(100, 100, 100));
810 focusStartActor.SetProperty(Dali::Actor::Property::POSITION, Vector3(-200, 0, 0));
811 focusStartActor.SetProperty(Dali::Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER);
812 focusStartActor.SetProperty(Dali::Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
813 focusStartActor.SetProperty(Dali::Actor::Property::KEYBOARD_FOCUSABLE, true);
814 application.GetScene().Add(focusStartActor);
817 manager.ClearFocus();
818 manager.SetCurrentFocusActor(focusStartActor);
819 gFocusChangedCallBackCalled = false;
821 // flush the queue and render once
822 application.SendNotification();
823 application.Render();
825 // Focusable view find success
826 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::RIGHT) == true);
827 DALI_TEST_CHECK(gFocusChangedCallBackCalled);
830 manager.ClearFocus();
831 manager.SetCurrentFocusActor(focusStartActor);
832 gFocusChangedCallBackCalled = false;
834 // Block children actor's focus
835 view.SetChildrenFocusable(false);
836 DALI_TEST_EQUALS(view.GetChildrenFocusable(), false, TEST_LOCATION);
838 // flush the queue and render once
839 application.SendNotification();
840 application.Render();
842 // Focusable view find failed
843 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::RIGHT) == false);
844 DALI_TEST_CHECK(!gFocusChangedCallBackCalled);
847 manager.ClearFocus();
848 manager.SetCurrentFocusActor(focusStartActor);
849 gFocusChangedCallBackCalled = false;
852 view.SetChildrenFocusable(true);
853 DALI_TEST_EQUALS(view.GetChildrenFocusable(), true, TEST_LOCATION);
855 // flush the queue and render once
856 application.SendNotification();
857 application.Render();
859 // Focusable view find success
860 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::RIGHT) == true);
861 DALI_TEST_CHECK(gFocusChangedCallBackCalled);
864 manager.ClearFocus();
865 manager.SetCurrentFocusActor(focusStartActor);
866 gFocusChangedCallBackCalled = false;
871 int UtcDaliModelModelChildrenFocusable02(void)
873 ToolkitTestApplication application;
875 Scene3D::Model view = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
876 view.SetProperty(Dali::Actor::Property::SIZE, Vector3(100, 100, 100));
877 view.SetProperty(Dali::Actor::Property::POSITION, Vector3(0, 0, 0));
878 view.SetProperty(Dali::Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER);
879 view.SetProperty(Dali::Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
881 // Get vaule. Default is true.
882 DALI_TEST_EQUALS(view.GetChildrenFocusable(), DEFAULT_MODEL_CHILDREN_FOCUSABLE, TEST_LOCATION);
884 // Block children actor's focus before on scene.
885 view.SetChildrenFocusable(false);
886 DALI_TEST_EQUALS(view.GetChildrenFocusable(), false, TEST_LOCATION);
887 application.GetScene().Add(view);
889 gResourceReadyCalled = false;
890 view.ResourceReadySignal().Connect(&OnResourceReady);
891 DALI_TEST_EQUALS(gResourceReadyCalled, false, TEST_LOCATION);
893 application.SendNotification();
894 application.Render();
896 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
897 application.SendNotification();
898 application.Render();
900 DALI_TEST_EQUALS(gResourceReadyCalled, true, TEST_LOCATION);
902 Actor meshActor = view.FindChildByName("AnimatedCube");
903 DALI_TEST_CHECK(meshActor);
905 // Enable the default algorithm
906 KeyboardFocusManager manager = KeyboardFocusManager::Get();
907 DALI_TEST_CHECK(manager);
908 Dali::Toolkit::DevelKeyboardFocusManager::EnableDefaultAlgorithm(manager, true);
910 // connect focusable signal
911 gFocusChangedCallBackCalled = false;
912 meshActor.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true);
913 manager.FocusChangedSignal().Connect(TestFocusChangedCallback);
915 // Initialize with some left-positioned actor
916 Control focusStartActor = Control::New();
917 focusStartActor.SetProperty(Dali::Actor::Property::SIZE, Vector3(100, 100, 100));
918 focusStartActor.SetProperty(Dali::Actor::Property::POSITION, Vector3(-200, 0, 0));
919 focusStartActor.SetProperty(Dali::Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER);
920 focusStartActor.SetProperty(Dali::Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
921 focusStartActor.SetProperty(Dali::Actor::Property::KEYBOARD_FOCUSABLE, true);
922 application.GetScene().Add(focusStartActor);
925 manager.ClearFocus();
926 manager.SetCurrentFocusActor(focusStartActor);
927 gFocusChangedCallBackCalled = false;
929 // flush the queue and render once
930 application.SendNotification();
931 application.Render();
933 // Focusable view find failed
934 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::RIGHT) == false);
935 DALI_TEST_CHECK(!gFocusChangedCallBackCalled);
938 manager.ClearFocus();
939 manager.SetCurrentFocusActor(focusStartActor);
940 gFocusChangedCallBackCalled = false;
943 view.SetChildrenFocusable(true);
944 DALI_TEST_EQUALS(view.GetChildrenFocusable(), true, TEST_LOCATION);
946 // flush the queue and render once
947 application.SendNotification();
948 application.Render();
950 // Focusable view find success
951 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::RIGHT) == true);
952 DALI_TEST_CHECK(gFocusChangedCallBackCalled);
955 manager.ClearFocus();
956 manager.SetCurrentFocusActor(focusStartActor);
957 gFocusChangedCallBackCalled = false;
962 int UtcDaliModelAnimation01(void)
964 ToolkitTestApplication application;
966 Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
967 model.SetProperty(Dali::Actor::Property::SIZE, Vector2(50, 50));
968 application.GetScene().Add(model);
970 gResourceReadyCalled = false;
971 model.ResourceReadySignal().Connect(&OnResourceReady);
972 DALI_TEST_EQUALS(gResourceReadyCalled, false, TEST_LOCATION);
974 application.SendNotification();
975 application.Render();
977 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
978 application.SendNotification();
979 application.Render();
981 DALI_TEST_EQUALS(gResourceReadyCalled, true, TEST_LOCATION);
983 uint32_t animationCount = model.GetAnimationCount();
984 DALI_TEST_EQUALS(1, animationCount, TEST_LOCATION);
986 Animation animationByIndex = model.GetAnimation(0u);
987 DALI_TEST_CHECK(animationByIndex);
989 Animation animationByName = model.GetAnimation("animation_AnimatedCube");
990 DALI_TEST_CHECK(animationByName);
991 DALI_TEST_EQUALS(animationByIndex, animationByName, TEST_LOCATION);
996 int UtcDaliModelAnimation02(void)
998 ToolkitTestApplication application;
1000 Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_ANIMATION_TEST_FILE_NAME);
1001 model.SetProperty(Dali::Actor::Property::SIZE, Vector2(50, 50));
1002 application.GetScene().Add(model);
1004 gResourceReadyCalled = false;
1005 model.ResourceReadySignal().Connect(&OnResourceReady);
1006 DALI_TEST_EQUALS(gResourceReadyCalled, false, TEST_LOCATION);
1008 application.SendNotification();
1009 application.Render();
1011 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1012 application.SendNotification();
1013 application.Render();
1015 uint32_t animationCount = model.GetAnimationCount();
1016 DALI_TEST_EQUALS(9, animationCount, TEST_LOCATION);
1018 Animation animation1 = model.GetAnimation("Step Scale");
1019 DALI_TEST_CHECK(animation1);
1020 DALI_TEST_EQUALS(1.66667f, animation1.GetDuration(), 0.001f, TEST_LOCATION);
1022 Animation animation2 = model.GetAnimation("CubicSpline Scale");
1023 DALI_TEST_CHECK(animation2);
1024 DALI_TEST_EQUALS(1.66667f, animation2.GetDuration(), 0.001f, TEST_LOCATION);
1026 DALI_TEST_NOT_EQUALS(animation1, animation2, 0.0f, TEST_LOCATION);
1031 int UtcDaliModelAnimation03(void)
1033 ToolkitTestApplication application;
1035 Scene3D::Model model = Scene3D::Model::New(TEST_DLI_EXERCISE_FILE_NAME);
1036 model.SetProperty(Dali::Actor::Property::SIZE, Vector2(50, 50));
1037 application.GetScene().Add(model);
1039 gResourceReadyCalled = false;
1040 model.ResourceReadySignal().Connect(&OnResourceReady);
1041 DALI_TEST_EQUALS(gResourceReadyCalled, false, TEST_LOCATION);
1043 application.SendNotification();
1044 application.Render();
1046 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1047 application.SendNotification();
1048 application.Render();
1050 DALI_TEST_EQUALS(gResourceReadyCalled, true, TEST_LOCATION);
1052 uint32_t animationCount = model.GetAnimationCount();
1053 DALI_TEST_EQUALS(18, animationCount, TEST_LOCATION);
1055 Animation animationByIndex = model.GetAnimation(0u);
1056 DALI_TEST_CHECK(animationByIndex);
1058 Animation animationByName = model.GetAnimation("idleClip");
1059 DALI_TEST_CHECK(animationByName);
1060 DALI_TEST_EQUALS(animationByIndex, animationByName, TEST_LOCATION);
1065 int UtcDaliModelCameraGenerate01(void)
1067 ToolkitTestApplication application;
1069 Scene3D::Model model = Scene3D::Model::New(TEST_DLI_EXERCISE_FILE_NAME);
1070 model.SetProperty(Dali::Actor::Property::SIZE, Vector2(50, 50));
1071 application.GetScene().Add(model);
1073 gResourceReadyCalled = false;
1074 model.ResourceReadySignal().Connect(&OnResourceReady);
1075 DALI_TEST_EQUALS(gResourceReadyCalled, false, TEST_LOCATION);
1077 application.SendNotification();
1078 application.Render();
1080 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1081 application.SendNotification();
1082 application.Render();
1084 DALI_TEST_EQUALS(gResourceReadyCalled, true, TEST_LOCATION);
1086 uint32_t cameraCount = model.GetCameraCount();
1087 DALI_TEST_EQUALS(1, cameraCount, TEST_LOCATION);
1089 CameraActor generatedCamera = model.GenerateCamera(0u);
1090 DALI_TEST_CHECK(generatedCamera);
1092 generatedCamera = model.GenerateCamera(1u); // Fail to generate camera
1093 DALI_TEST_CHECK(!generatedCamera);
1098 int UtcDaliModelCameraGenerate02(void)
1100 ToolkitTestApplication application;
1102 Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
1103 model.SetProperty(Dali::Actor::Property::SIZE, Vector2(50, 50));
1104 application.GetScene().Add(model);
1106 gResourceReadyCalled = false;
1107 model.ResourceReadySignal().Connect(&OnResourceReady);
1108 DALI_TEST_EQUALS(gResourceReadyCalled, false, TEST_LOCATION);
1110 application.SendNotification();
1111 application.Render();
1113 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1114 application.SendNotification();
1115 application.Render();
1117 DALI_TEST_EQUALS(gResourceReadyCalled, true, TEST_LOCATION);
1119 uint32_t cameraCount = model.GetCameraCount();
1120 DALI_TEST_EQUALS(6, cameraCount, TEST_LOCATION);
1122 CameraActor generatedCamera0 = model.GenerateCamera(0u);
1123 DALI_TEST_CHECK(generatedCamera0);
1124 CameraActor generatedCamera1 = model.GenerateCamera(1u);
1125 DALI_TEST_CHECK(generatedCamera1);
1126 CameraActor generatedCamera2 = model.GenerateCamera(2u);
1127 DALI_TEST_CHECK(generatedCamera2);
1128 CameraActor generatedCamera3 = model.GenerateCamera(3u); // Infinity far camera
1129 DALI_TEST_CHECK(generatedCamera3);
1130 CameraActor generatedCamera4 = model.GenerateCamera(4u); // Broken camera 1
1131 DALI_TEST_CHECK(!generatedCamera4);
1132 CameraActor generatedCamera5 = model.GenerateCamera(5u); // Broken camera 2
1133 DALI_TEST_CHECK(!generatedCamera5);
1134 CameraActor generatedCamera6 = model.GenerateCamera(6u); // Out of bound
1135 DALI_TEST_CHECK(!generatedCamera6);
1137 CameraActor appliedCamera;
1138 DALI_TEST_EQUALS(model.ApplyCamera(0u, appliedCamera), false, TEST_LOCATION); // Cannot apply into empty camera.
1140 auto CompareCameraProperties = [](CameraActor lhs, CameraActor rhs, const char* location) {
1141 DALI_TEST_EQUALS(lhs.GetProperty<int>(Dali::CameraActor::Property::PROJECTION_MODE), rhs.GetProperty<int>(Dali::CameraActor::Property::PROJECTION_MODE), TEST_LOCATION);
1142 DALI_TEST_EQUALS(lhs.GetProperty<float>(Dali::CameraActor::Property::NEAR_PLANE_DISTANCE), rhs.GetProperty<float>(Dali::CameraActor::Property::NEAR_PLANE_DISTANCE), TEST_LOCATION);
1144 if(lhs.GetProperty<int>(Dali::CameraActor::Property::PROJECTION_MODE) == static_cast<int>(Dali::Camera::ProjectionMode::PERSPECTIVE_PROJECTION))
1146 DALI_TEST_EQUALS(lhs.GetProperty<float>(Dali::CameraActor::Property::FIELD_OF_VIEW), rhs.GetProperty<float>(Dali::CameraActor::Property::FIELD_OF_VIEW), TEST_LOCATION);
1147 // TODO : Open this test when infinity far projection implement.
1148 // DALI_TEST_EQUALS(lhs.GetProperty<float>(Dali::CameraActor::Property::FAR_PLANE_DISTANCE), rhs.GetProperty<float>(Dali::CameraActor::Property::FAR_PLANE_DISTANCE), TEST_LOCATION);
1152 DALI_TEST_EQUALS(lhs.GetProperty<float>(Dali::DevelCameraActor::Property::ORTHOGRAPHIC_SIZE), rhs.GetProperty<float>(Dali::DevelCameraActor::Property::ORTHOGRAPHIC_SIZE), TEST_LOCATION);
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 appliedCamera = CameraActor::New();
1158 DALI_TEST_EQUALS(model.ApplyCamera(0u, appliedCamera), true, TEST_LOCATION);
1159 CompareCameraProperties(generatedCamera0, appliedCamera, TEST_LOCATION);
1160 DALI_TEST_EQUALS(model.ApplyCamera(1u, appliedCamera), true, TEST_LOCATION);
1161 CompareCameraProperties(generatedCamera1, appliedCamera, TEST_LOCATION);
1162 DALI_TEST_EQUALS(model.ApplyCamera(2u, appliedCamera), true, TEST_LOCATION);
1163 CompareCameraProperties(generatedCamera2, appliedCamera, TEST_LOCATION);
1164 DALI_TEST_EQUALS(model.ApplyCamera(3u, appliedCamera), true, TEST_LOCATION);
1165 CompareCameraProperties(generatedCamera3, appliedCamera, TEST_LOCATION);
1166 DALI_TEST_EQUALS(model.ApplyCamera(4u, appliedCamera), false, TEST_LOCATION); // Broken camera 1
1167 DALI_TEST_EQUALS(model.ApplyCamera(5u, appliedCamera), false, TEST_LOCATION); // Broken camera 2
1168 DALI_TEST_EQUALS(model.ApplyCamera(6u, appliedCamera), false, TEST_LOCATION); // Cannot apply over the index.
1173 int UtcDaliModelMultiplePrimitives(void)
1175 ToolkitTestApplication application;
1177 Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_MULTIPLE_PRIMITIVE_FILE_NAME);
1178 model.SetProperty(Dali::Actor::Property::SIZE, Vector2(50, 50));
1179 application.GetScene().Add(model);
1181 gResourceReadyCalled = false;
1182 model.ResourceReadySignal().Connect(&OnResourceReady);
1183 DALI_TEST_EQUALS(gResourceReadyCalled, false, TEST_LOCATION);
1185 application.SendNotification();
1186 application.Render();
1188 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1189 application.SendNotification();
1190 application.Render();
1192 Actor actor = model.FindChildByName("rootNode");
1194 DALI_TEST_EQUALS(0, actor.GetChildCount(), TEST_LOCATION);
1195 DALI_TEST_EQUALS(2, actor.GetRendererCount(), TEST_LOCATION);
1200 int UtcDaliModelColorMode(void)
1202 ToolkitTestApplication application;
1204 Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
1205 model.SetProperty(Dali::Actor::Property::SIZE, Vector2(50, 50));
1206 model.SetProperty(Dali::Actor::Property::COLOR, Color::RED);
1207 application.GetScene().Add(model);
1209 gResourceReadyCalled = false;
1210 model.ResourceReadySignal().Connect(&OnResourceReady);
1211 DALI_TEST_EQUALS(gResourceReadyCalled, false, TEST_LOCATION);
1213 application.SendNotification();
1214 application.Render();
1216 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1217 application.SendNotification();
1218 application.Render();
1220 Actor actor = model.FindChildByName("AnimatedCube");
1221 Vector4 childColor = actor[Dali::Actor::Property::COLOR];
1222 Vector4 childWorldColor = actor[Dali::Actor::Property::WORLD_COLOR];
1224 DALI_TEST_EQUALS(childColor, Color::WHITE, TEST_LOCATION);
1225 DALI_TEST_EQUALS(childWorldColor, Color::RED, TEST_LOCATION);
1230 int UtcDaliModelResourceReady(void)
1232 ToolkitTestApplication application;
1234 gOnRelayoutCallBackCalled = false;
1235 gResourceReadyCalled = false;
1236 Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_ANIMATION_TEST_FILE_NAME);
1237 model.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
1238 model.OnRelayoutSignal().Connect(OnRelayoutCallback);
1239 model.ResourceReadySignal().Connect(OnResourceReady);
1240 DALI_TEST_EQUALS(model.IsResourceReady(), false, TEST_LOCATION);
1243 DALI_TEST_CHECK(!gOnRelayoutCallBackCalled);
1244 DALI_TEST_CHECK(!gResourceReadyCalled);
1246 application.GetScene().Add(model);
1248 application.SendNotification();
1249 application.Render();
1251 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1252 application.SendNotification();
1253 application.Render();
1255 DALI_TEST_EQUALS(gOnRelayoutCallBackCalled, false, TEST_LOCATION);
1256 DALI_TEST_EQUALS(model.IsResourceReady(), true, TEST_LOCATION);
1257 DALI_TEST_EQUALS(gResourceReadyCalled, true, TEST_LOCATION);
1262 int UtcDaliModelResourceCacheCheck(void)
1264 ToolkitTestApplication application;
1266 // Load three instances of the same model and add them to the scene
1267 Scene3D::Model model1 = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
1268 Scene3D::Model model2 = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
1269 Scene3D::Model model3 = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
1271 application.GetScene().Add(model1);
1272 application.GetScene().Add(model2);
1273 application.GetScene().Add(model3);
1275 gResourceReadyCalled = false;
1276 model1.ResourceReadySignal().Connect(&OnResourceReady);
1277 model2.ResourceReadySignal().Connect(&OnResourceReady);
1278 model3.ResourceReadySignal().Connect(&OnResourceReady);
1279 DALI_TEST_EQUALS(gResourceReadyCalled, false, TEST_LOCATION);
1281 application.SendNotification();
1282 application.Render();
1284 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(3), true, TEST_LOCATION);
1285 application.SendNotification();
1286 application.Render();
1288 // Check that the loading has finished for all the three instances
1289 DALI_TEST_EQUALS(gResourceReadyCalled, true, TEST_LOCATION);
1291 Actor meshActor1 = model1.FindChildByName("AnimatedCube");
1292 Actor meshActor2 = model2.FindChildByName("AnimatedCube");
1293 Actor meshActor3 = model3.FindChildByName("AnimatedCube");
1294 DALI_TEST_CHECK(meshActor1);
1295 DALI_TEST_CHECK(meshActor2);
1296 DALI_TEST_CHECK(meshActor3);
1298 Renderer renderer1 = meshActor1.GetRendererAt(0u);
1299 Renderer renderer2 = meshActor2.GetRendererAt(0u);
1300 Renderer renderer3 = meshActor3.GetRendererAt(0u);
1301 DALI_TEST_CHECK(renderer1);
1302 DALI_TEST_CHECK(renderer2);
1303 DALI_TEST_CHECK(renderer3);
1305 // Check that all the three instances use the shared textures and geometries from the cache
1306 // but have their own shader objects
1307 DALI_TEST_EQUALS(renderer1.GetTextures(), renderer2.GetTextures(), TEST_LOCATION);
1308 DALI_TEST_EQUALS(renderer1.GetTextures(), renderer3.GetTextures(), TEST_LOCATION);
1309 DALI_TEST_EQUALS(renderer1.GetGeometry(), renderer2.GetGeometry(), TEST_LOCATION);
1310 DALI_TEST_EQUALS(renderer1.GetGeometry(), renderer3.GetGeometry(), TEST_LOCATION);
1311 DALI_TEST_NOT_EQUALS(renderer1.GetShader(), renderer2.GetShader(), 0.0f, TEST_LOCATION);
1312 DALI_TEST_NOT_EQUALS(renderer1.GetShader(), renderer3.GetShader(), 0.0f, TEST_LOCATION);
1313 DALI_TEST_NOT_EQUALS(renderer2.GetShader(), renderer3.GetShader(), 0.0f, TEST_LOCATION);
1319 // Check that all the other two instances still use the shared textures and geometries from the cache
1320 // but have their own shader objects
1321 DALI_TEST_EQUALS(renderer2.GetTextures(), renderer3.GetTextures(), TEST_LOCATION);
1322 DALI_TEST_EQUALS(renderer2.GetGeometry(), renderer3.GetGeometry(), TEST_LOCATION);
1323 DALI_TEST_NOT_EQUALS(renderer2.GetShader(), renderer3.GetShader(), 0.0f, TEST_LOCATION);
1325 // Set new IBL textures for model2, and this should apply to model2 instance only
1326 gResourceReadyCalled = false;
1327 DALI_TEST_EQUALS(gResourceReadyCalled, false, TEST_LOCATION);
1328 model2.SetImageBasedLightSource(TEST_DIFFUSE_TEXTURE, TEST_SPECULAR_TEXTURE);
1330 application.SendNotification();
1331 application.Render();
1333 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1334 application.SendNotification();
1335 application.Render();
1337 // Check that the new IBL textures are loaded for model2
1338 DALI_TEST_EQUALS(gResourceReadyCalled, true, TEST_LOCATION);
1340 // Check that the two instances still use the shared geometries from the cache
1341 // but now have their own shader objects and different texture set
1342 DALI_TEST_NOT_EQUALS(renderer2.GetTextures(), renderer3.GetTextures(), 0.0f, TEST_LOCATION);
1343 DALI_TEST_EQUALS(renderer2.GetGeometry(), renderer3.GetGeometry(), TEST_LOCATION);
1344 DALI_TEST_NOT_EQUALS(renderer2.GetShader(), renderer3.GetShader(), 0.0f, TEST_LOCATION);
1346 // Check that the two instances now have their own diffuse texture and specular texture,
1347 // but all the other textures are still the same
1348 TextureSet textureSet2 = renderer2.GetTextures();
1349 TextureSet textureSet3 = renderer3.GetTextures();
1350 DALI_TEST_EQUALS(textureSet2.GetTextureCount(), 9u, TEST_LOCATION);
1351 DALI_TEST_EQUALS(textureSet3.GetTextureCount(), 9u, TEST_LOCATION);
1353 for(uint32_t i = 0; i < 7u; i++)
1355 DALI_TEST_EQUALS(textureSet2.GetTexture(i), textureSet3.GetTexture(i), TEST_LOCATION);
1358 DALI_TEST_NOT_EQUALS(textureSet2.GetTexture(7u), textureSet3.GetTexture(7u), 0.0f, TEST_LOCATION);
1359 DALI_TEST_NOT_EQUALS(textureSet2.GetTexture(8u), textureSet3.GetTexture(8u), 0.0f, TEST_LOCATION);
1364 int UtcDaliModelAddRemoveModelNode(void)
1366 ToolkitTestApplication application;
1368 Scene3D::Model model = Scene3D::Model::New();
1369 model.SetProperty(Dali::Actor::Property::SIZE, Vector2(50, 50));
1371 Scene3D::ModelNode node1 = Scene3D::ModelNode::New();
1372 Scene3D::ModelNode node2 = Scene3D::ModelNode::New();
1373 Scene3D::ModelNode node3 = Scene3D::ModelNode::New();
1374 Scene3D::ModelNode node4 = Scene3D::ModelNode::New();
1376 model.AddModelNode(node1);
1377 model.AddModelNode(node2);
1378 model.AddModelNode(node3);
1379 model.RemoveModelNode(node1); // Remove node before scene on
1381 application.GetScene().Add(model);
1383 Dali::Scene3D::ModelNode root = model.GetModelRoot();
1384 DALI_TEST_CHECK(root);
1385 DALI_TEST_EQUALS(2, root.GetChildCount(), TEST_LOCATION);
1387 model.RemoveModelNode(node2); // Remove node after scene on
1389 DALI_TEST_EQUALS(1, root.GetChildCount(), TEST_LOCATION);
1391 model.AddModelNode(node4); // Add during scene on
1393 DALI_TEST_EQUALS(2, root.GetChildCount(), TEST_LOCATION);
1395 application.GetScene().Remove(model);
1397 model.RemoveModelNode(node3); // Remove node after scene off
1402 int UtcDaliModelFindChildModelNodeByName(void)
1404 tet_infoline(" UtcDaliModelNodeFindChildModelNodeByName.");
1406 ToolkitTestApplication application;
1408 Scene3D::Model model = Scene3D::Model::New();
1409 application.GetScene().Add(model);
1411 Scene3D::ModelNode modelNode1 = Scene3D::ModelNode::New();
1412 Scene3D::ModelNode modelNode2 = Scene3D::ModelNode::New();
1414 modelNode1.SetProperty(Dali::Actor::Property::NAME, "modelNode1");
1415 modelNode2.SetProperty(Dali::Actor::Property::NAME, "modelNode2");
1416 model.AddModelNode(modelNode1);
1417 model.AddModelNode(modelNode2);
1419 Scene3D::ModelNode child1 = model.FindChildModelNodeByName("modelNode1");
1420 DALI_TEST_CHECK(child1);
1421 DALI_TEST_EQUALS(child1, modelNode1, TEST_LOCATION);
1423 Scene3D::ModelNode child2 = model.FindChildModelNodeByName("modelNode2");
1424 DALI_TEST_CHECK(child2);
1425 DALI_TEST_EQUALS(child2, modelNode2, TEST_LOCATION);
1430 int UtcDaliModelSizeChange(void)
1432 tet_infoline(" UtcDaliModelSizeChange.");
1434 ToolkitTestApplication application;
1436 Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
1437 model.SetProperty(Dali::Actor::Property::SIZE, Vector3(300, 300, 300));
1438 application.GetScene().Add(model);
1440 application.SendNotification();
1441 application.Render();
1443 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1444 application.SendNotification();
1445 application.Render();
1447 DALI_TEST_EQUALS(model.GetChildCount(), 1u, TEST_LOCATION);
1448 Vector3 scale = model.GetChildAt(0u).GetProperty<Vector3>(Dali::Actor::Property::SCALE);
1450 model.SetProperty(Dali::Actor::Property::SIZE, Vector3(600, 600, 600));
1451 Vector3 scale2 = model.GetChildAt(0u).GetProperty<Vector3>(Dali::Actor::Property::SCALE);
1453 DALI_TEST_NOT_EQUALS(scale, scale2, 0.1f, TEST_LOCATION);
1458 int UtcDaliModelSizeChange2(void)
1460 tet_infoline(" UtcDaliModelSizeChange2.");
1462 ToolkitTestApplication application;
1464 Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
1465 model.SetProperty(Dali::Actor::Property::SIZE, Vector3(300, 300, 300));
1466 application.GetScene().Add(model);
1468 application.SendNotification();
1469 application.Render();
1471 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1472 application.SendNotification();
1473 application.Render();
1475 DALI_TEST_EQUALS(model.GetChildCount(), 1u, TEST_LOCATION);
1476 Vector3 scale = model.GetChildAt(0u).GetProperty<Vector3>(Dali::Actor::Property::SCALE);
1478 Animation animation = Animation::New(0.5f);
1479 animation.AnimateTo(Dali::Property(model, Dali::Actor::Property::SIZE), Vector3(600, 600, 600));
1482 application.SendNotification();
1483 application.Render(250);
1485 application.SendNotification();
1487 Vector3 scale2 = model.GetChildAt(0u).GetProperty<Vector3>(Dali::Actor::Property::SCALE);
1488 DALI_TEST_NOT_EQUALS(scale, scale2, 0.1f, TEST_LOCATION);
1493 int UtcDaliModelRetrieveBlendShapeNames(void)
1495 tet_infoline(" UtcDaliModelRetrieveBlendShapeByName.");
1497 ToolkitTestApplication application;
1499 Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_EXTRAS_FILE_NAME);
1500 model.SetProperty(Dali::Actor::Property::SIZE, Vector3(300, 300, 300));
1501 application.GetScene().Add(model);
1503 application.SendNotification();
1504 application.Render();
1506 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1507 application.SendNotification();
1508 application.Render();
1510 DALI_TEST_EQUALS(model.GetChildCount(), 1u, TEST_LOCATION);
1512 // Get target ModelNode that has extras
1513 Scene3D::ModelNode expectNode = model.FindChildModelNodeByName("AnimatedMorphCube");
1515 // Pair of expected blend shape index from expectNode.
1516 std::map<std::string, Scene3D::Loader::BlendShapes::Index> expectBlendShapeNames = {
1521 std::vector<std::string> blendShapeNameList;
1522 model.RetrieveBlendShapeNames(blendShapeNameList);
1524 DALI_TEST_EQUALS(blendShapeNameList.size(), expectBlendShapeNames.size(), TEST_LOCATION);
1525 for(auto i = 0u; i < blendShapeNameList.size(); ++i)
1527 const auto& name = blendShapeNameList[i];
1528 tet_printf("Check retrieved blendshape name : %s\n", name.c_str());
1530 const auto& iter = expectBlendShapeNames.find(name);
1531 DALI_TEST_CHECK(iter != expectBlendShapeNames.end());
1533 std::vector<Scene3D::ModelNode> nodeList;
1534 model.RetrieveModelNodesByBlendShapeName(name, nodeList);
1535 DALI_TEST_EQUALS(nodeList.size(), 1u, TEST_LOCATION);
1536 DALI_TEST_EQUALS(nodeList[0], expectNode, TEST_LOCATION);
1537 DALI_TEST_EQUALS(nodeList[0].GetBlendShapeIndexByName(name), iter->second, TEST_LOCATION);