2 * Copyright (c) 2022 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 #define ENABLE_VECTOR_ASSERTS
20 #include <dali-test-suite-utils.h>
21 #include <dali/public-api/dali-core.h>
30 const Dali::VectorBase::SizeType ZERO(0);
32 /// Compare a short with an int
33 void DALI_TEST_EQUALS(short value1, int value2, const char* location)
35 ::DALI_TEST_EQUALS<short>(value1, static_cast<short>(value2), location);
38 /// Compare a char with an int
39 void DALI_TEST_EQUALS(char value1, int value2, const char* location)
41 ::DALI_TEST_EQUALS<char>(value1, static_cast<char>(value2), location);
44 } // unnamed namespace
46 int UtcDaliEmptyVectorInt(void)
48 tet_infoline("Testing Dali::Vector<int>");
50 Vector<int> intvector;
52 DALI_TEST_EQUALS(ZERO, intvector.Count(), TEST_LOCATION);
53 DALI_TEST_EQUALS(ZERO, intvector.Capacity(), TEST_LOCATION);
56 DALI_TEST_EQUALS(ZERO, intvector.Count(), TEST_LOCATION);
57 DALI_TEST_EQUALS(ZERO, intvector.Capacity(), TEST_LOCATION);
60 DALI_TEST_EQUALS(ZERO, intvector.Count(), TEST_LOCATION);
61 DALI_TEST_EQUALS(ZERO, intvector.Capacity(), TEST_LOCATION);
65 int UtcDaliVectorInt(void)
67 tet_infoline("Testing Dali::Vector<int>");
69 Vector<int> intvector;
71 DALI_TEST_EQUALS(ZERO, intvector.Count(), TEST_LOCATION);
72 DALI_TEST_EQUALS(ZERO, intvector.Capacity(), TEST_LOCATION);
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);
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);
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);
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);
100 int UtcDaliVectorIntCopy(void)
102 tet_infoline("Testing Dali::Vector<int>::Copy");
104 Vector<int> intvector;
105 DALI_TEST_EQUALS(ZERO, intvector.Count(), TEST_LOCATION);
106 DALI_TEST_EQUALS(ZERO, intvector.Capacity(), TEST_LOCATION);
108 intvector.PushBack(99);
109 intvector.PushBack(11);
110 intvector.PushBack(34);
113 Vector<int> intvector2(intvector);
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);
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);
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);
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);
145 int UtcDaliVectorIntResize(void)
147 tet_infoline("Testing Dali::Vector<short>::Resize");
149 Vector<short> vector;
150 DALI_TEST_EQUALS(ZERO, vector.Count(), TEST_LOCATION);
151 DALI_TEST_EQUALS(ZERO, vector.Capacity(), TEST_LOCATION);
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);
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);
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);
166 DALI_TEST_EQUALS(ZERO, vector.Count(), TEST_LOCATION);
167 DALI_TEST_EQUALS(static_cast<Dali::VectorBase::SizeType>(10), vector.Capacity(), TEST_LOCATION);
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);
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);
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);
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);
206 int UtcDaliVectorIntErase(void)
208 tet_infoline("Testing Dali::Vector<short>::Erase");
211 DALI_TEST_EQUALS(ZERO, vector.Count(), TEST_LOCATION);
212 DALI_TEST_EQUALS(ZERO, vector.Capacity(), TEST_LOCATION);
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);
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);
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);
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);
249 // illegal erase, one past the end
250 vector.Erase(vector.End());
251 tet_result(TET_FAIL);
253 catch(Dali::DaliException& e)
255 DALI_TEST_PRINT_ASSERT(e);
256 DALI_TEST_ASSERT(e, "(iterator < End())", TEST_LOCATION);
260 tet_printf("Assertion test failed - wrong Exception\n");
261 tet_result(TET_FAIL);
266 // illegal erase, one before the begin
267 vector.Erase(vector.Begin() - 1u);
268 tet_result(TET_FAIL);
270 catch(Dali::DaliException& e)
272 DALI_TEST_PRINT_ASSERT(e);
273 DALI_TEST_ASSERT(e, "(iterator < End()) && (iterator >= Begin())", TEST_LOCATION);
277 tet_printf("Assertion test failed - wrong Exception\n");
278 tet_result(TET_FAIL);
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);
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);
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);
297 // illegal erase, one past the end
298 vector.Erase(vector.Begin() + 1);
299 tet_result(TET_FAIL);
301 catch(Dali::DaliException& e)
303 DALI_TEST_PRINT_ASSERT(e);
304 DALI_TEST_ASSERT(e, "(iterator < End())", TEST_LOCATION);
308 tet_printf("Assertion test failed - wrong Exception\n");
309 tet_result(TET_FAIL);
311 DALI_TEST_EQUALS(static_cast<Dali::VectorBase::SizeType>(1), vector.Count(), TEST_LOCATION);
312 DALI_TEST_EQUALS(vector[0], 2, TEST_LOCATION);
314 vector.Erase(vector.Begin());
315 DALI_TEST_EQUALS(ZERO, vector.Count(), TEST_LOCATION);
319 // illegal erase, one before the beginning
320 vector.Erase(vector.Begin() - 1);
321 tet_result(TET_FAIL);
323 catch(Dali::DaliException& e)
325 DALI_TEST_PRINT_ASSERT(e);
326 DALI_TEST_ASSERT(e, "(iterator < End())", TEST_LOCATION);
330 tet_printf("Assertion test failed - wrong Exception\n");
331 tet_result(TET_FAIL);
334 DALI_TEST_EQUALS(ZERO, vector.Count(), TEST_LOCATION);
335 DALI_TEST_EQUALS(vector.Begin(), vector.End(), TEST_LOCATION);
337 Vector<char>::Iterator endIter = vector.End();
338 for(Vector<char>::Iterator iter = vector.Begin(); iter != endIter; ++iter)
340 tet_result(TET_FAIL);
344 DALI_TEST_EQUALS(static_cast<Dali::VectorBase::SizeType>(1), vector.Count(), TEST_LOCATION);
347 DALI_TEST_EQUALS(ZERO, vector.Count(), TEST_LOCATION);
348 DALI_TEST_EQUALS(vector.Begin(), vector.End(), TEST_LOCATION);
350 endIter = vector.End();
351 for(Vector<char>::Iterator iter = vector.Begin(); iter != endIter; ++iter)
353 tet_result(TET_FAIL);
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);
362 ptrVector.PushBack(pointer);
363 DALI_TEST_EQUALS(static_cast<Dali::VectorBase::SizeType>(1), ptrVector.Count(), TEST_LOCATION);
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);
373 int UtcDaliVectorDoubleRemove(void)
375 tet_infoline("Testing Dali::Vector<double>::Remove");
377 Vector<double> vector;
378 DALI_TEST_EQUALS(ZERO, vector.Count(), TEST_LOCATION);
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);
390 Vector<double>::Iterator res = std::find(vector.Begin(), vector.End(), 22.2);
391 DALI_TEST_EQUALS(22.2, *res, TEST_LOCATION);
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);
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);
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);
411 // illegal erase, one past the end
412 vector.Remove(vector.Begin() + 1);
413 tet_result(TET_FAIL);
415 catch(Dali::DaliException& e)
417 DALI_TEST_PRINT_ASSERT(e);
418 DALI_TEST_ASSERT(e, "(iterator < End()) && (iterator >= Begin())", TEST_LOCATION);
422 tet_printf("Assertion test failed - wrong Exception\n");
423 tet_result(TET_FAIL);
425 DALI_TEST_EQUALS(static_cast<Dali::VectorBase::SizeType>(1), vector.Count(), TEST_LOCATION);
426 DALI_TEST_EQUALS(vector[0], 44.4, TEST_LOCATION);
428 vector.Remove(vector.Begin());
429 DALI_TEST_EQUALS(ZERO, vector.Count(), TEST_LOCATION);
433 // illegal erase, one before the beginning
434 vector.Remove(vector.Begin() - 1);
435 tet_result(TET_FAIL);
437 catch(Dali::DaliException& e)
439 DALI_TEST_PRINT_ASSERT(e);
440 DALI_TEST_ASSERT(e, "(iterator < End()) && (iterator >= Begin())", TEST_LOCATION);
444 tet_printf("Assertion test failed - wrong Exception\n");
445 tet_result(TET_FAIL);
451 int UtcDaliVectorIntSwap(void)
453 tet_infoline("Testing Dali::Vector<int>::Swap");
455 Vector<int> intvector;
456 DALI_TEST_EQUALS(ZERO, intvector.Count(), TEST_LOCATION);
457 DALI_TEST_EQUALS(ZERO, intvector.Capacity(), TEST_LOCATION);
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);
464 Vector<int> intvector2;
465 DALI_TEST_EQUALS(ZERO, intvector2.Count(), TEST_LOCATION);
466 DALI_TEST_EQUALS(ZERO, intvector2.Capacity(), TEST_LOCATION);
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);
476 intvector.PushBack(99);
477 intvector.PushBack(88);
478 DALI_TEST_EQUALS(static_cast<Dali::VectorBase::SizeType>(2), intvector.Count(), TEST_LOCATION);
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);
490 intvector.Swap(empty);
491 DALI_TEST_EQUALS(ZERO, intvector.Count(), TEST_LOCATION);
492 DALI_TEST_EQUALS(ZERO, intvector.Capacity(), TEST_LOCATION);
496 int UtcDaliVectorIterate(void)
498 tet_infoline("Testing Dali::Vector<float>::Begin");
500 Vector<float> floatvector;
501 DALI_TEST_EQUALS(ZERO, floatvector.Count(), TEST_LOCATION);
502 DALI_TEST_EQUALS(ZERO, floatvector.Capacity(), TEST_LOCATION);
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);
509 Vector<float>::Iterator iter = floatvector.Begin();
511 for(; iter != floatvector.End(); ++iter, ++index)
513 std::cout << "value " << *iter << std::endl;
514 DALI_TEST_EQUALS(*iter, floatvector[index], TEST_LOCATION);
516 DALI_TEST_EQUALS(3, index, TEST_LOCATION);
518 iter = std::find(floatvector.Begin(), floatvector.End(), 1.1f);
519 DALI_TEST_EQUALS(1.1f, *iter, TEST_LOCATION);
522 iter = std::find(floatvector.Begin(), floatvector.End(), 1.1f);
523 DALI_TEST_EQUALS(floatvector.End(), iter, TEST_LOCATION);
527 int UtcDaliVectorPair(void)
529 tet_infoline("Testing Dali::Vector< std::pair< int, float > >");
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);
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);
542 Vector<std::pair<int, float> >::Iterator iter = pairvector.Begin();
544 for(; iter != pairvector.End(); ++iter, ++index)
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);
553 int UtcDaliVectorAsserts(void)
555 tet_infoline("Testing Dali::Vector< int* > exception handling");
558 Vector<int*> pointervector;
562 pointervector[1] = value;
563 tet_printf("Assertion expected, but not occurred at %s\n", TEST_LOCATION);
564 tet_result(TET_FAIL);
566 catch(Dali::DaliException& e)
568 DALI_TEST_PRINT_ASSERT(e);
569 DALI_TEST_ASSERT(e, "VectorBase::mData", TEST_LOCATION);
573 tet_printf("Assertion test failed - wrong Exception\n");
574 tet_result(TET_FAIL);
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);
585 catch(Dali::DaliException& e)
587 DALI_TEST_PRINT_ASSERT(e);
588 DALI_TEST_ASSERT(e, "VectorBase::mData", TEST_LOCATION);
592 tet_printf("Assertion test failed - wrong Exception\n");
593 tet_result(TET_FAIL);
596 Vector<int*>::Iterator iter = pointervector.Begin();
597 if(iter != pointervector.End())
599 tet_result(TET_FAIL);
604 pointervector.Erase(pointervector.Begin());
605 tet_printf("Assertion expected, but not occurred at %s\n", TEST_LOCATION);
606 tet_result(TET_FAIL);
608 catch(Dali::DaliException& e)
610 DALI_TEST_PRINT_ASSERT(e);
611 DALI_TEST_ASSERT(e, "(iterator < End()) && (iterator >= Begin())", TEST_LOCATION);
615 tet_printf("Assertion test failed - wrong Exception\n");
616 tet_result(TET_FAIL);
619 iter = pointervector.Begin();
620 if(iter != pointervector.End())
622 tet_result(TET_FAIL);
627 pointervector.Remove(pointervector.Begin());
628 tet_printf("Assertion expected, but not occurred at %s\n", TEST_LOCATION);
629 tet_result(TET_FAIL);
631 catch(Dali::DaliException& e)
633 DALI_TEST_PRINT_ASSERT(e);
634 DALI_TEST_ASSERT(e, "(iterator < End()) && (iterator >= Begin())", TEST_LOCATION);
638 tet_printf("Assertion test failed - wrong Exception\n");
639 tet_result(TET_FAIL);
642 iter = pointervector.Begin();
643 if(iter != pointervector.End())
645 tet_result(TET_FAIL);
649 pointervector.Reserve(0);
650 iter = pointervector.Begin();
651 if(iter != pointervector.End())
653 tet_result(TET_FAIL);
657 pointervector.Reserve(1);
658 iter = pointervector.Begin();
659 if(iter != pointervector.End())
661 tet_result(TET_FAIL);
667 pointervector[1] = value;
668 tet_printf("Assertion expected, but not occurred at %s\n", TEST_LOCATION);
669 tet_result(TET_FAIL);
671 catch(Dali::DaliException& e)
673 DALI_TEST_PRINT_ASSERT(e);
674 DALI_TEST_ASSERT(e, "index < VectorBase::Count()", TEST_LOCATION);
678 tet_printf("Assertion test failed - wrong Exception\n");
679 tet_result(TET_FAIL);
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);
689 catch(Dali::DaliException& e)
691 DALI_TEST_PRINT_ASSERT(e);
692 DALI_TEST_ASSERT(e, "index < VectorBase::Count()", TEST_LOCATION);
696 tet_printf("Assertion test failed - wrong Exception\n");
697 tet_result(TET_FAIL);
703 int UtcDaliVectorAcidTest(void)
705 tet_infoline("Testing multiple Dali::Vector's");
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);
728 static unsigned int acidCount = 10000;
730 for(unsigned int i = 0; i < acidCount; ++i)
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);
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();
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);
760 for(unsigned int i = 0; i < acidCount; ++i)
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()));
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);
785 int UtcDaliVectorPushBack(void)
787 tet_infoline("Testing Dali::Vector< int* >PushBack(Element)");
789 Vector<unsigned int> vector;
790 DALI_TEST_EQUALS(ZERO, vector.Count(), TEST_LOCATION);
791 DALI_TEST_EQUALS(ZERO, vector.Capacity(), TEST_LOCATION);
794 DALI_TEST_EQUALS(ZERO, vector.Count(), TEST_LOCATION);
795 DALI_TEST_EQUALS(2u, vector.Capacity(), TEST_LOCATION);
801 DALI_TEST_EQUALS(3u, vector.Count(), TEST_LOCATION);
802 DALI_TEST_EQUALS(6u, vector.Capacity(), TEST_LOCATION);
806 DALI_TEST_EQUALS(4u, vector.Count(), TEST_LOCATION);
807 DALI_TEST_EQUALS(6u, vector.Capacity(), TEST_LOCATION);
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);
817 int UtcDaliVectorInsert01(void)
819 tet_infoline("Testing Dali::Vector< int* >Insert(Iterator, Element)");
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)
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);
831 for(unsigned int i = 0u; i < 10u; ++i)
833 DALI_TEST_EQUALS(i, orderedVector[i], TEST_LOCATION);
836 // Test insertion out of range in non-empty array throws:
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);
843 catch(Dali::DaliException& e)
845 DALI_TEST_PRINT_ASSERT(e);
846 DALI_TEST_ASSERT(e, "(at <= End()) && (at >= Begin())", TEST_LOCATION);
850 tet_printf("Assertion test failed - wrong Exception\n");
851 tet_result(TET_FAIL);
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);
860 catch(Dali::DaliException& e)
862 DALI_TEST_PRINT_ASSERT(e);
863 DALI_TEST_ASSERT(e, "(at <= End()) && (at >= Begin())", TEST_LOCATION);
867 tet_printf("Assertion test failed - wrong Exception\n");
868 tet_result(TET_FAIL);
871 // Test insertion part-way through a largish array retains ordering:
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)
879 longerVector.PushBack(i);
881 for(unsigned int i = insertionPoint; i < finalLength; ++i)
883 longerVector.PushBack(i + 1);
886 // Fill the hole in the sequence:
887 longerVector.Insert(longerVector.Begin() + insertionPoint, insertionPoint);
889 // Check the sequence is monotonically increasing by one every time:
890 for(unsigned int i = 0u; i <= finalLength; ++i)
892 DALI_TEST_EQUALS(i, longerVector[i], TEST_LOCATION);
895 // Insert into an empty vector
896 Vector<unsigned int> vector;
898 vector.Insert(vector.End(), orderedVector.Begin(), orderedVector.End());
899 for(unsigned int i = 0u; i < 10u; ++i)
901 DALI_TEST_EQUALS(i, vector[i], TEST_LOCATION);
905 vector.Insert(vector.Begin(), orderedVector.Begin(), orderedVector.End());
906 for(unsigned int i = 0u; i < 10u; ++i)
908 DALI_TEST_EQUALS(i, vector[i], TEST_LOCATION);
912 vector.Insert(vector.Begin(), orderedVector.Begin(), orderedVector.Begin());
913 for(unsigned int i = 0u; i < 10u; ++i)
915 DALI_TEST_EQUALS(i, vector[i], TEST_LOCATION);
918 vector.Insert(vector.Begin() + 5, vector.Begin() + 5, vector.Begin() + 5);
919 for(unsigned int i = 0u; i < 10u; ++i)
921 DALI_TEST_EQUALS(i, vector[i], TEST_LOCATION);
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);
945 int UtcDaliVectorInsert02(void)
947 tet_infoline("Testing Dali::Vector<char>::Insert(Iterator,Iterator,Iterator)");
950 DALI_TEST_EQUALS(ZERO, vector.Count(), TEST_LOCATION);
951 DALI_TEST_EQUALS(ZERO, vector.Capacity(), TEST_LOCATION);
958 Vector<char> vector2;
959 DALI_TEST_EQUALS(ZERO, vector2.Count(), TEST_LOCATION);
960 DALI_TEST_EQUALS(ZERO, vector2.Capacity(), TEST_LOCATION);
965 vector2.PushBack(10);
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);
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);
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);
1003 int UtcDaliVectorIntInsertAssert(void)
1005 tet_infoline("Testing Dali::Vector<char>::Insert(Iterator,Iterator,Iterator) asserts");
1007 Vector<char> vector;
1008 DALI_TEST_EQUALS(ZERO, vector.Count(), TEST_LOCATION);
1009 DALI_TEST_EQUALS(ZERO, vector.Capacity(), TEST_LOCATION);
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);
1024 vector.Insert(vector.Begin() + 3u, vector2.Begin(), vector2.End());
1025 tet_result(TET_FAIL);
1027 catch(Dali::DaliException& e)
1029 DALI_TEST_PRINT_ASSERT(e);
1030 DALI_TEST_ASSERT(e, "(at <= End()) && (at >= Begin())", TEST_LOCATION);
1034 tet_printf("Assertion test failed - wrong Exception\n");
1035 tet_result(TET_FAIL);
1040 vector.Insert(vector.Begin() - 1u, vector2.Begin(), vector2.End());
1041 tet_result(TET_FAIL);
1043 catch(Dali::DaliException& e)
1045 DALI_TEST_PRINT_ASSERT(e);
1046 DALI_TEST_ASSERT(e, "(at <= End()) && (at >= Begin())", TEST_LOCATION);
1050 tet_printf("Assertion test failed - wrong Exception\n");
1051 tet_result(TET_FAIL);
1056 vector.Insert(vector.End(), vector2.End(), vector2.Begin());
1057 tet_result(TET_FAIL);
1059 catch(Dali::DaliException& e)
1061 DALI_TEST_PRINT_ASSERT(e);
1062 DALI_TEST_ASSERT(e, "(from <= to)", TEST_LOCATION);
1066 tet_printf("Assertion test failed - wrong Exception\n");
1067 tet_result(TET_FAIL);
1073 int UtcDaliVectorIntEraseRange(void)
1075 tet_infoline("Testing Dali::Vector<char>::Erase(Iterator,Iterator)");
1077 Vector<char> vector;
1078 DALI_TEST_EQUALS(ZERO, vector.Count(), TEST_LOCATION);
1079 DALI_TEST_EQUALS(ZERO, vector.Capacity(), TEST_LOCATION);
1081 // Try to delete from empty vector.
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);
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);
1099 Vector<char>::Iterator ret;
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);
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);
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);
1125 vector.PushBack(100);
1126 vector.PushBack(101);
1127 vector.PushBack(102);
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);
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);
1139 // try erase from Iterator to the same Iterator.
1140 vector.PushBack(100);
1141 vector.PushBack(101);
1142 vector.PushBack(102);
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);
1149 ret = vector.Erase(vector.Begin() + 1, vector.Begin() + 1);
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);
1156 DALI_TEST_EQUALS(*ret, 101, TEST_LOCATION);
1161 int UtcDaliVectorIntEraseRangeAssert(void)
1163 tet_infoline("Testing Dali::Vector<char>::Erase(Iterator,Iterator) asserts");
1165 Vector<char> vector;
1166 DALI_TEST_EQUALS(ZERO, vector.Count(), TEST_LOCATION);
1167 DALI_TEST_EQUALS(ZERO, vector.Capacity(), TEST_LOCATION);
1169 // Add some elements.
1173 // first out of bounds
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);
1180 catch(Dali::DaliException& e)
1182 DALI_TEST_PRINT_ASSERT(e);
1183 DALI_TEST_ASSERT(e, "(first <= End()) && (first >= Begin())", TEST_LOCATION);
1187 tet_printf("Assertion test failed - wrong Exception\n");
1188 tet_result(TET_FAIL);
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);
1197 catch(Dali::DaliException& e)
1199 DALI_TEST_PRINT_ASSERT(e);
1200 DALI_TEST_ASSERT(e, "(first <= End()) && (first >= Begin())", TEST_LOCATION);
1204 tet_printf("Assertion test failed - wrong Exception\n");
1205 tet_result(TET_FAIL);
1208 // last out of bounds
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);
1216 catch(Dali::DaliException& e)
1218 DALI_TEST_PRINT_ASSERT(e);
1219 DALI_TEST_ASSERT(e, "(last <= End()) && (last >= Begin())", TEST_LOCATION);
1223 tet_printf("Assertion test failed - wrong Exception\n");
1224 tet_result(TET_FAIL);
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);
1233 catch(Dali::DaliException& e)
1235 DALI_TEST_PRINT_ASSERT(e);
1236 DALI_TEST_ASSERT(e, "(last <= End()) && (last >= Begin())", TEST_LOCATION);
1240 tet_printf("Assertion test failed - wrong Exception\n");
1241 tet_result(TET_FAIL);
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);
1253 catch(Dali::DaliException& e)
1255 DALI_TEST_PRINT_ASSERT(e);
1256 DALI_TEST_ASSERT(e, "(first <= last)", TEST_LOCATION);
1260 tet_printf("Assertion test failed - wrong Exception\n");
1261 tet_result(TET_FAIL);
1267 int UtcDaliVectorVector2P(void)
1269 tet_infoline("Testing Dali::Vector< Vector2 >");
1271 Vector<Vector2> classvector;
1272 DALI_TEST_EQUALS(ZERO, classvector.Count(), TEST_LOCATION);
1273 DALI_TEST_EQUALS(ZERO, classvector.Capacity(), TEST_LOCATION);
1275 classvector.PushBack(Vector2());
1277 DALI_TEST_EQUALS(1u, classvector.Count(), TEST_LOCATION);
1278 DALI_TEST_GREATER(classvector.Capacity(), ZERO, TEST_LOCATION);
1280 classvector.PushBack(Vector2(0.1f, 0.2f));
1282 DALI_TEST_EQUALS(2u, classvector.Count(), TEST_LOCATION);
1284 DALI_TEST_EQUALS(Vector2(), classvector[0], TEST_LOCATION);
1285 DALI_TEST_EQUALS(Vector2(0.1f, 0.2f), classvector[1], TEST_LOCATION);
1287 tet_result(TET_PASS); // for now
1291 int UtcDaliVectorVector3P(void)
1293 tet_infoline("Testing Dali::Vector< Vector3 >");
1295 Vector<Vector3> classvector;
1296 DALI_TEST_EQUALS(ZERO, classvector.Count(), TEST_LOCATION);
1297 DALI_TEST_EQUALS(ZERO, classvector.Capacity(), TEST_LOCATION);
1299 classvector.PushBack(Vector3());
1301 DALI_TEST_EQUALS(1u, classvector.Count(), TEST_LOCATION);
1302 DALI_TEST_GREATER(classvector.Capacity(), ZERO, TEST_LOCATION);
1304 classvector.PushBack(Vector3(0.1f, 0.2f, 0.3f));
1306 DALI_TEST_EQUALS(2u, classvector.Count(), TEST_LOCATION);
1308 DALI_TEST_EQUALS(Vector3(), classvector[0], TEST_LOCATION);
1309 DALI_TEST_EQUALS(Vector3(0.1f, 0.2f, 0.3f), classvector[1], TEST_LOCATION);
1311 tet_result(TET_PASS); // for now
1315 int UtcDaliVectorMatrixP(void)
1317 tet_infoline("Testing Dali::Vector< Matrix >");
1319 Vector<Matrix> classvector;
1320 DALI_TEST_EQUALS(ZERO, classvector.Count(), TEST_LOCATION);
1321 DALI_TEST_EQUALS(ZERO, classvector.Capacity(), TEST_LOCATION);
1323 classvector.PushBack(Matrix());
1325 DALI_TEST_EQUALS(1u, classvector.Count(), TEST_LOCATION);
1326 DALI_TEST_GREATER(classvector.Capacity(), ZERO, TEST_LOCATION);
1328 classvector.PushBack(Matrix::IDENTITY);
1330 DALI_TEST_EQUALS(2u, classvector.Count(), TEST_LOCATION);
1332 DALI_TEST_EQUALS(Matrix(), classvector[0], TEST_LOCATION);
1333 DALI_TEST_EQUALS(Matrix::IDENTITY, classvector[1], TEST_LOCATION);
1335 tet_result(TET_PASS); // for now
1339 int UtcDaliVectorCpp11ForP(void)
1341 Vector<Vector3> classvector;
1342 for(auto i : classvector)
1345 tet_result(TET_FAIL);
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));
1352 for(auto i : classvector)
1354 DALI_TEST_EQUALS(Vector3(0.1f, 0.2f, 0.3f), i, TEST_LOCATION);
1360 int UtcDaliVectorMoveConstructor(void)
1362 Vector<Vector3> movedFrom;
1363 movedFrom.PushBack(Vector3::ONE);
1364 movedFrom.PushBack(Vector3::NEGATIVE_YAXIS);
1365 movedFrom.PushBack(Vector3::NEGATIVE_ZAXIS);
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);
1374 int UtcDaliVectorMoveAssignment(void)
1376 Vector<Vector3> movedFrom;
1377 movedFrom.PushBack(Vector3::ONE);
1378 movedFrom.PushBack(Vector3::NEGATIVE_YAXIS);
1379 movedFrom.PushBack(Vector3::NEGATIVE_ZAXIS);
1381 Vector<Vector3> movedTo;
1382 DALI_TEST_EQUALS(movedTo.Size(), 0u, TEST_LOCATION);
1383 DALI_TEST_EQUALS(movedFrom.Size(), 3u, TEST_LOCATION);
1385 movedTo = std::move(movedFrom);
1386 DALI_TEST_EQUALS(movedTo.Size(), 3u, TEST_LOCATION);
1387 DALI_TEST_EQUALS(movedFrom.Size(), 0u, TEST_LOCATION);
1392 int UtcDaliVectorEraseFreeFunction(void)
1394 tet_infoline("Testing Dali::Erase<Vector<int>>");
1398 // erasing from empty vector
1399 Dali::Erase(vector, 2);
1400 DALI_TEST_EQUALS(ZERO, vector.Count(), TEST_LOCATION);
1401 DALI_TEST_EQUALS(ZERO, vector.Capacity(), TEST_LOCATION);
1410 // erase multiple value
1411 Dali::Erase(vector, 3);
1412 DALI_TEST_EQUALS(static_cast<Dali::VectorBase::SizeType>(4), vector.Count(), TEST_LOCATION);
1414 DALI_TEST_EQUALS(vector[0], 1, TEST_LOCATION);
1415 DALI_TEST_EQUALS(vector[1], 2, TEST_LOCATION);
1416 DALI_TEST_EQUALS(vector[2], 4, TEST_LOCATION);
1417 DALI_TEST_EQUALS(vector[3], 5, TEST_LOCATION);
1419 // erase an element present at start
1420 Dali::Erase(vector, 1);
1421 DALI_TEST_EQUALS(static_cast<Dali::VectorBase::SizeType>(3), vector.Count(), TEST_LOCATION);
1422 DALI_TEST_EQUALS(vector[0], 2, TEST_LOCATION);
1423 DALI_TEST_EQUALS(vector[1], 4, TEST_LOCATION);
1424 DALI_TEST_EQUALS(vector[2], 5, TEST_LOCATION);
1426 // erase an element present at end
1427 Dali::Erase(vector, 5);
1428 DALI_TEST_EQUALS(static_cast<Dali::VectorBase::SizeType>(2), vector.Count(), TEST_LOCATION);
1429 DALI_TEST_EQUALS(vector[0], 2, TEST_LOCATION);
1430 DALI_TEST_EQUALS(vector[1], 4, TEST_LOCATION);
1432 // erase an element not present in the vector
1433 Dali::Erase(vector, 42);
1434 DALI_TEST_EQUALS(static_cast<Dali::VectorBase::SizeType>(2), vector.Count(), TEST_LOCATION);
1435 DALI_TEST_EQUALS(vector[0], 2, TEST_LOCATION);
1436 DALI_TEST_EQUALS(vector[1], 4, TEST_LOCATION);
1441 int UtcDaliVectorEraseIfFreeFunction(void)
1443 tet_infoline("Testing Dali::EraseIf<Vector<int>>");
1447 // erasing from empty vector
1448 Dali::EraseIf(vector, [](const auto& value) { return value == 2; });
1449 DALI_TEST_EQUALS(ZERO, vector.Count(), TEST_LOCATION);
1450 DALI_TEST_EQUALS(ZERO, vector.Capacity(), TEST_LOCATION);
1459 // erase multiple value
1460 Dali::EraseIf(vector, [](const auto& value) { return value == 3; });
1461 DALI_TEST_EQUALS(static_cast<Dali::VectorBase::SizeType>(4), vector.Count(), TEST_LOCATION);
1463 DALI_TEST_EQUALS(vector[0], 1, TEST_LOCATION);
1464 DALI_TEST_EQUALS(vector[1], 2, TEST_LOCATION);
1465 DALI_TEST_EQUALS(vector[2], 4, TEST_LOCATION);
1466 DALI_TEST_EQUALS(vector[3], 5, TEST_LOCATION);
1468 // erase an element present at start
1469 Dali::EraseIf(vector, [](const auto& value) { return value == 1; });
1470 DALI_TEST_EQUALS(static_cast<Dali::VectorBase::SizeType>(3), vector.Count(), TEST_LOCATION);
1471 DALI_TEST_EQUALS(vector[0], 2, TEST_LOCATION);
1472 DALI_TEST_EQUALS(vector[1], 4, TEST_LOCATION);
1473 DALI_TEST_EQUALS(vector[2], 5, TEST_LOCATION);
1475 // erase an element present at end
1476 Dali::EraseIf(vector, [](const auto& value) { return value == 5; });
1477 DALI_TEST_EQUALS(static_cast<Dali::VectorBase::SizeType>(2), vector.Count(), TEST_LOCATION);
1478 DALI_TEST_EQUALS(vector[0], 2, TEST_LOCATION);
1479 DALI_TEST_EQUALS(vector[1], 4, TEST_LOCATION);
1481 // erase an element not present in the vector
1482 Dali::EraseIf(vector, [](const auto& value) { return value == 42; });
1483 DALI_TEST_EQUALS(static_cast<Dali::VectorBase::SizeType>(2), vector.Count(), TEST_LOCATION);
1484 DALI_TEST_EQUALS(vector[0], 2, TEST_LOCATION);
1485 DALI_TEST_EQUALS(vector[1], 4, TEST_LOCATION);
1491 * this does not compile at the moment
1492 * Vector< Actor > classvector; this does not compile yet either
1497 bool gConstructorCalled = false;
1498 bool gDestructorCalled = false;
1504 gConstructorCalled = true;
1508 gDestructorCalled = true;
1512 } // anonymous namespace
1514 int UtcDaliVectorComplex( void)
1516 tet_infoline("Testing Dali::Vector< ComplexType > ");
1518 Vector< ComplexType > classvector;
1519 DALI_TEST_EQUALS( ZERO, classvector.Count(), TEST_LOCATION );
1520 DALI_TEST_EQUALS( ZERO, classvector.Capacity(), TEST_LOCATION );
1522 DALI_TEST_EQUALS( false, gConstructorCalled, TEST_LOCATION );
1523 DALI_TEST_EQUALS( false, gDestructorCalled, TEST_LOCATION );
1524 classvector.PushBack( ComplexType() );
1525 DALI_TEST_EQUALS( true, gConstructorCalled, TEST_LOCATION );
1526 classvector.Clear();
1527 DALI_TEST_EQUALS( true, gDestructorCalled, TEST_LOCATION );
1528 tet_result(TET_PASS); // for now