2 * Copyright (c) 2017 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);
31 /// Compare a short with an int
32 void DALI_TEST_EQUALS( short value1, int value2, const char* location )
34 ::DALI_TEST_EQUALS< short >( value1, static_cast< short >( value2 ), location );
37 /// Compare a char with an int
38 void DALI_TEST_EQUALS( char value1, int value2, const char* location )
40 ::DALI_TEST_EQUALS< char >( value1, static_cast< char >( value2 ), location );
43 } // unnamed namespace
45 int UtcDaliEmptyVectorInt(void)
47 tet_infoline("Testing Dali::Vector<int>");
49 Vector< int > intvector;
51 DALI_TEST_EQUALS( ZERO, intvector.Count(), TEST_LOCATION );
52 DALI_TEST_EQUALS( ZERO, intvector.Capacity(), TEST_LOCATION );
55 DALI_TEST_EQUALS( ZERO, intvector.Count(), TEST_LOCATION );
56 DALI_TEST_EQUALS( ZERO, intvector.Capacity(), TEST_LOCATION );
59 DALI_TEST_EQUALS( ZERO, intvector.Count(), TEST_LOCATION );
60 DALI_TEST_EQUALS( ZERO, intvector.Capacity(), TEST_LOCATION );
64 int UtcDaliVectorInt(void)
66 tet_infoline("Testing Dali::Vector<int>");
68 Vector< int > intvector;
70 DALI_TEST_EQUALS( ZERO, intvector.Count(), TEST_LOCATION );
71 DALI_TEST_EQUALS( ZERO, intvector.Capacity(), TEST_LOCATION );
73 intvector.PushBack( 11 );
74 DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(1), intvector.Count(), TEST_LOCATION );
75 DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(2), intvector.Capacity(), TEST_LOCATION );
76 DALI_TEST_EQUALS( 11, intvector[ 0 ], TEST_LOCATION );
78 intvector.PushBack( 99 );
79 DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(2), intvector.Count(), TEST_LOCATION );
80 DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(2), intvector.Capacity(), TEST_LOCATION );
81 DALI_TEST_EQUALS( 99, intvector[ 1 ], TEST_LOCATION );
83 intvector.PushBack( 34 );
84 DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(3), intvector.Count(), TEST_LOCATION );
85 DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(6), intvector.Capacity(), TEST_LOCATION );
86 DALI_TEST_EQUALS( 11, intvector[ 0 ], TEST_LOCATION );
87 DALI_TEST_EQUALS( 99, intvector[ 1 ], TEST_LOCATION );
88 DALI_TEST_EQUALS( 34, intvector[ 2 ], TEST_LOCATION );
91 DALI_TEST_EQUALS( ZERO, intvector.Count(), TEST_LOCATION );
92 DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(6), intvector.Capacity(), TEST_LOCATION );
93 intvector.PushBack( 123 );
94 DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(1), intvector.Count(), TEST_LOCATION );
95 DALI_TEST_EQUALS( 123, intvector[ 0 ], TEST_LOCATION );
99 int UtcDaliVectorIntCopy(void)
101 tet_infoline("Testing Dali::Vector<int>::Copy");
103 Vector< int > intvector;
104 DALI_TEST_EQUALS( ZERO, intvector.Count(), TEST_LOCATION );
105 DALI_TEST_EQUALS( ZERO, intvector.Capacity(), TEST_LOCATION );
107 intvector.PushBack( 99 );
108 intvector.PushBack( 11 );
109 intvector.PushBack( 34 );
112 Vector< int > intvector2( intvector );
114 DALI_TEST_EQUALS( intvector2.Count(), intvector.Count(), TEST_LOCATION );
115 DALI_TEST_EQUALS( intvector2.Capacity(), intvector.Capacity(), TEST_LOCATION );
116 DALI_TEST_EQUALS( intvector2[ 0 ], intvector[ 0 ], TEST_LOCATION );
117 DALI_TEST_EQUALS( intvector2[ 1 ], intvector[ 1 ], TEST_LOCATION );
118 DALI_TEST_EQUALS( intvector2[ 2 ], intvector[ 2 ], TEST_LOCATION );
121 Vector< int > intvector3;
122 DALI_TEST_EQUALS( ZERO, intvector3.Count(), TEST_LOCATION );
123 DALI_TEST_EQUALS( ZERO, intvector3.Capacity(), TEST_LOCATION );
124 intvector2 = intvector3;
125 DALI_TEST_EQUALS( intvector2.Count(), intvector3.Count(), TEST_LOCATION );
126 DALI_TEST_EQUALS( intvector2.Capacity(), intvector3.Capacity(), TEST_LOCATION );
129 Vector< int > intvector4;
130 intvector4.Reserve( 100 );
131 DALI_TEST_EQUALS( ZERO, intvector4.Count(), TEST_LOCATION );
132 DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(100), intvector4.Capacity(), TEST_LOCATION );
133 intvector3 = intvector4;
134 DALI_TEST_EQUALS( ZERO, intvector3.Count(), TEST_LOCATION );
135 DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(100), intvector3.Capacity(), TEST_LOCATION );
138 intvector4 = intvector4;
139 DALI_TEST_EQUALS( ZERO, intvector4.Count(), TEST_LOCATION );
140 DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(100), intvector4.Capacity(), TEST_LOCATION );
144 int UtcDaliVectorIntResize(void)
146 tet_infoline("Testing Dali::Vector<short>::Resize");
148 Vector< short > vector;
149 DALI_TEST_EQUALS( ZERO, vector.Count(), TEST_LOCATION );
150 DALI_TEST_EQUALS( ZERO, vector.Capacity(), TEST_LOCATION );
152 vector.Resize( 10u );
153 DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(10), vector.Count(), TEST_LOCATION );
154 DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(10), vector.Capacity(), TEST_LOCATION );
157 DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(4), vector.Count(), TEST_LOCATION );
158 DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(10), vector.Capacity(), TEST_LOCATION );
161 DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(4), vector.Count(), TEST_LOCATION );
162 DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(10), vector.Capacity(), TEST_LOCATION );
165 DALI_TEST_EQUALS( ZERO, vector.Count(), TEST_LOCATION );
166 DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(10), vector.Capacity(), TEST_LOCATION );
168 vector.Resize( 12u, 123 );
169 DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(12), vector.Count(), TEST_LOCATION );
170 DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(12), vector.Capacity(), TEST_LOCATION );
172 DALI_TEST_EQUALS( vector[ 0 ], 123, TEST_LOCATION );
173 DALI_TEST_EQUALS( vector[ 1 ], 123, TEST_LOCATION );
174 DALI_TEST_EQUALS( vector[ 2 ], 123, TEST_LOCATION );
175 DALI_TEST_EQUALS( vector[ 3 ], 123, TEST_LOCATION );
176 DALI_TEST_EQUALS( vector[ 4 ], 123, TEST_LOCATION );
177 DALI_TEST_EQUALS( vector[ 5 ], 123, TEST_LOCATION );
178 DALI_TEST_EQUALS( vector[ 6 ], 123, TEST_LOCATION );
179 DALI_TEST_EQUALS( vector[ 7 ], 123, TEST_LOCATION );
180 DALI_TEST_EQUALS( vector[ 8 ], 123, TEST_LOCATION );
181 DALI_TEST_EQUALS( vector[ 9 ], 123, TEST_LOCATION );
182 DALI_TEST_EQUALS( vector[ 10 ], 123, TEST_LOCATION );
183 DALI_TEST_EQUALS( vector[ 11 ], 123, TEST_LOCATION );
185 vector.Resize( 13u, 321 );
186 DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(13), vector.Count(), TEST_LOCATION );
187 DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(13), vector.Capacity(), TEST_LOCATION );
189 DALI_TEST_EQUALS( vector[ 0 ], 123, TEST_LOCATION );
190 DALI_TEST_EQUALS( vector[ 1 ], 123, TEST_LOCATION );
191 DALI_TEST_EQUALS( vector[ 2 ], 123, TEST_LOCATION );
192 DALI_TEST_EQUALS( vector[ 3 ], 123, TEST_LOCATION );
193 DALI_TEST_EQUALS( vector[ 4 ], 123, TEST_LOCATION );
194 DALI_TEST_EQUALS( vector[ 5 ], 123, TEST_LOCATION );
195 DALI_TEST_EQUALS( vector[ 6 ], 123, TEST_LOCATION );
196 DALI_TEST_EQUALS( vector[ 7 ], 123, TEST_LOCATION );
197 DALI_TEST_EQUALS( vector[ 8 ], 123, TEST_LOCATION );
198 DALI_TEST_EQUALS( vector[ 9 ], 123, TEST_LOCATION );
199 DALI_TEST_EQUALS( vector[ 10 ], 123, TEST_LOCATION );
200 DALI_TEST_EQUALS( vector[ 11 ], 123, TEST_LOCATION );
201 DALI_TEST_EQUALS( vector[ 12 ], 321, TEST_LOCATION );
205 int UtcDaliVectorIntErase(void)
207 tet_infoline("Testing Dali::Vector<short>::Erase");
209 Vector< char > vector;
210 DALI_TEST_EQUALS( ZERO, vector.Count(), TEST_LOCATION );
211 DALI_TEST_EQUALS( ZERO, vector.Capacity(), TEST_LOCATION );
212 vector.PushBack( 1 );
213 vector.PushBack( 2 );
214 vector.PushBack( 3 );
215 vector.PushBack( 4 );
216 vector.PushBack( 5 );
217 DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(5), vector.Count(), TEST_LOCATION );
218 DALI_TEST_EQUALS( vector[ 0 ], 1, TEST_LOCATION );
219 DALI_TEST_EQUALS( vector[ 1 ], 2, TEST_LOCATION );
220 DALI_TEST_EQUALS( vector[ 2 ], 3, TEST_LOCATION );
221 DALI_TEST_EQUALS( vector[ 3 ], 4, TEST_LOCATION );
222 DALI_TEST_EQUALS( vector[ 4 ], 5, TEST_LOCATION );
224 vector.Erase( vector.Begin() );
225 DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(4), vector.Count(), TEST_LOCATION );
226 DALI_TEST_EQUALS( vector[ 0 ], 2, TEST_LOCATION );
227 DALI_TEST_EQUALS( vector[ 1 ], 3, TEST_LOCATION );
228 DALI_TEST_EQUALS( vector[ 2 ], 4, TEST_LOCATION );
229 DALI_TEST_EQUALS( vector[ 3 ], 5, TEST_LOCATION );
231 Vector< char >::Iterator ret = vector.Erase( std::find( vector.Begin(), vector.End(), 4 ) );
232 DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(3), vector.Count(), TEST_LOCATION );
233 DALI_TEST_EQUALS( vector[ 0 ], 2, TEST_LOCATION );
234 DALI_TEST_EQUALS( vector[ 1 ], 3, TEST_LOCATION );
235 DALI_TEST_EQUALS( vector[ 2 ], 5, TEST_LOCATION );
236 DALI_TEST_EQUALS( *ret, 5, TEST_LOCATION );
239 vector.PushBack( 99 );
240 DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(4), vector.Count(), TEST_LOCATION );
241 DALI_TEST_EQUALS( vector[ 3 ], 99, TEST_LOCATION );
242 ret = vector.Erase( vector.End() - 1 );
243 DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(3), vector.Count(), TEST_LOCATION );
244 DALI_TEST_EQUALS( ret, vector.End(), TEST_LOCATION );
248 // illegal erase, one past the end
249 vector.Erase( vector.End() );
250 tet_result(TET_FAIL);
252 catch( Dali::DaliException& e )
254 DALI_TEST_PRINT_ASSERT( e );
255 DALI_TEST_ASSERT( e, "(iterator < End())", TEST_LOCATION );
259 tet_printf("Assertion test failed - wrong Exception\n" );
260 tet_result(TET_FAIL);
265 // illegal erase, one before the begin
266 vector.Erase( vector.Begin() - 1u );
267 tet_result(TET_FAIL);
269 catch( Dali::DaliException& e )
271 DALI_TEST_PRINT_ASSERT( e );
272 DALI_TEST_ASSERT( e, "(iterator < End()) && (iterator >= Begin())", TEST_LOCATION );
276 tet_printf("Assertion test failed - wrong Exception\n" );
277 tet_result(TET_FAIL);
281 DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(3), vector.Count(), TEST_LOCATION );
282 DALI_TEST_EQUALS( vector[ 0 ], 2, TEST_LOCATION );
283 DALI_TEST_EQUALS( vector[ 1 ], 3, TEST_LOCATION );
284 DALI_TEST_EQUALS( vector[ 2 ], 5, TEST_LOCATION );
286 vector.Erase( vector.Begin() + 1 );
287 DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(2), vector.Count(), TEST_LOCATION );
288 DALI_TEST_EQUALS( vector[ 0 ], 2, TEST_LOCATION );
289 DALI_TEST_EQUALS( vector[ 1 ], 5, TEST_LOCATION );
291 vector.Erase( vector.Begin() + 1 );
292 DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(1), vector.Count(), TEST_LOCATION );
293 DALI_TEST_EQUALS( vector[ 0 ], 2, TEST_LOCATION );
297 // illegal erase, one past the end
298 vector.Erase( vector.Begin() + 1 );
299 tet_result(TET_FAIL);
301 catch( Dali::DaliException& e )
303 DALI_TEST_PRINT_ASSERT( e );
304 DALI_TEST_ASSERT( e, "(iterator < End())", TEST_LOCATION );
308 tet_printf("Assertion test failed - wrong Exception\n" );
309 tet_result(TET_FAIL);
311 DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(1), vector.Count(), TEST_LOCATION );
312 DALI_TEST_EQUALS( vector[ 0 ], 2, TEST_LOCATION );
314 vector.Erase( vector.Begin() );
315 DALI_TEST_EQUALS( ZERO, vector.Count(), TEST_LOCATION );
319 // illegal erase, one before the beginning
320 vector.Erase( vector.Begin() - 1 );
321 tet_result(TET_FAIL);
323 catch( Dali::DaliException& e )
325 DALI_TEST_PRINT_ASSERT( e );
326 DALI_TEST_ASSERT( e, "(iterator < End())", TEST_LOCATION );
330 tet_printf("Assertion test failed - wrong Exception\n" );
331 tet_result(TET_FAIL);
334 DALI_TEST_EQUALS( ZERO, vector.Count(), TEST_LOCATION );
335 DALI_TEST_EQUALS( vector.Begin(), vector.End(), TEST_LOCATION );
337 Vector< char >::Iterator endIter = vector.End();
338 for( Vector< char >::Iterator iter = vector.Begin(); iter != endIter; ++iter )
340 tet_result(TET_FAIL);
343 vector.PushBack( 3 );
344 DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(1), vector.Count(), TEST_LOCATION );
347 DALI_TEST_EQUALS( ZERO, vector.Count(), TEST_LOCATION );
348 DALI_TEST_EQUALS( vector.Begin(), vector.End(), TEST_LOCATION );
350 endIter = vector.End();
351 for( Vector< char >::Iterator iter = vector.Begin(); iter != endIter; ++iter )
353 tet_result(TET_FAIL);
356 // test a vector of pointers
357 Vector< int* > ptrVector;
358 DALI_TEST_EQUALS( ZERO, ptrVector.Count(), TEST_LOCATION );
359 DALI_TEST_EQUALS( ptrVector.Begin(), ptrVector.End(), TEST_LOCATION );
362 ptrVector.PushBack( pointer );
363 DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(1), ptrVector.Count(), TEST_LOCATION );
365 Vector< int* >::Iterator ptriter = std::find( ptrVector.Begin(), ptrVector.End(), pointer );
366 ptriter = ptrVector.Erase( ptriter );
367 DALI_TEST_EQUALS( ZERO, ptrVector.Count(), TEST_LOCATION );
368 DALI_TEST_EQUALS( ptrVector.Begin(), ptrVector.End(), TEST_LOCATION );
369 DALI_TEST_EQUALS( ptrVector.Begin(), ptriter, TEST_LOCATION );
374 int UtcDaliVectorDoubleRemove(void)
376 tet_infoline("Testing Dali::Vector<double>::Remove");
378 Vector< double > vector;
379 DALI_TEST_EQUALS( ZERO, vector.Count(), TEST_LOCATION );
381 vector.PushBack( 11.1 );
382 vector.PushBack( 22.2 );
383 vector.PushBack( 33.3 );
384 vector.PushBack( 44.4 );
385 DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(4), vector.Count(), TEST_LOCATION );
386 DALI_TEST_EQUALS( vector[ 0 ], 11.1, TEST_LOCATION );
387 DALI_TEST_EQUALS( vector[ 1 ], 22.2, TEST_LOCATION );
388 DALI_TEST_EQUALS( vector[ 2 ], 33.3, TEST_LOCATION );
389 DALI_TEST_EQUALS( vector[ 3 ], 44.4, TEST_LOCATION );
391 Vector< double >::Iterator res = std::find( vector.Begin(), vector.End(), 22.2 );
392 DALI_TEST_EQUALS( 22.2, *res, TEST_LOCATION );
393 vector.Remove( res );
394 res = std::find( vector.Begin(), vector.End(), 22.2 );
395 DALI_TEST_EQUALS( vector.End(), res, TEST_LOCATION );
396 DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(3), vector.Count(), TEST_LOCATION );
397 DALI_TEST_EQUALS( vector[ 0 ], 11.1, TEST_LOCATION );
398 DALI_TEST_EQUALS( vector[ 1 ], 44.4, TEST_LOCATION );
399 DALI_TEST_EQUALS( vector[ 2 ], 33.3, TEST_LOCATION );
401 vector.Remove( vector.End() - 1 );
402 DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(2), vector.Count(), TEST_LOCATION );
403 DALI_TEST_EQUALS( vector[ 0 ], 11.1, TEST_LOCATION );
404 DALI_TEST_EQUALS( vector[ 1 ], 44.4, TEST_LOCATION );
406 vector.Remove( vector.Begin() );
407 DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(1), vector.Count(), TEST_LOCATION );
408 DALI_TEST_EQUALS( vector[ 0 ], 44.4, TEST_LOCATION );
412 // illegal erase, one past the end
413 vector.Remove( vector.Begin() + 1 );
414 tet_result(TET_FAIL);
416 catch( Dali::DaliException& e )
418 DALI_TEST_PRINT_ASSERT( e );
419 DALI_TEST_ASSERT( e, "(iterator < End()) && (iterator >= Begin())", TEST_LOCATION );
423 tet_printf("Assertion test failed - wrong Exception\n" );
424 tet_result(TET_FAIL);
426 DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(1), vector.Count(), TEST_LOCATION );
427 DALI_TEST_EQUALS( vector[ 0 ], 44.4, TEST_LOCATION );
429 vector.Remove( vector.Begin() );
430 DALI_TEST_EQUALS( ZERO, vector.Count(), TEST_LOCATION );
434 // illegal erase, one before the beginning
435 vector.Remove( vector.Begin() - 1 );
436 tet_result(TET_FAIL);
438 catch( Dali::DaliException& e )
440 DALI_TEST_PRINT_ASSERT( e );
441 DALI_TEST_ASSERT( e, "(iterator < End()) && (iterator >= Begin())", TEST_LOCATION );
445 tet_printf("Assertion test failed - wrong Exception\n" );
446 tet_result(TET_FAIL);
452 int UtcDaliVectorIntSwap(void)
454 tet_infoline("Testing Dali::Vector<int>::Swap");
456 Vector< int > intvector;
457 DALI_TEST_EQUALS( ZERO, intvector.Count(), TEST_LOCATION );
458 DALI_TEST_EQUALS( ZERO, intvector.Capacity(), TEST_LOCATION );
460 intvector.PushBack( 11 );
461 intvector.PushBack( 22 );
462 intvector.PushBack( 33 );
463 DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(3), intvector.Count(), TEST_LOCATION );
465 Vector< int > intvector2;
466 DALI_TEST_EQUALS( ZERO, intvector2.Count(), TEST_LOCATION );
467 DALI_TEST_EQUALS( ZERO, intvector2.Capacity(), TEST_LOCATION );
469 intvector2.Swap( intvector );
470 DALI_TEST_EQUALS( ZERO, intvector.Count(), TEST_LOCATION );
471 DALI_TEST_EQUALS( ZERO, intvector.Capacity(), TEST_LOCATION );
472 DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(3), intvector2.Count(), TEST_LOCATION );
473 DALI_TEST_EQUALS( 11, intvector2[ 0 ], TEST_LOCATION );
474 DALI_TEST_EQUALS( 22, intvector2[ 1 ], TEST_LOCATION );
475 DALI_TEST_EQUALS( 33, intvector2[ 2 ], TEST_LOCATION );
477 intvector.PushBack( 99 );
478 intvector.PushBack( 88 );
479 DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(2), intvector.Count(), TEST_LOCATION );
481 intvector.Swap( intvector2 );
482 DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(2), intvector2.Count(), TEST_LOCATION );
483 DALI_TEST_EQUALS( 99, intvector2[ 0 ], TEST_LOCATION );
484 DALI_TEST_EQUALS( 88, intvector2[ 1 ], TEST_LOCATION );
485 DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(3), intvector.Count(), TEST_LOCATION );
486 DALI_TEST_EQUALS( 11, intvector[ 0 ], TEST_LOCATION );
487 DALI_TEST_EQUALS( 22, intvector[ 1 ], TEST_LOCATION );
488 DALI_TEST_EQUALS( 33, intvector[ 2 ], TEST_LOCATION );
491 intvector.Swap( empty );
492 DALI_TEST_EQUALS( ZERO, intvector.Count(), TEST_LOCATION );
493 DALI_TEST_EQUALS( ZERO, intvector.Capacity(), TEST_LOCATION );
497 int UtcDaliVectorIterate(void)
499 tet_infoline("Testing Dali::Vector<float>::Begin");
501 Vector< float > floatvector;
502 DALI_TEST_EQUALS( ZERO, floatvector.Count(), TEST_LOCATION );
503 DALI_TEST_EQUALS( ZERO, floatvector.Capacity(), TEST_LOCATION );
505 floatvector.PushBack( 0.9f );
506 floatvector.PushBack( 1.1f );
507 floatvector.PushBack( 1.2f );
508 DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(3), floatvector.Count(), TEST_LOCATION );
510 Vector< float >::Iterator iter = floatvector.Begin();
512 for( ; iter != floatvector.End(); ++iter, ++index )
514 std::cout << "value " << *iter << std::endl;
515 DALI_TEST_EQUALS( *iter, floatvector[ index ], TEST_LOCATION );
517 DALI_TEST_EQUALS( 3, index, TEST_LOCATION );
519 iter = std::find( floatvector.Begin(), floatvector.End(), 1.1f );
520 DALI_TEST_EQUALS( 1.1f, *iter, TEST_LOCATION );
523 iter = std::find( floatvector.Begin(), floatvector.End(), 1.1f );
524 DALI_TEST_EQUALS( floatvector.End(), iter, TEST_LOCATION );
528 int UtcDaliVectorPair(void)
530 tet_infoline("Testing Dali::Vector< std::pair< int, float > >");
532 Vector< std::pair< int, float > > pairvector;
533 DALI_TEST_EQUALS( ZERO, pairvector.Count(), TEST_LOCATION );
534 DALI_TEST_EQUALS( ZERO, pairvector.Capacity(), TEST_LOCATION );
536 pairvector.PushBack( std::make_pair( 5, 0.1f ) );
537 pairvector.PushBack( std::make_pair( 3, 0.2f ) );
538 pairvector.PushBack( std::make_pair( 4, 0.3f ) );
539 pairvector.PushBack( std::make_pair( 1, 0.4f ) );
540 pairvector.PushBack( std::make_pair( 2, 0.5f ) );
541 DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(5), pairvector.Count(), TEST_LOCATION );
543 Vector< std::pair< int, float > >::Iterator iter = pairvector.Begin();
545 for( ; iter != pairvector.End(); ++iter, ++index )
547 std::cout << "pair " << (*iter).first << ":" << (*iter).second << std::endl;
548 DALI_TEST_EQUALS( (*iter).first, pairvector[ index ].first, TEST_LOCATION );
549 DALI_TEST_EQUALS( (*iter).second, pairvector[ index ].second, TEST_LOCATION );
554 int UtcDaliVectorAsserts(void)
556 tet_infoline("Testing Dali::Vector< int* > exception handling");
559 Vector< int* > pointervector;
563 pointervector[ 1 ] = value;
564 tet_printf("Assertion expected, but not occurred at %s\n", TEST_LOCATION );
565 tet_result(TET_FAIL);
567 catch(Dali::DaliException& e)
569 DALI_TEST_PRINT_ASSERT( e );
570 DALI_TEST_ASSERT( e, "VectorBase::mData", TEST_LOCATION );
574 tet_printf("Assertion test failed - wrong Exception\n" );
575 tet_result(TET_FAIL);
581 value = pointervector[ 0 ];
582 (void)value; // to "use" the value
583 tet_printf("Assertion expected, but not occurred at %s\n", TEST_LOCATION );
584 tet_result(TET_FAIL);
586 catch(Dali::DaliException& e)
588 DALI_TEST_PRINT_ASSERT( e );
589 DALI_TEST_ASSERT( e, "VectorBase::mData", TEST_LOCATION );
593 tet_printf("Assertion test failed - wrong Exception\n" );
594 tet_result(TET_FAIL);
597 Vector< int* >::Iterator iter = pointervector.Begin();
598 if( iter != pointervector.End() )
600 tet_result(TET_FAIL);
605 pointervector.Erase( pointervector.Begin() );
606 tet_printf("Assertion expected, but not occurred at %s\n", TEST_LOCATION );
607 tet_result(TET_FAIL);
609 catch(Dali::DaliException& e)
611 DALI_TEST_PRINT_ASSERT( e );
612 DALI_TEST_ASSERT( e, "(iterator < End()) && (iterator >= Begin())", TEST_LOCATION );
616 tet_printf("Assertion test failed - wrong Exception\n" );
617 tet_result(TET_FAIL);
620 iter = pointervector.Begin();
621 if( iter != pointervector.End() )
623 tet_result(TET_FAIL);
628 pointervector.Remove( pointervector.Begin() );
629 tet_printf("Assertion expected, but not occurred at %s\n", TEST_LOCATION );
630 tet_result(TET_FAIL);
632 catch(Dali::DaliException& e)
634 DALI_TEST_PRINT_ASSERT( e );
635 DALI_TEST_ASSERT( e, "(iterator < End()) && (iterator >= Begin())", TEST_LOCATION );
639 tet_printf("Assertion test failed - wrong Exception\n" );
640 tet_result(TET_FAIL);
643 iter = pointervector.Begin();
644 if( iter != pointervector.End() )
646 tet_result(TET_FAIL);
650 pointervector.Reserve( 0 );
651 iter = pointervector.Begin();
652 if( iter != pointervector.End() )
654 tet_result(TET_FAIL);
658 pointervector.Reserve( 1 );
659 iter = pointervector.Begin();
660 if( iter != pointervector.End() )
662 tet_result(TET_FAIL);
668 pointervector[ 1 ] = value;
669 tet_printf("Assertion expected, but not occurred at %s\n", TEST_LOCATION );
670 tet_result(TET_FAIL);
672 catch(Dali::DaliException& e)
674 DALI_TEST_PRINT_ASSERT( e );
675 DALI_TEST_ASSERT( e, "index < VectorBase::Count()", TEST_LOCATION );
679 tet_printf("Assertion test failed - wrong Exception\n" );
680 tet_result(TET_FAIL);
685 int* value = pointervector[ 1 ];
686 (void)value; // to "use" the value
687 tet_printf("Assertion expected, but not occurred at %s\n", TEST_LOCATION );
688 tet_result(TET_FAIL);
690 catch(Dali::DaliException& e)
692 DALI_TEST_PRINT_ASSERT( e );
693 DALI_TEST_ASSERT( e, "index < VectorBase::Count()", TEST_LOCATION );
697 tet_printf("Assertion test failed - wrong Exception\n" );
698 tet_result(TET_FAIL);
704 int UtcDaliVectorAcidTest(void)
706 tet_infoline("Testing multiple Dali::Vector's");
708 // create multiple vectors
709 Vector< std::pair< float, float > > pairvector;
710 DALI_TEST_EQUALS( ZERO, pairvector.Count(), TEST_LOCATION );
711 DALI_TEST_EQUALS( ZERO, pairvector.Capacity(), TEST_LOCATION );
712 Vector< double > doublevector;
713 DALI_TEST_EQUALS( ZERO, doublevector.Count(), TEST_LOCATION );
714 DALI_TEST_EQUALS( ZERO, doublevector.Capacity(), TEST_LOCATION );
715 Vector< int* > intptrvector;
716 DALI_TEST_EQUALS( ZERO, intptrvector.Count(), TEST_LOCATION );
717 DALI_TEST_EQUALS( ZERO, intptrvector.Capacity(), TEST_LOCATION );
718 Vector< Dali::Actor* > actorptrvector;
719 DALI_TEST_EQUALS( ZERO, actorptrvector.Count(), TEST_LOCATION );
720 DALI_TEST_EQUALS( ZERO, actorptrvector.Capacity(), TEST_LOCATION );
721 Vector< long > longvector;
722 DALI_TEST_EQUALS( ZERO, longvector.Count(), TEST_LOCATION );
723 DALI_TEST_EQUALS( ZERO, longvector.Capacity(), TEST_LOCATION );
724 Vector< char > charvector;
725 DALI_TEST_EQUALS( ZERO, charvector.Count(), TEST_LOCATION );
726 DALI_TEST_EQUALS( ZERO, charvector.Capacity(), TEST_LOCATION );
729 static unsigned int acidCount = 10000;
731 for( unsigned int i = 0; i < acidCount; ++i )
733 pairvector.PushBack( std::make_pair( i, i ) );
734 doublevector.PushBack( (double)i );
735 intptrvector.PushBack( (int*)ptr );
736 actorptrvector.PushBack( (Dali::Actor*)ptr );
737 longvector.PushBack( (long)i );
738 charvector.PushBack( (char)i );
740 DALI_TEST_EQUALS( acidCount, pairvector.Count(), TEST_LOCATION );
741 std::size_t pairCapacity = pairvector.Capacity();
742 DALI_TEST_EQUALS( acidCount, doublevector.Count(), TEST_LOCATION );
743 std::size_t doubleCapacity = doublevector.Capacity();
744 DALI_TEST_EQUALS( acidCount, intptrvector.Count(), TEST_LOCATION );
745 std::size_t intptrCapacity = intptrvector.Capacity();
746 DALI_TEST_EQUALS( acidCount, actorptrvector.Count(), TEST_LOCATION );
747 std::size_t actorptrCapacity = actorptrvector.Capacity();
748 DALI_TEST_EQUALS( acidCount, longvector.Count(), TEST_LOCATION );
749 std::size_t longCapacity = longvector.Capacity();
750 DALI_TEST_EQUALS( acidCount, charvector.Count(), TEST_LOCATION );
751 std::size_t charCapacity = charvector.Capacity();
753 tet_printf("Dali::Vector< pair > capacity after %d pushbacks is %d", acidCount, pairCapacity );
754 tet_printf("Dali::Vector< double > capacity after %d pushbacks is %d", acidCount, doubleCapacity );
755 tet_printf("Dali::Vector< int* > capacity after %d pushbacks is %d", acidCount, intptrCapacity );
756 tet_printf("Dali::Vector< Actor* > capacity after %d pushbacks is %d", acidCount, actorptrCapacity );
757 tet_printf("Dali::Vector< long > capacity after %d pushbacks is %d", acidCount, longCapacity );
758 tet_printf("Dali::Vector< char > capacity after %d pushbacks is %d", acidCount, charCapacity );
761 for( unsigned int i = 0; i < acidCount; ++i )
763 pairvector.Erase( pairvector.Begin() + ( i % pairvector.Count() ) );
764 doublevector.Erase( doublevector.Begin() + ( i % doublevector.Count() ) );
765 intptrvector.Erase( intptrvector.Begin() + ( i % intptrvector.Count() ) );
766 actorptrvector.Erase( actorptrvector.Begin() + ( i % actorptrvector.Count() ) );
767 longvector.Erase( longvector.Begin() + ( i % longvector.Count() ) );
768 charvector.Erase( charvector.Begin() + ( i % charvector.Count() ) );
770 DALI_TEST_EQUALS( ZERO, pairvector.Count(), TEST_LOCATION );
771 DALI_TEST_EQUALS( pairCapacity, pairvector.Capacity(), TEST_LOCATION );
772 DALI_TEST_EQUALS( ZERO, doublevector.Count(), TEST_LOCATION );
773 DALI_TEST_EQUALS( doubleCapacity, doublevector.Capacity(), TEST_LOCATION );
774 DALI_TEST_EQUALS( ZERO, intptrvector.Count(), TEST_LOCATION );
775 DALI_TEST_EQUALS( intptrCapacity, intptrvector.Capacity(), TEST_LOCATION );
776 DALI_TEST_EQUALS( ZERO, actorptrvector.Count(), TEST_LOCATION );
777 DALI_TEST_EQUALS( actorptrCapacity, actorptrvector.Capacity(), TEST_LOCATION );
778 DALI_TEST_EQUALS( ZERO, longvector.Count(), TEST_LOCATION );
779 DALI_TEST_EQUALS( longCapacity, longvector.Capacity(), TEST_LOCATION );
780 DALI_TEST_EQUALS( ZERO, charvector.Count(), TEST_LOCATION );
781 DALI_TEST_EQUALS( charCapacity, charvector.Capacity(), TEST_LOCATION );
786 int UtcDaliVectorPushBack(void)
788 tet_infoline( "Testing Dali::Vector< int* >PushBack(Element)" );
790 Vector<unsigned int> vector;
791 DALI_TEST_EQUALS( ZERO, vector.Count(), TEST_LOCATION );
792 DALI_TEST_EQUALS( ZERO, vector.Capacity(), TEST_LOCATION );
794 vector.Reserve( 2u );
795 DALI_TEST_EQUALS( ZERO, vector.Count(), TEST_LOCATION );
796 DALI_TEST_EQUALS( 2u, vector.Capacity(), TEST_LOCATION );
798 vector.PushBack( 0u );
799 vector.PushBack( 1u );
800 vector.PushBack( 2u );
802 DALI_TEST_EQUALS( 3u, vector.Count(), TEST_LOCATION );
803 DALI_TEST_EQUALS( 6u, vector.Capacity(), TEST_LOCATION );
805 vector.PushBack( 3u );
807 DALI_TEST_EQUALS( 4u, vector.Count(), TEST_LOCATION );
808 DALI_TEST_EQUALS( 6u, vector.Capacity(), TEST_LOCATION );
810 DALI_TEST_EQUALS( 0u, vector[0u], TEST_LOCATION );
811 DALI_TEST_EQUALS( 1u, vector[1u], TEST_LOCATION );
812 DALI_TEST_EQUALS( 2u, vector[2u], TEST_LOCATION );
813 DALI_TEST_EQUALS( 3u, vector[3u], TEST_LOCATION );
818 int UtcDaliVectorInsert01(void)
820 tet_infoline( "Testing Dali::Vector< int* >Insert(Iterator, Element)" );
822 // Test order of array inserted-into:
823 Vector< unsigned int > orderedVector;
824 orderedVector.PushBack( 9u );
825 for( unsigned int i = 8u; i <= 8u; --i )
827 orderedVector.Insert( orderedVector.Begin(), i );
828 DALI_TEST_EQUALS( 10u - i, orderedVector.Count(), TEST_LOCATION );
829 DALI_TEST_EQUALS( i, orderedVector[0u], TEST_LOCATION );
832 for( unsigned int i = 0u; i < 10u; ++i )
834 DALI_TEST_EQUALS( i, orderedVector[i], TEST_LOCATION );
837 // Test insertion out of range in non-empty array throws:
840 orderedVector.Insert( orderedVector.Begin() + 99u, 99u );
841 tet_printf( "Assertion expected, but not occurred at %s\n", TEST_LOCATION );
842 tet_result( TET_FAIL );
844 catch( Dali::DaliException& e )
846 DALI_TEST_PRINT_ASSERT( e );
847 DALI_TEST_ASSERT( e, "( at <= End() ) && ( at >= Begin() )", TEST_LOCATION );
851 tet_printf( "Assertion test failed - wrong Exception\n" );
852 tet_result( TET_FAIL );
857 orderedVector.Insert( orderedVector.Begin() - 1u, 99u );
858 tet_printf( "Assertion expected, but not occurred at %s\n", TEST_LOCATION );
859 tet_result( TET_FAIL );
861 catch( Dali::DaliException& e )
863 DALI_TEST_PRINT_ASSERT( e );
864 DALI_TEST_ASSERT( e, "( at <= End() ) && ( at >= Begin() )", TEST_LOCATION );
868 tet_printf( "Assertion test failed - wrong Exception\n" );
869 tet_result( TET_FAIL );
872 // Test insertion part-way through a largish array retains ordering:
874 // Build vector with hole in sequence:
875 Vector< unsigned int > longerVector;
876 const unsigned int insertionPoint = 131571u;
877 const unsigned int finalLength = 262143u;
878 for( unsigned int i = 0u; i < insertionPoint; ++i )
880 longerVector.PushBack( i );
882 for( unsigned int i = insertionPoint; i < finalLength; ++i )
884 longerVector.PushBack( i + 1 );
887 // Fill the hole in the sequence:
888 longerVector.Insert( longerVector.Begin() + insertionPoint, insertionPoint );
890 // Check the sequence is monotonically increasing by one every time:
891 for( unsigned int i = 0u; i <= finalLength; ++i )
893 DALI_TEST_EQUALS( i, longerVector[i], TEST_LOCATION );
896 // Insert into an empty vector
897 Vector< unsigned int > vector;
899 vector.Insert( vector.End(), orderedVector.Begin(), orderedVector.End() );
900 for( unsigned int i = 0u; i < 10u; ++i )
902 DALI_TEST_EQUALS( i, vector[i], TEST_LOCATION );
906 vector.Insert( vector.Begin(), orderedVector.Begin(), orderedVector.End() );
907 for( unsigned int i = 0u; i < 10u; ++i )
909 DALI_TEST_EQUALS( i, vector[i], TEST_LOCATION );
913 vector.Insert( vector.Begin(), orderedVector.Begin(), orderedVector.Begin() );
914 for( unsigned int i = 0u; i < 10u; ++i )
916 DALI_TEST_EQUALS( i, vector[i], TEST_LOCATION );
919 vector.Insert( vector.Begin() + 5, vector.Begin() + 5, vector.Begin() + 5 );
920 for( unsigned int i = 0u; i < 10u; ++i )
922 DALI_TEST_EQUALS( i, vector[i], TEST_LOCATION );
927 vector.PushBack( 0u );
928 vector.PushBack( 1u );
929 vector.PushBack( 2u );
930 vector.PushBack( 3u );
932 vector.Insert( vector.Begin() + 2, vector.Begin(), vector.End() );
933 DALI_TEST_EQUALS( 8u, vector.Count(), TEST_LOCATION );
934 DALI_TEST_EQUALS( 0u, vector[0u], TEST_LOCATION );
935 DALI_TEST_EQUALS( 1u, vector[1u], TEST_LOCATION );
936 DALI_TEST_EQUALS( 0u, vector[2u], TEST_LOCATION );
937 DALI_TEST_EQUALS( 1u, vector[3u], TEST_LOCATION );
938 DALI_TEST_EQUALS( 2u, vector[4u], TEST_LOCATION );
939 DALI_TEST_EQUALS( 3u, vector[5u], TEST_LOCATION );
940 DALI_TEST_EQUALS( 2u, vector[6u], TEST_LOCATION );
941 DALI_TEST_EQUALS( 3u, vector[7u], TEST_LOCATION );
946 int UtcDaliVectorInsert02(void)
948 tet_infoline("Testing Dali::Vector<char>::Insert(Iterator,Iterator,Iterator)");
950 Vector< char > vector;
951 DALI_TEST_EQUALS( ZERO, vector.Count(), TEST_LOCATION );
952 DALI_TEST_EQUALS( ZERO, vector.Capacity(), TEST_LOCATION );
953 vector.PushBack( 1 );
954 vector.PushBack( 2 );
955 vector.PushBack( 3 );
956 vector.PushBack( 4 );
957 vector.PushBack( 5 );
959 Vector< char > vector2;
960 DALI_TEST_EQUALS( ZERO, vector2.Count(), TEST_LOCATION );
961 DALI_TEST_EQUALS( ZERO, vector2.Capacity(), TEST_LOCATION );
962 vector2.PushBack( 6 );
963 vector2.PushBack( 7 );
964 vector2.PushBack( 8 );
965 vector2.PushBack( 9 );
966 vector2.PushBack( 10 );
968 // Test insert at end
969 vector.Insert( vector.End(), vector2.Begin(), vector2.Begin() + 1u );
970 DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(6), vector.Count(), TEST_LOCATION );
971 DALI_TEST_EQUALS( vector[ 0 ], 1, TEST_LOCATION );
972 DALI_TEST_EQUALS( vector[ 1 ], 2, TEST_LOCATION );
973 DALI_TEST_EQUALS( vector[ 2 ], 3, TEST_LOCATION );
974 DALI_TEST_EQUALS( vector[ 3 ], 4, TEST_LOCATION );
975 DALI_TEST_EQUALS( vector[ 4 ], 5, TEST_LOCATION );
976 DALI_TEST_EQUALS( vector[ 5 ], 6, TEST_LOCATION );
978 // Test insert at begin
979 vector.Insert( vector.Begin(), vector2.Begin()+1, vector2.Begin() + 2u );
980 DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(7), vector.Count(), TEST_LOCATION );
981 DALI_TEST_EQUALS( vector[ 0 ], 7, TEST_LOCATION );
982 DALI_TEST_EQUALS( vector[ 1 ], 1, TEST_LOCATION );
983 DALI_TEST_EQUALS( vector[ 2 ], 2, TEST_LOCATION );
984 DALI_TEST_EQUALS( vector[ 3 ], 3, TEST_LOCATION );
985 DALI_TEST_EQUALS( vector[ 4 ], 4, TEST_LOCATION );
986 DALI_TEST_EQUALS( vector[ 5 ], 5, TEST_LOCATION );
987 DALI_TEST_EQUALS( vector[ 6 ], 6, TEST_LOCATION );
989 // Test insert in the middle
990 vector.Insert( vector.Begin() + 3, vector2.Begin()+3, vector2.End() );
991 DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(9), vector.Count(), TEST_LOCATION );
992 DALI_TEST_EQUALS( vector[ 0 ], 7, TEST_LOCATION );
993 DALI_TEST_EQUALS( vector[ 1 ], 1, TEST_LOCATION );
994 DALI_TEST_EQUALS( vector[ 2 ], 2, TEST_LOCATION );
995 DALI_TEST_EQUALS( vector[ 3 ], 9, TEST_LOCATION );
996 DALI_TEST_EQUALS( vector[ 4 ], 10, TEST_LOCATION );
997 DALI_TEST_EQUALS( vector[ 5 ], 3, TEST_LOCATION );
998 DALI_TEST_EQUALS( vector[ 6 ], 4, TEST_LOCATION );
999 DALI_TEST_EQUALS( vector[ 7 ], 5, TEST_LOCATION );
1000 DALI_TEST_EQUALS( vector[ 8 ], 6, TEST_LOCATION );
1004 int UtcDaliVectorIntInsertAssert(void)
1006 tet_infoline("Testing Dali::Vector<char>::Insert(Iterator,Iterator,Iterator) asserts");
1008 Vector< char > vector;
1009 DALI_TEST_EQUALS( ZERO, vector.Count(), TEST_LOCATION );
1010 DALI_TEST_EQUALS( ZERO, vector.Capacity(), TEST_LOCATION );
1011 vector.PushBack( 1 );
1012 vector.PushBack( 2 );
1014 Vector< char > vector2;
1015 DALI_TEST_EQUALS( ZERO, vector2.Count(), TEST_LOCATION );
1016 DALI_TEST_EQUALS( ZERO, vector2.Capacity(), TEST_LOCATION );
1017 vector2.PushBack( 6 );
1018 vector2.PushBack( 7 );
1019 vector2.PushBack( 8 );
1020 vector2.PushBack( 9 );
1021 vector2.PushBack( 10 );
1025 vector.Insert( vector.Begin() + 3u, vector2.Begin(), vector2.End() );
1026 tet_result(TET_FAIL);
1028 catch( Dali::DaliException& e )
1030 DALI_TEST_PRINT_ASSERT( e );
1031 DALI_TEST_ASSERT( e, "( at <= End() ) && ( at >= Begin() )", TEST_LOCATION );
1035 tet_printf("Assertion test failed - wrong Exception\n" );
1036 tet_result(TET_FAIL);
1041 vector.Insert( vector.Begin() - 1u, vector2.Begin(), vector2.End() );
1042 tet_result(TET_FAIL);
1044 catch( Dali::DaliException& e )
1046 DALI_TEST_PRINT_ASSERT( e );
1047 DALI_TEST_ASSERT( e, "( at <= End() ) && ( at >= Begin() )", TEST_LOCATION );
1051 tet_printf("Assertion test failed - wrong Exception\n" );
1052 tet_result(TET_FAIL);
1057 vector.Insert( vector.End(), vector2.End(), vector2.Begin() );
1058 tet_result(TET_FAIL);
1060 catch( Dali::DaliException& e )
1062 DALI_TEST_PRINT_ASSERT( e );
1063 DALI_TEST_ASSERT( e, "( from <= to )", TEST_LOCATION );
1067 tet_printf("Assertion test failed - wrong Exception\n" );
1068 tet_result(TET_FAIL);
1075 int UtcDaliVectorIntEraseRange(void)
1077 tet_infoline("Testing Dali::Vector<char>::Erase(Iterator,Iterator)");
1079 Vector< char > vector;
1080 DALI_TEST_EQUALS( ZERO, vector.Count(), TEST_LOCATION );
1081 DALI_TEST_EQUALS( ZERO, vector.Capacity(), TEST_LOCATION );
1083 // Try to delete from empty vector.
1085 vector.Erase( vector.Begin(), vector.End() );
1086 DALI_TEST_EQUALS( ZERO, vector.Count(), TEST_LOCATION );
1087 DALI_TEST_EQUALS( ZERO, vector.Capacity(), TEST_LOCATION );
1089 vector.PushBack( 1 );
1090 vector.PushBack( 2 );
1091 vector.PushBack( 3 );
1092 vector.PushBack( 4 );
1093 vector.PushBack( 5 );
1094 DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(5), vector.Count(), TEST_LOCATION );
1095 DALI_TEST_EQUALS( vector[ 0 ], 1, TEST_LOCATION );
1096 DALI_TEST_EQUALS( vector[ 1 ], 2, TEST_LOCATION );
1097 DALI_TEST_EQUALS( vector[ 2 ], 3, TEST_LOCATION );
1098 DALI_TEST_EQUALS( vector[ 3 ], 4, TEST_LOCATION );
1099 DALI_TEST_EQUALS( vector[ 4 ], 5, TEST_LOCATION );
1101 Vector< char >::Iterator ret;
1103 ret = vector.Erase( vector.Begin() + 1u, vector.Begin() + 2u );
1104 DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(4), vector.Count(), TEST_LOCATION );
1105 DALI_TEST_EQUALS( vector[ 0 ], 1, TEST_LOCATION );
1106 DALI_TEST_EQUALS( vector[ 1 ], 3, TEST_LOCATION );
1107 DALI_TEST_EQUALS( vector[ 2 ], 4, TEST_LOCATION );
1108 DALI_TEST_EQUALS( vector[ 3 ], 5, TEST_LOCATION );
1109 DALI_TEST_EQUALS( *ret, 3, TEST_LOCATION );
1111 ret = vector.Erase( vector.Begin(), vector.Begin() + 2 );
1112 DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(2), vector.Count(), TEST_LOCATION );
1113 DALI_TEST_EQUALS( vector[ 0 ], 4, TEST_LOCATION );
1114 DALI_TEST_EQUALS( vector[ 1 ], 5, TEST_LOCATION );
1115 DALI_TEST_EQUALS( *ret, 4, TEST_LOCATION );
1118 vector.PushBack( 99 );
1119 DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(3), vector.Count(), TEST_LOCATION );
1120 DALI_TEST_EQUALS( vector[ 2 ], 99, TEST_LOCATION );
1121 ret = vector.Erase( vector.Begin() + 1u, vector.End() );
1122 DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(1), vector.Count(), TEST_LOCATION );
1123 DALI_TEST_EQUALS( vector[ 0 ], 4, TEST_LOCATION );
1124 DALI_TEST_EQUALS( ret, vector.End(), TEST_LOCATION );
1127 vector.PushBack( 100 );
1128 vector.PushBack( 101 );
1129 vector.PushBack( 102 );
1131 DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(4), vector.Count(), TEST_LOCATION );
1132 DALI_TEST_EQUALS( vector[ 0 ], 4, TEST_LOCATION );
1133 DALI_TEST_EQUALS( vector[ 1 ], 100, TEST_LOCATION );
1134 DALI_TEST_EQUALS( vector[ 2 ], 101, TEST_LOCATION );
1135 DALI_TEST_EQUALS( vector[ 3 ], 102, TEST_LOCATION );
1137 ret = vector.Erase( vector.Begin(), vector.End() );
1138 DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(0), vector.Count(), TEST_LOCATION );
1139 DALI_TEST_EQUALS( ret, vector.End(), TEST_LOCATION );
1141 // try erase from Iterator to the same Iterator.
1142 vector.PushBack( 100 );
1143 vector.PushBack( 101 );
1144 vector.PushBack( 102 );
1146 DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(3), vector.Count(), TEST_LOCATION );
1147 DALI_TEST_EQUALS( vector[ 0 ], 100, TEST_LOCATION );
1148 DALI_TEST_EQUALS( vector[ 1 ], 101, TEST_LOCATION );
1149 DALI_TEST_EQUALS( vector[ 2 ], 102, TEST_LOCATION );
1151 ret = vector.Erase( vector.Begin() + 1, vector.Begin() + 1 );
1153 DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(3), vector.Count(), TEST_LOCATION );
1154 DALI_TEST_EQUALS( vector[ 0 ], 100, TEST_LOCATION );
1155 DALI_TEST_EQUALS( vector[ 1 ], 101, TEST_LOCATION );
1156 DALI_TEST_EQUALS( vector[ 2 ], 102, TEST_LOCATION );
1158 DALI_TEST_EQUALS( *ret, 101, TEST_LOCATION );
1163 int UtcDaliVectorIntEraseRangeAssert(void)
1165 tet_infoline("Testing Dali::Vector<char>::Erase(Iterator,Iterator) asserts");
1167 Vector< char > vector;
1168 DALI_TEST_EQUALS( ZERO, vector.Count(), TEST_LOCATION );
1169 DALI_TEST_EQUALS( ZERO, vector.Capacity(), TEST_LOCATION );
1172 // Add some elements.
1173 vector.PushBack( 1 );
1174 vector.PushBack( 2 );
1176 // first out of bounds
1179 vector.Erase( vector.Begin() + 3u, vector.Begin() + 4u );
1180 tet_printf( "Assertion expected, but not occurred at %s\n", TEST_LOCATION );
1181 tet_result(TET_FAIL);
1183 catch( Dali::DaliException& e )
1185 DALI_TEST_PRINT_ASSERT( e );
1186 DALI_TEST_ASSERT( e, "( first <= End() ) && ( first >= Begin() )", TEST_LOCATION );
1190 tet_printf("Assertion test failed - wrong Exception\n" );
1191 tet_result(TET_FAIL);
1196 vector.Erase( vector.Begin() - 1u, vector.End() );
1197 tet_printf( "Assertion expected, but not occurred at %s\n", TEST_LOCATION );
1198 tet_result(TET_FAIL);
1200 catch( Dali::DaliException& e )
1202 DALI_TEST_PRINT_ASSERT( e );
1203 DALI_TEST_ASSERT( e, "( first <= End() ) && ( first >= Begin() )", TEST_LOCATION );
1207 tet_printf("Assertion test failed - wrong Exception\n" );
1208 tet_result(TET_FAIL);
1211 // last out of bounds
1215 vector.Erase( vector.Begin(), vector.Begin() + 3u );
1216 tet_printf( "Assertion expected, but not occurred at %s\n", TEST_LOCATION );
1217 tet_result(TET_FAIL);
1219 catch( Dali::DaliException& e )
1221 DALI_TEST_PRINT_ASSERT( e );
1222 DALI_TEST_ASSERT( e, "( last <= End() ) && ( last >= Begin() )", TEST_LOCATION );
1226 tet_printf("Assertion test failed - wrong Exception\n" );
1227 tet_result(TET_FAIL);
1232 vector.Erase( vector.Begin(), vector.Begin() - 1u );
1233 tet_printf( "Assertion expected, but not occurred at %s\n", TEST_LOCATION );
1234 tet_result(TET_FAIL);
1236 catch( Dali::DaliException& e )
1238 DALI_TEST_PRINT_ASSERT( e );
1239 DALI_TEST_ASSERT( e, "( last <= End() ) && ( last >= Begin() )", TEST_LOCATION );
1243 tet_printf("Assertion test failed - wrong Exception\n" );
1244 tet_result(TET_FAIL);
1247 vector.PushBack( 3 );
1252 vector.Erase( vector.Begin() + 2u, vector.Begin() + 1u );
1253 tet_printf( "Assertion expected, but not occurred at %s\n", TEST_LOCATION );
1254 tet_result(TET_FAIL);
1256 catch( Dali::DaliException& e )
1258 DALI_TEST_PRINT_ASSERT( e );
1259 DALI_TEST_ASSERT( e, "( first <= last )", TEST_LOCATION );
1263 tet_printf("Assertion test failed - wrong Exception\n" );
1264 tet_result(TET_FAIL);
1270 int UtcDaliVectorVector2P(void)
1272 tet_infoline("Testing Dali::Vector< Vector2 >");
1274 Vector< Vector2 > classvector;
1275 DALI_TEST_EQUALS( ZERO, classvector.Count(), TEST_LOCATION );
1276 DALI_TEST_EQUALS( ZERO, classvector.Capacity(), TEST_LOCATION );
1278 classvector.PushBack( Vector2() );
1280 DALI_TEST_EQUALS( 1u, classvector.Count(), TEST_LOCATION );
1281 DALI_TEST_GREATER( classvector.Capacity(), ZERO, TEST_LOCATION );
1283 classvector.PushBack( Vector2( 0.1f, 0.2f ) );
1285 DALI_TEST_EQUALS( 2u, classvector.Count(), TEST_LOCATION );
1287 DALI_TEST_EQUALS( Vector2(), classvector[ 0 ], TEST_LOCATION );
1288 DALI_TEST_EQUALS( Vector2( 0.1f, 0.2f ), classvector[ 1 ], TEST_LOCATION );
1290 tet_result(TET_PASS); // for now
1294 int UtcDaliVectorVector3P(void)
1296 tet_infoline("Testing Dali::Vector< Vector3 >");
1298 Vector< Vector3 > classvector;
1299 DALI_TEST_EQUALS( ZERO, classvector.Count(), TEST_LOCATION );
1300 DALI_TEST_EQUALS( ZERO, classvector.Capacity(), TEST_LOCATION );
1302 classvector.PushBack( Vector3() );
1304 DALI_TEST_EQUALS( 1u, classvector.Count(), TEST_LOCATION );
1305 DALI_TEST_GREATER( classvector.Capacity(), ZERO, TEST_LOCATION );
1307 classvector.PushBack( Vector3( 0.1f, 0.2f, 0.3f ) );
1309 DALI_TEST_EQUALS( 2u, classvector.Count(), TEST_LOCATION );
1311 DALI_TEST_EQUALS( Vector3(), classvector[ 0 ], TEST_LOCATION );
1312 DALI_TEST_EQUALS( Vector3( 0.1f, 0.2f, 0.3f ), classvector[ 1 ], TEST_LOCATION );
1314 tet_result(TET_PASS); // for now
1318 int UtcDaliVectorMatrixP(void)
1320 tet_infoline("Testing Dali::Vector< Matrix >");
1322 Vector< Matrix > classvector;
1323 DALI_TEST_EQUALS( ZERO, classvector.Count(), TEST_LOCATION );
1324 DALI_TEST_EQUALS( ZERO, classvector.Capacity(), TEST_LOCATION );
1326 classvector.PushBack( Matrix() );
1328 DALI_TEST_EQUALS( 1u, classvector.Count(), TEST_LOCATION );
1329 DALI_TEST_GREATER( classvector.Capacity(), ZERO, TEST_LOCATION );
1331 classvector.PushBack( Matrix::IDENTITY );
1333 DALI_TEST_EQUALS( 2u, classvector.Count(), TEST_LOCATION );
1335 DALI_TEST_EQUALS( Matrix(), classvector[ 0 ], TEST_LOCATION );
1336 DALI_TEST_EQUALS( Matrix::IDENTITY, classvector[ 1 ], TEST_LOCATION );
1338 tet_result(TET_PASS); // for now
1342 int UtcDaliVectorCpp11ForP(void)
1344 Vector< Vector3 > classvector;
1345 for ( auto i : classvector )
1348 tet_result( TET_FAIL );
1351 classvector.PushBack( Vector3( 0.1f, 0.2f, 0.3f ) );
1352 classvector.PushBack( Vector3( 0.1f, 0.2f, 0.3f ) );
1353 classvector.PushBack( Vector3( 0.1f, 0.2f, 0.3f ) );
1355 for ( auto i : classvector )
1357 DALI_TEST_EQUALS( Vector3( 0.1f, 0.2f, 0.3f ), i, TEST_LOCATION );
1365 * this does not compile at the moment
1366 * Vector< Actor > classvector; this does not compile yet either
1371 bool gConstructorCalled = false;
1372 bool gDestructorCalled = false;
1378 gConstructorCalled = true;
1382 gDestructorCalled = true;
1386 } // anonymous namespace
1388 int UtcDaliVectorComplex( void)
1390 tet_infoline("Testing Dali::Vector< ComplexType > ");
1392 Vector< ComplexType > classvector;
1393 DALI_TEST_EQUALS( ZERO, classvector.Count(), TEST_LOCATION );
1394 DALI_TEST_EQUALS( ZERO, classvector.Capacity(), TEST_LOCATION );
1396 DALI_TEST_EQUALS( false, gConstructorCalled, TEST_LOCATION );
1397 DALI_TEST_EQUALS( false, gDestructorCalled, TEST_LOCATION );
1398 classvector.PushBack( ComplexType() );
1399 DALI_TEST_EQUALS( true, gConstructorCalled, TEST_LOCATION );
1400 classvector.Clear();
1401 DALI_TEST_EQUALS( true, gDestructorCalled, TEST_LOCATION );
1402 tet_result(TET_PASS); // for now