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