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>
26 #include <dali-scene3d/public-api/controls/model/model.h>
29 using namespace Dali::Toolkit;
31 void model_startup(void)
33 test_return_value = TET_UNDEF;
36 void model_cleanup(void)
38 test_return_value = TET_PASS;
43 const bool DEFAULT_MODEL_CHILDREN_SENSITIVE = false;
45 * For the AnimatedCube.gltf and its Assets
46 * Donated by Norbert Nopper for glTF testing.
47 * Take from https://github.com/KhronosGroup/glTF-Sample-Models/tree/master/2.0/AnimatedCube
49 const char* TEST_GLTF_FILE_NAME = TEST_RESOURCE_DIR "/AnimatedCube.gltf";
50 const char* TEST_GLTF_ANIMATION_TEST_FILE_NAME = TEST_RESOURCE_DIR "/animationTest.gltf";
51 const char* TEST_DLI_FILE_NAME = TEST_RESOURCE_DIR "/arc.dli";
53 * For the diffuse and specular cube map texture.
54 * These textures are based off version of Wave engine sample
55 * Take from https://github.com/WaveEngine/Samples
57 * Copyright (c) 2022 Wave Coorporation
59 * Permission is hereby granted, free of charge, to any person obtaining a copy
60 * of this software and associated documentation files (the "Software"), to
61 * deal in the Software without restriction, including without limitation the
62 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
63 * sell copies of the Software, and to permit persons to whom the Software is
64 * furnished to do so, subject to the following conditions:
66 * The above copyright notice and this permission notice shall be included in
67 * all copies or substantial portions of the Software.
69 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
70 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
71 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
72 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
73 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
74 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
77 const char* TEST_DIFFUSE_TEXTURE = TEST_RESOURCE_DIR "/forest_irradiance.ktx";
78 const char* TEST_SPECULAR_TEXTURE = TEST_RESOURCE_DIR "/forest_radiance.ktx";
80 bool gTouchCallBackCalled = false;
81 bool TestTouchCallback(Actor, const TouchEvent&)
83 gTouchCallBackCalled = true;
89 // Negative test case for a method
90 int UtcDaliModelUninitialized(void)
92 ToolkitTestApplication application;
93 tet_infoline(" UtcDaliModelUninitialized");
99 // New() must be called to create a Model or it wont be valid.
100 Actor a = Actor::New();
102 DALI_TEST_CHECK(false);
104 catch(Dali::DaliException& e)
106 // Tests that a negative test of an assertion succeeds
107 DALI_TEST_PRINT_ASSERT(e);
108 DALI_TEST_CHECK(!model);
113 // Positive test case for a method
114 int UtcDaliModelNew(void)
116 ToolkitTestApplication application;
117 tet_infoline(" UtcDaliModelNew");
119 Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
120 DALI_TEST_CHECK(model);
124 // Positive test case for a method
125 int UtcDaliModelDownCast(void)
127 ToolkitTestApplication application;
128 tet_infoline(" UtcDaliModelDownCast");
130 Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
131 BaseHandle handle(model);
133 Scene3D::Model model2 = Scene3D::Model::DownCast(handle);
134 DALI_TEST_CHECK(model);
135 DALI_TEST_CHECK(model2);
136 DALI_TEST_CHECK(model2 == model);
140 int UtcDaliModelTypeRegistry(void)
142 ToolkitTestApplication application;
144 TypeRegistry typeRegistry = TypeRegistry::Get();
145 DALI_TEST_CHECK(typeRegistry);
147 TypeInfo typeInfo = typeRegistry.GetTypeInfo("Model");
148 DALI_TEST_CHECK(typeInfo);
150 BaseHandle handle = typeInfo.CreateInstance();
151 DALI_TEST_CHECK(handle);
153 Scene3D::Model model = Scene3D::Model::DownCast(handle);
154 DALI_TEST_CHECK(model);
159 // Positive test case for a method
160 int UtcDaliModelAddRemove(void)
162 ToolkitTestApplication application;
163 tet_infoline(" UtcDaliModelAddRemove");
165 Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
166 DALI_TEST_CHECK(model);
168 Actor actor = Actor::New();
169 DALI_TEST_CHECK(!actor.GetProperty<bool>(Actor::Property::CONNECTED_TO_SCENE));
171 model.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
172 model.SetProperty(Actor::Property::SIZE, application.GetScene().GetSize());
174 application.GetScene().Add(model);
176 DALI_TEST_CHECK(actor.GetProperty<bool>(Actor::Property::CONNECTED_TO_SCENE));
180 DALI_TEST_CHECK(!actor.GetProperty<bool>(Actor::Property::CONNECTED_TO_SCENE));
184 int UtcDaliModelCopyAndAssignment(void)
186 ToolkitTestApplication application;
188 Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
189 DALI_TEST_CHECK(model);
191 Scene3D::Model copy(model);
192 DALI_TEST_CHECK(model == copy);
194 Scene3D::Model assign;
195 DALI_TEST_CHECK(!assign);
198 DALI_TEST_CHECK(assign == model);
203 int UtcDaliModelMoveConstructor(void)
205 ToolkitTestApplication application;
207 Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
208 DALI_TEST_EQUALS(1, model.GetBaseObject().ReferenceCount(), TEST_LOCATION);
209 model.SetProperty(Actor::Property::SENSITIVE, false);
210 DALI_TEST_CHECK(false == model.GetProperty<bool>(Actor::Property::SENSITIVE));
212 Scene3D::Model moved = std::move(model);
213 DALI_TEST_CHECK(moved);
214 DALI_TEST_EQUALS(1, moved.GetBaseObject().ReferenceCount(), TEST_LOCATION);
215 DALI_TEST_CHECK(false == moved.GetProperty<bool>(Actor::Property::SENSITIVE));
216 DALI_TEST_CHECK(!model);
221 int UtcDaliModelMoveAssignment(void)
223 ToolkitTestApplication application;
225 Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
226 DALI_TEST_EQUALS(1, model.GetBaseObject().ReferenceCount(), TEST_LOCATION);
227 model.SetProperty(Actor::Property::SENSITIVE, false);
228 DALI_TEST_CHECK(false == model.GetProperty<bool>(Actor::Property::SENSITIVE));
230 Scene3D::Model moved;
231 moved = std::move(model);
232 DALI_TEST_CHECK(moved);
233 DALI_TEST_EQUALS(1, moved.GetBaseObject().ReferenceCount(), TEST_LOCATION);
234 DALI_TEST_CHECK(false == moved.GetProperty<bool>(Actor::Property::SENSITIVE));
235 DALI_TEST_CHECK(!model);
240 int UtcDaliModelOnScene01(void)
242 ToolkitTestApplication application;
244 Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
246 application.GetScene().Add(model);
248 application.SendNotification();
249 application.Render();
251 uint32_t modelCount = model.GetModelRoot().GetChildCount();
252 DALI_TEST_EQUALS(1, modelCount, TEST_LOCATION);
257 int UtcDaliModelOnScene02(void)
259 ToolkitTestApplication application;
261 Scene3D::Model model = Scene3D::Model::New(TEST_DLI_FILE_NAME);
263 application.GetScene().Add(model);
265 application.SendNotification();
266 application.Render();
268 uint32_t modelCount = model.GetModelRoot().GetChildCount();
269 DALI_TEST_EQUALS(1, modelCount, TEST_LOCATION);
271 Actor rootActor = model.GetModelRoot();
272 Vector3 rootSize = rootActor.GetProperty<Vector3>(Dali::Actor::Property::SIZE);
273 DALI_TEST_EQUALS(Vector3(2, 2, 1), rootSize, TEST_LOCATION);
278 int UtcDaliModelOnSizeSet(void)
280 ToolkitTestApplication application;
282 Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
284 application.GetScene().Add(model);
286 application.SendNotification();
287 application.Render();
289 Vector2 size(200.0f, 300.0f);
290 model.SetProperty(Actor::Property::SIZE, size);
292 application.SendNotification();
293 application.Render();
295 DALI_TEST_EQUALS(model.GetCurrentProperty<Vector2>(Actor::Property::SIZE), size, TEST_LOCATION);
300 int UtcDaliModelGetNaturalSize(void)
302 ToolkitTestApplication application;
304 Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
306 Vector3 naturalSize = model.GetNaturalSize();
308 DALI_TEST_EQUALS(Vector3(2, 2, 2), naturalSize, TEST_LOCATION);
310 Actor root = model.GetModelRoot();
311 DALI_TEST_CHECK(root);
316 int UtcDaliModelSetImageBasedLightSource01(void)
318 ToolkitTestApplication application;
320 Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
322 application.GetScene().Add(model);
324 application.SendNotification();
325 application.Render();
327 Actor meshActor = model.FindChildByName("AnimatedCube");
328 DALI_TEST_CHECK(meshActor);
330 Renderer renderer = meshActor.GetRendererAt(0u);
331 DALI_TEST_CHECK(renderer);
333 TextureSet textureSet = renderer.GetTextures();
334 DALI_TEST_EQUALS(textureSet.GetTextureCount(), 7u, TEST_LOCATION);
336 Texture diffuseTexture = textureSet.GetTexture(5u);
337 Texture specularTexture = textureSet.GetTexture(6u);
339 model.SetImageBasedLightSource(TEST_DIFFUSE_TEXTURE, TEST_SPECULAR_TEXTURE);
341 Texture newDiffuseTexture = textureSet.GetTexture(5u);
342 Texture newSpecularTexture = textureSet.GetTexture(6u);
344 DALI_TEST_NOT_EQUALS(diffuseTexture, newDiffuseTexture, 0.0f, TEST_LOCATION);
345 DALI_TEST_NOT_EQUALS(specularTexture, newSpecularTexture, 0.0f, TEST_LOCATION);
350 int UtcDaliModelSetImageBasedLightSource02(void)
352 ToolkitTestApplication application;
354 Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
356 application.GetScene().Add(model);
358 application.SendNotification();
359 application.Render();
361 Actor meshActor = model.FindChildByName("AnimatedCube");
362 DALI_TEST_CHECK(meshActor);
364 Renderer renderer = meshActor.GetRendererAt(0u);
365 DALI_TEST_CHECK(renderer);
367 TextureSet textureSet = renderer.GetTextures();
368 DALI_TEST_EQUALS(textureSet.GetTextureCount(), 7u, TEST_LOCATION);
370 Texture diffuseTexture = textureSet.GetTexture(5u);
371 Texture specularTexture = textureSet.GetTexture(6u);
373 model.SetImageBasedLightSource("", "");
375 Texture newDiffuseTexture = textureSet.GetTexture(5u);
376 Texture newSpecularTexture = textureSet.GetTexture(6u);
378 DALI_TEST_EQUALS(diffuseTexture, newDiffuseTexture, TEST_LOCATION);
379 DALI_TEST_EQUALS(specularTexture, newSpecularTexture, TEST_LOCATION);
384 int UtcDaliModelSetImageBasedLightSource03(void)
386 ToolkitTestApplication application;
388 Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
390 application.GetScene().Add(model);
392 application.SendNotification();
393 application.Render();
395 Actor meshActor = model.FindChildByName("AnimatedCube");
396 DALI_TEST_CHECK(meshActor);
398 Renderer renderer = meshActor.GetRendererAt(0u);
399 DALI_TEST_CHECK(renderer);
401 TextureSet textureSet = renderer.GetTextures();
402 DALI_TEST_EQUALS(textureSet.GetTextureCount(), 7u, TEST_LOCATION);
404 Texture diffuseTexture = textureSet.GetTexture(5u);
405 Texture specularTexture = textureSet.GetTexture(6u);
407 model.SetImageBasedLightSource("dummy.ktx", "dummy.ktx");
409 Texture newDiffuseTexture = textureSet.GetTexture(5u);
410 Texture newSpecularTexture = textureSet.GetTexture(6u);
412 DALI_TEST_EQUALS(diffuseTexture, newDiffuseTexture, TEST_LOCATION);
413 DALI_TEST_EQUALS(specularTexture, newSpecularTexture, TEST_LOCATION);
418 int UtcDaliModelImageBasedFactor(void)
420 ToolkitTestApplication application;
422 Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
424 DALI_TEST_EQUALS(model.GetImageBasedLightScaleFactor(), 1.0f, TEST_LOCATION);
426 model.SetImageBasedLightScaleFactor(0.5f);
427 DALI_TEST_EQUALS(model.GetImageBasedLightScaleFactor(), 0.5f, TEST_LOCATION);
431 int UtcDaliModelChildrenSensitive01(void)
433 ToolkitTestApplication application;
435 Scene3D::Model view = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
436 view.SetProperty(Dali::Actor::Property::SIZE, Vector3(100, 100, 100));
437 view.SetProperty(Dali::Actor::Property::POSITION, Vector3(0, 0, 0));
438 view.SetProperty(Dali::Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER);
439 view.SetProperty(Dali::Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
441 // Get default vaule.
442 DALI_TEST_EQUALS(view.GetChildrenSensitive(), DEFAULT_MODEL_CHILDREN_SENSITIVE, TEST_LOCATION);
444 // Allow children actor's event before on scene.
445 view.SetChildrenSensitive(true);
446 DALI_TEST_EQUALS(view.GetChildrenSensitive(), true, TEST_LOCATION);
448 application.GetScene().Add(view);
450 application.SendNotification();
451 application.Render();
453 Actor meshActor = view.FindChildByName("AnimatedCube");
454 DALI_TEST_CHECK(meshActor);
456 // connect hit-test signal
457 gTouchCallBackCalled = false;
458 meshActor.TouchedSignal().Connect(TestTouchCallback);
460 Vector2 sceneSize = application.GetScene().GetSize();
462 // Try to touch center of scene.
463 Dali::Integration::Point point;
464 point.SetState(PointState::DOWN);
465 point.SetScreenPosition(sceneSize * 0.5f);
466 Dali::Integration::TouchEvent event;
467 event.AddPoint(point);
469 // flush the queue and render once
470 application.SendNotification();
471 application.Render();
474 DALI_TEST_CHECK(!gTouchCallBackCalled);
475 application.ProcessEvent(event);
477 DALI_TEST_CHECK(gTouchCallBackCalled);
480 gTouchCallBackCalled = false;
482 // Block children actor's event
483 view.SetChildrenSensitive(false);
484 DALI_TEST_EQUALS(view.GetChildrenSensitive(), false, TEST_LOCATION);
486 // flush the queue and render once
487 application.SendNotification();
488 application.Render();
491 DALI_TEST_CHECK(!gTouchCallBackCalled);
492 application.ProcessEvent(event);
494 DALI_TEST_CHECK(!gTouchCallBackCalled);
497 gTouchCallBackCalled = false;
500 view.SetChildrenSensitive(true);
501 DALI_TEST_EQUALS(view.GetChildrenSensitive(), true, TEST_LOCATION);
503 // flush the queue and render once
504 application.SendNotification();
505 application.Render();
508 DALI_TEST_CHECK(!gTouchCallBackCalled);
509 application.ProcessEvent(event);
511 DALI_TEST_CHECK(gTouchCallBackCalled);
514 gTouchCallBackCalled = false;
519 int UtcDaliModelChildrenSensitive02(void)
521 ToolkitTestApplication application;
523 Scene3D::Model view = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
524 view.SetProperty(Dali::Actor::Property::SIZE, Vector3(100, 100, 100));
525 view.SetProperty(Dali::Actor::Property::POSITION, Vector3(0, 0, 0));
526 view.SetProperty(Dali::Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER);
527 view.SetProperty(Dali::Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
530 DALI_TEST_EQUALS(view.GetChildrenSensitive(), DEFAULT_MODEL_CHILDREN_SENSITIVE, TEST_LOCATION);
532 // Block children actor's event before on scene.
533 view.SetChildrenSensitive(false);
534 DALI_TEST_EQUALS(view.GetChildrenSensitive(), false, TEST_LOCATION);
536 application.GetScene().Add(view);
538 application.SendNotification();
539 application.Render();
541 Actor meshActor = view.FindChildByName("AnimatedCube");
542 DALI_TEST_CHECK(meshActor);
544 // connect hit-test signal
545 gTouchCallBackCalled = false;
546 meshActor.TouchedSignal().Connect(TestTouchCallback);
548 Vector2 sceneSize = application.GetScene().GetSize();
550 // Try to touch center of scene.
551 Dali::Integration::Point point;
552 point.SetState(PointState::DOWN);
553 point.SetScreenPosition(sceneSize * 0.5f);
554 Dali::Integration::TouchEvent event;
555 event.AddPoint(point);
557 // flush the queue and render once
558 application.SendNotification();
559 application.Render();
562 DALI_TEST_CHECK(!gTouchCallBackCalled);
563 application.ProcessEvent(event);
565 DALI_TEST_CHECK(!gTouchCallBackCalled);
568 gTouchCallBackCalled = false;
571 view.SetChildrenSensitive(true);
572 DALI_TEST_EQUALS(view.GetChildrenSensitive(), true, TEST_LOCATION);
574 // flush the queue and render once
575 application.SendNotification();
576 application.Render();
579 DALI_TEST_CHECK(!gTouchCallBackCalled);
580 application.ProcessEvent(event);
582 DALI_TEST_CHECK(gTouchCallBackCalled);
585 gTouchCallBackCalled = false;
590 int UtcDaliModelAnimation01(void)
592 ToolkitTestApplication application;
594 Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
595 model.SetProperty(Dali::Actor::Property::SIZE, Vector2(50, 50));
597 application.GetScene().Add(model);
599 application.SendNotification();
600 application.Render();
602 uint32_t animationCount = model.GetAnimationCount();
603 DALI_TEST_EQUALS(1, animationCount, TEST_LOCATION);
605 Animation animationByIndex = model.GetAnimation(0u);
606 DALI_TEST_CHECK(animationByIndex);
608 Animation animationByName = model.GetAnimation("animation_AnimatedCube");
609 DALI_TEST_CHECK(animationByName);
610 DALI_TEST_EQUALS(animationByIndex, animationByName, TEST_LOCATION);
615 int UtcDaliModelAnimation02(void)
617 ToolkitTestApplication application;
619 Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_ANIMATION_TEST_FILE_NAME);
620 model.SetProperty(Dali::Actor::Property::SIZE, Vector2(50, 50));
622 application.GetScene().Add(model);
624 application.SendNotification();
625 application.Render();
627 uint32_t animationCount = model.GetAnimationCount();
628 DALI_TEST_EQUALS(9, animationCount, TEST_LOCATION);
630 Animation animation1 = model.GetAnimation("Step Scale");
631 DALI_TEST_CHECK(animation1);
632 DALI_TEST_EQUALS(1.66667f, animation1.GetDuration(), 0.001f, TEST_LOCATION);
634 Animation animation2 = model.GetAnimation("CubicSpline Scale");
635 DALI_TEST_CHECK(animation2);
636 DALI_TEST_EQUALS(1.66667f, animation2.GetDuration(), 0.001f, TEST_LOCATION);
638 DALI_TEST_NOT_EQUALS(animation1, animation2, 0.0f, TEST_LOCATION);
646 static bool gOnRelayoutCallBackCalled = false;
647 void OnRelayoutCallback(Actor actor)
649 gOnRelayoutCallBackCalled = true;
652 static bool gResourceReadyCalled = false;
653 void OnResourceReady(Control control)
655 gResourceReadyCalled = true;
659 int UtcDaliModelResourceReady(void)
661 ToolkitTestApplication application;
663 gOnRelayoutCallBackCalled = false;
664 gResourceReadyCalled = false;
665 Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_ANIMATION_TEST_FILE_NAME);
666 model.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
667 model.OnRelayoutSignal().Connect(OnRelayoutCallback);
668 model.ResourceReadySignal().Connect(OnResourceReady);
669 DALI_TEST_EQUALS(model.IsResourceReady(), false, TEST_LOCATION);
672 DALI_TEST_CHECK(!gOnRelayoutCallBackCalled);
673 DALI_TEST_CHECK(!gResourceReadyCalled);
675 application.GetScene().Add(model);
677 application.SendNotification();
678 application.Render();
680 DALI_TEST_EQUALS(gOnRelayoutCallBackCalled, false, TEST_LOCATION);
681 DALI_TEST_EQUALS(model.IsResourceReady(), true, TEST_LOCATION);
682 DALI_TEST_EQUALS(gResourceReadyCalled, true, TEST_LOCATION);