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-scene-loader/public-api/controls/model-view/model-view.h>
26 using namespace Dali::Toolkit;
28 void model_view_startup(void)
30 test_return_value = TET_UNDEF;
33 void model_view_cleanup(void)
35 test_return_value = TET_PASS;
41 * For the AnimatedCube.gltf and its Assets
42 * Donated by Norbert Nopper for glTF testing.
43 * Take from https://github.com/KhronosGroup/glTF-Sample-Models/tree/master/2.0/AnimatedCube
45 const char* TEST_GLTF_FILE_NAME = TEST_RESOURCE_DIR "/AnimatedCube.gltf";
46 const char* TEST_GLTF_TRIANGLE_FILE_NAME = TEST_RESOURCE_DIR "/AnimatedTriangle.gltf";
47 const char* TEST_GLTF_ANIMATION_TEST_FILE_NAME = TEST_RESOURCE_DIR "/animationTest.gltf";
48 const char* TEST_DLI_FILE_NAME = TEST_RESOURCE_DIR "/arc.dli";
50 * For the diffuse and specular cube map texture.
51 * These textures are based off version of Wave engine sample
52 * Take from https://github.com/WaveEngine/Samples
54 * Copyright (c) 2022 Wave Coorporation
56 * Permission is hereby granted, free of charge, to any person obtaining a copy
57 * of this software and associated documentation files (the "Software"), to
58 * deal in the Software without restriction, including without limitation the
59 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
60 * sell copies of the Software, and to permit persons to whom the Software is
61 * furnished to do so, subject to the following conditions:
63 * The above copyright notice and this permission notice shall be included in
64 * all copies or substantial portions of the Software.
66 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
67 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
68 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
69 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
70 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
71 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
74 const char* TEST_DIFFUSE_TEXTURE = TEST_RESOURCE_DIR "/forest_irradiance.ktx";
75 const char* TEST_SPECULAR_TEXTURE = TEST_RESOURCE_DIR "/forest_radiance.ktx";
78 // Negative test case for a method
79 int UtcDaliModelViewUninitialized(void)
81 ToolkitTestApplication application;
82 tet_infoline(" UtcDaliModelViewUninitialized");
84 Scene3D::ModelView view;
88 // New() must be called to create a ModelView or it wont be valid.
89 Actor a = Actor::New();
91 DALI_TEST_CHECK(false);
93 catch(Dali::DaliException& e)
95 // Tests that a negative test of an assertion succeeds
96 DALI_TEST_PRINT_ASSERT(e);
97 DALI_TEST_CHECK(!view);
102 // Positive test case for a method
103 int UtcDaliModelViewNew(void)
105 ToolkitTestApplication application;
106 tet_infoline(" UtcDaliModelViewNew");
108 Scene3D::ModelView view = Scene3D::ModelView::New(TEST_GLTF_FILE_NAME);
109 DALI_TEST_CHECK(view);
113 // Positive test case for a method
114 int UtcDaliModelViewDownCast(void)
116 ToolkitTestApplication application;
117 tet_infoline(" UtcDaliModelViewDownCast");
119 Scene3D::ModelView view = Scene3D::ModelView::New(TEST_GLTF_FILE_NAME);
120 BaseHandle handle(view);
122 Scene3D::ModelView modelView = Scene3D::ModelView::DownCast(handle);
123 DALI_TEST_CHECK(view);
124 DALI_TEST_CHECK(modelView);
125 DALI_TEST_CHECK(modelView == view);
129 int UtcDaliModelViewTypeRegistry(void)
131 ToolkitTestApplication application;
133 TypeRegistry typeRegistry = TypeRegistry::Get();
134 DALI_TEST_CHECK(typeRegistry);
136 TypeInfo typeInfo = typeRegistry.GetTypeInfo("ModelView");
137 DALI_TEST_CHECK(typeInfo);
139 BaseHandle handle = typeInfo.CreateInstance();
140 DALI_TEST_CHECK(handle);
142 Scene3D::ModelView modelView = Scene3D::ModelView::DownCast(handle);
143 DALI_TEST_CHECK(modelView);
148 // Positive test case for a method
149 int UtcDaliModelViewAddRemove(void)
151 ToolkitTestApplication application;
152 tet_infoline(" UtcDaliModelViewAddRemove");
154 Scene3D::ModelView view = Scene3D::ModelView::New(TEST_GLTF_FILE_NAME);
155 DALI_TEST_CHECK(view);
157 Actor actor = Actor::New();
158 DALI_TEST_CHECK(!actor.GetProperty<bool>(Actor::Property::CONNECTED_TO_SCENE));
160 view.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
161 view.SetProperty(Actor::Property::SIZE, application.GetScene().GetSize());
163 application.GetScene().Add(view);
165 DALI_TEST_CHECK(actor.GetProperty<bool>(Actor::Property::CONNECTED_TO_SCENE));
169 DALI_TEST_CHECK(!actor.GetProperty<bool>(Actor::Property::CONNECTED_TO_SCENE));
173 int UtcDaliModelViewCopyAndAssignment(void)
175 ToolkitTestApplication application;
177 Scene3D::ModelView view = Scene3D::ModelView::New(TEST_GLTF_FILE_NAME);
178 DALI_TEST_CHECK(view);
180 Scene3D::ModelView copy(view);
181 DALI_TEST_CHECK(view == copy);
183 Scene3D::ModelView assign;
184 DALI_TEST_CHECK(!assign);
187 DALI_TEST_CHECK(assign == view);
192 int UtcDaliModelViewMoveConstructor(void)
194 ToolkitTestApplication application;
196 Scene3D::ModelView view = Scene3D::ModelView::New(TEST_GLTF_FILE_NAME);
197 DALI_TEST_EQUALS(1, view.GetBaseObject().ReferenceCount(), TEST_LOCATION);
198 view.SetProperty(Actor::Property::SENSITIVE, false);
199 DALI_TEST_CHECK(false == view.GetProperty<bool>(Actor::Property::SENSITIVE));
201 Scene3D::ModelView moved = std::move(view);
202 DALI_TEST_CHECK(moved);
203 DALI_TEST_EQUALS(1, moved.GetBaseObject().ReferenceCount(), TEST_LOCATION);
204 DALI_TEST_CHECK(false == moved.GetProperty<bool>(Actor::Property::SENSITIVE));
205 DALI_TEST_CHECK(!view);
210 int UtcDaliModelViewMoveAssignment(void)
212 ToolkitTestApplication application;
214 Scene3D::ModelView view = Scene3D::ModelView::New(TEST_GLTF_FILE_NAME);
215 DALI_TEST_EQUALS(1, view.GetBaseObject().ReferenceCount(), TEST_LOCATION);
216 view.SetProperty(Actor::Property::SENSITIVE, false);
217 DALI_TEST_CHECK(false == view.GetProperty<bool>(Actor::Property::SENSITIVE));
219 Scene3D::ModelView moved;
220 moved = std::move(view);
221 DALI_TEST_CHECK(moved);
222 DALI_TEST_EQUALS(1, moved.GetBaseObject().ReferenceCount(), TEST_LOCATION);
223 DALI_TEST_CHECK(false == moved.GetProperty<bool>(Actor::Property::SENSITIVE));
224 DALI_TEST_CHECK(!view);
229 int UtcDaliModelViewOnScene01(void)
231 ToolkitTestApplication application;
233 Scene3D::ModelView view = Scene3D::ModelView::New(TEST_GLTF_FILE_NAME);
235 application.GetScene().Add(view);
237 application.SendNotification();
238 application.Render();
240 uint32_t modelCount = view.GetModelRoot().GetChildCount();
241 DALI_TEST_EQUALS(1, modelCount, TEST_LOCATION);
246 int UtcDaliModelViewOnScene02(void)
248 ToolkitTestApplication application;
250 Scene3D::ModelView view = Scene3D::ModelView::New(TEST_DLI_FILE_NAME);
252 application.GetScene().Add(view);
254 application.SendNotification();
255 application.Render();
257 uint32_t modelCount = view.GetModelRoot().GetChildCount();
258 DALI_TEST_EQUALS(1, modelCount, TEST_LOCATION);
260 Actor rootActor = view.GetModelRoot();
261 Vector3 rootSize = rootActor.GetProperty<Vector3>(Dali::Actor::Property::SIZE);
262 DALI_TEST_EQUALS(Vector3(2, 2, 1), rootSize, TEST_LOCATION);
267 int UtcDaliModelViewOnSizeSet(void)
269 ToolkitTestApplication application;
271 Scene3D::ModelView view = Scene3D::ModelView::New(TEST_GLTF_FILE_NAME);
273 application.GetScene().Add(view);
275 application.SendNotification();
276 application.Render();
278 Vector2 size(200.0f, 300.0f);
279 view.SetProperty(Actor::Property::SIZE, size);
281 application.SendNotification();
282 application.Render();
284 DALI_TEST_EQUALS(view.GetCurrentProperty<Vector2>(Actor::Property::SIZE), size, TEST_LOCATION);
289 int UtcDaliModelViewGetNaturalSize(void)
291 ToolkitTestApplication application;
293 Scene3D::ModelView view = Scene3D::ModelView::New(TEST_GLTF_FILE_NAME);
295 Vector3 naturalSize = view.GetNaturalSize();
297 DALI_TEST_EQUALS(Vector3(2, 2, 2), naturalSize, TEST_LOCATION);
299 Actor root = view.GetModelRoot();
300 DALI_TEST_CHECK(root);
305 int UtcDaliModelViewSetImageBasedLightSource01(void)
307 ToolkitTestApplication application;
309 Scene3D::ModelView view = Scene3D::ModelView::New(TEST_GLTF_FILE_NAME);
311 application.GetScene().Add(view);
313 application.SendNotification();
314 application.Render();
316 Actor meshActor = view.FindChildByName("AnimatedCube");
317 DALI_TEST_CHECK(meshActor);
319 Renderer renderer = meshActor.GetRendererAt(0u);
320 DALI_TEST_CHECK(renderer);
322 TextureSet textureSet = renderer.GetTextures();
323 DALI_TEST_EQUALS(textureSet.GetTextureCount(), 7u, TEST_LOCATION);
325 Texture diffuseTexture = textureSet.GetTexture(5u);
326 Texture specularTexture = textureSet.GetTexture(6u);
328 view.SetImageBasedLightSource(TEST_DIFFUSE_TEXTURE, TEST_SPECULAR_TEXTURE);
330 Texture newDiffuseTexture = textureSet.GetTexture(5u);
331 Texture newSpecularTexture = textureSet.GetTexture(6u);
333 DALI_TEST_NOT_EQUALS(diffuseTexture, newDiffuseTexture, 0.0f, TEST_LOCATION);
334 DALI_TEST_NOT_EQUALS(specularTexture, newSpecularTexture, 0.0f, TEST_LOCATION);
339 int UtcDaliModelViewSetImageBasedLightSource02(void)
341 ToolkitTestApplication application;
343 Scene3D::ModelView view = Scene3D::ModelView::New(TEST_GLTF_FILE_NAME);
345 application.GetScene().Add(view);
347 application.SendNotification();
348 application.Render();
350 Actor meshActor = view.FindChildByName("AnimatedCube");
351 DALI_TEST_CHECK(meshActor);
353 Renderer renderer = meshActor.GetRendererAt(0u);
354 DALI_TEST_CHECK(renderer);
356 TextureSet textureSet = renderer.GetTextures();
357 DALI_TEST_EQUALS(textureSet.GetTextureCount(), 7u, TEST_LOCATION);
359 Texture diffuseTexture = textureSet.GetTexture(5u);
360 Texture specularTexture = textureSet.GetTexture(6u);
362 view.SetImageBasedLightSource("", "");
364 Texture newDiffuseTexture = textureSet.GetTexture(5u);
365 Texture newSpecularTexture = textureSet.GetTexture(6u);
367 DALI_TEST_EQUALS(diffuseTexture, newDiffuseTexture, TEST_LOCATION);
368 DALI_TEST_EQUALS(specularTexture, newSpecularTexture, TEST_LOCATION);
373 int UtcDaliModelViewSetImageBasedLightSource03(void)
375 ToolkitTestApplication application;
377 Scene3D::ModelView view = Scene3D::ModelView::New(TEST_GLTF_FILE_NAME);
379 application.GetScene().Add(view);
381 application.SendNotification();
382 application.Render();
384 Actor meshActor = view.FindChildByName("AnimatedCube");
385 DALI_TEST_CHECK(meshActor);
387 Renderer renderer = meshActor.GetRendererAt(0u);
388 DALI_TEST_CHECK(renderer);
390 TextureSet textureSet = renderer.GetTextures();
391 DALI_TEST_EQUALS(textureSet.GetTextureCount(), 7u, TEST_LOCATION);
393 Texture diffuseTexture = textureSet.GetTexture(5u);
394 Texture specularTexture = textureSet.GetTexture(6u);
396 view.SetImageBasedLightSource("dummy.ktx", "dummy.ktx");
398 Texture newDiffuseTexture = textureSet.GetTexture(5u);
399 Texture newSpecularTexture = textureSet.GetTexture(6u);
401 DALI_TEST_EQUALS(diffuseTexture, newDiffuseTexture, TEST_LOCATION);
402 DALI_TEST_EQUALS(specularTexture, newSpecularTexture, TEST_LOCATION);
407 int UtcDaliModelViewFitSize01(void)
409 ToolkitTestApplication application;
411 Scene3D::ModelView view = Scene3D::ModelView::New(TEST_GLTF_FILE_NAME);
412 view.SetProperty(Dali::Actor::Property::SIZE, Vector2(50, 50));
414 application.GetScene().Add(view);
416 application.SendNotification();
417 application.Render();
419 Actor rootActor = view.GetModelRoot();
420 Vector3 rootSize = rootActor.GetProperty<Vector3>(Dali::Actor::Property::SIZE);
421 DALI_TEST_EQUALS(Vector3(2, 2, 2), rootSize, TEST_LOCATION);
423 Vector3 rootScale = rootActor.GetProperty<Vector3>(Dali::Actor::Property::SCALE);
424 DALI_TEST_EQUALS(Vector3(1, 1, 1), rootScale, TEST_LOCATION);
427 rootSize = rootActor.GetProperty<Vector3>(Dali::Actor::Property::SIZE);
428 DALI_TEST_EQUALS(Vector3(2, 2, 2), rootSize, TEST_LOCATION);
430 rootScale = rootActor.GetProperty<Vector3>(Dali::Actor::Property::SCALE);
431 DALI_TEST_EQUALS(Vector3(25, 25, 25), rootScale, TEST_LOCATION);
436 int UtcDaliModelViewFitSize02(void)
438 ToolkitTestApplication application;
440 Scene3D::ModelView view = Scene3D::ModelView::New(TEST_GLTF_FILE_NAME);
441 view.SetProperty(Dali::Actor::Property::SIZE, Vector2(0, 0));
443 application.GetScene().Add(view);
445 application.SendNotification();
446 application.Render();
448 Actor rootActor = view.GetModelRoot();
449 Vector3 rootSize = rootActor.GetProperty<Vector3>(Dali::Actor::Property::SIZE);
450 DALI_TEST_EQUALS(Vector3(2, 2, 2), rootSize, TEST_LOCATION);
452 Vector3 rootScale = rootActor.GetProperty<Vector3>(Dali::Actor::Property::SCALE);
453 DALI_TEST_EQUALS(Vector3(1, 1, 1), rootScale, TEST_LOCATION);
456 rootSize = rootActor.GetProperty<Vector3>(Dali::Actor::Property::SIZE);
457 DALI_TEST_EQUALS(Vector3(2, 2, 2), rootSize, TEST_LOCATION);
459 rootScale = rootActor.GetProperty<Vector3>(Dali::Actor::Property::SCALE);
460 DALI_TEST_EQUALS(Vector3(1, 1, 1), rootScale, TEST_LOCATION);
465 int UtcDaliModelViewFitCenter(void)
467 ToolkitTestApplication application;
469 Scene3D::ModelView view = Scene3D::ModelView::New(TEST_GLTF_TRIANGLE_FILE_NAME);
470 view.SetProperty(Dali::Actor::Property::SIZE, Vector2(50, 50));
472 application.GetScene().Add(view);
474 application.SendNotification();
475 application.Render();
477 Vector3 naturalSize = view.GetNaturalSize();
478 DALI_TEST_EQUALS(Vector3(1, 1, 0), naturalSize, TEST_LOCATION);
480 Actor rootActor = view.GetModelRoot();
481 Vector3 anchorPoint = rootActor.GetProperty<Vector3>(Dali::Actor::Property::ANCHOR_POINT);
482 DALI_TEST_EQUALS(Vector3(0.5, 0.5, 0.5), anchorPoint, TEST_LOCATION);
484 view.FitCenter(true);
485 anchorPoint = rootActor.GetProperty<Vector3>(Dali::Actor::Property::ANCHOR_POINT);
486 DALI_TEST_EQUALS(Vector3(1.0, 1.0, 0.5), anchorPoint, TEST_LOCATION);
491 int UtcDaliModelViewAnimation01(void)
493 ToolkitTestApplication application;
495 Scene3D::ModelView view = Scene3D::ModelView::New(TEST_GLTF_FILE_NAME);
496 view.SetProperty(Dali::Actor::Property::SIZE, Vector2(50, 50));
498 application.GetScene().Add(view);
500 application.SendNotification();
501 application.Render();
503 uint32_t animationCount = view.GetAnimationCount();
504 DALI_TEST_EQUALS(1, animationCount, TEST_LOCATION);
506 Animation animationByIndex = view.GetAnimation(0u);
507 DALI_TEST_CHECK(animationByIndex);
509 Animation animationByName = view.GetAnimation("animation_AnimatedCube");
510 DALI_TEST_CHECK(animationByName);
511 DALI_TEST_EQUALS(animationByIndex, animationByName, TEST_LOCATION);
516 int UtcDaliModelViewAnimation02(void)
518 ToolkitTestApplication application;
520 Scene3D::ModelView view = Scene3D::ModelView::New(TEST_GLTF_ANIMATION_TEST_FILE_NAME);
521 view.SetProperty(Dali::Actor::Property::SIZE, Vector2(50, 50));
523 application.GetScene().Add(view);
525 application.SendNotification();
526 application.Render();
528 uint32_t animationCount = view.GetAnimationCount();
529 DALI_TEST_EQUALS(9, animationCount, TEST_LOCATION);
531 Animation animation1 = view.GetAnimation("Step Scale");
532 DALI_TEST_CHECK(animation1);
533 DALI_TEST_EQUALS(1.66667f, animation1.GetDuration(), 0.001f, TEST_LOCATION);
535 Animation animation2 = view.GetAnimation("CubicSpline Scale");
536 DALI_TEST_CHECK(animation2);
537 DALI_TEST_EQUALS(1.66667f, animation2.GetDuration(), 0.001f, TEST_LOCATION);
539 DALI_TEST_NOT_EQUALS(animation1, animation2, 0.0f, TEST_LOCATION);