removed reliance on dali-adaptor
[platform/core/uifw/dali-core.git] / automated-tests / src / dali-unmanaged / utc-Dali-Vector.cpp
1 /*
2  * Copyright (c) 2014 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17
18 #include <iostream>
19 #include <stdlib.h>
20 #include <dali/public-api/dali-core.h>
21 #include <dali-test-suite-utils.h>
22
23 using namespace Dali;
24
25 namespace
26 {
27
28 const Dali::VectorBase::SizeType ZERO(0);
29
30 }
31
32
33 int UtcDaliEmptyVectorInt(void)
34 {
35   tet_infoline("Testing Dali::Vector<int>");
36
37   Vector< int > intvector;
38
39   DALI_TEST_EQUALS( ZERO, intvector.Count(), TEST_LOCATION );
40   DALI_TEST_EQUALS( ZERO, intvector.Capacity(), TEST_LOCATION );
41
42   intvector.Clear();
43   DALI_TEST_EQUALS( ZERO, intvector.Count(), TEST_LOCATION );
44   DALI_TEST_EQUALS( ZERO, intvector.Capacity(), TEST_LOCATION );
45
46   intvector.Release();
47   DALI_TEST_EQUALS( ZERO, intvector.Count(), TEST_LOCATION );
48   DALI_TEST_EQUALS( ZERO, intvector.Capacity(), TEST_LOCATION );
49   END_TEST;
50 }
51
52 int UtcDaliVectorInt(void)
53 {
54   tet_infoline("Testing Dali::Vector<int>");
55
56   Vector< int > intvector;
57
58   DALI_TEST_EQUALS( ZERO, intvector.Count(), TEST_LOCATION );
59   DALI_TEST_EQUALS( ZERO, intvector.Capacity(), TEST_LOCATION );
60
61   intvector.PushBack( 11 );
62   DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(1), intvector.Count(), TEST_LOCATION );
63   DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(2), intvector.Capacity(), TEST_LOCATION );
64   DALI_TEST_EQUALS( 11, intvector[ 0 ], TEST_LOCATION );
65
66   intvector.PushBack( 99 );
67   DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(2), intvector.Count(), TEST_LOCATION );
68   DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(2), intvector.Capacity(), TEST_LOCATION );
69   DALI_TEST_EQUALS( 99, intvector[ 1 ], TEST_LOCATION );
70
71   intvector.PushBack( 34 );
72   DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(3), intvector.Count(), TEST_LOCATION );
73   DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(6), intvector.Capacity(), TEST_LOCATION );
74   DALI_TEST_EQUALS( 11, intvector[ 0 ], TEST_LOCATION );
75   DALI_TEST_EQUALS( 99, intvector[ 1 ], TEST_LOCATION );
76   DALI_TEST_EQUALS( 34, intvector[ 2 ], TEST_LOCATION );
77
78   intvector.Clear();
79   DALI_TEST_EQUALS( ZERO, intvector.Count(), TEST_LOCATION );
80   DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(6), intvector.Capacity(), TEST_LOCATION );
81   intvector.PushBack( 123 );
82   DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(1), intvector.Count(), TEST_LOCATION );
83   DALI_TEST_EQUALS( 123, intvector[ 0 ], TEST_LOCATION );
84   END_TEST;
85 }
86
87 int UtcDaliVectorIntCopy(void)
88 {
89   tet_infoline("Testing Dali::Vector<int>::Copy");
90
91   Vector< int > intvector;
92   DALI_TEST_EQUALS( ZERO, intvector.Count(), TEST_LOCATION );
93   DALI_TEST_EQUALS( ZERO, intvector.Capacity(), TEST_LOCATION );
94
95   intvector.PushBack( 99 );
96   intvector.PushBack( 11 );
97   intvector.PushBack( 34 );
98
99   // copy construct
100   Vector< int > intvector2( intvector );
101
102   DALI_TEST_EQUALS( intvector2.Count(), intvector.Count(), TEST_LOCATION );
103   DALI_TEST_EQUALS( intvector2.Capacity(), intvector.Capacity(), TEST_LOCATION );
104   DALI_TEST_EQUALS( intvector2[ 0 ], intvector[ 0 ], TEST_LOCATION );
105   DALI_TEST_EQUALS( intvector2[ 1 ], intvector[ 1 ], TEST_LOCATION );
106   DALI_TEST_EQUALS( intvector2[ 2 ], intvector[ 2 ], TEST_LOCATION );
107
108   // assign
109   Vector< int > intvector3;
110   DALI_TEST_EQUALS( ZERO, intvector3.Count(), TEST_LOCATION );
111   DALI_TEST_EQUALS( ZERO, intvector3.Capacity(), TEST_LOCATION );
112   intvector2 = intvector3;
113   DALI_TEST_EQUALS( intvector2.Count(), intvector3.Count(), TEST_LOCATION );
114   DALI_TEST_EQUALS( intvector2.Capacity(), intvector3.Capacity(), TEST_LOCATION );
115
116   // copy empty
117   Vector< int > intvector4;
118   intvector4.Reserve( 100 );
119   DALI_TEST_EQUALS( ZERO, intvector4.Count(), TEST_LOCATION );
120   DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(100), intvector4.Capacity(), TEST_LOCATION );
121   intvector3 = intvector4;
122   DALI_TEST_EQUALS( ZERO, intvector3.Count(), TEST_LOCATION );
123   DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(100), intvector3.Capacity(), TEST_LOCATION );
124
125   // self copy
126   intvector4 = intvector4;
127   DALI_TEST_EQUALS( ZERO, intvector4.Count(), TEST_LOCATION );
128   DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(100), intvector4.Capacity(), TEST_LOCATION );
129   END_TEST;
130 }
131
132 int UtcDaliVectorIntResize(void)
133 {
134   tet_infoline("Testing Dali::Vector<short>::Resize");
135
136   Vector< short > vector;
137   DALI_TEST_EQUALS( ZERO, vector.Count(), TEST_LOCATION );
138   DALI_TEST_EQUALS( ZERO, vector.Capacity(), TEST_LOCATION );
139
140   vector.Resize( 10u );
141   DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(10), vector.Count(), TEST_LOCATION );
142   DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(10), vector.Capacity(), TEST_LOCATION );
143
144   vector.Resize( 4u );
145   DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(4), vector.Count(), TEST_LOCATION );
146   DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(10), vector.Capacity(), TEST_LOCATION );
147
148   vector.Resize( 4u );
149   DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(4), vector.Count(), TEST_LOCATION );
150   DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(10), vector.Capacity(), TEST_LOCATION );
151
152   vector.Resize( 0u );
153   DALI_TEST_EQUALS( ZERO, vector.Count(), TEST_LOCATION );
154   DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(10), vector.Capacity(), TEST_LOCATION );
155
156   vector.Resize( 12u, 123 );
157   DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(12), vector.Count(), TEST_LOCATION );
158   DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(12), vector.Capacity(), TEST_LOCATION );
159
160   DALI_TEST_EQUALS( vector[ 0 ], 123, TEST_LOCATION );
161   DALI_TEST_EQUALS( vector[ 1 ], 123, TEST_LOCATION );
162   DALI_TEST_EQUALS( vector[ 2 ], 123, TEST_LOCATION );
163   DALI_TEST_EQUALS( vector[ 3 ], 123, TEST_LOCATION );
164   DALI_TEST_EQUALS( vector[ 4 ], 123, TEST_LOCATION );
165   DALI_TEST_EQUALS( vector[ 5 ], 123, TEST_LOCATION );
166   DALI_TEST_EQUALS( vector[ 6 ], 123, TEST_LOCATION );
167   DALI_TEST_EQUALS( vector[ 7 ], 123, TEST_LOCATION );
168   DALI_TEST_EQUALS( vector[ 8 ], 123, TEST_LOCATION );
169   DALI_TEST_EQUALS( vector[ 9 ], 123, TEST_LOCATION );
170   DALI_TEST_EQUALS( vector[ 10 ], 123, TEST_LOCATION );
171   DALI_TEST_EQUALS( vector[ 11 ], 123, TEST_LOCATION );
172
173   vector.Resize( 13u, 321 );
174   DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(13), vector.Count(), TEST_LOCATION );
175   DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(13), vector.Capacity(), TEST_LOCATION );
176
177   DALI_TEST_EQUALS( vector[ 0 ], 123, TEST_LOCATION );
178   DALI_TEST_EQUALS( vector[ 1 ], 123, TEST_LOCATION );
179   DALI_TEST_EQUALS( vector[ 2 ], 123, TEST_LOCATION );
180   DALI_TEST_EQUALS( vector[ 3 ], 123, TEST_LOCATION );
181   DALI_TEST_EQUALS( vector[ 4 ], 123, TEST_LOCATION );
182   DALI_TEST_EQUALS( vector[ 5 ], 123, TEST_LOCATION );
183   DALI_TEST_EQUALS( vector[ 6 ], 123, TEST_LOCATION );
184   DALI_TEST_EQUALS( vector[ 7 ], 123, TEST_LOCATION );
185   DALI_TEST_EQUALS( vector[ 8 ], 123, TEST_LOCATION );
186   DALI_TEST_EQUALS( vector[ 9 ], 123, TEST_LOCATION );
187   DALI_TEST_EQUALS( vector[ 10 ], 123, TEST_LOCATION );
188   DALI_TEST_EQUALS( vector[ 11 ], 123, TEST_LOCATION );
189   DALI_TEST_EQUALS( vector[ 12 ], 321, TEST_LOCATION );
190   END_TEST;
191 }
192
193 int UtcDaliVectorIntErase(void)
194 {
195   tet_infoline("Testing Dali::Vector<short>::Erase");
196
197   Vector< char > vector;
198   DALI_TEST_EQUALS( ZERO, vector.Count(), TEST_LOCATION );
199   DALI_TEST_EQUALS( ZERO, vector.Capacity(), TEST_LOCATION );
200   vector.PushBack( 1 );
201   vector.PushBack( 2 );
202   vector.PushBack( 3 );
203   vector.PushBack( 4 );
204   vector.PushBack( 5 );
205   DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(5), vector.Count(), TEST_LOCATION );
206   DALI_TEST_EQUALS( vector[ 0 ], 1, TEST_LOCATION );
207   DALI_TEST_EQUALS( vector[ 1 ], 2, TEST_LOCATION );
208   DALI_TEST_EQUALS( vector[ 2 ], 3, TEST_LOCATION );
209   DALI_TEST_EQUALS( vector[ 3 ], 4, TEST_LOCATION );
210   DALI_TEST_EQUALS( vector[ 4 ], 5, TEST_LOCATION );
211
212   vector.Erase( vector.Begin() );
213   DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(4), vector.Count(), TEST_LOCATION );
214   DALI_TEST_EQUALS( vector[ 0 ], 2, TEST_LOCATION );
215   DALI_TEST_EQUALS( vector[ 1 ], 3, TEST_LOCATION );
216   DALI_TEST_EQUALS( vector[ 2 ], 4, TEST_LOCATION );
217   DALI_TEST_EQUALS( vector[ 3 ], 5, TEST_LOCATION );
218
219   Vector< char >::Iterator ret = vector.Erase( std::find( vector.Begin(), vector.End(), 4 ) );
220   DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(3), vector.Count(), TEST_LOCATION );
221   DALI_TEST_EQUALS( vector[ 0 ], 2, TEST_LOCATION );
222   DALI_TEST_EQUALS( vector[ 1 ], 3, TEST_LOCATION );
223   DALI_TEST_EQUALS( vector[ 2 ], 5, TEST_LOCATION );
224   DALI_TEST_EQUALS( *ret, 5, TEST_LOCATION );
225
226   // try erasing last
227   vector.PushBack( 99 );
228   DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(4), vector.Count(), TEST_LOCATION );
229   DALI_TEST_EQUALS( vector[ 3 ], 99, TEST_LOCATION );
230   ret = vector.Erase( vector.End() - 1 );
231   DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(3), vector.Count(), TEST_LOCATION );
232   DALI_TEST_EQUALS( ret, vector.End(), TEST_LOCATION );
233
234   try
235   {
236     // illegal erase, one past the end
237     vector.Erase( vector.End() );
238     tet_result(TET_FAIL);
239   }
240   catch( Dali::DaliException& e )
241   {
242     tet_printf("Assertion %s test at %s\n", e.mCondition.c_str(), e.mLocation.c_str());
243     DALI_TEST_ASSERT( e, "(iterator < End())", TEST_LOCATION );
244   }
245   catch( ... )
246   {
247     tet_printf("Assertion test failed - wrong Exception\n" );
248     tet_result(TET_FAIL);
249   }
250   DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(3), vector.Count(), TEST_LOCATION );
251   DALI_TEST_EQUALS( vector[ 0 ], 2, TEST_LOCATION );
252   DALI_TEST_EQUALS( vector[ 1 ], 3, TEST_LOCATION );
253   DALI_TEST_EQUALS( vector[ 2 ], 5, TEST_LOCATION );
254
255   vector.Erase( vector.Begin() + 1 );
256   DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(2), vector.Count(), TEST_LOCATION );
257   DALI_TEST_EQUALS( vector[ 0 ], 2, TEST_LOCATION );
258   DALI_TEST_EQUALS( vector[ 1 ], 5, TEST_LOCATION );
259
260   vector.Erase( vector.Begin() + 1 );
261   DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(1), vector.Count(), TEST_LOCATION );
262   DALI_TEST_EQUALS( vector[ 0 ], 2, TEST_LOCATION );
263
264   try
265   {
266     // illegal erase, one past the end
267     vector.Erase( vector.Begin() + 1 );
268     tet_result(TET_FAIL);
269   }
270   catch( Dali::DaliException& e )
271   {
272     tet_printf("Assertion %s test at %s\n", e.mCondition.c_str(), e.mLocation.c_str());
273     DALI_TEST_ASSERT( e, "(iterator < End())", TEST_LOCATION );
274   }
275   catch( ... )
276   {
277     tet_printf("Assertion test failed - wrong Exception\n" );
278     tet_result(TET_FAIL);
279   }
280   DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(1), vector.Count(), TEST_LOCATION );
281   DALI_TEST_EQUALS( vector[ 0 ], 2, TEST_LOCATION );
282
283   vector.Erase( vector.Begin() );
284   DALI_TEST_EQUALS( ZERO, vector.Count(), TEST_LOCATION );
285
286   try
287   {
288     // illegal erase, one before the beginning
289     vector.Erase( vector.Begin() - 1 );
290     tet_result(TET_FAIL);
291   }
292   catch( Dali::DaliException& e )
293   {
294     tet_printf("Assertion %s test at %s\n", e.mCondition.c_str(), e.mLocation.c_str());
295     DALI_TEST_ASSERT( e, "(iterator < End())", TEST_LOCATION );
296   }
297   catch( ... )
298   {
299     tet_printf("Assertion test failed - wrong Exception\n" );
300     tet_result(TET_FAIL);
301   }
302
303   DALI_TEST_EQUALS( ZERO, vector.Count(), TEST_LOCATION );
304   DALI_TEST_EQUALS( vector.Begin(), vector.End(), TEST_LOCATION );
305
306   Vector< char >::Iterator endIter = vector.End();
307   for( Vector< char >::Iterator iter = vector.Begin(); iter != endIter; ++iter )
308   {
309     tet_result(TET_FAIL);
310   }
311
312   vector.PushBack( 3 );
313   DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(1), vector.Count(), TEST_LOCATION );
314
315   vector.Clear();
316   DALI_TEST_EQUALS( ZERO, vector.Count(), TEST_LOCATION );
317   DALI_TEST_EQUALS( vector.Begin(), vector.End(), TEST_LOCATION );
318
319   endIter = vector.End();
320   for( Vector< char >::Iterator iter = vector.Begin(); iter != endIter; ++iter )
321   {
322     tet_result(TET_FAIL);
323   }
324
325   // test a vector of pointers
326   Vector< int* > ptrVector;
327   DALI_TEST_EQUALS( ZERO, ptrVector.Count(), TEST_LOCATION );
328   DALI_TEST_EQUALS( ptrVector.Begin(), ptrVector.End(), TEST_LOCATION );
329
330   int* pointer = NULL;
331   ptrVector.PushBack( pointer );
332   DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(1), ptrVector.Count(), TEST_LOCATION );
333
334   Vector< int* >::Iterator ptriter = std::find( ptrVector.Begin(), ptrVector.End(), pointer );
335   ptriter = ptrVector.Erase( ptriter );
336   DALI_TEST_EQUALS( ZERO, ptrVector.Count(), TEST_LOCATION );
337   DALI_TEST_EQUALS( ptrVector.Begin(), ptrVector.End(), TEST_LOCATION );
338   DALI_TEST_EQUALS( ptrVector.Begin(), ptriter, TEST_LOCATION );
339   END_TEST;
340 }
341
342
343 int UtcDaliVectorDoubleRemove(void)
344 {
345   tet_infoline("Testing Dali::Vector<double>::Remove");
346
347   Vector< double > vector;
348   DALI_TEST_EQUALS( ZERO, vector.Count(), TEST_LOCATION );
349
350   vector.PushBack( 11.1 );
351   vector.PushBack( 22.2 );
352   vector.PushBack( 33.3 );
353   vector.PushBack( 44.4 );
354   DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(4), vector.Count(), TEST_LOCATION );
355   DALI_TEST_EQUALS( vector[ 0 ], 11.1, TEST_LOCATION );
356   DALI_TEST_EQUALS( vector[ 1 ], 22.2, TEST_LOCATION );
357   DALI_TEST_EQUALS( vector[ 2 ], 33.3, TEST_LOCATION );
358   DALI_TEST_EQUALS( vector[ 3 ], 44.4, TEST_LOCATION );
359
360   Vector< double >::Iterator res = std::find( vector.Begin(), vector.End(), 22.2 );
361   DALI_TEST_EQUALS( 22.2, *res, TEST_LOCATION );
362   vector.Remove( res );
363   res = std::find( vector.Begin(), vector.End(), 22.2 );
364   DALI_TEST_EQUALS( vector.End(), res, TEST_LOCATION );
365   DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(3), vector.Count(), TEST_LOCATION );
366   DALI_TEST_EQUALS( vector[ 0 ], 11.1, TEST_LOCATION );
367   DALI_TEST_EQUALS( vector[ 1 ], 44.4, TEST_LOCATION );
368   DALI_TEST_EQUALS( vector[ 2 ], 33.3, TEST_LOCATION );
369
370   vector.Remove( vector.End() - 1 );
371   DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(2), vector.Count(), TEST_LOCATION );
372   DALI_TEST_EQUALS( vector[ 0 ], 11.1, TEST_LOCATION );
373   DALI_TEST_EQUALS( vector[ 1 ], 44.4, TEST_LOCATION );
374
375   vector.Remove( vector.Begin() );
376   DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(1), vector.Count(), TEST_LOCATION );
377   DALI_TEST_EQUALS( vector[ 0 ], 44.4, TEST_LOCATION );
378
379   try
380   {
381     // illegal erase, one past the end
382     vector.Remove( vector.Begin() + 1 );
383     tet_result(TET_FAIL);
384   }
385   catch( Dali::DaliException& e )
386   {
387     tet_printf("Assertion %s test at %s\n", e.mCondition.c_str(), e.mLocation.c_str());
388     DALI_TEST_ASSERT( e, "(iterator < end)", TEST_LOCATION );
389   }
390   catch( ... )
391   {
392     tet_printf("Assertion test failed - wrong Exception\n" );
393     tet_result(TET_FAIL);
394   }
395   DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(1), vector.Count(), TEST_LOCATION );
396   DALI_TEST_EQUALS( vector[ 0 ], 44.4, TEST_LOCATION );
397
398   vector.Remove( vector.Begin() );
399   DALI_TEST_EQUALS( ZERO, vector.Count(), TEST_LOCATION );
400
401   try
402   {
403     // illegal erase, one before the beginning
404     vector.Remove( vector.Begin() - 1 );
405     tet_result(TET_FAIL);
406   }
407   catch( Dali::DaliException& e )
408   {
409     tet_printf("Assertion %s test at %s\n", e.mCondition.c_str(), e.mLocation.c_str());
410     DALI_TEST_ASSERT( e, "(iterator < end) && (iterator >= Begin()", TEST_LOCATION );
411   }
412   catch( ... )
413   {
414     tet_printf("Assertion test failed - wrong Exception\n" );
415     tet_result(TET_FAIL);
416   }
417
418   END_TEST;
419 }
420
421 int UtcDaliVectorIntSwap(void)
422 {
423   tet_infoline("Testing Dali::Vector<int>::Swap");
424
425   Vector< int > intvector;
426   DALI_TEST_EQUALS( ZERO, intvector.Count(), TEST_LOCATION );
427   DALI_TEST_EQUALS( ZERO, intvector.Capacity(), TEST_LOCATION );
428
429   intvector.PushBack( 11 );
430   intvector.PushBack( 22 );
431   intvector.PushBack( 33 );
432   DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(3), intvector.Count(), TEST_LOCATION );
433
434   Vector< int > intvector2;
435   DALI_TEST_EQUALS( ZERO, intvector2.Count(), TEST_LOCATION );
436   DALI_TEST_EQUALS( ZERO, intvector2.Capacity(), TEST_LOCATION );
437
438   intvector2.Swap( intvector );
439   DALI_TEST_EQUALS( ZERO, intvector.Count(), TEST_LOCATION );
440   DALI_TEST_EQUALS( ZERO, intvector.Capacity(), TEST_LOCATION );
441   DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(3), intvector2.Count(), TEST_LOCATION );
442   DALI_TEST_EQUALS( 11, intvector2[ 0 ], TEST_LOCATION );
443   DALI_TEST_EQUALS( 22, intvector2[ 1 ], TEST_LOCATION );
444   DALI_TEST_EQUALS( 33, intvector2[ 2 ], TEST_LOCATION );
445
446   intvector.PushBack( 99 );
447   intvector.PushBack( 88 );
448   DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(2), intvector.Count(), TEST_LOCATION );
449
450   intvector.Swap( intvector2 );
451   DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(2), intvector2.Count(), TEST_LOCATION );
452   DALI_TEST_EQUALS( 99, intvector2[ 0 ], TEST_LOCATION );
453   DALI_TEST_EQUALS( 88, intvector2[ 1 ], TEST_LOCATION );
454   DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(3), intvector.Count(), TEST_LOCATION );
455   DALI_TEST_EQUALS( 11, intvector[ 0 ], TEST_LOCATION );
456   DALI_TEST_EQUALS( 22, intvector[ 1 ], TEST_LOCATION );
457   DALI_TEST_EQUALS( 33, intvector[ 2 ], TEST_LOCATION );
458
459   Vector< int > empty;
460   intvector.Swap( empty );
461   DALI_TEST_EQUALS( ZERO, intvector.Count(), TEST_LOCATION );
462   DALI_TEST_EQUALS( ZERO, intvector.Capacity(), TEST_LOCATION );
463   END_TEST;
464 }
465
466 int UtcDaliVectorIterate(void)
467 {
468   tet_infoline("Testing Dali::Vector<float>::Begin");
469
470   Vector< float > floatvector;
471   DALI_TEST_EQUALS( ZERO, floatvector.Count(), TEST_LOCATION );
472   DALI_TEST_EQUALS( ZERO, floatvector.Capacity(), TEST_LOCATION );
473
474   floatvector.PushBack( 0.9f );
475   floatvector.PushBack( 1.1f );
476   floatvector.PushBack( 1.2f );
477   DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(3), floatvector.Count(), TEST_LOCATION );
478
479   Vector< float >::Iterator iter = floatvector.Begin();
480   int index = 0;
481   for( ; iter != floatvector.End(); ++iter, ++index )
482   {
483     std::cout << "value " << *iter << std::endl;
484     DALI_TEST_EQUALS( *iter, floatvector[ index ], TEST_LOCATION );
485   }
486   DALI_TEST_EQUALS( 3, index, TEST_LOCATION );
487
488   iter = std::find( floatvector.Begin(), floatvector.End(), 1.1f );
489   DALI_TEST_EQUALS( 1.1f, *iter, TEST_LOCATION );
490
491   floatvector.Clear();
492   iter = std::find( floatvector.Begin(), floatvector.End(), 1.1f );
493   DALI_TEST_EQUALS( floatvector.End(), iter, TEST_LOCATION );
494   END_TEST;
495 }
496
497 int UtcDaliVectorPair(void)
498 {
499   tet_infoline("Testing Dali::Vector< std::pair< int, float > >");
500
501   Vector< std::pair< int, float > > pairvector;
502   DALI_TEST_EQUALS( ZERO, pairvector.Count(), TEST_LOCATION );
503   DALI_TEST_EQUALS( ZERO, pairvector.Capacity(), TEST_LOCATION );
504
505   pairvector.PushBack( std::make_pair( 5, 0.1f ) );
506   pairvector.PushBack( std::make_pair( 3, 0.2f ) );
507   pairvector.PushBack( std::make_pair( 4, 0.3f ) );
508   pairvector.PushBack( std::make_pair( 1, 0.4f ) );
509   pairvector.PushBack( std::make_pair( 2, 0.5f ) );
510   DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(5), pairvector.Count(), TEST_LOCATION );
511
512   Vector< std::pair< int, float > >::Iterator iter = pairvector.Begin();
513   int index = 0;
514   for( ; iter != pairvector.End(); ++iter, ++index )
515   {
516     std::cout << "pair " << (*iter).first << ":" << (*iter).second << std::endl;
517     DALI_TEST_EQUALS( (*iter).first, pairvector[ index ].first, TEST_LOCATION );
518     DALI_TEST_EQUALS( (*iter).second, pairvector[ index ].second, TEST_LOCATION );
519   }
520   END_TEST;
521 }
522
523 int UtcDaliVectorAsserts(void)
524 {
525   tet_infoline("Testing Dali::Vector< int* > exception handling");
526
527   // empty vector
528   Vector< int* > pointervector;
529   try
530   {
531     int* value = NULL;
532     pointervector[ 1 ] = value;
533     tet_printf("Assertion expected, but not occurred at %s\n", TEST_LOCATION );
534     tet_result(TET_FAIL);
535   }
536   catch(Dali::DaliException& e)
537   {
538     tet_printf("Assertion %s test at %s\n", e.mCondition.c_str(), e.mLocation.c_str());
539     DALI_TEST_ASSERT( e, "VectorBase::mData", TEST_LOCATION );
540   }
541   catch(...)
542   {
543     tet_printf("Assertion test failed - wrong Exception\n" );
544     tet_result(TET_FAIL);
545   }
546
547   try
548   {
549     int* value = NULL;
550     value = pointervector[ 0 ];
551     (void)value; // to "use" the value
552     tet_printf("Assertion expected, but not occurred at %s\n", TEST_LOCATION );
553     tet_result(TET_FAIL);
554   }
555   catch(Dali::DaliException& e)
556   {
557     tet_printf("Assertion %s test at %s\n", e.mCondition.c_str(), e.mLocation.c_str());
558     DALI_TEST_ASSERT( e, "VectorBase::mData", TEST_LOCATION );
559   }
560   catch(...)
561   {
562     tet_printf("Assertion test failed - wrong Exception\n" );
563     tet_result(TET_FAIL);
564   }
565
566   Vector< int* >::Iterator iter = pointervector.Begin();
567   if( iter != pointervector.End() )
568   {
569     tet_result(TET_FAIL);
570   }
571
572   try
573   {
574     pointervector.Erase( pointervector.Begin() );
575     tet_printf("Assertion expected, but not occurred at %s\n", TEST_LOCATION );
576     tet_result(TET_FAIL);
577   }
578   catch(Dali::DaliException& e)
579   {
580     tet_printf("Assertion %s test at %s\n", e.mCondition.c_str(), e.mLocation.c_str());
581     DALI_TEST_ASSERT( e, "VectorBase::mData", TEST_LOCATION );
582   }
583   catch(...)
584   {
585     tet_printf("Assertion test failed - wrong Exception\n" );
586     tet_result(TET_FAIL);
587   }
588
589   iter = pointervector.Begin();
590   if( iter != pointervector.End() )
591   {
592     tet_result(TET_FAIL);
593   }
594
595   try
596   {
597     pointervector.Remove( pointervector.Begin() );
598     tet_printf("Assertion expected, but not occurred at %s\n", TEST_LOCATION );
599     tet_result(TET_FAIL);
600   }
601   catch(Dali::DaliException& e)
602   {
603     tet_printf("Assertion %s test at %s\n", e.mCondition.c_str(), e.mLocation.c_str());
604     DALI_TEST_ASSERT( e, "VectorBase::mData", TEST_LOCATION );
605   }
606   catch(...)
607   {
608     tet_printf("Assertion test failed - wrong Exception\n" );
609     tet_result(TET_FAIL);
610   }
611
612   iter = pointervector.Begin();
613   if( iter != pointervector.End() )
614   {
615     tet_result(TET_FAIL);
616   }
617
618   // reserve 0 space
619   pointervector.Reserve( 0 );
620   iter = pointervector.Begin();
621   if( iter != pointervector.End() )
622   {
623     tet_result(TET_FAIL);
624   }
625
626   // reserve 1 space
627   pointervector.Reserve( 1 );
628   iter = pointervector.Begin();
629   if( iter != pointervector.End() )
630   {
631     tet_result(TET_FAIL);
632   }
633
634   try
635   {
636     int* value = NULL;
637     pointervector[ 1 ] = value;
638     tet_printf("Assertion expected, but not occurred at %s\n", TEST_LOCATION );
639     tet_result(TET_FAIL);
640   }
641   catch(Dali::DaliException& e)
642   {
643     tet_printf("Assertion %s test at %s\n", e.mCondition.c_str(), e.mLocation.c_str());
644     DALI_TEST_ASSERT( e, "index < VectorBase::Count()", TEST_LOCATION );
645   }
646   catch(...)
647   {
648     tet_printf("Assertion test failed - wrong Exception\n" );
649     tet_result(TET_FAIL);
650   }
651
652   try
653   {
654     int* value = pointervector[ 1 ];
655     (void)value; // to "use" the 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     tet_printf("Assertion %s test at %s\n", e.mCondition.c_str(), e.mLocation.c_str());
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   END_TEST;
671 }
672
673 int UtcDaliVectorAcidTest(void)
674 {
675   tet_infoline("Testing multiple Dali::Vector's");
676
677   // create multiple vectors
678   Vector< std::pair< float, float > > pairvector;
679   DALI_TEST_EQUALS( ZERO, pairvector.Count(), TEST_LOCATION );
680   DALI_TEST_EQUALS( ZERO, pairvector.Capacity(), TEST_LOCATION );
681   Vector< double > doublevector;
682   DALI_TEST_EQUALS( ZERO, doublevector.Count(), TEST_LOCATION );
683   DALI_TEST_EQUALS( ZERO, doublevector.Capacity(), TEST_LOCATION );
684   Vector< int* > intptrvector;
685   DALI_TEST_EQUALS( ZERO, intptrvector.Count(), TEST_LOCATION );
686   DALI_TEST_EQUALS( ZERO, intptrvector.Capacity(), TEST_LOCATION );
687   Vector< Dali::Actor* > actorptrvector;
688   DALI_TEST_EQUALS( ZERO, actorptrvector.Count(), TEST_LOCATION );
689   DALI_TEST_EQUALS( ZERO, actorptrvector.Capacity(), TEST_LOCATION );
690   Vector< long > longvector;
691   DALI_TEST_EQUALS( ZERO, longvector.Count(), TEST_LOCATION );
692   DALI_TEST_EQUALS( ZERO, longvector.Capacity(), TEST_LOCATION );
693   Vector< char > charvector;
694   DALI_TEST_EQUALS( ZERO, charvector.Count(), TEST_LOCATION );
695   DALI_TEST_EQUALS( ZERO, charvector.Capacity(), TEST_LOCATION );
696
697   // add items
698   static unsigned int acidCount = 10000;
699   int* ptr = NULL;
700   for( unsigned int i = 0; i < acidCount; ++i )
701   {
702     ++ptr;
703     pairvector.PushBack( std::make_pair( i, i ) );
704     doublevector.PushBack( (double)i );
705     intptrvector.PushBack( (int*)ptr );
706     actorptrvector.PushBack( (Dali::Actor*)ptr );
707     longvector.PushBack( (long)i );
708     charvector.PushBack( (char)i );
709   }
710   DALI_TEST_EQUALS( acidCount, pairvector.Count(), TEST_LOCATION );
711   std::size_t pairCapacity = pairvector.Capacity();
712   DALI_TEST_EQUALS( acidCount, doublevector.Count(), TEST_LOCATION );
713   std::size_t doubleCapacity = doublevector.Capacity();
714   DALI_TEST_EQUALS( acidCount, intptrvector.Count(), TEST_LOCATION );
715   std::size_t intptrCapacity = intptrvector.Capacity();
716   DALI_TEST_EQUALS( acidCount, actorptrvector.Count(), TEST_LOCATION );
717   std::size_t actorptrCapacity = actorptrvector.Capacity();
718   DALI_TEST_EQUALS( acidCount, longvector.Count(), TEST_LOCATION );
719   std::size_t longCapacity = longvector.Capacity();
720   DALI_TEST_EQUALS( acidCount, charvector.Count(), TEST_LOCATION );
721   std::size_t charCapacity = charvector.Capacity();
722
723   tet_printf("Dali::Vector< pair > capacity after %d pushbacks is %d", acidCount, pairCapacity );
724   tet_printf("Dali::Vector< double > capacity after %d pushbacks is %d", acidCount, doubleCapacity );
725   tet_printf("Dali::Vector< int* > capacity after %d pushbacks is %d", acidCount, intptrCapacity );
726   tet_printf("Dali::Vector< Actor* > capacity after %d pushbacks is %d", acidCount, actorptrCapacity );
727   tet_printf("Dali::Vector< long > capacity after %d pushbacks is %d", acidCount, longCapacity );
728   tet_printf("Dali::Vector< char > capacity after %d pushbacks is %d", acidCount, charCapacity );
729
730   // erase items
731   for( unsigned int i = 0; i < acidCount; ++i )
732   {
733     pairvector.Erase( pairvector.Begin() + ( i % pairvector.Count() ) );
734     doublevector.Erase( doublevector.Begin() + ( i % doublevector.Count() ) );
735     intptrvector.Erase( intptrvector.Begin() + ( i % intptrvector.Count() ) );
736     actorptrvector.Erase( actorptrvector.Begin() + ( i % actorptrvector.Count() ) );
737     longvector.Erase( longvector.Begin() + ( i % longvector.Count() ) );
738     charvector.Erase( charvector.Begin() + ( i % charvector.Count() ) );
739   }
740   DALI_TEST_EQUALS( ZERO, pairvector.Count(), TEST_LOCATION );
741   DALI_TEST_EQUALS( pairCapacity, pairvector.Capacity(), TEST_LOCATION );
742   DALI_TEST_EQUALS( ZERO, doublevector.Count(), TEST_LOCATION );
743   DALI_TEST_EQUALS( doubleCapacity, doublevector.Capacity(), TEST_LOCATION );
744   DALI_TEST_EQUALS( ZERO, intptrvector.Count(), TEST_LOCATION );
745   DALI_TEST_EQUALS( intptrCapacity, intptrvector.Capacity(), TEST_LOCATION );
746   DALI_TEST_EQUALS( ZERO, actorptrvector.Count(), TEST_LOCATION );
747   DALI_TEST_EQUALS( actorptrCapacity, actorptrvector.Capacity(), TEST_LOCATION );
748   DALI_TEST_EQUALS( ZERO, longvector.Count(), TEST_LOCATION );
749   DALI_TEST_EQUALS( longCapacity, longvector.Capacity(), TEST_LOCATION );
750   DALI_TEST_EQUALS( ZERO, charvector.Count(), TEST_LOCATION );
751   DALI_TEST_EQUALS( charCapacity, charvector.Capacity(), TEST_LOCATION );
752
753   END_TEST;
754 }
755
756 namespace
757 {
758
759 bool gConstructorCalled = false;
760 bool gDestructorCalled = false;
761
762 struct ComplexType
763 {
764   ComplexType()
765   {
766     gConstructorCalled = true;
767   }
768   ~ComplexType()
769   {
770     gDestructorCalled = true;
771   }
772 };
773
774 } // anonymous namespace
775
776
777 int UtcDaliVectorComplex(void)
778 {
779   tet_infoline("Testing Dali::Vector< int* > exception handling");
780
781   // this does not compile at the moment
782 /*  Vector< ComplexType > classvector;
783   DALI_TEST_EQUALS( ZERO, classvector.Count(), TEST_LOCATION );
784   DALI_TEST_EQUALS( ZERO, classvector.Capacity(), TEST_LOCATION );
785
786   DALI_TEST_EQUALS( false, gConstructorCalled, TEST_LOCATION );
787   DALI_TEST_EQUALS( false, gDestructorCalled, TEST_LOCATION );
788   classvector.PushBack( ComplexType() );
789   DALI_TEST_EQUALS( true, gConstructorCalled, TEST_LOCATION );
790   classvector.Clear();
791   DALI_TEST_EQUALS( true, gDestructorCalled, TEST_LOCATION );
792 */
793 //  Vector< Actor > classvector; this does not compile yet either
794   tet_result(TET_PASS); // for now
795   END_TEST;
796 }