2 * Copyright (c) 2021 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 #include <dali-test-suite-utils.h>
19 #include <dali/public-api/dali-core.h>
28 const Dali::VectorBase::SizeType ZERO(0);
30 /// Compare a short with an int
31 void DALI_TEST_EQUALS(short value1, int value2, const char* location)
33 ::DALI_TEST_EQUALS<short>(value1, static_cast<short>(value2), location);
36 /// Compare a char with an int
37 void DALI_TEST_EQUALS(char value1, int value2, const char* location)
39 ::DALI_TEST_EQUALS<char>(value1, static_cast<char>(value2), location);
42 } // unnamed namespace
44 int UtcDaliEmptyVectorInt(void)
46 tet_infoline("Testing Dali::Vector<int>");
48 Vector<int> intvector;
50 DALI_TEST_EQUALS(ZERO, intvector.Count(), TEST_LOCATION);
51 DALI_TEST_EQUALS(ZERO, intvector.Capacity(), TEST_LOCATION);
54 DALI_TEST_EQUALS(ZERO, intvector.Count(), TEST_LOCATION);
55 DALI_TEST_EQUALS(ZERO, intvector.Capacity(), TEST_LOCATION);
58 DALI_TEST_EQUALS(ZERO, intvector.Count(), TEST_LOCATION);
59 DALI_TEST_EQUALS(ZERO, intvector.Capacity(), TEST_LOCATION);
63 int UtcDaliVectorInt(void)
65 tet_infoline("Testing Dali::Vector<int>");
67 Vector<int> intvector;
69 DALI_TEST_EQUALS(ZERO, intvector.Count(), TEST_LOCATION);
70 DALI_TEST_EQUALS(ZERO, intvector.Capacity(), TEST_LOCATION);
72 intvector.PushBack(11);
73 DALI_TEST_EQUALS(static_cast<Dali::VectorBase::SizeType>(1), intvector.Count(), TEST_LOCATION);
74 DALI_TEST_EQUALS(static_cast<Dali::VectorBase::SizeType>(2), intvector.Capacity(), TEST_LOCATION);
75 DALI_TEST_EQUALS(11, intvector[0], TEST_LOCATION);
77 intvector.PushBack(99);
78 DALI_TEST_EQUALS(static_cast<Dali::VectorBase::SizeType>(2), intvector.Count(), TEST_LOCATION);
79 DALI_TEST_EQUALS(static_cast<Dali::VectorBase::SizeType>(2), intvector.Capacity(), TEST_LOCATION);
80 DALI_TEST_EQUALS(99, intvector[1], TEST_LOCATION);
82 intvector.PushBack(34);
83 DALI_TEST_EQUALS(static_cast<Dali::VectorBase::SizeType>(3), intvector.Count(), TEST_LOCATION);
84 DALI_TEST_EQUALS(static_cast<Dali::VectorBase::SizeType>(6), intvector.Capacity(), TEST_LOCATION);
85 DALI_TEST_EQUALS(11, intvector[0], TEST_LOCATION);
86 DALI_TEST_EQUALS(99, intvector[1], TEST_LOCATION);
87 DALI_TEST_EQUALS(34, intvector[2], TEST_LOCATION);
90 DALI_TEST_EQUALS(ZERO, intvector.Count(), TEST_LOCATION);
91 DALI_TEST_EQUALS(static_cast<Dali::VectorBase::SizeType>(6), intvector.Capacity(), TEST_LOCATION);
92 intvector.PushBack(123);
93 DALI_TEST_EQUALS(static_cast<Dali::VectorBase::SizeType>(1), intvector.Count(), TEST_LOCATION);
94 DALI_TEST_EQUALS(123, intvector[0], TEST_LOCATION);
98 int UtcDaliVectorIntCopy(void)
100 tet_infoline("Testing Dali::Vector<int>::Copy");
102 Vector<int> intvector;
103 DALI_TEST_EQUALS(ZERO, intvector.Count(), TEST_LOCATION);
104 DALI_TEST_EQUALS(ZERO, intvector.Capacity(), TEST_LOCATION);
106 intvector.PushBack(99);
107 intvector.PushBack(11);
108 intvector.PushBack(34);
111 Vector<int> intvector2(intvector);
113 DALI_TEST_EQUALS(intvector2.Count(), intvector.Count(), TEST_LOCATION);
114 DALI_TEST_EQUALS(intvector2.Capacity(), intvector.Capacity(), TEST_LOCATION);
115 DALI_TEST_EQUALS(intvector2[0], intvector[0], TEST_LOCATION);
116 DALI_TEST_EQUALS(intvector2[1], intvector[1], TEST_LOCATION);
117 DALI_TEST_EQUALS(intvector2[2], intvector[2], TEST_LOCATION);
120 Vector<int> intvector3;
121 DALI_TEST_EQUALS(ZERO, intvector3.Count(), TEST_LOCATION);
122 DALI_TEST_EQUALS(ZERO, intvector3.Capacity(), TEST_LOCATION);
123 intvector2 = intvector3;
124 DALI_TEST_EQUALS(intvector2.Count(), intvector3.Count(), TEST_LOCATION);
125 DALI_TEST_EQUALS(intvector2.Capacity(), intvector3.Capacity(), TEST_LOCATION);
128 Vector<int> intvector4;
129 intvector4.Reserve(100);
130 DALI_TEST_EQUALS(ZERO, intvector4.Count(), TEST_LOCATION);
131 DALI_TEST_EQUALS(static_cast<Dali::VectorBase::SizeType>(100), intvector4.Capacity(), TEST_LOCATION);
132 intvector3 = intvector4;
133 DALI_TEST_EQUALS(ZERO, intvector3.Count(), TEST_LOCATION);
134 DALI_TEST_EQUALS(static_cast<Dali::VectorBase::SizeType>(100), intvector3.Capacity(), TEST_LOCATION);
137 intvector4 = intvector4;
138 DALI_TEST_EQUALS(ZERO, intvector4.Count(), TEST_LOCATION);
139 DALI_TEST_EQUALS(static_cast<Dali::VectorBase::SizeType>(100), intvector4.Capacity(), TEST_LOCATION);
143 int UtcDaliVectorIntResize(void)
145 tet_infoline("Testing Dali::Vector<short>::Resize");
147 Vector<short> vector;
148 DALI_TEST_EQUALS(ZERO, vector.Count(), TEST_LOCATION);
149 DALI_TEST_EQUALS(ZERO, vector.Capacity(), TEST_LOCATION);
152 DALI_TEST_EQUALS(static_cast<Dali::VectorBase::SizeType>(10), vector.Count(), TEST_LOCATION);
153 DALI_TEST_EQUALS(static_cast<Dali::VectorBase::SizeType>(10), vector.Capacity(), TEST_LOCATION);
156 DALI_TEST_EQUALS(static_cast<Dali::VectorBase::SizeType>(4), vector.Count(), TEST_LOCATION);
157 DALI_TEST_EQUALS(static_cast<Dali::VectorBase::SizeType>(10), vector.Capacity(), TEST_LOCATION);
160 DALI_TEST_EQUALS(static_cast<Dali::VectorBase::SizeType>(4), vector.Count(), TEST_LOCATION);
161 DALI_TEST_EQUALS(static_cast<Dali::VectorBase::SizeType>(10), vector.Capacity(), TEST_LOCATION);
164 DALI_TEST_EQUALS(ZERO, vector.Count(), TEST_LOCATION);
165 DALI_TEST_EQUALS(static_cast<Dali::VectorBase::SizeType>(10), vector.Capacity(), TEST_LOCATION);
167 vector.Resize(12u, 123);
168 DALI_TEST_EQUALS(static_cast<Dali::VectorBase::SizeType>(12), vector.Count(), TEST_LOCATION);
169 DALI_TEST_EQUALS(static_cast<Dali::VectorBase::SizeType>(12), vector.Capacity(), TEST_LOCATION);
171 DALI_TEST_EQUALS(vector[0], 123, TEST_LOCATION);
172 DALI_TEST_EQUALS(vector[1], 123, TEST_LOCATION);
173 DALI_TEST_EQUALS(vector[2], 123, TEST_LOCATION);
174 DALI_TEST_EQUALS(vector[3], 123, TEST_LOCATION);
175 DALI_TEST_EQUALS(vector[4], 123, TEST_LOCATION);
176 DALI_TEST_EQUALS(vector[5], 123, TEST_LOCATION);
177 DALI_TEST_EQUALS(vector[6], 123, TEST_LOCATION);
178 DALI_TEST_EQUALS(vector[7], 123, TEST_LOCATION);
179 DALI_TEST_EQUALS(vector[8], 123, TEST_LOCATION);
180 DALI_TEST_EQUALS(vector[9], 123, TEST_LOCATION);
181 DALI_TEST_EQUALS(vector[10], 123, TEST_LOCATION);
182 DALI_TEST_EQUALS(vector[11], 123, TEST_LOCATION);
184 vector.Resize(13u, 321);
185 DALI_TEST_EQUALS(static_cast<Dali::VectorBase::SizeType>(13), vector.Count(), TEST_LOCATION);
186 DALI_TEST_EQUALS(static_cast<Dali::VectorBase::SizeType>(13), vector.Capacity(), TEST_LOCATION);
188 DALI_TEST_EQUALS(vector[0], 123, TEST_LOCATION);
189 DALI_TEST_EQUALS(vector[1], 123, TEST_LOCATION);
190 DALI_TEST_EQUALS(vector[2], 123, TEST_LOCATION);
191 DALI_TEST_EQUALS(vector[3], 123, TEST_LOCATION);
192 DALI_TEST_EQUALS(vector[4], 123, TEST_LOCATION);
193 DALI_TEST_EQUALS(vector[5], 123, TEST_LOCATION);
194 DALI_TEST_EQUALS(vector[6], 123, TEST_LOCATION);
195 DALI_TEST_EQUALS(vector[7], 123, TEST_LOCATION);
196 DALI_TEST_EQUALS(vector[8], 123, TEST_LOCATION);
197 DALI_TEST_EQUALS(vector[9], 123, TEST_LOCATION);
198 DALI_TEST_EQUALS(vector[10], 123, TEST_LOCATION);
199 DALI_TEST_EQUALS(vector[11], 123, TEST_LOCATION);
200 DALI_TEST_EQUALS(vector[12], 321, TEST_LOCATION);
204 int UtcDaliVectorIntErase(void)
206 tet_infoline("Testing Dali::Vector<short>::Erase");
209 DALI_TEST_EQUALS(ZERO, vector.Count(), TEST_LOCATION);
210 DALI_TEST_EQUALS(ZERO, vector.Capacity(), TEST_LOCATION);
216 DALI_TEST_EQUALS(static_cast<Dali::VectorBase::SizeType>(5), vector.Count(), TEST_LOCATION);
217 DALI_TEST_EQUALS(vector[0], 1, TEST_LOCATION);
218 DALI_TEST_EQUALS(vector[1], 2, TEST_LOCATION);
219 DALI_TEST_EQUALS(vector[2], 3, TEST_LOCATION);
220 DALI_TEST_EQUALS(vector[3], 4, TEST_LOCATION);
221 DALI_TEST_EQUALS(vector[4], 5, TEST_LOCATION);
223 vector.Erase(vector.Begin());
224 DALI_TEST_EQUALS(static_cast<Dali::VectorBase::SizeType>(4), vector.Count(), TEST_LOCATION);
225 DALI_TEST_EQUALS(vector[0], 2, TEST_LOCATION);
226 DALI_TEST_EQUALS(vector[1], 3, TEST_LOCATION);
227 DALI_TEST_EQUALS(vector[2], 4, TEST_LOCATION);
228 DALI_TEST_EQUALS(vector[3], 5, TEST_LOCATION);
230 Vector<char>::Iterator ret = vector.Erase(std::find(vector.Begin(), vector.End(), 4));
231 DALI_TEST_EQUALS(static_cast<Dali::VectorBase::SizeType>(3), vector.Count(), TEST_LOCATION);
232 DALI_TEST_EQUALS(vector[0], 2, TEST_LOCATION);
233 DALI_TEST_EQUALS(vector[1], 3, TEST_LOCATION);
234 DALI_TEST_EQUALS(vector[2], 5, TEST_LOCATION);
235 DALI_TEST_EQUALS(*ret, 5, TEST_LOCATION);
239 DALI_TEST_EQUALS(static_cast<Dali::VectorBase::SizeType>(4), vector.Count(), TEST_LOCATION);
240 DALI_TEST_EQUALS(vector[3], 99, TEST_LOCATION);
241 ret = vector.Erase(vector.End() - 1);
242 DALI_TEST_EQUALS(static_cast<Dali::VectorBase::SizeType>(3), vector.Count(), TEST_LOCATION);
243 DALI_TEST_EQUALS(ret, vector.End(), TEST_LOCATION);
247 // illegal erase, one past the end
248 vector.Erase(vector.End());
249 tet_result(TET_FAIL);
251 catch(Dali::DaliException& e)
253 DALI_TEST_PRINT_ASSERT(e);
254 DALI_TEST_ASSERT(e, "(iterator < End())", TEST_LOCATION);
258 tet_printf("Assertion test failed - wrong Exception\n");
259 tet_result(TET_FAIL);
264 // illegal erase, one before the begin
265 vector.Erase(vector.Begin() - 1u);
266 tet_result(TET_FAIL);
268 catch(Dali::DaliException& e)
270 DALI_TEST_PRINT_ASSERT(e);
271 DALI_TEST_ASSERT(e, "(iterator < End()) && (iterator >= Begin())", TEST_LOCATION);
275 tet_printf("Assertion test failed - wrong Exception\n");
276 tet_result(TET_FAIL);
279 DALI_TEST_EQUALS(static_cast<Dali::VectorBase::SizeType>(3), vector.Count(), TEST_LOCATION);
280 DALI_TEST_EQUALS(vector[0], 2, TEST_LOCATION);
281 DALI_TEST_EQUALS(vector[1], 3, TEST_LOCATION);
282 DALI_TEST_EQUALS(vector[2], 5, TEST_LOCATION);
284 vector.Erase(vector.Begin() + 1);
285 DALI_TEST_EQUALS(static_cast<Dali::VectorBase::SizeType>(2), vector.Count(), TEST_LOCATION);
286 DALI_TEST_EQUALS(vector[0], 2, TEST_LOCATION);
287 DALI_TEST_EQUALS(vector[1], 5, TEST_LOCATION);
289 vector.Erase(vector.Begin() + 1);
290 DALI_TEST_EQUALS(static_cast<Dali::VectorBase::SizeType>(1), vector.Count(), TEST_LOCATION);
291 DALI_TEST_EQUALS(vector[0], 2, TEST_LOCATION);
295 // illegal erase, one past the end
296 vector.Erase(vector.Begin() + 1);
297 tet_result(TET_FAIL);
299 catch(Dali::DaliException& e)
301 DALI_TEST_PRINT_ASSERT(e);
302 DALI_TEST_ASSERT(e, "(iterator < End())", TEST_LOCATION);
306 tet_printf("Assertion test failed - wrong Exception\n");
307 tet_result(TET_FAIL);
309 DALI_TEST_EQUALS(static_cast<Dali::VectorBase::SizeType>(1), vector.Count(), TEST_LOCATION);
310 DALI_TEST_EQUALS(vector[0], 2, TEST_LOCATION);
312 vector.Erase(vector.Begin());
313 DALI_TEST_EQUALS(ZERO, vector.Count(), TEST_LOCATION);
317 // illegal erase, one before the beginning
318 vector.Erase(vector.Begin() - 1);
319 tet_result(TET_FAIL);
321 catch(Dali::DaliException& e)
323 DALI_TEST_PRINT_ASSERT(e);
324 DALI_TEST_ASSERT(e, "(iterator < End())", TEST_LOCATION);
328 tet_printf("Assertion test failed - wrong Exception\n");
329 tet_result(TET_FAIL);
332 DALI_TEST_EQUALS(ZERO, vector.Count(), TEST_LOCATION);
333 DALI_TEST_EQUALS(vector.Begin(), vector.End(), TEST_LOCATION);
335 Vector<char>::Iterator endIter = vector.End();
336 for(Vector<char>::Iterator iter = vector.Begin(); iter != endIter; ++iter)
338 tet_result(TET_FAIL);
342 DALI_TEST_EQUALS(static_cast<Dali::VectorBase::SizeType>(1), vector.Count(), TEST_LOCATION);
345 DALI_TEST_EQUALS(ZERO, vector.Count(), TEST_LOCATION);
346 DALI_TEST_EQUALS(vector.Begin(), vector.End(), TEST_LOCATION);
348 endIter = vector.End();
349 for(Vector<char>::Iterator iter = vector.Begin(); iter != endIter; ++iter)
351 tet_result(TET_FAIL);
354 // test a vector of pointers
355 Vector<int*> ptrVector;
356 DALI_TEST_EQUALS(ZERO, ptrVector.Count(), TEST_LOCATION);
357 DALI_TEST_EQUALS(ptrVector.Begin(), ptrVector.End(), TEST_LOCATION);
360 ptrVector.PushBack(pointer);
361 DALI_TEST_EQUALS(static_cast<Dali::VectorBase::SizeType>(1), ptrVector.Count(), TEST_LOCATION);
363 Vector<int*>::Iterator ptriter = std::find(ptrVector.Begin(), ptrVector.End(), pointer);
364 ptriter = ptrVector.Erase(ptriter);
365 DALI_TEST_EQUALS(ZERO, ptrVector.Count(), TEST_LOCATION);
366 DALI_TEST_EQUALS(ptrVector.Begin(), ptrVector.End(), TEST_LOCATION);
367 DALI_TEST_EQUALS(ptrVector.Begin(), ptriter, TEST_LOCATION);
371 int UtcDaliVectorDoubleRemove(void)
373 tet_infoline("Testing Dali::Vector<double>::Remove");
375 Vector<double> vector;
376 DALI_TEST_EQUALS(ZERO, vector.Count(), TEST_LOCATION);
378 vector.PushBack(11.1);
379 vector.PushBack(22.2);
380 vector.PushBack(33.3);
381 vector.PushBack(44.4);
382 DALI_TEST_EQUALS(static_cast<Dali::VectorBase::SizeType>(4), vector.Count(), TEST_LOCATION);
383 DALI_TEST_EQUALS(vector[0], 11.1, TEST_LOCATION);
384 DALI_TEST_EQUALS(vector[1], 22.2, TEST_LOCATION);
385 DALI_TEST_EQUALS(vector[2], 33.3, TEST_LOCATION);
386 DALI_TEST_EQUALS(vector[3], 44.4, TEST_LOCATION);
388 Vector<double>::Iterator res = std::find(vector.Begin(), vector.End(), 22.2);
389 DALI_TEST_EQUALS(22.2, *res, TEST_LOCATION);
391 res = std::find(vector.Begin(), vector.End(), 22.2);
392 DALI_TEST_EQUALS(vector.End(), res, TEST_LOCATION);
393 DALI_TEST_EQUALS(static_cast<Dali::VectorBase::SizeType>(3), vector.Count(), TEST_LOCATION);
394 DALI_TEST_EQUALS(vector[0], 11.1, TEST_LOCATION);
395 DALI_TEST_EQUALS(vector[1], 44.4, TEST_LOCATION);
396 DALI_TEST_EQUALS(vector[2], 33.3, TEST_LOCATION);
398 vector.Remove(vector.End() - 1);
399 DALI_TEST_EQUALS(static_cast<Dali::VectorBase::SizeType>(2), vector.Count(), TEST_LOCATION);
400 DALI_TEST_EQUALS(vector[0], 11.1, TEST_LOCATION);
401 DALI_TEST_EQUALS(vector[1], 44.4, TEST_LOCATION);
403 vector.Remove(vector.Begin());
404 DALI_TEST_EQUALS(static_cast<Dali::VectorBase::SizeType>(1), vector.Count(), TEST_LOCATION);
405 DALI_TEST_EQUALS(vector[0], 44.4, TEST_LOCATION);
409 // illegal erase, one past the end
410 vector.Remove(vector.Begin() + 1);
411 tet_result(TET_FAIL);
413 catch(Dali::DaliException& e)
415 DALI_TEST_PRINT_ASSERT(e);
416 DALI_TEST_ASSERT(e, "(iterator < End()) && (iterator >= Begin())", TEST_LOCATION);
420 tet_printf("Assertion test failed - wrong Exception\n");
421 tet_result(TET_FAIL);
423 DALI_TEST_EQUALS(static_cast<Dali::VectorBase::SizeType>(1), vector.Count(), TEST_LOCATION);
424 DALI_TEST_EQUALS(vector[0], 44.4, TEST_LOCATION);
426 vector.Remove(vector.Begin());
427 DALI_TEST_EQUALS(ZERO, vector.Count(), TEST_LOCATION);
431 // illegal erase, one before the beginning
432 vector.Remove(vector.Begin() - 1);
433 tet_result(TET_FAIL);
435 catch(Dali::DaliException& e)
437 DALI_TEST_PRINT_ASSERT(e);
438 DALI_TEST_ASSERT(e, "(iterator < End()) && (iterator >= Begin())", TEST_LOCATION);
442 tet_printf("Assertion test failed - wrong Exception\n");
443 tet_result(TET_FAIL);
449 int UtcDaliVectorIntSwap(void)
451 tet_infoline("Testing Dali::Vector<int>::Swap");
453 Vector<int> intvector;
454 DALI_TEST_EQUALS(ZERO, intvector.Count(), TEST_LOCATION);
455 DALI_TEST_EQUALS(ZERO, intvector.Capacity(), TEST_LOCATION);
457 intvector.PushBack(11);
458 intvector.PushBack(22);
459 intvector.PushBack(33);
460 DALI_TEST_EQUALS(static_cast<Dali::VectorBase::SizeType>(3), intvector.Count(), TEST_LOCATION);
462 Vector<int> intvector2;
463 DALI_TEST_EQUALS(ZERO, intvector2.Count(), TEST_LOCATION);
464 DALI_TEST_EQUALS(ZERO, intvector2.Capacity(), TEST_LOCATION);
466 intvector2.Swap(intvector);
467 DALI_TEST_EQUALS(ZERO, intvector.Count(), TEST_LOCATION);
468 DALI_TEST_EQUALS(ZERO, intvector.Capacity(), TEST_LOCATION);
469 DALI_TEST_EQUALS(static_cast<Dali::VectorBase::SizeType>(3), intvector2.Count(), TEST_LOCATION);
470 DALI_TEST_EQUALS(11, intvector2[0], TEST_LOCATION);
471 DALI_TEST_EQUALS(22, intvector2[1], TEST_LOCATION);
472 DALI_TEST_EQUALS(33, intvector2[2], TEST_LOCATION);
474 intvector.PushBack(99);
475 intvector.PushBack(88);
476 DALI_TEST_EQUALS(static_cast<Dali::VectorBase::SizeType>(2), intvector.Count(), TEST_LOCATION);
478 intvector.Swap(intvector2);
479 DALI_TEST_EQUALS(static_cast<Dali::VectorBase::SizeType>(2), intvector2.Count(), TEST_LOCATION);
480 DALI_TEST_EQUALS(99, intvector2[0], TEST_LOCATION);
481 DALI_TEST_EQUALS(88, intvector2[1], TEST_LOCATION);
482 DALI_TEST_EQUALS(static_cast<Dali::VectorBase::SizeType>(3), intvector.Count(), TEST_LOCATION);
483 DALI_TEST_EQUALS(11, intvector[0], TEST_LOCATION);
484 DALI_TEST_EQUALS(22, intvector[1], TEST_LOCATION);
485 DALI_TEST_EQUALS(33, intvector[2], TEST_LOCATION);
488 intvector.Swap(empty);
489 DALI_TEST_EQUALS(ZERO, intvector.Count(), TEST_LOCATION);
490 DALI_TEST_EQUALS(ZERO, intvector.Capacity(), TEST_LOCATION);
494 int UtcDaliVectorIterate(void)
496 tet_infoline("Testing Dali::Vector<float>::Begin");
498 Vector<float> floatvector;
499 DALI_TEST_EQUALS(ZERO, floatvector.Count(), TEST_LOCATION);
500 DALI_TEST_EQUALS(ZERO, floatvector.Capacity(), TEST_LOCATION);
502 floatvector.PushBack(0.9f);
503 floatvector.PushBack(1.1f);
504 floatvector.PushBack(1.2f);
505 DALI_TEST_EQUALS(static_cast<Dali::VectorBase::SizeType>(3), floatvector.Count(), TEST_LOCATION);
507 Vector<float>::Iterator iter = floatvector.Begin();
509 for(; iter != floatvector.End(); ++iter, ++index)
511 std::cout << "value " << *iter << std::endl;
512 DALI_TEST_EQUALS(*iter, floatvector[index], TEST_LOCATION);
514 DALI_TEST_EQUALS(3, index, TEST_LOCATION);
516 iter = std::find(floatvector.Begin(), floatvector.End(), 1.1f);
517 DALI_TEST_EQUALS(1.1f, *iter, TEST_LOCATION);
520 iter = std::find(floatvector.Begin(), floatvector.End(), 1.1f);
521 DALI_TEST_EQUALS(floatvector.End(), iter, TEST_LOCATION);
525 int UtcDaliVectorPair(void)
527 tet_infoline("Testing Dali::Vector< std::pair< int, float > >");
529 Vector<std::pair<int, float> > pairvector;
530 DALI_TEST_EQUALS(ZERO, pairvector.Count(), TEST_LOCATION);
531 DALI_TEST_EQUALS(ZERO, pairvector.Capacity(), TEST_LOCATION);
533 pairvector.PushBack(std::make_pair(5, 0.1f));
534 pairvector.PushBack(std::make_pair(3, 0.2f));
535 pairvector.PushBack(std::make_pair(4, 0.3f));
536 pairvector.PushBack(std::make_pair(1, 0.4f));
537 pairvector.PushBack(std::make_pair(2, 0.5f));
538 DALI_TEST_EQUALS(static_cast<Dali::VectorBase::SizeType>(5), pairvector.Count(), TEST_LOCATION);
540 Vector<std::pair<int, float> >::Iterator iter = pairvector.Begin();
542 for(; iter != pairvector.End(); ++iter, ++index)
544 std::cout << "pair " << (*iter).first << ":" << (*iter).second << std::endl;
545 DALI_TEST_EQUALS((*iter).first, pairvector[index].first, TEST_LOCATION);
546 DALI_TEST_EQUALS((*iter).second, pairvector[index].second, TEST_LOCATION);
551 int UtcDaliVectorAsserts(void)
553 tet_infoline("Testing Dali::Vector< int* > exception handling");
556 Vector<int*> pointervector;
560 pointervector[1] = value;
561 tet_printf("Assertion expected, but not occurred at %s\n", TEST_LOCATION);
562 tet_result(TET_FAIL);
564 catch(Dali::DaliException& e)
566 DALI_TEST_PRINT_ASSERT(e);
567 DALI_TEST_ASSERT(e, "VectorBase::mData", TEST_LOCATION);
571 tet_printf("Assertion test failed - wrong Exception\n");
572 tet_result(TET_FAIL);
578 value = pointervector[0];
579 (void)value; // to "use" the value
580 tet_printf("Assertion expected, but not occurred at %s\n", TEST_LOCATION);
581 tet_result(TET_FAIL);
583 catch(Dali::DaliException& e)
585 DALI_TEST_PRINT_ASSERT(e);
586 DALI_TEST_ASSERT(e, "VectorBase::mData", TEST_LOCATION);
590 tet_printf("Assertion test failed - wrong Exception\n");
591 tet_result(TET_FAIL);
594 Vector<int*>::Iterator iter = pointervector.Begin();
595 if(iter != pointervector.End())
597 tet_result(TET_FAIL);
602 pointervector.Erase(pointervector.Begin());
603 tet_printf("Assertion expected, but not occurred at %s\n", TEST_LOCATION);
604 tet_result(TET_FAIL);
606 catch(Dali::DaliException& e)
608 DALI_TEST_PRINT_ASSERT(e);
609 DALI_TEST_ASSERT(e, "(iterator < End()) && (iterator >= Begin())", TEST_LOCATION);
613 tet_printf("Assertion test failed - wrong Exception\n");
614 tet_result(TET_FAIL);
617 iter = pointervector.Begin();
618 if(iter != pointervector.End())
620 tet_result(TET_FAIL);
625 pointervector.Remove(pointervector.Begin());
626 tet_printf("Assertion expected, but not occurred at %s\n", TEST_LOCATION);
627 tet_result(TET_FAIL);
629 catch(Dali::DaliException& e)
631 DALI_TEST_PRINT_ASSERT(e);
632 DALI_TEST_ASSERT(e, "(iterator < End()) && (iterator >= Begin())", TEST_LOCATION);
636 tet_printf("Assertion test failed - wrong Exception\n");
637 tet_result(TET_FAIL);
640 iter = pointervector.Begin();
641 if(iter != pointervector.End())
643 tet_result(TET_FAIL);
647 pointervector.Reserve(0);
648 iter = pointervector.Begin();
649 if(iter != pointervector.End())
651 tet_result(TET_FAIL);
655 pointervector.Reserve(1);
656 iter = pointervector.Begin();
657 if(iter != pointervector.End())
659 tet_result(TET_FAIL);
665 pointervector[1] = value;
666 tet_printf("Assertion expected, but not occurred at %s\n", TEST_LOCATION);
667 tet_result(TET_FAIL);
669 catch(Dali::DaliException& e)
671 DALI_TEST_PRINT_ASSERT(e);
672 DALI_TEST_ASSERT(e, "index < VectorBase::Count()", TEST_LOCATION);
676 tet_printf("Assertion test failed - wrong Exception\n");
677 tet_result(TET_FAIL);
682 int* value = pointervector[1];
683 (void)value; // to "use" the value
684 tet_printf("Assertion expected, but not occurred at %s\n", TEST_LOCATION);
685 tet_result(TET_FAIL);
687 catch(Dali::DaliException& e)
689 DALI_TEST_PRINT_ASSERT(e);
690 DALI_TEST_ASSERT(e, "index < VectorBase::Count()", TEST_LOCATION);
694 tet_printf("Assertion test failed - wrong Exception\n");
695 tet_result(TET_FAIL);
701 int UtcDaliVectorAcidTest(void)
703 tet_infoline("Testing multiple Dali::Vector's");
705 // create multiple vectors
706 Vector<std::pair<float, float> > pairvector;
707 DALI_TEST_EQUALS(ZERO, pairvector.Count(), TEST_LOCATION);
708 DALI_TEST_EQUALS(ZERO, pairvector.Capacity(), TEST_LOCATION);
709 Vector<double> doublevector;
710 DALI_TEST_EQUALS(ZERO, doublevector.Count(), TEST_LOCATION);
711 DALI_TEST_EQUALS(ZERO, doublevector.Capacity(), TEST_LOCATION);
712 Vector<int*> intptrvector;
713 DALI_TEST_EQUALS(ZERO, intptrvector.Count(), TEST_LOCATION);
714 DALI_TEST_EQUALS(ZERO, intptrvector.Capacity(), TEST_LOCATION);
715 Vector<Dali::Actor*> actorptrvector;
716 DALI_TEST_EQUALS(ZERO, actorptrvector.Count(), TEST_LOCATION);
717 DALI_TEST_EQUALS(ZERO, actorptrvector.Capacity(), TEST_LOCATION);
718 Vector<long> longvector;
719 DALI_TEST_EQUALS(ZERO, longvector.Count(), TEST_LOCATION);
720 DALI_TEST_EQUALS(ZERO, longvector.Capacity(), TEST_LOCATION);
721 Vector<char> charvector;
722 DALI_TEST_EQUALS(ZERO, charvector.Count(), TEST_LOCATION);
723 DALI_TEST_EQUALS(ZERO, charvector.Capacity(), TEST_LOCATION);
726 static unsigned int acidCount = 10000;
728 for(unsigned int i = 0; i < acidCount; ++i)
730 pairvector.PushBack(std::make_pair(i, i));
731 doublevector.PushBack((double)i);
732 intptrvector.PushBack((int*)ptr);
733 actorptrvector.PushBack((Dali::Actor*)ptr);
734 longvector.PushBack((long)i);
735 charvector.PushBack((char)i);
737 DALI_TEST_EQUALS(acidCount, pairvector.Count(), TEST_LOCATION);
738 std::size_t pairCapacity = pairvector.Capacity();
739 DALI_TEST_EQUALS(acidCount, doublevector.Count(), TEST_LOCATION);
740 std::size_t doubleCapacity = doublevector.Capacity();
741 DALI_TEST_EQUALS(acidCount, intptrvector.Count(), TEST_LOCATION);
742 std::size_t intptrCapacity = intptrvector.Capacity();
743 DALI_TEST_EQUALS(acidCount, actorptrvector.Count(), TEST_LOCATION);
744 std::size_t actorptrCapacity = actorptrvector.Capacity();
745 DALI_TEST_EQUALS(acidCount, longvector.Count(), TEST_LOCATION);
746 std::size_t longCapacity = longvector.Capacity();
747 DALI_TEST_EQUALS(acidCount, charvector.Count(), TEST_LOCATION);
748 std::size_t charCapacity = charvector.Capacity();
750 tet_printf("Dali::Vector< pair > capacity after %d pushbacks is %d", acidCount, pairCapacity);
751 tet_printf("Dali::Vector< double > capacity after %d pushbacks is %d", acidCount, doubleCapacity);
752 tet_printf("Dali::Vector< int* > capacity after %d pushbacks is %d", acidCount, intptrCapacity);
753 tet_printf("Dali::Vector< Actor* > capacity after %d pushbacks is %d", acidCount, actorptrCapacity);
754 tet_printf("Dali::Vector< long > capacity after %d pushbacks is %d", acidCount, longCapacity);
755 tet_printf("Dali::Vector< char > capacity after %d pushbacks is %d", acidCount, charCapacity);
758 for(unsigned int i = 0; i < acidCount; ++i)
760 pairvector.Erase(pairvector.Begin() + (i % pairvector.Count()));
761 doublevector.Erase(doublevector.Begin() + (i % doublevector.Count()));
762 intptrvector.Erase(intptrvector.Begin() + (i % intptrvector.Count()));
763 actorptrvector.Erase(actorptrvector.Begin() + (i % actorptrvector.Count()));
764 longvector.Erase(longvector.Begin() + (i % longvector.Count()));
765 charvector.Erase(charvector.Begin() + (i % charvector.Count()));
767 DALI_TEST_EQUALS(ZERO, pairvector.Count(), TEST_LOCATION);
768 DALI_TEST_EQUALS(pairCapacity, pairvector.Capacity(), TEST_LOCATION);
769 DALI_TEST_EQUALS(ZERO, doublevector.Count(), TEST_LOCATION);
770 DALI_TEST_EQUALS(doubleCapacity, doublevector.Capacity(), TEST_LOCATION);
771 DALI_TEST_EQUALS(ZERO, intptrvector.Count(), TEST_LOCATION);
772 DALI_TEST_EQUALS(intptrCapacity, intptrvector.Capacity(), TEST_LOCATION);
773 DALI_TEST_EQUALS(ZERO, actorptrvector.Count(), TEST_LOCATION);
774 DALI_TEST_EQUALS(actorptrCapacity, actorptrvector.Capacity(), TEST_LOCATION);
775 DALI_TEST_EQUALS(ZERO, longvector.Count(), TEST_LOCATION);
776 DALI_TEST_EQUALS(longCapacity, longvector.Capacity(), TEST_LOCATION);
777 DALI_TEST_EQUALS(ZERO, charvector.Count(), TEST_LOCATION);
778 DALI_TEST_EQUALS(charCapacity, charvector.Capacity(), TEST_LOCATION);
783 int UtcDaliVectorPushBack(void)
785 tet_infoline("Testing Dali::Vector< int* >PushBack(Element)");
787 Vector<unsigned int> vector;
788 DALI_TEST_EQUALS(ZERO, vector.Count(), TEST_LOCATION);
789 DALI_TEST_EQUALS(ZERO, vector.Capacity(), TEST_LOCATION);
792 DALI_TEST_EQUALS(ZERO, vector.Count(), TEST_LOCATION);
793 DALI_TEST_EQUALS(2u, vector.Capacity(), TEST_LOCATION);
799 DALI_TEST_EQUALS(3u, vector.Count(), TEST_LOCATION);
800 DALI_TEST_EQUALS(6u, vector.Capacity(), TEST_LOCATION);
804 DALI_TEST_EQUALS(4u, vector.Count(), TEST_LOCATION);
805 DALI_TEST_EQUALS(6u, vector.Capacity(), TEST_LOCATION);
807 DALI_TEST_EQUALS(0u, vector[0u], TEST_LOCATION);
808 DALI_TEST_EQUALS(1u, vector[1u], TEST_LOCATION);
809 DALI_TEST_EQUALS(2u, vector[2u], TEST_LOCATION);
810 DALI_TEST_EQUALS(3u, vector[3u], TEST_LOCATION);
815 int UtcDaliVectorInsert01(void)
817 tet_infoline("Testing Dali::Vector< int* >Insert(Iterator, Element)");
819 // Test order of array inserted-into:
820 Vector<unsigned int> orderedVector;
821 orderedVector.PushBack(9u);
822 for(unsigned int i = 8u; i <= 8u; --i)
824 orderedVector.Insert(orderedVector.Begin(), i);
825 DALI_TEST_EQUALS(10u - i, orderedVector.Count(), TEST_LOCATION);
826 DALI_TEST_EQUALS(i, orderedVector[0u], TEST_LOCATION);
829 for(unsigned int i = 0u; i < 10u; ++i)
831 DALI_TEST_EQUALS(i, orderedVector[i], TEST_LOCATION);
834 // Test insertion out of range in non-empty array throws:
837 orderedVector.Insert(orderedVector.Begin() + 99u, 99u);
838 tet_printf("Assertion expected, but not occurred at %s\n", TEST_LOCATION);
839 tet_result(TET_FAIL);
841 catch(Dali::DaliException& e)
843 DALI_TEST_PRINT_ASSERT(e);
844 DALI_TEST_ASSERT(e, "(at <= End()) && (at >= Begin())", TEST_LOCATION);
848 tet_printf("Assertion test failed - wrong Exception\n");
849 tet_result(TET_FAIL);
854 orderedVector.Insert(orderedVector.Begin() - 1u, 99u);
855 tet_printf("Assertion expected, but not occurred at %s\n", TEST_LOCATION);
856 tet_result(TET_FAIL);
858 catch(Dali::DaliException& e)
860 DALI_TEST_PRINT_ASSERT(e);
861 DALI_TEST_ASSERT(e, "(at <= End()) && (at >= Begin())", TEST_LOCATION);
865 tet_printf("Assertion test failed - wrong Exception\n");
866 tet_result(TET_FAIL);
869 // Test insertion part-way through a largish array retains ordering:
871 // Build vector with hole in sequence:
872 Vector<unsigned int> longerVector;
873 const unsigned int insertionPoint = 131571u;
874 const unsigned int finalLength = 262143u;
875 for(unsigned int i = 0u; i < insertionPoint; ++i)
877 longerVector.PushBack(i);
879 for(unsigned int i = insertionPoint; i < finalLength; ++i)
881 longerVector.PushBack(i + 1);
884 // Fill the hole in the sequence:
885 longerVector.Insert(longerVector.Begin() + insertionPoint, insertionPoint);
887 // Check the sequence is monotonically increasing by one every time:
888 for(unsigned int i = 0u; i <= finalLength; ++i)
890 DALI_TEST_EQUALS(i, longerVector[i], TEST_LOCATION);
893 // Insert into an empty vector
894 Vector<unsigned int> vector;
896 vector.Insert(vector.End(), orderedVector.Begin(), orderedVector.End());
897 for(unsigned int i = 0u; i < 10u; ++i)
899 DALI_TEST_EQUALS(i, vector[i], TEST_LOCATION);
903 vector.Insert(vector.Begin(), orderedVector.Begin(), orderedVector.End());
904 for(unsigned int i = 0u; i < 10u; ++i)
906 DALI_TEST_EQUALS(i, vector[i], TEST_LOCATION);
910 vector.Insert(vector.Begin(), orderedVector.Begin(), orderedVector.Begin());
911 for(unsigned int i = 0u; i < 10u; ++i)
913 DALI_TEST_EQUALS(i, vector[i], TEST_LOCATION);
916 vector.Insert(vector.Begin() + 5, vector.Begin() + 5, vector.Begin() + 5);
917 for(unsigned int i = 0u; i < 10u; ++i)
919 DALI_TEST_EQUALS(i, vector[i], TEST_LOCATION);
929 vector.Insert(vector.Begin() + 2, vector.Begin(), vector.End());
930 DALI_TEST_EQUALS(8u, vector.Count(), TEST_LOCATION);
931 DALI_TEST_EQUALS(0u, vector[0u], TEST_LOCATION);
932 DALI_TEST_EQUALS(1u, vector[1u], TEST_LOCATION);
933 DALI_TEST_EQUALS(0u, vector[2u], TEST_LOCATION);
934 DALI_TEST_EQUALS(1u, vector[3u], TEST_LOCATION);
935 DALI_TEST_EQUALS(2u, vector[4u], TEST_LOCATION);
936 DALI_TEST_EQUALS(3u, vector[5u], TEST_LOCATION);
937 DALI_TEST_EQUALS(2u, vector[6u], TEST_LOCATION);
938 DALI_TEST_EQUALS(3u, vector[7u], TEST_LOCATION);
943 int UtcDaliVectorInsert02(void)
945 tet_infoline("Testing Dali::Vector<char>::Insert(Iterator,Iterator,Iterator)");
948 DALI_TEST_EQUALS(ZERO, vector.Count(), TEST_LOCATION);
949 DALI_TEST_EQUALS(ZERO, vector.Capacity(), TEST_LOCATION);
956 Vector<char> vector2;
957 DALI_TEST_EQUALS(ZERO, vector2.Count(), TEST_LOCATION);
958 DALI_TEST_EQUALS(ZERO, vector2.Capacity(), TEST_LOCATION);
963 vector2.PushBack(10);
965 // Test insert at end
966 vector.Insert(vector.End(), vector2.Begin(), vector2.Begin() + 1u);
967 DALI_TEST_EQUALS(static_cast<Dali::VectorBase::SizeType>(6), vector.Count(), TEST_LOCATION);
968 DALI_TEST_EQUALS(vector[0], 1, TEST_LOCATION);
969 DALI_TEST_EQUALS(vector[1], 2, TEST_LOCATION);
970 DALI_TEST_EQUALS(vector[2], 3, TEST_LOCATION);
971 DALI_TEST_EQUALS(vector[3], 4, TEST_LOCATION);
972 DALI_TEST_EQUALS(vector[4], 5, TEST_LOCATION);
973 DALI_TEST_EQUALS(vector[5], 6, TEST_LOCATION);
975 // Test insert at begin
976 vector.Insert(vector.Begin(), vector2.Begin() + 1, vector2.Begin() + 2u);
977 DALI_TEST_EQUALS(static_cast<Dali::VectorBase::SizeType>(7), vector.Count(), TEST_LOCATION);
978 DALI_TEST_EQUALS(vector[0], 7, TEST_LOCATION);
979 DALI_TEST_EQUALS(vector[1], 1, TEST_LOCATION);
980 DALI_TEST_EQUALS(vector[2], 2, TEST_LOCATION);
981 DALI_TEST_EQUALS(vector[3], 3, TEST_LOCATION);
982 DALI_TEST_EQUALS(vector[4], 4, TEST_LOCATION);
983 DALI_TEST_EQUALS(vector[5], 5, TEST_LOCATION);
984 DALI_TEST_EQUALS(vector[6], 6, TEST_LOCATION);
986 // Test insert in the middle
987 vector.Insert(vector.Begin() + 3, vector2.Begin() + 3, vector2.End());
988 DALI_TEST_EQUALS(static_cast<Dali::VectorBase::SizeType>(9), vector.Count(), TEST_LOCATION);
989 DALI_TEST_EQUALS(vector[0], 7, TEST_LOCATION);
990 DALI_TEST_EQUALS(vector[1], 1, TEST_LOCATION);
991 DALI_TEST_EQUALS(vector[2], 2, TEST_LOCATION);
992 DALI_TEST_EQUALS(vector[3], 9, TEST_LOCATION);
993 DALI_TEST_EQUALS(vector[4], 10, TEST_LOCATION);
994 DALI_TEST_EQUALS(vector[5], 3, TEST_LOCATION);
995 DALI_TEST_EQUALS(vector[6], 4, TEST_LOCATION);
996 DALI_TEST_EQUALS(vector[7], 5, TEST_LOCATION);
997 DALI_TEST_EQUALS(vector[8], 6, TEST_LOCATION);
1001 int UtcDaliVectorIntInsertAssert(void)
1003 tet_infoline("Testing Dali::Vector<char>::Insert(Iterator,Iterator,Iterator) asserts");
1005 Vector<char> vector;
1006 DALI_TEST_EQUALS(ZERO, vector.Count(), TEST_LOCATION);
1007 DALI_TEST_EQUALS(ZERO, vector.Capacity(), TEST_LOCATION);
1011 Vector<char> vector2;
1012 DALI_TEST_EQUALS(ZERO, vector2.Count(), TEST_LOCATION);
1013 DALI_TEST_EQUALS(ZERO, vector2.Capacity(), TEST_LOCATION);
1014 vector2.PushBack(6);
1015 vector2.PushBack(7);
1016 vector2.PushBack(8);
1017 vector2.PushBack(9);
1018 vector2.PushBack(10);
1022 vector.Insert(vector.Begin() + 3u, vector2.Begin(), vector2.End());
1023 tet_result(TET_FAIL);
1025 catch(Dali::DaliException& e)
1027 DALI_TEST_PRINT_ASSERT(e);
1028 DALI_TEST_ASSERT(e, "(at <= End()) && (at >= Begin())", TEST_LOCATION);
1032 tet_printf("Assertion test failed - wrong Exception\n");
1033 tet_result(TET_FAIL);
1038 vector.Insert(vector.Begin() - 1u, vector2.Begin(), vector2.End());
1039 tet_result(TET_FAIL);
1041 catch(Dali::DaliException& e)
1043 DALI_TEST_PRINT_ASSERT(e);
1044 DALI_TEST_ASSERT(e, "(at <= End()) && (at >= Begin())", TEST_LOCATION);
1048 tet_printf("Assertion test failed - wrong Exception\n");
1049 tet_result(TET_FAIL);
1054 vector.Insert(vector.End(), vector2.End(), vector2.Begin());
1055 tet_result(TET_FAIL);
1057 catch(Dali::DaliException& e)
1059 DALI_TEST_PRINT_ASSERT(e);
1060 DALI_TEST_ASSERT(e, "(from <= to)", TEST_LOCATION);
1064 tet_printf("Assertion test failed - wrong Exception\n");
1065 tet_result(TET_FAIL);
1071 int UtcDaliVectorIntEraseRange(void)
1073 tet_infoline("Testing Dali::Vector<char>::Erase(Iterator,Iterator)");
1075 Vector<char> vector;
1076 DALI_TEST_EQUALS(ZERO, vector.Count(), TEST_LOCATION);
1077 DALI_TEST_EQUALS(ZERO, vector.Capacity(), TEST_LOCATION);
1079 // Try to delete from empty vector.
1081 vector.Erase(vector.Begin(), vector.End());
1082 DALI_TEST_EQUALS(ZERO, vector.Count(), TEST_LOCATION);
1083 DALI_TEST_EQUALS(ZERO, vector.Capacity(), TEST_LOCATION);
1090 DALI_TEST_EQUALS(static_cast<Dali::VectorBase::SizeType>(5), vector.Count(), TEST_LOCATION);
1091 DALI_TEST_EQUALS(vector[0], 1, TEST_LOCATION);
1092 DALI_TEST_EQUALS(vector[1], 2, TEST_LOCATION);
1093 DALI_TEST_EQUALS(vector[2], 3, TEST_LOCATION);
1094 DALI_TEST_EQUALS(vector[3], 4, TEST_LOCATION);
1095 DALI_TEST_EQUALS(vector[4], 5, TEST_LOCATION);
1097 Vector<char>::Iterator ret;
1099 ret = vector.Erase(vector.Begin() + 1u, vector.Begin() + 2u);
1100 DALI_TEST_EQUALS(static_cast<Dali::VectorBase::SizeType>(4), vector.Count(), TEST_LOCATION);
1101 DALI_TEST_EQUALS(vector[0], 1, TEST_LOCATION);
1102 DALI_TEST_EQUALS(vector[1], 3, TEST_LOCATION);
1103 DALI_TEST_EQUALS(vector[2], 4, TEST_LOCATION);
1104 DALI_TEST_EQUALS(vector[3], 5, TEST_LOCATION);
1105 DALI_TEST_EQUALS(*ret, 3, TEST_LOCATION);
1107 ret = vector.Erase(vector.Begin(), vector.Begin() + 2);
1108 DALI_TEST_EQUALS(static_cast<Dali::VectorBase::SizeType>(2), vector.Count(), TEST_LOCATION);
1109 DALI_TEST_EQUALS(vector[0], 4, TEST_LOCATION);
1110 DALI_TEST_EQUALS(vector[1], 5, TEST_LOCATION);
1111 DALI_TEST_EQUALS(*ret, 4, TEST_LOCATION);
1114 vector.PushBack(99);
1115 DALI_TEST_EQUALS(static_cast<Dali::VectorBase::SizeType>(3), vector.Count(), TEST_LOCATION);
1116 DALI_TEST_EQUALS(vector[2], 99, TEST_LOCATION);
1117 ret = vector.Erase(vector.Begin() + 1u, vector.End());
1118 DALI_TEST_EQUALS(static_cast<Dali::VectorBase::SizeType>(1), vector.Count(), TEST_LOCATION);
1119 DALI_TEST_EQUALS(vector[0], 4, TEST_LOCATION);
1120 DALI_TEST_EQUALS(ret, vector.End(), TEST_LOCATION);
1123 vector.PushBack(100);
1124 vector.PushBack(101);
1125 vector.PushBack(102);
1127 DALI_TEST_EQUALS(static_cast<Dali::VectorBase::SizeType>(4), vector.Count(), TEST_LOCATION);
1128 DALI_TEST_EQUALS(vector[0], 4, TEST_LOCATION);
1129 DALI_TEST_EQUALS(vector[1], 100, TEST_LOCATION);
1130 DALI_TEST_EQUALS(vector[2], 101, TEST_LOCATION);
1131 DALI_TEST_EQUALS(vector[3], 102, TEST_LOCATION);
1133 ret = vector.Erase(vector.Begin(), vector.End());
1134 DALI_TEST_EQUALS(static_cast<Dali::VectorBase::SizeType>(0), vector.Count(), TEST_LOCATION);
1135 DALI_TEST_EQUALS(ret, vector.End(), TEST_LOCATION);
1137 // try erase from Iterator to the same Iterator.
1138 vector.PushBack(100);
1139 vector.PushBack(101);
1140 vector.PushBack(102);
1142 DALI_TEST_EQUALS(static_cast<Dali::VectorBase::SizeType>(3), vector.Count(), TEST_LOCATION);
1143 DALI_TEST_EQUALS(vector[0], 100, TEST_LOCATION);
1144 DALI_TEST_EQUALS(vector[1], 101, TEST_LOCATION);
1145 DALI_TEST_EQUALS(vector[2], 102, TEST_LOCATION);
1147 ret = vector.Erase(vector.Begin() + 1, vector.Begin() + 1);
1149 DALI_TEST_EQUALS(static_cast<Dali::VectorBase::SizeType>(3), vector.Count(), TEST_LOCATION);
1150 DALI_TEST_EQUALS(vector[0], 100, TEST_LOCATION);
1151 DALI_TEST_EQUALS(vector[1], 101, TEST_LOCATION);
1152 DALI_TEST_EQUALS(vector[2], 102, TEST_LOCATION);
1154 DALI_TEST_EQUALS(*ret, 101, TEST_LOCATION);
1159 int UtcDaliVectorIntEraseRangeAssert(void)
1161 tet_infoline("Testing Dali::Vector<char>::Erase(Iterator,Iterator) asserts");
1163 Vector<char> vector;
1164 DALI_TEST_EQUALS(ZERO, vector.Count(), TEST_LOCATION);
1165 DALI_TEST_EQUALS(ZERO, vector.Capacity(), TEST_LOCATION);
1167 // Add some elements.
1171 // first out of bounds
1174 vector.Erase(vector.Begin() + 3u, vector.Begin() + 4u);
1175 tet_printf("Assertion expected, but not occurred at %s\n", TEST_LOCATION);
1176 tet_result(TET_FAIL);
1178 catch(Dali::DaliException& e)
1180 DALI_TEST_PRINT_ASSERT(e);
1181 DALI_TEST_ASSERT(e, "(first <= End()) && (first >= Begin())", TEST_LOCATION);
1185 tet_printf("Assertion test failed - wrong Exception\n");
1186 tet_result(TET_FAIL);
1191 vector.Erase(vector.Begin() - 1u, vector.End());
1192 tet_printf("Assertion expected, but not occurred at %s\n", TEST_LOCATION);
1193 tet_result(TET_FAIL);
1195 catch(Dali::DaliException& e)
1197 DALI_TEST_PRINT_ASSERT(e);
1198 DALI_TEST_ASSERT(e, "(first <= End()) && (first >= Begin())", TEST_LOCATION);
1202 tet_printf("Assertion test failed - wrong Exception\n");
1203 tet_result(TET_FAIL);
1206 // last out of bounds
1210 vector.Erase(vector.Begin(), vector.Begin() + 3u);
1211 tet_printf("Assertion expected, but not occurred at %s\n", TEST_LOCATION);
1212 tet_result(TET_FAIL);
1214 catch(Dali::DaliException& e)
1216 DALI_TEST_PRINT_ASSERT(e);
1217 DALI_TEST_ASSERT(e, "(last <= End()) && (last >= Begin())", TEST_LOCATION);
1221 tet_printf("Assertion test failed - wrong Exception\n");
1222 tet_result(TET_FAIL);
1227 vector.Erase(vector.Begin(), vector.Begin() - 1u);
1228 tet_printf("Assertion expected, but not occurred at %s\n", TEST_LOCATION);
1229 tet_result(TET_FAIL);
1231 catch(Dali::DaliException& e)
1233 DALI_TEST_PRINT_ASSERT(e);
1234 DALI_TEST_ASSERT(e, "(last <= End()) && (last >= Begin())", TEST_LOCATION);
1238 tet_printf("Assertion test failed - wrong Exception\n");
1239 tet_result(TET_FAIL);
1247 vector.Erase(vector.Begin() + 2u, vector.Begin() + 1u);
1248 tet_printf("Assertion expected, but not occurred at %s\n", TEST_LOCATION);
1249 tet_result(TET_FAIL);
1251 catch(Dali::DaliException& e)
1253 DALI_TEST_PRINT_ASSERT(e);
1254 DALI_TEST_ASSERT(e, "(first <= last)", TEST_LOCATION);
1258 tet_printf("Assertion test failed - wrong Exception\n");
1259 tet_result(TET_FAIL);
1265 int UtcDaliVectorVector2P(void)
1267 tet_infoline("Testing Dali::Vector< Vector2 >");
1269 Vector<Vector2> classvector;
1270 DALI_TEST_EQUALS(ZERO, classvector.Count(), TEST_LOCATION);
1271 DALI_TEST_EQUALS(ZERO, classvector.Capacity(), TEST_LOCATION);
1273 classvector.PushBack(Vector2());
1275 DALI_TEST_EQUALS(1u, classvector.Count(), TEST_LOCATION);
1276 DALI_TEST_GREATER(classvector.Capacity(), ZERO, TEST_LOCATION);
1278 classvector.PushBack(Vector2(0.1f, 0.2f));
1280 DALI_TEST_EQUALS(2u, classvector.Count(), TEST_LOCATION);
1282 DALI_TEST_EQUALS(Vector2(), classvector[0], TEST_LOCATION);
1283 DALI_TEST_EQUALS(Vector2(0.1f, 0.2f), classvector[1], TEST_LOCATION);
1285 tet_result(TET_PASS); // for now
1289 int UtcDaliVectorVector3P(void)
1291 tet_infoline("Testing Dali::Vector< Vector3 >");
1293 Vector<Vector3> classvector;
1294 DALI_TEST_EQUALS(ZERO, classvector.Count(), TEST_LOCATION);
1295 DALI_TEST_EQUALS(ZERO, classvector.Capacity(), TEST_LOCATION);
1297 classvector.PushBack(Vector3());
1299 DALI_TEST_EQUALS(1u, classvector.Count(), TEST_LOCATION);
1300 DALI_TEST_GREATER(classvector.Capacity(), ZERO, TEST_LOCATION);
1302 classvector.PushBack(Vector3(0.1f, 0.2f, 0.3f));
1304 DALI_TEST_EQUALS(2u, classvector.Count(), TEST_LOCATION);
1306 DALI_TEST_EQUALS(Vector3(), classvector[0], TEST_LOCATION);
1307 DALI_TEST_EQUALS(Vector3(0.1f, 0.2f, 0.3f), classvector[1], TEST_LOCATION);
1309 tet_result(TET_PASS); // for now
1313 int UtcDaliVectorMatrixP(void)
1315 tet_infoline("Testing Dali::Vector< Matrix >");
1317 Vector<Matrix> classvector;
1318 DALI_TEST_EQUALS(ZERO, classvector.Count(), TEST_LOCATION);
1319 DALI_TEST_EQUALS(ZERO, classvector.Capacity(), TEST_LOCATION);
1321 classvector.PushBack(Matrix());
1323 DALI_TEST_EQUALS(1u, classvector.Count(), TEST_LOCATION);
1324 DALI_TEST_GREATER(classvector.Capacity(), ZERO, TEST_LOCATION);
1326 classvector.PushBack(Matrix::IDENTITY);
1328 DALI_TEST_EQUALS(2u, classvector.Count(), TEST_LOCATION);
1330 DALI_TEST_EQUALS(Matrix(), classvector[0], TEST_LOCATION);
1331 DALI_TEST_EQUALS(Matrix::IDENTITY, classvector[1], TEST_LOCATION);
1333 tet_result(TET_PASS); // for now
1337 int UtcDaliVectorCpp11ForP(void)
1339 Vector<Vector3> classvector;
1340 for(auto i : classvector)
1343 tet_result(TET_FAIL);
1346 classvector.PushBack(Vector3(0.1f, 0.2f, 0.3f));
1347 classvector.PushBack(Vector3(0.1f, 0.2f, 0.3f));
1348 classvector.PushBack(Vector3(0.1f, 0.2f, 0.3f));
1350 for(auto i : classvector)
1352 DALI_TEST_EQUALS(Vector3(0.1f, 0.2f, 0.3f), i, TEST_LOCATION);
1358 int UtcDaliVectorMoveConstructor(void)
1360 Vector<Vector3> movedFrom;
1361 movedFrom.PushBack(Vector3::ONE);
1362 movedFrom.PushBack(Vector3::NEGATIVE_YAXIS);
1363 movedFrom.PushBack(Vector3::NEGATIVE_ZAXIS);
1365 Vector<Vector3> movedTo(std::move(movedFrom));
1366 DALI_TEST_EQUALS(movedTo.Size(), 3u, TEST_LOCATION);
1367 DALI_TEST_EQUALS(movedFrom.Size(), 0u, TEST_LOCATION);
1372 int UtcDaliVectorMoveAssignment(void)
1374 Vector<Vector3> movedFrom;
1375 movedFrom.PushBack(Vector3::ONE);
1376 movedFrom.PushBack(Vector3::NEGATIVE_YAXIS);
1377 movedFrom.PushBack(Vector3::NEGATIVE_ZAXIS);
1379 Vector<Vector3> movedTo;
1380 DALI_TEST_EQUALS(movedTo.Size(), 0u, TEST_LOCATION);
1381 DALI_TEST_EQUALS(movedFrom.Size(), 3u, TEST_LOCATION);
1383 movedTo = std::move(movedFrom);
1384 DALI_TEST_EQUALS(movedTo.Size(), 3u, TEST_LOCATION);
1385 DALI_TEST_EQUALS(movedFrom.Size(), 0u, TEST_LOCATION);
1390 int UtcDaliVectorEraseFreeFunction(void)
1392 tet_infoline("Testing Dali::Erase<Vector<int>>");
1396 // erasing from empty vector
1397 Dali::Erase(vector, 2);
1398 DALI_TEST_EQUALS(ZERO, vector.Count(), TEST_LOCATION);
1399 DALI_TEST_EQUALS(ZERO, vector.Capacity(), TEST_LOCATION);
1408 // erase multiple value
1409 Dali::Erase(vector, 3);
1410 DALI_TEST_EQUALS(static_cast<Dali::VectorBase::SizeType>(4), vector.Count(), TEST_LOCATION);
1412 DALI_TEST_EQUALS(vector[0], 1, TEST_LOCATION);
1413 DALI_TEST_EQUALS(vector[1], 2, TEST_LOCATION);
1414 DALI_TEST_EQUALS(vector[2], 4, TEST_LOCATION);
1415 DALI_TEST_EQUALS(vector[3], 5, TEST_LOCATION);
1417 // erase an element present at start
1418 Dali::Erase(vector, 1);
1419 DALI_TEST_EQUALS(static_cast<Dali::VectorBase::SizeType>(3), vector.Count(), TEST_LOCATION);
1420 DALI_TEST_EQUALS(vector[0], 2, TEST_LOCATION);
1421 DALI_TEST_EQUALS(vector[1], 4, TEST_LOCATION);
1422 DALI_TEST_EQUALS(vector[2], 5, TEST_LOCATION);
1424 // erase an element present at end
1425 Dali::Erase(vector, 5);
1426 DALI_TEST_EQUALS(static_cast<Dali::VectorBase::SizeType>(2), vector.Count(), TEST_LOCATION);
1427 DALI_TEST_EQUALS(vector[0], 2, TEST_LOCATION);
1428 DALI_TEST_EQUALS(vector[1], 4, TEST_LOCATION);
1430 // erase an element not present in the vector
1431 Dali::Erase(vector, 42);
1432 DALI_TEST_EQUALS(static_cast<Dali::VectorBase::SizeType>(2), vector.Count(), TEST_LOCATION);
1433 DALI_TEST_EQUALS(vector[0], 2, TEST_LOCATION);
1434 DALI_TEST_EQUALS(vector[1], 4, TEST_LOCATION);
1439 int UtcDaliVectorEraseIfFreeFunction(void)
1441 tet_infoline("Testing Dali::EraseIf<Vector<int>>");
1445 // erasing from empty vector
1446 Dali::EraseIf(vector, [](const auto& value) { return value == 2; });
1447 DALI_TEST_EQUALS(ZERO, vector.Count(), TEST_LOCATION);
1448 DALI_TEST_EQUALS(ZERO, vector.Capacity(), TEST_LOCATION);
1457 // erase multiple value
1458 Dali::EraseIf(vector, [](const auto& value) { return value == 3; });
1459 DALI_TEST_EQUALS(static_cast<Dali::VectorBase::SizeType>(4), vector.Count(), TEST_LOCATION);
1461 DALI_TEST_EQUALS(vector[0], 1, TEST_LOCATION);
1462 DALI_TEST_EQUALS(vector[1], 2, TEST_LOCATION);
1463 DALI_TEST_EQUALS(vector[2], 4, TEST_LOCATION);
1464 DALI_TEST_EQUALS(vector[3], 5, TEST_LOCATION);
1466 // erase an element present at start
1467 Dali::EraseIf(vector, [](const auto& value) { return value == 1; });
1468 DALI_TEST_EQUALS(static_cast<Dali::VectorBase::SizeType>(3), vector.Count(), TEST_LOCATION);
1469 DALI_TEST_EQUALS(vector[0], 2, TEST_LOCATION);
1470 DALI_TEST_EQUALS(vector[1], 4, TEST_LOCATION);
1471 DALI_TEST_EQUALS(vector[2], 5, TEST_LOCATION);
1473 // erase an element present at end
1474 Dali::EraseIf(vector, [](const auto& value) { return value == 5; });
1475 DALI_TEST_EQUALS(static_cast<Dali::VectorBase::SizeType>(2), vector.Count(), TEST_LOCATION);
1476 DALI_TEST_EQUALS(vector[0], 2, TEST_LOCATION);
1477 DALI_TEST_EQUALS(vector[1], 4, TEST_LOCATION);
1479 // erase an element not present in the vector
1480 Dali::EraseIf(vector, [](const auto& value) { return value == 42; });
1481 DALI_TEST_EQUALS(static_cast<Dali::VectorBase::SizeType>(2), vector.Count(), TEST_LOCATION);
1482 DALI_TEST_EQUALS(vector[0], 2, TEST_LOCATION);
1483 DALI_TEST_EQUALS(vector[1], 4, TEST_LOCATION);
1489 * this does not compile at the moment
1490 * Vector< Actor > classvector; this does not compile yet either
1495 bool gConstructorCalled = false;
1496 bool gDestructorCalled = false;
1502 gConstructorCalled = true;
1506 gDestructorCalled = true;
1510 } // anonymous namespace
1512 int UtcDaliVectorComplex( void)
1514 tet_infoline("Testing Dali::Vector< ComplexType > ");
1516 Vector< ComplexType > classvector;
1517 DALI_TEST_EQUALS( ZERO, classvector.Count(), TEST_LOCATION );
1518 DALI_TEST_EQUALS( ZERO, classvector.Capacity(), TEST_LOCATION );
1520 DALI_TEST_EQUALS( false, gConstructorCalled, TEST_LOCATION );
1521 DALI_TEST_EQUALS( false, gDestructorCalled, TEST_LOCATION );
1522 classvector.PushBack( ComplexType() );
1523 DALI_TEST_EQUALS( true, gConstructorCalled, TEST_LOCATION );
1524 classvector.Clear();
1525 DALI_TEST_EQUALS( true, gDestructorCalled, TEST_LOCATION );
1526 tet_result(TET_PASS); // for now