[AT-SPI] Squashed implementation
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit / dali-toolkit-test-utils / test-compare-types.h
1 #ifndef DALI_TEST_COMPARE_TYPES_H
2 #define DALI_TEST_COMPARE_TYPES_H
3
4 /*
5  * Copyright (c) 2020 Samsung Electronics Co., Ltd.
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  */
19
20 #include <dali/public-api/dali-core.h>
21 using namespace Dali;
22
23 template<typename Type>
24 inline bool CompareType(Type value1, Type value2, float epsilon)
25 {
26   return value1 == value2;
27 }
28
29 /**
30  * A helper for fuzzy-comparing Vector2 objects
31  * @param[in] vector1 the first object
32  * @param[in] vector2 the second object
33  * @param[in] epsilon difference threshold
34  * @returns true if difference is smaller than epsilon threshold, false otherwise
35  */
36 template<>
37 inline bool CompareType<float>(float value1, float value2, float epsilon)
38 {
39   return fabsf(value1 - value2) < epsilon;
40 }
41
42 /**
43  * A helper for fuzzy-comparing Vector2 objects
44  * @param[in] vector1 the first object
45  * @param[in] vector2 the second object
46  * @param[in] epsilon difference threshold
47  * @returns true if difference is smaller than epsilon threshold, false otherwise
48  */
49 template<>
50 inline bool CompareType<Vector2>(Vector2 vector1, Vector2 vector2, float epsilon)
51 {
52   return fabsf(vector1.x - vector2.x) < epsilon && fabsf(vector1.y - vector2.y) < epsilon;
53 }
54
55 /**
56  * A helper for fuzzy-comparing Vector3 objects
57  * @param[in] vector1 the first object
58  * @param[in] vector2 the second object
59  * @param[in] epsilon difference threshold
60  * @returns true if difference is smaller than epsilon threshold, false otherwise
61  */
62 template<>
63 inline bool CompareType<Vector3>(Vector3 vector1, Vector3 vector2, float epsilon)
64 {
65   return fabsf(vector1.x - vector2.x) < epsilon &&
66          fabsf(vector1.y - vector2.y) < epsilon &&
67          fabsf(vector1.z - vector2.z) < epsilon;
68 }
69
70 /**
71  * A helper for fuzzy-comparing Vector4 objects
72  * @param[in] vector1 the first object
73  * @param[in] vector2 the second object
74  * @param[in] epsilon difference threshold
75  * @returns true if difference is smaller than epsilon threshold, false otherwise
76  */
77 template<>
78 inline bool CompareType<Vector4>(Vector4 vector1, Vector4 vector2, float epsilon)
79 {
80   return fabsf(vector1.x - vector2.x) < epsilon &&
81          fabsf(vector1.y - vector2.y) < epsilon &&
82          fabsf(vector1.z - vector2.z) < epsilon &&
83          fabsf(vector1.w - vector2.w) < epsilon;
84 }
85
86 template<>
87 inline bool CompareType<Quaternion>(Quaternion q1, Quaternion q2, float epsilon)
88 {
89   Quaternion q2N = -q2; // These quaternions represent the same rotation
90   return CompareType<Vector4>(q1.mVector, q2.mVector, epsilon) || CompareType<Vector4>(q1.mVector, q2N.mVector, epsilon);
91 }
92
93 template<>
94 inline bool CompareType<Radian>(Radian q1, Radian q2, float epsilon)
95 {
96   return CompareType<float>(q1.radian, q2.radian, epsilon);
97 }
98
99 template<>
100 inline bool CompareType<Degree>(Degree q1, Degree q2, float epsilon)
101 {
102   return CompareType<float>(q1.degree, q2.degree, epsilon);
103 }
104
105 template<>
106 inline bool CompareType<Extents>(Extents extents1, Extents extents2, float epsilon)
107 {
108   return (extents1.start == extents2.start) &&
109          (extents1.end == extents2.end) &&
110          (extents1.top == extents2.top) &&
111          (extents1.bottom == extents2.bottom);
112 }
113
114 template<>
115 inline bool CompareType<Property::Value>(Property::Value q1, Property::Value q2, float epsilon)
116 {
117   Property::Type type = q1.GetType();
118   if(type != q2.GetType())
119   {
120     return false;
121   }
122
123   bool result = false;
124   switch(type)
125   {
126     case Property::BOOLEAN:
127     {
128       bool a, b;
129       q1.Get(a);
130       q2.Get(b);
131       result = a == b;
132       break;
133     }
134     case Property::INTEGER:
135     {
136       int a, b;
137       q1.Get(a);
138       q2.Get(b);
139       result = a == b;
140       break;
141     }
142     case Property::FLOAT:
143     {
144       float a, b;
145       q1.Get(a);
146       q2.Get(b);
147       result = CompareType<float>(a, b, epsilon);
148       break;
149     }
150     case Property::VECTOR2:
151     {
152       Vector2 a, b;
153       q1.Get(a);
154       q2.Get(b);
155       result = CompareType<Vector2>(a, b, epsilon);
156       break;
157     }
158     case Property::VECTOR3:
159     {
160       Vector3 a, b;
161       q1.Get(a);
162       q2.Get(b);
163       result = CompareType<Vector3>(a, b, epsilon);
164       break;
165     }
166     case Property::RECTANGLE:
167     case Property::VECTOR4:
168     {
169       Vector4 a, b;
170       q1.Get(a);
171       q2.Get(b);
172       result = CompareType<Vector4>(a, b, epsilon);
173       break;
174     }
175     case Property::ROTATION:
176     {
177       Quaternion a, b;
178       q1.Get(a);
179       q2.Get(b);
180       result = CompareType<Quaternion>(a, b, epsilon);
181       break;
182     }
183     case Property::STRING:
184     {
185       std::string a, b;
186       q1.Get(a);
187       q2.Get(b);
188       result = (a.compare(b) == 0);
189       break;
190     }
191     case Property::MATRIX:
192     case Property::MATRIX3:
193     case Property::ARRAY:
194     case Property::MAP:
195     {
196       //TODO: Implement this?
197       DALI_ASSERT_ALWAYS(0 && "Not implemented");
198       result = false;
199       break;
200     }
201     case Property::EXTENTS:
202     {
203       Extents a, b;
204       q1.Get(a);
205       q2.Get(b);
206       result = CompareType<Extents>(a, b, epsilon);
207       break;
208     }
209     case Property::NONE:
210     {
211       result = false;
212       break;
213     }
214   }
215
216   return result;
217 }
218
219 #endif