2 * Copyright (c) 2020 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-scene-loader/internal/gltf2-asset.h"
22 #include <dali-test-suite-utils.h>
26 using namespace Dali::SceneLoader;
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))
56 #define STRING_CHECK(type, x) DALI_TEST_EQUAL(gltf2::type:: FROM_STRING_HELPER(x), gltf2::type::x)
58 int UtcDaliGltf2AssetAccessorType(void)
60 STRING_CHECK(AccessorType, SCALAR);
61 STRING_CHECK(AccessorType, VEC2);
62 STRING_CHECK(AccessorType, VEC3);
63 STRING_CHECK(AccessorType, VEC4);
64 STRING_CHECK(AccessorType, MAT2);
65 STRING_CHECK(AccessorType, MAT3);
66 STRING_CHECK(AccessorType, MAT4);
67 DALI_TEST_EQUAL(gltf2::AccessorType::FROM_STRING_HELPER(VEC88), gltf2::AccessorType::INVALID);
72 int UtcDaliGltf2AssetAlphaMode(void)
74 STRING_CHECK(AlphaMode, OPAQUE);
75 STRING_CHECK(AlphaMode, MASK);
76 STRING_CHECK(AlphaMode, BLEND);
77 DALI_TEST_EQUAL(gltf2::AlphaMode::FROM_STRING_HELPER(ALPHA_SCHMALPHA), gltf2::AlphaMode::INVALID);
82 int UtcDaliGltf2AssetAttribute(void)
84 STRING_CHECK(Attribute, POSITION);
85 STRING_CHECK(Attribute, NORMAL);
86 STRING_CHECK(Attribute, TANGENT);
87 STRING_CHECK(Attribute, TEXCOORD_0);
88 STRING_CHECK(Attribute, TEXCOORD_1);
89 STRING_CHECK(Attribute, COLOR_0);
90 STRING_CHECK(Attribute, JOINTS_0);
91 STRING_CHECK(Attribute, WEIGHTS_0);
92 DALI_TEST_EQUAL(gltf2::Attribute::FROM_STRING_HELPER(VISCOSITY), gltf2::Attribute::INVALID);
97 int UtcDaliGltf2AssetAnimationSamplerInterpolation(void)
99 STRING_CHECK(Animation::Sampler::Interpolation, STEP);
100 STRING_CHECK(Animation::Sampler::Interpolation, LINEAR);
101 STRING_CHECK(Animation::Sampler::Interpolation, CUBICSPLINE);
102 DALI_TEST_EQUAL(gltf2::Animation::Sampler::Interpolation::FROM_STRING_HELPER(EASE_IN_OUT), gltf2::Animation::Sampler::Interpolation::INVALID);
107 int UtcDaliGltf2AssetAnimationChannelTarget(void)
109 STRING_CHECK(Animation::Channel::Target, TRANSLATION);
110 STRING_CHECK(Animation::Channel::Target, ROTATION);
111 STRING_CHECK(Animation::Channel::Target, SCALE);
112 STRING_CHECK(Animation::Channel::Target, WEIGHTS);
113 DALI_TEST_EQUAL(gltf2::Animation::Channel::Target::FROM_STRING_HELPER(FLUFFINESS), gltf2::Animation::Channel::Target::INVALID);
118 int UtcDaliGltf2AssetAccessorSparse(void)
121 DALI_TEST_CHECK(!acc.mSparse);
123 std::vector<gltf2::BufferView> bufferViews;
125 gltf2::Accessor::Sparse sparse{ 256u };
126 sparse.mIndices.mBufferView = gltf2::Ref<gltf2::BufferView>(bufferViews, 5u);
127 sparse.mIndices.mComponentType = gltf2::Component::FLOAT;
128 sparse.mValues.mBufferView = gltf2::Ref<gltf2::BufferView>(bufferViews, 284u);
129 sparse.mValues.mByteOffset = 16532;
130 acc.SetSparse(sparse);
132 DALI_TEST_EQUAL(acc.mSparse->mCount, sparse.mCount);
133 DALI_TEST_EQUAL(acc.mSparse->mIndices.mBufferView, sparse.mIndices.mBufferView);
134 DALI_TEST_EQUAL(acc.mSparse->mIndices.mByteOffset, sparse.mIndices.mByteOffset);
135 DALI_TEST_EQUAL(acc.mSparse->mIndices.mComponentType, sparse.mIndices.mComponentType);
136 DALI_TEST_EQUAL(acc.mSparse->mValues.mBufferView, sparse.mValues.mBufferView);
137 DALI_TEST_EQUAL(acc.mSparse->mValues.mByteOffset, sparse.mValues.mByteOffset);