Merge "Make Dali::Any move operator + Resolve memory leak." into devel/master
[platform/core/uifw/dali-core.git] / automated-tests / src / dali / utc-Dali-IntPair.cpp
1 /*
2  * Copyright (c) 2022 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-test-suite-utils.h>
19 #include <dali/public-api/dali-core.h>
20 #include <stdlib.h>
21
22 #include <iostream>
23
24 using namespace Dali;
25
26 namespace
27 {
28 /// Compare a uint16_t value with an unsigned int
29 void DALI_TEST_EQUALS(uint16_t value1, unsigned int value2, const char* location)
30 {
31   ::DALI_TEST_EQUALS<uint16_t>(value1, static_cast<uint16_t>(value2), location);
32 }
33 } // unnamed namespace
34
35 // class Uint16Pair
36
37 int UtcDaliUint16PairConstructor01P(void)
38 {
39   Uint16Pair v;
40
41   DALI_TEST_EQUALS(v.GetX(), 0u, TEST_LOCATION);
42   DALI_TEST_EQUALS(v.GetY(), 0u, TEST_LOCATION);
43
44   END_TEST;
45 }
46
47 int UtcDaliUint16PairConstructor02P(void)
48 {
49   Uint16Pair v(10u, 10u);
50
51   DALI_TEST_EQUALS(v.GetX(), 10u, TEST_LOCATION);
52   DALI_TEST_EQUALS(v.GetY(), 10u, TEST_LOCATION);
53
54   END_TEST;
55 }
56
57 int UtcDaliUint16PairCopyConstructor(void)
58 {
59   Uint16Pair u(5u, 5u);
60   Uint16Pair v(u);
61   DALI_TEST_EQUALS(v.GetX(), 5u, TEST_LOCATION);
62   DALI_TEST_EQUALS(v.GetY(), 5u, TEST_LOCATION);
63
64   END_TEST;
65 }
66
67 int UtcDaliUint16PairMoveConstructor(void)
68 {
69   Uint16Pair u(5u, 5u);
70   Uint16Pair v = std::move(u);
71   DALI_TEST_EQUALS(v.GetX(), 5u, TEST_LOCATION);
72   DALI_TEST_EQUALS(v.GetY(), 5u, TEST_LOCATION);
73
74   END_TEST;
75 }
76
77 int UtcDaliUint16PairCopyAssignment(void)
78 {
79   Uint16Pair u(5u, 5u);
80   Uint16Pair v;
81   v = u;
82   DALI_TEST_EQUALS(v.GetX(), 5u, TEST_LOCATION);
83   DALI_TEST_EQUALS(v.GetY(), 5u, TEST_LOCATION);
84
85   END_TEST;
86 }
87
88 int UtcDaliUint16PairMoveAssignment(void)
89 {
90   Uint16Pair u(5u, 5u);
91   Uint16Pair v;
92   v = std::move(u);
93   DALI_TEST_EQUALS(v.GetX(), 5u, TEST_LOCATION);
94   DALI_TEST_EQUALS(v.GetY(), 5u, TEST_LOCATION);
95
96   END_TEST;
97 }
98
99 int UtcDaliUint16PairGetWidthP(void)
100 {
101   Uint16Pair v(5u, 5u);
102   DALI_TEST_EQUALS(v.GetWidth(), 5u, TEST_LOCATION);
103
104   END_TEST;
105 }
106
107 int UtcDaliUint16PairGetHeightP(void)
108 {
109   Uint16Pair v(5u, 5u);
110   DALI_TEST_EQUALS(v.GetHeight(), 5u, TEST_LOCATION);
111
112   END_TEST;
113 }
114
115 int UtcDaliUint16PairGetXP(void)
116 {
117   Uint16Pair v(5u, 5u);
118   DALI_TEST_EQUALS(v.GetX(), 5u, TEST_LOCATION);
119
120   END_TEST;
121 }
122
123 int UtcDaliUint16PairGetYP(void)
124 {
125   Uint16Pair v(5u, 5u);
126   DALI_TEST_EQUALS(v.GetY(), 5u, TEST_LOCATION);
127
128   END_TEST;
129 }
130
131 int UtcDaliUint16PairSetXP(void)
132 {
133   Uint16Pair v(5u, 5u);
134   DALI_TEST_EQUALS(v.GetX(), 5u, TEST_LOCATION);
135   v.SetX(10u);
136   DALI_TEST_EQUALS(v.GetX(), 10u, TEST_LOCATION);
137
138   END_TEST;
139 }
140
141 int UtcDaliUint16PairSetWidthP(void)
142 {
143   Uint16Pair v(5u, 5u);
144   DALI_TEST_EQUALS(v.GetWidth(), 5u, TEST_LOCATION);
145   v.SetWidth(10u);
146   DALI_TEST_EQUALS(v.GetWidth(), 10u, TEST_LOCATION);
147
148   END_TEST;
149 }
150
151 int UtcDaliUint16PairSetYP(void)
152 {
153   Uint16Pair v(5u, 5u);
154   DALI_TEST_EQUALS(v.GetY(), 5u, TEST_LOCATION);
155   v.SetY(10u);
156   DALI_TEST_EQUALS(v.GetY(), 10u, TEST_LOCATION);
157
158   END_TEST;
159 }
160
161 int UtcDaliUint16PairSetHeightP(void)
162 {
163   Uint16Pair v(5u, 5u);
164   DALI_TEST_EQUALS(v.GetHeight(), 5u, TEST_LOCATION);
165   v.SetHeight(10u);
166   DALI_TEST_EQUALS(v.GetHeight(), 10u, TEST_LOCATION);
167
168   END_TEST;
169 }
170
171 int UtcDaliUint16PairEqualsP(void)
172 {
173   Uint16Pair v(5u, 5u);
174   Uint16Pair u(5u, 5u);
175   DALI_TEST_EQUALS(v == u, true, TEST_LOCATION);
176
177   v = Uint16Pair(5u, 4u);
178   u = Uint16Pair(5u, 5u);
179   DALI_TEST_EQUALS(v == u, false, TEST_LOCATION);
180
181   END_TEST;
182 }
183
184 int UtcDaliUint16PairNotEqualsP(void)
185 {
186   Uint16Pair v(5u, 5u);
187   Uint16Pair u(5u, 5u);
188   DALI_TEST_EQUALS(v != u, false, TEST_LOCATION);
189
190   v = Uint16Pair(5u, 4u);
191   u = Uint16Pair(5u, 5u);
192   DALI_TEST_EQUALS(v != u, true, TEST_LOCATION);
193
194   END_TEST;
195 }
196
197 int UtcDaliUint16PairLessThanP(void)
198 {
199   Uint16Pair u(5u, 5u);
200   Uint16Pair v(6u, 6u);
201   DALI_TEST_EQUALS(u < v, true, TEST_LOCATION);
202
203   u = Uint16Pair(0u, 1u);
204   v = Uint16Pair(1u, 0u);
205   DALI_TEST_EQUALS(v < u, true, TEST_LOCATION);
206
207   u = Uint16Pair(1u, 0u);
208   v = Uint16Pair(0u, 1u);
209   DALI_TEST_EQUALS(v < u, false, TEST_LOCATION);
210
211   END_TEST;
212 }
213
214 int UtcDaliUint16PairGreaterThanP(void)
215 {
216   Uint16Pair u;
217   Uint16Pair v;
218
219   u = Uint16Pair(0u, 1u);
220   v = Uint16Pair(1u, 0u);
221   DALI_TEST_EQUALS(u > v, true, TEST_LOCATION);
222
223   u = Uint16Pair(1u, 0u);
224   v = Uint16Pair(0u, 1u);
225   DALI_TEST_EQUALS(v > u, true, TEST_LOCATION);
226
227   END_TEST;
228 }
229
230 int UtcDaliUint16PairFromFloatVecP(void)
231 {
232   Dali::Vector2 v2(5.f, 5.f);
233
234   Uint16Pair u = Uint16Pair::FromFloatVec2(v2);
235   DALI_TEST_EQUALS(u.GetX(), 5u, TEST_LOCATION);
236   DALI_TEST_EQUALS(u.GetY(), 5u, TEST_LOCATION);
237
238   Dali::Vector3 v3(5.f, 5.f, 5.f);
239
240   u = Uint16Pair::FromFloatVec2(v3);
241   DALI_TEST_EQUALS(u.GetX(), 5u, TEST_LOCATION);
242   DALI_TEST_EQUALS(u.GetY(), 5u, TEST_LOCATION);
243
244   END_TEST;
245 }
246
247 int UtcDaliUint16PairFromFloatArrayP(void)
248 {
249   float array[] = {5.f, 5.f};
250
251   Uint16Pair u = Uint16Pair::FromFloatArray(array);
252   DALI_TEST_EQUALS(u.GetX(), 5u, TEST_LOCATION);
253   DALI_TEST_EQUALS(u.GetY(), 5u, TEST_LOCATION);
254
255   END_TEST;
256 }
257
258 // class Int32Pair
259
260 int UtcDaliInt32PairConstructor01P(void)
261 {
262   Int32Pair v;
263
264   DALI_TEST_EQUALS(v.GetX(), 0, TEST_LOCATION);
265   DALI_TEST_EQUALS(v.GetY(), 0, TEST_LOCATION);
266
267   END_TEST;
268 }
269
270 int UtcDaliInt32PairConstructor02P(void)
271 {
272   Int32Pair v(-10, 20);
273
274   DALI_TEST_EQUALS(v.GetX(), -10, TEST_LOCATION);
275   DALI_TEST_EQUALS(v.GetY(), 20, TEST_LOCATION);
276
277   END_TEST;
278 }
279
280 int UtcDaliInt32PairCopyConstructor(void)
281 {
282   Int32Pair u(-5, -10);
283   Int32Pair v(u);
284   DALI_TEST_EQUALS(v.GetX(), -5, TEST_LOCATION);
285   DALI_TEST_EQUALS(v.GetY(), -10, TEST_LOCATION);
286
287   END_TEST;
288 }
289
290 int UtcDaliInt32PairMoveConstructor(void)
291 {
292   Int32Pair u(5, -10);
293   Int32Pair v = std::move(u);
294   DALI_TEST_EQUALS(v.GetX(), 5, TEST_LOCATION);
295   DALI_TEST_EQUALS(v.GetY(), -10, TEST_LOCATION);
296
297   END_TEST;
298 }
299
300 int UtcDaliInt32PairCopyAssignment(void)
301 {
302   Int32Pair u(5, 10);
303   Int32Pair v;
304   v = u;
305   DALI_TEST_EQUALS(v.GetX(), 5, TEST_LOCATION);
306   DALI_TEST_EQUALS(v.GetY(), 10, TEST_LOCATION);
307
308   END_TEST;
309 }
310
311 int UtcDaliInt32PairMoveAssignment(void)
312 {
313   Int32Pair u(5, 10);
314   Int32Pair v;
315   v = std::move(u);
316   DALI_TEST_EQUALS(v.GetX(), 5, TEST_LOCATION);
317   DALI_TEST_EQUALS(v.GetY(), 10, TEST_LOCATION);
318
319   END_TEST;
320 }
321
322 int UtcDaliInt32PairGetXP(void)
323 {
324   Int32Pair v(5, 10);
325   DALI_TEST_EQUALS(v.GetX(), 5, TEST_LOCATION);
326   DALI_TEST_EQUALS(v.GetWidth(), 5, TEST_LOCATION);
327
328   END_TEST;
329 }
330
331 int UtcDaliInt32PairGetYP(void)
332 {
333   Int32Pair v(5, 10);
334   DALI_TEST_EQUALS(v.GetY(), 10, TEST_LOCATION);
335   DALI_TEST_EQUALS(v.GetHeight(), 10, TEST_LOCATION);
336
337   END_TEST;
338 }
339
340 int UtcDaliInt32PairSetXP(void)
341 {
342   Int32Pair v(5, 10);
343   DALI_TEST_EQUALS(v.GetX(), 5, TEST_LOCATION);
344   v.SetX(10);
345   DALI_TEST_EQUALS(v.GetX(), 10, TEST_LOCATION);
346   v.SetWidth(65539);
347   DALI_TEST_EQUALS(v.GetWidth(), 65539, TEST_LOCATION);
348
349   END_TEST;
350 }
351
352 int UtcDaliInt32PairSetYP(void)
353 {
354   Int32Pair v(5, 10);
355   DALI_TEST_EQUALS(v.GetY(), 10, TEST_LOCATION);
356   v.SetY(-5);
357   DALI_TEST_EQUALS(v.GetY(), -5, TEST_LOCATION);
358   v.SetHeight(65537);
359   DALI_TEST_EQUALS(v.GetHeight(), 65537, TEST_LOCATION);
360
361   END_TEST;
362 }
363
364 int UtcDaliInt32PairEqualsP(void)
365 {
366   Int32Pair v(5, 5);
367   Int32Pair u(5, 5);
368   DALI_TEST_EQUALS(v == u, true, TEST_LOCATION);
369
370   v = Int32Pair(5, 4);
371   u = Int32Pair(5, 5);
372   DALI_TEST_EQUALS(v == u, false, TEST_LOCATION);
373
374   END_TEST;
375 }
376
377 int UtcDaliInt32PairNotEqualsP(void)
378 {
379   Int32Pair v(5, 5);
380   Int32Pair u(5, 5);
381   DALI_TEST_EQUALS(v != u, false, TEST_LOCATION);
382
383   v = Int32Pair(5, 4);
384   u = Int32Pair(5, 5);
385   DALI_TEST_EQUALS(v != u, true, TEST_LOCATION);
386
387   END_TEST;
388 }