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";
49 const char* TEST_DLI_BEER_FILE_NAME = TEST_RESOURCE_DIR "/beer_modelViewTest.dli";
51 * For the diffuse and specular cube map texture.
52 * These textures are based off version of Wave engine sample
53 * Take from https://github.com/WaveEngine/Samples
55 * Copyright (c) 2022 Wave Coorporation
57 * Permission is hereby granted, free of charge, to any person obtaining a copy
58 * of this software and associated documentation files (the "Software"), to
59 * deal in the Software without restriction, including without limitation the
60 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
61 * sell copies of the Software, and to permit persons to whom the Software is
62 * furnished to do so, subject to the following conditions:
64 * The above copyright notice and this permission notice shall be included in
65 * all copies or substantial portions of the Software.
67 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
68 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
69 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
70 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
71 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
72 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
75 const char* TEST_DIFFUSE_TEXTURE = TEST_RESOURCE_DIR "/forest_irradiance.ktx";
76 const char* TEST_SPECULAR_TEXTURE = TEST_RESOURCE_DIR "/forest_radiance.ktx";
79 // Negative test case for a method
80 int UtcDaliModelViewUninitialized(void)
82 ToolkitTestApplication application;
83 tet_infoline(" UtcDaliModelViewUninitialized");
85 Scene3D::ModelView view;
89 // New() must be called to create a ModelView or it wont be valid.
90 Actor a = Actor::New();
92 DALI_TEST_CHECK(false);
94 catch(Dali::DaliException& e)
96 // Tests that a negative test of an assertion succeeds
97 DALI_TEST_PRINT_ASSERT(e);
98 DALI_TEST_CHECK(!view);
103 // Positive test case for a method
104 int UtcDaliModelViewNew(void)
106 ToolkitTestApplication application;
107 tet_infoline(" UtcDaliModelViewNew");
109 Scene3D::ModelView view = Scene3D::ModelView::New(TEST_GLTF_FILE_NAME);
110 DALI_TEST_CHECK(view);
114 // Positive test case for a method
115 int UtcDaliModelViewDownCast(void)
117 ToolkitTestApplication application;
118 tet_infoline(" UtcDaliModelViewDownCast");
120 Scene3D::ModelView view = Scene3D::ModelView::New(TEST_GLTF_FILE_NAME);
121 BaseHandle handle(view);
123 Scene3D::ModelView modelView = Scene3D::ModelView::DownCast(handle);
124 DALI_TEST_CHECK(view);
125 DALI_TEST_CHECK(modelView);
126 DALI_TEST_CHECK(modelView == view);
130 int UtcDaliModelViewTypeRegistry(void)
132 ToolkitTestApplication application;
134 TypeRegistry typeRegistry = TypeRegistry::Get();
135 DALI_TEST_CHECK(typeRegistry);
137 TypeInfo typeInfo = typeRegistry.GetTypeInfo("ModelView");
138 DALI_TEST_CHECK(typeInfo);
140 BaseHandle handle = typeInfo.CreateInstance();
141 DALI_TEST_CHECK(handle);
143 Scene3D::ModelView modelView = Scene3D::ModelView::DownCast(handle);
144 DALI_TEST_CHECK(modelView);
149 // Positive test case for a method
150 int UtcDaliModelViewAddRemove(void)
152 ToolkitTestApplication application;
153 tet_infoline(" UtcDaliModelViewAddRemove");
155 Scene3D::ModelView view = Scene3D::ModelView::New(TEST_GLTF_FILE_NAME);
156 DALI_TEST_CHECK(view);
158 Actor actor = Actor::New();
159 DALI_TEST_CHECK(!actor.GetProperty<bool>(Actor::Property::CONNECTED_TO_SCENE));
161 view.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
162 view.SetProperty(Actor::Property::SIZE, application.GetScene().GetSize());
164 application.GetScene().Add(view);
166 DALI_TEST_CHECK(actor.GetProperty<bool>(Actor::Property::CONNECTED_TO_SCENE));
170 DALI_TEST_CHECK(!actor.GetProperty<bool>(Actor::Property::CONNECTED_TO_SCENE));
174 int UtcDaliModelViewCopyAndAssignment(void)
176 ToolkitTestApplication application;
178 Scene3D::ModelView view = Scene3D::ModelView::New(TEST_GLTF_FILE_NAME);
179 DALI_TEST_CHECK(view);
181 Scene3D::ModelView copy(view);
182 DALI_TEST_CHECK(view == copy);
184 Scene3D::ModelView assign;
185 DALI_TEST_CHECK(!assign);
188 DALI_TEST_CHECK(assign == view);
193 int UtcDaliModelViewMoveConstructor(void)
195 ToolkitTestApplication application;
197 Scene3D::ModelView view = Scene3D::ModelView::New(TEST_GLTF_FILE_NAME);
198 DALI_TEST_EQUALS(1, view.GetBaseObject().ReferenceCount(), TEST_LOCATION);
199 view.SetProperty(Actor::Property::SENSITIVE, false);
200 DALI_TEST_CHECK(false == view.GetProperty<bool>(Actor::Property::SENSITIVE));
202 Scene3D::ModelView moved = std::move(view);
203 DALI_TEST_CHECK(moved);
204 DALI_TEST_EQUALS(1, moved.GetBaseObject().ReferenceCount(), TEST_LOCATION);
205 DALI_TEST_CHECK(false == moved.GetProperty<bool>(Actor::Property::SENSITIVE));
206 DALI_TEST_CHECK(!view);
211 int UtcDaliModelViewMoveAssignment(void)
213 ToolkitTestApplication application;
215 Scene3D::ModelView view = Scene3D::ModelView::New(TEST_GLTF_FILE_NAME);
216 DALI_TEST_EQUALS(1, view.GetBaseObject().ReferenceCount(), TEST_LOCATION);
217 view.SetProperty(Actor::Property::SENSITIVE, false);
218 DALI_TEST_CHECK(false == view.GetProperty<bool>(Actor::Property::SENSITIVE));
220 Scene3D::ModelView moved;
221 moved = std::move(view);
222 DALI_TEST_CHECK(moved);
223 DALI_TEST_EQUALS(1, moved.GetBaseObject().ReferenceCount(), TEST_LOCATION);
224 DALI_TEST_CHECK(false == moved.GetProperty<bool>(Actor::Property::SENSITIVE));
225 DALI_TEST_CHECK(!view);
230 int UtcDaliModelViewOnScene01(void)
232 ToolkitTestApplication application;
234 Scene3D::ModelView view = Scene3D::ModelView::New(TEST_GLTF_FILE_NAME);
236 application.GetScene().Add(view);
238 application.SendNotification();
239 application.Render();
241 uint32_t modelCount = view.GetModelRoot().GetChildCount();
242 DALI_TEST_EQUALS(1, modelCount, TEST_LOCATION);
247 int UtcDaliModelViewOnScene02(void)
249 ToolkitTestApplication application;
251 Scene3D::ModelView view = Scene3D::ModelView::New(TEST_DLI_FILE_NAME);
253 application.GetScene().Add(view);
255 application.SendNotification();
256 application.Render();
258 uint32_t modelCount = view.GetModelRoot().GetChildCount();
259 DALI_TEST_EQUALS(1, modelCount, TEST_LOCATION);
261 Actor rootActor = view.GetModelRoot();
262 Vector3 rootSize = rootActor.GetProperty<Vector3>(Dali::Actor::Property::SIZE);
263 DALI_TEST_EQUALS(Vector3(2, 2, 1), rootSize, TEST_LOCATION);
268 int UtcDaliModelViewOnSizeSet(void)
270 ToolkitTestApplication application;
272 Scene3D::ModelView view = Scene3D::ModelView::New(TEST_GLTF_FILE_NAME);
274 application.GetScene().Add(view);
276 application.SendNotification();
277 application.Render();
279 Vector2 size(200.0f, 300.0f);
280 view.SetProperty(Actor::Property::SIZE, size);
282 application.SendNotification();
283 application.Render();
285 DALI_TEST_EQUALS(view.GetCurrentProperty<Vector2>(Actor::Property::SIZE), size, TEST_LOCATION);
290 int UtcDaliModelViewGetNaturalSize(void)
292 ToolkitTestApplication application;
294 Scene3D::ModelView view = Scene3D::ModelView::New(TEST_GLTF_FILE_NAME);
296 Vector3 naturalSize = view.GetNaturalSize();
298 DALI_TEST_EQUALS(Vector3(2, 2, 2), naturalSize, TEST_LOCATION);
300 Actor root = view.GetModelRoot();
301 DALI_TEST_CHECK(root);
306 int UtcDaliModelViewSetImageBasedLightSource01(void)
308 ToolkitTestApplication application;
310 Scene3D::ModelView view = Scene3D::ModelView::New(TEST_GLTF_FILE_NAME);
312 application.GetScene().Add(view);
314 application.SendNotification();
315 application.Render();
317 Actor meshActor = view.FindChildByName("AnimatedCube");
318 DALI_TEST_CHECK(meshActor);
320 Renderer renderer = meshActor.GetRendererAt(0u);
321 DALI_TEST_CHECK(renderer);
323 TextureSet textureSet = renderer.GetTextures();
324 DALI_TEST_EQUALS(textureSet.GetTextureCount(), 7u, TEST_LOCATION);
326 Texture diffuseTexture = textureSet.GetTexture(5u);
327 Texture specularTexture = textureSet.GetTexture(6u);
329 view.SetImageBasedLightSource(TEST_DIFFUSE_TEXTURE, TEST_SPECULAR_TEXTURE);
331 Texture newDiffuseTexture = textureSet.GetTexture(5u);
332 Texture newSpecularTexture = textureSet.GetTexture(6u);
334 DALI_TEST_NOT_EQUALS(diffuseTexture, newDiffuseTexture, 0.0f, TEST_LOCATION);
335 DALI_TEST_NOT_EQUALS(specularTexture, newSpecularTexture, 0.0f, TEST_LOCATION);
340 int UtcDaliModelViewSetImageBasedLightSource02(void)
342 ToolkitTestApplication application;
344 Scene3D::ModelView view = Scene3D::ModelView::New(TEST_GLTF_FILE_NAME);
346 application.GetScene().Add(view);
348 application.SendNotification();
349 application.Render();
351 Actor meshActor = view.FindChildByName("AnimatedCube");
352 DALI_TEST_CHECK(meshActor);
354 Renderer renderer = meshActor.GetRendererAt(0u);
355 DALI_TEST_CHECK(renderer);
357 TextureSet textureSet = renderer.GetTextures();
358 DALI_TEST_EQUALS(textureSet.GetTextureCount(), 7u, TEST_LOCATION);
360 Texture diffuseTexture = textureSet.GetTexture(5u);
361 Texture specularTexture = textureSet.GetTexture(6u);
363 view.SetImageBasedLightSource("", "");
365 Texture newDiffuseTexture = textureSet.GetTexture(5u);
366 Texture newSpecularTexture = textureSet.GetTexture(6u);
368 DALI_TEST_EQUALS(diffuseTexture, newDiffuseTexture, TEST_LOCATION);
369 DALI_TEST_EQUALS(specularTexture, newSpecularTexture, TEST_LOCATION);
374 int UtcDaliModelViewSetImageBasedLightSource03(void)
376 ToolkitTestApplication application;
378 Scene3D::ModelView view = Scene3D::ModelView::New(TEST_GLTF_FILE_NAME);
380 application.GetScene().Add(view);
382 application.SendNotification();
383 application.Render();
385 Actor meshActor = view.FindChildByName("AnimatedCube");
386 DALI_TEST_CHECK(meshActor);
388 Renderer renderer = meshActor.GetRendererAt(0u);
389 DALI_TEST_CHECK(renderer);
391 TextureSet textureSet = renderer.GetTextures();
392 DALI_TEST_EQUALS(textureSet.GetTextureCount(), 7u, TEST_LOCATION);
394 Texture diffuseTexture = textureSet.GetTexture(5u);
395 Texture specularTexture = textureSet.GetTexture(6u);
397 view.SetImageBasedLightSource("dummy.ktx", "dummy.ktx");
399 Texture newDiffuseTexture = textureSet.GetTexture(5u);
400 Texture newSpecularTexture = textureSet.GetTexture(6u);
402 DALI_TEST_EQUALS(diffuseTexture, newDiffuseTexture, TEST_LOCATION);
403 DALI_TEST_EQUALS(specularTexture, newSpecularTexture, TEST_LOCATION);
408 int UtcDaliModelViewFitSize01(void)
410 ToolkitTestApplication application;
412 Scene3D::ModelView view = Scene3D::ModelView::New(TEST_GLTF_FILE_NAME);
413 view.SetProperty(Dali::Actor::Property::SIZE, Vector2(50, 50));
415 application.GetScene().Add(view);
417 application.SendNotification();
418 application.Render();
420 Actor rootActor = view.GetModelRoot();
421 Vector3 rootSize = rootActor.GetProperty<Vector3>(Dali::Actor::Property::SIZE);
422 DALI_TEST_EQUALS(Vector3(2, 2, 2), rootSize, TEST_LOCATION);
424 Vector3 rootScale = rootActor.GetProperty<Vector3>(Dali::Actor::Property::SCALE);
425 DALI_TEST_EQUALS(Vector3(1, 1, 1), rootScale, TEST_LOCATION);
428 rootSize = rootActor.GetProperty<Vector3>(Dali::Actor::Property::SIZE);
429 DALI_TEST_EQUALS(Vector3(2, 2, 2), rootSize, TEST_LOCATION);
431 rootScale = rootActor.GetProperty<Vector3>(Dali::Actor::Property::SCALE);
432 DALI_TEST_EQUALS(Vector3(25, 25, 25), rootScale, TEST_LOCATION);
437 int UtcDaliModelViewFitSize02(void)
439 ToolkitTestApplication application;
441 Scene3D::ModelView view = Scene3D::ModelView::New(TEST_DLI_BEER_FILE_NAME);
442 view.SetProperty(Dali::Actor::Property::SIZE, Vector2(50, 50));
444 application.GetScene().Add(view);
446 application.SendNotification();
447 application.Render();
449 Actor rootActor = view.GetModelRoot();
450 Vector3 rootSize = rootActor.GetProperty<Vector3>(Dali::Actor::Property::SIZE);
451 DALI_TEST_EQUALS(Vector3(5, 5, 5), rootSize, TEST_LOCATION);
453 Vector3 rootScale = rootActor.GetProperty<Vector3>(Dali::Actor::Property::SCALE);
454 DALI_TEST_EQUALS(Vector3(1, 1, 1), rootScale, TEST_LOCATION);
457 rootSize = rootActor.GetProperty<Vector3>(Dali::Actor::Property::SIZE);
458 DALI_TEST_EQUALS(Vector3(5, 5, 5), rootSize, TEST_LOCATION);
460 rootScale = rootActor.GetProperty<Vector3>(Dali::Actor::Property::SCALE);
461 DALI_TEST_EQUALS(Vector3(10, 10, 10), rootScale, TEST_LOCATION);
466 int UtcDaliModelViewFitSize03(void)
468 ToolkitTestApplication application;
470 Scene3D::ModelView view = Scene3D::ModelView::New(TEST_GLTF_FILE_NAME);
471 view.SetProperty(Dali::Actor::Property::SIZE, Vector2(0, 0));
473 application.GetScene().Add(view);
475 application.SendNotification();
476 application.Render();
478 Actor rootActor = view.GetModelRoot();
479 Vector3 rootSize = rootActor.GetProperty<Vector3>(Dali::Actor::Property::SIZE);
480 DALI_TEST_EQUALS(Vector3(2, 2, 2), rootSize, TEST_LOCATION);
482 Vector3 rootScale = rootActor.GetProperty<Vector3>(Dali::Actor::Property::SCALE);
483 DALI_TEST_EQUALS(Vector3(1, 1, 1), rootScale, TEST_LOCATION);
486 rootSize = rootActor.GetProperty<Vector3>(Dali::Actor::Property::SIZE);
487 DALI_TEST_EQUALS(Vector3(2, 2, 2), rootSize, TEST_LOCATION);
489 rootScale = rootActor.GetProperty<Vector3>(Dali::Actor::Property::SCALE);
490 DALI_TEST_EQUALS(Vector3(1, 1, 1), rootScale, TEST_LOCATION);
495 int UtcDaliModelViewFitCenter(void)
497 ToolkitTestApplication application;
499 Scene3D::ModelView view = Scene3D::ModelView::New(TEST_GLTF_TRIANGLE_FILE_NAME);
500 view.SetProperty(Dali::Actor::Property::SIZE, Vector2(50, 50));
502 application.GetScene().Add(view);
504 application.SendNotification();
505 application.Render();
507 Vector3 naturalSize = view.GetNaturalSize();
508 DALI_TEST_EQUALS(Vector3(1, 1, 0), naturalSize, TEST_LOCATION);
510 Actor rootActor = view.GetModelRoot();
511 Vector3 anchorPoint = rootActor.GetProperty<Vector3>(Dali::Actor::Property::ANCHOR_POINT);
512 DALI_TEST_EQUALS(Vector3(0.5, 0.5, 0.5), anchorPoint, TEST_LOCATION);
514 view.FitCenter(true);
515 anchorPoint = rootActor.GetProperty<Vector3>(Dali::Actor::Property::ANCHOR_POINT);
516 DALI_TEST_EQUALS(Vector3(1.0, 1.0, 0.5), anchorPoint, TEST_LOCATION);
521 int UtcDaliModelViewAnimation01(void)
523 ToolkitTestApplication application;
525 Scene3D::ModelView view = Scene3D::ModelView::New(TEST_GLTF_FILE_NAME);
526 view.SetProperty(Dali::Actor::Property::SIZE, Vector2(50, 50));
528 application.GetScene().Add(view);
530 application.SendNotification();
531 application.Render();
533 uint32_t animationCount = view.GetAnimationCount();
534 DALI_TEST_EQUALS(1, animationCount, TEST_LOCATION);
536 Animation animationByIndex = view.GetAnimation(0u);
537 DALI_TEST_CHECK(animationByIndex);
539 Animation animationByName = view.GetAnimation("animation_AnimatedCube");
540 DALI_TEST_CHECK(animationByName);
541 DALI_TEST_EQUALS(animationByIndex, animationByName, TEST_LOCATION);
546 int UtcDaliModelViewAnimation02(void)
548 ToolkitTestApplication application;
550 Scene3D::ModelView view = Scene3D::ModelView::New(TEST_GLTF_ANIMATION_TEST_FILE_NAME);
551 view.SetProperty(Dali::Actor::Property::SIZE, Vector2(50, 50));
553 application.GetScene().Add(view);
555 application.SendNotification();
556 application.Render();
558 uint32_t animationCount = view.GetAnimationCount();
559 DALI_TEST_EQUALS(9, animationCount, TEST_LOCATION);
561 Animation animation1 = view.GetAnimation("Step Scale");
562 DALI_TEST_CHECK(animation1);
563 DALI_TEST_EQUALS(1.66667f, animation1.GetDuration(), 0.001f, TEST_LOCATION);
565 Animation animation2 = view.GetAnimation("CubicSpline Scale");
566 DALI_TEST_CHECK(animation2);
567 DALI_TEST_EQUALS(1.66667f, animation2.GetDuration(), 0.001f, TEST_LOCATION);
569 DALI_TEST_NOT_EQUALS(animation1, animation2, 0.0f, TEST_LOCATION);