Improved pan gesture prediction
[platform/core/uifw/dali-core.git] / automated-tests / src / dali-unmanaged / utc-Dali-Vector.cpp
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 #include <stdlib.h>
20 #include <dali/public-api/dali-core.h>
21 #include <dali-test-suite-utils.h>
22
23 using namespace Dali;
24
25 namespace
26 {
27 const Dali::VectorBase::SizeType ZERO(0);
28 }
29
30 int UtcDaliEmptyVectorInt(void)
31 {
32   tet_infoline("Testing Dali::Vector<int>");
33
34   Vector< int > intvector;
35
36   DALI_TEST_EQUALS( ZERO, intvector.Count(), TEST_LOCATION );
37   DALI_TEST_EQUALS( ZERO, intvector.Capacity(), TEST_LOCATION );
38
39   intvector.Clear();
40   DALI_TEST_EQUALS( ZERO, intvector.Count(), TEST_LOCATION );
41   DALI_TEST_EQUALS( ZERO, intvector.Capacity(), TEST_LOCATION );
42
43   intvector.Release();
44   DALI_TEST_EQUALS( ZERO, intvector.Count(), TEST_LOCATION );
45   DALI_TEST_EQUALS( ZERO, intvector.Capacity(), TEST_LOCATION );
46   END_TEST;
47 }
48
49 int UtcDaliVectorInt(void)
50 {
51   tet_infoline("Testing Dali::Vector<int>");
52
53   Vector< int > intvector;
54
55   DALI_TEST_EQUALS( ZERO, intvector.Count(), TEST_LOCATION );
56   DALI_TEST_EQUALS( ZERO, intvector.Capacity(), TEST_LOCATION );
57
58   intvector.PushBack( 11 );
59   DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(1), intvector.Count(), TEST_LOCATION );
60   DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(2), intvector.Capacity(), TEST_LOCATION );
61   DALI_TEST_EQUALS( 11, intvector[ 0 ], TEST_LOCATION );
62
63   intvector.PushBack( 99 );
64   DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(2), intvector.Count(), TEST_LOCATION );
65   DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(2), intvector.Capacity(), TEST_LOCATION );
66   DALI_TEST_EQUALS( 99, intvector[ 1 ], TEST_LOCATION );
67
68   intvector.PushBack( 34 );
69   DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(3), intvector.Count(), TEST_LOCATION );
70   DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(6), intvector.Capacity(), TEST_LOCATION );
71   DALI_TEST_EQUALS( 11, intvector[ 0 ], TEST_LOCATION );
72   DALI_TEST_EQUALS( 99, intvector[ 1 ], TEST_LOCATION );
73   DALI_TEST_EQUALS( 34, intvector[ 2 ], TEST_LOCATION );
74
75   intvector.Clear();
76   DALI_TEST_EQUALS( ZERO, intvector.Count(), TEST_LOCATION );
77   DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(6), intvector.Capacity(), TEST_LOCATION );
78   intvector.PushBack( 123 );
79   DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(1), intvector.Count(), TEST_LOCATION );
80   DALI_TEST_EQUALS( 123, intvector[ 0 ], TEST_LOCATION );
81   END_TEST;
82 }
83
84 int UtcDaliVectorIntCopy(void)
85 {
86   tet_infoline("Testing Dali::Vector<int>::Copy");
87
88   Vector< int > intvector;
89   DALI_TEST_EQUALS( ZERO, intvector.Count(), TEST_LOCATION );
90   DALI_TEST_EQUALS( ZERO, intvector.Capacity(), TEST_LOCATION );
91
92   intvector.PushBack( 99 );
93   intvector.PushBack( 11 );
94   intvector.PushBack( 34 );
95
96   // copy construct
97   Vector< int > intvector2( intvector );
98
99   DALI_TEST_EQUALS( intvector2.Count(), intvector.Count(), TEST_LOCATION );
100   DALI_TEST_EQUALS( intvector2.Capacity(), intvector.Capacity(), TEST_LOCATION );
101   DALI_TEST_EQUALS( intvector2[ 0 ], intvector[ 0 ], TEST_LOCATION );
102   DALI_TEST_EQUALS( intvector2[ 1 ], intvector[ 1 ], TEST_LOCATION );
103   DALI_TEST_EQUALS( intvector2[ 2 ], intvector[ 2 ], TEST_LOCATION );
104
105   // assign
106   Vector< int > intvector3;
107   DALI_TEST_EQUALS( ZERO, intvector3.Count(), TEST_LOCATION );
108   DALI_TEST_EQUALS( ZERO, intvector3.Capacity(), TEST_LOCATION );
109   intvector2 = intvector3;
110   DALI_TEST_EQUALS( intvector2.Count(), intvector3.Count(), TEST_LOCATION );
111   DALI_TEST_EQUALS( intvector2.Capacity(), intvector3.Capacity(), TEST_LOCATION );
112
113   // copy empty
114   Vector< int > intvector4;
115   intvector4.Reserve( 100 );
116   DALI_TEST_EQUALS( ZERO, intvector4.Count(), TEST_LOCATION );
117   DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(100), intvector4.Capacity(), TEST_LOCATION );
118   intvector3 = intvector4;
119   DALI_TEST_EQUALS( ZERO, intvector3.Count(), TEST_LOCATION );
120   DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(100), intvector3.Capacity(), TEST_LOCATION );
121
122   // self copy
123   intvector4 = intvector4;
124   DALI_TEST_EQUALS( ZERO, intvector4.Count(), TEST_LOCATION );
125   DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(100), intvector4.Capacity(), TEST_LOCATION );
126   END_TEST;
127 }
128
129 int UtcDaliVectorIntResize(void)
130 {
131   tet_infoline("Testing Dali::Vector<short>::Resize");
132
133   Vector< short > vector;
134   DALI_TEST_EQUALS( ZERO, vector.Count(), TEST_LOCATION );
135   DALI_TEST_EQUALS( ZERO, vector.Capacity(), TEST_LOCATION );
136
137   vector.Resize( 10u );
138   DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(10), vector.Count(), TEST_LOCATION );
139   DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(10), vector.Capacity(), TEST_LOCATION );
140
141   vector.Resize( 4u );
142   DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(4), vector.Count(), TEST_LOCATION );
143   DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(10), vector.Capacity(), TEST_LOCATION );
144
145   vector.Resize( 4u );
146   DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(4), vector.Count(), TEST_LOCATION );
147   DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(10), vector.Capacity(), TEST_LOCATION );
148
149   vector.Resize( 0u );
150   DALI_TEST_EQUALS( ZERO, vector.Count(), TEST_LOCATION );
151   DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(10), vector.Capacity(), TEST_LOCATION );
152
153   vector.Resize( 12u, 123 );
154   DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(12), vector.Count(), TEST_LOCATION );
155   DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(12), vector.Capacity(), TEST_LOCATION );
156
157   DALI_TEST_EQUALS( vector[ 0 ], 123, TEST_LOCATION );
158   DALI_TEST_EQUALS( vector[ 1 ], 123, TEST_LOCATION );
159   DALI_TEST_EQUALS( vector[ 2 ], 123, TEST_LOCATION );
160   DALI_TEST_EQUALS( vector[ 3 ], 123, TEST_LOCATION );
161   DALI_TEST_EQUALS( vector[ 4 ], 123, TEST_LOCATION );
162   DALI_TEST_EQUALS( vector[ 5 ], 123, TEST_LOCATION );
163   DALI_TEST_EQUALS( vector[ 6 ], 123, TEST_LOCATION );
164   DALI_TEST_EQUALS( vector[ 7 ], 123, TEST_LOCATION );
165   DALI_TEST_EQUALS( vector[ 8 ], 123, TEST_LOCATION );
166   DALI_TEST_EQUALS( vector[ 9 ], 123, TEST_LOCATION );
167   DALI_TEST_EQUALS( vector[ 10 ], 123, TEST_LOCATION );
168   DALI_TEST_EQUALS( vector[ 11 ], 123, TEST_LOCATION );
169
170   vector.Resize( 13u, 321 );
171   DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(13), vector.Count(), TEST_LOCATION );
172   DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(13), vector.Capacity(), TEST_LOCATION );
173
174   DALI_TEST_EQUALS( vector[ 0 ], 123, TEST_LOCATION );
175   DALI_TEST_EQUALS( vector[ 1 ], 123, TEST_LOCATION );
176   DALI_TEST_EQUALS( vector[ 2 ], 123, TEST_LOCATION );
177   DALI_TEST_EQUALS( vector[ 3 ], 123, TEST_LOCATION );
178   DALI_TEST_EQUALS( vector[ 4 ], 123, TEST_LOCATION );
179   DALI_TEST_EQUALS( vector[ 5 ], 123, TEST_LOCATION );
180   DALI_TEST_EQUALS( vector[ 6 ], 123, TEST_LOCATION );
181   DALI_TEST_EQUALS( vector[ 7 ], 123, TEST_LOCATION );
182   DALI_TEST_EQUALS( vector[ 8 ], 123, TEST_LOCATION );
183   DALI_TEST_EQUALS( vector[ 9 ], 123, TEST_LOCATION );
184   DALI_TEST_EQUALS( vector[ 10 ], 123, TEST_LOCATION );
185   DALI_TEST_EQUALS( vector[ 11 ], 123, TEST_LOCATION );
186   DALI_TEST_EQUALS( vector[ 12 ], 321, TEST_LOCATION );
187   END_TEST;
188 }
189
190 int UtcDaliVectorIntErase(void)
191 {
192   tet_infoline("Testing Dali::Vector<short>::Erase");
193
194   Vector< char > vector;
195   DALI_TEST_EQUALS( ZERO, vector.Count(), TEST_LOCATION );
196   DALI_TEST_EQUALS( ZERO, vector.Capacity(), TEST_LOCATION );
197   vector.PushBack( 1 );
198   vector.PushBack( 2 );
199   vector.PushBack( 3 );
200   vector.PushBack( 4 );
201   vector.PushBack( 5 );
202   DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(5), vector.Count(), TEST_LOCATION );
203   DALI_TEST_EQUALS( vector[ 0 ], 1, TEST_LOCATION );
204   DALI_TEST_EQUALS( vector[ 1 ], 2, TEST_LOCATION );
205   DALI_TEST_EQUALS( vector[ 2 ], 3, TEST_LOCATION );
206   DALI_TEST_EQUALS( vector[ 3 ], 4, TEST_LOCATION );
207   DALI_TEST_EQUALS( vector[ 4 ], 5, TEST_LOCATION );
208
209   vector.Erase( vector.Begin() );
210   DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(4), vector.Count(), TEST_LOCATION );
211   DALI_TEST_EQUALS( vector[ 0 ], 2, TEST_LOCATION );
212   DALI_TEST_EQUALS( vector[ 1 ], 3, TEST_LOCATION );
213   DALI_TEST_EQUALS( vector[ 2 ], 4, TEST_LOCATION );
214   DALI_TEST_EQUALS( vector[ 3 ], 5, TEST_LOCATION );
215
216   Vector< char >::Iterator ret = vector.Erase( std::find( vector.Begin(), vector.End(), 4 ) );
217   DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(3), vector.Count(), TEST_LOCATION );
218   DALI_TEST_EQUALS( vector[ 0 ], 2, TEST_LOCATION );
219   DALI_TEST_EQUALS( vector[ 1 ], 3, TEST_LOCATION );
220   DALI_TEST_EQUALS( vector[ 2 ], 5, TEST_LOCATION );
221   DALI_TEST_EQUALS( *ret, 5, TEST_LOCATION );
222
223   // try erasing last
224   vector.PushBack( 99 );
225   DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(4), vector.Count(), TEST_LOCATION );
226   DALI_TEST_EQUALS( vector[ 3 ], 99, TEST_LOCATION );
227   ret = vector.Erase( vector.End() - 1 );
228   DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(3), vector.Count(), TEST_LOCATION );
229   DALI_TEST_EQUALS( ret, vector.End(), TEST_LOCATION );
230
231   try
232   {
233     // illegal erase, one past the end
234     vector.Erase( vector.End() );
235     tet_result(TET_FAIL);
236   }
237   catch( Dali::DaliException& e )
238   {
239     DALI_TEST_PRINT_ASSERT( e );
240     DALI_TEST_ASSERT( e, "(iterator < End())", TEST_LOCATION );
241   }
242   catch( ... )
243   {
244     tet_printf("Assertion test failed - wrong Exception\n" );
245     tet_result(TET_FAIL);
246   }
247
248   try
249   {
250     // illegal erase, one before the begin
251     vector.Erase( vector.Begin() - 1u );
252     tet_result(TET_FAIL);
253   }
254   catch( Dali::DaliException& e )
255   {
256     DALI_TEST_PRINT_ASSERT( e );
257     DALI_TEST_ASSERT( e, "(iterator < End()) && (iterator >= Begin())", TEST_LOCATION );
258   }
259   catch( ... )
260   {
261     tet_printf("Assertion test failed - wrong Exception\n" );
262     tet_result(TET_FAIL);
263   }
264
265
266   DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(3), vector.Count(), TEST_LOCATION );
267   DALI_TEST_EQUALS( vector[ 0 ], 2, TEST_LOCATION );
268   DALI_TEST_EQUALS( vector[ 1 ], 3, TEST_LOCATION );
269   DALI_TEST_EQUALS( vector[ 2 ], 5, TEST_LOCATION );
270
271   vector.Erase( vector.Begin() + 1 );
272   DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(2), vector.Count(), TEST_LOCATION );
273   DALI_TEST_EQUALS( vector[ 0 ], 2, TEST_LOCATION );
274   DALI_TEST_EQUALS( vector[ 1 ], 5, TEST_LOCATION );
275
276   vector.Erase( vector.Begin() + 1 );
277   DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(1), vector.Count(), TEST_LOCATION );
278   DALI_TEST_EQUALS( vector[ 0 ], 2, TEST_LOCATION );
279
280   try
281   {
282     // illegal erase, one past the end
283     vector.Erase( vector.Begin() + 1 );
284     tet_result(TET_FAIL);
285   }
286   catch( Dali::DaliException& e )
287   {
288     DALI_TEST_PRINT_ASSERT( e );
289     DALI_TEST_ASSERT( e, "(iterator < End())", TEST_LOCATION );
290   }
291   catch( ... )
292   {
293     tet_printf("Assertion test failed - wrong Exception\n" );
294     tet_result(TET_FAIL);
295   }
296   DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(1), vector.Count(), TEST_LOCATION );
297   DALI_TEST_EQUALS( vector[ 0 ], 2, TEST_LOCATION );
298
299   vector.Erase( vector.Begin() );
300   DALI_TEST_EQUALS( ZERO, vector.Count(), TEST_LOCATION );
301
302   try
303   {
304     // illegal erase, one before the beginning
305     vector.Erase( vector.Begin() - 1 );
306     tet_result(TET_FAIL);
307   }
308   catch( Dali::DaliException& e )
309   {
310     DALI_TEST_PRINT_ASSERT( e );
311     DALI_TEST_ASSERT( e, "(iterator < End())", TEST_LOCATION );
312   }
313   catch( ... )
314   {
315     tet_printf("Assertion test failed - wrong Exception\n" );
316     tet_result(TET_FAIL);
317   }
318
319   DALI_TEST_EQUALS( ZERO, vector.Count(), TEST_LOCATION );
320   DALI_TEST_EQUALS( vector.Begin(), vector.End(), TEST_LOCATION );
321
322   Vector< char >::Iterator endIter = vector.End();
323   for( Vector< char >::Iterator iter = vector.Begin(); iter != endIter; ++iter )
324   {
325     tet_result(TET_FAIL);
326   }
327
328   vector.PushBack( 3 );
329   DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(1), vector.Count(), TEST_LOCATION );
330
331   vector.Clear();
332   DALI_TEST_EQUALS( ZERO, vector.Count(), TEST_LOCATION );
333   DALI_TEST_EQUALS( vector.Begin(), vector.End(), TEST_LOCATION );
334
335   endIter = vector.End();
336   for( Vector< char >::Iterator iter = vector.Begin(); iter != endIter; ++iter )
337   {
338     tet_result(TET_FAIL);
339   }
340
341   // test a vector of pointers
342   Vector< int* > ptrVector;
343   DALI_TEST_EQUALS( ZERO, ptrVector.Count(), TEST_LOCATION );
344   DALI_TEST_EQUALS( ptrVector.Begin(), ptrVector.End(), TEST_LOCATION );
345
346   int* pointer = NULL;
347   ptrVector.PushBack( pointer );
348   DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(1), ptrVector.Count(), TEST_LOCATION );
349
350   Vector< int* >::Iterator ptriter = std::find( ptrVector.Begin(), ptrVector.End(), pointer );
351   ptriter = ptrVector.Erase( ptriter );
352   DALI_TEST_EQUALS( ZERO, ptrVector.Count(), TEST_LOCATION );
353   DALI_TEST_EQUALS( ptrVector.Begin(), ptrVector.End(), TEST_LOCATION );
354   DALI_TEST_EQUALS( ptrVector.Begin(), ptriter, TEST_LOCATION );
355   END_TEST;
356 }
357
358
359 int UtcDaliVectorDoubleRemove(void)
360 {
361   tet_infoline("Testing Dali::Vector<double>::Remove");
362
363   Vector< double > vector;
364   DALI_TEST_EQUALS( ZERO, vector.Count(), TEST_LOCATION );
365
366   vector.PushBack( 11.1 );
367   vector.PushBack( 22.2 );
368   vector.PushBack( 33.3 );
369   vector.PushBack( 44.4 );
370   DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(4), vector.Count(), TEST_LOCATION );
371   DALI_TEST_EQUALS( vector[ 0 ], 11.1, TEST_LOCATION );
372   DALI_TEST_EQUALS( vector[ 1 ], 22.2, TEST_LOCATION );
373   DALI_TEST_EQUALS( vector[ 2 ], 33.3, TEST_LOCATION );
374   DALI_TEST_EQUALS( vector[ 3 ], 44.4, TEST_LOCATION );
375
376   Vector< double >::Iterator res = std::find( vector.Begin(), vector.End(), 22.2 );
377   DALI_TEST_EQUALS( 22.2, *res, TEST_LOCATION );
378   vector.Remove( res );
379   res = std::find( vector.Begin(), vector.End(), 22.2 );
380   DALI_TEST_EQUALS( vector.End(), res, TEST_LOCATION );
381   DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(3), vector.Count(), TEST_LOCATION );
382   DALI_TEST_EQUALS( vector[ 0 ], 11.1, TEST_LOCATION );
383   DALI_TEST_EQUALS( vector[ 1 ], 44.4, TEST_LOCATION );
384   DALI_TEST_EQUALS( vector[ 2 ], 33.3, TEST_LOCATION );
385
386   vector.Remove( vector.End() - 1 );
387   DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(2), vector.Count(), TEST_LOCATION );
388   DALI_TEST_EQUALS( vector[ 0 ], 11.1, TEST_LOCATION );
389   DALI_TEST_EQUALS( vector[ 1 ], 44.4, TEST_LOCATION );
390
391   vector.Remove( vector.Begin() );
392   DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(1), vector.Count(), TEST_LOCATION );
393   DALI_TEST_EQUALS( vector[ 0 ], 44.4, TEST_LOCATION );
394
395   try
396   {
397     // illegal erase, one past the end
398     vector.Remove( vector.Begin() + 1 );
399     tet_result(TET_FAIL);
400   }
401   catch( Dali::DaliException& e )
402   {
403     DALI_TEST_PRINT_ASSERT( e );
404     DALI_TEST_ASSERT( e, "(iterator < End()) && (iterator >= Begin())", TEST_LOCATION );
405   }
406   catch( ... )
407   {
408     tet_printf("Assertion test failed - wrong Exception\n" );
409     tet_result(TET_FAIL);
410   }
411   DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(1), vector.Count(), TEST_LOCATION );
412   DALI_TEST_EQUALS( vector[ 0 ], 44.4, TEST_LOCATION );
413
414   vector.Remove( vector.Begin() );
415   DALI_TEST_EQUALS( ZERO, vector.Count(), TEST_LOCATION );
416
417   try
418   {
419     // illegal erase, one before the beginning
420     vector.Remove( vector.Begin() - 1 );
421     tet_result(TET_FAIL);
422   }
423   catch( Dali::DaliException& e )
424   {
425     DALI_TEST_PRINT_ASSERT( e );
426     DALI_TEST_ASSERT( e, "(iterator < End()) && (iterator >= Begin())", TEST_LOCATION );
427   }
428   catch( ... )
429   {
430     tet_printf("Assertion test failed - wrong Exception\n" );
431     tet_result(TET_FAIL);
432   }
433
434   END_TEST;
435 }
436
437 int UtcDaliVectorIntSwap(void)
438 {
439   tet_infoline("Testing Dali::Vector<int>::Swap");
440
441   Vector< int > intvector;
442   DALI_TEST_EQUALS( ZERO, intvector.Count(), TEST_LOCATION );
443   DALI_TEST_EQUALS( ZERO, intvector.Capacity(), TEST_LOCATION );
444
445   intvector.PushBack( 11 );
446   intvector.PushBack( 22 );
447   intvector.PushBack( 33 );
448   DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(3), intvector.Count(), TEST_LOCATION );
449
450   Vector< int > intvector2;
451   DALI_TEST_EQUALS( ZERO, intvector2.Count(), TEST_LOCATION );
452   DALI_TEST_EQUALS( ZERO, intvector2.Capacity(), TEST_LOCATION );
453
454   intvector2.Swap( intvector );
455   DALI_TEST_EQUALS( ZERO, intvector.Count(), TEST_LOCATION );
456   DALI_TEST_EQUALS( ZERO, intvector.Capacity(), TEST_LOCATION );
457   DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(3), intvector2.Count(), TEST_LOCATION );
458   DALI_TEST_EQUALS( 11, intvector2[ 0 ], TEST_LOCATION );
459   DALI_TEST_EQUALS( 22, intvector2[ 1 ], TEST_LOCATION );
460   DALI_TEST_EQUALS( 33, intvector2[ 2 ], TEST_LOCATION );
461
462   intvector.PushBack( 99 );
463   intvector.PushBack( 88 );
464   DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(2), intvector.Count(), TEST_LOCATION );
465
466   intvector.Swap( intvector2 );
467   DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(2), intvector2.Count(), TEST_LOCATION );
468   DALI_TEST_EQUALS( 99, intvector2[ 0 ], TEST_LOCATION );
469   DALI_TEST_EQUALS( 88, intvector2[ 1 ], TEST_LOCATION );
470   DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(3), intvector.Count(), TEST_LOCATION );
471   DALI_TEST_EQUALS( 11, intvector[ 0 ], TEST_LOCATION );
472   DALI_TEST_EQUALS( 22, intvector[ 1 ], TEST_LOCATION );
473   DALI_TEST_EQUALS( 33, intvector[ 2 ], TEST_LOCATION );
474
475   Vector< int > empty;
476   intvector.Swap( empty );
477   DALI_TEST_EQUALS( ZERO, intvector.Count(), TEST_LOCATION );
478   DALI_TEST_EQUALS( ZERO, intvector.Capacity(), TEST_LOCATION );
479   END_TEST;
480 }
481
482 int UtcDaliVectorIterate(void)
483 {
484   tet_infoline("Testing Dali::Vector<float>::Begin");
485
486   Vector< float > floatvector;
487   DALI_TEST_EQUALS( ZERO, floatvector.Count(), TEST_LOCATION );
488   DALI_TEST_EQUALS( ZERO, floatvector.Capacity(), TEST_LOCATION );
489
490   floatvector.PushBack( 0.9f );
491   floatvector.PushBack( 1.1f );
492   floatvector.PushBack( 1.2f );
493   DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(3), floatvector.Count(), TEST_LOCATION );
494
495   Vector< float >::Iterator iter = floatvector.Begin();
496   int index = 0;
497   for( ; iter != floatvector.End(); ++iter, ++index )
498   {
499     std::cout << "value " << *iter << std::endl;
500     DALI_TEST_EQUALS( *iter, floatvector[ index ], TEST_LOCATION );
501   }
502   DALI_TEST_EQUALS( 3, index, TEST_LOCATION );
503
504   iter = std::find( floatvector.Begin(), floatvector.End(), 1.1f );
505   DALI_TEST_EQUALS( 1.1f, *iter, TEST_LOCATION );
506
507   floatvector.Clear();
508   iter = std::find( floatvector.Begin(), floatvector.End(), 1.1f );
509   DALI_TEST_EQUALS( floatvector.End(), iter, TEST_LOCATION );
510   END_TEST;
511 }
512
513 int UtcDaliVectorPair(void)
514 {
515   tet_infoline("Testing Dali::Vector< std::pair< int, float > >");
516
517   Vector< std::pair< int, float > > pairvector;
518   DALI_TEST_EQUALS( ZERO, pairvector.Count(), TEST_LOCATION );
519   DALI_TEST_EQUALS( ZERO, pairvector.Capacity(), TEST_LOCATION );
520
521   pairvector.PushBack( std::make_pair( 5, 0.1f ) );
522   pairvector.PushBack( std::make_pair( 3, 0.2f ) );
523   pairvector.PushBack( std::make_pair( 4, 0.3f ) );
524   pairvector.PushBack( std::make_pair( 1, 0.4f ) );
525   pairvector.PushBack( std::make_pair( 2, 0.5f ) );
526   DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(5), pairvector.Count(), TEST_LOCATION );
527
528   Vector< std::pair< int, float > >::Iterator iter = pairvector.Begin();
529   int index = 0;
530   for( ; iter != pairvector.End(); ++iter, ++index )
531   {
532     std::cout << "pair " << (*iter).first << ":" << (*iter).second << std::endl;
533     DALI_TEST_EQUALS( (*iter).first, pairvector[ index ].first, TEST_LOCATION );
534     DALI_TEST_EQUALS( (*iter).second, pairvector[ index ].second, TEST_LOCATION );
535   }
536   END_TEST;
537 }
538
539 int UtcDaliVectorAsserts(void)
540 {
541   tet_infoline("Testing Dali::Vector< int* > exception handling");
542
543   // empty vector
544   Vector< int* > pointervector;
545   try
546   {
547     int* value = NULL;
548     pointervector[ 1 ] = value;
549     tet_printf("Assertion expected, but not occurred at %s\n", TEST_LOCATION );
550     tet_result(TET_FAIL);
551   }
552   catch(Dali::DaliException& e)
553   {
554     DALI_TEST_PRINT_ASSERT( e );
555     DALI_TEST_ASSERT( e, "VectorBase::mData", TEST_LOCATION );
556   }
557   catch(...)
558   {
559     tet_printf("Assertion test failed - wrong Exception\n" );
560     tet_result(TET_FAIL);
561   }
562
563   try
564   {
565     int* value = NULL;
566     value = pointervector[ 0 ];
567     (void)value; // to "use" the value
568     tet_printf("Assertion expected, but not occurred at %s\n", TEST_LOCATION );
569     tet_result(TET_FAIL);
570   }
571   catch(Dali::DaliException& e)
572   {
573     DALI_TEST_PRINT_ASSERT( e );
574     DALI_TEST_ASSERT( e, "VectorBase::mData", TEST_LOCATION );
575   }
576   catch(...)
577   {
578     tet_printf("Assertion test failed - wrong Exception\n" );
579     tet_result(TET_FAIL);
580   }
581
582   Vector< int* >::Iterator iter = pointervector.Begin();
583   if( iter != pointervector.End() )
584   {
585     tet_result(TET_FAIL);
586   }
587
588   try
589   {
590     pointervector.Erase( pointervector.Begin() );
591     tet_printf("Assertion expected, but not occurred at %s\n", TEST_LOCATION );
592     tet_result(TET_FAIL);
593   }
594   catch(Dali::DaliException& e)
595   {
596     DALI_TEST_PRINT_ASSERT( e );
597     DALI_TEST_ASSERT( e, "(iterator < End()) && (iterator >= Begin())", TEST_LOCATION );
598   }
599   catch(...)
600   {
601     tet_printf("Assertion test failed - wrong Exception\n" );
602     tet_result(TET_FAIL);
603   }
604
605   iter = pointervector.Begin();
606   if( iter != pointervector.End() )
607   {
608     tet_result(TET_FAIL);
609   }
610
611   try
612   {
613     pointervector.Remove( pointervector.Begin() );
614     tet_printf("Assertion expected, but not occurred at %s\n", TEST_LOCATION );
615     tet_result(TET_FAIL);
616   }
617   catch(Dali::DaliException& e)
618   {
619     DALI_TEST_PRINT_ASSERT( e );
620     DALI_TEST_ASSERT( e, "(iterator < End()) && (iterator >= Begin())", TEST_LOCATION );
621   }
622   catch(...)
623   {
624     tet_printf("Assertion test failed - wrong Exception\n" );
625     tet_result(TET_FAIL);
626   }
627
628   iter = pointervector.Begin();
629   if( iter != pointervector.End() )
630   {
631     tet_result(TET_FAIL);
632   }
633
634   // reserve 0 space
635   pointervector.Reserve( 0 );
636   iter = pointervector.Begin();
637   if( iter != pointervector.End() )
638   {
639     tet_result(TET_FAIL);
640   }
641
642   // reserve 1 space
643   pointervector.Reserve( 1 );
644   iter = pointervector.Begin();
645   if( iter != pointervector.End() )
646   {
647     tet_result(TET_FAIL);
648   }
649
650   try
651   {
652     int* value = NULL;
653     pointervector[ 1 ] = value;
654     tet_printf("Assertion expected, but not occurred at %s\n", TEST_LOCATION );
655     tet_result(TET_FAIL);
656   }
657   catch(Dali::DaliException& e)
658   {
659     DALI_TEST_PRINT_ASSERT( e );
660     DALI_TEST_ASSERT( e, "index < VectorBase::Count()", TEST_LOCATION );
661   }
662   catch(...)
663   {
664     tet_printf("Assertion test failed - wrong Exception\n" );
665     tet_result(TET_FAIL);
666   }
667
668   try
669   {
670     int* value = pointervector[ 1 ];
671     (void)value; // to "use" the value
672     tet_printf("Assertion expected, but not occurred at %s\n", TEST_LOCATION );
673     tet_result(TET_FAIL);
674   }
675   catch(Dali::DaliException& e)
676   {
677     DALI_TEST_PRINT_ASSERT( e );
678     DALI_TEST_ASSERT( e, "index < VectorBase::Count()", TEST_LOCATION );
679   }
680   catch(...)
681   {
682     tet_printf("Assertion test failed - wrong Exception\n" );
683     tet_result(TET_FAIL);
684   }
685
686   END_TEST;
687 }
688
689 int UtcDaliVectorAcidTest(void)
690 {
691   tet_infoline("Testing multiple Dali::Vector's");
692
693   // create multiple vectors
694   Vector< std::pair< float, float > > pairvector;
695   DALI_TEST_EQUALS( ZERO, pairvector.Count(), TEST_LOCATION );
696   DALI_TEST_EQUALS( ZERO, pairvector.Capacity(), TEST_LOCATION );
697   Vector< double > doublevector;
698   DALI_TEST_EQUALS( ZERO, doublevector.Count(), TEST_LOCATION );
699   DALI_TEST_EQUALS( ZERO, doublevector.Capacity(), TEST_LOCATION );
700   Vector< int* > intptrvector;
701   DALI_TEST_EQUALS( ZERO, intptrvector.Count(), TEST_LOCATION );
702   DALI_TEST_EQUALS( ZERO, intptrvector.Capacity(), TEST_LOCATION );
703   Vector< Dali::Actor* > actorptrvector;
704   DALI_TEST_EQUALS( ZERO, actorptrvector.Count(), TEST_LOCATION );
705   DALI_TEST_EQUALS( ZERO, actorptrvector.Capacity(), TEST_LOCATION );
706   Vector< long > longvector;
707   DALI_TEST_EQUALS( ZERO, longvector.Count(), TEST_LOCATION );
708   DALI_TEST_EQUALS( ZERO, longvector.Capacity(), TEST_LOCATION );
709   Vector< char > charvector;
710   DALI_TEST_EQUALS( ZERO, charvector.Count(), TEST_LOCATION );
711   DALI_TEST_EQUALS( ZERO, charvector.Capacity(), TEST_LOCATION );
712
713   // add items
714   static unsigned int acidCount = 10000;
715   int* ptr = NULL;
716   for( unsigned int i = 0; i < acidCount; ++i )
717   {
718     ++ptr;
719     pairvector.PushBack( std::make_pair( i, i ) );
720     doublevector.PushBack( (double)i );
721     intptrvector.PushBack( (int*)ptr );
722     actorptrvector.PushBack( (Dali::Actor*)ptr );
723     longvector.PushBack( (long)i );
724     charvector.PushBack( (char)i );
725   }
726   DALI_TEST_EQUALS( acidCount, pairvector.Count(), TEST_LOCATION );
727   std::size_t pairCapacity = pairvector.Capacity();
728   DALI_TEST_EQUALS( acidCount, doublevector.Count(), TEST_LOCATION );
729   std::size_t doubleCapacity = doublevector.Capacity();
730   DALI_TEST_EQUALS( acidCount, intptrvector.Count(), TEST_LOCATION );
731   std::size_t intptrCapacity = intptrvector.Capacity();
732   DALI_TEST_EQUALS( acidCount, actorptrvector.Count(), TEST_LOCATION );
733   std::size_t actorptrCapacity = actorptrvector.Capacity();
734   DALI_TEST_EQUALS( acidCount, longvector.Count(), TEST_LOCATION );
735   std::size_t longCapacity = longvector.Capacity();
736   DALI_TEST_EQUALS( acidCount, charvector.Count(), TEST_LOCATION );
737   std::size_t charCapacity = charvector.Capacity();
738
739   tet_printf("Dali::Vector< pair > capacity after %d pushbacks is %d", acidCount, pairCapacity );
740   tet_printf("Dali::Vector< double > capacity after %d pushbacks is %d", acidCount, doubleCapacity );
741   tet_printf("Dali::Vector< int* > capacity after %d pushbacks is %d", acidCount, intptrCapacity );
742   tet_printf("Dali::Vector< Actor* > capacity after %d pushbacks is %d", acidCount, actorptrCapacity );
743   tet_printf("Dali::Vector< long > capacity after %d pushbacks is %d", acidCount, longCapacity );
744   tet_printf("Dali::Vector< char > capacity after %d pushbacks is %d", acidCount, charCapacity );
745
746   // erase items
747   for( unsigned int i = 0; i < acidCount; ++i )
748   {
749     pairvector.Erase( pairvector.Begin() + ( i % pairvector.Count() ) );
750     doublevector.Erase( doublevector.Begin() + ( i % doublevector.Count() ) );
751     intptrvector.Erase( intptrvector.Begin() + ( i % intptrvector.Count() ) );
752     actorptrvector.Erase( actorptrvector.Begin() + ( i % actorptrvector.Count() ) );
753     longvector.Erase( longvector.Begin() + ( i % longvector.Count() ) );
754     charvector.Erase( charvector.Begin() + ( i % charvector.Count() ) );
755   }
756   DALI_TEST_EQUALS( ZERO, pairvector.Count(), TEST_LOCATION );
757   DALI_TEST_EQUALS( pairCapacity, pairvector.Capacity(), TEST_LOCATION );
758   DALI_TEST_EQUALS( ZERO, doublevector.Count(), TEST_LOCATION );
759   DALI_TEST_EQUALS( doubleCapacity, doublevector.Capacity(), TEST_LOCATION );
760   DALI_TEST_EQUALS( ZERO, intptrvector.Count(), TEST_LOCATION );
761   DALI_TEST_EQUALS( intptrCapacity, intptrvector.Capacity(), TEST_LOCATION );
762   DALI_TEST_EQUALS( ZERO, actorptrvector.Count(), TEST_LOCATION );
763   DALI_TEST_EQUALS( actorptrCapacity, actorptrvector.Capacity(), TEST_LOCATION );
764   DALI_TEST_EQUALS( ZERO, longvector.Count(), TEST_LOCATION );
765   DALI_TEST_EQUALS( longCapacity, longvector.Capacity(), TEST_LOCATION );
766   DALI_TEST_EQUALS( ZERO, charvector.Count(), TEST_LOCATION );
767   DALI_TEST_EQUALS( charCapacity, charvector.Capacity(), TEST_LOCATION );
768
769   END_TEST;
770 }
771
772 int UtcDaliVectorPushBack(void)
773 {
774   tet_infoline( "Testing Dali::Vector< int* >PushBack(Element)" );
775
776   Vector<unsigned int> vector;
777   DALI_TEST_EQUALS( ZERO, vector.Count(), TEST_LOCATION );
778   DALI_TEST_EQUALS( ZERO, vector.Capacity(), TEST_LOCATION );
779
780   vector.Reserve( 2u );
781   DALI_TEST_EQUALS( ZERO, vector.Count(), TEST_LOCATION );
782   DALI_TEST_EQUALS( 2u, vector.Capacity(), TEST_LOCATION );
783
784   vector.PushBack( 0u );
785   vector.PushBack( 1u );
786   vector.PushBack( 2u );
787
788   DALI_TEST_EQUALS( 3u, vector.Count(), TEST_LOCATION );
789   DALI_TEST_EQUALS( 6u, vector.Capacity(), TEST_LOCATION );
790
791   vector.PushBack( 3u );
792
793   DALI_TEST_EQUALS( 4u, vector.Count(), TEST_LOCATION );
794   DALI_TEST_EQUALS( 6u, vector.Capacity(), TEST_LOCATION );
795
796   DALI_TEST_EQUALS( 0u, vector[0u], TEST_LOCATION );
797   DALI_TEST_EQUALS( 1u, vector[1u], TEST_LOCATION );
798   DALI_TEST_EQUALS( 2u, vector[2u], TEST_LOCATION );
799   DALI_TEST_EQUALS( 3u, vector[3u], TEST_LOCATION );
800
801   END_TEST;
802 }
803
804 int UtcDaliVectorInsert01(void)
805 {
806   tet_infoline( "Testing Dali::Vector< int* >Insert(Iterator, Element)" );
807
808   // Test order of array inserted-into:
809   Vector< unsigned int > orderedVector;
810   orderedVector.PushBack( 9u );
811   for( unsigned int i = 8u; i <= 8u; --i )
812   {
813     orderedVector.Insert( orderedVector.Begin(), i );
814     DALI_TEST_EQUALS( 10u - i, orderedVector.Count(), TEST_LOCATION );
815     DALI_TEST_EQUALS( i, orderedVector[0u], TEST_LOCATION );
816   }
817
818   for( unsigned int i = 0u; i < 10u; ++i )
819   {
820     DALI_TEST_EQUALS( i, orderedVector[i], TEST_LOCATION );
821   }
822
823   // Test insertion out of range in non-empty array throws:
824   try
825   {
826     orderedVector.Insert( orderedVector.Begin() + 99u, 99u );
827     tet_printf( "Assertion expected, but not occurred at %s\n", TEST_LOCATION );
828     tet_result( TET_FAIL );
829   }
830   catch( Dali::DaliException& e )
831   {
832     DALI_TEST_PRINT_ASSERT( e );
833     DALI_TEST_ASSERT( e, "( at <= End() ) && ( at >= Begin() )", TEST_LOCATION );
834   }
835   catch( ... )
836   {
837     tet_printf( "Assertion test failed - wrong Exception\n" );
838     tet_result( TET_FAIL );
839   }
840
841   try
842   {
843     orderedVector.Insert( orderedVector.Begin() - 1u, 99u );
844     tet_printf( "Assertion expected, but not occurred at %s\n", TEST_LOCATION );
845     tet_result( TET_FAIL );
846   }
847   catch( Dali::DaliException& e )
848   {
849     DALI_TEST_PRINT_ASSERT( e );
850     DALI_TEST_ASSERT( e, "( at <= End() ) && ( at >= Begin() )", TEST_LOCATION );
851   }
852   catch( ... )
853   {
854     tet_printf( "Assertion test failed - wrong Exception\n" );
855     tet_result( TET_FAIL );
856   }
857
858   // Test insertion part-way through a largish array retains ordering:
859
860   // Build vector with hole in sequence:
861   Vector< unsigned int > longerVector;
862   const unsigned int insertionPoint = 131571u;
863   const unsigned int finalLength = 262143u;
864   for( unsigned int i = 0u; i < insertionPoint; ++i )
865   {
866     longerVector.PushBack( i );
867   }
868   for( unsigned int i = insertionPoint; i < finalLength; ++i )
869   {
870     longerVector.PushBack( i + 1 );
871   }
872
873   // Fill the hole in the sequence:
874   longerVector.Insert( longerVector.Begin() + insertionPoint, insertionPoint );
875
876   // Check the sequence is monotonically increasing by one every time:
877   for( unsigned int i = 0u; i <= finalLength; ++i )
878   {
879     DALI_TEST_EQUALS( i, longerVector[i], TEST_LOCATION );
880   }
881
882   // Insert into an empty vector
883   Vector< unsigned int > vector;
884
885   vector.Insert( vector.End(), orderedVector.Begin(), orderedVector.End() );
886   for( unsigned int i = 0u; i < 10u; ++i )
887   {
888     DALI_TEST_EQUALS( i, vector[i], TEST_LOCATION );
889   }
890
891   vector.Clear();
892   vector.Insert( vector.Begin(), orderedVector.Begin(), orderedVector.End() );
893   for( unsigned int i = 0u; i < 10u; ++i )
894   {
895     DALI_TEST_EQUALS( i, vector[i], TEST_LOCATION );
896   }
897
898   // Insert nothing.
899   vector.Insert( vector.Begin(), orderedVector.Begin(), orderedVector.Begin() );
900   for( unsigned int i = 0u; i < 10u; ++i )
901   {
902     DALI_TEST_EQUALS( i, vector[i], TEST_LOCATION );
903   }
904
905   vector.Insert( vector.Begin() + 5, vector.Begin() + 5, vector.Begin() + 5 );
906   for( unsigned int i = 0u; i < 10u; ++i )
907   {
908     DALI_TEST_EQUALS( i, vector[i], TEST_LOCATION );
909   }
910
911   // AutoInsert
912   vector.Clear();
913   vector.PushBack( 0u );
914   vector.PushBack( 1u );
915   vector.PushBack( 2u );
916   vector.PushBack( 3u );
917
918   vector.Insert( vector.Begin() + 2, vector.Begin(), vector.End() );
919   DALI_TEST_EQUALS( 8u, vector.Count(), TEST_LOCATION );
920   DALI_TEST_EQUALS( 0u, vector[0u], TEST_LOCATION );
921   DALI_TEST_EQUALS( 1u, vector[1u], TEST_LOCATION );
922   DALI_TEST_EQUALS( 0u, vector[2u], TEST_LOCATION );
923   DALI_TEST_EQUALS( 1u, vector[3u], TEST_LOCATION );
924   DALI_TEST_EQUALS( 2u, vector[4u], TEST_LOCATION );
925   DALI_TEST_EQUALS( 3u, vector[5u], TEST_LOCATION );
926   DALI_TEST_EQUALS( 2u, vector[6u], TEST_LOCATION );
927   DALI_TEST_EQUALS( 3u, vector[7u], TEST_LOCATION );
928
929   END_TEST;
930 }
931
932 int UtcDaliVectorInsert02(void)
933 {
934   tet_infoline("Testing Dali::Vector<char>::Insert(Iterator,Iterator,Iterator)");
935
936   Vector< char > vector;
937   DALI_TEST_EQUALS( ZERO, vector.Count(), TEST_LOCATION );
938   DALI_TEST_EQUALS( ZERO, vector.Capacity(), TEST_LOCATION );
939   vector.PushBack( 1 );
940   vector.PushBack( 2 );
941   vector.PushBack( 3 );
942   vector.PushBack( 4 );
943   vector.PushBack( 5 );
944
945   Vector< char > vector2;
946   DALI_TEST_EQUALS( ZERO, vector2.Count(), TEST_LOCATION );
947   DALI_TEST_EQUALS( ZERO, vector2.Capacity(), TEST_LOCATION );
948   vector2.PushBack( 6 );
949   vector2.PushBack( 7 );
950   vector2.PushBack( 8 );
951   vector2.PushBack( 9 );
952   vector2.PushBack( 10 );
953
954   // Test insert at end
955   vector.Insert( vector.End(), vector2.Begin(), vector2.Begin() + 1u );
956   DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(6), vector.Count(), TEST_LOCATION );
957   DALI_TEST_EQUALS( vector[ 0 ], 1, TEST_LOCATION );
958   DALI_TEST_EQUALS( vector[ 1 ], 2, TEST_LOCATION );
959   DALI_TEST_EQUALS( vector[ 2 ], 3, TEST_LOCATION );
960   DALI_TEST_EQUALS( vector[ 3 ], 4, TEST_LOCATION );
961   DALI_TEST_EQUALS( vector[ 4 ], 5, TEST_LOCATION );
962   DALI_TEST_EQUALS( vector[ 5 ], 6, TEST_LOCATION );
963
964   // Test insert at begin
965   vector.Insert( vector.Begin(), vector2.Begin()+1, vector2.Begin() + 2u );
966   DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(7), vector.Count(), TEST_LOCATION );
967   DALI_TEST_EQUALS( vector[ 0 ], 7, TEST_LOCATION );
968   DALI_TEST_EQUALS( vector[ 1 ], 1, TEST_LOCATION );
969   DALI_TEST_EQUALS( vector[ 2 ], 2, TEST_LOCATION );
970   DALI_TEST_EQUALS( vector[ 3 ], 3, TEST_LOCATION );
971   DALI_TEST_EQUALS( vector[ 4 ], 4, TEST_LOCATION );
972   DALI_TEST_EQUALS( vector[ 5 ], 5, TEST_LOCATION );
973   DALI_TEST_EQUALS( vector[ 6 ], 6, TEST_LOCATION );
974
975   // Test insert in the middle
976   vector.Insert( vector.Begin() + 3, vector2.Begin()+3, vector2.End() );
977   DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(9), vector.Count(), TEST_LOCATION );
978   DALI_TEST_EQUALS( vector[ 0 ], 7, TEST_LOCATION );
979   DALI_TEST_EQUALS( vector[ 1 ], 1, TEST_LOCATION );
980   DALI_TEST_EQUALS( vector[ 2 ], 2, TEST_LOCATION );
981   DALI_TEST_EQUALS( vector[ 3 ], 9, TEST_LOCATION );
982   DALI_TEST_EQUALS( vector[ 4 ], 10, TEST_LOCATION );
983   DALI_TEST_EQUALS( vector[ 5 ], 3, TEST_LOCATION );
984   DALI_TEST_EQUALS( vector[ 6 ], 4, TEST_LOCATION );
985   DALI_TEST_EQUALS( vector[ 7 ], 5, TEST_LOCATION );
986   DALI_TEST_EQUALS( vector[ 8 ], 6, TEST_LOCATION );
987   END_TEST;
988 }
989
990 int UtcDaliVectorIntInsertAssert(void)
991 {
992   tet_infoline("Testing Dali::Vector<char>::Insert(Iterator,Iterator,Iterator) asserts");
993
994   Vector< char > vector;
995   DALI_TEST_EQUALS( ZERO, vector.Count(), TEST_LOCATION );
996   DALI_TEST_EQUALS( ZERO, vector.Capacity(), TEST_LOCATION );
997   vector.PushBack( 1 );
998   vector.PushBack( 2 );
999
1000   Vector< char > vector2;
1001   DALI_TEST_EQUALS( ZERO, vector2.Count(), TEST_LOCATION );
1002   DALI_TEST_EQUALS( ZERO, vector2.Capacity(), TEST_LOCATION );
1003   vector2.PushBack( 6 );
1004   vector2.PushBack( 7 );
1005   vector2.PushBack( 8 );
1006   vector2.PushBack( 9 );
1007   vector2.PushBack( 10 );
1008
1009   try
1010   {
1011     vector.Insert( vector.Begin() +  3u, vector2.Begin(), vector2.End() );
1012     tet_result(TET_FAIL);
1013   }
1014   catch( Dali::DaliException& e )
1015   {
1016     DALI_TEST_PRINT_ASSERT( e );
1017     DALI_TEST_ASSERT( e, "( at <= End() ) && ( at >= Begin() )", TEST_LOCATION );
1018   }
1019   catch( ... )
1020   {
1021     tet_printf("Assertion test failed - wrong Exception\n" );
1022     tet_result(TET_FAIL);
1023   }
1024
1025   try
1026   {
1027     vector.Insert( vector.Begin() -  1u, vector2.Begin(), vector2.End() );
1028     tet_result(TET_FAIL);
1029   }
1030   catch( Dali::DaliException& e )
1031   {
1032     DALI_TEST_PRINT_ASSERT( e );
1033     DALI_TEST_ASSERT( e, "( at <= End() ) && ( at >= Begin() )", TEST_LOCATION );
1034   }
1035   catch( ... )
1036   {
1037     tet_printf("Assertion test failed - wrong Exception\n" );
1038     tet_result(TET_FAIL);
1039   }
1040
1041   try
1042   {
1043     vector.Insert( vector.End(), vector2.End(), vector2.Begin() );
1044     tet_result(TET_FAIL);
1045   }
1046   catch( Dali::DaliException& e )
1047   {
1048     DALI_TEST_PRINT_ASSERT( e );
1049     DALI_TEST_ASSERT( e, "( from <= to )", TEST_LOCATION );
1050   }
1051   catch( ... )
1052   {
1053     tet_printf("Assertion test failed - wrong Exception\n" );
1054     tet_result(TET_FAIL);
1055   }
1056
1057   END_TEST;
1058  }
1059
1060
1061 int UtcDaliVectorIntEraseRange(void)
1062 {
1063   tet_infoline("Testing Dali::Vector<char>::Erase(Iterator,Iterator)");
1064
1065   Vector< char > vector;
1066   DALI_TEST_EQUALS( ZERO, vector.Count(), TEST_LOCATION );
1067   DALI_TEST_EQUALS( ZERO, vector.Capacity(), TEST_LOCATION );
1068
1069   // Try to delete from empty vector.
1070
1071   vector.Erase( vector.Begin(), vector.End() );
1072   DALI_TEST_EQUALS( ZERO, vector.Count(), TEST_LOCATION );
1073   DALI_TEST_EQUALS( ZERO, vector.Capacity(), TEST_LOCATION );
1074
1075   vector.PushBack( 1 );
1076   vector.PushBack( 2 );
1077   vector.PushBack( 3 );
1078   vector.PushBack( 4 );
1079   vector.PushBack( 5 );
1080   DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(5), vector.Count(), TEST_LOCATION );
1081   DALI_TEST_EQUALS( vector[ 0 ], 1, TEST_LOCATION );
1082   DALI_TEST_EQUALS( vector[ 1 ], 2, TEST_LOCATION );
1083   DALI_TEST_EQUALS( vector[ 2 ], 3, TEST_LOCATION );
1084   DALI_TEST_EQUALS( vector[ 3 ], 4, TEST_LOCATION );
1085   DALI_TEST_EQUALS( vector[ 4 ], 5, TEST_LOCATION );
1086
1087   Vector< char >::Iterator ret;
1088
1089   ret = vector.Erase( vector.Begin() + 1u, vector.Begin() + 2u );
1090   DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(4), vector.Count(), TEST_LOCATION );
1091   DALI_TEST_EQUALS( vector[ 0 ], 1, TEST_LOCATION );
1092   DALI_TEST_EQUALS( vector[ 1 ], 3, TEST_LOCATION );
1093   DALI_TEST_EQUALS( vector[ 2 ], 4, TEST_LOCATION );
1094   DALI_TEST_EQUALS( vector[ 3 ], 5, TEST_LOCATION );
1095   DALI_TEST_EQUALS( *ret, 3, TEST_LOCATION );
1096
1097   ret = vector.Erase( vector.Begin(), vector.Begin() + 2 );
1098   DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(2), vector.Count(), TEST_LOCATION );
1099   DALI_TEST_EQUALS( vector[ 0 ], 4, TEST_LOCATION );
1100   DALI_TEST_EQUALS( vector[ 1 ], 5, TEST_LOCATION );
1101   DALI_TEST_EQUALS( *ret, 4, TEST_LOCATION );
1102
1103   // try erasing last
1104   vector.PushBack( 99 );
1105   DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(3), vector.Count(), TEST_LOCATION );
1106   DALI_TEST_EQUALS( vector[ 2 ], 99, TEST_LOCATION );
1107   ret = vector.Erase( vector.Begin() + 1u, vector.End() );
1108   DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(1), vector.Count(), TEST_LOCATION );
1109   DALI_TEST_EQUALS( vector[ 0 ], 4, TEST_LOCATION );
1110   DALI_TEST_EQUALS( ret, vector.End(), TEST_LOCATION );
1111
1112   // try erasing all
1113   vector.PushBack( 100 );
1114   vector.PushBack( 101 );
1115   vector.PushBack( 102 );
1116
1117   DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(4), vector.Count(), TEST_LOCATION );
1118   DALI_TEST_EQUALS( vector[ 0 ], 4, TEST_LOCATION );
1119   DALI_TEST_EQUALS( vector[ 1 ], 100, TEST_LOCATION );
1120   DALI_TEST_EQUALS( vector[ 2 ], 101, TEST_LOCATION );
1121   DALI_TEST_EQUALS( vector[ 3 ], 102, TEST_LOCATION );
1122
1123   ret = vector.Erase( vector.Begin(), vector.End() );
1124   DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(0), vector.Count(), TEST_LOCATION );
1125   DALI_TEST_EQUALS( ret, vector.End(), TEST_LOCATION );
1126
1127   // try erase from Iterator to the same Iterator.
1128   vector.PushBack( 100 );
1129   vector.PushBack( 101 );
1130   vector.PushBack( 102 );
1131
1132   DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(3), vector.Count(), TEST_LOCATION );
1133   DALI_TEST_EQUALS( vector[ 0 ], 100, TEST_LOCATION );
1134   DALI_TEST_EQUALS( vector[ 1 ], 101, TEST_LOCATION );
1135   DALI_TEST_EQUALS( vector[ 2 ], 102, TEST_LOCATION );
1136
1137   ret = vector.Erase( vector.Begin() + 1, vector.Begin() + 1 );
1138
1139   DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(3), vector.Count(), TEST_LOCATION );
1140   DALI_TEST_EQUALS( vector[ 0 ], 100, TEST_LOCATION );
1141   DALI_TEST_EQUALS( vector[ 1 ], 101, TEST_LOCATION );
1142   DALI_TEST_EQUALS( vector[ 2 ], 102, TEST_LOCATION );
1143
1144   DALI_TEST_EQUALS( *ret, 101, TEST_LOCATION );
1145
1146   END_TEST;
1147 }
1148
1149 int UtcDaliVectorIntEraseRangeAssert(void)
1150 {
1151   tet_infoline("Testing Dali::Vector<char>::Erase(Iterator,Iterator) asserts");
1152
1153   Vector< char > vector;
1154   DALI_TEST_EQUALS( ZERO, vector.Count(), TEST_LOCATION );
1155   DALI_TEST_EQUALS( ZERO, vector.Capacity(), TEST_LOCATION );
1156
1157
1158   // Add some elements.
1159   vector.PushBack( 1 );
1160   vector.PushBack( 2 );
1161
1162   // first out of bounds
1163   try
1164   {
1165     vector.Erase( vector.Begin() + 3u, vector.Begin() + 4u );
1166     tet_printf( "Assertion expected, but not occurred at %s\n", TEST_LOCATION );
1167     tet_result(TET_FAIL);
1168   }
1169   catch( Dali::DaliException& e )
1170   {
1171     DALI_TEST_PRINT_ASSERT( e );
1172     DALI_TEST_ASSERT( e, "( first <= End() ) && ( first >= Begin() )", TEST_LOCATION );
1173   }
1174   catch( ... )
1175   {
1176     tet_printf("Assertion test failed - wrong Exception\n" );
1177     tet_result(TET_FAIL);
1178   }
1179
1180   try
1181   {
1182     vector.Erase( vector.Begin() - 1u, vector.End() );
1183     tet_printf( "Assertion expected, but not occurred at %s\n", TEST_LOCATION );
1184     tet_result(TET_FAIL);
1185   }
1186   catch( Dali::DaliException& e )
1187   {
1188     DALI_TEST_PRINT_ASSERT( e );
1189     DALI_TEST_ASSERT( e, "( first <= End() ) && ( first >= Begin() )", TEST_LOCATION );
1190   }
1191   catch( ... )
1192   {
1193     tet_printf("Assertion test failed - wrong Exception\n" );
1194     tet_result(TET_FAIL);
1195   }
1196
1197   // last out of bounds
1198
1199   try
1200   {
1201     vector.Erase( vector.Begin(), vector.Begin() + 3u );
1202     tet_printf( "Assertion expected, but not occurred at %s\n", TEST_LOCATION );
1203     tet_result(TET_FAIL);
1204   }
1205   catch( Dali::DaliException& e )
1206   {
1207     DALI_TEST_PRINT_ASSERT( e );
1208     DALI_TEST_ASSERT( e, "( last <= End() ) && ( last >= Begin() )", TEST_LOCATION );
1209   }
1210   catch( ... )
1211   {
1212     tet_printf("Assertion test failed - wrong Exception\n" );
1213     tet_result(TET_FAIL);
1214   }
1215
1216   try
1217   {
1218     vector.Erase( vector.Begin(), vector.Begin() - 1u );
1219     tet_printf( "Assertion expected, but not occurred at %s\n", TEST_LOCATION );
1220     tet_result(TET_FAIL);
1221   }
1222   catch( Dali::DaliException& e )
1223   {
1224     DALI_TEST_PRINT_ASSERT( e );
1225     DALI_TEST_ASSERT( e, "( last <= End() ) && ( last >= Begin() )", TEST_LOCATION );
1226   }
1227   catch( ... )
1228   {
1229     tet_printf("Assertion test failed - wrong Exception\n" );
1230     tet_result(TET_FAIL);
1231   }
1232
1233   vector.PushBack( 3 );
1234
1235   // first > last
1236   try
1237   {
1238     vector.Erase( vector.Begin() + 2u, vector.Begin() + 1u );
1239     tet_printf( "Assertion expected, but not occurred at %s\n", TEST_LOCATION );
1240     tet_result(TET_FAIL);
1241   }
1242   catch( Dali::DaliException& e )
1243   {
1244     DALI_TEST_PRINT_ASSERT( e );
1245     DALI_TEST_ASSERT( e, "( first <= last )", TEST_LOCATION );
1246   }
1247   catch( ... )
1248   {
1249     tet_printf("Assertion test failed - wrong Exception\n" );
1250     tet_result(TET_FAIL);
1251   }
1252
1253   END_TEST;
1254 }
1255
1256 namespace
1257 {
1258
1259 bool gConstructorCalled = false;
1260 bool gDestructorCalled = false;
1261
1262 struct ComplexType
1263 {
1264   ComplexType()
1265   {
1266     gConstructorCalled = true;
1267   }
1268   ~ComplexType()
1269   {
1270     gDestructorCalled = true;
1271   }
1272 };
1273
1274 } // anonymous namespace
1275
1276
1277 int UtcDaliVectorComplex(void)
1278 {
1279   tet_infoline("Testing Dali::Vector< int* > exception handling");
1280
1281   // this does not compile at the moment
1282 /*  Vector< ComplexType > classvector;
1283   DALI_TEST_EQUALS( ZERO, classvector.Count(), TEST_LOCATION );
1284   DALI_TEST_EQUALS( ZERO, classvector.Capacity(), TEST_LOCATION );
1285
1286   DALI_TEST_EQUALS( false, gConstructorCalled, TEST_LOCATION );
1287   DALI_TEST_EQUALS( false, gDestructorCalled, TEST_LOCATION );
1288   classvector.PushBack( ComplexType() );
1289   DALI_TEST_EQUALS( true, gConstructorCalled, TEST_LOCATION );
1290   classvector.Clear();
1291   DALI_TEST_EQUALS( true, gDestructorCalled, TEST_LOCATION );
1292 */
1293 //  Vector< Actor > classvector; this does not compile yet either
1294   tet_result(TET_PASS); // for now
1295   END_TEST;
1296 }