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.
18 #define ENABLE_VECTOR_ASSERTS
22 #include <dali/public-api/dali-core.h>
23 #include <dali-test-suite-utils.h>
29 const Dali::VectorBase::SizeType ZERO(0);
32 int UtcDaliEmptyVectorInt(void)
34 tet_infoline("Testing Dali::Vector<int>");
36 Vector< int > intvector;
38 DALI_TEST_EQUALS( ZERO, intvector.Count(), TEST_LOCATION );
39 DALI_TEST_EQUALS( ZERO, intvector.Capacity(), TEST_LOCATION );
42 DALI_TEST_EQUALS( ZERO, intvector.Count(), TEST_LOCATION );
43 DALI_TEST_EQUALS( ZERO, intvector.Capacity(), TEST_LOCATION );
46 DALI_TEST_EQUALS( ZERO, intvector.Count(), TEST_LOCATION );
47 DALI_TEST_EQUALS( ZERO, intvector.Capacity(), TEST_LOCATION );
51 int UtcDaliVectorInt(void)
53 tet_infoline("Testing Dali::Vector<int>");
55 Vector< int > intvector;
57 DALI_TEST_EQUALS( ZERO, intvector.Count(), TEST_LOCATION );
58 DALI_TEST_EQUALS( ZERO, intvector.Capacity(), TEST_LOCATION );
60 intvector.PushBack( 11 );
61 DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(1), intvector.Count(), TEST_LOCATION );
62 DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(2), intvector.Capacity(), TEST_LOCATION );
63 DALI_TEST_EQUALS( 11, intvector[ 0 ], TEST_LOCATION );
65 intvector.PushBack( 99 );
66 DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(2), intvector.Count(), TEST_LOCATION );
67 DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(2), intvector.Capacity(), TEST_LOCATION );
68 DALI_TEST_EQUALS( 99, intvector[ 1 ], TEST_LOCATION );
70 intvector.PushBack( 34 );
71 DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(3), intvector.Count(), TEST_LOCATION );
72 DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(6), intvector.Capacity(), TEST_LOCATION );
73 DALI_TEST_EQUALS( 11, intvector[ 0 ], TEST_LOCATION );
74 DALI_TEST_EQUALS( 99, intvector[ 1 ], TEST_LOCATION );
75 DALI_TEST_EQUALS( 34, intvector[ 2 ], TEST_LOCATION );
78 DALI_TEST_EQUALS( ZERO, intvector.Count(), TEST_LOCATION );
79 DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(6), intvector.Capacity(), TEST_LOCATION );
80 intvector.PushBack( 123 );
81 DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(1), intvector.Count(), TEST_LOCATION );
82 DALI_TEST_EQUALS( 123, intvector[ 0 ], TEST_LOCATION );
86 int UtcDaliVectorIntCopy(void)
88 tet_infoline("Testing Dali::Vector<int>::Copy");
90 Vector< int > intvector;
91 DALI_TEST_EQUALS( ZERO, intvector.Count(), TEST_LOCATION );
92 DALI_TEST_EQUALS( ZERO, intvector.Capacity(), TEST_LOCATION );
94 intvector.PushBack( 99 );
95 intvector.PushBack( 11 );
96 intvector.PushBack( 34 );
99 Vector< int > intvector2( intvector );
101 DALI_TEST_EQUALS( intvector2.Count(), intvector.Count(), TEST_LOCATION );
102 DALI_TEST_EQUALS( intvector2.Capacity(), intvector.Capacity(), TEST_LOCATION );
103 DALI_TEST_EQUALS( intvector2[ 0 ], intvector[ 0 ], TEST_LOCATION );
104 DALI_TEST_EQUALS( intvector2[ 1 ], intvector[ 1 ], TEST_LOCATION );
105 DALI_TEST_EQUALS( intvector2[ 2 ], intvector[ 2 ], TEST_LOCATION );
108 Vector< int > intvector3;
109 DALI_TEST_EQUALS( ZERO, intvector3.Count(), TEST_LOCATION );
110 DALI_TEST_EQUALS( ZERO, intvector3.Capacity(), TEST_LOCATION );
111 intvector2 = intvector3;
112 DALI_TEST_EQUALS( intvector2.Count(), intvector3.Count(), TEST_LOCATION );
113 DALI_TEST_EQUALS( intvector2.Capacity(), intvector3.Capacity(), TEST_LOCATION );
116 Vector< int > intvector4;
117 intvector4.Reserve( 100 );
118 DALI_TEST_EQUALS( ZERO, intvector4.Count(), TEST_LOCATION );
119 DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(100), intvector4.Capacity(), TEST_LOCATION );
120 intvector3 = intvector4;
121 DALI_TEST_EQUALS( ZERO, intvector3.Count(), TEST_LOCATION );
122 DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(100), intvector3.Capacity(), TEST_LOCATION );
125 intvector4 = intvector4;
126 DALI_TEST_EQUALS( ZERO, intvector4.Count(), TEST_LOCATION );
127 DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(100), intvector4.Capacity(), TEST_LOCATION );
131 int UtcDaliVectorIntResize(void)
133 tet_infoline("Testing Dali::Vector<short>::Resize");
135 Vector< short > vector;
136 DALI_TEST_EQUALS( ZERO, vector.Count(), TEST_LOCATION );
137 DALI_TEST_EQUALS( ZERO, vector.Capacity(), TEST_LOCATION );
139 vector.Resize( 10u );
140 DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(10), vector.Count(), TEST_LOCATION );
141 DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(10), vector.Capacity(), TEST_LOCATION );
144 DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(4), vector.Count(), TEST_LOCATION );
145 DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(10), vector.Capacity(), TEST_LOCATION );
148 DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(4), vector.Count(), TEST_LOCATION );
149 DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(10), vector.Capacity(), TEST_LOCATION );
152 DALI_TEST_EQUALS( ZERO, vector.Count(), TEST_LOCATION );
153 DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(10), vector.Capacity(), TEST_LOCATION );
155 vector.Resize( 12u, 123 );
156 DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(12), vector.Count(), TEST_LOCATION );
157 DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(12), vector.Capacity(), TEST_LOCATION );
159 DALI_TEST_EQUALS( vector[ 0 ], 123, TEST_LOCATION );
160 DALI_TEST_EQUALS( vector[ 1 ], 123, TEST_LOCATION );
161 DALI_TEST_EQUALS( vector[ 2 ], 123, TEST_LOCATION );
162 DALI_TEST_EQUALS( vector[ 3 ], 123, TEST_LOCATION );
163 DALI_TEST_EQUALS( vector[ 4 ], 123, TEST_LOCATION );
164 DALI_TEST_EQUALS( vector[ 5 ], 123, TEST_LOCATION );
165 DALI_TEST_EQUALS( vector[ 6 ], 123, TEST_LOCATION );
166 DALI_TEST_EQUALS( vector[ 7 ], 123, TEST_LOCATION );
167 DALI_TEST_EQUALS( vector[ 8 ], 123, TEST_LOCATION );
168 DALI_TEST_EQUALS( vector[ 9 ], 123, TEST_LOCATION );
169 DALI_TEST_EQUALS( vector[ 10 ], 123, TEST_LOCATION );
170 DALI_TEST_EQUALS( vector[ 11 ], 123, TEST_LOCATION );
172 vector.Resize( 13u, 321 );
173 DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(13), vector.Count(), TEST_LOCATION );
174 DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(13), vector.Capacity(), TEST_LOCATION );
176 DALI_TEST_EQUALS( vector[ 0 ], 123, TEST_LOCATION );
177 DALI_TEST_EQUALS( vector[ 1 ], 123, TEST_LOCATION );
178 DALI_TEST_EQUALS( vector[ 2 ], 123, TEST_LOCATION );
179 DALI_TEST_EQUALS( vector[ 3 ], 123, TEST_LOCATION );
180 DALI_TEST_EQUALS( vector[ 4 ], 123, TEST_LOCATION );
181 DALI_TEST_EQUALS( vector[ 5 ], 123, TEST_LOCATION );
182 DALI_TEST_EQUALS( vector[ 6 ], 123, TEST_LOCATION );
183 DALI_TEST_EQUALS( vector[ 7 ], 123, TEST_LOCATION );
184 DALI_TEST_EQUALS( vector[ 8 ], 123, TEST_LOCATION );
185 DALI_TEST_EQUALS( vector[ 9 ], 123, TEST_LOCATION );
186 DALI_TEST_EQUALS( vector[ 10 ], 123, TEST_LOCATION );
187 DALI_TEST_EQUALS( vector[ 11 ], 123, TEST_LOCATION );
188 DALI_TEST_EQUALS( vector[ 12 ], 321, TEST_LOCATION );
192 int UtcDaliVectorIntErase(void)
194 tet_infoline("Testing Dali::Vector<short>::Erase");
196 Vector< char > vector;
197 DALI_TEST_EQUALS( ZERO, vector.Count(), TEST_LOCATION );
198 DALI_TEST_EQUALS( ZERO, vector.Capacity(), TEST_LOCATION );
199 vector.PushBack( 1 );
200 vector.PushBack( 2 );
201 vector.PushBack( 3 );
202 vector.PushBack( 4 );
203 vector.PushBack( 5 );
204 DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(5), vector.Count(), TEST_LOCATION );
205 DALI_TEST_EQUALS( vector[ 0 ], 1, TEST_LOCATION );
206 DALI_TEST_EQUALS( vector[ 1 ], 2, TEST_LOCATION );
207 DALI_TEST_EQUALS( vector[ 2 ], 3, TEST_LOCATION );
208 DALI_TEST_EQUALS( vector[ 3 ], 4, TEST_LOCATION );
209 DALI_TEST_EQUALS( vector[ 4 ], 5, TEST_LOCATION );
211 vector.Erase( vector.Begin() );
212 DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(4), vector.Count(), TEST_LOCATION );
213 DALI_TEST_EQUALS( vector[ 0 ], 2, TEST_LOCATION );
214 DALI_TEST_EQUALS( vector[ 1 ], 3, TEST_LOCATION );
215 DALI_TEST_EQUALS( vector[ 2 ], 4, TEST_LOCATION );
216 DALI_TEST_EQUALS( vector[ 3 ], 5, TEST_LOCATION );
218 Vector< char >::Iterator ret = vector.Erase( std::find( vector.Begin(), vector.End(), 4 ) );
219 DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(3), vector.Count(), TEST_LOCATION );
220 DALI_TEST_EQUALS( vector[ 0 ], 2, TEST_LOCATION );
221 DALI_TEST_EQUALS( vector[ 1 ], 3, TEST_LOCATION );
222 DALI_TEST_EQUALS( vector[ 2 ], 5, TEST_LOCATION );
223 DALI_TEST_EQUALS( *ret, 5, TEST_LOCATION );
226 vector.PushBack( 99 );
227 DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(4), vector.Count(), TEST_LOCATION );
228 DALI_TEST_EQUALS( vector[ 3 ], 99, TEST_LOCATION );
229 ret = vector.Erase( vector.End() - 1 );
230 DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(3), vector.Count(), TEST_LOCATION );
231 DALI_TEST_EQUALS( ret, vector.End(), TEST_LOCATION );
235 // illegal erase, one past the end
236 vector.Erase( vector.End() );
237 tet_result(TET_FAIL);
239 catch( Dali::DaliException& e )
241 DALI_TEST_PRINT_ASSERT( e );
242 DALI_TEST_ASSERT( e, "(iterator < End())", TEST_LOCATION );
246 tet_printf("Assertion test failed - wrong Exception\n" );
247 tet_result(TET_FAIL);
252 // illegal erase, one before the begin
253 vector.Erase( vector.Begin() - 1u );
254 tet_result(TET_FAIL);
256 catch( Dali::DaliException& e )
258 DALI_TEST_PRINT_ASSERT( e );
259 DALI_TEST_ASSERT( e, "(iterator < End()) && (iterator >= Begin())", TEST_LOCATION );
263 tet_printf("Assertion test failed - wrong Exception\n" );
264 tet_result(TET_FAIL);
268 DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(3), vector.Count(), TEST_LOCATION );
269 DALI_TEST_EQUALS( vector[ 0 ], 2, TEST_LOCATION );
270 DALI_TEST_EQUALS( vector[ 1 ], 3, TEST_LOCATION );
271 DALI_TEST_EQUALS( vector[ 2 ], 5, TEST_LOCATION );
273 vector.Erase( vector.Begin() + 1 );
274 DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(2), vector.Count(), TEST_LOCATION );
275 DALI_TEST_EQUALS( vector[ 0 ], 2, TEST_LOCATION );
276 DALI_TEST_EQUALS( vector[ 1 ], 5, TEST_LOCATION );
278 vector.Erase( vector.Begin() + 1 );
279 DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(1), vector.Count(), TEST_LOCATION );
280 DALI_TEST_EQUALS( vector[ 0 ], 2, TEST_LOCATION );
284 // illegal erase, one past the end
285 vector.Erase( vector.Begin() + 1 );
286 tet_result(TET_FAIL);
288 catch( Dali::DaliException& e )
290 DALI_TEST_PRINT_ASSERT( e );
291 DALI_TEST_ASSERT( e, "(iterator < End())", TEST_LOCATION );
295 tet_printf("Assertion test failed - wrong Exception\n" );
296 tet_result(TET_FAIL);
298 DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(1), vector.Count(), TEST_LOCATION );
299 DALI_TEST_EQUALS( vector[ 0 ], 2, TEST_LOCATION );
301 vector.Erase( vector.Begin() );
302 DALI_TEST_EQUALS( ZERO, vector.Count(), TEST_LOCATION );
306 // illegal erase, one before the beginning
307 vector.Erase( vector.Begin() - 1 );
308 tet_result(TET_FAIL);
310 catch( Dali::DaliException& e )
312 DALI_TEST_PRINT_ASSERT( e );
313 DALI_TEST_ASSERT( e, "(iterator < End())", TEST_LOCATION );
317 tet_printf("Assertion test failed - wrong Exception\n" );
318 tet_result(TET_FAIL);
321 DALI_TEST_EQUALS( ZERO, vector.Count(), TEST_LOCATION );
322 DALI_TEST_EQUALS( vector.Begin(), vector.End(), TEST_LOCATION );
324 Vector< char >::Iterator endIter = vector.End();
325 for( Vector< char >::Iterator iter = vector.Begin(); iter != endIter; ++iter )
327 tet_result(TET_FAIL);
330 vector.PushBack( 3 );
331 DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(1), vector.Count(), TEST_LOCATION );
334 DALI_TEST_EQUALS( ZERO, vector.Count(), TEST_LOCATION );
335 DALI_TEST_EQUALS( vector.Begin(), vector.End(), TEST_LOCATION );
337 endIter = vector.End();
338 for( Vector< char >::Iterator iter = vector.Begin(); iter != endIter; ++iter )
340 tet_result(TET_FAIL);
343 // test a vector of pointers
344 Vector< int* > ptrVector;
345 DALI_TEST_EQUALS( ZERO, ptrVector.Count(), TEST_LOCATION );
346 DALI_TEST_EQUALS( ptrVector.Begin(), ptrVector.End(), TEST_LOCATION );
349 ptrVector.PushBack( pointer );
350 DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(1), ptrVector.Count(), TEST_LOCATION );
352 Vector< int* >::Iterator ptriter = std::find( ptrVector.Begin(), ptrVector.End(), pointer );
353 ptriter = ptrVector.Erase( ptriter );
354 DALI_TEST_EQUALS( ZERO, ptrVector.Count(), TEST_LOCATION );
355 DALI_TEST_EQUALS( ptrVector.Begin(), ptrVector.End(), TEST_LOCATION );
356 DALI_TEST_EQUALS( ptrVector.Begin(), ptriter, TEST_LOCATION );
361 int UtcDaliVectorDoubleRemove(void)
363 tet_infoline("Testing Dali::Vector<double>::Remove");
365 Vector< double > vector;
366 DALI_TEST_EQUALS( ZERO, vector.Count(), TEST_LOCATION );
368 vector.PushBack( 11.1 );
369 vector.PushBack( 22.2 );
370 vector.PushBack( 33.3 );
371 vector.PushBack( 44.4 );
372 DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(4), vector.Count(), TEST_LOCATION );
373 DALI_TEST_EQUALS( vector[ 0 ], 11.1, TEST_LOCATION );
374 DALI_TEST_EQUALS( vector[ 1 ], 22.2, TEST_LOCATION );
375 DALI_TEST_EQUALS( vector[ 2 ], 33.3, TEST_LOCATION );
376 DALI_TEST_EQUALS( vector[ 3 ], 44.4, TEST_LOCATION );
378 Vector< double >::Iterator res = std::find( vector.Begin(), vector.End(), 22.2 );
379 DALI_TEST_EQUALS( 22.2, *res, TEST_LOCATION );
380 vector.Remove( res );
381 res = std::find( vector.Begin(), vector.End(), 22.2 );
382 DALI_TEST_EQUALS( vector.End(), res, TEST_LOCATION );
383 DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(3), vector.Count(), TEST_LOCATION );
384 DALI_TEST_EQUALS( vector[ 0 ], 11.1, TEST_LOCATION );
385 DALI_TEST_EQUALS( vector[ 1 ], 44.4, TEST_LOCATION );
386 DALI_TEST_EQUALS( vector[ 2 ], 33.3, TEST_LOCATION );
388 vector.Remove( vector.End() - 1 );
389 DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(2), vector.Count(), TEST_LOCATION );
390 DALI_TEST_EQUALS( vector[ 0 ], 11.1, TEST_LOCATION );
391 DALI_TEST_EQUALS( vector[ 1 ], 44.4, TEST_LOCATION );
393 vector.Remove( vector.Begin() );
394 DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(1), vector.Count(), TEST_LOCATION );
395 DALI_TEST_EQUALS( vector[ 0 ], 44.4, TEST_LOCATION );
399 // illegal erase, one past the end
400 vector.Remove( vector.Begin() + 1 );
401 tet_result(TET_FAIL);
403 catch( Dali::DaliException& e )
405 DALI_TEST_PRINT_ASSERT( e );
406 DALI_TEST_ASSERT( e, "(iterator < End()) && (iterator >= Begin())", TEST_LOCATION );
410 tet_printf("Assertion test failed - wrong Exception\n" );
411 tet_result(TET_FAIL);
413 DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(1), vector.Count(), TEST_LOCATION );
414 DALI_TEST_EQUALS( vector[ 0 ], 44.4, TEST_LOCATION );
416 vector.Remove( vector.Begin() );
417 DALI_TEST_EQUALS( ZERO, vector.Count(), TEST_LOCATION );
421 // illegal erase, one before the beginning
422 vector.Remove( vector.Begin() - 1 );
423 tet_result(TET_FAIL);
425 catch( Dali::DaliException& e )
427 DALI_TEST_PRINT_ASSERT( e );
428 DALI_TEST_ASSERT( e, "(iterator < End()) && (iterator >= Begin())", TEST_LOCATION );
432 tet_printf("Assertion test failed - wrong Exception\n" );
433 tet_result(TET_FAIL);
439 int UtcDaliVectorIntSwap(void)
441 tet_infoline("Testing Dali::Vector<int>::Swap");
443 Vector< int > intvector;
444 DALI_TEST_EQUALS( ZERO, intvector.Count(), TEST_LOCATION );
445 DALI_TEST_EQUALS( ZERO, intvector.Capacity(), TEST_LOCATION );
447 intvector.PushBack( 11 );
448 intvector.PushBack( 22 );
449 intvector.PushBack( 33 );
450 DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(3), intvector.Count(), TEST_LOCATION );
452 Vector< int > intvector2;
453 DALI_TEST_EQUALS( ZERO, intvector2.Count(), TEST_LOCATION );
454 DALI_TEST_EQUALS( ZERO, intvector2.Capacity(), TEST_LOCATION );
456 intvector2.Swap( intvector );
457 DALI_TEST_EQUALS( ZERO, intvector.Count(), TEST_LOCATION );
458 DALI_TEST_EQUALS( ZERO, intvector.Capacity(), TEST_LOCATION );
459 DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(3), intvector2.Count(), TEST_LOCATION );
460 DALI_TEST_EQUALS( 11, intvector2[ 0 ], TEST_LOCATION );
461 DALI_TEST_EQUALS( 22, intvector2[ 1 ], TEST_LOCATION );
462 DALI_TEST_EQUALS( 33, intvector2[ 2 ], TEST_LOCATION );
464 intvector.PushBack( 99 );
465 intvector.PushBack( 88 );
466 DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(2), intvector.Count(), TEST_LOCATION );
468 intvector.Swap( intvector2 );
469 DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(2), intvector2.Count(), TEST_LOCATION );
470 DALI_TEST_EQUALS( 99, intvector2[ 0 ], TEST_LOCATION );
471 DALI_TEST_EQUALS( 88, intvector2[ 1 ], TEST_LOCATION );
472 DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(3), intvector.Count(), TEST_LOCATION );
473 DALI_TEST_EQUALS( 11, intvector[ 0 ], TEST_LOCATION );
474 DALI_TEST_EQUALS( 22, intvector[ 1 ], TEST_LOCATION );
475 DALI_TEST_EQUALS( 33, intvector[ 2 ], TEST_LOCATION );
478 intvector.Swap( empty );
479 DALI_TEST_EQUALS( ZERO, intvector.Count(), TEST_LOCATION );
480 DALI_TEST_EQUALS( ZERO, intvector.Capacity(), TEST_LOCATION );
484 int UtcDaliVectorIterate(void)
486 tet_infoline("Testing Dali::Vector<float>::Begin");
488 Vector< float > floatvector;
489 DALI_TEST_EQUALS( ZERO, floatvector.Count(), TEST_LOCATION );
490 DALI_TEST_EQUALS( ZERO, floatvector.Capacity(), TEST_LOCATION );
492 floatvector.PushBack( 0.9f );
493 floatvector.PushBack( 1.1f );
494 floatvector.PushBack( 1.2f );
495 DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(3), floatvector.Count(), TEST_LOCATION );
497 Vector< float >::Iterator iter = floatvector.Begin();
499 for( ; iter != floatvector.End(); ++iter, ++index )
501 std::cout << "value " << *iter << std::endl;
502 DALI_TEST_EQUALS( *iter, floatvector[ index ], TEST_LOCATION );
504 DALI_TEST_EQUALS( 3, index, TEST_LOCATION );
506 iter = std::find( floatvector.Begin(), floatvector.End(), 1.1f );
507 DALI_TEST_EQUALS( 1.1f, *iter, TEST_LOCATION );
510 iter = std::find( floatvector.Begin(), floatvector.End(), 1.1f );
511 DALI_TEST_EQUALS( floatvector.End(), iter, TEST_LOCATION );
515 int UtcDaliVectorPair(void)
517 tet_infoline("Testing Dali::Vector< std::pair< int, float > >");
519 Vector< std::pair< int, float > > pairvector;
520 DALI_TEST_EQUALS( ZERO, pairvector.Count(), TEST_LOCATION );
521 DALI_TEST_EQUALS( ZERO, pairvector.Capacity(), TEST_LOCATION );
523 pairvector.PushBack( std::make_pair( 5, 0.1f ) );
524 pairvector.PushBack( std::make_pair( 3, 0.2f ) );
525 pairvector.PushBack( std::make_pair( 4, 0.3f ) );
526 pairvector.PushBack( std::make_pair( 1, 0.4f ) );
527 pairvector.PushBack( std::make_pair( 2, 0.5f ) );
528 DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(5), pairvector.Count(), TEST_LOCATION );
530 Vector< std::pair< int, float > >::Iterator iter = pairvector.Begin();
532 for( ; iter != pairvector.End(); ++iter, ++index )
534 std::cout << "pair " << (*iter).first << ":" << (*iter).second << std::endl;
535 DALI_TEST_EQUALS( (*iter).first, pairvector[ index ].first, TEST_LOCATION );
536 DALI_TEST_EQUALS( (*iter).second, pairvector[ index ].second, TEST_LOCATION );
541 int UtcDaliVectorAsserts(void)
543 tet_infoline("Testing Dali::Vector< int* > exception handling");
546 Vector< int* > pointervector;
550 pointervector[ 1 ] = value;
551 tet_printf("Assertion expected, but not occurred at %s\n", TEST_LOCATION );
552 tet_result(TET_FAIL);
554 catch(Dali::DaliException& e)
556 DALI_TEST_PRINT_ASSERT( e );
557 DALI_TEST_ASSERT( e, "VectorBase::mData", TEST_LOCATION );
561 tet_printf("Assertion test failed - wrong Exception\n" );
562 tet_result(TET_FAIL);
568 value = pointervector[ 0 ];
569 (void)value; // to "use" the value
570 tet_printf("Assertion expected, but not occurred at %s\n", TEST_LOCATION );
571 tet_result(TET_FAIL);
573 catch(Dali::DaliException& e)
575 DALI_TEST_PRINT_ASSERT( e );
576 DALI_TEST_ASSERT( e, "VectorBase::mData", TEST_LOCATION );
580 tet_printf("Assertion test failed - wrong Exception\n" );
581 tet_result(TET_FAIL);
584 Vector< int* >::Iterator iter = pointervector.Begin();
585 if( iter != pointervector.End() )
587 tet_result(TET_FAIL);
592 pointervector.Erase( pointervector.Begin() );
593 tet_printf("Assertion expected, but not occurred at %s\n", TEST_LOCATION );
594 tet_result(TET_FAIL);
596 catch(Dali::DaliException& e)
598 DALI_TEST_PRINT_ASSERT( e );
599 DALI_TEST_ASSERT( e, "(iterator < End()) && (iterator >= Begin())", TEST_LOCATION );
603 tet_printf("Assertion test failed - wrong Exception\n" );
604 tet_result(TET_FAIL);
607 iter = pointervector.Begin();
608 if( iter != pointervector.End() )
610 tet_result(TET_FAIL);
615 pointervector.Remove( pointervector.Begin() );
616 tet_printf("Assertion expected, but not occurred at %s\n", TEST_LOCATION );
617 tet_result(TET_FAIL);
619 catch(Dali::DaliException& e)
621 DALI_TEST_PRINT_ASSERT( e );
622 DALI_TEST_ASSERT( e, "(iterator < End()) && (iterator >= Begin())", TEST_LOCATION );
626 tet_printf("Assertion test failed - wrong Exception\n" );
627 tet_result(TET_FAIL);
630 iter = pointervector.Begin();
631 if( iter != pointervector.End() )
633 tet_result(TET_FAIL);
637 pointervector.Reserve( 0 );
638 iter = pointervector.Begin();
639 if( iter != pointervector.End() )
641 tet_result(TET_FAIL);
645 pointervector.Reserve( 1 );
646 iter = pointervector.Begin();
647 if( iter != pointervector.End() )
649 tet_result(TET_FAIL);
655 pointervector[ 1 ] = value;
656 tet_printf("Assertion expected, but not occurred at %s\n", TEST_LOCATION );
657 tet_result(TET_FAIL);
659 catch(Dali::DaliException& e)
661 DALI_TEST_PRINT_ASSERT( e );
662 DALI_TEST_ASSERT( e, "index < VectorBase::Count()", TEST_LOCATION );
666 tet_printf("Assertion test failed - wrong Exception\n" );
667 tet_result(TET_FAIL);
672 int* value = pointervector[ 1 ];
673 (void)value; // to "use" the value
674 tet_printf("Assertion expected, but not occurred at %s\n", TEST_LOCATION );
675 tet_result(TET_FAIL);
677 catch(Dali::DaliException& e)
679 DALI_TEST_PRINT_ASSERT( e );
680 DALI_TEST_ASSERT( e, "index < VectorBase::Count()", TEST_LOCATION );
684 tet_printf("Assertion test failed - wrong Exception\n" );
685 tet_result(TET_FAIL);
691 int UtcDaliVectorAcidTest(void)
693 tet_infoline("Testing multiple Dali::Vector's");
695 // create multiple vectors
696 Vector< std::pair< float, float > > pairvector;
697 DALI_TEST_EQUALS( ZERO, pairvector.Count(), TEST_LOCATION );
698 DALI_TEST_EQUALS( ZERO, pairvector.Capacity(), TEST_LOCATION );
699 Vector< double > doublevector;
700 DALI_TEST_EQUALS( ZERO, doublevector.Count(), TEST_LOCATION );
701 DALI_TEST_EQUALS( ZERO, doublevector.Capacity(), TEST_LOCATION );
702 Vector< int* > intptrvector;
703 DALI_TEST_EQUALS( ZERO, intptrvector.Count(), TEST_LOCATION );
704 DALI_TEST_EQUALS( ZERO, intptrvector.Capacity(), TEST_LOCATION );
705 Vector< Dali::Actor* > actorptrvector;
706 DALI_TEST_EQUALS( ZERO, actorptrvector.Count(), TEST_LOCATION );
707 DALI_TEST_EQUALS( ZERO, actorptrvector.Capacity(), TEST_LOCATION );
708 Vector< long > longvector;
709 DALI_TEST_EQUALS( ZERO, longvector.Count(), TEST_LOCATION );
710 DALI_TEST_EQUALS( ZERO, longvector.Capacity(), TEST_LOCATION );
711 Vector< char > charvector;
712 DALI_TEST_EQUALS( ZERO, charvector.Count(), TEST_LOCATION );
713 DALI_TEST_EQUALS( ZERO, charvector.Capacity(), TEST_LOCATION );
716 static unsigned int acidCount = 10000;
718 for( unsigned int i = 0; i < acidCount; ++i )
721 pairvector.PushBack( std::make_pair( i, i ) );
722 doublevector.PushBack( (double)i );
723 intptrvector.PushBack( (int*)ptr );
724 actorptrvector.PushBack( (Dali::Actor*)ptr );
725 longvector.PushBack( (long)i );
726 charvector.PushBack( (char)i );
728 DALI_TEST_EQUALS( acidCount, pairvector.Count(), TEST_LOCATION );
729 std::size_t pairCapacity = pairvector.Capacity();
730 DALI_TEST_EQUALS( acidCount, doublevector.Count(), TEST_LOCATION );
731 std::size_t doubleCapacity = doublevector.Capacity();
732 DALI_TEST_EQUALS( acidCount, intptrvector.Count(), TEST_LOCATION );
733 std::size_t intptrCapacity = intptrvector.Capacity();
734 DALI_TEST_EQUALS( acidCount, actorptrvector.Count(), TEST_LOCATION );
735 std::size_t actorptrCapacity = actorptrvector.Capacity();
736 DALI_TEST_EQUALS( acidCount, longvector.Count(), TEST_LOCATION );
737 std::size_t longCapacity = longvector.Capacity();
738 DALI_TEST_EQUALS( acidCount, charvector.Count(), TEST_LOCATION );
739 std::size_t charCapacity = charvector.Capacity();
741 tet_printf("Dali::Vector< pair > capacity after %d pushbacks is %d", acidCount, pairCapacity );
742 tet_printf("Dali::Vector< double > capacity after %d pushbacks is %d", acidCount, doubleCapacity );
743 tet_printf("Dali::Vector< int* > capacity after %d pushbacks is %d", acidCount, intptrCapacity );
744 tet_printf("Dali::Vector< Actor* > capacity after %d pushbacks is %d", acidCount, actorptrCapacity );
745 tet_printf("Dali::Vector< long > capacity after %d pushbacks is %d", acidCount, longCapacity );
746 tet_printf("Dali::Vector< char > capacity after %d pushbacks is %d", acidCount, charCapacity );
749 for( unsigned int i = 0; i < acidCount; ++i )
751 pairvector.Erase( pairvector.Begin() + ( i % pairvector.Count() ) );
752 doublevector.Erase( doublevector.Begin() + ( i % doublevector.Count() ) );
753 intptrvector.Erase( intptrvector.Begin() + ( i % intptrvector.Count() ) );
754 actorptrvector.Erase( actorptrvector.Begin() + ( i % actorptrvector.Count() ) );
755 longvector.Erase( longvector.Begin() + ( i % longvector.Count() ) );
756 charvector.Erase( charvector.Begin() + ( i % charvector.Count() ) );
758 DALI_TEST_EQUALS( ZERO, pairvector.Count(), TEST_LOCATION );
759 DALI_TEST_EQUALS( pairCapacity, pairvector.Capacity(), TEST_LOCATION );
760 DALI_TEST_EQUALS( ZERO, doublevector.Count(), TEST_LOCATION );
761 DALI_TEST_EQUALS( doubleCapacity, doublevector.Capacity(), TEST_LOCATION );
762 DALI_TEST_EQUALS( ZERO, intptrvector.Count(), TEST_LOCATION );
763 DALI_TEST_EQUALS( intptrCapacity, intptrvector.Capacity(), TEST_LOCATION );
764 DALI_TEST_EQUALS( ZERO, actorptrvector.Count(), TEST_LOCATION );
765 DALI_TEST_EQUALS( actorptrCapacity, actorptrvector.Capacity(), TEST_LOCATION );
766 DALI_TEST_EQUALS( ZERO, longvector.Count(), TEST_LOCATION );
767 DALI_TEST_EQUALS( longCapacity, longvector.Capacity(), TEST_LOCATION );
768 DALI_TEST_EQUALS( ZERO, charvector.Count(), TEST_LOCATION );
769 DALI_TEST_EQUALS( charCapacity, charvector.Capacity(), TEST_LOCATION );
774 int UtcDaliVectorPushBack(void)
776 tet_infoline( "Testing Dali::Vector< int* >PushBack(Element)" );
778 Vector<unsigned int> vector;
779 DALI_TEST_EQUALS( ZERO, vector.Count(), TEST_LOCATION );
780 DALI_TEST_EQUALS( ZERO, vector.Capacity(), TEST_LOCATION );
782 vector.Reserve( 2u );
783 DALI_TEST_EQUALS( ZERO, vector.Count(), TEST_LOCATION );
784 DALI_TEST_EQUALS( 2u, vector.Capacity(), TEST_LOCATION );
786 vector.PushBack( 0u );
787 vector.PushBack( 1u );
788 vector.PushBack( 2u );
790 DALI_TEST_EQUALS( 3u, vector.Count(), TEST_LOCATION );
791 DALI_TEST_EQUALS( 6u, vector.Capacity(), TEST_LOCATION );
793 vector.PushBack( 3u );
795 DALI_TEST_EQUALS( 4u, vector.Count(), TEST_LOCATION );
796 DALI_TEST_EQUALS( 6u, vector.Capacity(), TEST_LOCATION );
798 DALI_TEST_EQUALS( 0u, vector[0u], TEST_LOCATION );
799 DALI_TEST_EQUALS( 1u, vector[1u], TEST_LOCATION );
800 DALI_TEST_EQUALS( 2u, vector[2u], TEST_LOCATION );
801 DALI_TEST_EQUALS( 3u, vector[3u], TEST_LOCATION );
806 int UtcDaliVectorInsert01(void)
808 tet_infoline( "Testing Dali::Vector< int* >Insert(Iterator, Element)" );
810 // Test order of array inserted-into:
811 Vector< unsigned int > orderedVector;
812 orderedVector.PushBack( 9u );
813 for( unsigned int i = 8u; i <= 8u; --i )
815 orderedVector.Insert( orderedVector.Begin(), i );
816 DALI_TEST_EQUALS( 10u - i, orderedVector.Count(), TEST_LOCATION );
817 DALI_TEST_EQUALS( i, orderedVector[0u], TEST_LOCATION );
820 for( unsigned int i = 0u; i < 10u; ++i )
822 DALI_TEST_EQUALS( i, orderedVector[i], TEST_LOCATION );
825 // Test insertion out of range in non-empty array throws:
828 orderedVector.Insert( orderedVector.Begin() + 99u, 99u );
829 tet_printf( "Assertion expected, but not occurred at %s\n", TEST_LOCATION );
830 tet_result( TET_FAIL );
832 catch( Dali::DaliException& e )
834 DALI_TEST_PRINT_ASSERT( e );
835 DALI_TEST_ASSERT( e, "( at <= End() ) && ( at >= Begin() )", TEST_LOCATION );
839 tet_printf( "Assertion test failed - wrong Exception\n" );
840 tet_result( TET_FAIL );
845 orderedVector.Insert( orderedVector.Begin() - 1u, 99u );
846 tet_printf( "Assertion expected, but not occurred at %s\n", TEST_LOCATION );
847 tet_result( TET_FAIL );
849 catch( Dali::DaliException& e )
851 DALI_TEST_PRINT_ASSERT( e );
852 DALI_TEST_ASSERT( e, "( at <= End() ) && ( at >= Begin() )", TEST_LOCATION );
856 tet_printf( "Assertion test failed - wrong Exception\n" );
857 tet_result( TET_FAIL );
860 // Test insertion part-way through a largish array retains ordering:
862 // Build vector with hole in sequence:
863 Vector< unsigned int > longerVector;
864 const unsigned int insertionPoint = 131571u;
865 const unsigned int finalLength = 262143u;
866 for( unsigned int i = 0u; i < insertionPoint; ++i )
868 longerVector.PushBack( i );
870 for( unsigned int i = insertionPoint; i < finalLength; ++i )
872 longerVector.PushBack( i + 1 );
875 // Fill the hole in the sequence:
876 longerVector.Insert( longerVector.Begin() + insertionPoint, insertionPoint );
878 // Check the sequence is monotonically increasing by one every time:
879 for( unsigned int i = 0u; i <= finalLength; ++i )
881 DALI_TEST_EQUALS( i, longerVector[i], TEST_LOCATION );
884 // Insert into an empty vector
885 Vector< unsigned int > vector;
887 vector.Insert( vector.End(), orderedVector.Begin(), orderedVector.End() );
888 for( unsigned int i = 0u; i < 10u; ++i )
890 DALI_TEST_EQUALS( i, vector[i], TEST_LOCATION );
894 vector.Insert( vector.Begin(), orderedVector.Begin(), orderedVector.End() );
895 for( unsigned int i = 0u; i < 10u; ++i )
897 DALI_TEST_EQUALS( i, vector[i], TEST_LOCATION );
901 vector.Insert( vector.Begin(), orderedVector.Begin(), orderedVector.Begin() );
902 for( unsigned int i = 0u; i < 10u; ++i )
904 DALI_TEST_EQUALS( i, vector[i], TEST_LOCATION );
907 vector.Insert( vector.Begin() + 5, vector.Begin() + 5, vector.Begin() + 5 );
908 for( unsigned int i = 0u; i < 10u; ++i )
910 DALI_TEST_EQUALS( i, vector[i], TEST_LOCATION );
915 vector.PushBack( 0u );
916 vector.PushBack( 1u );
917 vector.PushBack( 2u );
918 vector.PushBack( 3u );
920 vector.Insert( vector.Begin() + 2, vector.Begin(), vector.End() );
921 DALI_TEST_EQUALS( 8u, vector.Count(), TEST_LOCATION );
922 DALI_TEST_EQUALS( 0u, vector[0u], TEST_LOCATION );
923 DALI_TEST_EQUALS( 1u, vector[1u], TEST_LOCATION );
924 DALI_TEST_EQUALS( 0u, vector[2u], TEST_LOCATION );
925 DALI_TEST_EQUALS( 1u, vector[3u], TEST_LOCATION );
926 DALI_TEST_EQUALS( 2u, vector[4u], TEST_LOCATION );
927 DALI_TEST_EQUALS( 3u, vector[5u], TEST_LOCATION );
928 DALI_TEST_EQUALS( 2u, vector[6u], TEST_LOCATION );
929 DALI_TEST_EQUALS( 3u, vector[7u], TEST_LOCATION );
934 int UtcDaliVectorInsert02(void)
936 tet_infoline("Testing Dali::Vector<char>::Insert(Iterator,Iterator,Iterator)");
938 Vector< char > vector;
939 DALI_TEST_EQUALS( ZERO, vector.Count(), TEST_LOCATION );
940 DALI_TEST_EQUALS( ZERO, vector.Capacity(), TEST_LOCATION );
941 vector.PushBack( 1 );
942 vector.PushBack( 2 );
943 vector.PushBack( 3 );
944 vector.PushBack( 4 );
945 vector.PushBack( 5 );
947 Vector< char > vector2;
948 DALI_TEST_EQUALS( ZERO, vector2.Count(), TEST_LOCATION );
949 DALI_TEST_EQUALS( ZERO, vector2.Capacity(), TEST_LOCATION );
950 vector2.PushBack( 6 );
951 vector2.PushBack( 7 );
952 vector2.PushBack( 8 );
953 vector2.PushBack( 9 );
954 vector2.PushBack( 10 );
956 // Test insert at end
957 vector.Insert( vector.End(), vector2.Begin(), vector2.Begin() + 1u );
958 DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(6), vector.Count(), TEST_LOCATION );
959 DALI_TEST_EQUALS( vector[ 0 ], 1, TEST_LOCATION );
960 DALI_TEST_EQUALS( vector[ 1 ], 2, TEST_LOCATION );
961 DALI_TEST_EQUALS( vector[ 2 ], 3, TEST_LOCATION );
962 DALI_TEST_EQUALS( vector[ 3 ], 4, TEST_LOCATION );
963 DALI_TEST_EQUALS( vector[ 4 ], 5, TEST_LOCATION );
964 DALI_TEST_EQUALS( vector[ 5 ], 6, TEST_LOCATION );
966 // Test insert at begin
967 vector.Insert( vector.Begin(), vector2.Begin()+1, vector2.Begin() + 2u );
968 DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(7), vector.Count(), TEST_LOCATION );
969 DALI_TEST_EQUALS( vector[ 0 ], 7, TEST_LOCATION );
970 DALI_TEST_EQUALS( vector[ 1 ], 1, TEST_LOCATION );
971 DALI_TEST_EQUALS( vector[ 2 ], 2, TEST_LOCATION );
972 DALI_TEST_EQUALS( vector[ 3 ], 3, TEST_LOCATION );
973 DALI_TEST_EQUALS( vector[ 4 ], 4, TEST_LOCATION );
974 DALI_TEST_EQUALS( vector[ 5 ], 5, TEST_LOCATION );
975 DALI_TEST_EQUALS( vector[ 6 ], 6, TEST_LOCATION );
977 // Test insert in the middle
978 vector.Insert( vector.Begin() + 3, vector2.Begin()+3, vector2.End() );
979 DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(9), 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 ], 9, TEST_LOCATION );
984 DALI_TEST_EQUALS( vector[ 4 ], 10, TEST_LOCATION );
985 DALI_TEST_EQUALS( vector[ 5 ], 3, TEST_LOCATION );
986 DALI_TEST_EQUALS( vector[ 6 ], 4, TEST_LOCATION );
987 DALI_TEST_EQUALS( vector[ 7 ], 5, TEST_LOCATION );
988 DALI_TEST_EQUALS( vector[ 8 ], 6, TEST_LOCATION );
992 int UtcDaliVectorIntInsertAssert(void)
994 tet_infoline("Testing Dali::Vector<char>::Insert(Iterator,Iterator,Iterator) asserts");
996 Vector< char > vector;
997 DALI_TEST_EQUALS( ZERO, vector.Count(), TEST_LOCATION );
998 DALI_TEST_EQUALS( ZERO, vector.Capacity(), TEST_LOCATION );
999 vector.PushBack( 1 );
1000 vector.PushBack( 2 );
1002 Vector< char > vector2;
1003 DALI_TEST_EQUALS( ZERO, vector2.Count(), TEST_LOCATION );
1004 DALI_TEST_EQUALS( ZERO, vector2.Capacity(), TEST_LOCATION );
1005 vector2.PushBack( 6 );
1006 vector2.PushBack( 7 );
1007 vector2.PushBack( 8 );
1008 vector2.PushBack( 9 );
1009 vector2.PushBack( 10 );
1013 vector.Insert( vector.Begin() + 3u, vector2.Begin(), vector2.End() );
1014 tet_result(TET_FAIL);
1016 catch( Dali::DaliException& e )
1018 DALI_TEST_PRINT_ASSERT( e );
1019 DALI_TEST_ASSERT( e, "( at <= End() ) && ( at >= Begin() )", TEST_LOCATION );
1023 tet_printf("Assertion test failed - wrong Exception\n" );
1024 tet_result(TET_FAIL);
1029 vector.Insert( vector.Begin() - 1u, vector2.Begin(), vector2.End() );
1030 tet_result(TET_FAIL);
1032 catch( Dali::DaliException& e )
1034 DALI_TEST_PRINT_ASSERT( e );
1035 DALI_TEST_ASSERT( e, "( at <= End() ) && ( at >= Begin() )", TEST_LOCATION );
1039 tet_printf("Assertion test failed - wrong Exception\n" );
1040 tet_result(TET_FAIL);
1045 vector.Insert( vector.End(), vector2.End(), vector2.Begin() );
1046 tet_result(TET_FAIL);
1048 catch( Dali::DaliException& e )
1050 DALI_TEST_PRINT_ASSERT( e );
1051 DALI_TEST_ASSERT( e, "( from <= to )", TEST_LOCATION );
1055 tet_printf("Assertion test failed - wrong Exception\n" );
1056 tet_result(TET_FAIL);
1063 int UtcDaliVectorIntEraseRange(void)
1065 tet_infoline("Testing Dali::Vector<char>::Erase(Iterator,Iterator)");
1067 Vector< char > vector;
1068 DALI_TEST_EQUALS( ZERO, vector.Count(), TEST_LOCATION );
1069 DALI_TEST_EQUALS( ZERO, vector.Capacity(), TEST_LOCATION );
1071 // Try to delete from empty vector.
1073 vector.Erase( vector.Begin(), vector.End() );
1074 DALI_TEST_EQUALS( ZERO, vector.Count(), TEST_LOCATION );
1075 DALI_TEST_EQUALS( ZERO, vector.Capacity(), TEST_LOCATION );
1077 vector.PushBack( 1 );
1078 vector.PushBack( 2 );
1079 vector.PushBack( 3 );
1080 vector.PushBack( 4 );
1081 vector.PushBack( 5 );
1082 DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(5), vector.Count(), TEST_LOCATION );
1083 DALI_TEST_EQUALS( vector[ 0 ], 1, TEST_LOCATION );
1084 DALI_TEST_EQUALS( vector[ 1 ], 2, TEST_LOCATION );
1085 DALI_TEST_EQUALS( vector[ 2 ], 3, TEST_LOCATION );
1086 DALI_TEST_EQUALS( vector[ 3 ], 4, TEST_LOCATION );
1087 DALI_TEST_EQUALS( vector[ 4 ], 5, TEST_LOCATION );
1089 Vector< char >::Iterator ret;
1091 ret = vector.Erase( vector.Begin() + 1u, vector.Begin() + 2u );
1092 DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(4), vector.Count(), TEST_LOCATION );
1093 DALI_TEST_EQUALS( vector[ 0 ], 1, TEST_LOCATION );
1094 DALI_TEST_EQUALS( vector[ 1 ], 3, TEST_LOCATION );
1095 DALI_TEST_EQUALS( vector[ 2 ], 4, TEST_LOCATION );
1096 DALI_TEST_EQUALS( vector[ 3 ], 5, TEST_LOCATION );
1097 DALI_TEST_EQUALS( *ret, 3, TEST_LOCATION );
1099 ret = vector.Erase( vector.Begin(), vector.Begin() + 2 );
1100 DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(2), vector.Count(), TEST_LOCATION );
1101 DALI_TEST_EQUALS( vector[ 0 ], 4, TEST_LOCATION );
1102 DALI_TEST_EQUALS( vector[ 1 ], 5, TEST_LOCATION );
1103 DALI_TEST_EQUALS( *ret, 4, TEST_LOCATION );
1106 vector.PushBack( 99 );
1107 DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(3), vector.Count(), TEST_LOCATION );
1108 DALI_TEST_EQUALS( vector[ 2 ], 99, TEST_LOCATION );
1109 ret = vector.Erase( vector.Begin() + 1u, vector.End() );
1110 DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(1), vector.Count(), TEST_LOCATION );
1111 DALI_TEST_EQUALS( vector[ 0 ], 4, TEST_LOCATION );
1112 DALI_TEST_EQUALS( ret, vector.End(), TEST_LOCATION );
1115 vector.PushBack( 100 );
1116 vector.PushBack( 101 );
1117 vector.PushBack( 102 );
1119 DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(4), vector.Count(), TEST_LOCATION );
1120 DALI_TEST_EQUALS( vector[ 0 ], 4, TEST_LOCATION );
1121 DALI_TEST_EQUALS( vector[ 1 ], 100, TEST_LOCATION );
1122 DALI_TEST_EQUALS( vector[ 2 ], 101, TEST_LOCATION );
1123 DALI_TEST_EQUALS( vector[ 3 ], 102, TEST_LOCATION );
1125 ret = vector.Erase( vector.Begin(), vector.End() );
1126 DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(0), vector.Count(), TEST_LOCATION );
1127 DALI_TEST_EQUALS( ret, vector.End(), TEST_LOCATION );
1129 // try erase from Iterator to the same Iterator.
1130 vector.PushBack( 100 );
1131 vector.PushBack( 101 );
1132 vector.PushBack( 102 );
1134 DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(3), vector.Count(), TEST_LOCATION );
1135 DALI_TEST_EQUALS( vector[ 0 ], 100, TEST_LOCATION );
1136 DALI_TEST_EQUALS( vector[ 1 ], 101, TEST_LOCATION );
1137 DALI_TEST_EQUALS( vector[ 2 ], 102, TEST_LOCATION );
1139 ret = vector.Erase( vector.Begin() + 1, vector.Begin() + 1 );
1141 DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(3), vector.Count(), TEST_LOCATION );
1142 DALI_TEST_EQUALS( vector[ 0 ], 100, TEST_LOCATION );
1143 DALI_TEST_EQUALS( vector[ 1 ], 101, TEST_LOCATION );
1144 DALI_TEST_EQUALS( vector[ 2 ], 102, TEST_LOCATION );
1146 DALI_TEST_EQUALS( *ret, 101, TEST_LOCATION );
1151 int UtcDaliVectorIntEraseRangeAssert(void)
1153 tet_infoline("Testing Dali::Vector<char>::Erase(Iterator,Iterator) asserts");
1155 Vector< char > vector;
1156 DALI_TEST_EQUALS( ZERO, vector.Count(), TEST_LOCATION );
1157 DALI_TEST_EQUALS( ZERO, vector.Capacity(), TEST_LOCATION );
1160 // Add some elements.
1161 vector.PushBack( 1 );
1162 vector.PushBack( 2 );
1164 // first out of bounds
1167 vector.Erase( vector.Begin() + 3u, vector.Begin() + 4u );
1168 tet_printf( "Assertion expected, but not occurred at %s\n", TEST_LOCATION );
1169 tet_result(TET_FAIL);
1171 catch( Dali::DaliException& e )
1173 DALI_TEST_PRINT_ASSERT( e );
1174 DALI_TEST_ASSERT( e, "( first <= End() ) && ( first >= Begin() )", TEST_LOCATION );
1178 tet_printf("Assertion test failed - wrong Exception\n" );
1179 tet_result(TET_FAIL);
1184 vector.Erase( vector.Begin() - 1u, vector.End() );
1185 tet_printf( "Assertion expected, but not occurred at %s\n", TEST_LOCATION );
1186 tet_result(TET_FAIL);
1188 catch( Dali::DaliException& e )
1190 DALI_TEST_PRINT_ASSERT( e );
1191 DALI_TEST_ASSERT( e, "( first <= End() ) && ( first >= Begin() )", TEST_LOCATION );
1195 tet_printf("Assertion test failed - wrong Exception\n" );
1196 tet_result(TET_FAIL);
1199 // last out of bounds
1203 vector.Erase( vector.Begin(), vector.Begin() + 3u );
1204 tet_printf( "Assertion expected, but not occurred at %s\n", TEST_LOCATION );
1205 tet_result(TET_FAIL);
1207 catch( Dali::DaliException& e )
1209 DALI_TEST_PRINT_ASSERT( e );
1210 DALI_TEST_ASSERT( e, "( last <= End() ) && ( last >= Begin() )", TEST_LOCATION );
1214 tet_printf("Assertion test failed - wrong Exception\n" );
1215 tet_result(TET_FAIL);
1220 vector.Erase( vector.Begin(), vector.Begin() - 1u );
1221 tet_printf( "Assertion expected, but not occurred at %s\n", TEST_LOCATION );
1222 tet_result(TET_FAIL);
1224 catch( Dali::DaliException& e )
1226 DALI_TEST_PRINT_ASSERT( e );
1227 DALI_TEST_ASSERT( e, "( last <= End() ) && ( last >= Begin() )", TEST_LOCATION );
1231 tet_printf("Assertion test failed - wrong Exception\n" );
1232 tet_result(TET_FAIL);
1235 vector.PushBack( 3 );
1240 vector.Erase( vector.Begin() + 2u, vector.Begin() + 1u );
1241 tet_printf( "Assertion expected, but not occurred at %s\n", TEST_LOCATION );
1242 tet_result(TET_FAIL);
1244 catch( Dali::DaliException& e )
1246 DALI_TEST_PRINT_ASSERT( e );
1247 DALI_TEST_ASSERT( e, "( first <= last )", TEST_LOCATION );
1251 tet_printf("Assertion test failed - wrong Exception\n" );
1252 tet_result(TET_FAIL);
1261 bool gConstructorCalled = false;
1262 bool gDestructorCalled = false;
1268 gConstructorCalled = true;
1272 gDestructorCalled = true;
1276 } // anonymous namespace
1279 int UtcDaliVectorComplex(void)
1281 tet_infoline("Testing Dali::Vector< int* > exception handling");
1283 // this does not compile at the moment
1284 /* Vector< ComplexType > classvector;
1285 DALI_TEST_EQUALS( ZERO, classvector.Count(), TEST_LOCATION );
1286 DALI_TEST_EQUALS( ZERO, classvector.Capacity(), TEST_LOCATION );
1288 DALI_TEST_EQUALS( false, gConstructorCalled, TEST_LOCATION );
1289 DALI_TEST_EQUALS( false, gDestructorCalled, TEST_LOCATION );
1290 classvector.PushBack( ComplexType() );
1291 DALI_TEST_EQUALS( true, gConstructorCalled, TEST_LOCATION );
1292 classvector.Clear();
1293 DALI_TEST_EQUALS( true, gDestructorCalled, TEST_LOCATION );
1295 // Vector< Actor > classvector; this does not compile yet either
1296 tet_result(TET_PASS); // for now