2 * Copyright (c) 2017 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
22 #include <dali/public-api/dali-core.h>
23 #include <dali/devel-api/common/circular-queue.h>
24 #include <dali-test-suite-utils.h>
28 void utc_dali_circular_queue_startup(void)
30 test_return_value = TET_UNDEF;
33 void utc_dali_circular_queue_cleanup(void)
35 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 );
51 int UtcDaliCircularQueuePushBack01(void)
53 CircularQueue<int> cQ = CircularQueue<int>( 20 );
56 DALI_TEST_EQUALS( cQ.Count(), 1, TEST_LOCATION );
57 DALI_TEST_EQUALS( cQ.IsEmpty(), false, TEST_LOCATION );
58 DALI_TEST_EQUALS( cQ.IsFull(), false, TEST_LOCATION );
60 DALI_TEST_EQUALS( cQ[0], 1, TEST_LOCATION );
63 DALI_TEST_EQUALS( cQ.Count(), 2, TEST_LOCATION );
64 DALI_TEST_EQUALS( cQ.IsEmpty(), false, TEST_LOCATION );
65 DALI_TEST_EQUALS( cQ.IsFull(), false, TEST_LOCATION );
67 DALI_TEST_EQUALS( cQ[0], 1, TEST_LOCATION );
68 DALI_TEST_EQUALS( cQ[1], 2, TEST_LOCATION );
73 int UtcDaliCircularQueuePushBack02(void)
75 CircularQueue<int> cQ = CircularQueue<int>( 20 );
76 for( int i=0; i<20; ++i)
79 DALI_TEST_EQUALS( cQ.Count(), i+1, TEST_LOCATION );
80 DALI_TEST_EQUALS( cQ.IsEmpty(), false, TEST_LOCATION );
81 DALI_TEST_EQUALS( cQ.IsFull(), i<19?false:true, TEST_LOCATION );
87 int UtcDaliCircularQueuePushBack03(void)
89 CircularQueue<int> cQ = CircularQueue<int>( 20 );
90 for( int i=0; i<19; ++i)
95 DALI_TEST_EQUALS( cQ.IsFull(), true, TEST_LOCATION );
97 for( int i=0; i<10; ++i )
99 tet_infoline( "Test that the end marker wraps around");
102 DALI_TEST_EQUALS( cQ.IsFull(), true, TEST_LOCATION );
103 DALI_TEST_EQUALS( cQ[0], 1+i, TEST_LOCATION );
104 DALI_TEST_EQUALS( cQ[19], 20+i, TEST_LOCATION );
111 int UtcDaliCircularQueuePushBack04(void)
113 CircularQueue<int> cQ = CircularQueue<int>( 20 );
114 for( int i=0; i<10; ++i)
117 int v = cQ.PopFront();
118 DALI_TEST_EQUALS( v, i, TEST_LOCATION );
119 DALI_TEST_EQUALS( cQ.Count(), 0, TEST_LOCATION );
121 DALI_TEST_EQUALS( cQ.IsEmpty(), true, TEST_LOCATION );
126 DALI_TEST_EQUALS( cQ[0], 10, TEST_LOCATION );
127 DALI_TEST_EQUALS( cQ.Count(), 1, TEST_LOCATION );
129 DALI_TEST_EQUALS( cQ.Count(), 0, TEST_LOCATION );
130 DALI_TEST_EQUALS( cQ.IsEmpty(), true, TEST_LOCATION );
132 // Queue is empty, markers should be in middle
134 for( int i=0; i<20; ++i)
137 int v = cQ.PopFront();
138 DALI_TEST_EQUALS( v, i, TEST_LOCATION );
139 DALI_TEST_EQUALS( cQ.Count(), 0, TEST_LOCATION );
146 int UtcDaliCircularQueuePushBackN(void)
148 CircularQueue<int> cQ = CircularQueue<int>( 20 );
149 for( int i=0; i<20; ++i)
152 DALI_TEST_EQUALS( cQ.Count(), i+1, TEST_LOCATION );
153 DALI_TEST_EQUALS( cQ.IsEmpty(), false, TEST_LOCATION );
154 DALI_TEST_EQUALS( cQ.IsFull(), i<19?false:true, TEST_LOCATION );
160 DALI_TEST_EQUALS( 0, 1, TEST_LOCATION );// Failure
162 catch( DaliException e )
164 DALI_TEST_EQUALS( 1, 1, TEST_LOCATION );
171 int UtcDaliCircularQueueOperatorIndex01(void)
173 CircularQueue<int> cQ = CircularQueue<int>( 20 );
174 for( int i=0; i<20; ++i)
177 DALI_TEST_EQUALS( cQ.Count(), 1+i, TEST_LOCATION );
178 DALI_TEST_EQUALS( cQ.IsEmpty(), false, TEST_LOCATION );
179 DALI_TEST_EQUALS( cQ.IsFull(), i<19?false:true, TEST_LOCATION );
182 for( int i=0; i<20; ++i)
184 DALI_TEST_EQUALS( cQ[i], i, TEST_LOCATION );
190 int UtcDaliCircularQueueOperatorIndexN01(void)
192 CircularQueue<int> cQ = CircularQueue<int>( 20 );
197 DALI_TEST_EQUALS(v, 1, TEST_LOCATION);
199 catch( DaliException e )
201 DALI_TEST_CHECK(true);
208 int UtcDaliCircularQueuePopFront01(void)
210 CircularQueue<int> cQ = CircularQueue<int>( 20 );
211 for( int i=0; i<20; ++i)
214 DALI_TEST_EQUALS( cQ.Count(), 1+i, TEST_LOCATION );
215 DALI_TEST_EQUALS( cQ.IsEmpty(), false, TEST_LOCATION );
216 DALI_TEST_EQUALS( cQ.IsFull(), i<19?false:true, TEST_LOCATION );
219 for( int i=0; i<20; ++i)
221 int v = cQ.PopFront();
222 DALI_TEST_EQUALS( cQ.Count(), 19-i, TEST_LOCATION );
223 DALI_TEST_EQUALS( v, i, TEST_LOCATION );
224 DALI_TEST_EQUALS( cQ.IsEmpty(), i<19?false:true, TEST_LOCATION );
229 int UtcDaliCircularQueuePopFront02(void)
231 CircularQueue<int> cQ = CircularQueue<int>( 20 );
232 for( int i=0; i<10; ++i)
235 DALI_TEST_EQUALS( cQ[i], i, TEST_LOCATION );
236 DALI_TEST_EQUALS( cQ.Count(), i+1, TEST_LOCATION );
239 for( int i=0; i<10; ++i)
241 DALI_TEST_EQUALS( cQ.PopFront(), i, TEST_LOCATION );
243 DALI_TEST_EQUALS( cQ.Count(), 0, TEST_LOCATION );
249 int UtcDaliCircularQueuePopFrontN01(void)
251 tet_infoline("Try popping from an empty queue");
252 CircularQueue<int> cQ = CircularQueue<int>( 20 );
257 DALI_TEST_CHECK( false );
259 catch( DaliException e )
261 DALI_TEST_CHECK( true );
268 int UtcDaliCircularQueuePopFrontN02(void)
270 tet_infoline("Try popping from an empty queue");
272 CircularQueue<int> cQ = CircularQueue<int>( 20 );
274 for( int i=0; i<10; ++i)
279 DALI_TEST_EQUALS( cQ.IsEmpty(), true, TEST_LOCATION );
284 DALI_TEST_CHECK( false );
286 catch( DaliException e )
288 DALI_TEST_CHECK( true );
294 int UtcDaliCircularQueueCount(void)
296 CircularQueue<int> cQ = CircularQueue<int>( 20 );
297 DALI_TEST_EQUALS( cQ.Count(), 0, TEST_LOCATION );
299 for( int i=0; i<20; ++i)
302 DALI_TEST_EQUALS( cQ.Count(), 1+i, TEST_LOCATION );
308 int UtcDaliCircularQueueIsEmpty(void)
310 CircularQueue<int> cQ = CircularQueue<int>( 20 );
311 DALI_TEST_EQUALS( cQ.IsEmpty(), true, TEST_LOCATION );
313 for( int i=0; i<20; ++i)
316 DALI_TEST_EQUALS( cQ.IsEmpty(), false, TEST_LOCATION );
319 // Pop off 19 elements
320 for( int i=0; i<19; ++i)
322 (void) cQ.PopFront();
323 DALI_TEST_EQUALS( cQ.IsEmpty(), false, TEST_LOCATION );
325 // pop off last element
326 (void) cQ.PopFront();
327 DALI_TEST_EQUALS( cQ.IsEmpty(), true, TEST_LOCATION );
329 tet_infoline( "Add half into queue, then remove");
331 for( int i=0; i<10; ++i)
334 DALI_TEST_EQUALS( cQ.IsEmpty(), false, TEST_LOCATION );
336 for( int i=0; i<9; ++i)
338 (void) cQ.PopFront();
339 DALI_TEST_EQUALS( cQ.IsEmpty(), false, TEST_LOCATION );
341 (void) cQ.PopFront();
342 DALI_TEST_EQUALS( cQ.IsEmpty(), true, TEST_LOCATION );
344 tet_infoline("Markers should now be in the middle of the data structure. Try adding 20 again");
345 for( int i=0; i<20; ++i)
348 DALI_TEST_EQUALS( cQ.IsEmpty(), false, TEST_LOCATION );
351 for( int i=0; i<19; ++i)
353 (void) cQ.PopFront();
354 DALI_TEST_EQUALS( cQ.IsEmpty(), false, TEST_LOCATION );
356 (void) cQ.PopFront();
357 DALI_TEST_EQUALS( cQ.IsEmpty(), true, TEST_LOCATION );
362 int UtcDaliCircularQueueIsFull(void)
364 CircularQueue<int> cQ = CircularQueue<int>( 20 );
365 DALI_TEST_EQUALS( cQ.IsFull(), false, TEST_LOCATION );
367 for( int i=0; i<20; ++i)
370 DALI_TEST_EQUALS( cQ.IsFull(), i<19?false:true, TEST_LOCATION );
372 DALI_TEST_EQUALS( cQ.IsFull(), true, TEST_LOCATION );
374 for( int i=0; i<20; ++i)
376 (void) cQ.PopFront();
377 DALI_TEST_EQUALS( cQ.IsFull(), false, TEST_LOCATION );
380 tet_infoline( "Add half into queue, then remove");
382 for( int i=0; i<10; ++i)
385 DALI_TEST_EQUALS( cQ.IsFull(), false, TEST_LOCATION );
387 for( int i=0; i<10; ++i)
389 (void) cQ.PopFront();
390 DALI_TEST_EQUALS( cQ.IsFull(), false, TEST_LOCATION );
393 tet_infoline("Markers should now be in the middle of the data structure. Try adding 20 again");
394 for( int i=0; i<20; ++i)
397 DALI_TEST_EQUALS( cQ.IsFull(), i<19?false:true, TEST_LOCATION );
400 for( int i=0; i<20; ++i)
402 (void) cQ.PopFront();
403 DALI_TEST_EQUALS( cQ.IsFull(), false, TEST_LOCATION );
410 int UtcDaliCircularQueueFront(void)
412 CircularQueue<int> cQ = CircularQueue<int>( 20 );
414 for( int i=0; i<20; ++i)
417 DALI_TEST_EQUALS( cQ.Front(), 0, TEST_LOCATION );
420 for( int i=0; i<19; ++i)
422 (void) cQ.PopFront();
423 DALI_TEST_EQUALS( cQ.Front(), i+1, TEST_LOCATION );
428 int UtcDaliCircularQueueBack(void)
430 CircularQueue<int> cQ = CircularQueue<int>( 20 );
432 for( int i=0; i<20; ++i)
435 DALI_TEST_EQUALS( cQ.Back(), i, TEST_LOCATION );
438 for( int i=0; i<19; ++i)
440 (void) cQ.PopFront();
441 DALI_TEST_EQUALS( cQ.Back(), 19, TEST_LOCATION );
446 int UtcDaliCircularQueueSize1(void)
448 CircularQueue<int> cQ = CircularQueue<int>( 1 );
450 DALI_TEST_EQUALS( cQ.IsEmpty(), true, TEST_LOCATION );
451 DALI_TEST_EQUALS( cQ.IsFull(), false, TEST_LOCATION );
454 DALI_TEST_EQUALS( cQ.IsEmpty(), false, TEST_LOCATION );
455 DALI_TEST_EQUALS( cQ.IsFull(), true, TEST_LOCATION );
456 DALI_TEST_EQUALS( cQ.Front(), 5, TEST_LOCATION );
457 DALI_TEST_EQUALS( cQ.Back(), 5, TEST_LOCATION );
459 DALI_TEST_EQUALS( cQ.PopFront(), 5, TEST_LOCATION );
460 DALI_TEST_EQUALS( cQ.IsEmpty(), true, TEST_LOCATION );
461 DALI_TEST_EQUALS( cQ.IsFull(), false, TEST_LOCATION );
474 // [O] [O] [O] [O] [O] [ ] => [O] [O] [O] [O] [O] [O]
477 // [ ] [O] [O] [O] [O] [O] => [O] [O] [O] [O] [O] [O]
480 // [ ] [ ] [O] [ ] [ ] [ ] => [ ] [ ] [O] [O] [ ] [ ]
483 // [ ] [ ] [ ] [ ] [ ] [O] => [O] [ ] [ ] [ ] [ ] [O]
486 // [ ] [ ] [ ] [ ] [ ] [ ] => [ ] [ ] [O] [ ] [ ] [ ]
489 // [ ] [ ] [ ] [ ] [ ] [ ] => [ ] [ ] [ ] [ ] [ ] [0]
492 // [O] [O] [O] [O] [O] [O] => [ ] [O] [O] [O] [O] [O]
495 // [O] [O] [O] [O] [O] [O] => [O] [O] [O] [O] [ ] [O]
498 // [O] [O] [O] [O] [O] [O] => [O] [O] [O] [O] [O] [ ]
501 // [ ] [ ] [O] [O] [ ] [ ] => [ ] [ ] [ ] [O] [ ] [ ]
504 // [ ] [ ] [ ] [O] [ ] [ ] => [ ] [ ] [ ] [ ] [ ] [ ]