(AnimatedVectorImageVisual) Render frames based on content's fps
[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) 2017 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
24 template <typename Type>
25 inline bool CompareType(Type value1, Type value2, float epsilon)
26 {
27   return value1 == value2;
28 }
29
30 /**
31  * A helper for fuzzy-comparing Vector2 objects
32  * @param[in] vector1 the first object
33  * @param[in] vector2 the second object
34  * @param[in] epsilon difference threshold
35  * @returns true if difference is smaller than epsilon threshold, false otherwise
36  */
37 template <>
38 inline bool CompareType<float>(float value1, float value2, float epsilon)
39 {
40   return fabsf(value1 - value2) < epsilon;
41 }
42
43 /**
44  * A helper for fuzzy-comparing Vector2 objects
45  * @param[in] vector1 the first object
46  * @param[in] vector2 the second object
47  * @param[in] epsilon difference threshold
48  * @returns true if difference is smaller than epsilon threshold, false otherwise
49  */
50 template <>
51 inline bool CompareType<Vector2>(Vector2 vector1, Vector2 vector2, float epsilon)
52 {
53   return fabsf(vector1.x - vector2.x)<epsilon && fabsf(vector1.y - vector2.y)<epsilon;
54 }
55
56 /**
57  * A helper for fuzzy-comparing Vector3 objects
58  * @param[in] vector1 the first object
59  * @param[in] vector2 the second object
60  * @param[in] epsilon difference threshold
61  * @returns true if difference is smaller than epsilon threshold, false otherwise
62  */
63 template <>
64 inline bool CompareType<Vector3>(Vector3 vector1, Vector3 vector2, float epsilon)
65 {
66   return fabsf(vector1.x - vector2.x)<epsilon &&
67          fabsf(vector1.y - vector2.y)<epsilon &&
68          fabsf(vector1.z - vector2.z)<epsilon;
69 }
70
71
72 /**
73  * A helper for fuzzy-comparing Vector4 objects
74  * @param[in] vector1 the first object
75  * @param[in] vector2 the second object
76  * @param[in] epsilon difference threshold
77  * @returns true if difference is smaller than epsilon threshold, false otherwise
78  */
79 template <>
80 inline bool CompareType<Vector4>(Vector4 vector1, Vector4 vector2, float epsilon)
81 {
82   return fabsf(vector1.x - vector2.x)<epsilon &&
83          fabsf(vector1.y - vector2.y)<epsilon &&
84          fabsf(vector1.z - vector2.z)<epsilon &&
85          fabsf(vector1.w - vector2.w)<epsilon;
86 }
87
88 template <>
89 inline bool CompareType<Quaternion>(Quaternion q1, Quaternion q2, float epsilon)
90 {
91   Quaternion q2N = -q2; // These quaternions represent the same rotation
92   return CompareType<Vector4>(q1.mVector, q2.mVector, epsilon) || CompareType<Vector4>(q1.mVector, q2N.mVector, epsilon);
93 }
94
95 template <>
96 inline bool CompareType<Radian>(Radian q1, Radian q2, float epsilon)
97 {
98   return CompareType<float>(q1.radian, q2.radian, epsilon);
99 }
100
101 template <>
102 inline bool CompareType<Degree>(Degree q1, Degree q2, float epsilon)
103 {
104   return CompareType<float>(q1.degree, q2.degree, epsilon);
105 }
106
107 template <>
108 inline bool CompareType<Extents>(Extents extents1, Extents extents2, float epsilon)
109 {
110   return (extents1.start == extents2.start) &&
111          (extents1.end == extents2.end) &&
112          (extents1.top == extents2.top) &&
113          (extents1.bottom == extents2.bottom);
114 }
115
116 template <>
117 inline bool CompareType<Property::Value>(Property::Value q1, Property::Value q2, float epsilon)
118 {
119   Property::Type type = q1.GetType();
120   if( type != q2.GetType() )
121   {
122     return false;
123   }
124
125   bool result = false;
126   switch(type)
127   {
128     case Property::BOOLEAN:
129     {
130       bool a, b;
131       q1.Get(a);
132       q2.Get(b);
133       result =  a == b;
134       break;
135     }
136     case Property::INTEGER:
137     {
138       int a, b;
139       q1.Get(a);
140       q2.Get(b);
141       result =  a == b;
142       break;
143     }
144     case Property::FLOAT:
145     {
146       float a, b;
147       q1.Get(a);
148       q2.Get(b);
149       result =  CompareType<float>(a, b, epsilon);
150       break;
151     }
152     case Property::VECTOR2:
153     {
154       Vector2 a, b;
155       q1.Get(a);
156       q2.Get(b);
157       result = CompareType<Vector2>(a, b, epsilon);
158       break;
159     }
160     case Property::VECTOR3:
161     {
162       Vector3 a, b;
163       q1.Get(a);
164       q2.Get(b);
165       result = CompareType<Vector3>(a, b, epsilon);
166       break;
167     }
168     case Property::RECTANGLE:
169     case Property::VECTOR4:
170     {
171       Vector4 a, b;
172       q1.Get(a);
173       q2.Get(b);
174       result = CompareType<Vector4>(a, b, epsilon);
175       break;
176     }
177     case Property::ROTATION:
178     {
179       Quaternion a, b;
180       q1.Get(a);
181       q2.Get(b);
182       result = CompareType<Quaternion>(a, b, epsilon);
183       break;
184     }
185     case Property::STRING:
186     {
187       std::string a, b;
188       q1.Get(a);
189       q2.Get(b);
190       result = (a.compare(b) == 0);
191       break;
192     }
193     case Property::MATRIX:
194     case Property::MATRIX3:
195     case Property::ARRAY:
196     case Property::MAP:
197     {
198       //TODO: Implement this?
199       DALI_ASSERT_ALWAYS( 0 && "Not implemented");
200       result = false;
201       break;
202     }
203     case Property::EXTENTS:
204     {
205       Extents a, b;
206       q1.Get(a);
207       q2.Get(b);
208       result = CompareType<Extents>( a, b, epsilon );
209       break;
210     }
211     case Property::NONE:
212     {
213       result = false;
214       break;
215     }
216   }
217
218   return result;
219 }
220
221
222
223 #endif