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 const char* TEST_DLI_EXERCISE_FILE_NAME = TEST_RESOURCE_DIR "/exercise.dli";
60 * For the diffuse and specular cube map texture.
61 * These textures are based off version of Wave engine sample
62 * Take from https://github.com/WaveEngine/Samples
64 * Copyright (c) 2023 Wave Coorporation
66 * Permission is hereby granted, free of charge, to any person obtaining a copy
67 * of this software and associated documentation files (the "Software"), to
68 * deal in the Software without restriction, including without limitation the
69 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
70 * sell copies of the Software, and to permit persons to whom the Software is
71 * furnished to do so, subject to the following conditions:
73 * The above copyright notice and this permission notice shall be included in
74 * all copies or substantial portions of the Software.
76 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
77 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
78 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
79 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
80 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
81 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
84 const char* TEST_DIFFUSE_TEXTURE = TEST_RESOURCE_DIR "/forest_irradiance.ktx";
85 const char* TEST_SPECULAR_TEXTURE = TEST_RESOURCE_DIR "/forest_radiance.ktx";
87 bool gTouchCallBackCalled = false;
88 bool TestTouchCallback(Actor, const TouchEvent&)
90 gTouchCallBackCalled = true;
94 bool gFocusChangedCallBackCalled = false;
95 void TestFocusChangedCallback(Actor, Actor)
97 gFocusChangedCallBackCalled = true;
101 static bool gOnRelayoutCallBackCalled = false;
102 void OnRelayoutCallback(Actor actor)
104 gOnRelayoutCallBackCalled = true;
107 static bool gResourceReadyCalled = false;
108 void OnResourceReady(Control control)
110 gResourceReadyCalled = true;
115 // Negative test case for a method
116 int UtcDaliModelUninitialized(void)
118 ToolkitTestApplication application;
119 tet_infoline(" UtcDaliModelUninitialized");
121 Scene3D::Model model;
125 // New() must be called to create a Model or it wont be valid.
126 Actor a = Actor::New();
128 DALI_TEST_CHECK(false);
130 catch(Dali::DaliException& e)
132 // Tests that a negative test of an assertion succeeds
133 DALI_TEST_PRINT_ASSERT(e);
134 DALI_TEST_CHECK(!model);
139 // Positive test case for a method
140 int UtcDaliModelNew(void)
142 ToolkitTestApplication application;
143 tet_infoline(" UtcDaliModelNew");
145 Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
146 DALI_TEST_CHECK(model);
150 // Positive test case for a method
151 int UtcDaliModelDownCast(void)
153 ToolkitTestApplication application;
154 tet_infoline(" UtcDaliModelDownCast");
156 Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
157 BaseHandle handle(model);
159 Scene3D::Model model2 = Scene3D::Model::DownCast(handle);
160 DALI_TEST_CHECK(model);
161 DALI_TEST_CHECK(model2);
162 DALI_TEST_CHECK(model2 == model);
166 int UtcDaliModelTypeRegistry(void)
168 ToolkitTestApplication application;
170 TypeRegistry typeRegistry = TypeRegistry::Get();
171 DALI_TEST_CHECK(typeRegistry);
173 TypeInfo typeInfo = typeRegistry.GetTypeInfo("Model");
174 DALI_TEST_CHECK(typeInfo);
176 BaseHandle handle = typeInfo.CreateInstance();
177 DALI_TEST_CHECK(handle);
179 Scene3D::Model model = Scene3D::Model::DownCast(handle);
180 DALI_TEST_CHECK(model);
185 // Positive test case for a method
186 int UtcDaliModelAddRemove(void)
188 ToolkitTestApplication application;
189 tet_infoline(" UtcDaliModelAddRemove");
191 Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
192 DALI_TEST_CHECK(model);
194 Actor actor = Actor::New();
195 DALI_TEST_CHECK(!actor.GetProperty<bool>(Actor::Property::CONNECTED_TO_SCENE));
197 model.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
198 model.SetProperty(Actor::Property::SIZE, application.GetScene().GetSize());
200 application.GetScene().Add(model);
202 DALI_TEST_CHECK(actor.GetProperty<bool>(Actor::Property::CONNECTED_TO_SCENE));
206 DALI_TEST_CHECK(!actor.GetProperty<bool>(Actor::Property::CONNECTED_TO_SCENE));
210 int UtcDaliModelCopyAndAssignment(void)
212 ToolkitTestApplication application;
214 Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
215 DALI_TEST_CHECK(model);
217 Scene3D::Model copy(model);
218 DALI_TEST_CHECK(model == copy);
220 Scene3D::Model assign;
221 DALI_TEST_CHECK(!assign);
224 DALI_TEST_CHECK(assign == model);
229 int UtcDaliModelMoveConstructor(void)
231 ToolkitTestApplication application;
233 Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
234 DALI_TEST_EQUALS(1, model.GetBaseObject().ReferenceCount(), TEST_LOCATION);
235 model.SetProperty(Actor::Property::SENSITIVE, false);
236 DALI_TEST_CHECK(false == model.GetProperty<bool>(Actor::Property::SENSITIVE));
238 Scene3D::Model moved = std::move(model);
239 DALI_TEST_CHECK(moved);
240 DALI_TEST_EQUALS(1, moved.GetBaseObject().ReferenceCount(), TEST_LOCATION);
241 DALI_TEST_CHECK(false == moved.GetProperty<bool>(Actor::Property::SENSITIVE));
242 DALI_TEST_CHECK(!model);
247 int UtcDaliModelMoveAssignment(void)
249 ToolkitTestApplication application;
251 Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
252 DALI_TEST_EQUALS(1, model.GetBaseObject().ReferenceCount(), TEST_LOCATION);
253 model.SetProperty(Actor::Property::SENSITIVE, false);
254 DALI_TEST_CHECK(false == model.GetProperty<bool>(Actor::Property::SENSITIVE));
256 Scene3D::Model moved;
257 moved = std::move(model);
258 DALI_TEST_CHECK(moved);
259 DALI_TEST_EQUALS(1, moved.GetBaseObject().ReferenceCount(), TEST_LOCATION);
260 DALI_TEST_CHECK(false == moved.GetProperty<bool>(Actor::Property::SENSITIVE));
261 DALI_TEST_CHECK(!model);
266 int UtcDaliModelOnScene01(void)
268 ToolkitTestApplication application;
270 Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
271 application.GetScene().Add(model);
273 gResourceReadyCalled = false;
274 model.ResourceReadySignal().Connect(&OnResourceReady);
275 DALI_TEST_EQUALS(gResourceReadyCalled, false, TEST_LOCATION);
277 application.SendNotification();
278 application.Render();
280 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
281 application.SendNotification();
282 application.Render();
284 DALI_TEST_EQUALS(gResourceReadyCalled, true, TEST_LOCATION);
286 uint32_t modelCount = model.GetModelRoot().GetChildCount();
287 DALI_TEST_EQUALS(1, modelCount, TEST_LOCATION);
291 int UtcDaliModelOnScene02(void)
293 ToolkitTestApplication application;
295 Scene3D::Model model = Scene3D::Model::New(TEST_DLI_FILE_NAME);
296 application.GetScene().Add(model);
298 gResourceReadyCalled = false;
299 model.ResourceReadySignal().Connect(&OnResourceReady);
300 DALI_TEST_EQUALS(gResourceReadyCalled, false, TEST_LOCATION);
302 application.SendNotification();
303 application.Render();
305 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
306 application.SendNotification();
307 application.Render();
309 DALI_TEST_EQUALS(gResourceReadyCalled, true, TEST_LOCATION);
311 uint32_t modelCount = model.GetModelRoot().GetChildCount();
312 DALI_TEST_EQUALS(1, modelCount, TEST_LOCATION);
314 Actor rootActor = model.GetModelRoot();
315 Vector3 rootSize = rootActor.GetProperty<Vector3>(Dali::Actor::Property::SIZE);
316 DALI_TEST_EQUALS(Vector3(2, 2, 1), rootSize, TEST_LOCATION);
321 int UtcDaliModelOnSizeSet(void)
323 ToolkitTestApplication application;
325 Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
327 application.GetScene().Add(model);
329 application.SendNotification();
330 application.Render();
332 Vector2 size(200.0f, 300.0f);
333 model.SetProperty(Actor::Property::SIZE, size);
335 application.SendNotification();
336 application.Render();
338 DALI_TEST_EQUALS(model.GetCurrentProperty<Vector2>(Actor::Property::SIZE), size, TEST_LOCATION);
343 int UtcDaliModelGetNaturalSize(void)
345 ToolkitTestApplication application;
347 Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
349 Vector3 naturalSize = model.GetNaturalSize();
350 DALI_TEST_EQUALS(Vector3::ZERO, naturalSize, TEST_LOCATION);
352 application.GetScene().Add(model);
354 gResourceReadyCalled = false;
355 model.ResourceReadySignal().Connect(&OnResourceReady);
356 DALI_TEST_EQUALS(gResourceReadyCalled, false, TEST_LOCATION);
358 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
359 application.SendNotification();
361 DALI_TEST_EQUALS(gResourceReadyCalled, true, TEST_LOCATION);
363 naturalSize = model.GetNaturalSize();
364 DALI_TEST_EQUALS(Vector3(2, 2, 2), naturalSize, TEST_LOCATION);
366 Actor root = model.GetModelRoot();
367 DALI_TEST_CHECK(root);
372 int UtcDaliModelSetImageBasedLightSource01(void)
374 ToolkitTestApplication application;
376 Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
377 application.GetScene().Add(model);
379 gResourceReadyCalled = false;
380 model.ResourceReadySignal().Connect(&OnResourceReady);
381 DALI_TEST_EQUALS(gResourceReadyCalled, false, TEST_LOCATION);
383 application.SendNotification();
384 application.Render();
386 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
387 application.SendNotification();
388 application.Render();
390 DALI_TEST_EQUALS(gResourceReadyCalled, true, TEST_LOCATION);
392 Actor meshActor = model.FindChildByName("AnimatedCube");
393 DALI_TEST_CHECK(meshActor);
395 Renderer renderer = meshActor.GetRendererAt(0u);
396 DALI_TEST_CHECK(renderer);
398 TextureSet textureSet = renderer.GetTextures();
399 DALI_TEST_EQUALS(textureSet.GetTextureCount(), 9u, TEST_LOCATION);
401 Texture diffuseTexture = textureSet.GetTexture(7u);
402 Texture specularTexture = textureSet.GetTexture(8u);
404 gResourceReadyCalled = false;
405 DALI_TEST_EQUALS(gResourceReadyCalled, false, TEST_LOCATION);
406 model.SetImageBasedLightSource(TEST_DIFFUSE_TEXTURE, TEST_SPECULAR_TEXTURE);
408 application.SendNotification();
409 application.Render();
411 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
412 application.SendNotification();
413 application.Render();
415 DALI_TEST_EQUALS(gResourceReadyCalled, true, TEST_LOCATION);
417 TextureSet newTextureSet = renderer.GetTextures();
418 Texture newDiffuseTexture = newTextureSet.GetTexture(7u);
419 Texture newSpecularTexture = newTextureSet.GetTexture(8u);
421 DALI_TEST_NOT_EQUALS(diffuseTexture, newDiffuseTexture, 0.0f, TEST_LOCATION);
422 DALI_TEST_NOT_EQUALS(specularTexture, newSpecularTexture, 0.0f, TEST_LOCATION);
429 int UtcDaliModelSetImageBasedLightSource02(void)
431 ToolkitTestApplication application;
433 Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
434 application.GetScene().Add(model);
436 gResourceReadyCalled = false;
437 model.ResourceReadySignal().Connect(&OnResourceReady);
438 DALI_TEST_EQUALS(gResourceReadyCalled, false, TEST_LOCATION);
440 application.SendNotification();
441 application.Render();
443 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
444 application.SendNotification();
445 application.Render();
447 DALI_TEST_EQUALS(gResourceReadyCalled, true, TEST_LOCATION);
449 Actor meshActor = model.FindChildByName("AnimatedCube");
450 DALI_TEST_CHECK(meshActor);
452 Renderer renderer = meshActor.GetRendererAt(0u);
453 DALI_TEST_CHECK(renderer);
455 TextureSet textureSet = renderer.GetTextures();
456 DALI_TEST_EQUALS(textureSet.GetTextureCount(), 9u, TEST_LOCATION);
458 Texture diffuseTexture = textureSet.GetTexture(7u);
459 Texture specularTexture = textureSet.GetTexture(8u);
461 // if url is empty, loading is not requested.
462 model.SetImageBasedLightSource("", "");
464 Texture newDiffuseTexture = textureSet.GetTexture(7u);
465 Texture newSpecularTexture = textureSet.GetTexture(8u);
467 DALI_TEST_EQUALS(diffuseTexture, newDiffuseTexture, TEST_LOCATION);
468 DALI_TEST_EQUALS(specularTexture, newSpecularTexture, TEST_LOCATION);
473 int UtcDaliModelSetImageBasedLightSource03(void)
475 ToolkitTestApplication application;
477 Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
478 application.GetScene().Add(model);
480 gResourceReadyCalled = false;
481 model.ResourceReadySignal().Connect(&OnResourceReady);
482 DALI_TEST_EQUALS(gResourceReadyCalled, false, TEST_LOCATION);
484 application.SendNotification();
485 application.Render();
487 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
488 application.SendNotification();
489 application.Render();
491 DALI_TEST_EQUALS(gResourceReadyCalled, true, TEST_LOCATION);
493 Actor meshActor = model.FindChildByName("AnimatedCube");
494 DALI_TEST_CHECK(meshActor);
496 Renderer renderer = meshActor.GetRendererAt(0u);
497 DALI_TEST_CHECK(renderer);
499 TextureSet textureSet = renderer.GetTextures();
500 DALI_TEST_EQUALS(textureSet.GetTextureCount(), 9u, TEST_LOCATION);
502 Texture diffuseTexture = textureSet.GetTexture(7u);
503 Texture specularTexture = textureSet.GetTexture(8u);
505 gResourceReadyCalled = false;
506 DALI_TEST_EQUALS(gResourceReadyCalled, false, TEST_LOCATION);
507 model.SetImageBasedLightSource("dummy.ktx", "dummy.ktx");
509 application.SendNotification();
510 application.Render();
512 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
513 application.SendNotification();
514 application.Render();
516 DALI_TEST_EQUALS(gResourceReadyCalled, true, TEST_LOCATION);
518 Texture newDiffuseTexture = textureSet.GetTexture(7u);
519 Texture newSpecularTexture = textureSet.GetTexture(8u);
521 DALI_TEST_EQUALS(diffuseTexture, newDiffuseTexture, TEST_LOCATION);
522 DALI_TEST_EQUALS(specularTexture, newSpecularTexture, TEST_LOCATION);
527 int UtcDaliModelSetImageBasedLightSource04(void)
529 ToolkitTestApplication application;
531 Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
532 model.SetImageBasedLightSource(TEST_DIFFUSE_TEXTURE, TEST_SPECULAR_TEXTURE);
533 application.GetScene().Add(model);
535 gResourceReadyCalled = false;
536 model.ResourceReadySignal().Connect(&OnResourceReady);
537 DALI_TEST_EQUALS(gResourceReadyCalled, false, TEST_LOCATION);
539 application.SendNotification();
540 application.Render();
542 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(3), true, TEST_LOCATION);
543 application.SendNotification();
544 application.Render();
546 DALI_TEST_EQUALS(gResourceReadyCalled, true, TEST_LOCATION);
550 int UtcDaliModelImageBasedFactor(void)
552 ToolkitTestApplication application;
554 Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
556 DALI_TEST_EQUALS(model.GetImageBasedLightScaleFactor(), 1.0f, TEST_LOCATION);
558 model.SetImageBasedLightScaleFactor(0.5f);
559 DALI_TEST_EQUALS(model.GetImageBasedLightScaleFactor(), 0.5f, TEST_LOCATION);
563 int UtcDaliModelChildrenSensitive01(void)
565 ToolkitTestApplication application;
567 Scene3D::Model view = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
568 view.SetProperty(Dali::Actor::Property::SIZE, Vector3(100, 100, 100));
569 view.SetProperty(Dali::Actor::Property::POSITION, Vector3(0, 0, 0));
570 view.SetProperty(Dali::Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER);
571 view.SetProperty(Dali::Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
573 // Get default vaule.
574 DALI_TEST_EQUALS(view.GetChildrenSensitive(), DEFAULT_MODEL_CHILDREN_SENSITIVE, TEST_LOCATION);
576 // Allow children actor's event before on scene.
577 view.SetChildrenSensitive(true);
578 DALI_TEST_EQUALS(view.GetChildrenSensitive(), true, TEST_LOCATION);
579 application.GetScene().Add(view);
581 gResourceReadyCalled = false;
582 view.ResourceReadySignal().Connect(&OnResourceReady);
583 DALI_TEST_EQUALS(gResourceReadyCalled, false, TEST_LOCATION);
585 application.SendNotification();
586 application.Render();
588 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
589 application.SendNotification();
590 application.Render();
592 DALI_TEST_EQUALS(gResourceReadyCalled, true, TEST_LOCATION);
594 Actor meshActor = view.FindChildByName("AnimatedCube");
595 DALI_TEST_CHECK(meshActor);
597 // connect hit-test signal
598 gTouchCallBackCalled = false;
599 meshActor.TouchedSignal().Connect(TestTouchCallback);
601 Vector2 sceneSize = application.GetScene().GetSize();
603 // Try to touch center of scene.
604 Dali::Integration::Point point;
605 point.SetState(PointState::DOWN);
606 point.SetScreenPosition(sceneSize * 0.5f);
607 Dali::Integration::TouchEvent event;
608 event.AddPoint(point);
610 // flush the queue and render once
611 application.SendNotification();
612 application.Render();
615 DALI_TEST_CHECK(!gTouchCallBackCalled);
616 application.ProcessEvent(event);
618 DALI_TEST_CHECK(gTouchCallBackCalled);
621 gTouchCallBackCalled = false;
623 // Block children actor's event
624 view.SetChildrenSensitive(false);
625 DALI_TEST_EQUALS(view.GetChildrenSensitive(), false, TEST_LOCATION);
627 // flush the queue and render once
628 application.SendNotification();
629 application.Render();
632 DALI_TEST_CHECK(!gTouchCallBackCalled);
633 application.ProcessEvent(event);
635 DALI_TEST_CHECK(!gTouchCallBackCalled);
638 gTouchCallBackCalled = false;
641 view.SetChildrenSensitive(true);
642 DALI_TEST_EQUALS(view.GetChildrenSensitive(), true, TEST_LOCATION);
644 // flush the queue and render once
645 application.SendNotification();
646 application.Render();
649 DALI_TEST_CHECK(!gTouchCallBackCalled);
650 application.ProcessEvent(event);
652 DALI_TEST_CHECK(gTouchCallBackCalled);
655 gTouchCallBackCalled = false;
660 int UtcDaliModelChildrenSensitive02(void)
662 ToolkitTestApplication application;
664 Scene3D::Model view = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
665 view.SetProperty(Dali::Actor::Property::SIZE, Vector3(100, 100, 100));
666 view.SetProperty(Dali::Actor::Property::POSITION, Vector3(0, 0, 0));
667 view.SetProperty(Dali::Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER);
668 view.SetProperty(Dali::Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
671 DALI_TEST_EQUALS(view.GetChildrenSensitive(), DEFAULT_MODEL_CHILDREN_SENSITIVE, TEST_LOCATION);
673 // Block children actor's event before on scene.
674 view.SetChildrenSensitive(false);
675 DALI_TEST_EQUALS(view.GetChildrenSensitive(), false, TEST_LOCATION);
676 application.GetScene().Add(view);
678 gResourceReadyCalled = false;
679 view.ResourceReadySignal().Connect(&OnResourceReady);
680 DALI_TEST_EQUALS(gResourceReadyCalled, false, TEST_LOCATION);
682 application.SendNotification();
683 application.Render();
685 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
686 application.SendNotification();
687 application.Render();
689 DALI_TEST_EQUALS(gResourceReadyCalled, true, TEST_LOCATION);
691 Actor meshActor = view.FindChildByName("AnimatedCube");
692 DALI_TEST_CHECK(meshActor);
694 // connect hit-test signal
695 gTouchCallBackCalled = false;
696 meshActor.TouchedSignal().Connect(TestTouchCallback);
698 Vector2 sceneSize = application.GetScene().GetSize();
700 // Try to touch center of scene.
701 Dali::Integration::Point point;
702 point.SetState(PointState::DOWN);
703 point.SetScreenPosition(sceneSize * 0.5f);
704 Dali::Integration::TouchEvent event;
705 event.AddPoint(point);
707 // flush the queue and render once
708 application.SendNotification();
709 application.Render();
712 DALI_TEST_CHECK(!gTouchCallBackCalled);
713 application.ProcessEvent(event);
715 DALI_TEST_CHECK(!gTouchCallBackCalled);
718 gTouchCallBackCalled = false;
721 view.SetChildrenSensitive(true);
722 DALI_TEST_EQUALS(view.GetChildrenSensitive(), true, TEST_LOCATION);
724 // flush the queue and render once
725 application.SendNotification();
726 application.Render();
729 DALI_TEST_CHECK(!gTouchCallBackCalled);
730 application.ProcessEvent(event);
732 DALI_TEST_CHECK(gTouchCallBackCalled);
735 gTouchCallBackCalled = false;
740 int UtcDaliModelChildrenFocusable01(void)
742 ToolkitTestApplication application;
744 Scene3D::Model view = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
745 view.SetProperty(Dali::Actor::Property::SIZE, Vector3(100, 100, 100));
746 view.SetProperty(Dali::Actor::Property::POSITION, Vector3(0, 0, 0));
747 view.SetProperty(Dali::Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER);
748 view.SetProperty(Dali::Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
750 // Get vaule. Default is false.
751 DALI_TEST_EQUALS(view.GetChildrenFocusable(), DEFAULT_MODEL_CHILDREN_FOCUSABLE, TEST_LOCATION);
753 // Allow children actor's focus before on scene.
754 view.SetChildrenFocusable(true);
755 DALI_TEST_EQUALS(view.GetChildrenFocusable(), true, TEST_LOCATION);
756 application.GetScene().Add(view);
758 gResourceReadyCalled = false;
759 view.ResourceReadySignal().Connect(&OnResourceReady);
760 DALI_TEST_EQUALS(gResourceReadyCalled, false, TEST_LOCATION);
762 application.SendNotification();
763 application.Render();
765 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
766 application.SendNotification();
767 application.Render();
769 DALI_TEST_EQUALS(gResourceReadyCalled, true, TEST_LOCATION);
771 Actor meshActor = view.FindChildByName("AnimatedCube");
772 DALI_TEST_CHECK(meshActor);
774 // Enable the default algorithm
775 KeyboardFocusManager manager = KeyboardFocusManager::Get();
776 DALI_TEST_CHECK(manager);
777 Dali::Toolkit::DevelKeyboardFocusManager::EnableDefaultAlgorithm(manager, true);
779 // connect focusable signal
780 gFocusChangedCallBackCalled = false;
781 meshActor.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true);
782 manager.FocusChangedSignal().Connect(TestFocusChangedCallback);
784 // Initialize with some left-positioned actor
785 Control focusStartActor = Control::New();
786 focusStartActor.SetProperty(Dali::Actor::Property::SIZE, Vector3(100, 100, 100));
787 focusStartActor.SetProperty(Dali::Actor::Property::POSITION, Vector3(-200, 0, 0));
788 focusStartActor.SetProperty(Dali::Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER);
789 focusStartActor.SetProperty(Dali::Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
790 focusStartActor.SetProperty(Dali::Actor::Property::KEYBOARD_FOCUSABLE, true);
791 application.GetScene().Add(focusStartActor);
794 manager.ClearFocus();
795 manager.SetCurrentFocusActor(focusStartActor);
796 gFocusChangedCallBackCalled = false;
798 // flush the queue and render once
799 application.SendNotification();
800 application.Render();
802 // Focusable view find success
803 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::RIGHT) == true);
804 DALI_TEST_CHECK(gFocusChangedCallBackCalled);
807 manager.ClearFocus();
808 manager.SetCurrentFocusActor(focusStartActor);
809 gFocusChangedCallBackCalled = false;
811 // Block children actor's focus
812 view.SetChildrenFocusable(false);
813 DALI_TEST_EQUALS(view.GetChildrenFocusable(), false, TEST_LOCATION);
815 // flush the queue and render once
816 application.SendNotification();
817 application.Render();
819 // Focusable view find failed
820 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::RIGHT) == false);
821 DALI_TEST_CHECK(!gFocusChangedCallBackCalled);
824 manager.ClearFocus();
825 manager.SetCurrentFocusActor(focusStartActor);
826 gFocusChangedCallBackCalled = false;
829 view.SetChildrenFocusable(true);
830 DALI_TEST_EQUALS(view.GetChildrenFocusable(), true, TEST_LOCATION);
832 // flush the queue and render once
833 application.SendNotification();
834 application.Render();
836 // Focusable view find success
837 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::RIGHT) == true);
838 DALI_TEST_CHECK(gFocusChangedCallBackCalled);
841 manager.ClearFocus();
842 manager.SetCurrentFocusActor(focusStartActor);
843 gFocusChangedCallBackCalled = false;
848 int UtcDaliModelModelChildrenFocusable02(void)
850 ToolkitTestApplication application;
852 Scene3D::Model view = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
853 view.SetProperty(Dali::Actor::Property::SIZE, Vector3(100, 100, 100));
854 view.SetProperty(Dali::Actor::Property::POSITION, Vector3(0, 0, 0));
855 view.SetProperty(Dali::Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER);
856 view.SetProperty(Dali::Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
858 // Get vaule. Default is true.
859 DALI_TEST_EQUALS(view.GetChildrenFocusable(), DEFAULT_MODEL_CHILDREN_FOCUSABLE, TEST_LOCATION);
861 // Block children actor's focus before on scene.
862 view.SetChildrenFocusable(false);
863 DALI_TEST_EQUALS(view.GetChildrenFocusable(), false, TEST_LOCATION);
864 application.GetScene().Add(view);
866 gResourceReadyCalled = false;
867 view.ResourceReadySignal().Connect(&OnResourceReady);
868 DALI_TEST_EQUALS(gResourceReadyCalled, false, TEST_LOCATION);
870 application.SendNotification();
871 application.Render();
873 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
874 application.SendNotification();
875 application.Render();
877 DALI_TEST_EQUALS(gResourceReadyCalled, true, TEST_LOCATION);
879 Actor meshActor = view.FindChildByName("AnimatedCube");
880 DALI_TEST_CHECK(meshActor);
882 // Enable the default algorithm
883 KeyboardFocusManager manager = KeyboardFocusManager::Get();
884 DALI_TEST_CHECK(manager);
885 Dali::Toolkit::DevelKeyboardFocusManager::EnableDefaultAlgorithm(manager, true);
887 // connect focusable signal
888 gFocusChangedCallBackCalled = false;
889 meshActor.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true);
890 manager.FocusChangedSignal().Connect(TestFocusChangedCallback);
892 // Initialize with some left-positioned actor
893 Control focusStartActor = Control::New();
894 focusStartActor.SetProperty(Dali::Actor::Property::SIZE, Vector3(100, 100, 100));
895 focusStartActor.SetProperty(Dali::Actor::Property::POSITION, Vector3(-200, 0, 0));
896 focusStartActor.SetProperty(Dali::Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER);
897 focusStartActor.SetProperty(Dali::Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
898 focusStartActor.SetProperty(Dali::Actor::Property::KEYBOARD_FOCUSABLE, true);
899 application.GetScene().Add(focusStartActor);
902 manager.ClearFocus();
903 manager.SetCurrentFocusActor(focusStartActor);
904 gFocusChangedCallBackCalled = false;
906 // flush the queue and render once
907 application.SendNotification();
908 application.Render();
910 // Focusable view find failed
911 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::RIGHT) == false);
912 DALI_TEST_CHECK(!gFocusChangedCallBackCalled);
915 manager.ClearFocus();
916 manager.SetCurrentFocusActor(focusStartActor);
917 gFocusChangedCallBackCalled = false;
920 view.SetChildrenFocusable(true);
921 DALI_TEST_EQUALS(view.GetChildrenFocusable(), true, TEST_LOCATION);
923 // flush the queue and render once
924 application.SendNotification();
925 application.Render();
927 // Focusable view find success
928 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::RIGHT) == true);
929 DALI_TEST_CHECK(gFocusChangedCallBackCalled);
932 manager.ClearFocus();
933 manager.SetCurrentFocusActor(focusStartActor);
934 gFocusChangedCallBackCalled = false;
939 int UtcDaliModelAnimation01(void)
941 ToolkitTestApplication application;
943 Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
944 model.SetProperty(Dali::Actor::Property::SIZE, Vector2(50, 50));
945 application.GetScene().Add(model);
947 gResourceReadyCalled = false;
948 model.ResourceReadySignal().Connect(&OnResourceReady);
949 DALI_TEST_EQUALS(gResourceReadyCalled, false, TEST_LOCATION);
951 application.SendNotification();
952 application.Render();
954 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
955 application.SendNotification();
956 application.Render();
958 DALI_TEST_EQUALS(gResourceReadyCalled, true, TEST_LOCATION);
960 uint32_t animationCount = model.GetAnimationCount();
961 DALI_TEST_EQUALS(1, animationCount, TEST_LOCATION);
963 Animation animationByIndex = model.GetAnimation(0u);
964 DALI_TEST_CHECK(animationByIndex);
966 Animation animationByName = model.GetAnimation("animation_AnimatedCube");
967 DALI_TEST_CHECK(animationByName);
968 DALI_TEST_EQUALS(animationByIndex, animationByName, TEST_LOCATION);
973 int UtcDaliModelAnimation02(void)
975 ToolkitTestApplication application;
977 Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_ANIMATION_TEST_FILE_NAME);
978 model.SetProperty(Dali::Actor::Property::SIZE, Vector2(50, 50));
979 application.GetScene().Add(model);
981 gResourceReadyCalled = false;
982 model.ResourceReadySignal().Connect(&OnResourceReady);
983 DALI_TEST_EQUALS(gResourceReadyCalled, false, TEST_LOCATION);
985 application.SendNotification();
986 application.Render();
988 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
989 application.SendNotification();
990 application.Render();
992 uint32_t animationCount = model.GetAnimationCount();
993 DALI_TEST_EQUALS(9, animationCount, TEST_LOCATION);
995 Animation animation1 = model.GetAnimation("Step Scale");
996 DALI_TEST_CHECK(animation1);
997 DALI_TEST_EQUALS(1.66667f, animation1.GetDuration(), 0.001f, TEST_LOCATION);
999 Animation animation2 = model.GetAnimation("CubicSpline Scale");
1000 DALI_TEST_CHECK(animation2);
1001 DALI_TEST_EQUALS(1.66667f, animation2.GetDuration(), 0.001f, TEST_LOCATION);
1003 DALI_TEST_NOT_EQUALS(animation1, animation2, 0.0f, TEST_LOCATION);
1008 int UtcDaliModelAnimation03(void)
1010 ToolkitTestApplication application;
1012 Scene3D::Model model = Scene3D::Model::New(TEST_DLI_EXERCISE_FILE_NAME);
1013 model.SetProperty(Dali::Actor::Property::SIZE, Vector2(50, 50));
1014 application.GetScene().Add(model);
1016 gResourceReadyCalled = false;
1017 model.ResourceReadySignal().Connect(&OnResourceReady);
1018 DALI_TEST_EQUALS(gResourceReadyCalled, false, TEST_LOCATION);
1020 application.SendNotification();
1021 application.Render();
1023 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1024 application.SendNotification();
1025 application.Render();
1027 DALI_TEST_EQUALS(gResourceReadyCalled, true, TEST_LOCATION);
1029 uint32_t animationCount = model.GetAnimationCount();
1030 DALI_TEST_EQUALS(18, animationCount, TEST_LOCATION);
1032 Animation animationByIndex = model.GetAnimation(0u);
1033 DALI_TEST_CHECK(animationByIndex);
1035 Animation animationByName = model.GetAnimation("idleClip");
1036 DALI_TEST_CHECK(animationByName);
1037 DALI_TEST_EQUALS(animationByIndex, animationByName, TEST_LOCATION);
1042 int UtcDaliModelCameraGenerate01(void)
1044 ToolkitTestApplication application;
1046 Scene3D::Model model = Scene3D::Model::New(TEST_DLI_EXERCISE_FILE_NAME);
1047 model.SetProperty(Dali::Actor::Property::SIZE, Vector2(50, 50));
1048 application.GetScene().Add(model);
1050 gResourceReadyCalled = false;
1051 model.ResourceReadySignal().Connect(&OnResourceReady);
1052 DALI_TEST_EQUALS(gResourceReadyCalled, false, TEST_LOCATION);
1054 application.SendNotification();
1055 application.Render();
1057 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1058 application.SendNotification();
1059 application.Render();
1061 DALI_TEST_EQUALS(gResourceReadyCalled, true, TEST_LOCATION);
1063 uint32_t cameraCount = model.GetCameraCount();
1064 DALI_TEST_EQUALS(1, cameraCount, TEST_LOCATION);
1066 CameraActor generatedCamera = model.GenerateCamera(0u);
1067 DALI_TEST_CHECK(generatedCamera);
1069 generatedCamera = model.GenerateCamera(1u); // Fail to generate camera
1070 DALI_TEST_CHECK(!generatedCamera);
1075 int UtcDaliModelCameraGenerate02(void)
1077 ToolkitTestApplication application;
1079 Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
1080 model.SetProperty(Dali::Actor::Property::SIZE, Vector2(50, 50));
1081 application.GetScene().Add(model);
1083 gResourceReadyCalled = false;
1084 model.ResourceReadySignal().Connect(&OnResourceReady);
1085 DALI_TEST_EQUALS(gResourceReadyCalled, false, TEST_LOCATION);
1087 application.SendNotification();
1088 application.Render();
1090 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1091 application.SendNotification();
1092 application.Render();
1094 DALI_TEST_EQUALS(gResourceReadyCalled, true, TEST_LOCATION);
1096 uint32_t cameraCount = model.GetCameraCount();
1097 DALI_TEST_EQUALS(6, cameraCount, TEST_LOCATION);
1099 CameraActor generatedCamera0 = model.GenerateCamera(0u);
1100 DALI_TEST_CHECK(generatedCamera0);
1101 CameraActor generatedCamera1 = model.GenerateCamera(1u);
1102 DALI_TEST_CHECK(generatedCamera1);
1103 CameraActor generatedCamera2 = model.GenerateCamera(2u);
1104 DALI_TEST_CHECK(generatedCamera2);
1105 CameraActor generatedCamera3 = model.GenerateCamera(3u); // Infinity far camera
1106 DALI_TEST_CHECK(generatedCamera3);
1107 CameraActor generatedCamera4 = model.GenerateCamera(4u); // Broken camera 1
1108 DALI_TEST_CHECK(!generatedCamera4);
1109 CameraActor generatedCamera5 = model.GenerateCamera(5u); // Broken camera 2
1110 DALI_TEST_CHECK(!generatedCamera5);
1111 CameraActor generatedCamera6 = model.GenerateCamera(6u); // Out of bound
1112 DALI_TEST_CHECK(!generatedCamera6);
1114 CameraActor appliedCamera;
1115 DALI_TEST_EQUALS(model.ApplyCamera(0u, appliedCamera), false, TEST_LOCATION); // Cannot apply into empty camera.
1117 auto CompareCameraProperties = [](CameraActor lhs, CameraActor rhs, const char* location) {
1118 DALI_TEST_EQUALS(lhs.GetProperty<int>(Dali::CameraActor::Property::PROJECTION_MODE), rhs.GetProperty<int>(Dali::CameraActor::Property::PROJECTION_MODE), TEST_LOCATION);
1119 DALI_TEST_EQUALS(lhs.GetProperty<float>(Dali::CameraActor::Property::NEAR_PLANE_DISTANCE), rhs.GetProperty<float>(Dali::CameraActor::Property::NEAR_PLANE_DISTANCE), TEST_LOCATION);
1121 if(lhs.GetProperty<int>(Dali::CameraActor::Property::PROJECTION_MODE) == static_cast<int>(Dali::Camera::ProjectionMode::PERSPECTIVE_PROJECTION))
1123 DALI_TEST_EQUALS(lhs.GetProperty<float>(Dali::CameraActor::Property::FIELD_OF_VIEW), rhs.GetProperty<float>(Dali::CameraActor::Property::FIELD_OF_VIEW), TEST_LOCATION);
1124 // TODO : Open this test when infinity far projection implement.
1125 //DALI_TEST_EQUALS(lhs.GetProperty<float>(Dali::CameraActor::Property::FAR_PLANE_DISTANCE), rhs.GetProperty<float>(Dali::CameraActor::Property::FAR_PLANE_DISTANCE), TEST_LOCATION);
1129 DALI_TEST_EQUALS(lhs.GetProperty<float>(Dali::DevelCameraActor::Property::ORTHOGRAPHIC_SIZE), rhs.GetProperty<float>(Dali::DevelCameraActor::Property::ORTHOGRAPHIC_SIZE), TEST_LOCATION);
1130 DALI_TEST_EQUALS(lhs.GetProperty<float>(Dali::CameraActor::Property::FAR_PLANE_DISTANCE), rhs.GetProperty<float>(Dali::CameraActor::Property::FAR_PLANE_DISTANCE), TEST_LOCATION);
1134 appliedCamera = CameraActor::New();
1135 DALI_TEST_EQUALS(model.ApplyCamera(0u, appliedCamera), true, TEST_LOCATION);
1136 CompareCameraProperties(generatedCamera0, appliedCamera, TEST_LOCATION);
1137 DALI_TEST_EQUALS(model.ApplyCamera(1u, appliedCamera), true, TEST_LOCATION);
1138 CompareCameraProperties(generatedCamera1, appliedCamera, TEST_LOCATION);
1139 DALI_TEST_EQUALS(model.ApplyCamera(2u, appliedCamera), true, TEST_LOCATION);
1140 CompareCameraProperties(generatedCamera2, appliedCamera, TEST_LOCATION);
1141 DALI_TEST_EQUALS(model.ApplyCamera(3u, appliedCamera), true, TEST_LOCATION);
1142 CompareCameraProperties(generatedCamera3, appliedCamera, TEST_LOCATION);
1143 DALI_TEST_EQUALS(model.ApplyCamera(4u, appliedCamera), false, TEST_LOCATION); // Broken camera 1
1144 DALI_TEST_EQUALS(model.ApplyCamera(5u, appliedCamera), false, TEST_LOCATION); // Broken camera 2
1145 DALI_TEST_EQUALS(model.ApplyCamera(6u, appliedCamera), false, TEST_LOCATION); // Cannot apply over the index.
1150 int UtcDaliModelMultiplePrimitives(void)
1152 ToolkitTestApplication application;
1154 Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_MULTIPLE_PRIMITIVE_FILE_NAME);
1155 model.SetProperty(Dali::Actor::Property::SIZE, Vector2(50, 50));
1156 application.GetScene().Add(model);
1158 gResourceReadyCalled = false;
1159 model.ResourceReadySignal().Connect(&OnResourceReady);
1160 DALI_TEST_EQUALS(gResourceReadyCalled, false, TEST_LOCATION);
1162 application.SendNotification();
1163 application.Render();
1165 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1166 application.SendNotification();
1167 application.Render();
1169 Actor actor = model.FindChildByName("rootNode");
1171 DALI_TEST_EQUALS(0, actor.GetChildCount(), TEST_LOCATION);
1172 DALI_TEST_EQUALS(2, actor.GetRendererCount(), TEST_LOCATION);
1177 int UtcDaliModelColorMode(void)
1179 ToolkitTestApplication application;
1181 Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
1182 model.SetProperty(Dali::Actor::Property::SIZE, Vector2(50, 50));
1183 model.SetProperty(Dali::Actor::Property::COLOR, Color::RED);
1184 application.GetScene().Add(model);
1186 gResourceReadyCalled = false;
1187 model.ResourceReadySignal().Connect(&OnResourceReady);
1188 DALI_TEST_EQUALS(gResourceReadyCalled, false, TEST_LOCATION);
1190 application.SendNotification();
1191 application.Render();
1193 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1194 application.SendNotification();
1195 application.Render();
1197 Actor actor = model.FindChildByName("AnimatedCube");
1198 Vector4 childColor = actor[Dali::Actor::Property::COLOR];
1199 Vector4 childWorldColor = actor[Dali::Actor::Property::WORLD_COLOR];
1201 DALI_TEST_EQUALS(childColor, Color::WHITE, TEST_LOCATION);
1202 DALI_TEST_EQUALS(childWorldColor, Color::RED, TEST_LOCATION);
1207 int UtcDaliModelResourceReady(void)
1209 ToolkitTestApplication application;
1211 gOnRelayoutCallBackCalled = false;
1212 gResourceReadyCalled = false;
1213 Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_ANIMATION_TEST_FILE_NAME);
1214 model.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
1215 model.OnRelayoutSignal().Connect(OnRelayoutCallback);
1216 model.ResourceReadySignal().Connect(OnResourceReady);
1217 DALI_TEST_EQUALS(model.IsResourceReady(), false, TEST_LOCATION);
1220 DALI_TEST_CHECK(!gOnRelayoutCallBackCalled);
1221 DALI_TEST_CHECK(!gResourceReadyCalled);
1223 application.GetScene().Add(model);
1225 application.SendNotification();
1226 application.Render();
1228 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1229 application.SendNotification();
1230 application.Render();
1232 DALI_TEST_EQUALS(gOnRelayoutCallBackCalled, false, TEST_LOCATION);
1233 DALI_TEST_EQUALS(model.IsResourceReady(), true, TEST_LOCATION);
1234 DALI_TEST_EQUALS(gResourceReadyCalled, true, TEST_LOCATION);
1239 int UtcDaliModelResourceCacheCheck(void)
1241 ToolkitTestApplication application;
1243 // Load three instances of the same model and add them to the scene
1244 Scene3D::Model model1 = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
1245 Scene3D::Model model2 = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
1246 Scene3D::Model model3 = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
1248 application.GetScene().Add(model1);
1249 application.GetScene().Add(model2);
1250 application.GetScene().Add(model3);
1252 gResourceReadyCalled = false;
1253 model1.ResourceReadySignal().Connect(&OnResourceReady);
1254 model2.ResourceReadySignal().Connect(&OnResourceReady);
1255 model3.ResourceReadySignal().Connect(&OnResourceReady);
1256 DALI_TEST_EQUALS(gResourceReadyCalled, false, TEST_LOCATION);
1258 application.SendNotification();
1259 application.Render();
1261 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(3), true, TEST_LOCATION);
1262 application.SendNotification();
1263 application.Render();
1265 // Check that the loading has finished for all the three instances
1266 DALI_TEST_EQUALS(gResourceReadyCalled, true, TEST_LOCATION);
1268 Actor meshActor1 = model1.FindChildByName("AnimatedCube");
1269 Actor meshActor2 = model2.FindChildByName("AnimatedCube");
1270 Actor meshActor3 = model3.FindChildByName("AnimatedCube");
1271 DALI_TEST_CHECK(meshActor1);
1272 DALI_TEST_CHECK(meshActor2);
1273 DALI_TEST_CHECK(meshActor3);
1275 Renderer renderer1 = meshActor1.GetRendererAt(0u);
1276 Renderer renderer2 = meshActor2.GetRendererAt(0u);
1277 Renderer renderer3 = meshActor3.GetRendererAt(0u);
1278 DALI_TEST_CHECK(renderer1);
1279 DALI_TEST_CHECK(renderer2);
1280 DALI_TEST_CHECK(renderer3);
1282 // Check that all the three instances use the shared textures and geometries from the cache
1283 // but have their own shader objects
1284 DALI_TEST_EQUALS(renderer1.GetTextures(), renderer2.GetTextures(), TEST_LOCATION);
1285 DALI_TEST_EQUALS(renderer1.GetTextures(), renderer3.GetTextures(), TEST_LOCATION);
1286 DALI_TEST_EQUALS(renderer1.GetGeometry(), renderer2.GetGeometry(), TEST_LOCATION);
1287 DALI_TEST_EQUALS(renderer1.GetGeometry(), renderer3.GetGeometry(), TEST_LOCATION);
1288 DALI_TEST_NOT_EQUALS(renderer1.GetShader(), renderer2.GetShader(), 0.0f, TEST_LOCATION);
1289 DALI_TEST_NOT_EQUALS(renderer1.GetShader(), renderer3.GetShader(), 0.0f, TEST_LOCATION);
1290 DALI_TEST_NOT_EQUALS(renderer2.GetShader(), renderer3.GetShader(), 0.0f, TEST_LOCATION);
1296 // Check that all the other two instances still use the shared textures and geometries from the cache
1297 // but have their own shader objects
1298 DALI_TEST_EQUALS(renderer2.GetTextures(), renderer3.GetTextures(), TEST_LOCATION);
1299 DALI_TEST_EQUALS(renderer2.GetGeometry(), renderer3.GetGeometry(), TEST_LOCATION);
1300 DALI_TEST_NOT_EQUALS(renderer2.GetShader(), renderer3.GetShader(), 0.0f, TEST_LOCATION);
1302 // Set new IBL textures for model2, and this should apply to model2 instance only
1303 gResourceReadyCalled = false;
1304 DALI_TEST_EQUALS(gResourceReadyCalled, false, TEST_LOCATION);
1305 model2.SetImageBasedLightSource(TEST_DIFFUSE_TEXTURE, TEST_SPECULAR_TEXTURE);
1307 application.SendNotification();
1308 application.Render();
1310 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1311 application.SendNotification();
1312 application.Render();
1314 // Check that the new IBL textures are loaded for model2
1315 DALI_TEST_EQUALS(gResourceReadyCalled, true, TEST_LOCATION);
1317 // Check that the two instances still use the shared geometries from the cache
1318 // but now have their own shader objects and different texture set
1319 DALI_TEST_NOT_EQUALS(renderer2.GetTextures(), renderer3.GetTextures(), 0.0f, TEST_LOCATION);
1320 DALI_TEST_EQUALS(renderer2.GetGeometry(), renderer3.GetGeometry(), TEST_LOCATION);
1321 DALI_TEST_NOT_EQUALS(renderer2.GetShader(), renderer3.GetShader(), 0.0f, TEST_LOCATION);
1323 // Check that the two instances now have their own diffuse texture and specular texture,
1324 // but all the other textures are still the same
1325 TextureSet textureSet2 = renderer2.GetTextures();
1326 TextureSet textureSet3 = renderer3.GetTextures();
1327 DALI_TEST_EQUALS(textureSet2.GetTextureCount(), 9u, TEST_LOCATION);
1328 DALI_TEST_EQUALS(textureSet3.GetTextureCount(), 9u, TEST_LOCATION);
1330 for (uint32_t i = 0; i < 7u; i++)
1332 DALI_TEST_EQUALS(textureSet2.GetTexture(i), textureSet3.GetTexture(i), TEST_LOCATION);
1335 DALI_TEST_NOT_EQUALS(textureSet2.GetTexture(7u), textureSet3.GetTexture(7u), 0.0f, TEST_LOCATION);
1336 DALI_TEST_NOT_EQUALS(textureSet2.GetTexture(8u), textureSet3.GetTexture(8u), 0.0f, TEST_LOCATION);