2 * Copyright (c) 2014 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.
20 #include <dali/public-api/dali-core.h>
21 #include <dali-test-suite-utils.h>
27 const Dali::VectorBase::SizeType ZERO(0);
30 int UtcDaliEmptyVectorInt(void)
32 tet_infoline("Testing Dali::Vector<int>");
34 Vector< int > intvector;
36 DALI_TEST_EQUALS( ZERO, intvector.Count(), TEST_LOCATION );
37 DALI_TEST_EQUALS( ZERO, intvector.Capacity(), TEST_LOCATION );
40 DALI_TEST_EQUALS( ZERO, intvector.Count(), TEST_LOCATION );
41 DALI_TEST_EQUALS( ZERO, intvector.Capacity(), TEST_LOCATION );
44 DALI_TEST_EQUALS( ZERO, intvector.Count(), TEST_LOCATION );
45 DALI_TEST_EQUALS( ZERO, intvector.Capacity(), TEST_LOCATION );
49 int UtcDaliVectorInt(void)
51 tet_infoline("Testing Dali::Vector<int>");
53 Vector< int > intvector;
55 DALI_TEST_EQUALS( ZERO, intvector.Count(), TEST_LOCATION );
56 DALI_TEST_EQUALS( ZERO, intvector.Capacity(), TEST_LOCATION );
58 intvector.PushBack( 11 );
59 DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(1), intvector.Count(), TEST_LOCATION );
60 DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(2), intvector.Capacity(), TEST_LOCATION );
61 DALI_TEST_EQUALS( 11, intvector[ 0 ], TEST_LOCATION );
63 intvector.PushBack( 99 );
64 DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(2), intvector.Count(), TEST_LOCATION );
65 DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(2), intvector.Capacity(), TEST_LOCATION );
66 DALI_TEST_EQUALS( 99, intvector[ 1 ], TEST_LOCATION );
68 intvector.PushBack( 34 );
69 DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(3), intvector.Count(), TEST_LOCATION );
70 DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(6), intvector.Capacity(), TEST_LOCATION );
71 DALI_TEST_EQUALS( 11, intvector[ 0 ], TEST_LOCATION );
72 DALI_TEST_EQUALS( 99, intvector[ 1 ], TEST_LOCATION );
73 DALI_TEST_EQUALS( 34, intvector[ 2 ], TEST_LOCATION );
76 DALI_TEST_EQUALS( ZERO, intvector.Count(), TEST_LOCATION );
77 DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(6), intvector.Capacity(), TEST_LOCATION );
78 intvector.PushBack( 123 );
79 DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(1), intvector.Count(), TEST_LOCATION );
80 DALI_TEST_EQUALS( 123, intvector[ 0 ], TEST_LOCATION );
84 int UtcDaliVectorIntCopy(void)
86 tet_infoline("Testing Dali::Vector<int>::Copy");
88 Vector< int > intvector;
89 DALI_TEST_EQUALS( ZERO, intvector.Count(), TEST_LOCATION );
90 DALI_TEST_EQUALS( ZERO, intvector.Capacity(), TEST_LOCATION );
92 intvector.PushBack( 99 );
93 intvector.PushBack( 11 );
94 intvector.PushBack( 34 );
97 Vector< int > intvector2( intvector );
99 DALI_TEST_EQUALS( intvector2.Count(), intvector.Count(), TEST_LOCATION );
100 DALI_TEST_EQUALS( intvector2.Capacity(), intvector.Capacity(), TEST_LOCATION );
101 DALI_TEST_EQUALS( intvector2[ 0 ], intvector[ 0 ], TEST_LOCATION );
102 DALI_TEST_EQUALS( intvector2[ 1 ], intvector[ 1 ], TEST_LOCATION );
103 DALI_TEST_EQUALS( intvector2[ 2 ], intvector[ 2 ], TEST_LOCATION );
106 Vector< int > intvector3;
107 DALI_TEST_EQUALS( ZERO, intvector3.Count(), TEST_LOCATION );
108 DALI_TEST_EQUALS( ZERO, intvector3.Capacity(), TEST_LOCATION );
109 intvector2 = intvector3;
110 DALI_TEST_EQUALS( intvector2.Count(), intvector3.Count(), TEST_LOCATION );
111 DALI_TEST_EQUALS( intvector2.Capacity(), intvector3.Capacity(), TEST_LOCATION );
114 Vector< int > intvector4;
115 intvector4.Reserve( 100 );
116 DALI_TEST_EQUALS( ZERO, intvector4.Count(), TEST_LOCATION );
117 DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(100), intvector4.Capacity(), TEST_LOCATION );
118 intvector3 = intvector4;
119 DALI_TEST_EQUALS( ZERO, intvector3.Count(), TEST_LOCATION );
120 DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(100), intvector3.Capacity(), TEST_LOCATION );
123 intvector4 = intvector4;
124 DALI_TEST_EQUALS( ZERO, intvector4.Count(), TEST_LOCATION );
125 DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(100), intvector4.Capacity(), TEST_LOCATION );
129 int UtcDaliVectorIntResize(void)
131 tet_infoline("Testing Dali::Vector<short>::Resize");
133 Vector< short > vector;
134 DALI_TEST_EQUALS( ZERO, vector.Count(), TEST_LOCATION );
135 DALI_TEST_EQUALS( ZERO, vector.Capacity(), TEST_LOCATION );
137 vector.Resize( 10u );
138 DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(10), vector.Count(), TEST_LOCATION );
139 DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(10), vector.Capacity(), TEST_LOCATION );
142 DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(4), vector.Count(), TEST_LOCATION );
143 DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(10), vector.Capacity(), TEST_LOCATION );
146 DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(4), vector.Count(), TEST_LOCATION );
147 DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(10), vector.Capacity(), TEST_LOCATION );
150 DALI_TEST_EQUALS( ZERO, vector.Count(), TEST_LOCATION );
151 DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(10), vector.Capacity(), TEST_LOCATION );
153 vector.Resize( 12u, 123 );
154 DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(12), vector.Count(), TEST_LOCATION );
155 DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(12), vector.Capacity(), TEST_LOCATION );
157 DALI_TEST_EQUALS( vector[ 0 ], 123, TEST_LOCATION );
158 DALI_TEST_EQUALS( vector[ 1 ], 123, TEST_LOCATION );
159 DALI_TEST_EQUALS( vector[ 2 ], 123, TEST_LOCATION );
160 DALI_TEST_EQUALS( vector[ 3 ], 123, TEST_LOCATION );
161 DALI_TEST_EQUALS( vector[ 4 ], 123, TEST_LOCATION );
162 DALI_TEST_EQUALS( vector[ 5 ], 123, TEST_LOCATION );
163 DALI_TEST_EQUALS( vector[ 6 ], 123, TEST_LOCATION );
164 DALI_TEST_EQUALS( vector[ 7 ], 123, TEST_LOCATION );
165 DALI_TEST_EQUALS( vector[ 8 ], 123, TEST_LOCATION );
166 DALI_TEST_EQUALS( vector[ 9 ], 123, TEST_LOCATION );
167 DALI_TEST_EQUALS( vector[ 10 ], 123, TEST_LOCATION );
168 DALI_TEST_EQUALS( vector[ 11 ], 123, TEST_LOCATION );
170 vector.Resize( 13u, 321 );
171 DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(13), vector.Count(), TEST_LOCATION );
172 DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(13), vector.Capacity(), TEST_LOCATION );
174 DALI_TEST_EQUALS( vector[ 0 ], 123, TEST_LOCATION );
175 DALI_TEST_EQUALS( vector[ 1 ], 123, TEST_LOCATION );
176 DALI_TEST_EQUALS( vector[ 2 ], 123, TEST_LOCATION );
177 DALI_TEST_EQUALS( vector[ 3 ], 123, TEST_LOCATION );
178 DALI_TEST_EQUALS( vector[ 4 ], 123, TEST_LOCATION );
179 DALI_TEST_EQUALS( vector[ 5 ], 123, TEST_LOCATION );
180 DALI_TEST_EQUALS( vector[ 6 ], 123, TEST_LOCATION );
181 DALI_TEST_EQUALS( vector[ 7 ], 123, TEST_LOCATION );
182 DALI_TEST_EQUALS( vector[ 8 ], 123, TEST_LOCATION );
183 DALI_TEST_EQUALS( vector[ 9 ], 123, TEST_LOCATION );
184 DALI_TEST_EQUALS( vector[ 10 ], 123, TEST_LOCATION );
185 DALI_TEST_EQUALS( vector[ 11 ], 123, TEST_LOCATION );
186 DALI_TEST_EQUALS( vector[ 12 ], 321, TEST_LOCATION );
190 int UtcDaliVectorIntErase(void)
192 tet_infoline("Testing Dali::Vector<short>::Erase");
194 Vector< char > vector;
195 DALI_TEST_EQUALS( ZERO, vector.Count(), TEST_LOCATION );
196 DALI_TEST_EQUALS( ZERO, vector.Capacity(), TEST_LOCATION );
197 vector.PushBack( 1 );
198 vector.PushBack( 2 );
199 vector.PushBack( 3 );
200 vector.PushBack( 4 );
201 vector.PushBack( 5 );
202 DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(5), vector.Count(), TEST_LOCATION );
203 DALI_TEST_EQUALS( vector[ 0 ], 1, TEST_LOCATION );
204 DALI_TEST_EQUALS( vector[ 1 ], 2, TEST_LOCATION );
205 DALI_TEST_EQUALS( vector[ 2 ], 3, TEST_LOCATION );
206 DALI_TEST_EQUALS( vector[ 3 ], 4, TEST_LOCATION );
207 DALI_TEST_EQUALS( vector[ 4 ], 5, TEST_LOCATION );
209 vector.Erase( vector.Begin() );
210 DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(4), vector.Count(), TEST_LOCATION );
211 DALI_TEST_EQUALS( vector[ 0 ], 2, TEST_LOCATION );
212 DALI_TEST_EQUALS( vector[ 1 ], 3, TEST_LOCATION );
213 DALI_TEST_EQUALS( vector[ 2 ], 4, TEST_LOCATION );
214 DALI_TEST_EQUALS( vector[ 3 ], 5, TEST_LOCATION );
216 Vector< char >::Iterator ret = vector.Erase( std::find( vector.Begin(), vector.End(), 4 ) );
217 DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(3), vector.Count(), TEST_LOCATION );
218 DALI_TEST_EQUALS( vector[ 0 ], 2, TEST_LOCATION );
219 DALI_TEST_EQUALS( vector[ 1 ], 3, TEST_LOCATION );
220 DALI_TEST_EQUALS( vector[ 2 ], 5, TEST_LOCATION );
221 DALI_TEST_EQUALS( *ret, 5, TEST_LOCATION );
224 vector.PushBack( 99 );
225 DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(4), vector.Count(), TEST_LOCATION );
226 DALI_TEST_EQUALS( vector[ 3 ], 99, TEST_LOCATION );
227 ret = vector.Erase( vector.End() - 1 );
228 DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(3), vector.Count(), TEST_LOCATION );
229 DALI_TEST_EQUALS( ret, vector.End(), TEST_LOCATION );
233 // illegal erase, one past the end
234 vector.Erase( vector.End() );
235 tet_result(TET_FAIL);
237 catch( Dali::DaliException& e )
239 DALI_TEST_PRINT_ASSERT( e );
240 DALI_TEST_ASSERT( e, "(iterator < End())", TEST_LOCATION );
244 tet_printf("Assertion test failed - wrong Exception\n" );
245 tet_result(TET_FAIL);
250 // illegal erase, one before the begin
251 vector.Erase( vector.Begin() - 1u );
252 tet_result(TET_FAIL);
254 catch( Dali::DaliException& e )
256 DALI_TEST_PRINT_ASSERT( e );
257 DALI_TEST_ASSERT( e, "(iterator < End()) && (iterator >= Begin())", TEST_LOCATION );
261 tet_printf("Assertion test failed - wrong Exception\n" );
262 tet_result(TET_FAIL);
266 DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(3), vector.Count(), TEST_LOCATION );
267 DALI_TEST_EQUALS( vector[ 0 ], 2, TEST_LOCATION );
268 DALI_TEST_EQUALS( vector[ 1 ], 3, TEST_LOCATION );
269 DALI_TEST_EQUALS( vector[ 2 ], 5, TEST_LOCATION );
271 vector.Erase( vector.Begin() + 1 );
272 DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(2), vector.Count(), TEST_LOCATION );
273 DALI_TEST_EQUALS( vector[ 0 ], 2, TEST_LOCATION );
274 DALI_TEST_EQUALS( vector[ 1 ], 5, TEST_LOCATION );
276 vector.Erase( vector.Begin() + 1 );
277 DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(1), vector.Count(), TEST_LOCATION );
278 DALI_TEST_EQUALS( vector[ 0 ], 2, TEST_LOCATION );
282 // illegal erase, one past the end
283 vector.Erase( vector.Begin() + 1 );
284 tet_result(TET_FAIL);
286 catch( Dali::DaliException& e )
288 DALI_TEST_PRINT_ASSERT( e );
289 DALI_TEST_ASSERT( e, "(iterator < End())", TEST_LOCATION );
293 tet_printf("Assertion test failed - wrong Exception\n" );
294 tet_result(TET_FAIL);
296 DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(1), vector.Count(), TEST_LOCATION );
297 DALI_TEST_EQUALS( vector[ 0 ], 2, TEST_LOCATION );
299 vector.Erase( vector.Begin() );
300 DALI_TEST_EQUALS( ZERO, vector.Count(), TEST_LOCATION );
304 // illegal erase, one before the beginning
305 vector.Erase( vector.Begin() - 1 );
306 tet_result(TET_FAIL);
308 catch( Dali::DaliException& e )
310 DALI_TEST_PRINT_ASSERT( e );
311 DALI_TEST_ASSERT( e, "(iterator < End())", TEST_LOCATION );
315 tet_printf("Assertion test failed - wrong Exception\n" );
316 tet_result(TET_FAIL);
319 DALI_TEST_EQUALS( ZERO, vector.Count(), TEST_LOCATION );
320 DALI_TEST_EQUALS( vector.Begin(), vector.End(), TEST_LOCATION );
322 Vector< char >::Iterator endIter = vector.End();
323 for( Vector< char >::Iterator iter = vector.Begin(); iter != endIter; ++iter )
325 tet_result(TET_FAIL);
328 vector.PushBack( 3 );
329 DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(1), vector.Count(), TEST_LOCATION );
332 DALI_TEST_EQUALS( ZERO, vector.Count(), TEST_LOCATION );
333 DALI_TEST_EQUALS( vector.Begin(), vector.End(), TEST_LOCATION );
335 endIter = vector.End();
336 for( Vector< char >::Iterator iter = vector.Begin(); iter != endIter; ++iter )
338 tet_result(TET_FAIL);
341 // test a vector of pointers
342 Vector< int* > ptrVector;
343 DALI_TEST_EQUALS( ZERO, ptrVector.Count(), TEST_LOCATION );
344 DALI_TEST_EQUALS( ptrVector.Begin(), ptrVector.End(), TEST_LOCATION );
347 ptrVector.PushBack( pointer );
348 DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(1), ptrVector.Count(), TEST_LOCATION );
350 Vector< int* >::Iterator ptriter = std::find( ptrVector.Begin(), ptrVector.End(), pointer );
351 ptriter = ptrVector.Erase( ptriter );
352 DALI_TEST_EQUALS( ZERO, ptrVector.Count(), TEST_LOCATION );
353 DALI_TEST_EQUALS( ptrVector.Begin(), ptrVector.End(), TEST_LOCATION );
354 DALI_TEST_EQUALS( ptrVector.Begin(), ptriter, TEST_LOCATION );
359 int UtcDaliVectorDoubleRemove(void)
361 tet_infoline("Testing Dali::Vector<double>::Remove");
363 Vector< double > vector;
364 DALI_TEST_EQUALS( ZERO, vector.Count(), TEST_LOCATION );
366 vector.PushBack( 11.1 );
367 vector.PushBack( 22.2 );
368 vector.PushBack( 33.3 );
369 vector.PushBack( 44.4 );
370 DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(4), vector.Count(), TEST_LOCATION );
371 DALI_TEST_EQUALS( vector[ 0 ], 11.1, TEST_LOCATION );
372 DALI_TEST_EQUALS( vector[ 1 ], 22.2, TEST_LOCATION );
373 DALI_TEST_EQUALS( vector[ 2 ], 33.3, TEST_LOCATION );
374 DALI_TEST_EQUALS( vector[ 3 ], 44.4, TEST_LOCATION );
376 Vector< double >::Iterator res = std::find( vector.Begin(), vector.End(), 22.2 );
377 DALI_TEST_EQUALS( 22.2, *res, TEST_LOCATION );
378 vector.Remove( res );
379 res = std::find( vector.Begin(), vector.End(), 22.2 );
380 DALI_TEST_EQUALS( vector.End(), res, TEST_LOCATION );
381 DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(3), vector.Count(), TEST_LOCATION );
382 DALI_TEST_EQUALS( vector[ 0 ], 11.1, TEST_LOCATION );
383 DALI_TEST_EQUALS( vector[ 1 ], 44.4, TEST_LOCATION );
384 DALI_TEST_EQUALS( vector[ 2 ], 33.3, TEST_LOCATION );
386 vector.Remove( vector.End() - 1 );
387 DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(2), vector.Count(), TEST_LOCATION );
388 DALI_TEST_EQUALS( vector[ 0 ], 11.1, TEST_LOCATION );
389 DALI_TEST_EQUALS( vector[ 1 ], 44.4, TEST_LOCATION );
391 vector.Remove( vector.Begin() );
392 DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(1), vector.Count(), TEST_LOCATION );
393 DALI_TEST_EQUALS( vector[ 0 ], 44.4, TEST_LOCATION );
397 // illegal erase, one past the end
398 vector.Remove( vector.Begin() + 1 );
399 tet_result(TET_FAIL);
401 catch( Dali::DaliException& e )
403 DALI_TEST_PRINT_ASSERT( e );
404 DALI_TEST_ASSERT( e, "(iterator < End()) && (iterator >= Begin())", TEST_LOCATION );
408 tet_printf("Assertion test failed - wrong Exception\n" );
409 tet_result(TET_FAIL);
411 DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(1), vector.Count(), TEST_LOCATION );
412 DALI_TEST_EQUALS( vector[ 0 ], 44.4, TEST_LOCATION );
414 vector.Remove( vector.Begin() );
415 DALI_TEST_EQUALS( ZERO, vector.Count(), TEST_LOCATION );
419 // illegal erase, one before the beginning
420 vector.Remove( vector.Begin() - 1 );
421 tet_result(TET_FAIL);
423 catch( Dali::DaliException& e )
425 DALI_TEST_PRINT_ASSERT( e );
426 DALI_TEST_ASSERT( e, "(iterator < End()) && (iterator >= Begin())", TEST_LOCATION );
430 tet_printf("Assertion test failed - wrong Exception\n" );
431 tet_result(TET_FAIL);
437 int UtcDaliVectorIntSwap(void)
439 tet_infoline("Testing Dali::Vector<int>::Swap");
441 Vector< int > intvector;
442 DALI_TEST_EQUALS( ZERO, intvector.Count(), TEST_LOCATION );
443 DALI_TEST_EQUALS( ZERO, intvector.Capacity(), TEST_LOCATION );
445 intvector.PushBack( 11 );
446 intvector.PushBack( 22 );
447 intvector.PushBack( 33 );
448 DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(3), intvector.Count(), TEST_LOCATION );
450 Vector< int > intvector2;
451 DALI_TEST_EQUALS( ZERO, intvector2.Count(), TEST_LOCATION );
452 DALI_TEST_EQUALS( ZERO, intvector2.Capacity(), TEST_LOCATION );
454 intvector2.Swap( intvector );
455 DALI_TEST_EQUALS( ZERO, intvector.Count(), TEST_LOCATION );
456 DALI_TEST_EQUALS( ZERO, intvector.Capacity(), TEST_LOCATION );
457 DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(3), intvector2.Count(), TEST_LOCATION );
458 DALI_TEST_EQUALS( 11, intvector2[ 0 ], TEST_LOCATION );
459 DALI_TEST_EQUALS( 22, intvector2[ 1 ], TEST_LOCATION );
460 DALI_TEST_EQUALS( 33, intvector2[ 2 ], TEST_LOCATION );
462 intvector.PushBack( 99 );
463 intvector.PushBack( 88 );
464 DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(2), intvector.Count(), TEST_LOCATION );
466 intvector.Swap( intvector2 );
467 DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(2), intvector2.Count(), TEST_LOCATION );
468 DALI_TEST_EQUALS( 99, intvector2[ 0 ], TEST_LOCATION );
469 DALI_TEST_EQUALS( 88, intvector2[ 1 ], TEST_LOCATION );
470 DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(3), intvector.Count(), TEST_LOCATION );
471 DALI_TEST_EQUALS( 11, intvector[ 0 ], TEST_LOCATION );
472 DALI_TEST_EQUALS( 22, intvector[ 1 ], TEST_LOCATION );
473 DALI_TEST_EQUALS( 33, intvector[ 2 ], TEST_LOCATION );
476 intvector.Swap( empty );
477 DALI_TEST_EQUALS( ZERO, intvector.Count(), TEST_LOCATION );
478 DALI_TEST_EQUALS( ZERO, intvector.Capacity(), TEST_LOCATION );
482 int UtcDaliVectorIterate(void)
484 tet_infoline("Testing Dali::Vector<float>::Begin");
486 Vector< float > floatvector;
487 DALI_TEST_EQUALS( ZERO, floatvector.Count(), TEST_LOCATION );
488 DALI_TEST_EQUALS( ZERO, floatvector.Capacity(), TEST_LOCATION );
490 floatvector.PushBack( 0.9f );
491 floatvector.PushBack( 1.1f );
492 floatvector.PushBack( 1.2f );
493 DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(3), floatvector.Count(), TEST_LOCATION );
495 Vector< float >::Iterator iter = floatvector.Begin();
497 for( ; iter != floatvector.End(); ++iter, ++index )
499 std::cout << "value " << *iter << std::endl;
500 DALI_TEST_EQUALS( *iter, floatvector[ index ], TEST_LOCATION );
502 DALI_TEST_EQUALS( 3, index, TEST_LOCATION );
504 iter = std::find( floatvector.Begin(), floatvector.End(), 1.1f );
505 DALI_TEST_EQUALS( 1.1f, *iter, TEST_LOCATION );
508 iter = std::find( floatvector.Begin(), floatvector.End(), 1.1f );
509 DALI_TEST_EQUALS( floatvector.End(), iter, TEST_LOCATION );
513 int UtcDaliVectorPair(void)
515 tet_infoline("Testing Dali::Vector< std::pair< int, float > >");
517 Vector< std::pair< int, float > > pairvector;
518 DALI_TEST_EQUALS( ZERO, pairvector.Count(), TEST_LOCATION );
519 DALI_TEST_EQUALS( ZERO, pairvector.Capacity(), TEST_LOCATION );
521 pairvector.PushBack( std::make_pair( 5, 0.1f ) );
522 pairvector.PushBack( std::make_pair( 3, 0.2f ) );
523 pairvector.PushBack( std::make_pair( 4, 0.3f ) );
524 pairvector.PushBack( std::make_pair( 1, 0.4f ) );
525 pairvector.PushBack( std::make_pair( 2, 0.5f ) );
526 DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(5), pairvector.Count(), TEST_LOCATION );
528 Vector< std::pair< int, float > >::Iterator iter = pairvector.Begin();
530 for( ; iter != pairvector.End(); ++iter, ++index )
532 std::cout << "pair " << (*iter).first << ":" << (*iter).second << std::endl;
533 DALI_TEST_EQUALS( (*iter).first, pairvector[ index ].first, TEST_LOCATION );
534 DALI_TEST_EQUALS( (*iter).second, pairvector[ index ].second, TEST_LOCATION );
539 int UtcDaliVectorAsserts(void)
541 tet_infoline("Testing Dali::Vector< int* > exception handling");
544 Vector< int* > pointervector;
548 pointervector[ 1 ] = value;
549 tet_printf("Assertion expected, but not occurred at %s\n", TEST_LOCATION );
550 tet_result(TET_FAIL);
552 catch(Dali::DaliException& e)
554 DALI_TEST_PRINT_ASSERT( e );
555 DALI_TEST_ASSERT( e, "VectorBase::mData", TEST_LOCATION );
559 tet_printf("Assertion test failed - wrong Exception\n" );
560 tet_result(TET_FAIL);
566 value = pointervector[ 0 ];
567 (void)value; // to "use" the value
568 tet_printf("Assertion expected, but not occurred at %s\n", TEST_LOCATION );
569 tet_result(TET_FAIL);
571 catch(Dali::DaliException& e)
573 DALI_TEST_PRINT_ASSERT( e );
574 DALI_TEST_ASSERT( e, "VectorBase::mData", TEST_LOCATION );
578 tet_printf("Assertion test failed - wrong Exception\n" );
579 tet_result(TET_FAIL);
582 Vector< int* >::Iterator iter = pointervector.Begin();
583 if( iter != pointervector.End() )
585 tet_result(TET_FAIL);
590 pointervector.Erase( pointervector.Begin() );
591 tet_printf("Assertion expected, but not occurred at %s\n", TEST_LOCATION );
592 tet_result(TET_FAIL);
594 catch(Dali::DaliException& e)
596 DALI_TEST_PRINT_ASSERT( e );
597 DALI_TEST_ASSERT( e, "(iterator < End()) && (iterator >= Begin())", TEST_LOCATION );
601 tet_printf("Assertion test failed - wrong Exception\n" );
602 tet_result(TET_FAIL);
605 iter = pointervector.Begin();
606 if( iter != pointervector.End() )
608 tet_result(TET_FAIL);
613 pointervector.Remove( pointervector.Begin() );
614 tet_printf("Assertion expected, but not occurred at %s\n", TEST_LOCATION );
615 tet_result(TET_FAIL);
617 catch(Dali::DaliException& e)
619 DALI_TEST_PRINT_ASSERT( e );
620 DALI_TEST_ASSERT( e, "(iterator < End()) && (iterator >= Begin())", TEST_LOCATION );
624 tet_printf("Assertion test failed - wrong Exception\n" );
625 tet_result(TET_FAIL);
628 iter = pointervector.Begin();
629 if( iter != pointervector.End() )
631 tet_result(TET_FAIL);
635 pointervector.Reserve( 0 );
636 iter = pointervector.Begin();
637 if( iter != pointervector.End() )
639 tet_result(TET_FAIL);
643 pointervector.Reserve( 1 );
644 iter = pointervector.Begin();
645 if( iter != pointervector.End() )
647 tet_result(TET_FAIL);
653 pointervector[ 1 ] = value;
654 tet_printf("Assertion expected, but not occurred at %s\n", TEST_LOCATION );
655 tet_result(TET_FAIL);
657 catch(Dali::DaliException& e)
659 DALI_TEST_PRINT_ASSERT( e );
660 DALI_TEST_ASSERT( e, "index < VectorBase::Count()", TEST_LOCATION );
664 tet_printf("Assertion test failed - wrong Exception\n" );
665 tet_result(TET_FAIL);
670 int* value = pointervector[ 1 ];
671 (void)value; // to "use" the value
672 tet_printf("Assertion expected, but not occurred at %s\n", TEST_LOCATION );
673 tet_result(TET_FAIL);
675 catch(Dali::DaliException& e)
677 DALI_TEST_PRINT_ASSERT( e );
678 DALI_TEST_ASSERT( e, "index < VectorBase::Count()", TEST_LOCATION );
682 tet_printf("Assertion test failed - wrong Exception\n" );
683 tet_result(TET_FAIL);
689 int UtcDaliVectorAcidTest(void)
691 tet_infoline("Testing multiple Dali::Vector's");
693 // create multiple vectors
694 Vector< std::pair< float, float > > pairvector;
695 DALI_TEST_EQUALS( ZERO, pairvector.Count(), TEST_LOCATION );
696 DALI_TEST_EQUALS( ZERO, pairvector.Capacity(), TEST_LOCATION );
697 Vector< double > doublevector;
698 DALI_TEST_EQUALS( ZERO, doublevector.Count(), TEST_LOCATION );
699 DALI_TEST_EQUALS( ZERO, doublevector.Capacity(), TEST_LOCATION );
700 Vector< int* > intptrvector;
701 DALI_TEST_EQUALS( ZERO, intptrvector.Count(), TEST_LOCATION );
702 DALI_TEST_EQUALS( ZERO, intptrvector.Capacity(), TEST_LOCATION );
703 Vector< Dali::Actor* > actorptrvector;
704 DALI_TEST_EQUALS( ZERO, actorptrvector.Count(), TEST_LOCATION );
705 DALI_TEST_EQUALS( ZERO, actorptrvector.Capacity(), TEST_LOCATION );
706 Vector< long > longvector;
707 DALI_TEST_EQUALS( ZERO, longvector.Count(), TEST_LOCATION );
708 DALI_TEST_EQUALS( ZERO, longvector.Capacity(), TEST_LOCATION );
709 Vector< char > charvector;
710 DALI_TEST_EQUALS( ZERO, charvector.Count(), TEST_LOCATION );
711 DALI_TEST_EQUALS( ZERO, charvector.Capacity(), TEST_LOCATION );
714 static unsigned int acidCount = 10000;
716 for( unsigned int i = 0; i < acidCount; ++i )
719 pairvector.PushBack( std::make_pair( i, i ) );
720 doublevector.PushBack( (double)i );
721 intptrvector.PushBack( (int*)ptr );
722 actorptrvector.PushBack( (Dali::Actor*)ptr );
723 longvector.PushBack( (long)i );
724 charvector.PushBack( (char)i );
726 DALI_TEST_EQUALS( acidCount, pairvector.Count(), TEST_LOCATION );
727 std::size_t pairCapacity = pairvector.Capacity();
728 DALI_TEST_EQUALS( acidCount, doublevector.Count(), TEST_LOCATION );
729 std::size_t doubleCapacity = doublevector.Capacity();
730 DALI_TEST_EQUALS( acidCount, intptrvector.Count(), TEST_LOCATION );
731 std::size_t intptrCapacity = intptrvector.Capacity();
732 DALI_TEST_EQUALS( acidCount, actorptrvector.Count(), TEST_LOCATION );
733 std::size_t actorptrCapacity = actorptrvector.Capacity();
734 DALI_TEST_EQUALS( acidCount, longvector.Count(), TEST_LOCATION );
735 std::size_t longCapacity = longvector.Capacity();
736 DALI_TEST_EQUALS( acidCount, charvector.Count(), TEST_LOCATION );
737 std::size_t charCapacity = charvector.Capacity();
739 tet_printf("Dali::Vector< pair > capacity after %d pushbacks is %d", acidCount, pairCapacity );
740 tet_printf("Dali::Vector< double > capacity after %d pushbacks is %d", acidCount, doubleCapacity );
741 tet_printf("Dali::Vector< int* > capacity after %d pushbacks is %d", acidCount, intptrCapacity );
742 tet_printf("Dali::Vector< Actor* > capacity after %d pushbacks is %d", acidCount, actorptrCapacity );
743 tet_printf("Dali::Vector< long > capacity after %d pushbacks is %d", acidCount, longCapacity );
744 tet_printf("Dali::Vector< char > capacity after %d pushbacks is %d", acidCount, charCapacity );
747 for( unsigned int i = 0; i < acidCount; ++i )
749 pairvector.Erase( pairvector.Begin() + ( i % pairvector.Count() ) );
750 doublevector.Erase( doublevector.Begin() + ( i % doublevector.Count() ) );
751 intptrvector.Erase( intptrvector.Begin() + ( i % intptrvector.Count() ) );
752 actorptrvector.Erase( actorptrvector.Begin() + ( i % actorptrvector.Count() ) );
753 longvector.Erase( longvector.Begin() + ( i % longvector.Count() ) );
754 charvector.Erase( charvector.Begin() + ( i % charvector.Count() ) );
756 DALI_TEST_EQUALS( ZERO, pairvector.Count(), TEST_LOCATION );
757 DALI_TEST_EQUALS( pairCapacity, pairvector.Capacity(), TEST_LOCATION );
758 DALI_TEST_EQUALS( ZERO, doublevector.Count(), TEST_LOCATION );
759 DALI_TEST_EQUALS( doubleCapacity, doublevector.Capacity(), TEST_LOCATION );
760 DALI_TEST_EQUALS( ZERO, intptrvector.Count(), TEST_LOCATION );
761 DALI_TEST_EQUALS( intptrCapacity, intptrvector.Capacity(), TEST_LOCATION );
762 DALI_TEST_EQUALS( ZERO, actorptrvector.Count(), TEST_LOCATION );
763 DALI_TEST_EQUALS( actorptrCapacity, actorptrvector.Capacity(), TEST_LOCATION );
764 DALI_TEST_EQUALS( ZERO, longvector.Count(), TEST_LOCATION );
765 DALI_TEST_EQUALS( longCapacity, longvector.Capacity(), TEST_LOCATION );
766 DALI_TEST_EQUALS( ZERO, charvector.Count(), TEST_LOCATION );
767 DALI_TEST_EQUALS( charCapacity, charvector.Capacity(), TEST_LOCATION );
772 int UtcDaliVectorPushBack(void)
774 tet_infoline( "Testing Dali::Vector< int* >PushBack(Element)" );
776 Vector<unsigned int> vector;
777 DALI_TEST_EQUALS( ZERO, vector.Count(), TEST_LOCATION );
778 DALI_TEST_EQUALS( ZERO, vector.Capacity(), TEST_LOCATION );
780 vector.Reserve( 2u );
781 DALI_TEST_EQUALS( ZERO, vector.Count(), TEST_LOCATION );
782 DALI_TEST_EQUALS( 2u, vector.Capacity(), TEST_LOCATION );
784 vector.PushBack( 0u );
785 vector.PushBack( 1u );
786 vector.PushBack( 2u );
788 DALI_TEST_EQUALS( 3u, vector.Count(), TEST_LOCATION );
789 DALI_TEST_EQUALS( 6u, vector.Capacity(), TEST_LOCATION );
791 vector.PushBack( 3u );
793 DALI_TEST_EQUALS( 4u, vector.Count(), TEST_LOCATION );
794 DALI_TEST_EQUALS( 6u, vector.Capacity(), TEST_LOCATION );
796 DALI_TEST_EQUALS( 0u, vector[0u], TEST_LOCATION );
797 DALI_TEST_EQUALS( 1u, vector[1u], TEST_LOCATION );
798 DALI_TEST_EQUALS( 2u, vector[2u], TEST_LOCATION );
799 DALI_TEST_EQUALS( 3u, vector[3u], TEST_LOCATION );
804 int UtcDaliVectorInsert01(void)
806 tet_infoline( "Testing Dali::Vector< int* >Insert(Iterator, Element)" );
808 // Test order of array inserted-into:
809 Vector< unsigned int > orderedVector;
810 orderedVector.PushBack( 9u );
811 for( unsigned int i = 8u; i <= 8u; --i )
813 orderedVector.Insert( orderedVector.Begin(), i );
814 DALI_TEST_EQUALS( 10u - i, orderedVector.Count(), TEST_LOCATION );
815 DALI_TEST_EQUALS( i, orderedVector[0u], TEST_LOCATION );
818 for( unsigned int i = 0u; i < 10u; ++i )
820 DALI_TEST_EQUALS( i, orderedVector[i], TEST_LOCATION );
823 // Test insertion out of range in non-empty array throws:
826 orderedVector.Insert( orderedVector.Begin() + 99u, 99u );
827 tet_printf( "Assertion expected, but not occurred at %s\n", TEST_LOCATION );
828 tet_result( TET_FAIL );
830 catch( Dali::DaliException& e )
832 DALI_TEST_PRINT_ASSERT( e );
833 DALI_TEST_ASSERT( e, "( at <= End() ) && ( at >= Begin() )", TEST_LOCATION );
837 tet_printf( "Assertion test failed - wrong Exception\n" );
838 tet_result( TET_FAIL );
843 orderedVector.Insert( orderedVector.Begin() - 1u, 99u );
844 tet_printf( "Assertion expected, but not occurred at %s\n", TEST_LOCATION );
845 tet_result( TET_FAIL );
847 catch( Dali::DaliException& e )
849 DALI_TEST_PRINT_ASSERT( e );
850 DALI_TEST_ASSERT( e, "( at <= End() ) && ( at >= Begin() )", TEST_LOCATION );
854 tet_printf( "Assertion test failed - wrong Exception\n" );
855 tet_result( TET_FAIL );
858 // Test insertion part-way through a largish array retains ordering:
860 // Build vector with hole in sequence:
861 Vector< unsigned int > longerVector;
862 const unsigned int insertionPoint = 131571u;
863 const unsigned int finalLength = 262143u;
864 for( unsigned int i = 0u; i < insertionPoint; ++i )
866 longerVector.PushBack( i );
868 for( unsigned int i = insertionPoint; i < finalLength; ++i )
870 longerVector.PushBack( i + 1 );
873 // Fill the hole in the sequence:
874 longerVector.Insert( longerVector.Begin() + insertionPoint, insertionPoint );
876 // Check the sequence is monotonically increasing by one every time:
877 for( unsigned int i = 0u; i <= finalLength; ++i )
879 DALI_TEST_EQUALS( i, longerVector[i], TEST_LOCATION );
882 // Insert into an empty vector
883 Vector< unsigned int > vector;
885 vector.Insert( vector.End(), orderedVector.Begin(), orderedVector.End() );
886 for( unsigned int i = 0u; i < 10u; ++i )
888 DALI_TEST_EQUALS( i, vector[i], TEST_LOCATION );
892 vector.Insert( vector.Begin(), orderedVector.Begin(), orderedVector.End() );
893 for( unsigned int i = 0u; i < 10u; ++i )
895 DALI_TEST_EQUALS( i, vector[i], TEST_LOCATION );
899 vector.Insert( vector.Begin(), orderedVector.Begin(), orderedVector.Begin() );
900 for( unsigned int i = 0u; i < 10u; ++i )
902 DALI_TEST_EQUALS( i, vector[i], TEST_LOCATION );
905 vector.Insert( vector.Begin() + 5, vector.Begin() + 5, vector.Begin() + 5 );
906 for( unsigned int i = 0u; i < 10u; ++i )
908 DALI_TEST_EQUALS( i, vector[i], TEST_LOCATION );
913 vector.PushBack( 0u );
914 vector.PushBack( 1u );
915 vector.PushBack( 2u );
916 vector.PushBack( 3u );
918 vector.Insert( vector.Begin() + 2, vector.Begin(), vector.End() );
919 DALI_TEST_EQUALS( 8u, vector.Count(), TEST_LOCATION );
920 DALI_TEST_EQUALS( 0u, vector[0u], TEST_LOCATION );
921 DALI_TEST_EQUALS( 1u, vector[1u], TEST_LOCATION );
922 DALI_TEST_EQUALS( 0u, vector[2u], TEST_LOCATION );
923 DALI_TEST_EQUALS( 1u, vector[3u], TEST_LOCATION );
924 DALI_TEST_EQUALS( 2u, vector[4u], TEST_LOCATION );
925 DALI_TEST_EQUALS( 3u, vector[5u], TEST_LOCATION );
926 DALI_TEST_EQUALS( 2u, vector[6u], TEST_LOCATION );
927 DALI_TEST_EQUALS( 3u, vector[7u], TEST_LOCATION );
932 int UtcDaliVectorInsert02(void)
934 tet_infoline("Testing Dali::Vector<char>::Insert(Iterator,Iterator,Iterator)");
936 Vector< char > vector;
937 DALI_TEST_EQUALS( ZERO, vector.Count(), TEST_LOCATION );
938 DALI_TEST_EQUALS( ZERO, vector.Capacity(), TEST_LOCATION );
939 vector.PushBack( 1 );
940 vector.PushBack( 2 );
941 vector.PushBack( 3 );
942 vector.PushBack( 4 );
943 vector.PushBack( 5 );
945 Vector< char > vector2;
946 DALI_TEST_EQUALS( ZERO, vector2.Count(), TEST_LOCATION );
947 DALI_TEST_EQUALS( ZERO, vector2.Capacity(), TEST_LOCATION );
948 vector2.PushBack( 6 );
949 vector2.PushBack( 7 );
950 vector2.PushBack( 8 );
951 vector2.PushBack( 9 );
952 vector2.PushBack( 10 );
954 // Test insert at end
955 vector.Insert( vector.End(), vector2.Begin(), vector2.Begin() + 1u );
956 DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(6), vector.Count(), TEST_LOCATION );
957 DALI_TEST_EQUALS( vector[ 0 ], 1, TEST_LOCATION );
958 DALI_TEST_EQUALS( vector[ 1 ], 2, TEST_LOCATION );
959 DALI_TEST_EQUALS( vector[ 2 ], 3, TEST_LOCATION );
960 DALI_TEST_EQUALS( vector[ 3 ], 4, TEST_LOCATION );
961 DALI_TEST_EQUALS( vector[ 4 ], 5, TEST_LOCATION );
962 DALI_TEST_EQUALS( vector[ 5 ], 6, TEST_LOCATION );
964 // Test insert at begin
965 vector.Insert( vector.Begin(), vector2.Begin()+1, vector2.Begin() + 2u );
966 DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(7), vector.Count(), TEST_LOCATION );
967 DALI_TEST_EQUALS( vector[ 0 ], 7, TEST_LOCATION );
968 DALI_TEST_EQUALS( vector[ 1 ], 1, TEST_LOCATION );
969 DALI_TEST_EQUALS( vector[ 2 ], 2, TEST_LOCATION );
970 DALI_TEST_EQUALS( vector[ 3 ], 3, TEST_LOCATION );
971 DALI_TEST_EQUALS( vector[ 4 ], 4, TEST_LOCATION );
972 DALI_TEST_EQUALS( vector[ 5 ], 5, TEST_LOCATION );
973 DALI_TEST_EQUALS( vector[ 6 ], 6, TEST_LOCATION );
975 // Test insert in the middle
976 vector.Insert( vector.Begin() + 3, vector2.Begin()+3, vector2.End() );
977 DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(9), 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 ], 9, TEST_LOCATION );
982 DALI_TEST_EQUALS( vector[ 4 ], 10, TEST_LOCATION );
983 DALI_TEST_EQUALS( vector[ 5 ], 3, TEST_LOCATION );
984 DALI_TEST_EQUALS( vector[ 6 ], 4, TEST_LOCATION );
985 DALI_TEST_EQUALS( vector[ 7 ], 5, TEST_LOCATION );
986 DALI_TEST_EQUALS( vector[ 8 ], 6, TEST_LOCATION );
990 int UtcDaliVectorIntInsertAssert(void)
992 tet_infoline("Testing Dali::Vector<char>::Insert(Iterator,Iterator,Iterator) asserts");
994 Vector< char > vector;
995 DALI_TEST_EQUALS( ZERO, vector.Count(), TEST_LOCATION );
996 DALI_TEST_EQUALS( ZERO, vector.Capacity(), TEST_LOCATION );
997 vector.PushBack( 1 );
998 vector.PushBack( 2 );
1000 Vector< char > vector2;
1001 DALI_TEST_EQUALS( ZERO, vector2.Count(), TEST_LOCATION );
1002 DALI_TEST_EQUALS( ZERO, vector2.Capacity(), TEST_LOCATION );
1003 vector2.PushBack( 6 );
1004 vector2.PushBack( 7 );
1005 vector2.PushBack( 8 );
1006 vector2.PushBack( 9 );
1007 vector2.PushBack( 10 );
1011 vector.Insert( vector.Begin() + 3u, vector2.Begin(), vector2.End() );
1012 tet_result(TET_FAIL);
1014 catch( Dali::DaliException& e )
1016 DALI_TEST_PRINT_ASSERT( e );
1017 DALI_TEST_ASSERT( e, "( at <= End() ) && ( at >= Begin() )", TEST_LOCATION );
1021 tet_printf("Assertion test failed - wrong Exception\n" );
1022 tet_result(TET_FAIL);
1027 vector.Insert( vector.Begin() - 1u, vector2.Begin(), vector2.End() );
1028 tet_result(TET_FAIL);
1030 catch( Dali::DaliException& e )
1032 DALI_TEST_PRINT_ASSERT( e );
1033 DALI_TEST_ASSERT( e, "( at <= End() ) && ( at >= Begin() )", TEST_LOCATION );
1037 tet_printf("Assertion test failed - wrong Exception\n" );
1038 tet_result(TET_FAIL);
1043 vector.Insert( vector.End(), vector2.End(), vector2.Begin() );
1044 tet_result(TET_FAIL);
1046 catch( Dali::DaliException& e )
1048 DALI_TEST_PRINT_ASSERT( e );
1049 DALI_TEST_ASSERT( e, "( from <= to )", TEST_LOCATION );
1053 tet_printf("Assertion test failed - wrong Exception\n" );
1054 tet_result(TET_FAIL);
1061 int UtcDaliVectorIntEraseRange(void)
1063 tet_infoline("Testing Dali::Vector<char>::Erase(Iterator,Iterator)");
1065 Vector< char > vector;
1066 DALI_TEST_EQUALS( ZERO, vector.Count(), TEST_LOCATION );
1067 DALI_TEST_EQUALS( ZERO, vector.Capacity(), TEST_LOCATION );
1069 // Try to delete from empty vector.
1071 vector.Erase( vector.Begin(), vector.End() );
1072 DALI_TEST_EQUALS( ZERO, vector.Count(), TEST_LOCATION );
1073 DALI_TEST_EQUALS( ZERO, vector.Capacity(), TEST_LOCATION );
1075 vector.PushBack( 1 );
1076 vector.PushBack( 2 );
1077 vector.PushBack( 3 );
1078 vector.PushBack( 4 );
1079 vector.PushBack( 5 );
1080 DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(5), vector.Count(), TEST_LOCATION );
1081 DALI_TEST_EQUALS( vector[ 0 ], 1, TEST_LOCATION );
1082 DALI_TEST_EQUALS( vector[ 1 ], 2, TEST_LOCATION );
1083 DALI_TEST_EQUALS( vector[ 2 ], 3, TEST_LOCATION );
1084 DALI_TEST_EQUALS( vector[ 3 ], 4, TEST_LOCATION );
1085 DALI_TEST_EQUALS( vector[ 4 ], 5, TEST_LOCATION );
1087 Vector< char >::Iterator ret;
1089 ret = vector.Erase( vector.Begin() + 1u, vector.Begin() + 2u );
1090 DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(4), vector.Count(), TEST_LOCATION );
1091 DALI_TEST_EQUALS( vector[ 0 ], 1, TEST_LOCATION );
1092 DALI_TEST_EQUALS( vector[ 1 ], 3, TEST_LOCATION );
1093 DALI_TEST_EQUALS( vector[ 2 ], 4, TEST_LOCATION );
1094 DALI_TEST_EQUALS( vector[ 3 ], 5, TEST_LOCATION );
1095 DALI_TEST_EQUALS( *ret, 3, TEST_LOCATION );
1097 ret = vector.Erase( vector.Begin(), vector.Begin() + 2 );
1098 DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(2), vector.Count(), TEST_LOCATION );
1099 DALI_TEST_EQUALS( vector[ 0 ], 4, TEST_LOCATION );
1100 DALI_TEST_EQUALS( vector[ 1 ], 5, TEST_LOCATION );
1101 DALI_TEST_EQUALS( *ret, 4, TEST_LOCATION );
1104 vector.PushBack( 99 );
1105 DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(3), vector.Count(), TEST_LOCATION );
1106 DALI_TEST_EQUALS( vector[ 2 ], 99, TEST_LOCATION );
1107 ret = vector.Erase( vector.Begin() + 1u, vector.End() );
1108 DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(1), vector.Count(), TEST_LOCATION );
1109 DALI_TEST_EQUALS( vector[ 0 ], 4, TEST_LOCATION );
1110 DALI_TEST_EQUALS( ret, vector.End(), TEST_LOCATION );
1113 vector.PushBack( 100 );
1114 vector.PushBack( 101 );
1115 vector.PushBack( 102 );
1117 DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(4), vector.Count(), TEST_LOCATION );
1118 DALI_TEST_EQUALS( vector[ 0 ], 4, TEST_LOCATION );
1119 DALI_TEST_EQUALS( vector[ 1 ], 100, TEST_LOCATION );
1120 DALI_TEST_EQUALS( vector[ 2 ], 101, TEST_LOCATION );
1121 DALI_TEST_EQUALS( vector[ 3 ], 102, TEST_LOCATION );
1123 ret = vector.Erase( vector.Begin(), vector.End() );
1124 DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(0), vector.Count(), TEST_LOCATION );
1125 DALI_TEST_EQUALS( ret, vector.End(), TEST_LOCATION );
1127 // try erase from Iterator to the same Iterator.
1128 vector.PushBack( 100 );
1129 vector.PushBack( 101 );
1130 vector.PushBack( 102 );
1132 DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(3), vector.Count(), TEST_LOCATION );
1133 DALI_TEST_EQUALS( vector[ 0 ], 100, TEST_LOCATION );
1134 DALI_TEST_EQUALS( vector[ 1 ], 101, TEST_LOCATION );
1135 DALI_TEST_EQUALS( vector[ 2 ], 102, TEST_LOCATION );
1137 ret = vector.Erase( vector.Begin() + 1, vector.Begin() + 1 );
1139 DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(3), vector.Count(), TEST_LOCATION );
1140 DALI_TEST_EQUALS( vector[ 0 ], 100, TEST_LOCATION );
1141 DALI_TEST_EQUALS( vector[ 1 ], 101, TEST_LOCATION );
1142 DALI_TEST_EQUALS( vector[ 2 ], 102, TEST_LOCATION );
1144 DALI_TEST_EQUALS( *ret, 101, TEST_LOCATION );
1149 int UtcDaliVectorIntEraseRangeAssert(void)
1151 tet_infoline("Testing Dali::Vector<char>::Erase(Iterator,Iterator) asserts");
1153 Vector< char > vector;
1154 DALI_TEST_EQUALS( ZERO, vector.Count(), TEST_LOCATION );
1155 DALI_TEST_EQUALS( ZERO, vector.Capacity(), TEST_LOCATION );
1158 // Add some elements.
1159 vector.PushBack( 1 );
1160 vector.PushBack( 2 );
1162 // first out of bounds
1165 vector.Erase( vector.Begin() + 3u, vector.Begin() + 4u );
1166 tet_printf( "Assertion expected, but not occurred at %s\n", TEST_LOCATION );
1167 tet_result(TET_FAIL);
1169 catch( Dali::DaliException& e )
1171 DALI_TEST_PRINT_ASSERT( e );
1172 DALI_TEST_ASSERT( e, "( first <= End() ) && ( first >= Begin() )", TEST_LOCATION );
1176 tet_printf("Assertion test failed - wrong Exception\n" );
1177 tet_result(TET_FAIL);
1182 vector.Erase( vector.Begin() - 1u, vector.End() );
1183 tet_printf( "Assertion expected, but not occurred at %s\n", TEST_LOCATION );
1184 tet_result(TET_FAIL);
1186 catch( Dali::DaliException& e )
1188 DALI_TEST_PRINT_ASSERT( e );
1189 DALI_TEST_ASSERT( e, "( first <= End() ) && ( first >= Begin() )", TEST_LOCATION );
1193 tet_printf("Assertion test failed - wrong Exception\n" );
1194 tet_result(TET_FAIL);
1197 // last out of bounds
1201 vector.Erase( vector.Begin(), vector.Begin() + 3u );
1202 tet_printf( "Assertion expected, but not occurred at %s\n", TEST_LOCATION );
1203 tet_result(TET_FAIL);
1205 catch( Dali::DaliException& e )
1207 DALI_TEST_PRINT_ASSERT( e );
1208 DALI_TEST_ASSERT( e, "( last <= End() ) && ( last >= Begin() )", TEST_LOCATION );
1212 tet_printf("Assertion test failed - wrong Exception\n" );
1213 tet_result(TET_FAIL);
1218 vector.Erase( vector.Begin(), vector.Begin() - 1u );
1219 tet_printf( "Assertion expected, but not occurred at %s\n", TEST_LOCATION );
1220 tet_result(TET_FAIL);
1222 catch( Dali::DaliException& e )
1224 DALI_TEST_PRINT_ASSERT( e );
1225 DALI_TEST_ASSERT( e, "( last <= End() ) && ( last >= Begin() )", TEST_LOCATION );
1229 tet_printf("Assertion test failed - wrong Exception\n" );
1230 tet_result(TET_FAIL);
1233 vector.PushBack( 3 );
1238 vector.Erase( vector.Begin() + 2u, vector.Begin() + 1u );
1239 tet_printf( "Assertion expected, but not occurred at %s\n", TEST_LOCATION );
1240 tet_result(TET_FAIL);
1242 catch( Dali::DaliException& e )
1244 DALI_TEST_PRINT_ASSERT( e );
1245 DALI_TEST_ASSERT( e, "( first <= last )", TEST_LOCATION );
1249 tet_printf("Assertion test failed - wrong Exception\n" );
1250 tet_result(TET_FAIL);
1259 bool gConstructorCalled = false;
1260 bool gDestructorCalled = false;
1266 gConstructorCalled = true;
1270 gDestructorCalled = true;
1274 } // anonymous namespace
1277 int UtcDaliVectorComplex(void)
1279 tet_infoline("Testing Dali::Vector< int* > exception handling");
1281 // this does not compile at the moment
1282 /* Vector< ComplexType > classvector;
1283 DALI_TEST_EQUALS( ZERO, classvector.Count(), TEST_LOCATION );
1284 DALI_TEST_EQUALS( ZERO, classvector.Capacity(), TEST_LOCATION );
1286 DALI_TEST_EQUALS( false, gConstructorCalled, TEST_LOCATION );
1287 DALI_TEST_EQUALS( false, gDestructorCalled, TEST_LOCATION );
1288 classvector.PushBack( ComplexType() );
1289 DALI_TEST_EQUALS( true, gConstructorCalled, TEST_LOCATION );
1290 classvector.Clear();
1291 DALI_TEST_EQUALS( true, gDestructorCalled, TEST_LOCATION );
1293 // Vector< Actor > classvector; this does not compile yet either
1294 tet_result(TET_PASS); // for now