[dali_2.3.21] Merge branch 'devel/master'
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-scene3d / utc-Dali-MotionPropertyIndex.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 #include <dali-toolkit-test-suite-utils.h>
19 #include <dali-toolkit/dali-toolkit.h>
20 #include <stdlib.h>
21 #include <iostream>
22
23 #include <dali-scene3d/public-api/model-motion/motion-index/motion-index.h>
24 #include <dali-scene3d/public-api/model-motion/motion-index/motion-property-index.h>
25
26 using namespace Dali;
27 using namespace Dali::Toolkit;
28 using namespace Dali::Scene3D;
29
30 void model_motion_motion_property_index_startup(void)
31 {
32   test_return_value = TET_UNDEF;
33 }
34
35 void model_motion_motion_property_index_cleanup(void)
36 {
37   test_return_value = TET_PASS;
38 }
39
40 namespace
41 {
42 } // namespace
43
44 // Positive test case for a method
45 int UtcDaliMotionPropertyIndexNew(void)
46 {
47   ToolkitTestApplication application;
48   tet_infoline(" UtcDaliMotionPropertyIndexNew");
49
50   MotionPropertyIndex motionPropertyIndex = MotionPropertyIndex::New();
51   DALI_TEST_CHECK(motionPropertyIndex);
52   DALI_TEST_EQUALS(motionPropertyIndex.GetModelNodeId().stringKey, "", TEST_LOCATION);
53   DALI_TEST_EQUALS(motionPropertyIndex.GetPropertyId().indexKey, Property::INVALID_INDEX, TEST_LOCATION);
54
55   motionPropertyIndex = MotionPropertyIndex::New("dummy", 3u);
56   DALI_TEST_CHECK(motionPropertyIndex);
57   DALI_TEST_EQUALS(motionPropertyIndex.GetModelNodeId().stringKey, "dummy", TEST_LOCATION);
58   DALI_TEST_EQUALS(motionPropertyIndex.GetPropertyId().indexKey, 3u, TEST_LOCATION);
59   END_TEST;
60 }
61
62 // Positive test case for a method
63 int UtcDaliMotionPropertyIndexDownCast(void)
64 {
65   ToolkitTestApplication application;
66   tet_infoline(" UtcDaliMotionPropertyIndexDownCast");
67
68   MotionPropertyIndex motionPropertyIndex = MotionPropertyIndex::New();
69   BaseHandle          handle(motionPropertyIndex);
70
71   MotionPropertyIndex motionPropertyIndex2 = MotionPropertyIndex::DownCast(handle);
72   DALI_TEST_CHECK(motionPropertyIndex);
73   DALI_TEST_CHECK(motionPropertyIndex2);
74   DALI_TEST_CHECK(motionPropertyIndex2 == motionPropertyIndex);
75   END_TEST;
76 }
77
78 int UtcDaliMotionPropertyIndexTypeRegistry(void)
79 {
80   ToolkitTestApplication application;
81
82   TypeRegistry typeRegistry = TypeRegistry::Get();
83   DALI_TEST_CHECK(typeRegistry);
84
85   TypeInfo typeInfo = typeRegistry.GetTypeInfo("MotionPropertyIndex");
86   DALI_TEST_CHECK(typeInfo);
87
88   BaseHandle handle = typeInfo.CreateInstance();
89   DALI_TEST_CHECK(handle);
90
91   MotionPropertyIndex motionPropertyIndex = MotionPropertyIndex::DownCast(handle);
92   DALI_TEST_CHECK(motionPropertyIndex);
93
94   END_TEST;
95 }
96
97 int UtcDaliMotionPropertyIndexCopyAndAssignment(void)
98 {
99   ToolkitTestApplication application;
100
101   MotionPropertyIndex motionPropertyIndex = MotionPropertyIndex::New();
102   DALI_TEST_CHECK(motionPropertyIndex);
103
104   MotionPropertyIndex copy(motionPropertyIndex);
105   DALI_TEST_CHECK(motionPropertyIndex == copy);
106
107   MotionPropertyIndex assign;
108   DALI_TEST_CHECK(!assign);
109
110   assign = copy;
111   DALI_TEST_CHECK(assign == motionPropertyIndex);
112
113   END_TEST;
114 }
115
116 int UtcDaliMotionPropertyIndexMoveConstructor(void)
117 {
118   ToolkitTestApplication application;
119
120   MotionPropertyIndex motionPropertyIndex = MotionPropertyIndex::New();
121   DALI_TEST_EQUALS(1, motionPropertyIndex.GetBaseObject().ReferenceCount(), TEST_LOCATION);
122
123   MotionPropertyIndex moved = std::move(motionPropertyIndex);
124   DALI_TEST_CHECK(moved);
125   DALI_TEST_EQUALS(1, moved.GetBaseObject().ReferenceCount(), TEST_LOCATION);
126   DALI_TEST_CHECK(!motionPropertyIndex);
127
128   END_TEST;
129 }
130
131 int UtcDaliMotionPropertyIndexMoveAssignment(void)
132 {
133   ToolkitTestApplication application;
134
135   MotionPropertyIndex motionPropertyIndex = MotionPropertyIndex::New();
136   DALI_TEST_EQUALS(1, motionPropertyIndex.GetBaseObject().ReferenceCount(), TEST_LOCATION);
137
138   MotionPropertyIndex moved;
139   moved = std::move(motionPropertyIndex);
140   DALI_TEST_CHECK(moved);
141   DALI_TEST_EQUALS(1, moved.GetBaseObject().ReferenceCount(), TEST_LOCATION);
142
143   END_TEST;
144 }
145
146 // Method test
147
148 int UtcDaliMotionPropertyIndexGetPropertyName(void)
149 {
150   std::string     expectPropertyName  = "";
151   Property::Index expectPropertyIndex = Property::INVALID_INDEX;
152
153   MotionIndex index = MotionPropertyIndex::New();
154
155   // Invalid motion index return empty string, invalid index
156   DALI_TEST_EQUALS(expectPropertyName, index.GetPropertyName(), TEST_LOCATION);
157   DALI_TEST_EQUALS(expectPropertyIndex, index.GetPropertyIndex(), TEST_LOCATION);
158
159   expectPropertyIndex = 0u;
160   index               = MotionPropertyIndex::New("", expectPropertyIndex);
161   DALI_TEST_EQUALS(expectPropertyIndex, index.GetPropertyIndex(), TEST_LOCATION);
162
163   expectPropertyIndex = 45u;
164   index               = MotionPropertyIndex::New("", expectPropertyIndex);
165   DALI_TEST_EQUALS(expectPropertyIndex, index.GetPropertyIndex(), TEST_LOCATION);
166
167   expectPropertyName = "name";
168   index              = MotionPropertyIndex::New("", expectPropertyName);
169   DALI_TEST_EQUALS(expectPropertyName, index.GetPropertyName(), TEST_LOCATION);
170
171   END_TEST;
172 }
173
174 int UtcDaliMotionPropertyIndexSetGetPropertyId(void)
175 {
176   Property::Index expectPropertyIndex = 0u;
177
178   MotionPropertyIndex index = MotionPropertyIndex::New("", expectPropertyIndex);
179
180   // Invalid motion index return empty string, invalid index
181   DALI_TEST_CHECK(index.GetPropertyId().type == Property::Key::Type::INDEX);
182   DALI_TEST_EQUALS(expectPropertyIndex, index.GetPropertyId().indexKey, TEST_LOCATION);
183
184   std::string expectPropertyName = "hello";
185   index.SetPropertyId(expectPropertyName);
186   DALI_TEST_CHECK(index.GetPropertyId().type == Property::Key::Type::STRING);
187   DALI_TEST_EQUALS(expectPropertyName, index.GetPropertyId().stringKey, TEST_LOCATION);
188
189   expectPropertyIndex = 100u;
190   index.SetPropertyId(expectPropertyIndex);
191   DALI_TEST_CHECK(index.GetPropertyId().type == Property::Key::Type::INDEX);
192   DALI_TEST_EQUALS(expectPropertyIndex, index.GetPropertyId().indexKey, TEST_LOCATION);
193
194   END_TEST;
195 }