Dali 3D User Interface Engine
utc-Dali-Rect.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2014 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 <iostream>
19 
20 #include <stdlib.h>
22 #include <dali-test-suite-utils.h>
23 
24 using namespace Dali;
25 
27 {
29 }
30 
32 {
34 }
35 
36 
37 // Positive test case for a method
39 {
40  TestApplication application;
41 
42  Rect<float> rect;
43  DALI_TEST_EQUALS(rect.x, 0.0f, 0.001, TEST_LOCATION);
44  DALI_TEST_EQUALS(rect.y, 0.0f, 0.001, TEST_LOCATION);
45  DALI_TEST_EQUALS(rect.width, 0.0f, 0.001, TEST_LOCATION);
46  DALI_TEST_EQUALS(rect.height, 0.0f, 0.001, TEST_LOCATION);
47  END_TEST;
48 }
49 
51 {
52  TestApplication application;
53 
54  Rect<float> rect(10.0f, 20.0f, 400.0f, 200.0f);
55  DALI_TEST_EQUALS(rect.x, 10.0f, 0.001, TEST_LOCATION);
56  DALI_TEST_EQUALS(rect.y, 20.0f, 0.001, TEST_LOCATION);
57  DALI_TEST_EQUALS(rect.width, 400.0f, 0.001, TEST_LOCATION);
58  DALI_TEST_EQUALS(rect.height, 200.0f, 0.001, TEST_LOCATION);
59  END_TEST;
60 }
61 
63 {
64  TestApplication application;
65 
66  Rect<float> rect(10.0f, 20.0f, 400.0f, 200.0f);
67 
68  Rect<float> r2 = rect;
69 
70  DALI_TEST_EQUALS(r2.x, 10.0f, 0.001, TEST_LOCATION);
71  DALI_TEST_EQUALS(r2.y, 20.0f, 0.001, TEST_LOCATION);
72  DALI_TEST_EQUALS(r2.width, 400.0f, 0.001, TEST_LOCATION);
73  DALI_TEST_EQUALS(r2.height, 200.0f, 0.001, TEST_LOCATION);
74  END_TEST;
75 }
76 
78 {
79  TestApplication application;
80 
81  Rect<float> rect(10.0f, 20.0f, 400.0f, 200.0f);
82 
83  Rect<float> r2(rect);
84 
85  DALI_TEST_EQUALS(r2.x, 10.0f, 0.001, TEST_LOCATION);
86  DALI_TEST_EQUALS(r2.y, 20.0f, 0.001, TEST_LOCATION);
87  DALI_TEST_EQUALS(r2.width, 400.0f, 0.001, TEST_LOCATION);
88  DALI_TEST_EQUALS(r2.height, 200.0f, 0.001, TEST_LOCATION);
89  END_TEST;
90 }
91 
92 int UtcDaliRectSet(void)
93 {
94  TestApplication application;
95 
96  Rect<float> rect(10.0f, 20.0f, 400.0f, 200.0f);
97 
98  rect.Set(1.0f, 2.0f, 3.0f, 4.0f);
99 
100  DALI_TEST_EQUALS(rect.x, 1.0f, 0.001, TEST_LOCATION);
101  DALI_TEST_EQUALS(rect.y, 2.0f, 0.001, TEST_LOCATION);
102  DALI_TEST_EQUALS(rect.width, 3.0f, 0.001, TEST_LOCATION);
103  DALI_TEST_EQUALS(rect.height, 4.0f, 0.001, TEST_LOCATION);
104  END_TEST;
105 }
106 
108 {
109  TestApplication application;
110 
111  Rect<int> ri;
112  Rect<float> rf(10.0f, 20.0f, 400.0f, 200.0f);
113  Rect<float> rf2;
114  Rect<float> rf3(10.0f, 20.0f, 0.0f, 200.0f);
115  Rect<float> rf4(10.0f, 20.0f, 400.0f, 0.0f);
116  Rect<double> rd(10.0, 20.0, 0.0, 200.0);
117  Rect<unsigned int> ru(0u, 0u, 4u, 0u);
118 
119  DALI_TEST_CHECK(!rf.IsEmpty());
120  DALI_TEST_CHECK(rf2.IsEmpty());
121  DALI_TEST_CHECK(rf3.IsEmpty());
122  DALI_TEST_CHECK(rf4.IsEmpty());
123  DALI_TEST_CHECK(ri.IsEmpty());
124  DALI_TEST_CHECK(rd.IsEmpty());
125  DALI_TEST_CHECK(ru.IsEmpty());
126  END_TEST;
127 }
128 
130 {
131  TestApplication application;
132 
133  Rect<float> rf(10.0f, 20.0f, 400.0f, 200.0f);
134 
135  DALI_TEST_EQUALS(rf.Left(), 10.0f, 0.001, TEST_LOCATION);
136  END_TEST;
137 }
138 
140 {
141  TestApplication application;
142 
143  Rect<float> rf(10.0f, 20.0f, 400.0f, 200.0f);
144 
145  DALI_TEST_EQUALS(rf.Right(), 410.0f, 0.001, TEST_LOCATION);
146  END_TEST;
147 }
148 
149 int UtcDaliRectTop(void)
150 {
151  TestApplication application;
152 
153  Rect<float> rf(10.0f, 20.0f, 400.0f, 200.0f);
154 
155  DALI_TEST_EQUALS(rf.Top(), 20.0f, 0.001, TEST_LOCATION);
156  END_TEST;
157 }
158 
160 {
161  TestApplication application;
162 
163  Rect<float> rf(10.0f, 20.0f, 400.0f, 200.0f);
164 
165  DALI_TEST_EQUALS(rf.Bottom(), 220.0f, 0.001, TEST_LOCATION);
166  END_TEST;
167 }
168 
169 
171 {
172  TestApplication application;
173 
174  Rect<float> rf(10.0f, 20.0f, 400.0f, 200.0f);
175 
176  DALI_TEST_EQUALS(rf.Area(), 80000.0f, 0.001, TEST_LOCATION);
177  END_TEST;
178 }
179 
180 
182 {
183  TestApplication application;
184 
185  Rect<float> rf1( 10.0f, 20.0f, 200.0f, 200.0f);
186  Rect<float> rf2( 10.0f, 120.0f, 200.0f, 200.0f);
187  Rect<float> rf3( 10.0f, -80.0f, 200.0f, 200.0f);
188  Rect<float> rf4(110.0f, 20.0f, 200.0f, 200.0f);
189  Rect<float> rf5(-90.0f, 20.0f, 200.0f, 200.0f);
190  Rect<float> rf6(1000.0f, 1200.0f, 10.0f, 10.0f);
191 
192  DALI_TEST_CHECK(rf1.Intersects(rf2));
193  DALI_TEST_CHECK(rf1.Intersects(rf3));
194  DALI_TEST_CHECK(rf1.Intersects(rf4));
195  DALI_TEST_CHECK(rf1.Intersects(rf5));
196  DALI_TEST_CHECK(!rf1.Intersects(rf6));
197  END_TEST;
198 }
199 
200 
201 
203 {
204  TestApplication application;
205 
206  Rect<float> rf1( 10.0f, 20.0f, 200.0f, 200.0f);
207 
208  Rect<float> rf2( 10.0f, 120.0f, 200.0f, 200.0f);
209  Rect<float> rf3( 10.0f, -80.0f, 200.0f, 200.0f);
210  Rect<float> rf4(110.0f, 20.0f, 200.0f, 200.0f);
211  Rect<float> rf5(-90.0f, 20.0f, 200.0f, 200.0f);
212  Rect<float> rf6(1000.0f, 1200.0f, 10.0f, 10.0f);
213 
214  Rect<float> rf7( 50.0f, 70.0f, 50.0f, 50.0f);
215 
216  Rect<float> rf8( 10.0f, 20.0f, 100.0f, 100.0f);
217  Rect<float> rf9( 110.0f, 20.0f, 100.0f, 100.0f);
218  Rect<float> rf10( 110.0f, 120.0f, 100.0f, 100.0f);
219  Rect<float> rf11( 10.0f, 120.0f, 100.0f, 100.0f);
220 
221  DALI_TEST_CHECK(rf1.Contains(rf1));
222  DALI_TEST_CHECK(!rf1.Contains(rf2));
223  DALI_TEST_CHECK(!rf1.Contains(rf3));
224  DALI_TEST_CHECK(!rf1.Contains(rf4));
225  DALI_TEST_CHECK(!rf1.Contains(rf5));
226  DALI_TEST_CHECK(!rf1.Contains(rf6));
227 
228  DALI_TEST_CHECK(rf1.Contains(rf7));
229 
230  DALI_TEST_CHECK(rf1.Contains(rf8));
231  DALI_TEST_CHECK(rf1.Contains(rf9));
232  DALI_TEST_CHECK(rf1.Contains(rf10));
233  DALI_TEST_CHECK(rf1.Contains(rf11));
234  END_TEST;
235 }
236 
237 
239 {
240  TestApplication application;
241 
242  Rect<float> rf1( 10.0f, 20.0f, 200.0f, 200.0f);
243  Rect<float> rf2( 10.0f, 120.0f, 200.0f, 200.0f);
244  Rect<float> rf3( 10.0f, -80.0f, 200.0f, 200.0f);
245  Rect<float> rf4(110.0f, 20.0f, 200.0f, 200.0f);
246  Rect<float> rf5(-90.0f, 20.0f, 200.0f, 200.0f);
247  Rect<float> rf6(1000.0f, 1200.0f, 10.0f, 10.0f);
248  Rect<float> rf7( 50.0f, 70.0f, 50.0f, 50.0f);
249  Rect<float> rf8( 10.0f, 20.0f, 100.0f, 100.0f);
250  Rect<float> rf9( 110.0f, 20.0f, 100.0f, 100.0f);
251  Rect<float> rf10( 110.0f, 120.0f, 100.0f, 100.0f);
252  Rect<float> rf11( 10.0f, 120.0f, 100.0f, 100.0f);
253 
254  DALI_TEST_CHECK(rf1 != rf2);
255  DALI_TEST_CHECK(rf1 != rf3);
256  DALI_TEST_CHECK(rf1 != rf4);
257  DALI_TEST_CHECK(rf1 != rf5);
258  DALI_TEST_CHECK(rf1 != rf6);
259  DALI_TEST_CHECK(rf1 != rf7);
260  DALI_TEST_CHECK(rf1 != rf8);
261  DALI_TEST_CHECK(rf1 != rf9);
262  DALI_TEST_CHECK(rf1 != rf10);
263  DALI_TEST_CHECK(rf1 != rf11);
264  END_TEST;
265 }
266 
267 
269 {
270  TestApplication application;
271 
272  Rect<float> rf1( 10.0f, 20.0f, 200.0f, 200.0f);
273  Rect<float> rf1p( 10.0f, 20.0f, 200.0f, 200.0f);
274 
275  Rect<float> rf2(110.0f, 20.0f, 200.0f, 200.0f);
276  Rect<float> rf3( 10.0f, 120.0f, 200.0f, 200.0f);
277  Rect<float> rf4( 10.0f, 20.0f, 300.0f, 200.0f);
278  Rect<float> rf5( 10.0f, 20.0f, 200.0f, 500.0f);
279 
280  Rect<float> rf6( 0.0f, 0.0f, 9.0f, 10.0f);
281 
282  DALI_TEST_CHECK(rf1 == rf1p);
283  DALI_TEST_CHECK(rf1 == rf1);
284  DALI_TEST_CHECK(!(rf1 == rf2));
285  DALI_TEST_CHECK(!(rf1 == rf3));
286  DALI_TEST_CHECK(!(rf1 == rf4));
287  DALI_TEST_CHECK(!(rf1 == rf5));
288  DALI_TEST_CHECK(!(rf1 == rf6));
289 
290 
291  // integers
292  Rect<int> ri1( 10, 20, 200, 200 );
293  Rect<int> ri1p( 10, 20, 200, 200 );
294 
295  DALI_TEST_CHECK(ri1 == ri1p);
296  END_TEST;
297 }
298 
300 {
301  TestApplication application;
302  std::ostringstream oss;
303 
304  Rect<int> rect( 1, 2, 10, 10 );
305 
306  oss << rect;
307 
308  std::string expectedOutput = "[1, 2, 10, 10]";
309 
310  DALI_TEST_EQUALS( oss.str(), expectedOutput, TEST_LOCATION);
311  END_TEST;
312 }
Dali Docs Home
Read more about Dali