[dali_2.3.21] Merge branch 'devel/master'
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-scene3d / utc-Dali-MotionIndex.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/blend-shape-index.h>
24 #include <dali-scene3d/public-api/model-motion/motion-index/motion-index.h>
25 #include <dali-scene3d/public-api/model-motion/motion-index/motion-property-index.h>
26 #include <dali-scene3d/public-api/model-motion/motion-index/motion-transform-index.h>
27
28 using namespace Dali;
29 using namespace Dali::Toolkit;
30 using namespace Dali::Scene3D;
31
32 void model_motion_motion_index_startup(void)
33 {
34   test_return_value = TET_UNDEF;
35 }
36
37 void model_motion_motion_index_cleanup(void)
38 {
39   test_return_value = TET_PASS;
40 }
41
42 namespace
43 {
44 } // namespace
45
46 // Positive test case for a method
47 int UtcDaliMotionIndexDownCast(void)
48 {
49   ToolkitTestApplication application;
50   tet_infoline(" UtcDaliMotionIndexDownCast");
51
52   MotionIndex blendShapeIndex = BlendShapeIndex::New();
53   BaseHandle  handle(blendShapeIndex);
54
55   MotionIndex blendShapeIndex2 = MotionIndex::DownCast(handle);
56   DALI_TEST_CHECK(blendShapeIndex);
57   DALI_TEST_CHECK(blendShapeIndex2);
58   DALI_TEST_CHECK(blendShapeIndex2 == blendShapeIndex);
59   END_TEST;
60 }
61
62 int UtcDaliMotionIndexDownCastNotMatchedType(void)
63 {
64   ToolkitTestApplication application;
65   tet_infoline(" UtcDaliMotionIndexDownCastNotMatchedType");
66
67   {
68     MotionIndex baseIndex = BlendShapeIndex::New();
69     DALI_TEST_CHECK(baseIndex);
70
71     BaseHandle handle(baseIndex);
72
73     MotionIndex motionPropertyIndex = MotionPropertyIndex::DownCast(handle);
74     DALI_TEST_CHECK(!motionPropertyIndex);
75
76     MotionIndex motionTransformIndex = MotionTransformIndex::DownCast(handle);
77     DALI_TEST_CHECK(!motionTransformIndex);
78
79     MotionIndex blendShapeIndex = BlendShapeIndex::DownCast(handle);
80     DALI_TEST_CHECK(blendShapeIndex);
81     DALI_TEST_CHECK(blendShapeIndex == baseIndex);
82   }
83   END_TEST;
84 }
85
86 int UtcDaliMotionIndexCopyAndAssignment(void)
87 {
88   ToolkitTestApplication application;
89
90   MotionIndex blendShapeIndex = BlendShapeIndex::New();
91   DALI_TEST_CHECK(blendShapeIndex);
92
93   MotionIndex copy(blendShapeIndex);
94   DALI_TEST_CHECK(blendShapeIndex == copy);
95
96   MotionIndex assign;
97   DALI_TEST_CHECK(!assign);
98
99   assign = copy;
100   DALI_TEST_CHECK(assign == blendShapeIndex);
101
102   END_TEST;
103 }
104
105 int UtcDaliMotionIndexMoveConstructor(void)
106 {
107   ToolkitTestApplication application;
108
109   MotionIndex blendShapeIndex = MotionTransformIndex::New();
110   DALI_TEST_EQUALS(1, blendShapeIndex.GetBaseObject().ReferenceCount(), TEST_LOCATION);
111
112   MotionIndex moved = std::move(blendShapeIndex);
113   DALI_TEST_CHECK(moved);
114   DALI_TEST_EQUALS(1, moved.GetBaseObject().ReferenceCount(), TEST_LOCATION);
115   DALI_TEST_CHECK(!blendShapeIndex);
116
117   END_TEST;
118 }
119
120 int UtcDaliMotionIndexMoveAssignment(void)
121 {
122   ToolkitTestApplication application;
123
124   MotionIndex blendShapeIndex = BlendShapeIndex::New();
125   DALI_TEST_EQUALS(1, blendShapeIndex.GetBaseObject().ReferenceCount(), TEST_LOCATION);
126
127   MotionIndex moved;
128   moved = std::move(blendShapeIndex);
129   DALI_TEST_CHECK(moved);
130   DALI_TEST_EQUALS(1, moved.GetBaseObject().ReferenceCount(), TEST_LOCATION);
131
132   END_TEST;
133 }
134
135 // Method test
136
137 int UtcDaliMotionIndexSetGetModelNodeId(void)
138 {
139   std::string expectModelNodeStringId = "nodeId";
140   MotionIndex index                   = MotionTransformIndex::New(expectModelNodeStringId, MotionTransformIndex::TransformType::POSITION);
141
142   auto propertyKey = index.GetModelNodeId();
143   DALI_TEST_CHECK(propertyKey.type == Property::Key::Type::STRING);
144   DALI_TEST_EQUALS(expectModelNodeStringId, propertyKey.stringKey, TEST_LOCATION);
145
146   expectModelNodeStringId = "anotherId";
147   index.SetModelNodeId(expectModelNodeStringId);
148
149   propertyKey = index.GetModelNodeId();
150   DALI_TEST_CHECK(propertyKey.type == Property::Key::Type::STRING);
151   DALI_TEST_EQUALS(expectModelNodeStringId, propertyKey.stringKey, TEST_LOCATION);
152
153   Property::Index expectModelNodeIndexId = 193u;
154   index.SetModelNodeId(expectModelNodeIndexId);
155
156   propertyKey = index.GetModelNodeId();
157   DALI_TEST_CHECK(propertyKey.type == Property::Key::Type::INDEX);
158   DALI_TEST_EQUALS(expectModelNodeIndexId, propertyKey.indexKey, TEST_LOCATION);
159
160   END_TEST;
161 }