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