2 * Copyright (c) 2021 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 #include <dali-test-suite-utils.h>
19 #include <dali/devel-api/common/circular-queue.h>
20 #include <dali/public-api/dali-core.h>
27 void utc_dali_circular_queue_startup(void)
29 test_return_value = TET_UNDEF;
32 void utc_dali_circular_queue_cleanup(void)
34 test_return_value = TET_PASS;
37 int UtcDaliCircularQueueNew(void)
39 CircularQueue<int> cQ = CircularQueue<int>(20);
41 DALI_TEST_EQUALS(cQ.Count(), 0, TEST_LOCATION);
42 DALI_TEST_EQUALS(cQ.IsEmpty(), true, TEST_LOCATION);
43 DALI_TEST_EQUALS(cQ.IsFull(), false, TEST_LOCATION);
48 int UtcDaliCircularQueuePushBack01(void)
50 CircularQueue<int> cQ = CircularQueue<int>(20);
53 DALI_TEST_EQUALS(cQ.Count(), 1, TEST_LOCATION);
54 DALI_TEST_EQUALS(cQ.IsEmpty(), false, TEST_LOCATION);
55 DALI_TEST_EQUALS(cQ.IsFull(), false, TEST_LOCATION);
57 DALI_TEST_EQUALS(cQ[0], 1, TEST_LOCATION);
60 DALI_TEST_EQUALS(cQ.Count(), 2, TEST_LOCATION);
61 DALI_TEST_EQUALS(cQ.IsEmpty(), false, TEST_LOCATION);
62 DALI_TEST_EQUALS(cQ.IsFull(), false, TEST_LOCATION);
64 DALI_TEST_EQUALS(cQ[0], 1, TEST_LOCATION);
65 DALI_TEST_EQUALS(cQ[1], 2, TEST_LOCATION);
70 int UtcDaliCircularQueuePushBack02(void)
72 CircularQueue<int> cQ = CircularQueue<int>(20);
73 for(int i = 0; i < 20; ++i)
76 DALI_TEST_EQUALS(cQ.Count(), i + 1, TEST_LOCATION);
77 DALI_TEST_EQUALS(cQ.IsEmpty(), false, TEST_LOCATION);
78 DALI_TEST_EQUALS(cQ.IsFull(), i < 19 ? false : true, TEST_LOCATION);
84 int UtcDaliCircularQueuePushBack03(void)
86 CircularQueue<int> cQ = CircularQueue<int>(20);
87 for(int i = 0; i < 19; ++i)
92 DALI_TEST_EQUALS(cQ.IsFull(), true, TEST_LOCATION);
94 for(int i = 0; i < 10; ++i)
96 tet_infoline("Test that the end marker wraps around");
99 DALI_TEST_EQUALS(cQ.IsFull(), true, TEST_LOCATION);
100 DALI_TEST_EQUALS(cQ[0], 1 + i, TEST_LOCATION);
101 DALI_TEST_EQUALS(cQ[19], 20 + i, TEST_LOCATION);
107 int UtcDaliCircularQueuePushBack04(void)
109 CircularQueue<int> cQ = CircularQueue<int>(20);
110 for(int i = 0; i < 10; ++i)
113 int v = cQ.PopFront();
114 DALI_TEST_EQUALS(v, i, TEST_LOCATION);
115 DALI_TEST_EQUALS(cQ.Count(), 0, TEST_LOCATION);
117 DALI_TEST_EQUALS(cQ.IsEmpty(), true, TEST_LOCATION);
122 DALI_TEST_EQUALS(cQ[0], 10, TEST_LOCATION);
123 DALI_TEST_EQUALS(cQ.Count(), 1, TEST_LOCATION);
125 DALI_TEST_EQUALS(cQ.Count(), 0, TEST_LOCATION);
126 DALI_TEST_EQUALS(cQ.IsEmpty(), true, TEST_LOCATION);
128 // Queue is empty, markers should be in middle
130 for(int i = 0; i < 20; ++i)
133 int v = cQ.PopFront();
134 DALI_TEST_EQUALS(v, i, TEST_LOCATION);
135 DALI_TEST_EQUALS(cQ.Count(), 0, TEST_LOCATION);
141 int UtcDaliCircularQueuePushBackN(void)
143 CircularQueue<int> cQ = CircularQueue<int>(20);
144 for(int i = 0; i < 20; ++i)
147 DALI_TEST_EQUALS(cQ.Count(), i + 1, TEST_LOCATION);
148 DALI_TEST_EQUALS(cQ.IsEmpty(), false, TEST_LOCATION);
149 DALI_TEST_EQUALS(cQ.IsFull(), i < 19 ? false : true, TEST_LOCATION);
155 DALI_TEST_EQUALS(0, 1, TEST_LOCATION); // Failure
157 catch(DaliException e)
159 DALI_TEST_EQUALS(1, 1, TEST_LOCATION);
165 int UtcDaliCircularQueueOperatorIndex01(void)
167 CircularQueue<int> cQ = CircularQueue<int>(20);
168 for(int i = 0; i < 20; ++i)
171 DALI_TEST_EQUALS(cQ.Count(), 1 + i, TEST_LOCATION);
172 DALI_TEST_EQUALS(cQ.IsEmpty(), false, TEST_LOCATION);
173 DALI_TEST_EQUALS(cQ.IsFull(), i < 19 ? false : true, TEST_LOCATION);
176 for(int i = 0; i < 20; ++i)
178 DALI_TEST_EQUALS(cQ[i], i, TEST_LOCATION);
184 int UtcDaliCircularQueueOperatorIndexN01(void)
186 CircularQueue<int> cQ = CircularQueue<int>(20);
191 DALI_TEST_EQUALS(v, 1, TEST_LOCATION);
193 catch(DaliException e)
195 DALI_TEST_CHECK(true);
201 int UtcDaliCircularQueuePopFront01(void)
203 CircularQueue<int> cQ = CircularQueue<int>(20);
204 for(int i = 0; i < 20; ++i)
207 DALI_TEST_EQUALS(cQ.Count(), 1 + i, TEST_LOCATION);
208 DALI_TEST_EQUALS(cQ.IsEmpty(), false, TEST_LOCATION);
209 DALI_TEST_EQUALS(cQ.IsFull(), i < 19 ? false : true, TEST_LOCATION);
212 for(int i = 0; i < 20; ++i)
214 int v = cQ.PopFront();
215 DALI_TEST_EQUALS(cQ.Count(), 19 - i, TEST_LOCATION);
216 DALI_TEST_EQUALS(v, i, TEST_LOCATION);
217 DALI_TEST_EQUALS(cQ.IsEmpty(), i < 19 ? false : true, TEST_LOCATION);
222 int UtcDaliCircularQueuePopFront02(void)
224 CircularQueue<int> cQ = CircularQueue<int>(20);
225 for(int i = 0; i < 10; ++i)
228 DALI_TEST_EQUALS(cQ[i], i, TEST_LOCATION);
229 DALI_TEST_EQUALS(cQ.Count(), i + 1, TEST_LOCATION);
232 for(int i = 0; i < 10; ++i)
234 DALI_TEST_EQUALS(cQ.PopFront(), i, TEST_LOCATION);
236 DALI_TEST_EQUALS(cQ.Count(), 0, TEST_LOCATION);
241 int UtcDaliCircularQueuePopFrontN01(void)
243 tet_infoline("Try popping from an empty queue");
244 CircularQueue<int> cQ = CircularQueue<int>(20);
249 DALI_TEST_CHECK(false);
251 catch(DaliException e)
253 DALI_TEST_CHECK(true);
259 int UtcDaliCircularQueuePopFrontN02(void)
261 tet_infoline("Try popping from an empty queue");
263 CircularQueue<int> cQ = CircularQueue<int>(20);
265 for(int i = 0; i < 10; ++i)
270 DALI_TEST_EQUALS(cQ.IsEmpty(), true, TEST_LOCATION);
275 DALI_TEST_CHECK(false);
277 catch(DaliException e)
279 DALI_TEST_CHECK(true);
285 int UtcDaliCircularQueueCount(void)
287 CircularQueue<int> cQ = CircularQueue<int>(20);
288 DALI_TEST_EQUALS(cQ.Count(), 0, TEST_LOCATION);
290 for(int i = 0; i < 20; ++i)
293 DALI_TEST_EQUALS(cQ.Count(), 1 + i, TEST_LOCATION);
299 int UtcDaliCircularQueueIsEmpty(void)
301 CircularQueue<int> cQ = CircularQueue<int>(20);
302 DALI_TEST_EQUALS(cQ.IsEmpty(), true, TEST_LOCATION);
304 for(int i = 0; i < 20; ++i)
307 DALI_TEST_EQUALS(cQ.IsEmpty(), false, TEST_LOCATION);
310 // Pop off 19 elements
311 for(int i = 0; i < 19; ++i)
314 DALI_TEST_EQUALS(cQ.IsEmpty(), false, TEST_LOCATION);
316 // pop off last element
318 DALI_TEST_EQUALS(cQ.IsEmpty(), true, TEST_LOCATION);
320 tet_infoline("Add half into queue, then remove");
322 for(int i = 0; i < 10; ++i)
325 DALI_TEST_EQUALS(cQ.IsEmpty(), false, TEST_LOCATION);
327 for(int i = 0; i < 9; ++i)
330 DALI_TEST_EQUALS(cQ.IsEmpty(), false, TEST_LOCATION);
333 DALI_TEST_EQUALS(cQ.IsEmpty(), true, TEST_LOCATION);
335 tet_infoline("Markers should now be in the middle of the data structure. Try adding 20 again");
336 for(int i = 0; i < 20; ++i)
339 DALI_TEST_EQUALS(cQ.IsEmpty(), false, TEST_LOCATION);
342 for(int i = 0; i < 19; ++i)
345 DALI_TEST_EQUALS(cQ.IsEmpty(), false, TEST_LOCATION);
348 DALI_TEST_EQUALS(cQ.IsEmpty(), true, TEST_LOCATION);
352 int UtcDaliCircularQueueIsFull(void)
354 CircularQueue<int> cQ = CircularQueue<int>(20);
355 DALI_TEST_EQUALS(cQ.IsFull(), false, TEST_LOCATION);
357 for(int i = 0; i < 20; ++i)
360 DALI_TEST_EQUALS(cQ.IsFull(), i < 19 ? false : true, TEST_LOCATION);
362 DALI_TEST_EQUALS(cQ.IsFull(), true, TEST_LOCATION);
364 for(int i = 0; i < 20; ++i)
367 DALI_TEST_EQUALS(cQ.IsFull(), false, TEST_LOCATION);
370 tet_infoline("Add half into queue, then remove");
372 for(int i = 0; i < 10; ++i)
375 DALI_TEST_EQUALS(cQ.IsFull(), false, TEST_LOCATION);
377 for(int i = 0; i < 10; ++i)
380 DALI_TEST_EQUALS(cQ.IsFull(), false, TEST_LOCATION);
383 tet_infoline("Markers should now be in the middle of the data structure. Try adding 20 again");
384 for(int i = 0; i < 20; ++i)
387 DALI_TEST_EQUALS(cQ.IsFull(), i < 19 ? false : true, TEST_LOCATION);
390 for(int i = 0; i < 20; ++i)
393 DALI_TEST_EQUALS(cQ.IsFull(), false, TEST_LOCATION);
399 int UtcDaliCircularQueueFront(void)
401 CircularQueue<int> cQ = CircularQueue<int>(20);
403 for(int i = 0; i < 20; ++i)
406 DALI_TEST_EQUALS(cQ.Front(), 0, TEST_LOCATION);
409 for(int i = 0; i < 19; ++i)
412 DALI_TEST_EQUALS(cQ.Front(), i + 1, TEST_LOCATION);
417 int UtcDaliCircularQueueBack(void)
419 CircularQueue<int> cQ = CircularQueue<int>(20);
421 for(int i = 0; i < 20; ++i)
424 DALI_TEST_EQUALS(cQ.Back(), i, TEST_LOCATION);
427 for(int i = 0; i < 19; ++i)
430 DALI_TEST_EQUALS(cQ.Back(), 19, TEST_LOCATION);
435 int UtcDaliCircularQueueSize1(void)
437 CircularQueue<int> cQ = CircularQueue<int>(1);
439 DALI_TEST_EQUALS(cQ.IsEmpty(), true, TEST_LOCATION);
440 DALI_TEST_EQUALS(cQ.IsFull(), false, TEST_LOCATION);
443 DALI_TEST_EQUALS(cQ.IsEmpty(), false, TEST_LOCATION);
444 DALI_TEST_EQUALS(cQ.IsFull(), true, TEST_LOCATION);
445 DALI_TEST_EQUALS(cQ.Front(), 5, TEST_LOCATION);
446 DALI_TEST_EQUALS(cQ.Back(), 5, TEST_LOCATION);
448 DALI_TEST_EQUALS(cQ.PopFront(), 5, TEST_LOCATION);
449 DALI_TEST_EQUALS(cQ.IsEmpty(), true, TEST_LOCATION);
450 DALI_TEST_EQUALS(cQ.IsFull(), false, TEST_LOCATION);
462 // [O] [O] [O] [O] [O] [ ] => [O] [O] [O] [O] [O] [O]
465 // [ ] [O] [O] [O] [O] [O] => [O] [O] [O] [O] [O] [O]
468 // [ ] [ ] [O] [ ] [ ] [ ] => [ ] [ ] [O] [O] [ ] [ ]
471 // [ ] [ ] [ ] [ ] [ ] [O] => [O] [ ] [ ] [ ] [ ] [O]
474 // [ ] [ ] [ ] [ ] [ ] [ ] => [ ] [ ] [O] [ ] [ ] [ ]
477 // [ ] [ ] [ ] [ ] [ ] [ ] => [ ] [ ] [ ] [ ] [ ] [0]
480 // [O] [O] [O] [O] [O] [O] => [ ] [O] [O] [O] [O] [O]
483 // [O] [O] [O] [O] [O] [O] => [O] [O] [O] [O] [ ] [O]
486 // [O] [O] [O] [O] [O] [O] => [O] [O] [O] [O] [O] [ ]
489 // [ ] [ ] [O] [O] [ ] [ ] => [ ] [ ] [ ] [O] [ ] [ ]
492 // [ ] [ ] [ ] [O] [ ] [ ] => [ ] [ ] [ ] [ ] [ ] [ ]