2 * Copyright (c) 2023 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-scene3d/internal/loader/glb-loader-impl.h>
22 #include <dali-scene3d/public-api/loader/load-result.h>
23 #include <dali-scene3d/public-api/loader/resource-bundle.h>
24 #include <dali-scene3d/public-api/loader/scene-definition.h>
25 #include <dali-scene3d/public-api/loader/shader-manager.h>
26 #include <dali-test-suite-utils.h>
27 #include <string_view>
30 using namespace Dali::Scene3D::Loader;
32 #define DALI_TEST_THROW(expression, exception, predicate) \
34 bool daliTestThrowSuccess__ = false; \
41 printf("No exception was thrown.\n"); \
43 catch(std::decay<exception>::type & ex) \
45 daliTestThrowSuccess__ = predicate(ex); \
49 printf("Wrong type of exception thrown.\n"); \
51 DALI_TEST_CHECK(daliTestThrowSuccess__); \
58 ResourceBundle::PathProvider pathProvider = [](ResourceType::Value type) {
59 return TEST_RESOURCE_DIR "/";
62 ResourceBundle resources;
63 SceneDefinition scene;
64 SceneMetadata metaData;
66 std::vector<AnimationDefinition> animations;
67 std::vector<AnimationGroupDefinition> animationGroups;
68 std::vector<CameraParameters> cameras;
69 std::vector<LightParameters> lights;
71 LoadResult loadResult{
80 Dali::Scene3D::Loader::Internal::GlbLoaderImpl loader;
83 struct ExceptionMessageStartsWith
85 const std::string_view expected;
87 bool operator()(const std::runtime_error& e)
89 const bool success = (0 == strncmp(e.what(), expected.data(), expected.size()));
92 printf("Expected: %s, got: %s.\n", expected.data(), e.what());
100 int UtcDaliGlbLoaderFailedToLoad(void)
104 DALI_TEST_EQUAL(ctx.loader.LoadModel("non-existent.glb", ctx.loadResult), false);
106 DALI_TEST_EQUAL(0, ctx.scene.GetRoots().size());
107 DALI_TEST_EQUAL(0, ctx.scene.GetNodeCount());
109 DALI_TEST_EQUAL(0, ctx.resources.mEnvironmentMaps.size());
110 DALI_TEST_EQUAL(0, ctx.resources.mMaterials.size());
111 DALI_TEST_EQUAL(0, ctx.resources.mMeshes.size());
112 DALI_TEST_EQUAL(0, ctx.resources.mShaders.size());
113 DALI_TEST_EQUAL(0, ctx.resources.mSkeletons.size());
115 DALI_TEST_EQUAL(0, ctx.cameras.size());
116 DALI_TEST_EQUAL(0, ctx.lights.size());
117 DALI_TEST_EQUAL(0, ctx.animations.size());
118 DALI_TEST_EQUAL(0, ctx.animationGroups.size());
123 int UtcDaliGlbLoaderFailedToParse(void)
126 DALI_TEST_EQUAL(ctx.loader.LoadModel(TEST_RESOURCE_DIR "/invalid.glb", ctx.loadResult), false);
128 DALI_TEST_EQUAL(0, ctx.scene.GetRoots().size());
129 DALI_TEST_EQUAL(0, ctx.scene.GetNodeCount());
131 DALI_TEST_EQUAL(0, ctx.resources.mEnvironmentMaps.size());
132 DALI_TEST_EQUAL(0, ctx.resources.mMaterials.size());
133 DALI_TEST_EQUAL(0, ctx.resources.mMeshes.size());
134 DALI_TEST_EQUAL(0, ctx.resources.mSkeletons.size());
136 DALI_TEST_EQUAL(0, ctx.cameras.size());
137 DALI_TEST_EQUAL(0, ctx.lights.size());
138 DALI_TEST_EQUAL(0, ctx.animations.size());
139 DALI_TEST_EQUAL(0, ctx.animationGroups.size());
144 int UtcDaliGlbLoaderSuccess1(void)
147 ctx.loader.LoadModel(TEST_RESOURCE_DIR "/BoxAnimated.glb", ctx.loadResult);
149 DALI_TEST_EQUAL(1u, ctx.scene.GetRoots().size());
150 DALI_TEST_EQUAL(5u, ctx.scene.GetNodeCount());
154 Customization::Choices choices;
155 for(auto iRoot : ctx.scene.GetRoots())
157 auto resourceRefs = ctx.resources.CreateRefCounter();
158 ctx.scene.CountResourceRefs(iRoot, choices, resourceRefs);
159 ctx.resources.mReferenceCounts = std::move(resourceRefs);
160 ctx.resources.LoadResources(ctx.pathProvider);
163 DALI_TEST_EQUAL(true, ctx.resources.mMeshes[0u].first.mPositions.IsDefined());
164 DALI_TEST_EQUAL(1152, ctx.resources.mMeshes[0u].first.mPositions.mBlob.mLength);