Added tracking of texture count to test harness
[platform/core/uifw/dali-core.git] / automated-tests / src / dali / utc-Dali-CircularQueue.cpp
1 /*
2  * Copyright (c) 2017 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 #define ENABLE_VECTOR_ASSERTS
19
20 #include <iostream>
21 #include <stdlib.h>
22 #include <dali/public-api/dali-core.h>
23 #include <dali/devel-api/common/circular-queue.h>
24 #include <dali-test-suite-utils.h>
25
26 using namespace Dali;
27
28 void utc_dali_circular_queue_startup(void)
29 {
30   test_return_value = TET_UNDEF;
31 }
32
33 void utc_dali_circular_queue_cleanup(void)
34 {
35   test_return_value = TET_PASS;
36 }
37
38
39 int UtcDaliCircularQueueNew(void)
40 {
41   CircularQueue<int> cQ = CircularQueue<int>( 20 );
42
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 );
46
47   END_TEST;
48 }
49
50
51 int UtcDaliCircularQueuePushBack01(void)
52 {
53   CircularQueue<int> cQ = CircularQueue<int>( 20 );
54
55   cQ.PushBack( 1 );
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 );
59
60   DALI_TEST_EQUALS( cQ[0], 1, TEST_LOCATION );
61
62   cQ.PushBack( 2 );
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 );
66
67   DALI_TEST_EQUALS( cQ[0], 1, TEST_LOCATION );
68   DALI_TEST_EQUALS( cQ[1], 2, TEST_LOCATION );
69
70   END_TEST;
71 }
72
73 int UtcDaliCircularQueuePushBack02(void)
74 {
75   CircularQueue<int> cQ = CircularQueue<int>( 20 );
76   for( int i=0; i<20; ++i)
77   {
78     cQ.PushBack( 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 );
82   }
83
84   END_TEST;
85 }
86
87 int UtcDaliCircularQueuePushBack03(void)
88 {
89   CircularQueue<int> cQ = CircularQueue<int>( 20 );
90   for( int i=0; i<19; ++i)
91   {
92     cQ.PushBack( i );
93   }
94   cQ.PushBack(19);
95   DALI_TEST_EQUALS( cQ.IsFull(), true, TEST_LOCATION );
96
97   for( int i=0; i<10; ++i )
98   {
99     tet_infoline( "Test that the end marker wraps around");
100     (void)cQ.PopFront();
101     cQ.PushBack(20+i);
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 );
105   }
106
107   END_TEST;
108 }
109
110
111 int UtcDaliCircularQueuePushBack04(void)
112 {
113   CircularQueue<int> cQ = CircularQueue<int>( 20 );
114   for( int i=0; i<10; ++i)
115   {
116     cQ.PushBack( i );
117     int v = cQ.PopFront();
118     DALI_TEST_EQUALS( v, i, TEST_LOCATION );
119     DALI_TEST_EQUALS( cQ.Count(), 0, TEST_LOCATION );
120   }
121   DALI_TEST_EQUALS( cQ.IsEmpty(), true, TEST_LOCATION );
122
123   // Queue is empty
124
125   cQ.PushBack(10);
126   DALI_TEST_EQUALS( cQ[0], 10, TEST_LOCATION );
127   DALI_TEST_EQUALS( cQ.Count(), 1, TEST_LOCATION );
128   (void)cQ.PopFront();
129   DALI_TEST_EQUALS( cQ.Count(), 0, TEST_LOCATION );
130   DALI_TEST_EQUALS( cQ.IsEmpty(), true, TEST_LOCATION );
131
132   // Queue is empty, markers should be in middle
133
134   for( int i=0; i<20; ++i)
135   {
136     cQ.PushBack( i );
137     int v = cQ.PopFront();
138     DALI_TEST_EQUALS( v, i, TEST_LOCATION );
139     DALI_TEST_EQUALS( cQ.Count(), 0, TEST_LOCATION );
140   }
141
142   END_TEST;
143 }
144
145
146 int UtcDaliCircularQueuePushBackN(void)
147 {
148   CircularQueue<int> cQ = CircularQueue<int>( 20 );
149   for( int i=0; i<20; ++i)
150   {
151     cQ.PushBack( 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 );
155   }
156
157   try
158   {
159     cQ.PushBack( 20 );
160     DALI_TEST_EQUALS( 0, 1, TEST_LOCATION );// Failure
161   }
162   catch( DaliException e )
163   {
164     DALI_TEST_EQUALS( 1, 1, TEST_LOCATION );
165   }
166
167   END_TEST;
168 }
169
170
171 int UtcDaliCircularQueueOperatorIndex01(void)
172 {
173   CircularQueue<int> cQ = CircularQueue<int>( 20 );
174   for( int i=0; i<20; ++i)
175   {
176     cQ.PushBack( 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 );
180   }
181
182   for( int i=0; i<20; ++i)
183   {
184     DALI_TEST_EQUALS( cQ[i], i, TEST_LOCATION );
185   }
186
187   END_TEST;
188 }
189
190 int UtcDaliCircularQueueOperatorIndexN01(void)
191 {
192   CircularQueue<int> cQ = CircularQueue<int>( 20 );
193
194   try
195   {
196     int v = cQ[0];
197     DALI_TEST_EQUALS(v, 1, TEST_LOCATION);
198   }
199   catch( DaliException e )
200   {
201     DALI_TEST_CHECK(true);
202   }
203
204   END_TEST;
205 }
206
207
208 int UtcDaliCircularQueuePopFront01(void)
209 {
210   CircularQueue<int> cQ = CircularQueue<int>( 20 );
211   for( int i=0; i<20; ++i)
212   {
213     cQ.PushBack( 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 );
217   }
218
219   for( int i=0; i<20; ++i)
220   {
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 );
225   }
226   END_TEST;
227 }
228
229 int UtcDaliCircularQueuePopFront02(void)
230 {
231   CircularQueue<int> cQ = CircularQueue<int>( 20 );
232   for( int i=0; i<10; ++i)
233   {
234     cQ.PushBack( i );
235     DALI_TEST_EQUALS( cQ[i], i, TEST_LOCATION );
236     DALI_TEST_EQUALS( cQ.Count(), i+1, TEST_LOCATION );
237   }
238
239   for( int i=0; i<10; ++i)
240   {
241     DALI_TEST_EQUALS( cQ.PopFront(), i, TEST_LOCATION );
242   }
243   DALI_TEST_EQUALS( cQ.Count(), 0, TEST_LOCATION );
244
245   END_TEST;
246 }
247
248
249 int UtcDaliCircularQueuePopFrontN01(void)
250 {
251   tet_infoline("Try popping from an empty queue");
252   CircularQueue<int> cQ = CircularQueue<int>( 20 );
253
254   try
255   {
256     (void)cQ.PopFront();
257     DALI_TEST_CHECK( false );
258   }
259   catch( DaliException e )
260   {
261     DALI_TEST_CHECK( true );
262   }
263
264   END_TEST;
265 }
266
267
268 int UtcDaliCircularQueuePopFrontN02(void)
269 {
270   tet_infoline("Try popping from an empty queue");
271
272   CircularQueue<int> cQ = CircularQueue<int>( 20 );
273
274   for( int i=0; i<10; ++i)
275   {
276     cQ.PushBack( i );
277     (void)cQ.PopFront();
278   }
279   DALI_TEST_EQUALS( cQ.IsEmpty(), true, TEST_LOCATION );
280
281   try
282   {
283     (void)cQ.PopFront();
284     DALI_TEST_CHECK( false );
285   }
286   catch( DaliException e )
287   {
288     DALI_TEST_CHECK( true );
289   }
290
291   END_TEST;
292 }
293
294 int UtcDaliCircularQueueCount(void)
295 {
296   CircularQueue<int> cQ = CircularQueue<int>( 20 );
297   DALI_TEST_EQUALS( cQ.Count(), 0, TEST_LOCATION );
298
299   for( int i=0; i<20; ++i)
300   {
301     cQ.PushBack( i );
302     DALI_TEST_EQUALS( cQ.Count(), 1+i, TEST_LOCATION );
303   }
304
305   END_TEST;
306 }
307
308 int UtcDaliCircularQueueIsEmpty(void)
309 {
310   CircularQueue<int> cQ = CircularQueue<int>( 20 );
311   DALI_TEST_EQUALS( cQ.IsEmpty(), true, TEST_LOCATION );
312
313   for( int i=0; i<20; ++i)
314   {
315     cQ.PushBack( i );
316     DALI_TEST_EQUALS( cQ.IsEmpty(), false, TEST_LOCATION );
317   }
318
319   // Pop off 19 elements
320   for( int i=0; i<19; ++i)
321   {
322     (void) cQ.PopFront();
323     DALI_TEST_EQUALS( cQ.IsEmpty(), false, TEST_LOCATION );
324   }
325   // pop off last element
326   (void) cQ.PopFront();
327   DALI_TEST_EQUALS( cQ.IsEmpty(), true, TEST_LOCATION );
328
329   tet_infoline( "Add half into queue, then remove");
330
331   for( int i=0; i<10; ++i)
332   {
333     cQ.PushBack( i );
334     DALI_TEST_EQUALS( cQ.IsEmpty(), false, TEST_LOCATION );
335   }
336   for( int i=0; i<9; ++i)
337   {
338     (void) cQ.PopFront();
339     DALI_TEST_EQUALS( cQ.IsEmpty(), false, TEST_LOCATION );
340   }
341   (void) cQ.PopFront();
342   DALI_TEST_EQUALS( cQ.IsEmpty(), true, TEST_LOCATION );
343
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)
346   {
347     cQ.PushBack( i );
348     DALI_TEST_EQUALS( cQ.IsEmpty(), false, TEST_LOCATION );
349   }
350
351   for( int i=0; i<19; ++i)
352   {
353     (void) cQ.PopFront();
354     DALI_TEST_EQUALS( cQ.IsEmpty(), false, TEST_LOCATION );
355   }
356   (void) cQ.PopFront();
357   DALI_TEST_EQUALS( cQ.IsEmpty(), true, TEST_LOCATION );
358   END_TEST;
359 }
360
361
362 int UtcDaliCircularQueueIsFull(void)
363 {
364   CircularQueue<int> cQ = CircularQueue<int>( 20 );
365   DALI_TEST_EQUALS( cQ.IsFull(), false, TEST_LOCATION );
366
367   for( int i=0; i<20; ++i)
368   {
369     cQ.PushBack( i );
370     DALI_TEST_EQUALS( cQ.IsFull(), i<19?false:true, TEST_LOCATION );
371   }
372   DALI_TEST_EQUALS( cQ.IsFull(), true, TEST_LOCATION );
373
374   for( int i=0; i<20; ++i)
375   {
376     (void) cQ.PopFront();
377     DALI_TEST_EQUALS( cQ.IsFull(), false, TEST_LOCATION );
378   }
379
380   tet_infoline( "Add half into queue, then remove");
381
382   for( int i=0; i<10; ++i)
383   {
384     cQ.PushBack( i );
385     DALI_TEST_EQUALS( cQ.IsFull(), false, TEST_LOCATION );
386   }
387   for( int i=0; i<10; ++i)
388   {
389     (void) cQ.PopFront();
390     DALI_TEST_EQUALS( cQ.IsFull(), false, TEST_LOCATION );
391   }
392
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)
395   {
396     cQ.PushBack( i );
397     DALI_TEST_EQUALS( cQ.IsFull(), i<19?false:true, TEST_LOCATION );
398   }
399
400   for( int i=0; i<20; ++i)
401   {
402     (void) cQ.PopFront();
403     DALI_TEST_EQUALS( cQ.IsFull(), false, TEST_LOCATION );
404   }
405
406   END_TEST;
407 }
408
409
410 int UtcDaliCircularQueueFront(void)
411 {
412   CircularQueue<int> cQ = CircularQueue<int>( 20 );
413
414   for( int i=0; i<20; ++i)
415   {
416     cQ.PushBack( i );
417     DALI_TEST_EQUALS( cQ.Front(), 0, TEST_LOCATION );
418   }
419
420   for( int i=0; i<19; ++i)
421   {
422     (void) cQ.PopFront();
423     DALI_TEST_EQUALS( cQ.Front(), i+1, TEST_LOCATION );
424   }
425   END_TEST;
426 }
427
428 int UtcDaliCircularQueueBack(void)
429 {
430   CircularQueue<int> cQ = CircularQueue<int>( 20 );
431
432   for( int i=0; i<20; ++i)
433   {
434     cQ.PushBack( i );
435     DALI_TEST_EQUALS( cQ.Back(), i, TEST_LOCATION );
436   }
437
438   for( int i=0; i<19; ++i)
439   {
440     (void) cQ.PopFront();
441     DALI_TEST_EQUALS( cQ.Back(), 19, TEST_LOCATION );
442   }
443   END_TEST;
444 }
445
446 int UtcDaliCircularQueueSize1(void)
447 {
448   CircularQueue<int> cQ = CircularQueue<int>( 1 );
449
450   DALI_TEST_EQUALS( cQ.IsEmpty(), true, TEST_LOCATION );
451   DALI_TEST_EQUALS( cQ.IsFull(), false, TEST_LOCATION );
452
453   cQ.PushBack( 5 );
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 );
458
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 );
462
463   END_TEST;
464 }
465
466
467   // pushback
468   //  .  => [O]
469   //  se     se
470
471   // [O] => [O] [O]
472   //  se     s   e
473
474   // [O] [O] [O] [O] [O] [ ]  => [O] [O] [O] [O] [O] [O]
475   //  s               e           s                   e
476
477   // [ ] [O] [O] [O] [O] [O]  => [O] [O] [O] [O] [O] [O]
478   //      s               e       e   s
479
480   // [ ] [ ] [O] [ ] [ ] [ ]  => [ ] [ ] [O] [O] [ ] [ ]
481   //          se                          s   e
482
483   // [ ] [ ] [ ] [ ] [ ] [O]  => [O] [ ] [ ] [ ] [ ] [O]
484   //                      se      e                   s
485
486   // [ ] [ ] [ ] [ ] [ ] [ ]  => [ ] [ ] [O] [ ] [ ] [ ]
487   //          se                          se
488
489   // [ ] [ ] [ ] [ ] [ ] [ ]  => [ ] [ ] [ ] [ ] [ ] [0]
490   //                      se                          se
491   // popfront
492   // [O] [O] [O] [O] [O] [O]  => [ ] [O] [O] [O] [O] [O]
493   //  s                   e           s               e
494
495   // [O] [O] [O] [O] [O] [O]  => [O] [O] [O] [O] [ ] [O]
496   //              e   s                       e       s
497
498   // [O] [O] [O] [O] [O] [O]  => [O] [O] [O] [O] [O] [ ]
499   //                  e   s       s               e
500
501   // [ ] [ ] [O] [O] [ ] [ ]  => [ ] [ ] [ ] [O] [ ] [ ]
502   //          s   e                           se
503
504   // [ ] [ ] [ ] [O] [ ] [ ]  => [ ] [ ] [ ] [ ] [ ] [ ]
505   //              se                          se