2 * Copyright (c) 2022 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>
30 using namespace Dali::Toolkit;
32 void model_startup(void)
34 test_return_value = TET_UNDEF;
37 void model_cleanup(void)
39 test_return_value = TET_PASS;
44 const bool DEFAULT_MODEL_CHILDREN_SENSITIVE = false;
45 const bool DEFAULT_MODEL_CHILDREN_FOCUSABLE = false;
47 * For the AnimatedCube.gltf and its Assets
48 * Donated by Norbert Nopper for glTF testing.
49 * Take from https://github.com/KhronosGroup/glTF-Sample-Models/tree/master/2.0/AnimatedCube
51 const char* TEST_GLTF_FILE_NAME = TEST_RESOURCE_DIR "/AnimatedCube.gltf";
52 const char* TEST_GLTF_ANIMATION_TEST_FILE_NAME = TEST_RESOURCE_DIR "/animationTest.gltf";
53 const char* TEST_GLTF_MULTIPLE_PRIMITIVE_FILE_NAME = TEST_RESOURCE_DIR "/simpleMultiplePrimitiveTest.gltf";
54 const char* TEST_DLI_FILE_NAME = TEST_RESOURCE_DIR "/arc.dli";
55 const char* TEST_DLI_EXERCISE_FILE_NAME = TEST_RESOURCE_DIR "/exercise.dli";
57 * For the diffuse and specular cube map texture.
58 * These textures are based off version of Wave engine sample
59 * Take from https://github.com/WaveEngine/Samples
61 * Copyright (c) 2022 Wave Coorporation
63 * Permission is hereby granted, free of charge, to any person obtaining a copy
64 * of this software and associated documentation files (the "Software"), to
65 * deal in the Software without restriction, including without limitation the
66 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
67 * sell copies of the Software, and to permit persons to whom the Software is
68 * furnished to do so, subject to the following conditions:
70 * The above copyright notice and this permission notice shall be included in
71 * all copies or substantial portions of the Software.
73 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
74 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
75 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
76 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
77 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
78 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
81 const char* TEST_DIFFUSE_TEXTURE = TEST_RESOURCE_DIR "/forest_irradiance.ktx";
82 const char* TEST_SPECULAR_TEXTURE = TEST_RESOURCE_DIR "/forest_radiance.ktx";
84 bool gTouchCallBackCalled = false;
85 bool TestTouchCallback(Actor, const TouchEvent&)
87 gTouchCallBackCalled = true;
91 bool gFocusChangedCallBackCalled = false;
92 void TestFocusChangedCallback(Actor, Actor)
94 gFocusChangedCallBackCalled = true;
98 static bool gOnRelayoutCallBackCalled = false;
99 void OnRelayoutCallback(Actor actor)
101 gOnRelayoutCallBackCalled = true;
104 static bool gResourceReadyCalled = false;
105 void OnResourceReady(Control control)
107 gResourceReadyCalled = true;
112 // Negative test case for a method
113 int UtcDaliModelUninitialized(void)
115 ToolkitTestApplication application;
116 tet_infoline(" UtcDaliModelUninitialized");
118 Scene3D::Model model;
122 // New() must be called to create a Model or it wont be valid.
123 Actor a = Actor::New();
125 DALI_TEST_CHECK(false);
127 catch(Dali::DaliException& e)
129 // Tests that a negative test of an assertion succeeds
130 DALI_TEST_PRINT_ASSERT(e);
131 DALI_TEST_CHECK(!model);
136 // Positive test case for a method
137 int UtcDaliModelNew(void)
139 ToolkitTestApplication application;
140 tet_infoline(" UtcDaliModelNew");
142 Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
143 DALI_TEST_CHECK(model);
147 // Positive test case for a method
148 int UtcDaliModelDownCast(void)
150 ToolkitTestApplication application;
151 tet_infoline(" UtcDaliModelDownCast");
153 Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
154 BaseHandle handle(model);
156 Scene3D::Model model2 = Scene3D::Model::DownCast(handle);
157 DALI_TEST_CHECK(model);
158 DALI_TEST_CHECK(model2);
159 DALI_TEST_CHECK(model2 == model);
163 int UtcDaliModelTypeRegistry(void)
165 ToolkitTestApplication application;
167 TypeRegistry typeRegistry = TypeRegistry::Get();
168 DALI_TEST_CHECK(typeRegistry);
170 TypeInfo typeInfo = typeRegistry.GetTypeInfo("Model");
171 DALI_TEST_CHECK(typeInfo);
173 BaseHandle handle = typeInfo.CreateInstance();
174 DALI_TEST_CHECK(handle);
176 Scene3D::Model model = Scene3D::Model::DownCast(handle);
177 DALI_TEST_CHECK(model);
182 // Positive test case for a method
183 int UtcDaliModelAddRemove(void)
185 ToolkitTestApplication application;
186 tet_infoline(" UtcDaliModelAddRemove");
188 Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
189 DALI_TEST_CHECK(model);
191 Actor actor = Actor::New();
192 DALI_TEST_CHECK(!actor.GetProperty<bool>(Actor::Property::CONNECTED_TO_SCENE));
194 model.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
195 model.SetProperty(Actor::Property::SIZE, application.GetScene().GetSize());
197 application.GetScene().Add(model);
199 DALI_TEST_CHECK(actor.GetProperty<bool>(Actor::Property::CONNECTED_TO_SCENE));
203 DALI_TEST_CHECK(!actor.GetProperty<bool>(Actor::Property::CONNECTED_TO_SCENE));
207 int UtcDaliModelCopyAndAssignment(void)
209 ToolkitTestApplication application;
211 Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
212 DALI_TEST_CHECK(model);
214 Scene3D::Model copy(model);
215 DALI_TEST_CHECK(model == copy);
217 Scene3D::Model assign;
218 DALI_TEST_CHECK(!assign);
221 DALI_TEST_CHECK(assign == model);
226 int UtcDaliModelMoveConstructor(void)
228 ToolkitTestApplication application;
230 Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
231 DALI_TEST_EQUALS(1, model.GetBaseObject().ReferenceCount(), TEST_LOCATION);
232 model.SetProperty(Actor::Property::SENSITIVE, false);
233 DALI_TEST_CHECK(false == model.GetProperty<bool>(Actor::Property::SENSITIVE));
235 Scene3D::Model moved = std::move(model);
236 DALI_TEST_CHECK(moved);
237 DALI_TEST_EQUALS(1, moved.GetBaseObject().ReferenceCount(), TEST_LOCATION);
238 DALI_TEST_CHECK(false == moved.GetProperty<bool>(Actor::Property::SENSITIVE));
239 DALI_TEST_CHECK(!model);
244 int UtcDaliModelMoveAssignment(void)
246 ToolkitTestApplication application;
248 Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
249 DALI_TEST_EQUALS(1, model.GetBaseObject().ReferenceCount(), TEST_LOCATION);
250 model.SetProperty(Actor::Property::SENSITIVE, false);
251 DALI_TEST_CHECK(false == model.GetProperty<bool>(Actor::Property::SENSITIVE));
253 Scene3D::Model moved;
254 moved = std::move(model);
255 DALI_TEST_CHECK(moved);
256 DALI_TEST_EQUALS(1, moved.GetBaseObject().ReferenceCount(), TEST_LOCATION);
257 DALI_TEST_CHECK(false == moved.GetProperty<bool>(Actor::Property::SENSITIVE));
258 DALI_TEST_CHECK(!model);
263 int UtcDaliModelOnScene01(void)
265 ToolkitTestApplication application;
267 Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
268 application.GetScene().Add(model);
270 gResourceReadyCalled = false;
271 model.ResourceReadySignal().Connect(&OnResourceReady);
272 DALI_TEST_EQUALS(gResourceReadyCalled, false, TEST_LOCATION);
274 application.SendNotification();
275 application.Render();
277 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
278 application.SendNotification();
279 application.Render();
281 DALI_TEST_EQUALS(gResourceReadyCalled, true, TEST_LOCATION);
283 uint32_t modelCount = model.GetModelRoot().GetChildCount();
284 DALI_TEST_EQUALS(1, modelCount, TEST_LOCATION);
288 int UtcDaliModelOnScene02(void)
290 ToolkitTestApplication application;
292 Scene3D::Model model = Scene3D::Model::New(TEST_DLI_FILE_NAME);
293 application.GetScene().Add(model);
295 gResourceReadyCalled = false;
296 model.ResourceReadySignal().Connect(&OnResourceReady);
297 DALI_TEST_EQUALS(gResourceReadyCalled, false, TEST_LOCATION);
299 application.SendNotification();
300 application.Render();
302 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
303 application.SendNotification();
304 application.Render();
306 DALI_TEST_EQUALS(gResourceReadyCalled, true, TEST_LOCATION);
308 uint32_t modelCount = model.GetModelRoot().GetChildCount();
309 DALI_TEST_EQUALS(1, modelCount, TEST_LOCATION);
311 Actor rootActor = model.GetModelRoot();
312 Vector3 rootSize = rootActor.GetProperty<Vector3>(Dali::Actor::Property::SIZE);
313 DALI_TEST_EQUALS(Vector3(2, 2, 1), rootSize, TEST_LOCATION);
318 int UtcDaliModelOnSizeSet(void)
320 ToolkitTestApplication application;
322 Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
324 application.GetScene().Add(model);
326 application.SendNotification();
327 application.Render();
329 Vector2 size(200.0f, 300.0f);
330 model.SetProperty(Actor::Property::SIZE, size);
332 application.SendNotification();
333 application.Render();
335 DALI_TEST_EQUALS(model.GetCurrentProperty<Vector2>(Actor::Property::SIZE), size, TEST_LOCATION);
340 int UtcDaliModelGetNaturalSize(void)
342 ToolkitTestApplication application;
344 Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
346 Vector3 naturalSize = model.GetNaturalSize();
347 DALI_TEST_EQUALS(Vector3::ZERO, naturalSize, TEST_LOCATION);
349 application.GetScene().Add(model);
351 gResourceReadyCalled = false;
352 model.ResourceReadySignal().Connect(&OnResourceReady);
353 DALI_TEST_EQUALS(gResourceReadyCalled, false, TEST_LOCATION);
355 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
356 application.SendNotification();
358 DALI_TEST_EQUALS(gResourceReadyCalled, true, TEST_LOCATION);
360 naturalSize = model.GetNaturalSize();
361 DALI_TEST_EQUALS(Vector3(2, 2, 2), naturalSize, TEST_LOCATION);
363 Actor root = model.GetModelRoot();
364 DALI_TEST_CHECK(root);
369 int UtcDaliModelSetImageBasedLightSource01(void)
371 ToolkitTestApplication application;
373 Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
374 application.GetScene().Add(model);
376 gResourceReadyCalled = false;
377 model.ResourceReadySignal().Connect(&OnResourceReady);
378 DALI_TEST_EQUALS(gResourceReadyCalled, false, TEST_LOCATION);
380 application.SendNotification();
381 application.Render();
383 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
384 application.SendNotification();
385 application.Render();
387 DALI_TEST_EQUALS(gResourceReadyCalled, true, TEST_LOCATION);
389 Actor meshActor = model.FindChildByName("AnimatedCube");
390 DALI_TEST_CHECK(meshActor);
392 Renderer renderer = meshActor.GetRendererAt(0u);
393 DALI_TEST_CHECK(renderer);
395 TextureSet textureSet = renderer.GetTextures();
396 DALI_TEST_EQUALS(textureSet.GetTextureCount(), 9u, TEST_LOCATION);
398 Texture diffuseTexture = textureSet.GetTexture(7u);
399 Texture specularTexture = textureSet.GetTexture(8u);
401 gResourceReadyCalled = false;
402 DALI_TEST_EQUALS(gResourceReadyCalled, false, TEST_LOCATION);
403 model.SetImageBasedLightSource(TEST_DIFFUSE_TEXTURE, TEST_SPECULAR_TEXTURE);
405 application.SendNotification();
406 application.Render();
408 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
409 application.SendNotification();
410 application.Render();
412 DALI_TEST_EQUALS(gResourceReadyCalled, true, TEST_LOCATION);
414 Texture newDiffuseTexture = textureSet.GetTexture(7u);
415 Texture newSpecularTexture = textureSet.GetTexture(8u);
417 DALI_TEST_NOT_EQUALS(diffuseTexture, newDiffuseTexture, 0.0f, TEST_LOCATION);
418 DALI_TEST_NOT_EQUALS(specularTexture, newSpecularTexture, 0.0f, TEST_LOCATION);
425 int UtcDaliModelSetImageBasedLightSource02(void)
427 ToolkitTestApplication application;
429 Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
430 application.GetScene().Add(model);
432 gResourceReadyCalled = false;
433 model.ResourceReadySignal().Connect(&OnResourceReady);
434 DALI_TEST_EQUALS(gResourceReadyCalled, false, TEST_LOCATION);
436 application.SendNotification();
437 application.Render();
439 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
440 application.SendNotification();
441 application.Render();
443 DALI_TEST_EQUALS(gResourceReadyCalled, true, TEST_LOCATION);
445 Actor meshActor = model.FindChildByName("AnimatedCube");
446 DALI_TEST_CHECK(meshActor);
448 Renderer renderer = meshActor.GetRendererAt(0u);
449 DALI_TEST_CHECK(renderer);
451 TextureSet textureSet = renderer.GetTextures();
452 DALI_TEST_EQUALS(textureSet.GetTextureCount(), 9u, TEST_LOCATION);
454 Texture diffuseTexture = textureSet.GetTexture(7u);
455 Texture specularTexture = textureSet.GetTexture(8u);
457 // if url is empty, loading is not requested.
458 model.SetImageBasedLightSource("", "");
460 Texture newDiffuseTexture = textureSet.GetTexture(7u);
461 Texture newSpecularTexture = textureSet.GetTexture(8u);
463 DALI_TEST_EQUALS(diffuseTexture, newDiffuseTexture, TEST_LOCATION);
464 DALI_TEST_EQUALS(specularTexture, newSpecularTexture, TEST_LOCATION);
469 int UtcDaliModelSetImageBasedLightSource03(void)
471 ToolkitTestApplication application;
473 Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
474 application.GetScene().Add(model);
476 gResourceReadyCalled = false;
477 model.ResourceReadySignal().Connect(&OnResourceReady);
478 DALI_TEST_EQUALS(gResourceReadyCalled, false, TEST_LOCATION);
480 application.SendNotification();
481 application.Render();
483 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
484 application.SendNotification();
485 application.Render();
487 DALI_TEST_EQUALS(gResourceReadyCalled, true, TEST_LOCATION);
489 Actor meshActor = model.FindChildByName("AnimatedCube");
490 DALI_TEST_CHECK(meshActor);
492 Renderer renderer = meshActor.GetRendererAt(0u);
493 DALI_TEST_CHECK(renderer);
495 TextureSet textureSet = renderer.GetTextures();
496 DALI_TEST_EQUALS(textureSet.GetTextureCount(), 9u, TEST_LOCATION);
498 Texture diffuseTexture = textureSet.GetTexture(7u);
499 Texture specularTexture = textureSet.GetTexture(8u);
501 gResourceReadyCalled = false;
502 DALI_TEST_EQUALS(gResourceReadyCalled, false, TEST_LOCATION);
503 model.SetImageBasedLightSource("dummy.ktx", "dummy.ktx");
505 application.SendNotification();
506 application.Render();
508 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(2), true, TEST_LOCATION);
509 application.SendNotification();
510 application.Render();
512 DALI_TEST_EQUALS(gResourceReadyCalled, true, TEST_LOCATION);
514 Texture newDiffuseTexture = textureSet.GetTexture(7u);
515 Texture newSpecularTexture = textureSet.GetTexture(8u);
517 DALI_TEST_EQUALS(diffuseTexture, newDiffuseTexture, TEST_LOCATION);
518 DALI_TEST_EQUALS(specularTexture, newSpecularTexture, TEST_LOCATION);
523 int UtcDaliModelSetImageBasedLightSource04(void)
525 ToolkitTestApplication application;
527 Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
528 model.SetImageBasedLightSource(TEST_DIFFUSE_TEXTURE, TEST_SPECULAR_TEXTURE);
529 application.GetScene().Add(model);
531 gResourceReadyCalled = false;
532 model.ResourceReadySignal().Connect(&OnResourceReady);
533 DALI_TEST_EQUALS(gResourceReadyCalled, false, TEST_LOCATION);
535 application.SendNotification();
536 application.Render();
538 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(3), true, TEST_LOCATION);
539 application.SendNotification();
540 application.Render();
542 DALI_TEST_EQUALS(gResourceReadyCalled, true, TEST_LOCATION);
546 int UtcDaliModelImageBasedFactor(void)
548 ToolkitTestApplication application;
550 Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
552 DALI_TEST_EQUALS(model.GetImageBasedLightScaleFactor(), 1.0f, TEST_LOCATION);
554 model.SetImageBasedLightScaleFactor(0.5f);
555 DALI_TEST_EQUALS(model.GetImageBasedLightScaleFactor(), 0.5f, TEST_LOCATION);
559 int UtcDaliModelChildrenSensitive01(void)
561 ToolkitTestApplication application;
563 Scene3D::Model view = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
564 view.SetProperty(Dali::Actor::Property::SIZE, Vector3(100, 100, 100));
565 view.SetProperty(Dali::Actor::Property::POSITION, Vector3(0, 0, 0));
566 view.SetProperty(Dali::Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER);
567 view.SetProperty(Dali::Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
569 // Get default vaule.
570 DALI_TEST_EQUALS(view.GetChildrenSensitive(), DEFAULT_MODEL_CHILDREN_SENSITIVE, TEST_LOCATION);
572 // Allow children actor's event before on scene.
573 view.SetChildrenSensitive(true);
574 DALI_TEST_EQUALS(view.GetChildrenSensitive(), true, TEST_LOCATION);
575 application.GetScene().Add(view);
577 gResourceReadyCalled = false;
578 view.ResourceReadySignal().Connect(&OnResourceReady);
579 DALI_TEST_EQUALS(gResourceReadyCalled, false, TEST_LOCATION);
581 application.SendNotification();
582 application.Render();
584 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
585 application.SendNotification();
586 application.Render();
588 DALI_TEST_EQUALS(gResourceReadyCalled, true, TEST_LOCATION);
590 Actor meshActor = view.FindChildByName("AnimatedCube");
591 DALI_TEST_CHECK(meshActor);
593 // connect hit-test signal
594 gTouchCallBackCalled = false;
595 meshActor.TouchedSignal().Connect(TestTouchCallback);
597 Vector2 sceneSize = application.GetScene().GetSize();
599 // Try to touch center of scene.
600 Dali::Integration::Point point;
601 point.SetState(PointState::DOWN);
602 point.SetScreenPosition(sceneSize * 0.5f);
603 Dali::Integration::TouchEvent event;
604 event.AddPoint(point);
606 // flush the queue and render once
607 application.SendNotification();
608 application.Render();
611 DALI_TEST_CHECK(!gTouchCallBackCalled);
612 application.ProcessEvent(event);
614 DALI_TEST_CHECK(gTouchCallBackCalled);
617 gTouchCallBackCalled = false;
619 // Block children actor's event
620 view.SetChildrenSensitive(false);
621 DALI_TEST_EQUALS(view.GetChildrenSensitive(), false, TEST_LOCATION);
623 // flush the queue and render once
624 application.SendNotification();
625 application.Render();
628 DALI_TEST_CHECK(!gTouchCallBackCalled);
629 application.ProcessEvent(event);
631 DALI_TEST_CHECK(!gTouchCallBackCalled);
634 gTouchCallBackCalled = false;
637 view.SetChildrenSensitive(true);
638 DALI_TEST_EQUALS(view.GetChildrenSensitive(), true, TEST_LOCATION);
640 // flush the queue and render once
641 application.SendNotification();
642 application.Render();
645 DALI_TEST_CHECK(!gTouchCallBackCalled);
646 application.ProcessEvent(event);
648 DALI_TEST_CHECK(gTouchCallBackCalled);
651 gTouchCallBackCalled = false;
656 int UtcDaliModelChildrenSensitive02(void)
658 ToolkitTestApplication application;
660 Scene3D::Model view = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
661 view.SetProperty(Dali::Actor::Property::SIZE, Vector3(100, 100, 100));
662 view.SetProperty(Dali::Actor::Property::POSITION, Vector3(0, 0, 0));
663 view.SetProperty(Dali::Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER);
664 view.SetProperty(Dali::Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
667 DALI_TEST_EQUALS(view.GetChildrenSensitive(), DEFAULT_MODEL_CHILDREN_SENSITIVE, TEST_LOCATION);
669 // Block children actor's event before on scene.
670 view.SetChildrenSensitive(false);
671 DALI_TEST_EQUALS(view.GetChildrenSensitive(), false, TEST_LOCATION);
672 application.GetScene().Add(view);
674 gResourceReadyCalled = false;
675 view.ResourceReadySignal().Connect(&OnResourceReady);
676 DALI_TEST_EQUALS(gResourceReadyCalled, false, TEST_LOCATION);
678 application.SendNotification();
679 application.Render();
681 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
682 application.SendNotification();
683 application.Render();
685 DALI_TEST_EQUALS(gResourceReadyCalled, true, TEST_LOCATION);
687 Actor meshActor = view.FindChildByName("AnimatedCube");
688 DALI_TEST_CHECK(meshActor);
690 // connect hit-test signal
691 gTouchCallBackCalled = false;
692 meshActor.TouchedSignal().Connect(TestTouchCallback);
694 Vector2 sceneSize = application.GetScene().GetSize();
696 // Try to touch center of scene.
697 Dali::Integration::Point point;
698 point.SetState(PointState::DOWN);
699 point.SetScreenPosition(sceneSize * 0.5f);
700 Dali::Integration::TouchEvent event;
701 event.AddPoint(point);
703 // flush the queue and render once
704 application.SendNotification();
705 application.Render();
708 DALI_TEST_CHECK(!gTouchCallBackCalled);
709 application.ProcessEvent(event);
711 DALI_TEST_CHECK(!gTouchCallBackCalled);
714 gTouchCallBackCalled = false;
717 view.SetChildrenSensitive(true);
718 DALI_TEST_EQUALS(view.GetChildrenSensitive(), true, TEST_LOCATION);
720 // flush the queue and render once
721 application.SendNotification();
722 application.Render();
725 DALI_TEST_CHECK(!gTouchCallBackCalled);
726 application.ProcessEvent(event);
728 DALI_TEST_CHECK(gTouchCallBackCalled);
731 gTouchCallBackCalled = false;
736 int UtcDaliModelChildrenFocusable01(void)
738 ToolkitTestApplication application;
740 Scene3D::Model view = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
741 view.SetProperty(Dali::Actor::Property::SIZE, Vector3(100, 100, 100));
742 view.SetProperty(Dali::Actor::Property::POSITION, Vector3(0, 0, 0));
743 view.SetProperty(Dali::Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER);
744 view.SetProperty(Dali::Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
746 // Get vaule. Default is false.
747 DALI_TEST_EQUALS(view.GetChildrenFocusable(), DEFAULT_MODEL_CHILDREN_FOCUSABLE, TEST_LOCATION);
749 // Allow children actor's focus before on scene.
750 view.SetChildrenFocusable(true);
751 DALI_TEST_EQUALS(view.GetChildrenFocusable(), true, TEST_LOCATION);
752 application.GetScene().Add(view);
754 gResourceReadyCalled = false;
755 view.ResourceReadySignal().Connect(&OnResourceReady);
756 DALI_TEST_EQUALS(gResourceReadyCalled, false, TEST_LOCATION);
758 application.SendNotification();
759 application.Render();
761 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
762 application.SendNotification();
763 application.Render();
765 DALI_TEST_EQUALS(gResourceReadyCalled, true, TEST_LOCATION);
767 Actor meshActor = view.FindChildByName("AnimatedCube");
768 DALI_TEST_CHECK(meshActor);
770 // Enable the default algorithm
771 KeyboardFocusManager manager = KeyboardFocusManager::Get();
772 DALI_TEST_CHECK(manager);
773 Dali::Toolkit::DevelKeyboardFocusManager::EnableDefaultAlgorithm(manager, true);
775 // connect focusable signal
776 gFocusChangedCallBackCalled = false;
777 meshActor.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true);
778 manager.FocusChangedSignal().Connect(TestFocusChangedCallback);
780 // Initialize with some left-positioned actor
781 Control focusStartActor = Control::New();
782 focusStartActor.SetProperty(Dali::Actor::Property::SIZE, Vector3(100, 100, 100));
783 focusStartActor.SetProperty(Dali::Actor::Property::POSITION, Vector3(-200, 0, 0));
784 focusStartActor.SetProperty(Dali::Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER);
785 focusStartActor.SetProperty(Dali::Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
786 focusStartActor.SetProperty(Dali::Actor::Property::KEYBOARD_FOCUSABLE, true);
787 application.GetScene().Add(focusStartActor);
790 manager.ClearFocus();
791 manager.SetCurrentFocusActor(focusStartActor);
792 gFocusChangedCallBackCalled = false;
794 // flush the queue and render once
795 application.SendNotification();
796 application.Render();
798 // Focusable view find success
799 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::RIGHT) == true);
800 DALI_TEST_CHECK(gFocusChangedCallBackCalled);
803 manager.ClearFocus();
804 manager.SetCurrentFocusActor(focusStartActor);
805 gFocusChangedCallBackCalled = false;
807 // Block children actor's focus
808 view.SetChildrenFocusable(false);
809 DALI_TEST_EQUALS(view.GetChildrenFocusable(), false, TEST_LOCATION);
811 // flush the queue and render once
812 application.SendNotification();
813 application.Render();
815 // Focusable view find failed
816 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::RIGHT) == false);
817 DALI_TEST_CHECK(!gFocusChangedCallBackCalled);
820 manager.ClearFocus();
821 manager.SetCurrentFocusActor(focusStartActor);
822 gFocusChangedCallBackCalled = false;
825 view.SetChildrenFocusable(true);
826 DALI_TEST_EQUALS(view.GetChildrenFocusable(), true, TEST_LOCATION);
828 // flush the queue and render once
829 application.SendNotification();
830 application.Render();
832 // Focusable view find success
833 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::RIGHT) == true);
834 DALI_TEST_CHECK(gFocusChangedCallBackCalled);
837 manager.ClearFocus();
838 manager.SetCurrentFocusActor(focusStartActor);
839 gFocusChangedCallBackCalled = false;
844 int UtcDaliModelModelChildrenFocusable02(void)
846 ToolkitTestApplication application;
848 Scene3D::Model view = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
849 view.SetProperty(Dali::Actor::Property::SIZE, Vector3(100, 100, 100));
850 view.SetProperty(Dali::Actor::Property::POSITION, Vector3(0, 0, 0));
851 view.SetProperty(Dali::Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER);
852 view.SetProperty(Dali::Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
854 // Get vaule. Default is true.
855 DALI_TEST_EQUALS(view.GetChildrenFocusable(), DEFAULT_MODEL_CHILDREN_FOCUSABLE, TEST_LOCATION);
857 // Block children actor's focus before on scene.
858 view.SetChildrenFocusable(false);
859 DALI_TEST_EQUALS(view.GetChildrenFocusable(), false, TEST_LOCATION);
860 application.GetScene().Add(view);
862 gResourceReadyCalled = false;
863 view.ResourceReadySignal().Connect(&OnResourceReady);
864 DALI_TEST_EQUALS(gResourceReadyCalled, false, TEST_LOCATION);
866 application.SendNotification();
867 application.Render();
869 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
870 application.SendNotification();
871 application.Render();
873 DALI_TEST_EQUALS(gResourceReadyCalled, true, TEST_LOCATION);
875 Actor meshActor = view.FindChildByName("AnimatedCube");
876 DALI_TEST_CHECK(meshActor);
878 // Enable the default algorithm
879 KeyboardFocusManager manager = KeyboardFocusManager::Get();
880 DALI_TEST_CHECK(manager);
881 Dali::Toolkit::DevelKeyboardFocusManager::EnableDefaultAlgorithm(manager, true);
883 // connect focusable signal
884 gFocusChangedCallBackCalled = false;
885 meshActor.SetProperty(Actor::Property::KEYBOARD_FOCUSABLE, true);
886 manager.FocusChangedSignal().Connect(TestFocusChangedCallback);
888 // Initialize with some left-positioned actor
889 Control focusStartActor = Control::New();
890 focusStartActor.SetProperty(Dali::Actor::Property::SIZE, Vector3(100, 100, 100));
891 focusStartActor.SetProperty(Dali::Actor::Property::POSITION, Vector3(-200, 0, 0));
892 focusStartActor.SetProperty(Dali::Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER);
893 focusStartActor.SetProperty(Dali::Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
894 focusStartActor.SetProperty(Dali::Actor::Property::KEYBOARD_FOCUSABLE, true);
895 application.GetScene().Add(focusStartActor);
898 manager.ClearFocus();
899 manager.SetCurrentFocusActor(focusStartActor);
900 gFocusChangedCallBackCalled = false;
902 // flush the queue and render once
903 application.SendNotification();
904 application.Render();
906 // Focusable view find failed
907 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::RIGHT) == false);
908 DALI_TEST_CHECK(!gFocusChangedCallBackCalled);
911 manager.ClearFocus();
912 manager.SetCurrentFocusActor(focusStartActor);
913 gFocusChangedCallBackCalled = false;
916 view.SetChildrenFocusable(true);
917 DALI_TEST_EQUALS(view.GetChildrenFocusable(), true, TEST_LOCATION);
919 // flush the queue and render once
920 application.SendNotification();
921 application.Render();
923 // Focusable view find success
924 DALI_TEST_CHECK(manager.MoveFocus(Control::KeyboardFocus::RIGHT) == true);
925 DALI_TEST_CHECK(gFocusChangedCallBackCalled);
928 manager.ClearFocus();
929 manager.SetCurrentFocusActor(focusStartActor);
930 gFocusChangedCallBackCalled = false;
935 int UtcDaliModelAnimation01(void)
937 ToolkitTestApplication application;
939 Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
940 model.SetProperty(Dali::Actor::Property::SIZE, Vector2(50, 50));
941 application.GetScene().Add(model);
943 gResourceReadyCalled = false;
944 model.ResourceReadySignal().Connect(&OnResourceReady);
945 DALI_TEST_EQUALS(gResourceReadyCalled, false, TEST_LOCATION);
947 application.SendNotification();
948 application.Render();
950 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
951 application.SendNotification();
952 application.Render();
954 DALI_TEST_EQUALS(gResourceReadyCalled, true, TEST_LOCATION);
956 uint32_t animationCount = model.GetAnimationCount();
957 DALI_TEST_EQUALS(1, animationCount, TEST_LOCATION);
959 Animation animationByIndex = model.GetAnimation(0u);
960 DALI_TEST_CHECK(animationByIndex);
962 Animation animationByName = model.GetAnimation("animation_AnimatedCube");
963 DALI_TEST_CHECK(animationByName);
964 DALI_TEST_EQUALS(animationByIndex, animationByName, TEST_LOCATION);
969 int UtcDaliModelAnimation02(void)
971 ToolkitTestApplication application;
973 Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_ANIMATION_TEST_FILE_NAME);
974 model.SetProperty(Dali::Actor::Property::SIZE, Vector2(50, 50));
975 application.GetScene().Add(model);
977 gResourceReadyCalled = false;
978 model.ResourceReadySignal().Connect(&OnResourceReady);
979 DALI_TEST_EQUALS(gResourceReadyCalled, false, TEST_LOCATION);
981 application.SendNotification();
982 application.Render();
984 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
985 application.SendNotification();
986 application.Render();
988 uint32_t animationCount = model.GetAnimationCount();
989 DALI_TEST_EQUALS(9, animationCount, TEST_LOCATION);
991 Animation animation1 = model.GetAnimation("Step Scale");
992 DALI_TEST_CHECK(animation1);
993 DALI_TEST_EQUALS(1.66667f, animation1.GetDuration(), 0.001f, TEST_LOCATION);
995 Animation animation2 = model.GetAnimation("CubicSpline Scale");
996 DALI_TEST_CHECK(animation2);
997 DALI_TEST_EQUALS(1.66667f, animation2.GetDuration(), 0.001f, TEST_LOCATION);
999 DALI_TEST_NOT_EQUALS(animation1, animation2, 0.0f, TEST_LOCATION);
1004 int UtcDaliModelAnimation03(void)
1006 ToolkitTestApplication application;
1008 Scene3D::Model model = Scene3D::Model::New(TEST_DLI_EXERCISE_FILE_NAME);
1009 model.SetProperty(Dali::Actor::Property::SIZE, Vector2(50, 50));
1010 application.GetScene().Add(model);
1012 gResourceReadyCalled = false;
1013 model.ResourceReadySignal().Connect(&OnResourceReady);
1014 DALI_TEST_EQUALS(gResourceReadyCalled, false, TEST_LOCATION);
1016 application.SendNotification();
1017 application.Render();
1019 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1020 application.SendNotification();
1021 application.Render();
1023 DALI_TEST_EQUALS(gResourceReadyCalled, true, TEST_LOCATION);
1025 uint32_t animationCount = model.GetAnimationCount();
1026 DALI_TEST_EQUALS(18, animationCount, TEST_LOCATION);
1028 Animation animationByIndex = model.GetAnimation(0u);
1029 DALI_TEST_CHECK(animationByIndex);
1031 Animation animationByName = model.GetAnimation("idleClip");
1032 DALI_TEST_CHECK(animationByName);
1033 DALI_TEST_EQUALS(animationByIndex, animationByName, TEST_LOCATION);
1038 int UtcDaliModelMultiplePrimitives(void)
1040 ToolkitTestApplication application;
1042 Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_MULTIPLE_PRIMITIVE_FILE_NAME);
1043 model.SetProperty(Dali::Actor::Property::SIZE, Vector2(50, 50));
1044 application.GetScene().Add(model);
1046 gResourceReadyCalled = false;
1047 model.ResourceReadySignal().Connect(&OnResourceReady);
1048 DALI_TEST_EQUALS(gResourceReadyCalled, false, TEST_LOCATION);
1050 application.SendNotification();
1051 application.Render();
1053 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1054 application.SendNotification();
1055 application.Render();
1057 Actor actor = model.FindChildByName("rootNode");
1059 DALI_TEST_EQUALS(0, actor.GetChildCount(), TEST_LOCATION);
1060 DALI_TEST_EQUALS(2, actor.GetRendererCount(), TEST_LOCATION);
1065 int UtcDaliModelColorMode(void)
1067 ToolkitTestApplication application;
1069 Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
1070 model.SetProperty(Dali::Actor::Property::SIZE, Vector2(50, 50));
1071 model.SetProperty(Dali::Actor::Property::COLOR, Color::RED);
1072 application.GetScene().Add(model);
1074 gResourceReadyCalled = false;
1075 model.ResourceReadySignal().Connect(&OnResourceReady);
1076 DALI_TEST_EQUALS(gResourceReadyCalled, false, TEST_LOCATION);
1078 application.SendNotification();
1079 application.Render();
1081 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1082 application.SendNotification();
1083 application.Render();
1085 Actor actor = model.FindChildByName("AnimatedCube");
1086 Vector4 childColor = actor[Dali::Actor::Property::COLOR];
1087 Vector4 childWorldColor = actor[Dali::Actor::Property::WORLD_COLOR];
1089 DALI_TEST_EQUALS(childColor, Color::WHITE, TEST_LOCATION);
1090 DALI_TEST_EQUALS(childWorldColor, Color::RED, TEST_LOCATION);
1094 int UtcDaliModelResourceReady(void)
1096 ToolkitTestApplication application;
1098 gOnRelayoutCallBackCalled = false;
1099 gResourceReadyCalled = false;
1100 Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_ANIMATION_TEST_FILE_NAME);
1101 model.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
1102 model.OnRelayoutSignal().Connect(OnRelayoutCallback);
1103 model.ResourceReadySignal().Connect(OnResourceReady);
1104 DALI_TEST_EQUALS(model.IsResourceReady(), false, TEST_LOCATION);
1107 DALI_TEST_CHECK(!gOnRelayoutCallBackCalled);
1108 DALI_TEST_CHECK(!gResourceReadyCalled);
1110 application.GetScene().Add(model);
1112 application.SendNotification();
1113 application.Render();
1115 DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
1116 application.SendNotification();
1117 application.Render();
1119 DALI_TEST_EQUALS(gOnRelayoutCallBackCalled, false, TEST_LOCATION);
1120 DALI_TEST_EQUALS(model.IsResourceReady(), true, TEST_LOCATION);
1121 DALI_TEST_EQUALS(gResourceReadyCalled, true, TEST_LOCATION);