[dali_2.3.21] Merge branch 'devel/master'
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-scene3d-internal / utc-Dali-Gltf2Asset.cpp
1 /*
2  * Copyright (c) 2023 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>
23 #include "dali-scene3d/internal/loader/gltf2-asset.h"
24
25 using namespace Dali;
26 using namespace Dali::Scene3D::Loader;
27
28 int UtcDaliGltf2AssetComponentIsUnsigned(void)
29 {
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);
37
38   END_TEST;
39 }
40
41 int UtcDaliGltf2AssetComponentSize(void)
42 {
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);
50
51   END_TEST;
52 }
53
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))
57
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))
61
62 int UtcDaliGltf2AssetAccessorType(void)
63 {
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);
72
73   END_TEST;
74 }
75
76 int UtcDaliGltf2AssetAlphaMode(void)
77 {
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);
82
83   END_TEST;
84 }
85
86 int UtcDaliGltf2AssetAttribute(void)
87 {
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);
102
103   END_TEST;
104 }
105
106 int UtcDaliGltf2AssetAnimationSamplerInterpolation(void)
107 {
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);
112
113   END_TEST;
114 }
115
116 int UtcDaliGltf2AssetAnimationChannelTarget(void)
117 {
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);
123
124   END_TEST;
125 }
126
127 int UtcDaliGltf2AssetAccessorSparse(void)
128 {
129   gltf2::Accessor acc;
130   DALI_TEST_CHECK(!acc.mSparse);
131
132   std::vector<gltf2::BufferView> bufferViews;
133
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);
140
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);
147
148   END_TEST;
149 }