[dali_2.1.32] Merge branch 'devel/master'
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-scene3d / utc-Dali-DliLoader.cpp
1 /*
2  * Copyright (c) 2022 Samsung Electronics Co., Ltd.
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  *
16  */
17
18 // Enable debug log for test coverage
19 #define DEBUG_ENABLED 1
20
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"
28
29 using namespace Dali;
30 using namespace Dali::Scene3D::Loader;
31
32 namespace
33 {
34 void ConfigureBlendShapeShaders(ResourceBundle& resources, const SceneDefinition& scene, Actor root, std::vector<BlendshapeShaderConfigurationRequest>&& requests)
35 {
36   std::vector<std::string> errors;
37   auto                     onError = [&errors](const std::string& msg) {
38     errors.push_back(msg);
39   };
40
41   if(!scene.ConfigureBlendshapeShaders(resources, root, std::move(requests), onError))
42   {
43     ExceptionFlinger flinger(ASSERT_LOCATION);
44     for(auto& msg : errors)
45     {
46       flinger << msg << '\n';
47     }
48   }
49 }
50
51 struct Context
52 {
53   ResourceBundle::PathProvider pathProvider = [](ResourceType::Value type) {
54     return TEST_RESOURCE_DIR "/";
55   };
56
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;
63
64   LoadResult output{
65     resources,
66     scene,
67     animations,
68     animGroups,
69     cameraParameters,
70     lights};
71
72   DliLoader::InputParams input{
73     pathProvider(ResourceType::Mesh),
74     nullptr,
75     {},
76     {},
77     nullptr,
78   };
79   DliLoader::LoadParams loadParams{input, output};
80
81   std::vector<std::string> errors;
82   DliLoader                loader;
83
84   StringCallback onError = [this](const std::string& error) {
85     errors.push_back(error);
86     printf("%s\n", error.c_str());
87   };
88
89   Context()
90   {
91     loader.SetErrorCallback(onError);
92   }
93 };
94
95 bool StringHasTokens(const char* string, const std::vector<const char*>& tokens)
96 {
97   for(auto& token : tokens)
98   {
99     auto result = strstr(string, token);
100     if(nullptr == result)
101     {
102       return false;
103     }
104     string = result + strlen(token);
105   }
106   return true;
107 }
108
109 } // namespace
110
111 int UtcDaliDliLoaderLoadSceneNotFound(void)
112 {
113   Context ctx;
114
115   DALI_TEST_EQUAL(ctx.loader.LoadScene("does_not_exist.dli", ctx.loadParams), false);
116
117   auto error = ctx.loader.GetParseError();
118   DALI_TEST_CHECK(StringHasTokens(error.c_str(), {"Empty source buffer to parse."}));
119
120   END_TEST;
121 }
122
123 int UtcDaliDliLoaderLoadSceneFailParse(void)
124 {
125   Context ctx;
126
127   auto path = ctx.pathProvider(ResourceType::Mesh) + "invalid.gltf";
128   DALI_TEST_EQUAL(ctx.loader.LoadScene(path, ctx.loadParams), false);
129
130   auto error = ctx.loader.GetParseError();
131   DALI_TEST_CHECK(StringHasTokens(error.c_str(), {"Unexpected character."}));
132
133   END_TEST;
134 }
135
136 int UtcDaliDliLoaderLoadSceneAssertions(void)
137 {
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"},
162     // from ParseNodes()
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)
173   {
174     Context ctx;
175
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());
179   }
180
181   END_TEST;
182 }
183
184 int UtcDaliDliLoaderLoadSceneExercise(void)
185 {
186   Context ctx;
187
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());
191
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");
197
198   DALI_TEST_EQUAL(scene.GetNodeCount(), 96u);
199
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);
206
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);
211
212   ViewProjection viewProjection;
213   Transforms     xforms{
214     MatrixStack{},
215     viewProjection};
216   NodeDefinition::CreateParams nodeParams{
217     resources,
218     xforms,
219   };
220
221   Customization::Choices choices;
222
223   TestApplication app;
224
225   Actor root = Actor::New();
226   SetActorCentered(root);
227   for(auto iRoot : scene.GetRoots())
228   {
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))
234     {
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));
239       root.Add(actor);
240     }
241   }
242
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");
246
247   END_TEST;
248 }
249
250 int UtcDaliDliLoaderLoadSceneMorph(void)
251 {
252   Context ctx;
253
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)
260                                                     {
261                                                       auto& data = array.GetElementAt(i0);
262                                                       DALI_TEST_EQUAL(data.GetType(), Property::MAP);
263
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>());
270
271                                                       ++metadataCount;
272                                                     }
273                                                   }});
274
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)
280                                                      {
281                                                        auto& data = array.GetElementAt(i0);
282                                                        DALI_TEST_EQUAL(data.GetType(), Property::MAP);
283
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>());
290
291                                                        ++behaviorCount;
292                                                      }
293                                                    }});
294
295   size_t numNodes                  = 0;
296   ctx.input.mNodePropertyProcessor = [&](const NodeDefinition&, const Property::Map&, StringCallback) {
297     ++numNodes;
298   };
299
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());
303
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");
308
309   DALI_TEST_EQUAL(numNodes, 3u);
310   DALI_TEST_EQUAL(scene.GetNodeCount(), numNodes);
311
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);
318
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);
323
324   DALI_TEST_EQUAL(metadata.size(), 4u);
325   DALI_TEST_EQUAL(behaviors.size(), 1u);
326
327   ViewProjection viewProjection;
328   Transforms     xforms{
329     MatrixStack{},
330     viewProjection};
331   NodeDefinition::CreateParams nodeParams{
332     resources,
333     xforms,
334   };
335
336   Customization::Choices choices;
337
338   TestApplication app;
339
340   Actor root = Actor::New();
341   SetActorCentered(root);
342   for(auto iRoot : scene.GetRoots())
343   {
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))
349     {
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));
354       root.Add(actor);
355     }
356   }
357
358   DALI_TEST_EQUAL(root.GetChildCount(), 1u);
359   DALI_TEST_EQUAL(root.GetChildAt(0).GetProperty(Actor::Property::NAME).Get<std::string>(), "HeadTest_002");
360
361   END_TEST;
362 }
363
364 int UtcDaliDliLoaderLoadSceneArc(void)
365 {
366   Context ctx;
367
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());
371
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");
376
377   DALI_TEST_EQUAL(scene.GetNodeCount(), 2u);
378
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);
385
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);
390
391   ViewProjection viewProjection;
392   Transforms     xforms{
393     MatrixStack{},
394     viewProjection};
395   NodeDefinition::CreateParams nodeParams{
396     resources,
397     xforms,
398   };
399
400   Customization::Choices choices;
401
402   TestApplication app;
403
404   Actor root = Actor::New();
405   SetActorCentered(root);
406   for(auto iRoot : scene.GetRoots())
407   {
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))
413     {
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));
418       root.Add(actor);
419     }
420   }
421
422   DALI_TEST_EQUAL(root.GetChildCount(), 1u);
423   DALI_TEST_EQUAL(root.GetChildAt(0).GetProperty(Actor::Property::NAME).Get<std::string>(), "root");
424
425   END_TEST;
426 }
427
428 int UtcDaliDliLoaderLoadSceneShaderUniforms(void)
429 {
430   Context ctx;
431
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);
436
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");
441
442   DALI_TEST_EQUAL(scene.GetNodeCount(), 1u);
443
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);
450
451   auto raw = resources.mShaders[0].first.LoadRaw(ctx.pathProvider(ResourceType::Shader));
452
453   TestApplication app;
454
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));
463
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);
467
468   END_TEST;
469 }
470
471 int UtcDaliDliLoaderLoadSceneExtras(void)
472 {
473   Context ctx;
474
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);
481
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");
486
487   DALI_TEST_EQUAL(scene.GetNodeCount(), 1u);
488
489   ViewProjection viewProjection;
490   Transforms     xforms{
491     MatrixStack{},
492     viewProjection};
493   auto&                        resources = ctx.resources;
494   NodeDefinition::CreateParams nodeParams{
495     resources,
496     xforms,
497   };
498
499   Customization::Choices choices;
500
501   TestApplication app;
502   Actor           actor = scene.CreateNodes(0, choices, nodeParams);
503
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);
510
511   END_TEST;
512 }
513
514 int UtcDaliDliLoaderLoadSceneConstraints(void)
515 {
516   Context ctx;
517
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);
522
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");
530
531   DALI_TEST_EQUAL(scene.GetNodeCount(), 4u);
532
533   ViewProjection viewProjection;
534   Transforms     xforms{
535     MatrixStack{},
536     viewProjection};
537   auto&                        resources = ctx.resources;
538   NodeDefinition::CreateParams nodeParams{
539     resources,
540     xforms,
541   };
542
543   Customization::Choices choices;
544
545   TestApplication app;
546
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");
551
552   DALI_TEST_EQUAL(nodeParams.mConstrainables.size(), 3u);
553   DALI_TEST_EQUAL(bob.GetProperty(bob.GetPropertyIndex("angularVelocity")).Get<Vector2>(), Vector2(-0.5, 0.0004));
554
555   ctx.errors.clear();
556   scene.ApplyConstraints(root, std::move(nodeParams.mConstrainables), ctx.onError);
557   DALI_TEST_CHECK(ctx.errors.empty());
558
559   app.GetScene().Add(root);
560   app.SendNotification();
561   app.Render();
562   app.SendNotification();
563   app.Render();
564
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")));
568
569   END_TEST;
570 }
571
572 int UtcDaliDliLoaderNodeProcessor(void)
573 {
574   Context ctx;
575
576   std::vector<Property::Map> nodeMaps;
577   ctx.input.mNodePropertyProcessor = [&](const NodeDefinition&, Property::Map&& map, StringCallback) {
578     nodeMaps.push_back(map);
579   };
580
581   auto path = ctx.pathProvider(ResourceType::Mesh) + "dli/node-processor.dli";
582   DALI_TEST_CHECK(ctx.loader.LoadScene(path, ctx.loadParams));
583
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);
589
590   auto propArray = nodeMaps[0].Find("array");
591   DALI_TEST_EQUAL(propArray->GetType(), Property::ARRAY);
592
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);
600
601   auto propObject = nodeMaps[0].Find("object");
602   DALI_TEST_EQUAL(propObject->GetType(), Property::MAP);
603
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);
609
610   auto propInnerArray = object->Find("inner array");
611   DALI_TEST_EQUAL(propInnerArray->GetType(), Property::ARRAY);
612
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);
618
619   auto propInnerObject = object->Find("inner object");
620   DALI_TEST_EQUAL(propInnerObject->GetType(), Property::MAP);
621
622   auto innerObject = propInnerObject->GetMap();
623   DALI_TEST_EQUAL(innerObject->Count(), 1);
624   DALI_TEST_EQUAL(innerObject->Find("supported")->Get<bool>(), true);
625
626   DALI_TEST_EQUAL(nodeMaps[1].Count(), 1u);
627   DALI_TEST_EQUAL(nodeMaps[1].Find("name")->Get<std::string>(), "rootB");
628
629   END_TEST;
630 }
631
632 int UtcDaliDliLoaderLoadCoverageTest(void)
633 {
634   Context ctx;
635
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());
639
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");
644
645   DALI_TEST_EQUAL(scene.GetNodeCount(), 1u);
646
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);
652
653   auto& materials = ctx.resources.mMaterials;
654   DALI_TEST_EQUAL(2u, materials.size());
655
656   auto  iMaterial = materials.begin();
657   auto& md        = iMaterial->first;
658   DALI_TEST_EQUAL(md.mTextureStages.size(), 1u);
659
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");
663   ++iTexture;
664
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);
669
670   ViewProjection viewProjection;
671   Transforms     xforms{
672     MatrixStack{},
673     viewProjection};
674   NodeDefinition::CreateParams nodeParams{
675     resources,
676     xforms,
677   };
678
679   Customization::Choices choices;
680
681   TestApplication app;
682
683   Actor root = Actor::New();
684   SetActorCentered(root);
685   for(auto iRoot : scene.GetRoots())
686   {
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))
692     {
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));
697       root.Add(actor);
698     }
699   }
700
701   DALI_TEST_EQUAL(root.GetChildCount(), 1u);
702   DALI_TEST_EQUAL(root.GetChildAt(0).GetProperty(Actor::Property::NAME).Get<std::string>(), "root");
703
704   END_TEST;
705 }