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>
23 #include <dali-toolkit/devel-api/focus-manager/keyboard-focus-manager-devel.h>
24 #include <dali/integration-api/events/touch-event-integ.h>
25 #include <toolkit-event-thread-callback.h>
27 #include <dali-scene3d/public-api/controls/model/model.h>
29 #include <dali/devel-api/actors/camera-actor-devel.h>
32 using namespace Dali::Toolkit;
34 void model_startup(void)
36 test_return_value = TET_UNDEF;
39 void model_cleanup(void)
41 test_return_value = TET_PASS;
46 const bool DEFAULT_MODEL_CHILDREN_SENSITIVE = false;
47 const bool DEFAULT_MODEL_CHILDREN_FOCUSABLE = false;
49 * For the AnimatedCube.gltf and its Assets
50 * Donated by Norbert Nopper for glTF testing.
51 * Take from https://github.com/KhronosGroup/glTF-Sample-Models/tree/master/2.0/AnimatedCube
53 const char* TEST_GLTF_FILE_NAME = TEST_RESOURCE_DIR "/AnimatedCube.gltf";
54 const char* TEST_GLTF_ANIMATION_TEST_FILE_NAME = TEST_RESOURCE_DIR "/animationTest.gltf";
55 const char* TEST_GLTF_MULTIPLE_PRIMITIVE_FILE_NAME = TEST_RESOURCE_DIR "/simpleMultiplePrimitiveTest.gltf";
56 const char* TEST_DLI_FILE_NAME = TEST_RESOURCE_DIR "/arc.dli";
57 // @TODO: The test cases for loading the DLI model below is temporarily disabled.
58 // Need to fix how resources are loaded when a model contains multiple scenes and
59 // each scene has its own root node.
60 #ifdef MULTIPLE_SCENES_MODEL_SUPPORT
61 const char* TEST_DLI_EXERCISE_FILE_NAME = TEST_RESOURCE_DIR "/exercise.dli";
64 * For the diffuse and specular cube map texture.
65 * These textures are based off version of Wave engine sample
66 * Take from https://github.com/WaveEngine/Samples
68 * Copyright (c) 2023 Wave Coorporation
70 * Permission is hereby granted, free of charge, to any person obtaining a copy
71 * of this software and associated documentation files (the "Software"), to
72 * deal in the Software without restriction, including without limitation the
73 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
74 * sell copies of the Software, and to permit persons to whom the Software is
75 * furnished to do so, subject to the following conditions:
77 * The above copyright notice and this permission notice shall be included in
78 * all copies or substantial portions of the Software.
80 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
81 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
82 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
83 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
84 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
85 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
88 const char* TEST_DIFFUSE_TEXTURE = TEST_RESOURCE_DIR "/forest_irradiance.ktx";
89 const char* TEST_SPECULAR_TEXTURE = TEST_RESOURCE_DIR "/forest_radiance.ktx";
91 bool gTouchCallBackCalled = false;
92 bool TestTouchCallback(Actor, const TouchEvent&)
94 gTouchCallBackCalled = true;
98 bool gFocusChangedCallBackCalled = false;
99 void TestFocusChangedCallback(Actor, Actor)
101 gFocusChangedCallBackCalled = true;
105 static bool gOnRelayoutCallBackCalled = false;
106 void OnRelayoutCallback(Actor actor)
108 gOnRelayoutCallBackCalled = true;
111 static bool gResourceReadyCalled = false;
112 void OnResourceReady(Control control)
114 gResourceReadyCalled = true;
119 // Negative test case for a method
120 int UtcDaliModelUninitialized(void)
122 ToolkitTestApplication application;
123 tet_infoline(" UtcDaliModelUninitialized");
125 Scene3D::Model model;
129 // New() must be called to create a Model or it wont be valid.
130 Actor a = Actor::New();
132 DALI_TEST_CHECK(false);
134 catch(Dali::DaliException& e)
136 // Tests that a negative test of an assertion succeeds
137 DALI_TEST_PRINT_ASSERT(e);
138 DALI_TEST_CHECK(!model);
143 // Positive test case for a method
144 int UtcDaliModelNew(void)
146 ToolkitTestApplication application;
147 tet_infoline(" UtcDaliModelNew");
149 Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
150 DALI_TEST_CHECK(model);
154 // Positive test case for a method
155 int UtcDaliModelDownCast(void)
157 ToolkitTestApplication application;
158 tet_infoline(" UtcDaliModelDownCast");
160 Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
161 BaseHandle handle(model);
163 Scene3D::Model model2 = Scene3D::Model::DownCast(handle);
164 DALI_TEST_CHECK(model);
165 DALI_TEST_CHECK(model2);
166 DALI_TEST_CHECK(model2 == model);
170 int UtcDaliModelTypeRegistry(void)
172 ToolkitTestApplication application;
174 TypeRegistry typeRegistry = TypeRegistry::Get();
175 DALI_TEST_CHECK(typeRegistry);
177 TypeInfo typeInfo = typeRegistry.GetTypeInfo("Model");
178 DALI_TEST_CHECK(typeInfo);
180 BaseHandle handle = typeInfo.CreateInstance();
181 DALI_TEST_CHECK(handle);
183 Scene3D::Model model = Scene3D::Model::DownCast(handle);
184 DALI_TEST_CHECK(model);
189 // Positive test case for a method
190 int UtcDaliModelAddRemove(void)
192 ToolkitTestApplication application;
193 tet_infoline(" UtcDaliModelAddRemove");
195 Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
196 DALI_TEST_CHECK(model);
198 Actor actor = Actor::New();
199 DALI_TEST_CHECK(!actor.GetProperty<bool>(Actor::Property::CONNECTED_TO_SCENE));
201 model.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
202 model.SetProperty(Actor::Property::SIZE, application.GetScene().GetSize());
204 application.GetScene().Add(model);
206 DALI_TEST_CHECK(actor.GetProperty<bool>(Actor::Property::CONNECTED_TO_SCENE));
210 DALI_TEST_CHECK(!actor.GetProperty<bool>(Actor::Property::CONNECTED_TO_SCENE));
214 int UtcDaliModelCopyAndAssignment(void)
216 ToolkitTestApplication application;
218 Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
219 DALI_TEST_CHECK(model);
221 Scene3D::Model copy(model);
222 DALI_TEST_CHECK(model == copy);
224 Scene3D::Model assign;
225 DALI_TEST_CHECK(!assign);
228 DALI_TEST_CHECK(assign == model);
233 int UtcDaliModelMoveConstructor(void)
235 ToolkitTestApplication application;
237 Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
238 DALI_TEST_EQUALS(1, model.GetBaseObject().ReferenceCount(), TEST_LOCATION);
239 model.SetProperty(Actor::Property::SENSITIVE, false);
240 DALI_TEST_CHECK(false == model.GetProperty<bool>(Actor::Property::SENSITIVE));
242 Scene3D::Model moved = std::move(model);
243 DALI_TEST_CHECK(moved);
244 DALI_TEST_EQUALS(1, moved.GetBaseObject().ReferenceCount(), TEST_LOCATION);
245 DALI_TEST_CHECK(false == moved.GetProperty<bool>(Actor::Property::SENSITIVE));
246 DALI_TEST_CHECK(!model);
251 int UtcDaliModelMoveAssignment(void)
253 ToolkitTestApplication application;
255 Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
256 DALI_TEST_EQUALS(1, model.GetBaseObject().ReferenceCount(), TEST_LOCATION);
257 model.SetProperty(Actor::Property::SENSITIVE, false);
258 DALI_TEST_CHECK(false == model.GetProperty<bool>(Actor::Property::SENSITIVE));
260 Scene3D::Model moved;
261 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 UtcDaliModelOnScene01(void)
272 ToolkitTestApplication application;
274 Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
275 application.GetScene().Add(model);
277 gResourceReadyCalled = false;
278 model.ResourceReadySignal().Connect(&OnResourceReady);
279 DALI_TEST_EQUALS(gResourceReadyCalled, false, TEST_LOCATION);
281 application.SendNotification();
282 application.Render();
284 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
285 application.SendNotification();
286 application.Render();
288 DALI_TEST_EQUALS(gResourceReadyCalled, true, TEST_LOCATION);
290 uint32_t modelCount = model.GetModelRoot().GetChildCount();
291 DALI_TEST_EQUALS(1, modelCount, TEST_LOCATION);
295 int UtcDaliModelOnScene02(void)
297 ToolkitTestApplication application;
299 Scene3D::Model model = Scene3D::Model::New(TEST_DLI_FILE_NAME);
300 application.GetScene().Add(model);
302 gResourceReadyCalled = false;
303 model.ResourceReadySignal().Connect(&OnResourceReady);
304 DALI_TEST_EQUALS(gResourceReadyCalled, false, TEST_LOCATION);
306 application.SendNotification();
307 application.Render();
309 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
310 application.SendNotification();
311 application.Render();
313 DALI_TEST_EQUALS(gResourceReadyCalled, true, TEST_LOCATION);
315 uint32_t modelCount = model.GetModelRoot().GetChildCount();
316 DALI_TEST_EQUALS(1, modelCount, TEST_LOCATION);
318 Actor rootActor = model.GetModelRoot();
319 Vector3 rootSize = rootActor.GetProperty<Vector3>(Dali::Actor::Property::SIZE);
320 DALI_TEST_EQUALS(Vector3(2, 2, 1), rootSize, TEST_LOCATION);
325 int UtcDaliModelOnSizeSet(void)
327 ToolkitTestApplication application;
329 Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
331 application.GetScene().Add(model);
333 application.SendNotification();
334 application.Render();
336 Vector2 size(200.0f, 300.0f);
337 model.SetProperty(Actor::Property::SIZE, size);
339 application.SendNotification();
340 application.Render();
342 DALI_TEST_EQUALS(model.GetCurrentProperty<Vector2>(Actor::Property::SIZE), size, TEST_LOCATION);
347 int UtcDaliModelGetNaturalSize(void)
349 ToolkitTestApplication application;
351 Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
353 Vector3 naturalSize = model.GetNaturalSize();
354 DALI_TEST_EQUALS(Vector3::ZERO, naturalSize, TEST_LOCATION);
356 application.GetScene().Add(model);
358 gResourceReadyCalled = false;
359 model.ResourceReadySignal().Connect(&OnResourceReady);
360 DALI_TEST_EQUALS(gResourceReadyCalled, false, TEST_LOCATION);
362 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
363 application.SendNotification();
365 DALI_TEST_EQUALS(gResourceReadyCalled, true, TEST_LOCATION);
367 naturalSize = model.GetNaturalSize();
368 DALI_TEST_EQUALS(Vector3(2, 2, 2), naturalSize, TEST_LOCATION);
370 Actor root = model.GetModelRoot();
371 DALI_TEST_CHECK(root);
376 int UtcDaliModelSetImageBasedLightSource01(void)
378 ToolkitTestApplication application;
380 Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
381 application.GetScene().Add(model);
383 gResourceReadyCalled = false;
384 model.ResourceReadySignal().Connect(&OnResourceReady);
385 DALI_TEST_EQUALS(gResourceReadyCalled, false, TEST_LOCATION);
387 application.SendNotification();
388 application.Render();
390 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
391 application.SendNotification();
392 application.Render();
394 DALI_TEST_EQUALS(gResourceReadyCalled, true, TEST_LOCATION);
396 Actor meshActor = model.FindChildByName("AnimatedCube");
397 DALI_TEST_CHECK(meshActor);
399 Renderer renderer = meshActor.GetRendererAt(0u);
400 DALI_TEST_CHECK(renderer);
402 TextureSet textureSet = renderer.GetTextures();
403 DALI_TEST_EQUALS(textureSet.GetTextureCount(), 9u, TEST_LOCATION);
405 Texture diffuseTexture = textureSet.GetTexture(7u);
406 Texture specularTexture = textureSet.GetTexture(8u);
408 gResourceReadyCalled = false;
409 DALI_TEST_EQUALS(gResourceReadyCalled, false, TEST_LOCATION);
410 model.SetImageBasedLightSource(TEST_DIFFUSE_TEXTURE, TEST_SPECULAR_TEXTURE);
412 application.SendNotification();
413 application.Render();
415 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
416 application.SendNotification();
417 application.Render();
419 DALI_TEST_EQUALS(gResourceReadyCalled, true, TEST_LOCATION);
421 TextureSet newTextureSet = renderer.GetTextures();
422 Texture newDiffuseTexture = newTextureSet.GetTexture(7u);
423 Texture newSpecularTexture = newTextureSet.GetTexture(8u);
425 DALI_TEST_NOT_EQUALS(diffuseTexture, newDiffuseTexture, 0.0f, TEST_LOCATION);
426 DALI_TEST_NOT_EQUALS(specularTexture, newSpecularTexture, 0.0f, TEST_LOCATION);
433 int UtcDaliModelSetImageBasedLightSource02(void)
435 ToolkitTestApplication application;
437 Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
438 application.GetScene().Add(model);
440 gResourceReadyCalled = false;
441 model.ResourceReadySignal().Connect(&OnResourceReady);
442 DALI_TEST_EQUALS(gResourceReadyCalled, false, TEST_LOCATION);
444 application.SendNotification();
445 application.Render();
447 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
448 application.SendNotification();
449 application.Render();
451 DALI_TEST_EQUALS(gResourceReadyCalled, true, TEST_LOCATION);
453 Actor meshActor = model.FindChildByName("AnimatedCube");
454 DALI_TEST_CHECK(meshActor);
456 Renderer renderer = meshActor.GetRendererAt(0u);
457 DALI_TEST_CHECK(renderer);
459 TextureSet textureSet = renderer.GetTextures();
460 DALI_TEST_EQUALS(textureSet.GetTextureCount(), 9u, TEST_LOCATION);
462 Texture diffuseTexture = textureSet.GetTexture(7u);
463 Texture specularTexture = textureSet.GetTexture(8u);
465 // if url is empty, loading is not requested.
466 model.SetImageBasedLightSource("", "");
468 Texture newDiffuseTexture = textureSet.GetTexture(7u);
469 Texture newSpecularTexture = textureSet.GetTexture(8u);
471 DALI_TEST_EQUALS(diffuseTexture, newDiffuseTexture, TEST_LOCATION);
472 DALI_TEST_EQUALS(specularTexture, newSpecularTexture, TEST_LOCATION);
477 int UtcDaliModelSetImageBasedLightSource03(void)
479 ToolkitTestApplication application;
481 Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
482 application.GetScene().Add(model);
484 gResourceReadyCalled = false;
485 model.ResourceReadySignal().Connect(&OnResourceReady);
486 DALI_TEST_EQUALS(gResourceReadyCalled, false, TEST_LOCATION);
488 application.SendNotification();
489 application.Render();
491 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
492 application.SendNotification();
493 application.Render();
495 DALI_TEST_EQUALS(gResourceReadyCalled, true, TEST_LOCATION);
497 Actor meshActor = model.FindChildByName("AnimatedCube");
498 DALI_TEST_CHECK(meshActor);
500 Renderer renderer = meshActor.GetRendererAt(0u);
501 DALI_TEST_CHECK(renderer);
503 TextureSet textureSet = renderer.GetTextures();
504 DALI_TEST_EQUALS(textureSet.GetTextureCount(), 9u, TEST_LOCATION);
506 Texture diffuseTexture = textureSet.GetTexture(7u);
507 Texture specularTexture = textureSet.GetTexture(8u);
509 gResourceReadyCalled = false;
510 DALI_TEST_EQUALS(gResourceReadyCalled, false, TEST_LOCATION);
511 model.SetImageBasedLightSource("dummy.ktx", "dummy.ktx");
513 application.SendNotification();
514 application.Render();
516 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
517 application.SendNotification();
518 application.Render();
520 DALI_TEST_EQUALS(gResourceReadyCalled, true, TEST_LOCATION);
522 Texture newDiffuseTexture = textureSet.GetTexture(7u);
523 Texture newSpecularTexture = textureSet.GetTexture(8u);
525 DALI_TEST_EQUALS(diffuseTexture, newDiffuseTexture, TEST_LOCATION);
526 DALI_TEST_EQUALS(specularTexture, newSpecularTexture, TEST_LOCATION);
531 int UtcDaliModelSetImageBasedLightSource04(void)
533 ToolkitTestApplication application;
535 Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
536 model.SetImageBasedLightSource(TEST_DIFFUSE_TEXTURE, TEST_SPECULAR_TEXTURE);
537 application.GetScene().Add(model);
539 gResourceReadyCalled = false;
540 model.ResourceReadySignal().Connect(&OnResourceReady);
541 DALI_TEST_EQUALS(gResourceReadyCalled, false, TEST_LOCATION);
543 application.SendNotification();
544 application.Render();
546 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(3), true, TEST_LOCATION);
547 application.SendNotification();
548 application.Render();
550 DALI_TEST_EQUALS(gResourceReadyCalled, true, TEST_LOCATION);
554 int UtcDaliModelImageBasedFactor(void)
556 ToolkitTestApplication application;
558 Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
560 DALI_TEST_EQUALS(model.GetImageBasedLightScaleFactor(), 1.0f, TEST_LOCATION);
562 model.SetImageBasedLightScaleFactor(0.5f);
563 DALI_TEST_EQUALS(model.GetImageBasedLightScaleFactor(), 0.5f, TEST_LOCATION);
567 int UtcDaliModelChildrenSensitive01(void)
569 ToolkitTestApplication application;
571 Scene3D::Model view = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
572 view.SetProperty(Dali::Actor::Property::SIZE, Vector3(100, 100, 100));
573 view.SetProperty(Dali::Actor::Property::POSITION, Vector3(0, 0, 0));
574 view.SetProperty(Dali::Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER);
575 view.SetProperty(Dali::Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
577 // Get default vaule.
578 DALI_TEST_EQUALS(view.GetChildrenSensitive(), DEFAULT_MODEL_CHILDREN_SENSITIVE, TEST_LOCATION);
580 // Allow children actor's event before on scene.
581 view.SetChildrenSensitive(true);
582 DALI_TEST_EQUALS(view.GetChildrenSensitive(), true, TEST_LOCATION);
583 application.GetScene().Add(view);
585 gResourceReadyCalled = false;
586 view.ResourceReadySignal().Connect(&OnResourceReady);
587 DALI_TEST_EQUALS(gResourceReadyCalled, false, TEST_LOCATION);
589 application.SendNotification();
590 application.Render();
592 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
593 application.SendNotification();
594 application.Render();
596 DALI_TEST_EQUALS(gResourceReadyCalled, true, TEST_LOCATION);
598 Actor meshActor = view.FindChildByName("AnimatedCube");
599 DALI_TEST_CHECK(meshActor);
601 // connect hit-test signal
602 gTouchCallBackCalled = false;
603 meshActor.TouchedSignal().Connect(TestTouchCallback);
605 Vector2 sceneSize = application.GetScene().GetSize();
607 // Try to touch center of scene.
608 Dali::Integration::Point point;
609 point.SetState(PointState::DOWN);
610 point.SetScreenPosition(sceneSize * 0.5f);
611 Dali::Integration::TouchEvent event;
612 event.AddPoint(point);
614 // flush the queue and render once
615 application.SendNotification();
616 application.Render();
619 DALI_TEST_CHECK(!gTouchCallBackCalled);
620 application.ProcessEvent(event);
622 DALI_TEST_CHECK(gTouchCallBackCalled);
625 gTouchCallBackCalled = false;
627 // Block children actor's event
628 view.SetChildrenSensitive(false);
629 DALI_TEST_EQUALS(view.GetChildrenSensitive(), false, TEST_LOCATION);
631 // flush the queue and render once
632 application.SendNotification();
633 application.Render();
636 DALI_TEST_CHECK(!gTouchCallBackCalled);
637 application.ProcessEvent(event);
639 DALI_TEST_CHECK(!gTouchCallBackCalled);
642 gTouchCallBackCalled = false;
645 view.SetChildrenSensitive(true);
646 DALI_TEST_EQUALS(view.GetChildrenSensitive(), true, TEST_LOCATION);
648 // flush the queue and render once
649 application.SendNotification();
650 application.Render();
653 DALI_TEST_CHECK(!gTouchCallBackCalled);
654 application.ProcessEvent(event);
656 DALI_TEST_CHECK(gTouchCallBackCalled);
659 gTouchCallBackCalled = false;
664 int UtcDaliModelChildrenSensitive02(void)
666 ToolkitTestApplication application;
668 Scene3D::Model view = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
669 view.SetProperty(Dali::Actor::Property::SIZE, Vector3(100, 100, 100));
670 view.SetProperty(Dali::Actor::Property::POSITION, Vector3(0, 0, 0));
671 view.SetProperty(Dali::Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER);
672 view.SetProperty(Dali::Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
675 DALI_TEST_EQUALS(view.GetChildrenSensitive(), DEFAULT_MODEL_CHILDREN_SENSITIVE, TEST_LOCATION);
677 // Block children actor's event before on scene.
678 view.SetChildrenSensitive(false);
679 DALI_TEST_EQUALS(view.GetChildrenSensitive(), false, TEST_LOCATION);
680 application.GetScene().Add(view);
682 gResourceReadyCalled = false;
683 view.ResourceReadySignal().Connect(&OnResourceReady);
684 DALI_TEST_EQUALS(gResourceReadyCalled, false, TEST_LOCATION);
686 application.SendNotification();
687 application.Render();
689 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
690 application.SendNotification();
691 application.Render();
693 DALI_TEST_EQUALS(gResourceReadyCalled, true, TEST_LOCATION);
695 Actor meshActor = view.FindChildByName("AnimatedCube");
696 DALI_TEST_CHECK(meshActor);
698 // connect hit-test signal
699 gTouchCallBackCalled = false;
700 meshActor.TouchedSignal().Connect(TestTouchCallback);
702 Vector2 sceneSize = application.GetScene().GetSize();
704 // Try to touch center of scene.
705 Dali::Integration::Point point;
706 point.SetState(PointState::DOWN);
707 point.SetScreenPosition(sceneSize * 0.5f);
708 Dali::Integration::TouchEvent event;
709 event.AddPoint(point);
711 // flush the queue and render once
712 application.SendNotification();
713 application.Render();
716 DALI_TEST_CHECK(!gTouchCallBackCalled);
717 application.ProcessEvent(event);
719 DALI_TEST_CHECK(!gTouchCallBackCalled);
722 gTouchCallBackCalled = false;
725 view.SetChildrenSensitive(true);
726 DALI_TEST_EQUALS(view.GetChildrenSensitive(), true, TEST_LOCATION);
728 // flush the queue and render once
729 application.SendNotification();
730 application.Render();
733 DALI_TEST_CHECK(!gTouchCallBackCalled);
734 application.ProcessEvent(event);
736 DALI_TEST_CHECK(gTouchCallBackCalled);
739 gTouchCallBackCalled = false;
744 int UtcDaliModelChildrenFocusable01(void)
746 ToolkitTestApplication application;
748 Scene3D::Model view = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
749 view.SetProperty(Dali::Actor::Property::SIZE, Vector3(100, 100, 100));
750 view.SetProperty(Dali::Actor::Property::POSITION, Vector3(0, 0, 0));
751 view.SetProperty(Dali::Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER);
752 view.SetProperty(Dali::Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
754 // Get vaule. Default is false.
755 DALI_TEST_EQUALS(view.GetChildrenFocusable(), DEFAULT_MODEL_CHILDREN_FOCUSABLE, TEST_LOCATION);
757 // Allow children actor's focus before on scene.
758 view.SetChildrenFocusable(true);
759 DALI_TEST_EQUALS(view.GetChildrenFocusable(), true, TEST_LOCATION);
760 application.GetScene().Add(view);
762 gResourceReadyCalled = false;
763 view.ResourceReadySignal().Connect(&OnResourceReady);
764 DALI_TEST_EQUALS(gResourceReadyCalled, false, TEST_LOCATION);
766 application.SendNotification();
767 application.Render();
769 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
770 application.SendNotification();
771 application.Render();
773 DALI_TEST_EQUALS(gResourceReadyCalled, true, TEST_LOCATION);
775 Actor meshActor = view.FindChildByName("AnimatedCube");
776 DALI_TEST_CHECK(meshActor);
778 // Enable the default algorithm
779 KeyboardFocusManager manager = KeyboardFocusManager::Get();
780 DALI_TEST_CHECK(manager);
781 Dali::Toolkit::DevelKeyboardFocusManager::EnableDefaultAlgorithm(manager, true);
783 // connect focusable signal
784 gFocusChangedCallBackCalled = false;
785 meshActor.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true);
786 manager.FocusChangedSignal().Connect(TestFocusChangedCallback);
788 // Initialize with some left-positioned actor
789 Control focusStartActor = Control::New();
790 focusStartActor.SetProperty(Dali::Actor::Property::SIZE, Vector3(100, 100, 100));
791 focusStartActor.SetProperty(Dali::Actor::Property::POSITION, Vector3(-200, 0, 0));
792 focusStartActor.SetProperty(Dali::Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER);
793 focusStartActor.SetProperty(Dali::Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
794 focusStartActor.SetProperty(Dali::Actor::Property::KEYBOARD_FOCUSABLE, true);
795 application.GetScene().Add(focusStartActor);
798 manager.ClearFocus();
799 manager.SetCurrentFocusActor(focusStartActor);
800 gFocusChangedCallBackCalled = false;
802 // flush the queue and render once
803 application.SendNotification();
804 application.Render();
806 // Focusable view find success
807 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::RIGHT) == true);
808 DALI_TEST_CHECK(gFocusChangedCallBackCalled);
811 manager.ClearFocus();
812 manager.SetCurrentFocusActor(focusStartActor);
813 gFocusChangedCallBackCalled = false;
815 // Block children actor's focus
816 view.SetChildrenFocusable(false);
817 DALI_TEST_EQUALS(view.GetChildrenFocusable(), false, TEST_LOCATION);
819 // flush the queue and render once
820 application.SendNotification();
821 application.Render();
823 // Focusable view find failed
824 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::RIGHT) == false);
825 DALI_TEST_CHECK(!gFocusChangedCallBackCalled);
828 manager.ClearFocus();
829 manager.SetCurrentFocusActor(focusStartActor);
830 gFocusChangedCallBackCalled = false;
833 view.SetChildrenFocusable(true);
834 DALI_TEST_EQUALS(view.GetChildrenFocusable(), true, TEST_LOCATION);
836 // flush the queue and render once
837 application.SendNotification();
838 application.Render();
840 // Focusable view find success
841 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::RIGHT) == true);
842 DALI_TEST_CHECK(gFocusChangedCallBackCalled);
845 manager.ClearFocus();
846 manager.SetCurrentFocusActor(focusStartActor);
847 gFocusChangedCallBackCalled = false;
852 int UtcDaliModelModelChildrenFocusable02(void)
854 ToolkitTestApplication application;
856 Scene3D::Model view = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
857 view.SetProperty(Dali::Actor::Property::SIZE, Vector3(100, 100, 100));
858 view.SetProperty(Dali::Actor::Property::POSITION, Vector3(0, 0, 0));
859 view.SetProperty(Dali::Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER);
860 view.SetProperty(Dali::Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
862 // Get vaule. Default is true.
863 DALI_TEST_EQUALS(view.GetChildrenFocusable(), DEFAULT_MODEL_CHILDREN_FOCUSABLE, TEST_LOCATION);
865 // Block children actor's focus before on scene.
866 view.SetChildrenFocusable(false);
867 DALI_TEST_EQUALS(view.GetChildrenFocusable(), false, TEST_LOCATION);
868 application.GetScene().Add(view);
870 gResourceReadyCalled = false;
871 view.ResourceReadySignal().Connect(&OnResourceReady);
872 DALI_TEST_EQUALS(gResourceReadyCalled, false, TEST_LOCATION);
874 application.SendNotification();
875 application.Render();
877 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
878 application.SendNotification();
879 application.Render();
881 DALI_TEST_EQUALS(gResourceReadyCalled, true, TEST_LOCATION);
883 Actor meshActor = view.FindChildByName("AnimatedCube");
884 DALI_TEST_CHECK(meshActor);
886 // Enable the default algorithm
887 KeyboardFocusManager manager = KeyboardFocusManager::Get();
888 DALI_TEST_CHECK(manager);
889 Dali::Toolkit::DevelKeyboardFocusManager::EnableDefaultAlgorithm(manager, true);
891 // connect focusable signal
892 gFocusChangedCallBackCalled = false;
893 meshActor.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true);
894 manager.FocusChangedSignal().Connect(TestFocusChangedCallback);
896 // Initialize with some left-positioned actor
897 Control focusStartActor = Control::New();
898 focusStartActor.SetProperty(Dali::Actor::Property::SIZE, Vector3(100, 100, 100));
899 focusStartActor.SetProperty(Dali::Actor::Property::POSITION, Vector3(-200, 0, 0));
900 focusStartActor.SetProperty(Dali::Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER);
901 focusStartActor.SetProperty(Dali::Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
902 focusStartActor.SetProperty(Dali::Actor::Property::KEYBOARD_FOCUSABLE, true);
903 application.GetScene().Add(focusStartActor);
906 manager.ClearFocus();
907 manager.SetCurrentFocusActor(focusStartActor);
908 gFocusChangedCallBackCalled = false;
910 // flush the queue and render once
911 application.SendNotification();
912 application.Render();
914 // Focusable view find failed
915 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::RIGHT) == false);
916 DALI_TEST_CHECK(!gFocusChangedCallBackCalled);
919 manager.ClearFocus();
920 manager.SetCurrentFocusActor(focusStartActor);
921 gFocusChangedCallBackCalled = false;
924 view.SetChildrenFocusable(true);
925 DALI_TEST_EQUALS(view.GetChildrenFocusable(), true, TEST_LOCATION);
927 // flush the queue and render once
928 application.SendNotification();
929 application.Render();
931 // Focusable view find success
932 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::RIGHT) == true);
933 DALI_TEST_CHECK(gFocusChangedCallBackCalled);
936 manager.ClearFocus();
937 manager.SetCurrentFocusActor(focusStartActor);
938 gFocusChangedCallBackCalled = false;
943 int UtcDaliModelAnimation01(void)
945 ToolkitTestApplication application;
947 Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
948 model.SetProperty(Dali::Actor::Property::SIZE, Vector2(50, 50));
949 application.GetScene().Add(model);
951 gResourceReadyCalled = false;
952 model.ResourceReadySignal().Connect(&OnResourceReady);
953 DALI_TEST_EQUALS(gResourceReadyCalled, false, TEST_LOCATION);
955 application.SendNotification();
956 application.Render();
958 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
959 application.SendNotification();
960 application.Render();
962 DALI_TEST_EQUALS(gResourceReadyCalled, true, TEST_LOCATION);
964 uint32_t animationCount = model.GetAnimationCount();
965 DALI_TEST_EQUALS(1, animationCount, TEST_LOCATION);
967 Animation animationByIndex = model.GetAnimation(0u);
968 DALI_TEST_CHECK(animationByIndex);
970 Animation animationByName = model.GetAnimation("animation_AnimatedCube");
971 DALI_TEST_CHECK(animationByName);
972 DALI_TEST_EQUALS(animationByIndex, animationByName, TEST_LOCATION);
977 int UtcDaliModelAnimation02(void)
979 ToolkitTestApplication application;
981 Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_ANIMATION_TEST_FILE_NAME);
982 model.SetProperty(Dali::Actor::Property::SIZE, Vector2(50, 50));
983 application.GetScene().Add(model);
985 gResourceReadyCalled = false;
986 model.ResourceReadySignal().Connect(&OnResourceReady);
987 DALI_TEST_EQUALS(gResourceReadyCalled, false, TEST_LOCATION);
989 application.SendNotification();
990 application.Render();
992 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
993 application.SendNotification();
994 application.Render();
996 uint32_t animationCount = model.GetAnimationCount();
997 DALI_TEST_EQUALS(9, animationCount, TEST_LOCATION);
999 Animation animation1 = model.GetAnimation("Step Scale");
1000 DALI_TEST_CHECK(animation1);
1001 DALI_TEST_EQUALS(1.66667f, animation1.GetDuration(), 0.001f, TEST_LOCATION);
1003 Animation animation2 = model.GetAnimation("CubicSpline Scale");
1004 DALI_TEST_CHECK(animation2);
1005 DALI_TEST_EQUALS(1.66667f, animation2.GetDuration(), 0.001f, TEST_LOCATION);
1007 DALI_TEST_NOT_EQUALS(animation1, animation2, 0.0f, TEST_LOCATION);
1012 int UtcDaliModelAnimation03(void)
1014 #ifdef MULTIPLE_SCENES_MODEL_SUPPORT
1015 ToolkitTestApplication application;
1017 Scene3D::Model model = Scene3D::Model::New(TEST_DLI_EXERCISE_FILE_NAME);
1018 model.SetProperty(Dali::Actor::Property::SIZE, Vector2(50, 50));
1019 application.GetScene().Add(model);
1021 gResourceReadyCalled = false;
1022 model.ResourceReadySignal().Connect(&OnResourceReady);
1023 DALI_TEST_EQUALS(gResourceReadyCalled, false, TEST_LOCATION);
1025 application.SendNotification();
1026 application.Render();
1028 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1029 application.SendNotification();
1030 application.Render();
1032 DALI_TEST_EQUALS(gResourceReadyCalled, true, TEST_LOCATION);
1034 uint32_t animationCount = model.GetAnimationCount();
1035 DALI_TEST_EQUALS(18, animationCount, TEST_LOCATION);
1037 Animation animationByIndex = model.GetAnimation(0u);
1038 DALI_TEST_CHECK(animationByIndex);
1040 Animation animationByName = model.GetAnimation("idleClip");
1041 DALI_TEST_CHECK(animationByName);
1042 DALI_TEST_EQUALS(animationByIndex, animationByName, TEST_LOCATION);
1044 tet_result(TET_PASS);
1050 int UtcDaliModelCameraGenerate01(void)
1052 #ifdef MULTIPLE_SCENES_MODEL_SUPPORT
1053 ToolkitTestApplication application;
1055 Scene3D::Model model = Scene3D::Model::New(TEST_DLI_EXERCISE_FILE_NAME);
1056 model.SetProperty(Dali::Actor::Property::SIZE, Vector2(50, 50));
1057 application.GetScene().Add(model);
1059 gResourceReadyCalled = false;
1060 model.ResourceReadySignal().Connect(&OnResourceReady);
1061 DALI_TEST_EQUALS(gResourceReadyCalled, false, TEST_LOCATION);
1063 application.SendNotification();
1064 application.Render();
1066 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1067 application.SendNotification();
1068 application.Render();
1070 DALI_TEST_EQUALS(gResourceReadyCalled, true, TEST_LOCATION);
1072 uint32_t cameraCount = model.GetCameraCount();
1073 DALI_TEST_EQUALS(1, cameraCount, TEST_LOCATION);
1075 CameraActor generatedCamera = model.GenerateCamera(0u);
1076 DALI_TEST_CHECK(generatedCamera);
1078 generatedCamera = model.GenerateCamera(1u); // Fail to generate camera
1079 DALI_TEST_CHECK(!generatedCamera);
1081 tet_result(TET_PASS);
1087 int UtcDaliModelCameraGenerate02(void)
1089 ToolkitTestApplication application;
1091 Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
1092 model.SetProperty(Dali::Actor::Property::SIZE, Vector2(50, 50));
1093 application.GetScene().Add(model);
1095 gResourceReadyCalled = false;
1096 model.ResourceReadySignal().Connect(&OnResourceReady);
1097 DALI_TEST_EQUALS(gResourceReadyCalled, false, TEST_LOCATION);
1099 application.SendNotification();
1100 application.Render();
1102 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1103 application.SendNotification();
1104 application.Render();
1106 DALI_TEST_EQUALS(gResourceReadyCalled, true, TEST_LOCATION);
1108 uint32_t cameraCount = model.GetCameraCount();
1109 DALI_TEST_EQUALS(6, cameraCount, TEST_LOCATION);
1111 CameraActor generatedCamera0 = model.GenerateCamera(0u);
1112 DALI_TEST_CHECK(generatedCamera0);
1113 CameraActor generatedCamera1 = model.GenerateCamera(1u);
1114 DALI_TEST_CHECK(generatedCamera1);
1115 CameraActor generatedCamera2 = model.GenerateCamera(2u);
1116 DALI_TEST_CHECK(generatedCamera2);
1117 CameraActor generatedCamera3 = model.GenerateCamera(3u); // Infinity far camera
1118 DALI_TEST_CHECK(generatedCamera3);
1119 CameraActor generatedCamera4 = model.GenerateCamera(4u); // Broken camera 1
1120 DALI_TEST_CHECK(!generatedCamera4);
1121 CameraActor generatedCamera5 = model.GenerateCamera(5u); // Broken camera 2
1122 DALI_TEST_CHECK(!generatedCamera5);
1123 CameraActor generatedCamera6 = model.GenerateCamera(6u); // Out of bound
1124 DALI_TEST_CHECK(!generatedCamera6);
1126 CameraActor appliedCamera;
1127 DALI_TEST_EQUALS(model.ApplyCamera(0u, appliedCamera), false, TEST_LOCATION); // Cannot apply into empty camera.
1129 auto CompareCameraProperties = [](CameraActor lhs, CameraActor rhs, const char* location) {
1130 DALI_TEST_EQUALS(lhs.GetProperty<int>(Dali::CameraActor::Property::PROJECTION_MODE), rhs.GetProperty<int>(Dali::CameraActor::Property::PROJECTION_MODE), TEST_LOCATION);
1131 DALI_TEST_EQUALS(lhs.GetProperty<float>(Dali::CameraActor::Property::NEAR_PLANE_DISTANCE), rhs.GetProperty<float>(Dali::CameraActor::Property::NEAR_PLANE_DISTANCE), TEST_LOCATION);
1133 if(lhs.GetProperty<int>(Dali::CameraActor::Property::PROJECTION_MODE) == static_cast<int>(Dali::Camera::ProjectionMode::PERSPECTIVE_PROJECTION))
1135 DALI_TEST_EQUALS(lhs.GetProperty<float>(Dali::CameraActor::Property::FIELD_OF_VIEW), rhs.GetProperty<float>(Dali::CameraActor::Property::FIELD_OF_VIEW), TEST_LOCATION);
1136 // TODO : Open this test when infinity far projection implement.
1137 //DALI_TEST_EQUALS(lhs.GetProperty<float>(Dali::CameraActor::Property::FAR_PLANE_DISTANCE), rhs.GetProperty<float>(Dali::CameraActor::Property::FAR_PLANE_DISTANCE), TEST_LOCATION);
1141 DALI_TEST_EQUALS(lhs.GetProperty<float>(Dali::DevelCameraActor::Property::ORTHOGRAPHIC_SIZE), rhs.GetProperty<float>(Dali::DevelCameraActor::Property::ORTHOGRAPHIC_SIZE), TEST_LOCATION);
1142 DALI_TEST_EQUALS(lhs.GetProperty<float>(Dali::CameraActor::Property::FAR_PLANE_DISTANCE), rhs.GetProperty<float>(Dali::CameraActor::Property::FAR_PLANE_DISTANCE), TEST_LOCATION);
1146 appliedCamera = CameraActor::New();
1147 DALI_TEST_EQUALS(model.ApplyCamera(0u, appliedCamera), true, TEST_LOCATION);
1148 CompareCameraProperties(generatedCamera0, appliedCamera, TEST_LOCATION);
1149 DALI_TEST_EQUALS(model.ApplyCamera(1u, appliedCamera), true, TEST_LOCATION);
1150 CompareCameraProperties(generatedCamera1, appliedCamera, TEST_LOCATION);
1151 DALI_TEST_EQUALS(model.ApplyCamera(2u, appliedCamera), true, TEST_LOCATION);
1152 CompareCameraProperties(generatedCamera2, appliedCamera, TEST_LOCATION);
1153 DALI_TEST_EQUALS(model.ApplyCamera(3u, appliedCamera), true, TEST_LOCATION);
1154 CompareCameraProperties(generatedCamera3, appliedCamera, TEST_LOCATION);
1155 DALI_TEST_EQUALS(model.ApplyCamera(4u, appliedCamera), false, TEST_LOCATION); // Broken camera 1
1156 DALI_TEST_EQUALS(model.ApplyCamera(5u, appliedCamera), false, TEST_LOCATION); // Broken camera 2
1157 DALI_TEST_EQUALS(model.ApplyCamera(6u, appliedCamera), false, TEST_LOCATION); // Cannot apply over the index.
1162 int UtcDaliModelMultiplePrimitives(void)
1164 ToolkitTestApplication application;
1166 Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_MULTIPLE_PRIMITIVE_FILE_NAME);
1167 model.SetProperty(Dali::Actor::Property::SIZE, Vector2(50, 50));
1168 application.GetScene().Add(model);
1170 gResourceReadyCalled = false;
1171 model.ResourceReadySignal().Connect(&OnResourceReady);
1172 DALI_TEST_EQUALS(gResourceReadyCalled, false, TEST_LOCATION);
1174 application.SendNotification();
1175 application.Render();
1177 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1178 application.SendNotification();
1179 application.Render();
1181 Actor actor = model.FindChildByName("rootNode");
1183 DALI_TEST_EQUALS(0, actor.GetChildCount(), TEST_LOCATION);
1184 DALI_TEST_EQUALS(2, actor.GetRendererCount(), TEST_LOCATION);
1189 int UtcDaliModelColorMode(void)
1191 ToolkitTestApplication application;
1193 Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
1194 model.SetProperty(Dali::Actor::Property::SIZE, Vector2(50, 50));
1195 model.SetProperty(Dali::Actor::Property::COLOR, Color::RED);
1196 application.GetScene().Add(model);
1198 gResourceReadyCalled = false;
1199 model.ResourceReadySignal().Connect(&OnResourceReady);
1200 DALI_TEST_EQUALS(gResourceReadyCalled, false, TEST_LOCATION);
1202 application.SendNotification();
1203 application.Render();
1205 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1206 application.SendNotification();
1207 application.Render();
1209 Actor actor = model.FindChildByName("AnimatedCube");
1210 Vector4 childColor = actor[Dali::Actor::Property::COLOR];
1211 Vector4 childWorldColor = actor[Dali::Actor::Property::WORLD_COLOR];
1213 DALI_TEST_EQUALS(childColor, Color::WHITE, TEST_LOCATION);
1214 DALI_TEST_EQUALS(childWorldColor, Color::RED, TEST_LOCATION);
1219 int UtcDaliModelResourceReady(void)
1221 ToolkitTestApplication application;
1223 gOnRelayoutCallBackCalled = false;
1224 gResourceReadyCalled = false;
1225 Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_ANIMATION_TEST_FILE_NAME);
1226 model.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
1227 model.OnRelayoutSignal().Connect(OnRelayoutCallback);
1228 model.ResourceReadySignal().Connect(OnResourceReady);
1229 DALI_TEST_EQUALS(model.IsResourceReady(), false, TEST_LOCATION);
1232 DALI_TEST_CHECK(!gOnRelayoutCallBackCalled);
1233 DALI_TEST_CHECK(!gResourceReadyCalled);
1235 application.GetScene().Add(model);
1237 application.SendNotification();
1238 application.Render();
1240 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1241 application.SendNotification();
1242 application.Render();
1244 DALI_TEST_EQUALS(gOnRelayoutCallBackCalled, false, TEST_LOCATION);
1245 DALI_TEST_EQUALS(model.IsResourceReady(), true, TEST_LOCATION);
1246 DALI_TEST_EQUALS(gResourceReadyCalled, true, TEST_LOCATION);
1251 int UtcDaliModelResourceCacheCheck(void)
1253 ToolkitTestApplication application;
1255 // Load three instances of the same model and add them to the scene
1256 Scene3D::Model model1 = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
1257 Scene3D::Model model2 = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
1258 Scene3D::Model model3 = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
1260 application.GetScene().Add(model1);
1261 application.GetScene().Add(model2);
1262 application.GetScene().Add(model3);
1264 gResourceReadyCalled = false;
1265 model1.ResourceReadySignal().Connect(&OnResourceReady);
1266 model2.ResourceReadySignal().Connect(&OnResourceReady);
1267 model3.ResourceReadySignal().Connect(&OnResourceReady);
1268 DALI_TEST_EQUALS(gResourceReadyCalled, false, TEST_LOCATION);
1270 application.SendNotification();
1271 application.Render();
1273 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(3), true, TEST_LOCATION);
1274 application.SendNotification();
1275 application.Render();
1277 // Check that the loading has finished for all the three instances
1278 DALI_TEST_EQUALS(gResourceReadyCalled, true, TEST_LOCATION);
1280 Actor meshActor1 = model1.FindChildByName("AnimatedCube");
1281 Actor meshActor2 = model2.FindChildByName("AnimatedCube");
1282 Actor meshActor3 = model3.FindChildByName("AnimatedCube");
1283 DALI_TEST_CHECK(meshActor1);
1284 DALI_TEST_CHECK(meshActor2);
1285 DALI_TEST_CHECK(meshActor3);
1287 Renderer renderer1 = meshActor1.GetRendererAt(0u);
1288 Renderer renderer2 = meshActor2.GetRendererAt(0u);
1289 Renderer renderer3 = meshActor3.GetRendererAt(0u);
1290 DALI_TEST_CHECK(renderer1);
1291 DALI_TEST_CHECK(renderer2);
1292 DALI_TEST_CHECK(renderer3);
1294 // Check that all the three instances use the shared textures and geometries from the cache
1295 // but have their own shader objects
1296 DALI_TEST_EQUALS(renderer1.GetTextures(), renderer2.GetTextures(), TEST_LOCATION);
1297 DALI_TEST_EQUALS(renderer1.GetTextures(), renderer3.GetTextures(), TEST_LOCATION);
1298 DALI_TEST_EQUALS(renderer1.GetGeometry(), renderer2.GetGeometry(), TEST_LOCATION);
1299 DALI_TEST_EQUALS(renderer1.GetGeometry(), renderer3.GetGeometry(), TEST_LOCATION);
1300 DALI_TEST_NOT_EQUALS(renderer1.GetShader(), renderer2.GetShader(), 0.0f, TEST_LOCATION);
1301 DALI_TEST_NOT_EQUALS(renderer1.GetShader(), renderer3.GetShader(), 0.0f, TEST_LOCATION);
1302 DALI_TEST_NOT_EQUALS(renderer2.GetShader(), renderer3.GetShader(), 0.0f, TEST_LOCATION);
1308 // Check that all the other two instances still use the shared textures and geometries from the cache
1309 // but have their own shader objects
1310 DALI_TEST_EQUALS(renderer2.GetTextures(), renderer3.GetTextures(), TEST_LOCATION);
1311 DALI_TEST_EQUALS(renderer2.GetGeometry(), renderer3.GetGeometry(), TEST_LOCATION);
1312 DALI_TEST_NOT_EQUALS(renderer2.GetShader(), renderer3.GetShader(), 0.0f, TEST_LOCATION);
1314 // Set new IBL textures for model2, and this should apply to model2 instance only
1315 gResourceReadyCalled = false;
1316 DALI_TEST_EQUALS(gResourceReadyCalled, false, TEST_LOCATION);
1317 model2.SetImageBasedLightSource(TEST_DIFFUSE_TEXTURE, TEST_SPECULAR_TEXTURE);
1319 application.SendNotification();
1320 application.Render();
1322 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1323 application.SendNotification();
1324 application.Render();
1326 // Check that the new IBL textures are loaded for model2
1327 DALI_TEST_EQUALS(gResourceReadyCalled, true, TEST_LOCATION);
1329 // Check that the two instances still use the shared geometries from the cache
1330 // but now have their own shader objects and different texture set
1331 DALI_TEST_NOT_EQUALS(renderer2.GetTextures(), renderer3.GetTextures(), 0.0f, TEST_LOCATION);
1332 DALI_TEST_EQUALS(renderer2.GetGeometry(), renderer3.GetGeometry(), TEST_LOCATION);
1333 DALI_TEST_NOT_EQUALS(renderer2.GetShader(), renderer3.GetShader(), 0.0f, TEST_LOCATION);
1335 // Check that the two instances now have their own diffuse texture and specular texture,
1336 // but all the other textures are still the same
1337 TextureSet textureSet2 = renderer2.GetTextures();
1338 TextureSet textureSet3 = renderer3.GetTextures();
1339 DALI_TEST_EQUALS(textureSet2.GetTextureCount(), 9u, TEST_LOCATION);
1340 DALI_TEST_EQUALS(textureSet3.GetTextureCount(), 9u, TEST_LOCATION);
1342 for (uint32_t i = 0; i < 7u; i++)
1344 DALI_TEST_EQUALS(textureSet2.GetTexture(i), textureSet3.GetTexture(i), TEST_LOCATION);
1347 DALI_TEST_NOT_EQUALS(textureSet2.GetTexture(7u), textureSet3.GetTexture(7u), 0.0f, TEST_LOCATION);
1348 DALI_TEST_NOT_EQUALS(textureSet2.GetTexture(8u), textureSet3.GetTexture(8u), 0.0f, TEST_LOCATION);