Change RegisterGlCallback function name of GlView
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-scene-loader-internal / utc-Dali-Gltf2Asset.cpp
1 /*
2  * Copyright (c) 2020 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-scene-loader/internal/gltf2-asset.h"
22 #include <dali-test-suite-utils.h>
23 #include <string>
24
25 using namespace Dali;
26 using namespace Dali::SceneLoader;
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
56 #define STRING_CHECK(type, x) DALI_TEST_EQUAL(gltf2::type:: FROM_STRING_HELPER(x), gltf2::type::x)
57
58 int UtcDaliGltf2AssetAccessorType(void)
59 {
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);
68
69   END_TEST;
70 }
71
72 int UtcDaliGltf2AssetAlphaMode(void)
73 {
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);
78
79   END_TEST;
80 }
81
82 int UtcDaliGltf2AssetAttribute(void)
83 {
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);
93
94   END_TEST;
95 }
96
97 int UtcDaliGltf2AssetAnimationSamplerInterpolation(void)
98 {
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);
103
104   END_TEST;
105 }
106
107 int UtcDaliGltf2AssetAnimationChannelTarget(void)
108 {
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);
114
115   END_TEST;
116 }
117
118 int UtcDaliGltf2AssetAccessorSparse(void)
119 {
120   gltf2::Accessor acc;
121   DALI_TEST_CHECK(!acc.mSparse);
122
123   std::vector<gltf2::BufferView> bufferViews;
124
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);
131
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);
138
139   END_TEST;
140 }
141