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-scene3d/public-api/controls/model/model.h>
26 using namespace Dali::Toolkit;
28 void model_startup(void)
30 test_return_value = TET_UNDEF;
33 void model_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_ANIMATION_TEST_FILE_NAME = TEST_RESOURCE_DIR "/animationTest.gltf";
47 const char* TEST_DLI_FILE_NAME = TEST_RESOURCE_DIR "/arc.dli";
49 * For the diffuse and specular cube map texture.
50 * These textures are based off version of Wave engine sample
51 * Take from https://github.com/WaveEngine/Samples
53 * Copyright (c) 2022 Wave Coorporation
55 * Permission is hereby granted, free of charge, to any person obtaining a copy
56 * of this software and associated documentation files (the "Software"), to
57 * deal in the Software without restriction, including without limitation the
58 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
59 * sell copies of the Software, and to permit persons to whom the Software is
60 * furnished to do so, subject to the following conditions:
62 * The above copyright notice and this permission notice shall be included in
63 * all copies or substantial portions of the Software.
65 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
66 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
67 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
68 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
69 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
70 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
73 const char* TEST_DIFFUSE_TEXTURE = TEST_RESOURCE_DIR "/forest_irradiance.ktx";
74 const char* TEST_SPECULAR_TEXTURE = TEST_RESOURCE_DIR "/forest_radiance.ktx";
77 // Negative test case for a method
78 int UtcDaliModelUninitialized(void)
80 ToolkitTestApplication application;
81 tet_infoline(" UtcDaliModelUninitialized");
87 // New() must be called to create a Model or it wont be valid.
88 Actor a = Actor::New();
90 DALI_TEST_CHECK(false);
92 catch(Dali::DaliException& e)
94 // Tests that a negative test of an assertion succeeds
95 DALI_TEST_PRINT_ASSERT(e);
96 DALI_TEST_CHECK(!model);
101 // Positive test case for a method
102 int UtcDaliModelNew(void)
104 ToolkitTestApplication application;
105 tet_infoline(" UtcDaliModelNew");
107 Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
108 DALI_TEST_CHECK(model);
112 // Positive test case for a method
113 int UtcDaliModelDownCast(void)
115 ToolkitTestApplication application;
116 tet_infoline(" UtcDaliModelDownCast");
118 Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
119 BaseHandle handle(model);
121 Scene3D::Model model2 = Scene3D::Model::DownCast(handle);
122 DALI_TEST_CHECK(model);
123 DALI_TEST_CHECK(model2);
124 DALI_TEST_CHECK(model2 == model);
128 int UtcDaliModelTypeRegistry(void)
130 ToolkitTestApplication application;
132 TypeRegistry typeRegistry = TypeRegistry::Get();
133 DALI_TEST_CHECK(typeRegistry);
135 TypeInfo typeInfo = typeRegistry.GetTypeInfo("Model");
136 DALI_TEST_CHECK(typeInfo);
138 BaseHandle handle = typeInfo.CreateInstance();
139 DALI_TEST_CHECK(handle);
141 Scene3D::Model model = Scene3D::Model::DownCast(handle);
142 DALI_TEST_CHECK(model);
147 // Positive test case for a method
148 int UtcDaliModelAddRemove(void)
150 ToolkitTestApplication application;
151 tet_infoline(" UtcDaliModelAddRemove");
153 Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
154 DALI_TEST_CHECK(model);
156 Actor actor = Actor::New();
157 DALI_TEST_CHECK(!actor.GetProperty<bool>(Actor::Property::CONNECTED_TO_SCENE));
159 model.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
160 model.SetProperty(Actor::Property::SIZE, application.GetScene().GetSize());
162 application.GetScene().Add(model);
164 DALI_TEST_CHECK(actor.GetProperty<bool>(Actor::Property::CONNECTED_TO_SCENE));
168 DALI_TEST_CHECK(!actor.GetProperty<bool>(Actor::Property::CONNECTED_TO_SCENE));
172 int UtcDaliModelCopyAndAssignment(void)
174 ToolkitTestApplication application;
176 Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
177 DALI_TEST_CHECK(model);
179 Scene3D::Model copy(model);
180 DALI_TEST_CHECK(model == copy);
182 Scene3D::Model assign;
183 DALI_TEST_CHECK(!assign);
186 DALI_TEST_CHECK(assign == model);
191 int UtcDaliModelMoveConstructor(void)
193 ToolkitTestApplication application;
195 Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
196 DALI_TEST_EQUALS(1, model.GetBaseObject().ReferenceCount(), TEST_LOCATION);
197 model.SetProperty(Actor::Property::SENSITIVE, false);
198 DALI_TEST_CHECK(false == model.GetProperty<bool>(Actor::Property::SENSITIVE));
200 Scene3D::Model moved = std::move(model);
201 DALI_TEST_CHECK(moved);
202 DALI_TEST_EQUALS(1, moved.GetBaseObject().ReferenceCount(), TEST_LOCATION);
203 DALI_TEST_CHECK(false == moved.GetProperty<bool>(Actor::Property::SENSITIVE));
204 DALI_TEST_CHECK(!model);
209 int UtcDaliModelMoveAssignment(void)
211 ToolkitTestApplication application;
213 Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
214 DALI_TEST_EQUALS(1, model.GetBaseObject().ReferenceCount(), TEST_LOCATION);
215 model.SetProperty(Actor::Property::SENSITIVE, false);
216 DALI_TEST_CHECK(false == model.GetProperty<bool>(Actor::Property::SENSITIVE));
218 Scene3D::Model moved;
219 moved = std::move(model);
220 DALI_TEST_CHECK(moved);
221 DALI_TEST_EQUALS(1, moved.GetBaseObject().ReferenceCount(), TEST_LOCATION);
222 DALI_TEST_CHECK(false == moved.GetProperty<bool>(Actor::Property::SENSITIVE));
223 DALI_TEST_CHECK(!model);
228 int UtcDaliModelOnScene01(void)
230 ToolkitTestApplication application;
232 Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
234 application.GetScene().Add(model);
236 application.SendNotification();
237 application.Render();
239 uint32_t modelCount = model.GetModelRoot().GetChildCount();
240 DALI_TEST_EQUALS(1, modelCount, TEST_LOCATION);
245 int UtcDaliModelOnScene02(void)
247 ToolkitTestApplication application;
249 Scene3D::Model model = Scene3D::Model::New(TEST_DLI_FILE_NAME);
251 application.GetScene().Add(model);
253 application.SendNotification();
254 application.Render();
256 uint32_t modelCount = model.GetModelRoot().GetChildCount();
257 DALI_TEST_EQUALS(1, modelCount, TEST_LOCATION);
259 Actor rootActor = model.GetModelRoot();
260 Vector3 rootSize = rootActor.GetProperty<Vector3>(Dali::Actor::Property::SIZE);
261 DALI_TEST_EQUALS(Vector3(2, 2, 1), rootSize, TEST_LOCATION);
266 int UtcDaliModelOnSizeSet(void)
268 ToolkitTestApplication application;
270 Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
272 application.GetScene().Add(model);
274 application.SendNotification();
275 application.Render();
277 Vector2 size(200.0f, 300.0f);
278 model.SetProperty(Actor::Property::SIZE, size);
280 application.SendNotification();
281 application.Render();
283 DALI_TEST_EQUALS(model.GetCurrentProperty<Vector2>(Actor::Property::SIZE), size, TEST_LOCATION);
288 int UtcDaliModelGetNaturalSize(void)
290 ToolkitTestApplication application;
292 Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
294 Vector3 naturalSize = model.GetNaturalSize();
296 DALI_TEST_EQUALS(Vector3(2, 2, 2), naturalSize, TEST_LOCATION);
298 Actor root = model.GetModelRoot();
299 DALI_TEST_CHECK(root);
304 int UtcDaliModelSetImageBasedLightSource01(void)
306 ToolkitTestApplication application;
308 Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
310 application.GetScene().Add(model);
312 application.SendNotification();
313 application.Render();
315 Actor meshActor = model.FindChildByName("AnimatedCube");
316 DALI_TEST_CHECK(meshActor);
318 Renderer renderer = meshActor.GetRendererAt(0u);
319 DALI_TEST_CHECK(renderer);
321 TextureSet textureSet = renderer.GetTextures();
322 DALI_TEST_EQUALS(textureSet.GetTextureCount(), 7u, TEST_LOCATION);
324 Texture diffuseTexture = textureSet.GetTexture(5u);
325 Texture specularTexture = textureSet.GetTexture(6u);
327 model.SetImageBasedLightSource(TEST_DIFFUSE_TEXTURE, TEST_SPECULAR_TEXTURE);
329 Texture newDiffuseTexture = textureSet.GetTexture(5u);
330 Texture newSpecularTexture = textureSet.GetTexture(6u);
332 DALI_TEST_NOT_EQUALS(diffuseTexture, newDiffuseTexture, 0.0f, TEST_LOCATION);
333 DALI_TEST_NOT_EQUALS(specularTexture, newSpecularTexture, 0.0f, TEST_LOCATION);
338 int UtcDaliModelSetImageBasedLightSource02(void)
340 ToolkitTestApplication application;
342 Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
344 application.GetScene().Add(model);
346 application.SendNotification();
347 application.Render();
349 Actor meshActor = model.FindChildByName("AnimatedCube");
350 DALI_TEST_CHECK(meshActor);
352 Renderer renderer = meshActor.GetRendererAt(0u);
353 DALI_TEST_CHECK(renderer);
355 TextureSet textureSet = renderer.GetTextures();
356 DALI_TEST_EQUALS(textureSet.GetTextureCount(), 7u, TEST_LOCATION);
358 Texture diffuseTexture = textureSet.GetTexture(5u);
359 Texture specularTexture = textureSet.GetTexture(6u);
361 model.SetImageBasedLightSource("", "");
363 Texture newDiffuseTexture = textureSet.GetTexture(5u);
364 Texture newSpecularTexture = textureSet.GetTexture(6u);
366 DALI_TEST_EQUALS(diffuseTexture, newDiffuseTexture, TEST_LOCATION);
367 DALI_TEST_EQUALS(specularTexture, newSpecularTexture, TEST_LOCATION);
372 int UtcDaliModelSetImageBasedLightSource03(void)
374 ToolkitTestApplication application;
376 Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
378 application.GetScene().Add(model);
380 application.SendNotification();
381 application.Render();
383 Actor meshActor = model.FindChildByName("AnimatedCube");
384 DALI_TEST_CHECK(meshActor);
386 Renderer renderer = meshActor.GetRendererAt(0u);
387 DALI_TEST_CHECK(renderer);
389 TextureSet textureSet = renderer.GetTextures();
390 DALI_TEST_EQUALS(textureSet.GetTextureCount(), 7u, TEST_LOCATION);
392 Texture diffuseTexture = textureSet.GetTexture(5u);
393 Texture specularTexture = textureSet.GetTexture(6u);
395 model.SetImageBasedLightSource("dummy.ktx", "dummy.ktx");
397 Texture newDiffuseTexture = textureSet.GetTexture(5u);
398 Texture newSpecularTexture = textureSet.GetTexture(6u);
400 DALI_TEST_EQUALS(diffuseTexture, newDiffuseTexture, TEST_LOCATION);
401 DALI_TEST_EQUALS(specularTexture, newSpecularTexture, TEST_LOCATION);
406 int UtcDaliModelImageBasedFactor(void)
408 ToolkitTestApplication application;
410 Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
412 DALI_TEST_EQUALS(model.GetImageBasedLightScaleFactor(), 1.0f, TEST_LOCATION);
414 model.SetImageBasedLightScaleFactor(0.5f);
415 DALI_TEST_EQUALS(model.GetImageBasedLightScaleFactor(), 0.5f, TEST_LOCATION);
419 int UtcDaliModelAnimation01(void)
421 ToolkitTestApplication application;
423 Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_FILE_NAME);
424 model.SetProperty(Dali::Actor::Property::SIZE, Vector2(50, 50));
426 application.GetScene().Add(model);
428 application.SendNotification();
429 application.Render();
431 uint32_t animationCount = model.GetAnimationCount();
432 DALI_TEST_EQUALS(1, animationCount, TEST_LOCATION);
434 Animation animationByIndex = model.GetAnimation(0u);
435 DALI_TEST_CHECK(animationByIndex);
437 Animation animationByName = model.GetAnimation("animation_AnimatedCube");
438 DALI_TEST_CHECK(animationByName);
439 DALI_TEST_EQUALS(animationByIndex, animationByName, TEST_LOCATION);
444 int UtcDaliModelAnimation02(void)
446 ToolkitTestApplication application;
448 Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_ANIMATION_TEST_FILE_NAME);
449 model.SetProperty(Dali::Actor::Property::SIZE, Vector2(50, 50));
451 application.GetScene().Add(model);
453 application.SendNotification();
454 application.Render();
456 uint32_t animationCount = model.GetAnimationCount();
457 DALI_TEST_EQUALS(9, animationCount, TEST_LOCATION);
459 Animation animation1 = model.GetAnimation("Step Scale");
460 DALI_TEST_CHECK(animation1);
461 DALI_TEST_EQUALS(1.66667f, animation1.GetDuration(), 0.001f, TEST_LOCATION);
463 Animation animation2 = model.GetAnimation("CubicSpline Scale");
464 DALI_TEST_CHECK(animation2);
465 DALI_TEST_EQUALS(1.66667f, animation2.GetDuration(), 0.001f, TEST_LOCATION);
467 DALI_TEST_NOT_EQUALS(animation1, animation2, 0.0f, TEST_LOCATION);
475 static bool gOnRelayoutCallBackCalled = false;
476 void OnRelayoutCallback(Actor actor)
478 gOnRelayoutCallBackCalled = true;
481 static bool gResourceReadyCalled = false;
482 void OnResourceReady(Control control)
484 gResourceReadyCalled = true;
488 int UtcDaliModelResourceReady(void)
490 ToolkitTestApplication application;
492 gOnRelayoutCallBackCalled = false;
493 gResourceReadyCalled = false;
494 Scene3D::Model model = Scene3D::Model::New(TEST_GLTF_ANIMATION_TEST_FILE_NAME);
495 model.SetProperty(Actor::Property::SIZE, Vector2(100.0f, 100.0f));
496 model.OnRelayoutSignal().Connect(OnRelayoutCallback);
497 model.ResourceReadySignal().Connect(OnResourceReady);
498 DALI_TEST_EQUALS(model.IsResourceReady(), false, TEST_LOCATION);
501 DALI_TEST_CHECK(!gOnRelayoutCallBackCalled);
502 DALI_TEST_CHECK(!gResourceReadyCalled);
504 application.GetScene().Add(model);
506 application.SendNotification();
507 application.Render();
509 DALI_TEST_EQUALS(gOnRelayoutCallBackCalled, false, TEST_LOCATION);
510 DALI_TEST_EQUALS(model.IsResourceReady(), true, TEST_LOCATION);
511 DALI_TEST_EQUALS(gResourceReadyCalled, true, TEST_LOCATION);