Merge "Include the algorithm header file" into devel/master
[platform/core/uifw/dali-core.git] / automated-tests / src / dali / utc-Dali-Vector.cpp
1 /*
2  * Copyright (c) 2020 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 <dali-test-suite-utils.h>
21 #include <dali/public-api/dali-core.h>
22 #include <stdlib.h>
23
24 #include <iostream>
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   DALI_TEST_EQUALS(static_cast<Dali::VectorBase::SizeType>(3), vector.Count(), TEST_LOCATION);
282   DALI_TEST_EQUALS(vector[0], 2, TEST_LOCATION);
283   DALI_TEST_EQUALS(vector[1], 3, TEST_LOCATION);
284   DALI_TEST_EQUALS(vector[2], 5, TEST_LOCATION);
285
286   vector.Erase(vector.Begin() + 1);
287   DALI_TEST_EQUALS(static_cast<Dali::VectorBase::SizeType>(2), vector.Count(), TEST_LOCATION);
288   DALI_TEST_EQUALS(vector[0], 2, TEST_LOCATION);
289   DALI_TEST_EQUALS(vector[1], 5, TEST_LOCATION);
290
291   vector.Erase(vector.Begin() + 1);
292   DALI_TEST_EQUALS(static_cast<Dali::VectorBase::SizeType>(1), vector.Count(), TEST_LOCATION);
293   DALI_TEST_EQUALS(vector[0], 2, TEST_LOCATION);
294
295   try
296   {
297     // illegal erase, one past the end
298     vector.Erase(vector.Begin() + 1);
299     tet_result(TET_FAIL);
300   }
301   catch(Dali::DaliException& e)
302   {
303     DALI_TEST_PRINT_ASSERT(e);
304     DALI_TEST_ASSERT(e, "(iterator < End())", TEST_LOCATION);
305   }
306   catch(...)
307   {
308     tet_printf("Assertion test failed - wrong Exception\n");
309     tet_result(TET_FAIL);
310   }
311   DALI_TEST_EQUALS(static_cast<Dali::VectorBase::SizeType>(1), vector.Count(), TEST_LOCATION);
312   DALI_TEST_EQUALS(vector[0], 2, TEST_LOCATION);
313
314   vector.Erase(vector.Begin());
315   DALI_TEST_EQUALS(ZERO, vector.Count(), TEST_LOCATION);
316
317   try
318   {
319     // illegal erase, one before the beginning
320     vector.Erase(vector.Begin() - 1);
321     tet_result(TET_FAIL);
322   }
323   catch(Dali::DaliException& e)
324   {
325     DALI_TEST_PRINT_ASSERT(e);
326     DALI_TEST_ASSERT(e, "(iterator < End())", TEST_LOCATION);
327   }
328   catch(...)
329   {
330     tet_printf("Assertion test failed - wrong Exception\n");
331     tet_result(TET_FAIL);
332   }
333
334   DALI_TEST_EQUALS(ZERO, vector.Count(), TEST_LOCATION);
335   DALI_TEST_EQUALS(vector.Begin(), vector.End(), TEST_LOCATION);
336
337   Vector<char>::Iterator endIter = vector.End();
338   for(Vector<char>::Iterator iter = vector.Begin(); iter != endIter; ++iter)
339   {
340     tet_result(TET_FAIL);
341   }
342
343   vector.PushBack(3);
344   DALI_TEST_EQUALS(static_cast<Dali::VectorBase::SizeType>(1), vector.Count(), TEST_LOCATION);
345
346   vector.Clear();
347   DALI_TEST_EQUALS(ZERO, vector.Count(), TEST_LOCATION);
348   DALI_TEST_EQUALS(vector.Begin(), vector.End(), TEST_LOCATION);
349
350   endIter = vector.End();
351   for(Vector<char>::Iterator iter = vector.Begin(); iter != endIter; ++iter)
352   {
353     tet_result(TET_FAIL);
354   }
355
356   // test a vector of pointers
357   Vector<int*> ptrVector;
358   DALI_TEST_EQUALS(ZERO, ptrVector.Count(), TEST_LOCATION);
359   DALI_TEST_EQUALS(ptrVector.Begin(), ptrVector.End(), TEST_LOCATION);
360
361   int* pointer = NULL;
362   ptrVector.PushBack(pointer);
363   DALI_TEST_EQUALS(static_cast<Dali::VectorBase::SizeType>(1), ptrVector.Count(), TEST_LOCATION);
364
365   Vector<int*>::Iterator ptriter = std::find(ptrVector.Begin(), ptrVector.End(), pointer);
366   ptriter                        = ptrVector.Erase(ptriter);
367   DALI_TEST_EQUALS(ZERO, ptrVector.Count(), TEST_LOCATION);
368   DALI_TEST_EQUALS(ptrVector.Begin(), ptrVector.End(), TEST_LOCATION);
369   DALI_TEST_EQUALS(ptrVector.Begin(), ptriter, TEST_LOCATION);
370   END_TEST;
371 }
372
373 int UtcDaliVectorDoubleRemove(void)
374 {
375   tet_infoline("Testing Dali::Vector<double>::Remove");
376
377   Vector<double> vector;
378   DALI_TEST_EQUALS(ZERO, vector.Count(), TEST_LOCATION);
379
380   vector.PushBack(11.1);
381   vector.PushBack(22.2);
382   vector.PushBack(33.3);
383   vector.PushBack(44.4);
384   DALI_TEST_EQUALS(static_cast<Dali::VectorBase::SizeType>(4), vector.Count(), TEST_LOCATION);
385   DALI_TEST_EQUALS(vector[0], 11.1, TEST_LOCATION);
386   DALI_TEST_EQUALS(vector[1], 22.2, TEST_LOCATION);
387   DALI_TEST_EQUALS(vector[2], 33.3, TEST_LOCATION);
388   DALI_TEST_EQUALS(vector[3], 44.4, TEST_LOCATION);
389
390   Vector<double>::Iterator res = std::find(vector.Begin(), vector.End(), 22.2);
391   DALI_TEST_EQUALS(22.2, *res, TEST_LOCATION);
392   vector.Remove(res);
393   res = std::find(vector.Begin(), vector.End(), 22.2);
394   DALI_TEST_EQUALS(vector.End(), res, TEST_LOCATION);
395   DALI_TEST_EQUALS(static_cast<Dali::VectorBase::SizeType>(3), vector.Count(), TEST_LOCATION);
396   DALI_TEST_EQUALS(vector[0], 11.1, TEST_LOCATION);
397   DALI_TEST_EQUALS(vector[1], 44.4, TEST_LOCATION);
398   DALI_TEST_EQUALS(vector[2], 33.3, TEST_LOCATION);
399
400   vector.Remove(vector.End() - 1);
401   DALI_TEST_EQUALS(static_cast<Dali::VectorBase::SizeType>(2), vector.Count(), TEST_LOCATION);
402   DALI_TEST_EQUALS(vector[0], 11.1, TEST_LOCATION);
403   DALI_TEST_EQUALS(vector[1], 44.4, TEST_LOCATION);
404
405   vector.Remove(vector.Begin());
406   DALI_TEST_EQUALS(static_cast<Dali::VectorBase::SizeType>(1), vector.Count(), TEST_LOCATION);
407   DALI_TEST_EQUALS(vector[0], 44.4, TEST_LOCATION);
408
409   try
410   {
411     // illegal erase, one past the end
412     vector.Remove(vector.Begin() + 1);
413     tet_result(TET_FAIL);
414   }
415   catch(Dali::DaliException& e)
416   {
417     DALI_TEST_PRINT_ASSERT(e);
418     DALI_TEST_ASSERT(e, "(iterator < End()) && (iterator >= Begin())", TEST_LOCATION);
419   }
420   catch(...)
421   {
422     tet_printf("Assertion test failed - wrong Exception\n");
423     tet_result(TET_FAIL);
424   }
425   DALI_TEST_EQUALS(static_cast<Dali::VectorBase::SizeType>(1), vector.Count(), TEST_LOCATION);
426   DALI_TEST_EQUALS(vector[0], 44.4, TEST_LOCATION);
427
428   vector.Remove(vector.Begin());
429   DALI_TEST_EQUALS(ZERO, vector.Count(), TEST_LOCATION);
430
431   try
432   {
433     // illegal erase, one before the beginning
434     vector.Remove(vector.Begin() - 1);
435     tet_result(TET_FAIL);
436   }
437   catch(Dali::DaliException& e)
438   {
439     DALI_TEST_PRINT_ASSERT(e);
440     DALI_TEST_ASSERT(e, "(iterator < End()) && (iterator >= Begin())", TEST_LOCATION);
441   }
442   catch(...)
443   {
444     tet_printf("Assertion test failed - wrong Exception\n");
445     tet_result(TET_FAIL);
446   }
447
448   END_TEST;
449 }
450
451 int UtcDaliVectorIntSwap(void)
452 {
453   tet_infoline("Testing Dali::Vector<int>::Swap");
454
455   Vector<int> intvector;
456   DALI_TEST_EQUALS(ZERO, intvector.Count(), TEST_LOCATION);
457   DALI_TEST_EQUALS(ZERO, intvector.Capacity(), TEST_LOCATION);
458
459   intvector.PushBack(11);
460   intvector.PushBack(22);
461   intvector.PushBack(33);
462   DALI_TEST_EQUALS(static_cast<Dali::VectorBase::SizeType>(3), intvector.Count(), TEST_LOCATION);
463
464   Vector<int> intvector2;
465   DALI_TEST_EQUALS(ZERO, intvector2.Count(), TEST_LOCATION);
466   DALI_TEST_EQUALS(ZERO, intvector2.Capacity(), TEST_LOCATION);
467
468   intvector2.Swap(intvector);
469   DALI_TEST_EQUALS(ZERO, intvector.Count(), TEST_LOCATION);
470   DALI_TEST_EQUALS(ZERO, intvector.Capacity(), TEST_LOCATION);
471   DALI_TEST_EQUALS(static_cast<Dali::VectorBase::SizeType>(3), intvector2.Count(), TEST_LOCATION);
472   DALI_TEST_EQUALS(11, intvector2[0], TEST_LOCATION);
473   DALI_TEST_EQUALS(22, intvector2[1], TEST_LOCATION);
474   DALI_TEST_EQUALS(33, intvector2[2], TEST_LOCATION);
475
476   intvector.PushBack(99);
477   intvector.PushBack(88);
478   DALI_TEST_EQUALS(static_cast<Dali::VectorBase::SizeType>(2), intvector.Count(), TEST_LOCATION);
479
480   intvector.Swap(intvector2);
481   DALI_TEST_EQUALS(static_cast<Dali::VectorBase::SizeType>(2), intvector2.Count(), TEST_LOCATION);
482   DALI_TEST_EQUALS(99, intvector2[0], TEST_LOCATION);
483   DALI_TEST_EQUALS(88, intvector2[1], TEST_LOCATION);
484   DALI_TEST_EQUALS(static_cast<Dali::VectorBase::SizeType>(3), intvector.Count(), TEST_LOCATION);
485   DALI_TEST_EQUALS(11, intvector[0], TEST_LOCATION);
486   DALI_TEST_EQUALS(22, intvector[1], TEST_LOCATION);
487   DALI_TEST_EQUALS(33, intvector[2], TEST_LOCATION);
488
489   Vector<int> empty;
490   intvector.Swap(empty);
491   DALI_TEST_EQUALS(ZERO, intvector.Count(), TEST_LOCATION);
492   DALI_TEST_EQUALS(ZERO, intvector.Capacity(), TEST_LOCATION);
493   END_TEST;
494 }
495
496 int UtcDaliVectorIterate(void)
497 {
498   tet_infoline("Testing Dali::Vector<float>::Begin");
499
500   Vector<float> floatvector;
501   DALI_TEST_EQUALS(ZERO, floatvector.Count(), TEST_LOCATION);
502   DALI_TEST_EQUALS(ZERO, floatvector.Capacity(), TEST_LOCATION);
503
504   floatvector.PushBack(0.9f);
505   floatvector.PushBack(1.1f);
506   floatvector.PushBack(1.2f);
507   DALI_TEST_EQUALS(static_cast<Dali::VectorBase::SizeType>(3), floatvector.Count(), TEST_LOCATION);
508
509   Vector<float>::Iterator iter  = floatvector.Begin();
510   int                     index = 0;
511   for(; iter != floatvector.End(); ++iter, ++index)
512   {
513     std::cout << "value " << *iter << std::endl;
514     DALI_TEST_EQUALS(*iter, floatvector[index], TEST_LOCATION);
515   }
516   DALI_TEST_EQUALS(3, index, TEST_LOCATION);
517
518   iter = std::find(floatvector.Begin(), floatvector.End(), 1.1f);
519   DALI_TEST_EQUALS(1.1f, *iter, TEST_LOCATION);
520
521   floatvector.Clear();
522   iter = std::find(floatvector.Begin(), floatvector.End(), 1.1f);
523   DALI_TEST_EQUALS(floatvector.End(), iter, TEST_LOCATION);
524   END_TEST;
525 }
526
527 int UtcDaliVectorPair(void)
528 {
529   tet_infoline("Testing Dali::Vector< std::pair< int, float > >");
530
531   Vector<std::pair<int, float> > pairvector;
532   DALI_TEST_EQUALS(ZERO, pairvector.Count(), TEST_LOCATION);
533   DALI_TEST_EQUALS(ZERO, pairvector.Capacity(), TEST_LOCATION);
534
535   pairvector.PushBack(std::make_pair(5, 0.1f));
536   pairvector.PushBack(std::make_pair(3, 0.2f));
537   pairvector.PushBack(std::make_pair(4, 0.3f));
538   pairvector.PushBack(std::make_pair(1, 0.4f));
539   pairvector.PushBack(std::make_pair(2, 0.5f));
540   DALI_TEST_EQUALS(static_cast<Dali::VectorBase::SizeType>(5), pairvector.Count(), TEST_LOCATION);
541
542   Vector<std::pair<int, float> >::Iterator iter  = pairvector.Begin();
543   int                                      index = 0;
544   for(; iter != pairvector.End(); ++iter, ++index)
545   {
546     std::cout << "pair " << (*iter).first << ":" << (*iter).second << std::endl;
547     DALI_TEST_EQUALS((*iter).first, pairvector[index].first, TEST_LOCATION);
548     DALI_TEST_EQUALS((*iter).second, pairvector[index].second, TEST_LOCATION);
549   }
550   END_TEST;
551 }
552
553 int UtcDaliVectorAsserts(void)
554 {
555   tet_infoline("Testing Dali::Vector< int* > exception handling");
556
557   // empty vector
558   Vector<int*> pointervector;
559   try
560   {
561     int* value       = NULL;
562     pointervector[1] = value;
563     tet_printf("Assertion expected, but not occurred at %s\n", TEST_LOCATION);
564     tet_result(TET_FAIL);
565   }
566   catch(Dali::DaliException& e)
567   {
568     DALI_TEST_PRINT_ASSERT(e);
569     DALI_TEST_ASSERT(e, "VectorBase::mData", TEST_LOCATION);
570   }
571   catch(...)
572   {
573     tet_printf("Assertion test failed - wrong Exception\n");
574     tet_result(TET_FAIL);
575   }
576
577   try
578   {
579     int* value = NULL;
580     value      = pointervector[0];
581     (void)value; // to "use" the value
582     tet_printf("Assertion expected, but not occurred at %s\n", TEST_LOCATION);
583     tet_result(TET_FAIL);
584   }
585   catch(Dali::DaliException& e)
586   {
587     DALI_TEST_PRINT_ASSERT(e);
588     DALI_TEST_ASSERT(e, "VectorBase::mData", TEST_LOCATION);
589   }
590   catch(...)
591   {
592     tet_printf("Assertion test failed - wrong Exception\n");
593     tet_result(TET_FAIL);
594   }
595
596   Vector<int*>::Iterator iter = pointervector.Begin();
597   if(iter != pointervector.End())
598   {
599     tet_result(TET_FAIL);
600   }
601
602   try
603   {
604     pointervector.Erase(pointervector.Begin());
605     tet_printf("Assertion expected, but not occurred at %s\n", TEST_LOCATION);
606     tet_result(TET_FAIL);
607   }
608   catch(Dali::DaliException& e)
609   {
610     DALI_TEST_PRINT_ASSERT(e);
611     DALI_TEST_ASSERT(e, "(iterator < End()) && (iterator >= Begin())", TEST_LOCATION);
612   }
613   catch(...)
614   {
615     tet_printf("Assertion test failed - wrong Exception\n");
616     tet_result(TET_FAIL);
617   }
618
619   iter = pointervector.Begin();
620   if(iter != pointervector.End())
621   {
622     tet_result(TET_FAIL);
623   }
624
625   try
626   {
627     pointervector.Remove(pointervector.Begin());
628     tet_printf("Assertion expected, but not occurred at %s\n", TEST_LOCATION);
629     tet_result(TET_FAIL);
630   }
631   catch(Dali::DaliException& e)
632   {
633     DALI_TEST_PRINT_ASSERT(e);
634     DALI_TEST_ASSERT(e, "(iterator < End()) && (iterator >= Begin())", TEST_LOCATION);
635   }
636   catch(...)
637   {
638     tet_printf("Assertion test failed - wrong Exception\n");
639     tet_result(TET_FAIL);
640   }
641
642   iter = pointervector.Begin();
643   if(iter != pointervector.End())
644   {
645     tet_result(TET_FAIL);
646   }
647
648   // reserve 0 space
649   pointervector.Reserve(0);
650   iter = pointervector.Begin();
651   if(iter != pointervector.End())
652   {
653     tet_result(TET_FAIL);
654   }
655
656   // reserve 1 space
657   pointervector.Reserve(1);
658   iter = pointervector.Begin();
659   if(iter != pointervector.End())
660   {
661     tet_result(TET_FAIL);
662   }
663
664   try
665   {
666     int* value       = NULL;
667     pointervector[1] = value;
668     tet_printf("Assertion expected, but not occurred at %s\n", TEST_LOCATION);
669     tet_result(TET_FAIL);
670   }
671   catch(Dali::DaliException& e)
672   {
673     DALI_TEST_PRINT_ASSERT(e);
674     DALI_TEST_ASSERT(e, "index < VectorBase::Count()", TEST_LOCATION);
675   }
676   catch(...)
677   {
678     tet_printf("Assertion test failed - wrong Exception\n");
679     tet_result(TET_FAIL);
680   }
681
682   try
683   {
684     int* value = pointervector[1];
685     (void)value; // to "use" the value
686     tet_printf("Assertion expected, but not occurred at %s\n", TEST_LOCATION);
687     tet_result(TET_FAIL);
688   }
689   catch(Dali::DaliException& e)
690   {
691     DALI_TEST_PRINT_ASSERT(e);
692     DALI_TEST_ASSERT(e, "index < VectorBase::Count()", TEST_LOCATION);
693   }
694   catch(...)
695   {
696     tet_printf("Assertion test failed - wrong Exception\n");
697     tet_result(TET_FAIL);
698   }
699
700   END_TEST;
701 }
702
703 int UtcDaliVectorAcidTest(void)
704 {
705   tet_infoline("Testing multiple Dali::Vector's");
706
707   // create multiple vectors
708   Vector<std::pair<float, float> > pairvector;
709   DALI_TEST_EQUALS(ZERO, pairvector.Count(), TEST_LOCATION);
710   DALI_TEST_EQUALS(ZERO, pairvector.Capacity(), TEST_LOCATION);
711   Vector<double> doublevector;
712   DALI_TEST_EQUALS(ZERO, doublevector.Count(), TEST_LOCATION);
713   DALI_TEST_EQUALS(ZERO, doublevector.Capacity(), TEST_LOCATION);
714   Vector<int*> intptrvector;
715   DALI_TEST_EQUALS(ZERO, intptrvector.Count(), TEST_LOCATION);
716   DALI_TEST_EQUALS(ZERO, intptrvector.Capacity(), TEST_LOCATION);
717   Vector<Dali::Actor*> actorptrvector;
718   DALI_TEST_EQUALS(ZERO, actorptrvector.Count(), TEST_LOCATION);
719   DALI_TEST_EQUALS(ZERO, actorptrvector.Capacity(), TEST_LOCATION);
720   Vector<long> longvector;
721   DALI_TEST_EQUALS(ZERO, longvector.Count(), TEST_LOCATION);
722   DALI_TEST_EQUALS(ZERO, longvector.Capacity(), TEST_LOCATION);
723   Vector<char> charvector;
724   DALI_TEST_EQUALS(ZERO, charvector.Count(), TEST_LOCATION);
725   DALI_TEST_EQUALS(ZERO, charvector.Capacity(), TEST_LOCATION);
726
727   // add items
728   static unsigned int acidCount = 10000;
729   int*                ptr       = NULL;
730   for(unsigned int i = 0; i < acidCount; ++i)
731   {
732     pairvector.PushBack(std::make_pair(i, i));
733     doublevector.PushBack((double)i);
734     intptrvector.PushBack((int*)ptr);
735     actorptrvector.PushBack((Dali::Actor*)ptr);
736     longvector.PushBack((long)i);
737     charvector.PushBack((char)i);
738   }
739   DALI_TEST_EQUALS(acidCount, pairvector.Count(), TEST_LOCATION);
740   std::size_t pairCapacity = pairvector.Capacity();
741   DALI_TEST_EQUALS(acidCount, doublevector.Count(), TEST_LOCATION);
742   std::size_t doubleCapacity = doublevector.Capacity();
743   DALI_TEST_EQUALS(acidCount, intptrvector.Count(), TEST_LOCATION);
744   std::size_t intptrCapacity = intptrvector.Capacity();
745   DALI_TEST_EQUALS(acidCount, actorptrvector.Count(), TEST_LOCATION);
746   std::size_t actorptrCapacity = actorptrvector.Capacity();
747   DALI_TEST_EQUALS(acidCount, longvector.Count(), TEST_LOCATION);
748   std::size_t longCapacity = longvector.Capacity();
749   DALI_TEST_EQUALS(acidCount, charvector.Count(), TEST_LOCATION);
750   std::size_t charCapacity = charvector.Capacity();
751
752   tet_printf("Dali::Vector< pair > capacity after %d pushbacks is %d", acidCount, pairCapacity);
753   tet_printf("Dali::Vector< double > capacity after %d pushbacks is %d", acidCount, doubleCapacity);
754   tet_printf("Dali::Vector< int* > capacity after %d pushbacks is %d", acidCount, intptrCapacity);
755   tet_printf("Dali::Vector< Actor* > capacity after %d pushbacks is %d", acidCount, actorptrCapacity);
756   tet_printf("Dali::Vector< long > capacity after %d pushbacks is %d", acidCount, longCapacity);
757   tet_printf("Dali::Vector< char > capacity after %d pushbacks is %d", acidCount, charCapacity);
758
759   // erase items
760   for(unsigned int i = 0; i < acidCount; ++i)
761   {
762     pairvector.Erase(pairvector.Begin() + (i % pairvector.Count()));
763     doublevector.Erase(doublevector.Begin() + (i % doublevector.Count()));
764     intptrvector.Erase(intptrvector.Begin() + (i % intptrvector.Count()));
765     actorptrvector.Erase(actorptrvector.Begin() + (i % actorptrvector.Count()));
766     longvector.Erase(longvector.Begin() + (i % longvector.Count()));
767     charvector.Erase(charvector.Begin() + (i % charvector.Count()));
768   }
769   DALI_TEST_EQUALS(ZERO, pairvector.Count(), TEST_LOCATION);
770   DALI_TEST_EQUALS(pairCapacity, pairvector.Capacity(), TEST_LOCATION);
771   DALI_TEST_EQUALS(ZERO, doublevector.Count(), TEST_LOCATION);
772   DALI_TEST_EQUALS(doubleCapacity, doublevector.Capacity(), TEST_LOCATION);
773   DALI_TEST_EQUALS(ZERO, intptrvector.Count(), TEST_LOCATION);
774   DALI_TEST_EQUALS(intptrCapacity, intptrvector.Capacity(), TEST_LOCATION);
775   DALI_TEST_EQUALS(ZERO, actorptrvector.Count(), TEST_LOCATION);
776   DALI_TEST_EQUALS(actorptrCapacity, actorptrvector.Capacity(), TEST_LOCATION);
777   DALI_TEST_EQUALS(ZERO, longvector.Count(), TEST_LOCATION);
778   DALI_TEST_EQUALS(longCapacity, longvector.Capacity(), TEST_LOCATION);
779   DALI_TEST_EQUALS(ZERO, charvector.Count(), TEST_LOCATION);
780   DALI_TEST_EQUALS(charCapacity, charvector.Capacity(), TEST_LOCATION);
781
782   END_TEST;
783 }
784
785 int UtcDaliVectorPushBack(void)
786 {
787   tet_infoline("Testing Dali::Vector< int* >PushBack(Element)");
788
789   Vector<unsigned int> vector;
790   DALI_TEST_EQUALS(ZERO, vector.Count(), TEST_LOCATION);
791   DALI_TEST_EQUALS(ZERO, vector.Capacity(), TEST_LOCATION);
792
793   vector.Reserve(2u);
794   DALI_TEST_EQUALS(ZERO, vector.Count(), TEST_LOCATION);
795   DALI_TEST_EQUALS(2u, vector.Capacity(), TEST_LOCATION);
796
797   vector.PushBack(0u);
798   vector.PushBack(1u);
799   vector.PushBack(2u);
800
801   DALI_TEST_EQUALS(3u, vector.Count(), TEST_LOCATION);
802   DALI_TEST_EQUALS(6u, vector.Capacity(), TEST_LOCATION);
803
804   vector.PushBack(3u);
805
806   DALI_TEST_EQUALS(4u, vector.Count(), TEST_LOCATION);
807   DALI_TEST_EQUALS(6u, vector.Capacity(), TEST_LOCATION);
808
809   DALI_TEST_EQUALS(0u, vector[0u], TEST_LOCATION);
810   DALI_TEST_EQUALS(1u, vector[1u], TEST_LOCATION);
811   DALI_TEST_EQUALS(2u, vector[2u], TEST_LOCATION);
812   DALI_TEST_EQUALS(3u, vector[3u], TEST_LOCATION);
813
814   END_TEST;
815 }
816
817 int UtcDaliVectorInsert01(void)
818 {
819   tet_infoline("Testing Dali::Vector< int* >Insert(Iterator, Element)");
820
821   // Test order of array inserted-into:
822   Vector<unsigned int> orderedVector;
823   orderedVector.PushBack(9u);
824   for(unsigned int i = 8u; i <= 8u; --i)
825   {
826     orderedVector.Insert(orderedVector.Begin(), i);
827     DALI_TEST_EQUALS(10u - i, orderedVector.Count(), TEST_LOCATION);
828     DALI_TEST_EQUALS(i, orderedVector[0u], TEST_LOCATION);
829   }
830
831   for(unsigned int i = 0u; i < 10u; ++i)
832   {
833     DALI_TEST_EQUALS(i, orderedVector[i], TEST_LOCATION);
834   }
835
836   // Test insertion out of range in non-empty array throws:
837   try
838   {
839     orderedVector.Insert(orderedVector.Begin() + 99u, 99u);
840     tet_printf("Assertion expected, but not occurred at %s\n", TEST_LOCATION);
841     tet_result(TET_FAIL);
842   }
843   catch(Dali::DaliException& e)
844   {
845     DALI_TEST_PRINT_ASSERT(e);
846     DALI_TEST_ASSERT(e, "(at <= End()) && (at >= Begin())", TEST_LOCATION);
847   }
848   catch(...)
849   {
850     tet_printf("Assertion test failed - wrong Exception\n");
851     tet_result(TET_FAIL);
852   }
853
854   try
855   {
856     orderedVector.Insert(orderedVector.Begin() - 1u, 99u);
857     tet_printf("Assertion expected, but not occurred at %s\n", TEST_LOCATION);
858     tet_result(TET_FAIL);
859   }
860   catch(Dali::DaliException& e)
861   {
862     DALI_TEST_PRINT_ASSERT(e);
863     DALI_TEST_ASSERT(e, "(at <= End()) && (at >= Begin())", TEST_LOCATION);
864   }
865   catch(...)
866   {
867     tet_printf("Assertion test failed - wrong Exception\n");
868     tet_result(TET_FAIL);
869   }
870
871   // Test insertion part-way through a largish array retains ordering:
872
873   // Build vector with hole in sequence:
874   Vector<unsigned int> longerVector;
875   const unsigned int   insertionPoint = 131571u;
876   const unsigned int   finalLength    = 262143u;
877   for(unsigned int i = 0u; i < insertionPoint; ++i)
878   {
879     longerVector.PushBack(i);
880   }
881   for(unsigned int i = insertionPoint; i < finalLength; ++i)
882   {
883     longerVector.PushBack(i + 1);
884   }
885
886   // Fill the hole in the sequence:
887   longerVector.Insert(longerVector.Begin() + insertionPoint, insertionPoint);
888
889   // Check the sequence is monotonically increasing by one every time:
890   for(unsigned int i = 0u; i <= finalLength; ++i)
891   {
892     DALI_TEST_EQUALS(i, longerVector[i], TEST_LOCATION);
893   }
894
895   // Insert into an empty vector
896   Vector<unsigned int> vector;
897
898   vector.Insert(vector.End(), orderedVector.Begin(), orderedVector.End());
899   for(unsigned int i = 0u; i < 10u; ++i)
900   {
901     DALI_TEST_EQUALS(i, vector[i], TEST_LOCATION);
902   }
903
904   vector.Clear();
905   vector.Insert(vector.Begin(), orderedVector.Begin(), orderedVector.End());
906   for(unsigned int i = 0u; i < 10u; ++i)
907   {
908     DALI_TEST_EQUALS(i, vector[i], TEST_LOCATION);
909   }
910
911   // Insert nothing.
912   vector.Insert(vector.Begin(), orderedVector.Begin(), orderedVector.Begin());
913   for(unsigned int i = 0u; i < 10u; ++i)
914   {
915     DALI_TEST_EQUALS(i, vector[i], TEST_LOCATION);
916   }
917
918   vector.Insert(vector.Begin() + 5, vector.Begin() + 5, vector.Begin() + 5);
919   for(unsigned int i = 0u; i < 10u; ++i)
920   {
921     DALI_TEST_EQUALS(i, vector[i], TEST_LOCATION);
922   }
923
924   // AutoInsert
925   vector.Clear();
926   vector.PushBack(0u);
927   vector.PushBack(1u);
928   vector.PushBack(2u);
929   vector.PushBack(3u);
930
931   vector.Insert(vector.Begin() + 2, vector.Begin(), vector.End());
932   DALI_TEST_EQUALS(8u, vector.Count(), TEST_LOCATION);
933   DALI_TEST_EQUALS(0u, vector[0u], TEST_LOCATION);
934   DALI_TEST_EQUALS(1u, vector[1u], TEST_LOCATION);
935   DALI_TEST_EQUALS(0u, vector[2u], TEST_LOCATION);
936   DALI_TEST_EQUALS(1u, vector[3u], TEST_LOCATION);
937   DALI_TEST_EQUALS(2u, vector[4u], TEST_LOCATION);
938   DALI_TEST_EQUALS(3u, vector[5u], TEST_LOCATION);
939   DALI_TEST_EQUALS(2u, vector[6u], TEST_LOCATION);
940   DALI_TEST_EQUALS(3u, vector[7u], TEST_LOCATION);
941
942   END_TEST;
943 }
944
945 int UtcDaliVectorInsert02(void)
946 {
947   tet_infoline("Testing Dali::Vector<char>::Insert(Iterator,Iterator,Iterator)");
948
949   Vector<char> vector;
950   DALI_TEST_EQUALS(ZERO, vector.Count(), TEST_LOCATION);
951   DALI_TEST_EQUALS(ZERO, vector.Capacity(), TEST_LOCATION);
952   vector.PushBack(1);
953   vector.PushBack(2);
954   vector.PushBack(3);
955   vector.PushBack(4);
956   vector.PushBack(5);
957
958   Vector<char> vector2;
959   DALI_TEST_EQUALS(ZERO, vector2.Count(), TEST_LOCATION);
960   DALI_TEST_EQUALS(ZERO, vector2.Capacity(), TEST_LOCATION);
961   vector2.PushBack(6);
962   vector2.PushBack(7);
963   vector2.PushBack(8);
964   vector2.PushBack(9);
965   vector2.PushBack(10);
966
967   // Test insert at end
968   vector.Insert(vector.End(), vector2.Begin(), vector2.Begin() + 1u);
969   DALI_TEST_EQUALS(static_cast<Dali::VectorBase::SizeType>(6), vector.Count(), TEST_LOCATION);
970   DALI_TEST_EQUALS(vector[0], 1, TEST_LOCATION);
971   DALI_TEST_EQUALS(vector[1], 2, TEST_LOCATION);
972   DALI_TEST_EQUALS(vector[2], 3, TEST_LOCATION);
973   DALI_TEST_EQUALS(vector[3], 4, TEST_LOCATION);
974   DALI_TEST_EQUALS(vector[4], 5, TEST_LOCATION);
975   DALI_TEST_EQUALS(vector[5], 6, TEST_LOCATION);
976
977   // Test insert at begin
978   vector.Insert(vector.Begin(), vector2.Begin() + 1, vector2.Begin() + 2u);
979   DALI_TEST_EQUALS(static_cast<Dali::VectorBase::SizeType>(7), 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], 3, TEST_LOCATION);
984   DALI_TEST_EQUALS(vector[4], 4, TEST_LOCATION);
985   DALI_TEST_EQUALS(vector[5], 5, TEST_LOCATION);
986   DALI_TEST_EQUALS(vector[6], 6, TEST_LOCATION);
987
988   // Test insert in the middle
989   vector.Insert(vector.Begin() + 3, vector2.Begin() + 3, vector2.End());
990   DALI_TEST_EQUALS(static_cast<Dali::VectorBase::SizeType>(9), vector.Count(), TEST_LOCATION);
991   DALI_TEST_EQUALS(vector[0], 7, TEST_LOCATION);
992   DALI_TEST_EQUALS(vector[1], 1, TEST_LOCATION);
993   DALI_TEST_EQUALS(vector[2], 2, TEST_LOCATION);
994   DALI_TEST_EQUALS(vector[3], 9, TEST_LOCATION);
995   DALI_TEST_EQUALS(vector[4], 10, TEST_LOCATION);
996   DALI_TEST_EQUALS(vector[5], 3, TEST_LOCATION);
997   DALI_TEST_EQUALS(vector[6], 4, TEST_LOCATION);
998   DALI_TEST_EQUALS(vector[7], 5, TEST_LOCATION);
999   DALI_TEST_EQUALS(vector[8], 6, TEST_LOCATION);
1000   END_TEST;
1001 }
1002
1003 int UtcDaliVectorIntInsertAssert(void)
1004 {
1005   tet_infoline("Testing Dali::Vector<char>::Insert(Iterator,Iterator,Iterator) asserts");
1006
1007   Vector<char> vector;
1008   DALI_TEST_EQUALS(ZERO, vector.Count(), TEST_LOCATION);
1009   DALI_TEST_EQUALS(ZERO, vector.Capacity(), TEST_LOCATION);
1010   vector.PushBack(1);
1011   vector.PushBack(2);
1012
1013   Vector<char> vector2;
1014   DALI_TEST_EQUALS(ZERO, vector2.Count(), TEST_LOCATION);
1015   DALI_TEST_EQUALS(ZERO, vector2.Capacity(), TEST_LOCATION);
1016   vector2.PushBack(6);
1017   vector2.PushBack(7);
1018   vector2.PushBack(8);
1019   vector2.PushBack(9);
1020   vector2.PushBack(10);
1021
1022   try
1023   {
1024     vector.Insert(vector.Begin() + 3u, vector2.Begin(), vector2.End());
1025     tet_result(TET_FAIL);
1026   }
1027   catch(Dali::DaliException& e)
1028   {
1029     DALI_TEST_PRINT_ASSERT(e);
1030     DALI_TEST_ASSERT(e, "(at <= End()) && (at >= Begin())", TEST_LOCATION);
1031   }
1032   catch(...)
1033   {
1034     tet_printf("Assertion test failed - wrong Exception\n");
1035     tet_result(TET_FAIL);
1036   }
1037
1038   try
1039   {
1040     vector.Insert(vector.Begin() - 1u, vector2.Begin(), vector2.End());
1041     tet_result(TET_FAIL);
1042   }
1043   catch(Dali::DaliException& e)
1044   {
1045     DALI_TEST_PRINT_ASSERT(e);
1046     DALI_TEST_ASSERT(e, "(at <= End()) && (at >= Begin())", TEST_LOCATION);
1047   }
1048   catch(...)
1049   {
1050     tet_printf("Assertion test failed - wrong Exception\n");
1051     tet_result(TET_FAIL);
1052   }
1053
1054   try
1055   {
1056     vector.Insert(vector.End(), vector2.End(), vector2.Begin());
1057     tet_result(TET_FAIL);
1058   }
1059   catch(Dali::DaliException& e)
1060   {
1061     DALI_TEST_PRINT_ASSERT(e);
1062     DALI_TEST_ASSERT(e, "(from <= to)", TEST_LOCATION);
1063   }
1064   catch(...)
1065   {
1066     tet_printf("Assertion test failed - wrong Exception\n");
1067     tet_result(TET_FAIL);
1068   }
1069
1070   END_TEST;
1071 }
1072
1073 int UtcDaliVectorIntEraseRange(void)
1074 {
1075   tet_infoline("Testing Dali::Vector<char>::Erase(Iterator,Iterator)");
1076
1077   Vector<char> vector;
1078   DALI_TEST_EQUALS(ZERO, vector.Count(), TEST_LOCATION);
1079   DALI_TEST_EQUALS(ZERO, vector.Capacity(), TEST_LOCATION);
1080
1081   // Try to delete from empty vector.
1082
1083   vector.Erase(vector.Begin(), vector.End());
1084   DALI_TEST_EQUALS(ZERO, vector.Count(), TEST_LOCATION);
1085   DALI_TEST_EQUALS(ZERO, vector.Capacity(), TEST_LOCATION);
1086
1087   vector.PushBack(1);
1088   vector.PushBack(2);
1089   vector.PushBack(3);
1090   vector.PushBack(4);
1091   vector.PushBack(5);
1092   DALI_TEST_EQUALS(static_cast<Dali::VectorBase::SizeType>(5), vector.Count(), TEST_LOCATION);
1093   DALI_TEST_EQUALS(vector[0], 1, TEST_LOCATION);
1094   DALI_TEST_EQUALS(vector[1], 2, TEST_LOCATION);
1095   DALI_TEST_EQUALS(vector[2], 3, TEST_LOCATION);
1096   DALI_TEST_EQUALS(vector[3], 4, TEST_LOCATION);
1097   DALI_TEST_EQUALS(vector[4], 5, TEST_LOCATION);
1098
1099   Vector<char>::Iterator ret;
1100
1101   ret = vector.Erase(vector.Begin() + 1u, vector.Begin() + 2u);
1102   DALI_TEST_EQUALS(static_cast<Dali::VectorBase::SizeType>(4), vector.Count(), TEST_LOCATION);
1103   DALI_TEST_EQUALS(vector[0], 1, TEST_LOCATION);
1104   DALI_TEST_EQUALS(vector[1], 3, TEST_LOCATION);
1105   DALI_TEST_EQUALS(vector[2], 4, TEST_LOCATION);
1106   DALI_TEST_EQUALS(vector[3], 5, TEST_LOCATION);
1107   DALI_TEST_EQUALS(*ret, 3, TEST_LOCATION);
1108
1109   ret = vector.Erase(vector.Begin(), vector.Begin() + 2);
1110   DALI_TEST_EQUALS(static_cast<Dali::VectorBase::SizeType>(2), vector.Count(), TEST_LOCATION);
1111   DALI_TEST_EQUALS(vector[0], 4, TEST_LOCATION);
1112   DALI_TEST_EQUALS(vector[1], 5, TEST_LOCATION);
1113   DALI_TEST_EQUALS(*ret, 4, TEST_LOCATION);
1114
1115   // try erasing last
1116   vector.PushBack(99);
1117   DALI_TEST_EQUALS(static_cast<Dali::VectorBase::SizeType>(3), vector.Count(), TEST_LOCATION);
1118   DALI_TEST_EQUALS(vector[2], 99, TEST_LOCATION);
1119   ret = vector.Erase(vector.Begin() + 1u, vector.End());
1120   DALI_TEST_EQUALS(static_cast<Dali::VectorBase::SizeType>(1), vector.Count(), TEST_LOCATION);
1121   DALI_TEST_EQUALS(vector[0], 4, TEST_LOCATION);
1122   DALI_TEST_EQUALS(ret, vector.End(), TEST_LOCATION);
1123
1124   // try erasing all
1125   vector.PushBack(100);
1126   vector.PushBack(101);
1127   vector.PushBack(102);
1128
1129   DALI_TEST_EQUALS(static_cast<Dali::VectorBase::SizeType>(4), vector.Count(), TEST_LOCATION);
1130   DALI_TEST_EQUALS(vector[0], 4, TEST_LOCATION);
1131   DALI_TEST_EQUALS(vector[1], 100, TEST_LOCATION);
1132   DALI_TEST_EQUALS(vector[2], 101, TEST_LOCATION);
1133   DALI_TEST_EQUALS(vector[3], 102, TEST_LOCATION);
1134
1135   ret = vector.Erase(vector.Begin(), vector.End());
1136   DALI_TEST_EQUALS(static_cast<Dali::VectorBase::SizeType>(0), vector.Count(), TEST_LOCATION);
1137   DALI_TEST_EQUALS(ret, vector.End(), TEST_LOCATION);
1138
1139   // try erase from Iterator to the same Iterator.
1140   vector.PushBack(100);
1141   vector.PushBack(101);
1142   vector.PushBack(102);
1143
1144   DALI_TEST_EQUALS(static_cast<Dali::VectorBase::SizeType>(3), vector.Count(), TEST_LOCATION);
1145   DALI_TEST_EQUALS(vector[0], 100, TEST_LOCATION);
1146   DALI_TEST_EQUALS(vector[1], 101, TEST_LOCATION);
1147   DALI_TEST_EQUALS(vector[2], 102, TEST_LOCATION);
1148
1149   ret = vector.Erase(vector.Begin() + 1, vector.Begin() + 1);
1150
1151   DALI_TEST_EQUALS(static_cast<Dali::VectorBase::SizeType>(3), vector.Count(), TEST_LOCATION);
1152   DALI_TEST_EQUALS(vector[0], 100, TEST_LOCATION);
1153   DALI_TEST_EQUALS(vector[1], 101, TEST_LOCATION);
1154   DALI_TEST_EQUALS(vector[2], 102, TEST_LOCATION);
1155
1156   DALI_TEST_EQUALS(*ret, 101, TEST_LOCATION);
1157
1158   END_TEST;
1159 }
1160
1161 int UtcDaliVectorIntEraseRangeAssert(void)
1162 {
1163   tet_infoline("Testing Dali::Vector<char>::Erase(Iterator,Iterator) asserts");
1164
1165   Vector<char> vector;
1166   DALI_TEST_EQUALS(ZERO, vector.Count(), TEST_LOCATION);
1167   DALI_TEST_EQUALS(ZERO, vector.Capacity(), TEST_LOCATION);
1168
1169   // Add some elements.
1170   vector.PushBack(1);
1171   vector.PushBack(2);
1172
1173   // first out of bounds
1174   try
1175   {
1176     vector.Erase(vector.Begin() + 3u, vector.Begin() + 4u);
1177     tet_printf("Assertion expected, but not occurred at %s\n", TEST_LOCATION);
1178     tet_result(TET_FAIL);
1179   }
1180   catch(Dali::DaliException& e)
1181   {
1182     DALI_TEST_PRINT_ASSERT(e);
1183     DALI_TEST_ASSERT(e, "(first <= End()) && (first >= Begin())", TEST_LOCATION);
1184   }
1185   catch(...)
1186   {
1187     tet_printf("Assertion test failed - wrong Exception\n");
1188     tet_result(TET_FAIL);
1189   }
1190
1191   try
1192   {
1193     vector.Erase(vector.Begin() - 1u, vector.End());
1194     tet_printf("Assertion expected, but not occurred at %s\n", TEST_LOCATION);
1195     tet_result(TET_FAIL);
1196   }
1197   catch(Dali::DaliException& e)
1198   {
1199     DALI_TEST_PRINT_ASSERT(e);
1200     DALI_TEST_ASSERT(e, "(first <= End()) && (first >= Begin())", TEST_LOCATION);
1201   }
1202   catch(...)
1203   {
1204     tet_printf("Assertion test failed - wrong Exception\n");
1205     tet_result(TET_FAIL);
1206   }
1207
1208   // last out of bounds
1209
1210   try
1211   {
1212     vector.Erase(vector.Begin(), vector.Begin() + 3u);
1213     tet_printf("Assertion expected, but not occurred at %s\n", TEST_LOCATION);
1214     tet_result(TET_FAIL);
1215   }
1216   catch(Dali::DaliException& e)
1217   {
1218     DALI_TEST_PRINT_ASSERT(e);
1219     DALI_TEST_ASSERT(e, "(last <= End()) && (last >= Begin())", TEST_LOCATION);
1220   }
1221   catch(...)
1222   {
1223     tet_printf("Assertion test failed - wrong Exception\n");
1224     tet_result(TET_FAIL);
1225   }
1226
1227   try
1228   {
1229     vector.Erase(vector.Begin(), vector.Begin() - 1u);
1230     tet_printf("Assertion expected, but not occurred at %s\n", TEST_LOCATION);
1231     tet_result(TET_FAIL);
1232   }
1233   catch(Dali::DaliException& e)
1234   {
1235     DALI_TEST_PRINT_ASSERT(e);
1236     DALI_TEST_ASSERT(e, "(last <= End()) && (last >= Begin())", TEST_LOCATION);
1237   }
1238   catch(...)
1239   {
1240     tet_printf("Assertion test failed - wrong Exception\n");
1241     tet_result(TET_FAIL);
1242   }
1243
1244   vector.PushBack(3);
1245
1246   // first > last
1247   try
1248   {
1249     vector.Erase(vector.Begin() + 2u, vector.Begin() + 1u);
1250     tet_printf("Assertion expected, but not occurred at %s\n", TEST_LOCATION);
1251     tet_result(TET_FAIL);
1252   }
1253   catch(Dali::DaliException& e)
1254   {
1255     DALI_TEST_PRINT_ASSERT(e);
1256     DALI_TEST_ASSERT(e, "(first <= last)", TEST_LOCATION);
1257   }
1258   catch(...)
1259   {
1260     tet_printf("Assertion test failed - wrong Exception\n");
1261     tet_result(TET_FAIL);
1262   }
1263
1264   END_TEST;
1265 }
1266
1267 int UtcDaliVectorVector2P(void)
1268 {
1269   tet_infoline("Testing Dali::Vector< Vector2 >");
1270
1271   Vector<Vector2> classvector;
1272   DALI_TEST_EQUALS(ZERO, classvector.Count(), TEST_LOCATION);
1273   DALI_TEST_EQUALS(ZERO, classvector.Capacity(), TEST_LOCATION);
1274
1275   classvector.PushBack(Vector2());
1276
1277   DALI_TEST_EQUALS(1u, classvector.Count(), TEST_LOCATION);
1278   DALI_TEST_GREATER(classvector.Capacity(), ZERO, TEST_LOCATION);
1279
1280   classvector.PushBack(Vector2(0.1f, 0.2f));
1281
1282   DALI_TEST_EQUALS(2u, classvector.Count(), TEST_LOCATION);
1283
1284   DALI_TEST_EQUALS(Vector2(), classvector[0], TEST_LOCATION);
1285   DALI_TEST_EQUALS(Vector2(0.1f, 0.2f), classvector[1], TEST_LOCATION);
1286
1287   tet_result(TET_PASS); // for now
1288   END_TEST;
1289 }
1290
1291 int UtcDaliVectorVector3P(void)
1292 {
1293   tet_infoline("Testing Dali::Vector< Vector3 >");
1294
1295   Vector<Vector3> classvector;
1296   DALI_TEST_EQUALS(ZERO, classvector.Count(), TEST_LOCATION);
1297   DALI_TEST_EQUALS(ZERO, classvector.Capacity(), TEST_LOCATION);
1298
1299   classvector.PushBack(Vector3());
1300
1301   DALI_TEST_EQUALS(1u, classvector.Count(), TEST_LOCATION);
1302   DALI_TEST_GREATER(classvector.Capacity(), ZERO, TEST_LOCATION);
1303
1304   classvector.PushBack(Vector3(0.1f, 0.2f, 0.3f));
1305
1306   DALI_TEST_EQUALS(2u, classvector.Count(), TEST_LOCATION);
1307
1308   DALI_TEST_EQUALS(Vector3(), classvector[0], TEST_LOCATION);
1309   DALI_TEST_EQUALS(Vector3(0.1f, 0.2f, 0.3f), classvector[1], TEST_LOCATION);
1310
1311   tet_result(TET_PASS); // for now
1312   END_TEST;
1313 }
1314
1315 int UtcDaliVectorMatrixP(void)
1316 {
1317   tet_infoline("Testing Dali::Vector< Matrix >");
1318
1319   Vector<Matrix> classvector;
1320   DALI_TEST_EQUALS(ZERO, classvector.Count(), TEST_LOCATION);
1321   DALI_TEST_EQUALS(ZERO, classvector.Capacity(), TEST_LOCATION);
1322
1323   classvector.PushBack(Matrix());
1324
1325   DALI_TEST_EQUALS(1u, classvector.Count(), TEST_LOCATION);
1326   DALI_TEST_GREATER(classvector.Capacity(), ZERO, TEST_LOCATION);
1327
1328   classvector.PushBack(Matrix::IDENTITY);
1329
1330   DALI_TEST_EQUALS(2u, classvector.Count(), TEST_LOCATION);
1331
1332   DALI_TEST_EQUALS(Matrix(), classvector[0], TEST_LOCATION);
1333   DALI_TEST_EQUALS(Matrix::IDENTITY, classvector[1], TEST_LOCATION);
1334
1335   tet_result(TET_PASS); // for now
1336   END_TEST;
1337 }
1338
1339 int UtcDaliVectorCpp11ForP(void)
1340 {
1341   Vector<Vector3> classvector;
1342   for(auto i : classvector)
1343   {
1344     std::ignore = i;
1345     tet_result(TET_FAIL);
1346   }
1347
1348   classvector.PushBack(Vector3(0.1f, 0.2f, 0.3f));
1349   classvector.PushBack(Vector3(0.1f, 0.2f, 0.3f));
1350   classvector.PushBack(Vector3(0.1f, 0.2f, 0.3f));
1351
1352   for(auto i : classvector)
1353   {
1354     DALI_TEST_EQUALS(Vector3(0.1f, 0.2f, 0.3f), i, TEST_LOCATION);
1355   }
1356
1357   END_TEST;
1358 }
1359
1360 int UtcDaliVectorMoveConstructor(void)
1361 {
1362   Vector<Vector3> movedFrom;
1363   movedFrom.PushBack(Vector3::ONE);
1364   movedFrom.PushBack(Vector3::NEGATIVE_YAXIS);
1365   movedFrom.PushBack(Vector3::NEGATIVE_ZAXIS);
1366
1367   Vector<Vector3> movedTo(std::move(movedFrom));
1368   DALI_TEST_EQUALS(movedTo.Size(), 3u, TEST_LOCATION);
1369   DALI_TEST_EQUALS(movedFrom.Size(), 0u, TEST_LOCATION);
1370
1371   END_TEST;
1372 }
1373
1374 int UtcDaliVectorMoveAssignment(void)
1375 {
1376   Vector<Vector3> movedFrom;
1377   movedFrom.PushBack(Vector3::ONE);
1378   movedFrom.PushBack(Vector3::NEGATIVE_YAXIS);
1379   movedFrom.PushBack(Vector3::NEGATIVE_ZAXIS);
1380
1381   Vector<Vector3> movedTo;
1382   DALI_TEST_EQUALS(movedTo.Size(), 0u, TEST_LOCATION);
1383   DALI_TEST_EQUALS(movedFrom.Size(), 3u, TEST_LOCATION);
1384
1385   movedTo = std::move(movedFrom);
1386   DALI_TEST_EQUALS(movedTo.Size(), 3u, TEST_LOCATION);
1387   DALI_TEST_EQUALS(movedFrom.Size(), 0u, TEST_LOCATION);
1388
1389   END_TEST;
1390 }
1391
1392 /*
1393  * this does not compile at the moment
1394  * Vector< Actor > classvector; this does not compile yet either
1395  *
1396 namespace
1397 {
1398
1399 bool gConstructorCalled = false;
1400 bool gDestructorCalled = false;
1401
1402 struct ComplexType
1403 {
1404   ComplexType()
1405   {
1406     gConstructorCalled = true;
1407   }
1408   ~ComplexType()
1409   {
1410     gDestructorCalled = true;
1411   }
1412 };
1413
1414 } // anonymous namespace
1415
1416 int UtcDaliVectorComplex( void)
1417 {
1418   tet_infoline("Testing Dali::Vector< ComplexType > ");
1419
1420   Vector< ComplexType > classvector;
1421   DALI_TEST_EQUALS( ZERO, classvector.Count(), TEST_LOCATION );
1422   DALI_TEST_EQUALS( ZERO, classvector.Capacity(), TEST_LOCATION );
1423
1424   DALI_TEST_EQUALS( false, gConstructorCalled, TEST_LOCATION );
1425   DALI_TEST_EQUALS( false, gDestructorCalled, TEST_LOCATION );
1426   classvector.PushBack( ComplexType() );
1427   DALI_TEST_EQUALS( true, gConstructorCalled, TEST_LOCATION );
1428   classvector.Clear();
1429   DALI_TEST_EQUALS( true, gDestructorCalled, TEST_LOCATION );
1430   tet_result(TET_PASS); // for now
1431   END_TEST;
1432 }
1433 */