2 * Copyright (c) 2022 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 #define ENABLE_VECTOR_ASSERTS
20 #include <dali-test-suite-utils.h>
21 #include <dali/devel-api/common/circular-queue.h>
22 #include <dali/public-api/dali-core.h>
29 void utc_dali_circular_queue_startup(void)
31 test_return_value = TET_UNDEF;
34 void utc_dali_circular_queue_cleanup(void)
36 test_return_value = TET_PASS;
39 int UtcDaliCircularQueueNew(void)
41 CircularQueue<int> cQ = CircularQueue<int>(20);
43 DALI_TEST_EQUALS(cQ.Count(), 0, TEST_LOCATION);
44 DALI_TEST_EQUALS(cQ.IsEmpty(), true, TEST_LOCATION);
45 DALI_TEST_EQUALS(cQ.IsFull(), false, TEST_LOCATION);
50 int UtcDaliCircularQueuePushBack01(void)
52 CircularQueue<int> cQ = CircularQueue<int>(20);
55 DALI_TEST_EQUALS(cQ.Count(), 1, TEST_LOCATION);
56 DALI_TEST_EQUALS(cQ.IsEmpty(), false, TEST_LOCATION);
57 DALI_TEST_EQUALS(cQ.IsFull(), false, TEST_LOCATION);
59 DALI_TEST_EQUALS(cQ[0], 1, TEST_LOCATION);
62 DALI_TEST_EQUALS(cQ.Count(), 2, TEST_LOCATION);
63 DALI_TEST_EQUALS(cQ.IsEmpty(), false, TEST_LOCATION);
64 DALI_TEST_EQUALS(cQ.IsFull(), false, TEST_LOCATION);
66 DALI_TEST_EQUALS(cQ[0], 1, TEST_LOCATION);
67 DALI_TEST_EQUALS(cQ[1], 2, TEST_LOCATION);
72 int UtcDaliCircularQueuePushBack02(void)
74 CircularQueue<int> cQ = CircularQueue<int>(20);
75 for(int i = 0; i < 20; ++i)
78 DALI_TEST_EQUALS(cQ.Count(), i + 1, TEST_LOCATION);
79 DALI_TEST_EQUALS(cQ.IsEmpty(), false, TEST_LOCATION);
80 DALI_TEST_EQUALS(cQ.IsFull(), i < 19 ? false : true, TEST_LOCATION);
86 int UtcDaliCircularQueuePushBack03(void)
88 CircularQueue<int> cQ = CircularQueue<int>(20);
89 for(int i = 0; i < 19; ++i)
94 DALI_TEST_EQUALS(cQ.IsFull(), true, TEST_LOCATION);
96 for(int i = 0; i < 10; ++i)
98 tet_infoline("Test that the end marker wraps around");
101 DALI_TEST_EQUALS(cQ.IsFull(), true, TEST_LOCATION);
102 DALI_TEST_EQUALS(cQ[0], 1 + i, TEST_LOCATION);
103 DALI_TEST_EQUALS(cQ[19], 20 + i, TEST_LOCATION);
109 int UtcDaliCircularQueuePushBack04(void)
111 CircularQueue<int> cQ = CircularQueue<int>(20);
112 for(int i = 0; i < 10; ++i)
115 int v = cQ.PopFront();
116 DALI_TEST_EQUALS(v, i, TEST_LOCATION);
117 DALI_TEST_EQUALS(cQ.Count(), 0, TEST_LOCATION);
119 DALI_TEST_EQUALS(cQ.IsEmpty(), true, TEST_LOCATION);
124 DALI_TEST_EQUALS(cQ[0], 10, TEST_LOCATION);
125 DALI_TEST_EQUALS(cQ.Count(), 1, TEST_LOCATION);
127 DALI_TEST_EQUALS(cQ.Count(), 0, TEST_LOCATION);
128 DALI_TEST_EQUALS(cQ.IsEmpty(), true, TEST_LOCATION);
130 // Queue is empty, markers should be in middle
132 for(int i = 0; i < 20; ++i)
135 int v = cQ.PopFront();
136 DALI_TEST_EQUALS(v, i, TEST_LOCATION);
137 DALI_TEST_EQUALS(cQ.Count(), 0, TEST_LOCATION);
143 int UtcDaliCircularQueuePushBackN(void)
145 CircularQueue<int> cQ = CircularQueue<int>(20);
146 for(int i = 0; i < 20; ++i)
149 DALI_TEST_EQUALS(cQ.Count(), i + 1, TEST_LOCATION);
150 DALI_TEST_EQUALS(cQ.IsEmpty(), false, TEST_LOCATION);
151 DALI_TEST_EQUALS(cQ.IsFull(), i < 19 ? false : true, TEST_LOCATION);
157 DALI_TEST_EQUALS(0, 1, TEST_LOCATION); // Failure
159 catch(DaliException e)
161 DALI_TEST_EQUALS(1, 1, TEST_LOCATION);
167 int UtcDaliCircularQueueOperatorIndex01(void)
169 CircularQueue<int> cQ = CircularQueue<int>(20);
170 for(int i = 0; i < 20; ++i)
173 DALI_TEST_EQUALS(cQ.Count(), 1 + i, TEST_LOCATION);
174 DALI_TEST_EQUALS(cQ.IsEmpty(), false, TEST_LOCATION);
175 DALI_TEST_EQUALS(cQ.IsFull(), i < 19 ? false : true, TEST_LOCATION);
178 for(int i = 0; i < 20; ++i)
180 DALI_TEST_EQUALS(cQ[i], i, TEST_LOCATION);
186 int UtcDaliCircularQueueOperatorIndexN01(void)
188 CircularQueue<int> cQ = CircularQueue<int>(20);
193 DALI_TEST_EQUALS(v, 1, TEST_LOCATION);
195 catch(DaliException e)
197 DALI_TEST_CHECK(true);
203 int UtcDaliCircularQueuePopFront01(void)
205 CircularQueue<int> cQ = CircularQueue<int>(20);
206 for(int i = 0; i < 20; ++i)
209 DALI_TEST_EQUALS(cQ.Count(), 1 + i, TEST_LOCATION);
210 DALI_TEST_EQUALS(cQ.IsEmpty(), false, TEST_LOCATION);
211 DALI_TEST_EQUALS(cQ.IsFull(), i < 19 ? false : true, TEST_LOCATION);
214 for(int i = 0; i < 20; ++i)
216 int v = cQ.PopFront();
217 DALI_TEST_EQUALS(cQ.Count(), 19 - i, TEST_LOCATION);
218 DALI_TEST_EQUALS(v, i, TEST_LOCATION);
219 DALI_TEST_EQUALS(cQ.IsEmpty(), i < 19 ? false : true, TEST_LOCATION);
224 int UtcDaliCircularQueuePopFront02(void)
226 CircularQueue<int> cQ = CircularQueue<int>(20);
227 for(int i = 0; i < 10; ++i)
230 DALI_TEST_EQUALS(cQ[i], i, TEST_LOCATION);
231 DALI_TEST_EQUALS(cQ.Count(), i + 1, TEST_LOCATION);
234 for(int i = 0; i < 10; ++i)
236 DALI_TEST_EQUALS(cQ.PopFront(), i, TEST_LOCATION);
238 DALI_TEST_EQUALS(cQ.Count(), 0, TEST_LOCATION);
243 int UtcDaliCircularQueuePopFrontN01(void)
245 tet_infoline("Try popping from an empty queue");
246 CircularQueue<int> cQ = CircularQueue<int>(20);
251 DALI_TEST_CHECK(false);
253 catch(DaliException e)
255 DALI_TEST_CHECK(true);
261 int UtcDaliCircularQueuePopFrontN02(void)
263 tet_infoline("Try popping from an empty queue");
265 CircularQueue<int> cQ = CircularQueue<int>(20);
267 for(int i = 0; i < 10; ++i)
272 DALI_TEST_EQUALS(cQ.IsEmpty(), true, TEST_LOCATION);
277 DALI_TEST_CHECK(false);
279 catch(DaliException e)
281 DALI_TEST_CHECK(true);
287 int UtcDaliCircularQueueCount(void)
289 CircularQueue<int> cQ = CircularQueue<int>(20);
290 DALI_TEST_EQUALS(cQ.Count(), 0, TEST_LOCATION);
292 for(int i = 0; i < 20; ++i)
295 DALI_TEST_EQUALS(cQ.Count(), 1 + i, TEST_LOCATION);
301 int UtcDaliCircularQueueIsEmpty(void)
303 CircularQueue<int> cQ = CircularQueue<int>(20);
304 DALI_TEST_EQUALS(cQ.IsEmpty(), true, TEST_LOCATION);
306 for(int i = 0; i < 20; ++i)
309 DALI_TEST_EQUALS(cQ.IsEmpty(), false, TEST_LOCATION);
312 // Pop off 19 elements
313 for(int i = 0; i < 19; ++i)
316 DALI_TEST_EQUALS(cQ.IsEmpty(), false, TEST_LOCATION);
318 // pop off last element
320 DALI_TEST_EQUALS(cQ.IsEmpty(), true, TEST_LOCATION);
322 tet_infoline("Add half into queue, then remove");
324 for(int i = 0; i < 10; ++i)
327 DALI_TEST_EQUALS(cQ.IsEmpty(), false, TEST_LOCATION);
329 for(int i = 0; i < 9; ++i)
332 DALI_TEST_EQUALS(cQ.IsEmpty(), false, TEST_LOCATION);
335 DALI_TEST_EQUALS(cQ.IsEmpty(), true, TEST_LOCATION);
337 tet_infoline("Markers should now be in the middle of the data structure. Try adding 20 again");
338 for(int i = 0; i < 20; ++i)
341 DALI_TEST_EQUALS(cQ.IsEmpty(), false, TEST_LOCATION);
344 for(int i = 0; i < 19; ++i)
347 DALI_TEST_EQUALS(cQ.IsEmpty(), false, TEST_LOCATION);
350 DALI_TEST_EQUALS(cQ.IsEmpty(), true, TEST_LOCATION);
354 int UtcDaliCircularQueueIsFull(void)
356 CircularQueue<int> cQ = CircularQueue<int>(20);
357 DALI_TEST_EQUALS(cQ.IsFull(), false, TEST_LOCATION);
359 for(int i = 0; i < 20; ++i)
362 DALI_TEST_EQUALS(cQ.IsFull(), i < 19 ? false : true, TEST_LOCATION);
364 DALI_TEST_EQUALS(cQ.IsFull(), true, TEST_LOCATION);
366 for(int i = 0; i < 20; ++i)
369 DALI_TEST_EQUALS(cQ.IsFull(), false, TEST_LOCATION);
372 tet_infoline("Add half into queue, then remove");
374 for(int i = 0; i < 10; ++i)
377 DALI_TEST_EQUALS(cQ.IsFull(), false, TEST_LOCATION);
379 for(int i = 0; i < 10; ++i)
382 DALI_TEST_EQUALS(cQ.IsFull(), false, TEST_LOCATION);
385 tet_infoline("Markers should now be in the middle of the data structure. Try adding 20 again");
386 for(int i = 0; i < 20; ++i)
389 DALI_TEST_EQUALS(cQ.IsFull(), i < 19 ? false : true, TEST_LOCATION);
392 for(int i = 0; i < 20; ++i)
395 DALI_TEST_EQUALS(cQ.IsFull(), false, TEST_LOCATION);
401 int UtcDaliCircularQueueFront(void)
403 CircularQueue<int> cQ = CircularQueue<int>(20);
405 for(int i = 0; i < 20; ++i)
408 DALI_TEST_EQUALS(cQ.Front(), 0, TEST_LOCATION);
411 for(int i = 0; i < 19; ++i)
414 DALI_TEST_EQUALS(cQ.Front(), i + 1, TEST_LOCATION);
419 int UtcDaliCircularQueueBack(void)
421 CircularQueue<int> cQ = CircularQueue<int>(20);
423 for(int i = 0; i < 20; ++i)
426 DALI_TEST_EQUALS(cQ.Back(), i, TEST_LOCATION);
429 for(int i = 0; i < 19; ++i)
432 DALI_TEST_EQUALS(cQ.Back(), 19, TEST_LOCATION);
437 int UtcDaliCircularQueueSize1(void)
439 CircularQueue<int> cQ = CircularQueue<int>(1);
441 DALI_TEST_EQUALS(cQ.IsEmpty(), true, TEST_LOCATION);
442 DALI_TEST_EQUALS(cQ.IsFull(), false, TEST_LOCATION);
445 DALI_TEST_EQUALS(cQ.IsEmpty(), false, TEST_LOCATION);
446 DALI_TEST_EQUALS(cQ.IsFull(), true, TEST_LOCATION);
447 DALI_TEST_EQUALS(cQ.Front(), 5, TEST_LOCATION);
448 DALI_TEST_EQUALS(cQ.Back(), 5, TEST_LOCATION);
450 DALI_TEST_EQUALS(cQ.PopFront(), 5, TEST_LOCATION);
451 DALI_TEST_EQUALS(cQ.IsEmpty(), true, TEST_LOCATION);
452 DALI_TEST_EQUALS(cQ.IsFull(), false, TEST_LOCATION);
464 // [O] [O] [O] [O] [O] [ ] => [O] [O] [O] [O] [O] [O]
467 // [ ] [O] [O] [O] [O] [O] => [O] [O] [O] [O] [O] [O]
470 // [ ] [ ] [O] [ ] [ ] [ ] => [ ] [ ] [O] [O] [ ] [ ]
473 // [ ] [ ] [ ] [ ] [ ] [O] => [O] [ ] [ ] [ ] [ ] [O]
476 // [ ] [ ] [ ] [ ] [ ] [ ] => [ ] [ ] [O] [ ] [ ] [ ]
479 // [ ] [ ] [ ] [ ] [ ] [ ] => [ ] [ ] [ ] [ ] [ ] [0]
482 // [O] [O] [O] [O] [O] [O] => [ ] [O] [O] [O] [O] [O]
485 // [O] [O] [O] [O] [O] [O] => [O] [O] [O] [O] [ ] [O]
488 // [O] [O] [O] [O] [O] [O] => [O] [O] [O] [O] [O] [ ]
491 // [ ] [ ] [O] [O] [ ] [ ] => [ ] [ ] [ ] [O] [ ] [ ]
494 // [ ] [ ] [ ] [O] [ ] [ ] => [ ] [ ] [ ] [ ] [ ] [ ]