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-test-suite-utils.h>
23 #include "dali-scene3d/internal/loader/gltf2-asset.h"
26 using namespace Dali::Scene3D::Loader;
28 int UtcDaliGltf2AssetComponentIsUnsigned(void)
30 DALI_TEST_EQUAL(gltf2::Component::IsUnsigned(gltf2::Component::BYTE), false);
31 DALI_TEST_EQUAL(gltf2::Component::IsUnsigned(gltf2::Component::UNSIGNED_BYTE), true);
32 DALI_TEST_EQUAL(gltf2::Component::IsUnsigned(gltf2::Component::SHORT), false);
33 DALI_TEST_EQUAL(gltf2::Component::IsUnsigned(gltf2::Component::UNSIGNED_SHORT), true);
34 DALI_TEST_EQUAL(gltf2::Component::IsUnsigned(gltf2::Component::UNSIGNED_INT), true);
35 DALI_TEST_EQUAL(gltf2::Component::IsUnsigned(gltf2::Component::FLOAT), false);
36 DALI_TEST_EQUAL(gltf2::Component::IsUnsigned(gltf2::Component::INVALID), false);
41 int UtcDaliGltf2AssetComponentSize(void)
43 DALI_TEST_EQUAL(gltf2::Component::Size(gltf2::Component::BYTE), 1u);
44 DALI_TEST_EQUAL(gltf2::Component::Size(gltf2::Component::UNSIGNED_BYTE), 1u);
45 DALI_TEST_EQUAL(gltf2::Component::Size(gltf2::Component::SHORT), 2u);
46 DALI_TEST_EQUAL(gltf2::Component::Size(gltf2::Component::UNSIGNED_SHORT), 2u);
47 DALI_TEST_EQUAL(gltf2::Component::Size(gltf2::Component::UNSIGNED_INT), 4u);
48 DALI_TEST_EQUAL(gltf2::Component::Size(gltf2::Component::FLOAT), 4u);
49 DALI_TEST_EQUAL(gltf2::Component::Size(gltf2::Component::INVALID), -1);
54 #define FROM_STRING_HELPER(x) FromString(#x, strlen(#x))
55 #define TARGET_FROM_STRING_HELPER(x) TargetFromString(#x, strlen(#x))
56 #define HASH_FROM_STRING_HELPER(x) HashFromString(#x, strlen(#x))
58 #define STRING_CHECK(type, x) DALI_TEST_EQUAL(gltf2::type::FROM_STRING_HELPER(x), gltf2::type::x)
59 #define TARGET_STRING_CHECK(type, x) DALI_TEST_EQUAL(gltf2::type::TARGET_FROM_STRING_HELPER(x), gltf2::type::x)
60 #define HASH_STRING_CHECK(type, x, y, z) DALI_TEST_EQUAL(gltf2::type::HASH_FROM_STRING_HELPER(x), gltf2::type::ToHash(gltf2::type::y, true, z))
62 int UtcDaliGltf2AssetAccessorType(void)
64 STRING_CHECK(AccessorType, SCALAR);
65 STRING_CHECK(AccessorType, VEC2);
66 STRING_CHECK(AccessorType, VEC3);
67 STRING_CHECK(AccessorType, VEC4);
68 STRING_CHECK(AccessorType, MAT2);
69 STRING_CHECK(AccessorType, MAT3);
70 STRING_CHECK(AccessorType, MAT4);
71 DALI_TEST_EQUAL(gltf2::AccessorType::FROM_STRING_HELPER(VEC88), gltf2::AccessorType::INVALID);
76 int UtcDaliGltf2AssetAlphaMode(void)
78 STRING_CHECK(AlphaMode, OPAQUE);
79 STRING_CHECK(AlphaMode, MASK);
80 STRING_CHECK(AlphaMode, BLEND);
81 DALI_TEST_EQUAL(gltf2::AlphaMode::FROM_STRING_HELPER(ALPHA_SCHMALPHA), gltf2::AlphaMode::INVALID);
86 int UtcDaliGltf2AssetAttribute(void)
88 TARGET_STRING_CHECK(Attribute, POSITION);
89 TARGET_STRING_CHECK(Attribute, NORMAL);
90 TARGET_STRING_CHECK(Attribute, TANGENT);
91 HASH_STRING_CHECK(Attribute, TEXCOORD_0, TEXCOORD_N, 0);
92 HASH_STRING_CHECK(Attribute, TEXCOORD_1, TEXCOORD_N, 1);
93 HASH_STRING_CHECK(Attribute, COLOR_0, COLOR_N, 0);
94 HASH_STRING_CHECK(Attribute, COLOR_1, COLOR_N, 1);
95 HASH_STRING_CHECK(Attribute, JOINTS_0, JOINTS_N, 0);
96 HASH_STRING_CHECK(Attribute, JOINTS_1, JOINTS_N, 1);
97 HASH_STRING_CHECK(Attribute, JOINTS_2, JOINTS_N, 2);
98 HASH_STRING_CHECK(Attribute, WEIGHTS_0, WEIGHTS_N, 0);
99 HASH_STRING_CHECK(Attribute, WEIGHTS_1, WEIGHTS_N, 1);
100 HASH_STRING_CHECK(Attribute, WEIGHTS_2, WEIGHTS_N, 2);
101 DALI_TEST_EQUAL(gltf2::Attribute::TARGET_FROM_STRING_HELPER(VISCOSITY), gltf2::Attribute::INVALID);
106 int UtcDaliGltf2AssetAnimationSamplerInterpolation(void)
108 STRING_CHECK(Animation::Sampler::Interpolation, STEP);
109 STRING_CHECK(Animation::Sampler::Interpolation, LINEAR);
110 STRING_CHECK(Animation::Sampler::Interpolation, CUBICSPLINE);
111 DALI_TEST_EQUAL(gltf2::Animation::Sampler::Interpolation::FROM_STRING_HELPER(EASE_IN_OUT), gltf2::Animation::Sampler::Interpolation::INVALID);
116 int UtcDaliGltf2AssetAnimationChannelTarget(void)
118 STRING_CHECK(Animation::Channel::Target, TRANSLATION);
119 STRING_CHECK(Animation::Channel::Target, ROTATION);
120 STRING_CHECK(Animation::Channel::Target, SCALE);
121 STRING_CHECK(Animation::Channel::Target, WEIGHTS);
122 DALI_TEST_EQUAL(gltf2::Animation::Channel::Target::FROM_STRING_HELPER(FLUFFINESS), gltf2::Animation::Channel::Target::INVALID);
127 int UtcDaliGltf2AssetAccessorSparse(void)
130 DALI_TEST_CHECK(!acc.mSparse);
132 std::vector<gltf2::BufferView> bufferViews;
134 gltf2::Accessor::Sparse sparse{256u};
135 sparse.mIndices.mBufferView = gltf2::Ref<gltf2::BufferView>(bufferViews, 5u);
136 sparse.mIndices.mComponentType = gltf2::Component::FLOAT;
137 sparse.mValues.mBufferView = gltf2::Ref<gltf2::BufferView>(bufferViews, 284u);
138 sparse.mValues.mByteOffset = 16532;
139 acc.SetSparse(sparse);
141 DALI_TEST_EQUAL(acc.mSparse->mCount, sparse.mCount);
142 DALI_TEST_EQUAL(acc.mSparse->mIndices.mBufferView, sparse.mIndices.mBufferView);
143 DALI_TEST_EQUAL(acc.mSparse->mIndices.mByteOffset, sparse.mIndices.mByteOffset);
144 DALI_TEST_EQUAL(acc.mSparse->mIndices.mComponentType, sparse.mIndices.mComponentType);
145 DALI_TEST_EQUAL(acc.mSparse->mValues.mBufferView, sparse.mValues.mBufferView);
146 DALI_TEST_EQUAL(acc.mSparse->mValues.mByteOffset, sparse.mValues.mByteOffset);