[dali_2.3.29] Merge branch 'devel/master'
[platform/core/uifw/dali-core.git] / automated-tests / src / dali-internal / utc-Dali-Internal-TransformManagerProperty.cpp
1 /*
2  * Copyright (c) 2024 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 #define DEBUG_ENABLED 1
19
20 #include <dali-test-suite-utils.h>
21 #include <dali/internal/update/manager/transform-manager-property.h>
22 #include <dali/internal/update/nodes/node-helper.h>
23
24 // Internal headers are allowed here
25
26 namespace
27 {
28 #if defined(DEBUG_ENABLED)
29 Debug::Filter* gLogFilter = Debug::Filter::New(Debug::Verbose, true, "LOG_UTC_TRANSFORM_MANAGER_PROPERTY");
30 #endif
31 } // namespace
32
33 void utc_dali_internal_transform_manager_property_startup()
34 {
35   test_return_value = TET_UNDEF;
36 }
37
38 void utc_dali_internal_transform_manager_property_cleanup()
39 {
40   test_return_value = TET_PASS;
41 }
42
43 int UtcTransformManagerPropertyGetFloatComponentN(void)
44 {
45   TestApplication application;
46
47   // For coverage
48   DALI_LOG_TRACE_METHOD(gLogFilter);
49
50   struct S
51   {
52     Dali::Internal::SceneGraph::TransformManagerData                                  txMgrData;
53     Dali::Internal::SceneGraph::TransformManagerPropertyQuaternion<sizeof(txMgrData)> property;
54   } s;
55
56   try
57   {
58     // There is no float component getter in derived class, only in base class.
59     s.property.GetFloatComponent(0u);
60   }
61   catch(Dali::DaliException& e)
62   {
63     DALI_TEST_ASSERT(e, "0 && \"Invalid call\"", TEST_LOCATION);
64   }
65
66   // For coverage
67   DALI_LOG_INFO(gLogFilter, Debug::Verbose, "Test End\n");
68
69   END_TEST;
70 }
71
72 int UtcTransformManagerPropertyUninitializedMgrData(void)
73 {
74   TestApplication application;
75
76   struct S
77   {
78     const Vector3 input{1.0f, 2.0f, 3.0f};
79
80     Dali::Internal::SceneGraph::TransformManagerData                            txMgrData;
81     Dali::Internal::SceneGraph::TransformManagerVector3Input<sizeof(txMgrData)> property{Dali::Internal::SceneGraph::TRANSFORM_PROPERTY_POSITION, input};
82   } s;
83
84   Vector3 output = s.property.GetVector3(0);
85
86   tet_infoline("Test that if input property's transform manager data is not initialized, that getting a value returns the initial value of the property.");
87
88   DALI_TEST_EQUALS(s.input, output, 0.001f, TEST_LOCATION);
89
90   END_TEST;
91 }
92
93 using namespace Dali::Internal::SceneGraph;
94 int UtcDaliInternalTransformPropertyGetValueSize(void)
95 {
96   struct S
97   {
98     Dali::Internal::PropertyInputImpl* property;
99     Property::Value                    value;
100     size_t                             size;
101     S(Dali::Internal::PropertyInputImpl* p, Property::Value v, size_t s)
102     : property(p),
103       value(v),
104       size(s)
105     {
106     }
107   };
108   std::vector<S> properties;
109
110   properties.emplace_back(new TransformManagerPropertyVector3<TransformManagerProperty::TRANSFORM_PROPERTY_SCALE, 0>(), Vector3(2.3f, 4.5f, 1.9f), sizeof(Vector3));
111
112   properties.emplace_back(new TransformManagerPropertyQuaternion<0>(), Quaternion(Radian(1.619f), Vector3::ZAXIS), sizeof(Quaternion));
113
114   properties.emplace_back(new TransformManagerVector3Input<0>(TransformManagerProperty::TRANSFORM_PROPERTY_WORLD_SCALE, Vector3(2.3f, 4.5f, 1.9f)), Vector3(2.3f, 4.5f, 1.9f), sizeof(Vector3));
115
116   properties.emplace_back(new TransformManagerQuaternionInput<0>(), Quaternion(Radian(1.619f), Vector3::ZAXIS), sizeof(Quaternion));
117
118   properties.emplace_back(new TransformManagerMatrixInput<0>(), Matrix::IDENTITY, sizeof(Matrix));
119
120   for(auto& s : properties)
121   {
122     DALI_TEST_EQUALS(s.property->GetValueSize(), s.size, TEST_LOCATION);
123   }
124
125   END_TEST;
126 }
127
128 int UtcDaliInternalTransformPropertyGetValueAddress(void)
129 {
130   struct N
131   {
132     BASE(TransformManagerData, mTransformManagerData);
133     PROPERTY_WRAPPER(mTransformManagerData, TransformManagerPropertyVector3, TRANSFORM_PROPERTY_SCALE, mScale);
134     TEMPLATE_WRAPPER(mScale, TransformManagerPropertyQuaternion, mOrientation);
135     TEMPLATE_WRAPPER(mOrientation, TransformManagerVector3Input, mWorldPosition);
136     TEMPLATE_WRAPPER(mWorldPosition, TransformManagerQuaternionInput, mWorldOrientation);
137     TEMPLATE_WRAPPER(mWorldOrientation, TransformManagerMatrixInput, mWorldMatrix);
138
139     N()
140     : mTransformManagerData(),
141       mWorldPosition(TRANSFORM_PROPERTY_WORLD_POSITION, Vector3(1.0f, 1.0f, 1.0f)),
142       mWorldOrientation(),
143       mWorldMatrix()
144     {
145     }
146   };
147
148   TransformManager testManager;
149   N                node;
150   node.mTransformManagerData.mManager = &testManager;
151   node.mTransformManagerData.mId      = testManager.CreateTransform();
152
153   const void* addr = node.mScale.GetValueAddress(0);
154   node.mScale.Set(0, Vector3(1.2f, 1.2f, 1.2f));
155
156   DALI_TEST_EQUALS(*reinterpret_cast<const Vector3*>(addr), Vector3(1.2f, 1.2f, 1.2f), TEST_LOCATION);
157
158   node.mOrientation.Set(0, Quaternion(Radian(1.619f), Vector3::ZAXIS));
159   addr = node.mOrientation.GetValueAddress(0);
160   DALI_TEST_EQUALS(*reinterpret_cast<const Quaternion*>(addr), Quaternion(Radian(1.619f), Vector3::ZAXIS), TEST_LOCATION);
161
162   Matrix& m = node.mWorldMatrix.Get(0);
163   m         = Matrix::IDENTITY;
164
165   addr = node.mWorldPosition.GetValueAddress(0);
166   DALI_TEST_EQUALS(*reinterpret_cast<const Vector3*>(addr), Vector3(0.f, 0.f, 0.f), TEST_LOCATION);
167
168   addr = node.mWorldOrientation.GetValueAddress(0);
169   DALI_TEST_EQUALS(*reinterpret_cast<const Quaternion*>(addr), Quaternion(Radian(0), Vector3::ZAXIS), TEST_LOCATION);
170
171   addr = node.mWorldMatrix.GetValueAddress(0);
172   DALI_TEST_EQUALS(*reinterpret_cast<const Matrix*>(addr), Matrix::IDENTITY, TEST_LOCATION);
173
174   END_TEST;
175 }