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>
28 const Dali::VectorBase::SizeType ZERO(0);
33 int UtcDaliEmptyVectorInt(void)
35 tet_infoline("Testing Dali::Vector<int>");
37 Vector< int > intvector;
39 DALI_TEST_EQUALS( ZERO, intvector.Count(), TEST_LOCATION );
40 DALI_TEST_EQUALS( ZERO, intvector.Capacity(), TEST_LOCATION );
43 DALI_TEST_EQUALS( ZERO, intvector.Count(), TEST_LOCATION );
44 DALI_TEST_EQUALS( ZERO, intvector.Capacity(), TEST_LOCATION );
47 DALI_TEST_EQUALS( ZERO, intvector.Count(), TEST_LOCATION );
48 DALI_TEST_EQUALS( ZERO, intvector.Capacity(), TEST_LOCATION );
52 int UtcDaliVectorInt(void)
54 tet_infoline("Testing Dali::Vector<int>");
56 Vector< int > intvector;
58 DALI_TEST_EQUALS( ZERO, intvector.Count(), TEST_LOCATION );
59 DALI_TEST_EQUALS( ZERO, intvector.Capacity(), TEST_LOCATION );
61 intvector.PushBack( 11 );
62 DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(1), intvector.Count(), TEST_LOCATION );
63 DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(2), intvector.Capacity(), TEST_LOCATION );
64 DALI_TEST_EQUALS( 11, intvector[ 0 ], TEST_LOCATION );
66 intvector.PushBack( 99 );
67 DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(2), intvector.Count(), TEST_LOCATION );
68 DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(2), intvector.Capacity(), TEST_LOCATION );
69 DALI_TEST_EQUALS( 99, intvector[ 1 ], TEST_LOCATION );
71 intvector.PushBack( 34 );
72 DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(3), intvector.Count(), TEST_LOCATION );
73 DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(6), intvector.Capacity(), TEST_LOCATION );
74 DALI_TEST_EQUALS( 11, intvector[ 0 ], TEST_LOCATION );
75 DALI_TEST_EQUALS( 99, intvector[ 1 ], TEST_LOCATION );
76 DALI_TEST_EQUALS( 34, intvector[ 2 ], TEST_LOCATION );
79 DALI_TEST_EQUALS( ZERO, intvector.Count(), TEST_LOCATION );
80 DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(6), intvector.Capacity(), TEST_LOCATION );
81 intvector.PushBack( 123 );
82 DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(1), intvector.Count(), TEST_LOCATION );
83 DALI_TEST_EQUALS( 123, intvector[ 0 ], TEST_LOCATION );
87 int UtcDaliVectorIntCopy(void)
89 tet_infoline("Testing Dali::Vector<int>::Copy");
91 Vector< int > intvector;
92 DALI_TEST_EQUALS( ZERO, intvector.Count(), TEST_LOCATION );
93 DALI_TEST_EQUALS( ZERO, intvector.Capacity(), TEST_LOCATION );
95 intvector.PushBack( 99 );
96 intvector.PushBack( 11 );
97 intvector.PushBack( 34 );
100 Vector< int > intvector2( intvector );
102 DALI_TEST_EQUALS( intvector2.Count(), intvector.Count(), TEST_LOCATION );
103 DALI_TEST_EQUALS( intvector2.Capacity(), intvector.Capacity(), TEST_LOCATION );
104 DALI_TEST_EQUALS( intvector2[ 0 ], intvector[ 0 ], TEST_LOCATION );
105 DALI_TEST_EQUALS( intvector2[ 1 ], intvector[ 1 ], TEST_LOCATION );
106 DALI_TEST_EQUALS( intvector2[ 2 ], intvector[ 2 ], TEST_LOCATION );
109 Vector< int > intvector3;
110 DALI_TEST_EQUALS( ZERO, intvector3.Count(), TEST_LOCATION );
111 DALI_TEST_EQUALS( ZERO, intvector3.Capacity(), TEST_LOCATION );
112 intvector2 = intvector3;
113 DALI_TEST_EQUALS( intvector2.Count(), intvector3.Count(), TEST_LOCATION );
114 DALI_TEST_EQUALS( intvector2.Capacity(), intvector3.Capacity(), TEST_LOCATION );
117 Vector< int > intvector4;
118 intvector4.Reserve( 100 );
119 DALI_TEST_EQUALS( ZERO, intvector4.Count(), TEST_LOCATION );
120 DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(100), intvector4.Capacity(), TEST_LOCATION );
121 intvector3 = intvector4;
122 DALI_TEST_EQUALS( ZERO, intvector3.Count(), TEST_LOCATION );
123 DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(100), intvector3.Capacity(), TEST_LOCATION );
126 intvector4 = intvector4;
127 DALI_TEST_EQUALS( ZERO, intvector4.Count(), TEST_LOCATION );
128 DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(100), intvector4.Capacity(), TEST_LOCATION );
132 int UtcDaliVectorIntResize(void)
134 tet_infoline("Testing Dali::Vector<short>::Resize");
136 Vector< short > vector;
137 DALI_TEST_EQUALS( ZERO, vector.Count(), TEST_LOCATION );
138 DALI_TEST_EQUALS( ZERO, vector.Capacity(), TEST_LOCATION );
140 vector.Resize( 10u );
141 DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(10), vector.Count(), TEST_LOCATION );
142 DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(10), vector.Capacity(), TEST_LOCATION );
145 DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(4), vector.Count(), TEST_LOCATION );
146 DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(10), vector.Capacity(), TEST_LOCATION );
149 DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(4), vector.Count(), TEST_LOCATION );
150 DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(10), vector.Capacity(), TEST_LOCATION );
153 DALI_TEST_EQUALS( ZERO, vector.Count(), TEST_LOCATION );
154 DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(10), vector.Capacity(), TEST_LOCATION );
156 vector.Resize( 12u, 123 );
157 DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(12), vector.Count(), TEST_LOCATION );
158 DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(12), vector.Capacity(), TEST_LOCATION );
160 DALI_TEST_EQUALS( vector[ 0 ], 123, TEST_LOCATION );
161 DALI_TEST_EQUALS( vector[ 1 ], 123, TEST_LOCATION );
162 DALI_TEST_EQUALS( vector[ 2 ], 123, TEST_LOCATION );
163 DALI_TEST_EQUALS( vector[ 3 ], 123, TEST_LOCATION );
164 DALI_TEST_EQUALS( vector[ 4 ], 123, TEST_LOCATION );
165 DALI_TEST_EQUALS( vector[ 5 ], 123, TEST_LOCATION );
166 DALI_TEST_EQUALS( vector[ 6 ], 123, TEST_LOCATION );
167 DALI_TEST_EQUALS( vector[ 7 ], 123, TEST_LOCATION );
168 DALI_TEST_EQUALS( vector[ 8 ], 123, TEST_LOCATION );
169 DALI_TEST_EQUALS( vector[ 9 ], 123, TEST_LOCATION );
170 DALI_TEST_EQUALS( vector[ 10 ], 123, TEST_LOCATION );
171 DALI_TEST_EQUALS( vector[ 11 ], 123, TEST_LOCATION );
173 vector.Resize( 13u, 321 );
174 DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(13), vector.Count(), TEST_LOCATION );
175 DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(13), vector.Capacity(), TEST_LOCATION );
177 DALI_TEST_EQUALS( vector[ 0 ], 123, TEST_LOCATION );
178 DALI_TEST_EQUALS( vector[ 1 ], 123, TEST_LOCATION );
179 DALI_TEST_EQUALS( vector[ 2 ], 123, TEST_LOCATION );
180 DALI_TEST_EQUALS( vector[ 3 ], 123, TEST_LOCATION );
181 DALI_TEST_EQUALS( vector[ 4 ], 123, TEST_LOCATION );
182 DALI_TEST_EQUALS( vector[ 5 ], 123, TEST_LOCATION );
183 DALI_TEST_EQUALS( vector[ 6 ], 123, TEST_LOCATION );
184 DALI_TEST_EQUALS( vector[ 7 ], 123, TEST_LOCATION );
185 DALI_TEST_EQUALS( vector[ 8 ], 123, TEST_LOCATION );
186 DALI_TEST_EQUALS( vector[ 9 ], 123, TEST_LOCATION );
187 DALI_TEST_EQUALS( vector[ 10 ], 123, TEST_LOCATION );
188 DALI_TEST_EQUALS( vector[ 11 ], 123, TEST_LOCATION );
189 DALI_TEST_EQUALS( vector[ 12 ], 321, TEST_LOCATION );
193 int UtcDaliVectorIntErase(void)
195 tet_infoline("Testing Dali::Vector<short>::Erase");
197 Vector< char > vector;
198 DALI_TEST_EQUALS( ZERO, vector.Count(), TEST_LOCATION );
199 DALI_TEST_EQUALS( ZERO, vector.Capacity(), TEST_LOCATION );
200 vector.PushBack( 1 );
201 vector.PushBack( 2 );
202 vector.PushBack( 3 );
203 vector.PushBack( 4 );
204 vector.PushBack( 5 );
205 DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(5), vector.Count(), TEST_LOCATION );
206 DALI_TEST_EQUALS( vector[ 0 ], 1, TEST_LOCATION );
207 DALI_TEST_EQUALS( vector[ 1 ], 2, TEST_LOCATION );
208 DALI_TEST_EQUALS( vector[ 2 ], 3, TEST_LOCATION );
209 DALI_TEST_EQUALS( vector[ 3 ], 4, TEST_LOCATION );
210 DALI_TEST_EQUALS( vector[ 4 ], 5, TEST_LOCATION );
212 vector.Erase( vector.Begin() );
213 DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(4), vector.Count(), TEST_LOCATION );
214 DALI_TEST_EQUALS( vector[ 0 ], 2, TEST_LOCATION );
215 DALI_TEST_EQUALS( vector[ 1 ], 3, TEST_LOCATION );
216 DALI_TEST_EQUALS( vector[ 2 ], 4, TEST_LOCATION );
217 DALI_TEST_EQUALS( vector[ 3 ], 5, TEST_LOCATION );
219 Vector< char >::Iterator ret = vector.Erase( std::find( vector.Begin(), vector.End(), 4 ) );
220 DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(3), vector.Count(), TEST_LOCATION );
221 DALI_TEST_EQUALS( vector[ 0 ], 2, TEST_LOCATION );
222 DALI_TEST_EQUALS( vector[ 1 ], 3, TEST_LOCATION );
223 DALI_TEST_EQUALS( vector[ 2 ], 5, TEST_LOCATION );
224 DALI_TEST_EQUALS( *ret, 5, TEST_LOCATION );
227 vector.PushBack( 99 );
228 DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(4), vector.Count(), TEST_LOCATION );
229 DALI_TEST_EQUALS( vector[ 3 ], 99, TEST_LOCATION );
230 ret = vector.Erase( vector.End() - 1 );
231 DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(3), vector.Count(), TEST_LOCATION );
232 DALI_TEST_EQUALS( ret, vector.End(), TEST_LOCATION );
236 // illegal erase, one past the end
237 vector.Erase( vector.End() );
238 tet_result(TET_FAIL);
240 catch( Dali::DaliException& e )
242 tet_printf("Assertion %s test at %s\n", e.mCondition.c_str(), e.mLocation.c_str());
243 DALI_TEST_ASSERT( e, "(iterator < End())", TEST_LOCATION );
247 tet_printf("Assertion test failed - wrong Exception\n" );
248 tet_result(TET_FAIL);
250 DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(3), vector.Count(), TEST_LOCATION );
251 DALI_TEST_EQUALS( vector[ 0 ], 2, TEST_LOCATION );
252 DALI_TEST_EQUALS( vector[ 1 ], 3, TEST_LOCATION );
253 DALI_TEST_EQUALS( vector[ 2 ], 5, TEST_LOCATION );
255 vector.Erase( vector.Begin() + 1 );
256 DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(2), vector.Count(), TEST_LOCATION );
257 DALI_TEST_EQUALS( vector[ 0 ], 2, TEST_LOCATION );
258 DALI_TEST_EQUALS( vector[ 1 ], 5, TEST_LOCATION );
260 vector.Erase( vector.Begin() + 1 );
261 DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(1), vector.Count(), TEST_LOCATION );
262 DALI_TEST_EQUALS( vector[ 0 ], 2, TEST_LOCATION );
266 // illegal erase, one past the end
267 vector.Erase( vector.Begin() + 1 );
268 tet_result(TET_FAIL);
270 catch( Dali::DaliException& e )
272 tet_printf("Assertion %s test at %s\n", e.mCondition.c_str(), e.mLocation.c_str());
273 DALI_TEST_ASSERT( e, "(iterator < End())", TEST_LOCATION );
277 tet_printf("Assertion test failed - wrong Exception\n" );
278 tet_result(TET_FAIL);
280 DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(1), vector.Count(), TEST_LOCATION );
281 DALI_TEST_EQUALS( vector[ 0 ], 2, TEST_LOCATION );
283 vector.Erase( vector.Begin() );
284 DALI_TEST_EQUALS( ZERO, vector.Count(), TEST_LOCATION );
288 // illegal erase, one before the beginning
289 vector.Erase( vector.Begin() - 1 );
290 tet_result(TET_FAIL);
292 catch( Dali::DaliException& e )
294 tet_printf("Assertion %s test at %s\n", e.mCondition.c_str(), e.mLocation.c_str());
295 DALI_TEST_ASSERT( e, "(iterator < End())", TEST_LOCATION );
299 tet_printf("Assertion test failed - wrong Exception\n" );
300 tet_result(TET_FAIL);
303 DALI_TEST_EQUALS( ZERO, vector.Count(), TEST_LOCATION );
304 DALI_TEST_EQUALS( vector.Begin(), vector.End(), TEST_LOCATION );
306 Vector< char >::Iterator endIter = vector.End();
307 for( Vector< char >::Iterator iter = vector.Begin(); iter != endIter; ++iter )
309 tet_result(TET_FAIL);
312 vector.PushBack( 3 );
313 DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(1), vector.Count(), TEST_LOCATION );
316 DALI_TEST_EQUALS( ZERO, vector.Count(), TEST_LOCATION );
317 DALI_TEST_EQUALS( vector.Begin(), vector.End(), TEST_LOCATION );
319 endIter = vector.End();
320 for( Vector< char >::Iterator iter = vector.Begin(); iter != endIter; ++iter )
322 tet_result(TET_FAIL);
325 // test a vector of pointers
326 Vector< int* > ptrVector;
327 DALI_TEST_EQUALS( ZERO, ptrVector.Count(), TEST_LOCATION );
328 DALI_TEST_EQUALS( ptrVector.Begin(), ptrVector.End(), TEST_LOCATION );
331 ptrVector.PushBack( pointer );
332 DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(1), ptrVector.Count(), TEST_LOCATION );
334 Vector< int* >::Iterator ptriter = std::find( ptrVector.Begin(), ptrVector.End(), pointer );
335 ptriter = ptrVector.Erase( ptriter );
336 DALI_TEST_EQUALS( ZERO, ptrVector.Count(), TEST_LOCATION );
337 DALI_TEST_EQUALS( ptrVector.Begin(), ptrVector.End(), TEST_LOCATION );
338 DALI_TEST_EQUALS( ptrVector.Begin(), ptriter, TEST_LOCATION );
343 int UtcDaliVectorDoubleRemove(void)
345 tet_infoline("Testing Dali::Vector<double>::Remove");
347 Vector< double > vector;
348 DALI_TEST_EQUALS( ZERO, vector.Count(), TEST_LOCATION );
350 vector.PushBack( 11.1 );
351 vector.PushBack( 22.2 );
352 vector.PushBack( 33.3 );
353 vector.PushBack( 44.4 );
354 DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(4), vector.Count(), TEST_LOCATION );
355 DALI_TEST_EQUALS( vector[ 0 ], 11.1, TEST_LOCATION );
356 DALI_TEST_EQUALS( vector[ 1 ], 22.2, TEST_LOCATION );
357 DALI_TEST_EQUALS( vector[ 2 ], 33.3, TEST_LOCATION );
358 DALI_TEST_EQUALS( vector[ 3 ], 44.4, TEST_LOCATION );
360 Vector< double >::Iterator res = std::find( vector.Begin(), vector.End(), 22.2 );
361 DALI_TEST_EQUALS( 22.2, *res, TEST_LOCATION );
362 vector.Remove( res );
363 res = std::find( vector.Begin(), vector.End(), 22.2 );
364 DALI_TEST_EQUALS( vector.End(), res, TEST_LOCATION );
365 DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(3), vector.Count(), TEST_LOCATION );
366 DALI_TEST_EQUALS( vector[ 0 ], 11.1, TEST_LOCATION );
367 DALI_TEST_EQUALS( vector[ 1 ], 44.4, TEST_LOCATION );
368 DALI_TEST_EQUALS( vector[ 2 ], 33.3, TEST_LOCATION );
370 vector.Remove( vector.End() - 1 );
371 DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(2), vector.Count(), TEST_LOCATION );
372 DALI_TEST_EQUALS( vector[ 0 ], 11.1, TEST_LOCATION );
373 DALI_TEST_EQUALS( vector[ 1 ], 44.4, TEST_LOCATION );
375 vector.Remove( vector.Begin() );
376 DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(1), vector.Count(), TEST_LOCATION );
377 DALI_TEST_EQUALS( vector[ 0 ], 44.4, TEST_LOCATION );
381 // illegal erase, one past the end
382 vector.Remove( vector.Begin() + 1 );
383 tet_result(TET_FAIL);
385 catch( Dali::DaliException& e )
387 tet_printf("Assertion %s test at %s\n", e.mCondition.c_str(), e.mLocation.c_str());
388 DALI_TEST_ASSERT( e, "(iterator < end)", TEST_LOCATION );
392 tet_printf("Assertion test failed - wrong Exception\n" );
393 tet_result(TET_FAIL);
395 DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(1), vector.Count(), TEST_LOCATION );
396 DALI_TEST_EQUALS( vector[ 0 ], 44.4, TEST_LOCATION );
398 vector.Remove( vector.Begin() );
399 DALI_TEST_EQUALS( ZERO, vector.Count(), TEST_LOCATION );
403 // illegal erase, one before the beginning
404 vector.Remove( vector.Begin() - 1 );
405 tet_result(TET_FAIL);
407 catch( Dali::DaliException& e )
409 tet_printf("Assertion %s test at %s\n", e.mCondition.c_str(), e.mLocation.c_str());
410 DALI_TEST_ASSERT( e, "(iterator < end) && (iterator >= Begin()", TEST_LOCATION );
414 tet_printf("Assertion test failed - wrong Exception\n" );
415 tet_result(TET_FAIL);
421 int UtcDaliVectorIntSwap(void)
423 tet_infoline("Testing Dali::Vector<int>::Swap");
425 Vector< int > intvector;
426 DALI_TEST_EQUALS( ZERO, intvector.Count(), TEST_LOCATION );
427 DALI_TEST_EQUALS( ZERO, intvector.Capacity(), TEST_LOCATION );
429 intvector.PushBack( 11 );
430 intvector.PushBack( 22 );
431 intvector.PushBack( 33 );
432 DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(3), intvector.Count(), TEST_LOCATION );
434 Vector< int > intvector2;
435 DALI_TEST_EQUALS( ZERO, intvector2.Count(), TEST_LOCATION );
436 DALI_TEST_EQUALS( ZERO, intvector2.Capacity(), TEST_LOCATION );
438 intvector2.Swap( intvector );
439 DALI_TEST_EQUALS( ZERO, intvector.Count(), TEST_LOCATION );
440 DALI_TEST_EQUALS( ZERO, intvector.Capacity(), TEST_LOCATION );
441 DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(3), intvector2.Count(), TEST_LOCATION );
442 DALI_TEST_EQUALS( 11, intvector2[ 0 ], TEST_LOCATION );
443 DALI_TEST_EQUALS( 22, intvector2[ 1 ], TEST_LOCATION );
444 DALI_TEST_EQUALS( 33, intvector2[ 2 ], TEST_LOCATION );
446 intvector.PushBack( 99 );
447 intvector.PushBack( 88 );
448 DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(2), intvector.Count(), TEST_LOCATION );
450 intvector.Swap( intvector2 );
451 DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(2), intvector2.Count(), TEST_LOCATION );
452 DALI_TEST_EQUALS( 99, intvector2[ 0 ], TEST_LOCATION );
453 DALI_TEST_EQUALS( 88, intvector2[ 1 ], TEST_LOCATION );
454 DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(3), intvector.Count(), TEST_LOCATION );
455 DALI_TEST_EQUALS( 11, intvector[ 0 ], TEST_LOCATION );
456 DALI_TEST_EQUALS( 22, intvector[ 1 ], TEST_LOCATION );
457 DALI_TEST_EQUALS( 33, intvector[ 2 ], TEST_LOCATION );
460 intvector.Swap( empty );
461 DALI_TEST_EQUALS( ZERO, intvector.Count(), TEST_LOCATION );
462 DALI_TEST_EQUALS( ZERO, intvector.Capacity(), TEST_LOCATION );
466 int UtcDaliVectorIterate(void)
468 tet_infoline("Testing Dali::Vector<float>::Begin");
470 Vector< float > floatvector;
471 DALI_TEST_EQUALS( ZERO, floatvector.Count(), TEST_LOCATION );
472 DALI_TEST_EQUALS( ZERO, floatvector.Capacity(), TEST_LOCATION );
474 floatvector.PushBack( 0.9f );
475 floatvector.PushBack( 1.1f );
476 floatvector.PushBack( 1.2f );
477 DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(3), floatvector.Count(), TEST_LOCATION );
479 Vector< float >::Iterator iter = floatvector.Begin();
481 for( ; iter != floatvector.End(); ++iter, ++index )
483 std::cout << "value " << *iter << std::endl;
484 DALI_TEST_EQUALS( *iter, floatvector[ index ], TEST_LOCATION );
486 DALI_TEST_EQUALS( 3, index, TEST_LOCATION );
488 iter = std::find( floatvector.Begin(), floatvector.End(), 1.1f );
489 DALI_TEST_EQUALS( 1.1f, *iter, TEST_LOCATION );
492 iter = std::find( floatvector.Begin(), floatvector.End(), 1.1f );
493 DALI_TEST_EQUALS( floatvector.End(), iter, TEST_LOCATION );
497 int UtcDaliVectorPair(void)
499 tet_infoline("Testing Dali::Vector< std::pair< int, float > >");
501 Vector< std::pair< int, float > > pairvector;
502 DALI_TEST_EQUALS( ZERO, pairvector.Count(), TEST_LOCATION );
503 DALI_TEST_EQUALS( ZERO, pairvector.Capacity(), TEST_LOCATION );
505 pairvector.PushBack( std::make_pair( 5, 0.1f ) );
506 pairvector.PushBack( std::make_pair( 3, 0.2f ) );
507 pairvector.PushBack( std::make_pair( 4, 0.3f ) );
508 pairvector.PushBack( std::make_pair( 1, 0.4f ) );
509 pairvector.PushBack( std::make_pair( 2, 0.5f ) );
510 DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(5), pairvector.Count(), TEST_LOCATION );
512 Vector< std::pair< int, float > >::Iterator iter = pairvector.Begin();
514 for( ; iter != pairvector.End(); ++iter, ++index )
516 std::cout << "pair " << (*iter).first << ":" << (*iter).second << std::endl;
517 DALI_TEST_EQUALS( (*iter).first, pairvector[ index ].first, TEST_LOCATION );
518 DALI_TEST_EQUALS( (*iter).second, pairvector[ index ].second, TEST_LOCATION );
523 int UtcDaliVectorAsserts(void)
525 tet_infoline("Testing Dali::Vector< int* > exception handling");
528 Vector< int* > pointervector;
532 pointervector[ 1 ] = value;
533 tet_printf("Assertion expected, but not occurred at %s\n", TEST_LOCATION );
534 tet_result(TET_FAIL);
536 catch(Dali::DaliException& e)
538 tet_printf("Assertion %s test at %s\n", e.mCondition.c_str(), e.mLocation.c_str());
539 DALI_TEST_ASSERT( e, "VectorBase::mData", TEST_LOCATION );
543 tet_printf("Assertion test failed - wrong Exception\n" );
544 tet_result(TET_FAIL);
550 value = pointervector[ 0 ];
551 (void)value; // to "use" the value
552 tet_printf("Assertion expected, but not occurred at %s\n", TEST_LOCATION );
553 tet_result(TET_FAIL);
555 catch(Dali::DaliException& e)
557 tet_printf("Assertion %s test at %s\n", e.mCondition.c_str(), e.mLocation.c_str());
558 DALI_TEST_ASSERT( e, "VectorBase::mData", TEST_LOCATION );
562 tet_printf("Assertion test failed - wrong Exception\n" );
563 tet_result(TET_FAIL);
566 Vector< int* >::Iterator iter = pointervector.Begin();
567 if( iter != pointervector.End() )
569 tet_result(TET_FAIL);
574 pointervector.Erase( pointervector.Begin() );
575 tet_printf("Assertion expected, but not occurred at %s\n", TEST_LOCATION );
576 tet_result(TET_FAIL);
578 catch(Dali::DaliException& e)
580 tet_printf("Assertion %s test at %s\n", e.mCondition.c_str(), e.mLocation.c_str());
581 DALI_TEST_ASSERT( e, "VectorBase::mData", TEST_LOCATION );
585 tet_printf("Assertion test failed - wrong Exception\n" );
586 tet_result(TET_FAIL);
589 iter = pointervector.Begin();
590 if( iter != pointervector.End() )
592 tet_result(TET_FAIL);
597 pointervector.Remove( pointervector.Begin() );
598 tet_printf("Assertion expected, but not occurred at %s\n", TEST_LOCATION );
599 tet_result(TET_FAIL);
601 catch(Dali::DaliException& e)
603 tet_printf("Assertion %s test at %s\n", e.mCondition.c_str(), e.mLocation.c_str());
604 DALI_TEST_ASSERT( e, "VectorBase::mData", TEST_LOCATION );
608 tet_printf("Assertion test failed - wrong Exception\n" );
609 tet_result(TET_FAIL);
612 iter = pointervector.Begin();
613 if( iter != pointervector.End() )
615 tet_result(TET_FAIL);
619 pointervector.Reserve( 0 );
620 iter = pointervector.Begin();
621 if( iter != pointervector.End() )
623 tet_result(TET_FAIL);
627 pointervector.Reserve( 1 );
628 iter = pointervector.Begin();
629 if( iter != pointervector.End() )
631 tet_result(TET_FAIL);
637 pointervector[ 1 ] = value;
638 tet_printf("Assertion expected, but not occurred at %s\n", TEST_LOCATION );
639 tet_result(TET_FAIL);
641 catch(Dali::DaliException& e)
643 tet_printf("Assertion %s test at %s\n", e.mCondition.c_str(), e.mLocation.c_str());
644 DALI_TEST_ASSERT( e, "index < VectorBase::Count()", TEST_LOCATION );
648 tet_printf("Assertion test failed - wrong Exception\n" );
649 tet_result(TET_FAIL);
654 int* value = pointervector[ 1 ];
655 (void)value; // to "use" the 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 tet_printf("Assertion %s test at %s\n", e.mCondition.c_str(), e.mLocation.c_str());
662 DALI_TEST_ASSERT( e, "index < VectorBase::Count()", TEST_LOCATION );
666 tet_printf("Assertion test failed - wrong Exception\n" );
667 tet_result(TET_FAIL);
673 int UtcDaliVectorAcidTest(void)
675 tet_infoline("Testing multiple Dali::Vector's");
677 // create multiple vectors
678 Vector< std::pair< float, float > > pairvector;
679 DALI_TEST_EQUALS( ZERO, pairvector.Count(), TEST_LOCATION );
680 DALI_TEST_EQUALS( ZERO, pairvector.Capacity(), TEST_LOCATION );
681 Vector< double > doublevector;
682 DALI_TEST_EQUALS( ZERO, doublevector.Count(), TEST_LOCATION );
683 DALI_TEST_EQUALS( ZERO, doublevector.Capacity(), TEST_LOCATION );
684 Vector< int* > intptrvector;
685 DALI_TEST_EQUALS( ZERO, intptrvector.Count(), TEST_LOCATION );
686 DALI_TEST_EQUALS( ZERO, intptrvector.Capacity(), TEST_LOCATION );
687 Vector< Dali::Actor* > actorptrvector;
688 DALI_TEST_EQUALS( ZERO, actorptrvector.Count(), TEST_LOCATION );
689 DALI_TEST_EQUALS( ZERO, actorptrvector.Capacity(), TEST_LOCATION );
690 Vector< long > longvector;
691 DALI_TEST_EQUALS( ZERO, longvector.Count(), TEST_LOCATION );
692 DALI_TEST_EQUALS( ZERO, longvector.Capacity(), TEST_LOCATION );
693 Vector< char > charvector;
694 DALI_TEST_EQUALS( ZERO, charvector.Count(), TEST_LOCATION );
695 DALI_TEST_EQUALS( ZERO, charvector.Capacity(), TEST_LOCATION );
698 static unsigned int acidCount = 10000;
700 for( unsigned int i = 0; i < acidCount; ++i )
703 pairvector.PushBack( std::make_pair( i, i ) );
704 doublevector.PushBack( (double)i );
705 intptrvector.PushBack( (int*)ptr );
706 actorptrvector.PushBack( (Dali::Actor*)ptr );
707 longvector.PushBack( (long)i );
708 charvector.PushBack( (char)i );
710 DALI_TEST_EQUALS( acidCount, pairvector.Count(), TEST_LOCATION );
711 std::size_t pairCapacity = pairvector.Capacity();
712 DALI_TEST_EQUALS( acidCount, doublevector.Count(), TEST_LOCATION );
713 std::size_t doubleCapacity = doublevector.Capacity();
714 DALI_TEST_EQUALS( acidCount, intptrvector.Count(), TEST_LOCATION );
715 std::size_t intptrCapacity = intptrvector.Capacity();
716 DALI_TEST_EQUALS( acidCount, actorptrvector.Count(), TEST_LOCATION );
717 std::size_t actorptrCapacity = actorptrvector.Capacity();
718 DALI_TEST_EQUALS( acidCount, longvector.Count(), TEST_LOCATION );
719 std::size_t longCapacity = longvector.Capacity();
720 DALI_TEST_EQUALS( acidCount, charvector.Count(), TEST_LOCATION );
721 std::size_t charCapacity = charvector.Capacity();
723 tet_printf("Dali::Vector< pair > capacity after %d pushbacks is %d", acidCount, pairCapacity );
724 tet_printf("Dali::Vector< double > capacity after %d pushbacks is %d", acidCount, doubleCapacity );
725 tet_printf("Dali::Vector< int* > capacity after %d pushbacks is %d", acidCount, intptrCapacity );
726 tet_printf("Dali::Vector< Actor* > capacity after %d pushbacks is %d", acidCount, actorptrCapacity );
727 tet_printf("Dali::Vector< long > capacity after %d pushbacks is %d", acidCount, longCapacity );
728 tet_printf("Dali::Vector< char > capacity after %d pushbacks is %d", acidCount, charCapacity );
731 for( unsigned int i = 0; i < acidCount; ++i )
733 pairvector.Erase( pairvector.Begin() + ( i % pairvector.Count() ) );
734 doublevector.Erase( doublevector.Begin() + ( i % doublevector.Count() ) );
735 intptrvector.Erase( intptrvector.Begin() + ( i % intptrvector.Count() ) );
736 actorptrvector.Erase( actorptrvector.Begin() + ( i % actorptrvector.Count() ) );
737 longvector.Erase( longvector.Begin() + ( i % longvector.Count() ) );
738 charvector.Erase( charvector.Begin() + ( i % charvector.Count() ) );
740 DALI_TEST_EQUALS( ZERO, pairvector.Count(), TEST_LOCATION );
741 DALI_TEST_EQUALS( pairCapacity, pairvector.Capacity(), TEST_LOCATION );
742 DALI_TEST_EQUALS( ZERO, doublevector.Count(), TEST_LOCATION );
743 DALI_TEST_EQUALS( doubleCapacity, doublevector.Capacity(), TEST_LOCATION );
744 DALI_TEST_EQUALS( ZERO, intptrvector.Count(), TEST_LOCATION );
745 DALI_TEST_EQUALS( intptrCapacity, intptrvector.Capacity(), TEST_LOCATION );
746 DALI_TEST_EQUALS( ZERO, actorptrvector.Count(), TEST_LOCATION );
747 DALI_TEST_EQUALS( actorptrCapacity, actorptrvector.Capacity(), TEST_LOCATION );
748 DALI_TEST_EQUALS( ZERO, longvector.Count(), TEST_LOCATION );
749 DALI_TEST_EQUALS( longCapacity, longvector.Capacity(), TEST_LOCATION );
750 DALI_TEST_EQUALS( ZERO, charvector.Count(), TEST_LOCATION );
751 DALI_TEST_EQUALS( charCapacity, charvector.Capacity(), TEST_LOCATION );
759 bool gConstructorCalled = false;
760 bool gDestructorCalled = false;
766 gConstructorCalled = true;
770 gDestructorCalled = true;
774 } // anonymous namespace
777 int UtcDaliVectorComplex(void)
779 tet_infoline("Testing Dali::Vector< int* > exception handling");
781 // this does not compile at the moment
782 /* Vector< ComplexType > classvector;
783 DALI_TEST_EQUALS( ZERO, classvector.Count(), TEST_LOCATION );
784 DALI_TEST_EQUALS( ZERO, classvector.Capacity(), TEST_LOCATION );
786 DALI_TEST_EQUALS( false, gConstructorCalled, TEST_LOCATION );
787 DALI_TEST_EQUALS( false, gDestructorCalled, TEST_LOCATION );
788 classvector.PushBack( ComplexType() );
789 DALI_TEST_EQUALS( true, gConstructorCalled, TEST_LOCATION );
791 DALI_TEST_EQUALS( true, gDestructorCalled, TEST_LOCATION );
793 // Vector< Actor > classvector; this does not compile yet either
794 tet_result(TET_PASS); // for now