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 // Enable debug log for test coverage
19 #define DEBUG_ENABLED 1
21 #include <dali-test-suite-utils.h>
22 #include <string_view>
23 #include "dali-scene3d/internal/loader/json-util.h"
24 #include "dali-scene3d/public-api/loader/dli-loader.h"
25 #include "dali-scene3d/public-api/loader/load-result.h"
26 #include "dali-scene3d/public-api/loader/resource-bundle.h"
27 #include "dali-scene3d/public-api/loader/scene-definition.h"
30 using namespace Dali::Scene3D::Loader;
34 void ConfigureBlendShapeShaders(ResourceBundle& resources, const SceneDefinition& scene, Actor root, std::vector<BlendshapeShaderConfigurationRequest>&& requests)
36 std::vector<std::string> errors;
37 auto onError = [&errors](const std::string& msg) {
38 errors.push_back(msg);
41 if(!scene.ConfigureBlendshapeShaders(resources, root, std::move(requests), onError))
43 ExceptionFlinger flinger(ASSERT_LOCATION);
44 for(auto& msg : errors)
46 flinger << msg << '\n';
53 ResourceBundle::PathProvider pathProvider = [](ResourceType::Value type) {
54 return TEST_RESOURCE_DIR "/";
57 ResourceBundle resources;
58 SceneDefinition scene;
59 std::vector<CameraParameters> cameraParameters;
60 std::vector<LightParameters> lights;
61 std::vector<AnimationDefinition> animations;
62 std::vector<AnimationGroupDefinition> animGroups;
72 DliLoader::InputParams input{
73 pathProvider(ResourceType::Mesh),
79 DliLoader::LoadParams loadParams{input, output};
81 std::vector<std::string> errors;
84 StringCallback onError = [this](const std::string& error) {
85 errors.push_back(error);
86 printf("%s\n", error.c_str());
91 loader.SetErrorCallback(onError);
95 bool StringHasTokens(const char* string, const std::vector<const char*>& tokens)
97 for(auto& token : tokens)
99 auto result = strstr(string, token);
100 if(nullptr == result)
104 string = result + strlen(token);
111 int UtcDaliDliLoaderLoadSceneNotFound(void)
115 DALI_TEST_EQUAL(ctx.loader.LoadScene("does_not_exist.dli", ctx.loadParams), false);
117 auto error = ctx.loader.GetParseError();
118 DALI_TEST_CHECK(StringHasTokens(error.c_str(), {"Empty source buffer to parse."}));
123 int UtcDaliDliLoaderLoadSceneFailParse(void)
127 auto path = ctx.pathProvider(ResourceType::Mesh) + "invalid.gltf";
128 DALI_TEST_EQUAL(ctx.loader.LoadScene(path, ctx.loadParams), false);
130 auto error = ctx.loader.GetParseError();
131 DALI_TEST_CHECK(StringHasTokens(error.c_str(), {"Unexpected character."}));
136 int UtcDaliDliLoaderLoadSceneAssertions(void)
138 const std::pair<std::string, std::string> pathExceptionPairs[]{
139 // from RequireChild()
140 {"scenes-nodes-missing", "Failed to find child node"},
141 {"scenes-missing", "Failed to find child node"},
142 {"nodes-missing", "Failed to find child node"},
143 // from ParseSceneInternal()
144 {"scene-out-of-bounds", "out of bounds"},
145 {"nodes-invalid-type", "invalid type; array required"},
146 {"nodes-array-empty", "must define a node id"},
147 {"root-id-invalid", "invalid value for root node index"},
148 {"root-id-out-of-bounds", "out of bounds"},
149 {"root-node-invalid-type", "invalid JSON type; object required"},
150 // from ParseSkeletons()
151 {"skeleton-node-missing", "Missing required attribute"},
152 {"skeleton-root-not-found", "not defined"},
153 // from ParseShaders()
154 {"shader-vertex-missing", "Missing vertex / fragment shader"},
155 {"shader-fragment-missing", "Missing vertex / fragment shader"},
156 // from ParseMeshes()
157 {"mesh-uri-missing", "Missing required attribute"},
158 {"mesh-indices-read-fail", "Failed to read indices"},
159 {"mesh-positions-read-fail", "Failed to read positions"},
160 // from ParseMaterials()
161 {"material-environment-out-of-bounds", "out of bounds"},
163 {"node-model-mesh-missing", "Missing mesh"},
164 {"node-arc-mesh-missing", "Missing mesh"},
165 {"node-animated-image-mesh-missing", "Missing mesh"},
166 {"node-renderable-mesh-invalid-type", "Invalid Mesh index type"},
167 {"node-renderable-mesh-out-of-bounds", "out of bounds"},
168 {"node-child-invalid-type", "invalid index type"},
169 {"node-name-already-used", "name already used"},
170 // from ParseAnimations()
171 {"animation-failed-to-open", "Failed to open animation data"}};
172 for(auto& i : pathExceptionPairs)
176 auto path = ctx.pathProvider(ResourceType::Mesh) + "dli/" + i.first + ".dli";
177 printf("\n\n%s: %s\n", path.c_str(), i.second.c_str());
178 DALI_TEST_ASSERTION(ctx.loader.LoadScene(path, ctx.loadParams), i.second.c_str());
184 int UtcDaliDliLoaderLoadSceneExercise(void)
188 auto path = ctx.pathProvider(ResourceType::Mesh) + "exercise.dli";
189 DALI_TEST_CHECK(ctx.loader.LoadScene(path, ctx.loadParams));
190 DALI_TEST_CHECK(ctx.errors.empty());
192 auto& scene = ctx.scene;
193 auto& roots = scene.GetRoots();
194 DALI_TEST_EQUAL(roots.size(), 2u);
195 DALI_TEST_EQUAL(scene.GetNode(roots[0])->mName, "Backdrop"); // default scene is scene 1 - this one.
196 DALI_TEST_EQUAL(scene.GetNode(roots[1])->mName, "ExerciseDemo");
198 DALI_TEST_EQUAL(scene.GetNodeCount(), 96u);
200 auto& resources = ctx.resources;
201 DALI_TEST_EQUAL(resources.mMeshes.size(), 11u);
202 DALI_TEST_EQUAL(resources.mMaterials.size(), 13u);
203 DALI_TEST_EQUAL(resources.mShaders.size(), 5u);
204 DALI_TEST_EQUAL(resources.mEnvironmentMaps.size(), 2u);
205 DALI_TEST_EQUAL(resources.mSkeletons.size(), 1u);
207 DALI_TEST_EQUAL(ctx.cameraParameters.size(), 1u);
208 DALI_TEST_EQUAL(ctx.lights.size(), 1u);
209 DALI_TEST_EQUAL(ctx.animations.size(), 18u);
210 DALI_TEST_EQUAL(ctx.animGroups.size(), 16u);
212 ViewProjection viewProjection;
216 NodeDefinition::CreateParams nodeParams{
221 Customization::Choices choices;
225 Actor root = Actor::New();
226 SetActorCentered(root);
227 for(auto iRoot : scene.GetRoots())
229 auto resourceRefs = resources.CreateRefCounter();
230 scene.CountResourceRefs(iRoot, choices, resourceRefs);
231 resources.CountEnvironmentReferences(resourceRefs);
232 resources.LoadResources(resourceRefs, ctx.pathProvider);
233 if(auto actor = scene.CreateNodes(iRoot, choices, nodeParams))
235 scene.ConfigureSkeletonJoints(iRoot, resources.mSkeletons, actor);
236 scene.ConfigureSkinningShaders(resources, actor, std::move(nodeParams.mSkinnables));
237 ConfigureBlendShapeShaders(resources, scene, actor, std::move(nodeParams.mBlendshapeRequests));
238 scene.ApplyConstraints(actor, std::move(nodeParams.mConstrainables));
243 DALI_TEST_EQUAL(root.GetChildCount(), 2u);
244 DALI_TEST_EQUAL(root.GetChildAt(0).GetProperty(Actor::Property::NAME).Get<std::string>(), "Backdrop");
245 DALI_TEST_EQUAL(root.GetChildAt(1).GetProperty(Actor::Property::NAME).Get<std::string>(), "ExerciseDemo");
250 int UtcDaliDliLoaderLoadSceneMorph(void)
254 std::vector<std::string> metadata;
255 uint32_t metadataCount = 0;
256 ctx.input.mPreNodeCategoryProcessors.push_back({"metadata",
257 [&](const Property::Array& array, StringCallback) {
258 std::string key, value;
259 for(uint32_t i0 = 0, i1 = array.Count(); i0 < i1; ++i0)
261 auto& data = array.GetElementAt(i0);
262 DALI_TEST_EQUAL(data.GetType(), Property::MAP);
264 auto map = data.GetMap();
265 auto key = map->Find("key");
266 auto value = map->Find("value");
267 DALI_TEST_EQUAL(key->GetType(), Property::STRING);
268 DALI_TEST_EQUAL(value->GetType(), Property::STRING);
269 metadata.push_back(key->Get<std::string>() + ":" + value->Get<std::string>());
275 std::vector<std::string> behaviors;
276 uint32_t behaviorCount = 0;
277 ctx.input.mPostNodeCategoryProcessors.push_back({"behaviors",
278 [&](const Property::Array& array, StringCallback) {
279 for(uint32_t i0 = 0, i1 = array.Count(); i0 < i1; ++i0)
281 auto& data = array.GetElementAt(i0);
282 DALI_TEST_EQUAL(data.GetType(), Property::MAP);
284 auto map = data.GetMap();
285 auto event = map->Find("event");
286 auto url = map->Find("url");
287 DALI_TEST_EQUAL(event->GetType(), Property::STRING);
288 DALI_TEST_EQUAL(url->GetType(), Property::STRING);
289 behaviors.push_back(event->Get<std::string>() + ":" + url->Get<std::string>());
296 ctx.input.mNodePropertyProcessor = [&](const NodeDefinition&, const Property::Map&, StringCallback) {
300 auto path = ctx.pathProvider(ResourceType::Mesh) + "morph.dli";
301 DALI_TEST_CHECK(ctx.loader.LoadScene(path, ctx.loadParams));
302 DALI_TEST_CHECK(ctx.errors.empty());
304 auto& scene = ctx.scene;
305 auto& roots = scene.GetRoots();
306 DALI_TEST_EQUAL(roots.size(), 1u);
307 DALI_TEST_EQUAL(scene.GetNode(roots[0])->mName, "HeadTest_002");
309 DALI_TEST_EQUAL(numNodes, 3u);
310 DALI_TEST_EQUAL(scene.GetNodeCount(), numNodes);
312 auto& resources = ctx.resources;
313 DALI_TEST_EQUAL(resources.mMeshes.size(), 2u);
314 DALI_TEST_EQUAL(resources.mMaterials.size(), 1u);
315 DALI_TEST_EQUAL(resources.mShaders.size(), 5u);
316 DALI_TEST_EQUAL(resources.mEnvironmentMaps.size(), 2u);
317 DALI_TEST_EQUAL(resources.mSkeletons.size(), 0u);
319 DALI_TEST_EQUAL(ctx.cameraParameters.size(), 1u);
320 DALI_TEST_EQUAL(ctx.lights.size(), 1u);
321 DALI_TEST_EQUAL(ctx.animations.size(), 1u);
322 DALI_TEST_EQUAL(ctx.animGroups.size(), 0u);
324 DALI_TEST_EQUAL(metadata.size(), 4u);
325 DALI_TEST_EQUAL(behaviors.size(), 1u);
327 ViewProjection viewProjection;
331 NodeDefinition::CreateParams nodeParams{
336 Customization::Choices choices;
340 Actor root = Actor::New();
341 SetActorCentered(root);
342 for(auto iRoot : scene.GetRoots())
344 auto resourceRefs = resources.CreateRefCounter();
345 scene.CountResourceRefs(iRoot, choices, resourceRefs);
346 resources.CountEnvironmentReferences(resourceRefs);
347 resources.LoadResources(resourceRefs, ctx.pathProvider);
348 if(auto actor = scene.CreateNodes(iRoot, choices, nodeParams))
350 scene.ConfigureSkeletonJoints(iRoot, resources.mSkeletons, actor);
351 scene.ConfigureSkinningShaders(resources, actor, std::move(nodeParams.mSkinnables));
352 ConfigureBlendShapeShaders(resources, scene, actor, std::move(nodeParams.mBlendshapeRequests));
353 scene.ApplyConstraints(actor, std::move(nodeParams.mConstrainables));
358 DALI_TEST_EQUAL(root.GetChildCount(), 1u);
359 DALI_TEST_EQUAL(root.GetChildAt(0).GetProperty(Actor::Property::NAME).Get<std::string>(), "HeadTest_002");
364 int UtcDaliDliLoaderLoadSceneArc(void)
368 auto path = ctx.pathProvider(ResourceType::Mesh) + "arc.dli";
369 DALI_TEST_CHECK(ctx.loader.LoadScene(path, ctx.loadParams));
370 DALI_TEST_CHECK(ctx.errors.empty());
372 auto& scene = ctx.scene;
373 auto& roots = scene.GetRoots();
374 DALI_TEST_EQUAL(roots.size(), 1u);
375 DALI_TEST_EQUAL(scene.GetNode(roots[0])->mName, "root");
377 DALI_TEST_EQUAL(scene.GetNodeCount(), 2u);
379 auto& resources = ctx.resources;
380 DALI_TEST_EQUAL(resources.mMeshes.size(), 1u);
381 DALI_TEST_EQUAL(resources.mMaterials.size(), 1u);
382 DALI_TEST_EQUAL(resources.mShaders.size(), 1u);
383 DALI_TEST_EQUAL(resources.mEnvironmentMaps.size(), 1u);
384 DALI_TEST_EQUAL(resources.mSkeletons.size(), 0u);
386 DALI_TEST_EQUAL(ctx.cameraParameters.size(), 0u);
387 DALI_TEST_EQUAL(ctx.lights.size(), 0u);
388 DALI_TEST_EQUAL(ctx.animations.size(), 0u);
389 DALI_TEST_EQUAL(ctx.animGroups.size(), 0u);
391 ViewProjection viewProjection;
395 NodeDefinition::CreateParams nodeParams{
400 Customization::Choices choices;
404 Actor root = Actor::New();
405 SetActorCentered(root);
406 for(auto iRoot : scene.GetRoots())
408 auto resourceRefs = resources.CreateRefCounter();
409 scene.CountResourceRefs(iRoot, choices, resourceRefs);
410 resources.CountEnvironmentReferences(resourceRefs);
411 resources.LoadResources(resourceRefs, ctx.pathProvider);
412 if(auto actor = scene.CreateNodes(iRoot, choices, nodeParams))
414 scene.ConfigureSkeletonJoints(iRoot, resources.mSkeletons, actor);
415 scene.ConfigureSkinningShaders(resources, actor, std::move(nodeParams.mSkinnables));
416 ConfigureBlendShapeShaders(resources, scene, actor, std::move(nodeParams.mBlendshapeRequests));
417 scene.ApplyConstraints(actor, std::move(nodeParams.mConstrainables));
422 DALI_TEST_EQUAL(root.GetChildCount(), 1u);
423 DALI_TEST_EQUAL(root.GetChildAt(0).GetProperty(Actor::Property::NAME).Get<std::string>(), "root");
428 int UtcDaliDliLoaderLoadSceneShaderUniforms(void)
432 auto path = ctx.pathProvider(ResourceType::Mesh) + "dli/shader-uniforms.dli";
433 DALI_TEST_CHECK(ctx.loader.LoadScene(path, ctx.loadParams));
434 DALI_TEST_EQUAL(ctx.errors.size(), 1u);
435 DALI_TEST_CHECK(ctx.errors[0].find("failed to infer type") != std::string::npos);
437 auto& scene = ctx.scene;
438 auto& roots = scene.GetRoots();
439 DALI_TEST_EQUAL(roots.size(), 1u);
440 DALI_TEST_EQUAL(scene.GetNode(roots[0])->mName, "root");
442 DALI_TEST_EQUAL(scene.GetNodeCount(), 1u);
444 auto& resources = ctx.resources;
445 DALI_TEST_EQUAL(resources.mMeshes.size(), 0u);
446 DALI_TEST_EQUAL(resources.mMaterials.size(), 0u);
447 DALI_TEST_EQUAL(resources.mShaders.size(), 1u);
448 DALI_TEST_EQUAL(resources.mEnvironmentMaps.size(), 0u);
449 DALI_TEST_EQUAL(resources.mSkeletons.size(), 0u);
451 auto raw = resources.mShaders[0].first.LoadRaw(ctx.pathProvider(ResourceType::Shader));
455 auto shader = resources.mShaders[0].first.Load(std::move(raw));
456 DALI_TEST_EQUAL(shader.GetProperty(shader.GetPropertyIndex("uBool")).Get<float>(), 1.0f);
457 DALI_TEST_EQUAL(shader.GetProperty(shader.GetPropertyIndex("uInt")).Get<float>(), 255.0f);
458 DALI_TEST_EQUAL(shader.GetProperty(shader.GetPropertyIndex("uFloat")).Get<float>(), -0.5f);
459 DALI_TEST_EQUAL(shader.GetProperty(shader.GetPropertyIndex("uVec2")).Get<Vector2>(), Vector2(100.0f, -100.0f));
460 DALI_TEST_EQUAL(shader.GetProperty(shader.GetPropertyIndex("uVec3")).Get<Vector3>(), Vector3(50.0f, 0.f, -200.0f));
461 DALI_TEST_EQUAL(shader.GetProperty(shader.GetPropertyIndex("uVec4")).Get<Vector4>(), Vector4(0.1774f, 1.0f, 0.5333f, 0.7997f));
462 DALI_TEST_EQUAL(shader.GetProperty(shader.GetPropertyIndex("uMat3")).Get<Matrix3>(), Matrix3(9.0f, 8.0f, 7.0f, 6.0f, 5.0f, 4.0f, 3.0f, 2.0f, 1.0f));
464 Matrix expectedMatrix;
465 expectedMatrix.SetTransformComponents(Vector3::ONE * 8.0, Quaternion::IDENTITY, Vector3::ZERO);
466 DALI_TEST_EQUAL(shader.GetProperty(shader.GetPropertyIndex("uMat4")).Get<Matrix>(), expectedMatrix);
471 int UtcDaliDliLoaderLoadSceneExtras(void)
475 auto path = ctx.pathProvider(ResourceType::Mesh) + "dli/extras.dli";
476 DALI_TEST_CHECK(ctx.loader.LoadScene(path, ctx.loadParams));
477 DALI_TEST_EQUAL(ctx.errors.size(), 3u);
478 DALI_TEST_CHECK(ctx.errors[0].find("already defined; overriding") != std::string::npos);
479 DALI_TEST_CHECK(ctx.errors[1].find("empty string is invalid for name") != std::string::npos);
480 DALI_TEST_CHECK(ctx.errors[2].find("failed to interpret value") != std::string::npos);
482 auto& scene = ctx.scene;
483 auto& roots = scene.GetRoots();
484 DALI_TEST_EQUAL(roots.size(), 1u);
485 DALI_TEST_EQUAL(scene.GetNode(roots[0])->mName, "root");
487 DALI_TEST_EQUAL(scene.GetNodeCount(), 1u);
489 ViewProjection viewProjection;
493 auto& resources = ctx.resources;
494 NodeDefinition::CreateParams nodeParams{
499 Customization::Choices choices;
502 Actor actor = scene.CreateNodes(0, choices, nodeParams);
504 DALI_TEST_EQUAL(actor.GetProperty(actor.GetPropertyIndex("fudgeFactor")).Get<float>(), 9000.1f);
505 DALI_TEST_EQUAL(actor.GetProperty(actor.GetPropertyIndex("fudgeVector")).Get<Vector2>(), Vector2(-.25f, 17.f));
506 DALI_TEST_EQUAL(actor.GetProperty(actor.GetPropertyIndex("isThisTheRealLife")).Get<bool>(), true);
507 DALI_TEST_EQUAL(actor.GetProperty(actor.GetPropertyIndex("isThisJustFantasy")).Get<bool>(), false);
508 DALI_TEST_EQUAL(actor.GetProperty(actor.GetPropertyIndex("velocity")).Get<Vector3>(), Vector3(.1f, 58.f, -.2f));
509 DALI_TEST_EQUAL(actor.GetProperty(actor.GetPropertyIndex("frameOfReference")).Get<Matrix>(), Matrix::IDENTITY);
514 int UtcDaliDliLoaderLoadSceneConstraints(void)
518 auto path = ctx.pathProvider(ResourceType::Mesh) + "dli/constraints.dli";
519 DALI_TEST_CHECK(ctx.loader.LoadScene(path, ctx.loadParams));
520 DALI_TEST_EQUAL(ctx.errors.size(), 1u);
521 DALI_TEST_CHECK(ctx.errors[0].find("invalid", ctx.errors[0].find("node ID")) != std::string::npos);
523 auto& scene = ctx.scene;
524 auto& roots = scene.GetRoots();
525 DALI_TEST_EQUAL(roots.size(), 1u);
526 DALI_TEST_EQUAL(scene.GetNode(0)->mName, "root");
527 DALI_TEST_EQUAL(scene.GetNode(1)->mName, "Alice");
528 DALI_TEST_EQUAL(scene.GetNode(2)->mName, "Bob");
529 DALI_TEST_EQUAL(scene.GetNode(3)->mName, "Charlie");
531 DALI_TEST_EQUAL(scene.GetNodeCount(), 4u);
533 ViewProjection viewProjection;
537 auto& resources = ctx.resources;
538 NodeDefinition::CreateParams nodeParams{
543 Customization::Choices choices;
547 Actor root = scene.CreateNodes(0, choices, nodeParams);
548 Actor alice = root.FindChildByName("Alice");
549 Actor bob = root.FindChildByName("Bob");
550 Actor charlie = root.FindChildByName("Charlie");
552 DALI_TEST_EQUAL(nodeParams.mConstrainables.size(), 3u);
553 DALI_TEST_EQUAL(bob.GetProperty(bob.GetPropertyIndex("angularVelocity")).Get<Vector2>(), Vector2(-0.5, 0.0004));
556 scene.ApplyConstraints(root, std::move(nodeParams.mConstrainables), ctx.onError);
557 DALI_TEST_CHECK(ctx.errors.empty());
559 app.GetScene().Add(root);
560 app.SendNotification();
562 app.SendNotification();
565 DALI_TEST_EQUAL(charlie.GetCurrentProperty(Actor::Property::ORIENTATION), alice.GetProperty(Actor::Property::ORIENTATION));
566 DALI_TEST_EQUAL(charlie.GetCurrentProperty(Actor::Property::POSITION), bob.GetProperty(Actor::Property::POSITION));
567 DALI_TEST_EQUAL(charlie.GetCurrentProperty(charlie.GetPropertyIndex("angularVelocity")), bob.GetProperty(bob.GetPropertyIndex("angularVelocity")));
572 int UtcDaliDliLoaderNodeProcessor(void)
576 std::vector<Property::Map> nodeMaps;
577 ctx.input.mNodePropertyProcessor = [&](const NodeDefinition&, Property::Map&& map, StringCallback) {
578 nodeMaps.push_back(map);
581 auto path = ctx.pathProvider(ResourceType::Mesh) + "dli/node-processor.dli";
582 DALI_TEST_CHECK(ctx.loader.LoadScene(path, ctx.loadParams));
584 DALI_TEST_EQUAL(nodeMaps.size(), 2u);
585 DALI_TEST_EQUAL(nodeMaps[0].Count(), 5u);
586 DALI_TEST_EQUAL(nodeMaps[0].Find("name")->Get<std::string>(), "rootA");
587 DALI_TEST_EQUAL(nodeMaps[0].Find("nickname")->Get<std::string>(), "same as name");
588 DALI_TEST_EQUAL(nodeMaps[0].Find("favourite number")->Get<int32_t>(), 63478);
590 auto propArray = nodeMaps[0].Find("array");
591 DALI_TEST_EQUAL(propArray->GetType(), Property::ARRAY);
593 auto array = propArray->GetArray();
594 DALI_TEST_EQUAL(array->Count(), 5);
595 DALI_TEST_EQUAL(array->GetElementAt(0).Get<int32_t>(), 1);
596 DALI_TEST_EQUAL(array->GetElementAt(1).Get<int32_t>(), 2);
597 DALI_TEST_EQUAL(array->GetElementAt(2).Get<int32_t>(), 4);
598 DALI_TEST_EQUAL(array->GetElementAt(3).Get<int32_t>(), 8);
599 DALI_TEST_EQUAL(array->GetElementAt(4).Get<int32_t>(), -500);
601 auto propObject = nodeMaps[0].Find("object");
602 DALI_TEST_EQUAL(propObject->GetType(), Property::MAP);
604 auto object = propObject->GetMap();
605 DALI_TEST_EQUAL(object->Count(), 5);
606 DALI_TEST_EQUAL(object->Find("physics")->Get<bool>(), true);
607 DALI_TEST_EQUAL(object->Find("elasticity")->Get<float>(), .27f);
608 DALI_TEST_EQUAL(object->Find("drag")->Get<float>(), .91f);
610 auto propInnerArray = object->Find("inner array");
611 DALI_TEST_EQUAL(propInnerArray->GetType(), Property::ARRAY);
613 auto innerArray = propInnerArray->GetArray();
614 DALI_TEST_EQUAL(innerArray->Count(), 3);
615 DALI_TEST_EQUAL(innerArray->GetElementAt(0).Get<std::string>(), "why");
616 DALI_TEST_EQUAL(innerArray->GetElementAt(1).Get<std::string>(), "not");
617 DALI_TEST_EQUAL(innerArray->GetElementAt(2).Get<bool>(), false);
619 auto propInnerObject = object->Find("inner object");
620 DALI_TEST_EQUAL(propInnerObject->GetType(), Property::MAP);
622 auto innerObject = propInnerObject->GetMap();
623 DALI_TEST_EQUAL(innerObject->Count(), 1);
624 DALI_TEST_EQUAL(innerObject->Find("supported")->Get<bool>(), true);
626 DALI_TEST_EQUAL(nodeMaps[1].Count(), 1u);
627 DALI_TEST_EQUAL(nodeMaps[1].Find("name")->Get<std::string>(), "rootB");
632 int UtcDaliDliLoaderLoadCoverageTest(void)
636 auto path = ctx.pathProvider(ResourceType::Mesh) + "coverageTest.dli";
637 DALI_TEST_CHECK(ctx.loader.LoadScene(path, ctx.loadParams));
638 DALI_TEST_CHECK(ctx.errors.empty());
640 auto& scene = ctx.scene;
641 auto& roots = scene.GetRoots();
642 DALI_TEST_EQUAL(roots.size(), 1u);
643 DALI_TEST_EQUAL(scene.GetNode(roots[0])->mName, "root");
645 DALI_TEST_EQUAL(scene.GetNodeCount(), 1u);
647 auto& resources = ctx.resources;
648 DALI_TEST_EQUAL(resources.mMeshes.size(), 1u);
649 DALI_TEST_EQUAL(resources.mShaders.size(), 1u);
650 DALI_TEST_EQUAL(resources.mEnvironmentMaps.size(), 2u);
651 DALI_TEST_EQUAL(resources.mSkeletons.size(), 0u);
653 auto& materials = ctx.resources.mMaterials;
654 DALI_TEST_EQUAL(2u, materials.size());
656 auto iMaterial = materials.begin();
657 auto& md = iMaterial->first;
658 DALI_TEST_EQUAL(md.mTextureStages.size(), 1u);
660 auto iTexture = md.mTextureStages.begin();
661 DALI_TEST_CHECK(MaskMatch(iTexture->mSemantic, MaterialDefinition::OCCLUSION));
662 DALI_TEST_EQUAL(iTexture->mTexture.mImageUri, "exercise/Icons/Icon_Idle.png");
665 DALI_TEST_EQUAL(ctx.cameraParameters.size(), 1u);
666 DALI_TEST_EQUAL(ctx.lights.size(), 1u);
667 DALI_TEST_EQUAL(ctx.animations.size(), 0u);
668 DALI_TEST_EQUAL(ctx.animGroups.size(), 0u);
670 ViewProjection viewProjection;
674 NodeDefinition::CreateParams nodeParams{
679 Customization::Choices choices;
683 Actor root = Actor::New();
684 SetActorCentered(root);
685 for(auto iRoot : scene.GetRoots())
687 auto resourceRefs = resources.CreateRefCounter();
688 scene.CountResourceRefs(iRoot, choices, resourceRefs);
689 resources.CountEnvironmentReferences(resourceRefs);
690 resources.LoadResources(resourceRefs, ctx.pathProvider);
691 if(auto actor = scene.CreateNodes(iRoot, choices, nodeParams))
693 scene.ConfigureSkeletonJoints(iRoot, resources.mSkeletons, actor);
694 scene.ConfigureSkinningShaders(resources, actor, std::move(nodeParams.mSkinnables));
695 ConfigureBlendShapeShaders(resources, scene, actor, std::move(nodeParams.mBlendshapeRequests));
696 scene.ApplyConstraints(actor, std::move(nodeParams.mConstrainables));
701 DALI_TEST_EQUAL(root.GetChildCount(), 1u);
702 DALI_TEST_EQUAL(root.GetChildAt(0).GetProperty(Actor::Property::NAME).Get<std::string>(), "root");