Dali 3D User Interface Engine
utc-Dali-Vector.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2014 Samsung Electronics Co., Ltd.
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  *
16  */
17 
18 #define ENABLE_VECTOR_ASSERTS
19 
20 #include <iostream>
21 #include <stdlib.h>
23 #include <dali-test-suite-utils.h>
24 
25 using namespace Dali;
26 
27 namespace
28 {
30 
32 void DALI_TEST_EQUALS( short value1, int value2, const char* location )
33 {
34  ::DALI_TEST_EQUALS< short >( value1, static_cast< short >( value2 ), location );
35 }
36 
38 void DALI_TEST_EQUALS( char value1, int value2, const char* location )
39 {
40  ::DALI_TEST_EQUALS< char >( value1, static_cast< char >( value2 ), location );
41 }
42 
43 } // unnamed namespace
44 
46 {
47  tet_infoline("Testing Dali::Vector<int>");
48 
49  Vector< int > intvector;
50 
51  DALI_TEST_EQUALS( ZERO, intvector.Count(), TEST_LOCATION );
53 
54  intvector.Clear();
55  DALI_TEST_EQUALS( ZERO, intvector.Count(), TEST_LOCATION );
57 
58  intvector.Release();
59  DALI_TEST_EQUALS( ZERO, intvector.Count(), TEST_LOCATION );
61  END_TEST;
62 }
63 
65 {
66  tet_infoline("Testing Dali::Vector<int>");
67 
68  Vector< int > intvector;
69 
70  DALI_TEST_EQUALS( ZERO, intvector.Count(), TEST_LOCATION );
72 
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 );
77 
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 );
82 
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 );
89 
90  intvector.Clear();
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 );
96  END_TEST;
97 }
98 
100 {
101  tet_infoline("Testing Dali::Vector<int>::Copy");
102 
103  Vector< int > intvector;
104  DALI_TEST_EQUALS( ZERO, intvector.Count(), TEST_LOCATION );
105  DALI_TEST_EQUALS( ZERO, intvector.Capacity(), TEST_LOCATION );
106 
107  intvector.PushBack( 99 );
108  intvector.PushBack( 11 );
109  intvector.PushBack( 34 );
110 
111  // copy construct
112  Vector< int > intvector2( intvector );
113 
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 );
119 
120  // assign
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 );
127 
128  // copy empty
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 );
136 
137  // self copy
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 );
141  END_TEST;
142 }
143 
145 {
146  tet_infoline("Testing Dali::Vector<short>::Resize");
147 
148  Vector< short > vector;
151 
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 );
155 
156  vector.Resize( 4u );
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 );
159 
160  vector.Resize( 4u );
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 );
163 
164  vector.Resize( 0u );
166  DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(10), vector.Capacity(), TEST_LOCATION );
167 
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 );
171 
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 );
184 
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 );
188 
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 );
202  END_TEST;
203 }
204 
206 {
207  tet_infoline("Testing Dali::Vector<short>::Erase");
208 
209  Vector< char > vector;
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 );
223 
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 );
230 
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 );
237 
238  // try erasing last
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 );
245 
246  try
247  {
248  // illegal erase, one past the end
249  vector.Erase( vector.End() );
251  }
252  catch( Dali::DaliException& e )
253  {
255  DALI_TEST_ASSERT( e, "(iterator < End())", TEST_LOCATION );
256  }
257  catch( ... )
258  {
259  tet_printf("Assertion test failed - wrong Exception\n" );
261  }
262 
263  try
264  {
265  // illegal erase, one before the begin
266  vector.Erase( vector.Begin() - 1u );
268  }
269  catch( Dali::DaliException& e )
270  {
272  DALI_TEST_ASSERT( e, "(iterator < End()) && (iterator >= Begin())", TEST_LOCATION );
273  }
274  catch( ... )
275  {
276  tet_printf("Assertion test failed - wrong Exception\n" );
278  }
279 
280 
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 );
285 
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 );
290 
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 );
294 
295  try
296  {
297  // illegal erase, one past the end
298  vector.Erase( vector.Begin() + 1 );
300  }
301  catch( Dali::DaliException& e )
302  {
304  DALI_TEST_ASSERT( e, "(iterator < End())", TEST_LOCATION );
305  }
306  catch( ... )
307  {
308  tet_printf("Assertion test failed - wrong Exception\n" );
310  }
311  DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(1), vector.Count(), TEST_LOCATION );
312  DALI_TEST_EQUALS( vector[ 0 ], 2, TEST_LOCATION );
313 
314  vector.Erase( vector.Begin() );
316 
317  try
318  {
319  // illegal erase, one before the beginning
320  vector.Erase( vector.Begin() - 1 );
322  }
323  catch( Dali::DaliException& e )
324  {
326  DALI_TEST_ASSERT( e, "(iterator < End())", TEST_LOCATION );
327  }
328  catch( ... )
329  {
330  tet_printf("Assertion test failed - wrong Exception\n" );
332  }
333 
335  DALI_TEST_EQUALS( vector.Begin(), vector.End(), TEST_LOCATION );
336 
337  Vector< char >::Iterator endIter = vector.End();
338  for( Vector< char >::Iterator iter = vector.Begin(); iter != endIter; ++iter )
339  {
341  }
342 
343  vector.PushBack( 3 );
344  DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(1), vector.Count(), TEST_LOCATION );
345 
346  vector.Clear();
348  DALI_TEST_EQUALS( vector.Begin(), vector.End(), TEST_LOCATION );
349 
350  endIter = vector.End();
351  for( Vector< char >::Iterator iter = vector.Begin(); iter != endIter; ++iter )
352  {
354  }
355 
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 );
360 
361  int* pointer = NULL;
362  ptrVector.PushBack( pointer );
363  DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(1), ptrVector.Count(), TEST_LOCATION );
364 
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 );
370  END_TEST;
371 }
372 
373 
375 {
376  tet_infoline("Testing Dali::Vector<double>::Remove");
377 
378  Vector< double > vector;
380 
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 );
390 
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 );
400 
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 );
405 
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 );
409 
410  try
411  {
412  // illegal erase, one past the end
413  vector.Remove( vector.Begin() + 1 );
415  }
416  catch( Dali::DaliException& e )
417  {
419  DALI_TEST_ASSERT( e, "(iterator < End()) && (iterator >= Begin())", TEST_LOCATION );
420  }
421  catch( ... )
422  {
423  tet_printf("Assertion test failed - wrong Exception\n" );
425  }
426  DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(1), vector.Count(), TEST_LOCATION );
427  DALI_TEST_EQUALS( vector[ 0 ], 44.4, TEST_LOCATION );
428 
429  vector.Remove( vector.Begin() );
431 
432  try
433  {
434  // illegal erase, one before the beginning
435  vector.Remove( vector.Begin() - 1 );
437  }
438  catch( Dali::DaliException& e )
439  {
441  DALI_TEST_ASSERT( e, "(iterator < End()) && (iterator >= Begin())", TEST_LOCATION );
442  }
443  catch( ... )
444  {
445  tet_printf("Assertion test failed - wrong Exception\n" );
447  }
448 
449  END_TEST;
450 }
451 
453 {
454  tet_infoline("Testing Dali::Vector<int>::Swap");
455 
456  Vector< int > intvector;
457  DALI_TEST_EQUALS( ZERO, intvector.Count(), TEST_LOCATION );
458  DALI_TEST_EQUALS( ZERO, intvector.Capacity(), TEST_LOCATION );
459 
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 );
464 
465  Vector< int > intvector2;
466  DALI_TEST_EQUALS( ZERO, intvector2.Count(), TEST_LOCATION );
467  DALI_TEST_EQUALS( ZERO, intvector2.Capacity(), TEST_LOCATION );
468 
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 );
476 
477  intvector.PushBack( 99 );
478  intvector.PushBack( 88 );
479  DALI_TEST_EQUALS( static_cast<Dali::VectorBase::SizeType>(2), intvector.Count(), TEST_LOCATION );
480 
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 );
489 
490  Vector< int > empty;
491  intvector.Swap( empty );
492  DALI_TEST_EQUALS( ZERO, intvector.Count(), TEST_LOCATION );
493  DALI_TEST_EQUALS( ZERO, intvector.Capacity(), TEST_LOCATION );
494  END_TEST;
495 }
496 
498 {
499  tet_infoline("Testing Dali::Vector<float>::Begin");
500 
501  Vector< float > floatvector;
502  DALI_TEST_EQUALS( ZERO, floatvector.Count(), TEST_LOCATION );
503  DALI_TEST_EQUALS( ZERO, floatvector.Capacity(), TEST_LOCATION );
504 
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 );
509 
510  Vector< float >::Iterator iter = floatvector.Begin();
511  int index = 0;
512  for( ; iter != floatvector.End(); ++iter, ++index )
513  {
514  std::cout << "value " << *iter << std::endl;
515  DALI_TEST_EQUALS( *iter, floatvector[ index ], TEST_LOCATION );
516  }
517  DALI_TEST_EQUALS( 3, index, TEST_LOCATION );
518 
519  iter = std::find( floatvector.Begin(), floatvector.End(), 1.1f );
520  DALI_TEST_EQUALS( 1.1f, *iter, TEST_LOCATION );
521 
522  floatvector.Clear();
523  iter = std::find( floatvector.Begin(), floatvector.End(), 1.1f );
524  DALI_TEST_EQUALS( floatvector.End(), iter, TEST_LOCATION );
525  END_TEST;
526 }
527 
529 {
530  tet_infoline("Testing Dali::Vector< std::pair< int, float > >");
531 
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 );
535 
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 );
542 
543  Vector< std::pair< int, float > >::Iterator iter = pairvector.Begin();
544  int index = 0;
545  for( ; iter != pairvector.End(); ++iter, ++index )
546  {
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 );
550  }
551  END_TEST;
552 }
553 
555 {
556  tet_infoline("Testing Dali::Vector< int* > exception handling");
557 
558  // empty vector
559  Vector< int* > pointervector;
560  try
561  {
562  int* value = NULL;
563  pointervector[ 1 ] = value;
564  tet_printf("Assertion expected, but not occurred at %s\n", TEST_LOCATION );
566  }
567  catch(Dali::DaliException& e)
568  {
570  DALI_TEST_ASSERT( e, "VectorBase::mData", TEST_LOCATION );
571  }
572  catch(...)
573  {
574  tet_printf("Assertion test failed - wrong Exception\n" );
576  }
577 
578  try
579  {
580  int* value = NULL;
581  value = pointervector[ 0 ];
582  (void)value; // to "use" the value
583  tet_printf("Assertion expected, but not occurred at %s\n", TEST_LOCATION );
585  }
586  catch(Dali::DaliException& e)
587  {
589  DALI_TEST_ASSERT( e, "VectorBase::mData", TEST_LOCATION );
590  }
591  catch(...)
592  {
593  tet_printf("Assertion test failed - wrong Exception\n" );
595  }
596 
597  Vector< int* >::Iterator iter = pointervector.Begin();
598  if( iter != pointervector.End() )
599  {
601  }
602 
603  try
604  {
605  pointervector.Erase( pointervector.Begin() );
606  tet_printf("Assertion expected, but not occurred at %s\n", TEST_LOCATION );
608  }
609  catch(Dali::DaliException& e)
610  {
612  DALI_TEST_ASSERT( e, "(iterator < End()) && (iterator >= Begin())", TEST_LOCATION );
613  }
614  catch(...)
615  {
616  tet_printf("Assertion test failed - wrong Exception\n" );
618  }
619 
620  iter = pointervector.Begin();
621  if( iter != pointervector.End() )
622  {
624  }
625 
626  try
627  {
628  pointervector.Remove( pointervector.Begin() );
629  tet_printf("Assertion expected, but not occurred at %s\n", TEST_LOCATION );
631  }
632  catch(Dali::DaliException& e)
633  {
635  DALI_TEST_ASSERT( e, "(iterator < End()) && (iterator >= Begin())", TEST_LOCATION );
636  }
637  catch(...)
638  {
639  tet_printf("Assertion test failed - wrong Exception\n" );
641  }
642 
643  iter = pointervector.Begin();
644  if( iter != pointervector.End() )
645  {
647  }
648 
649  // reserve 0 space
650  pointervector.Reserve( 0 );
651  iter = pointervector.Begin();
652  if( iter != pointervector.End() )
653  {
655  }
656 
657  // reserve 1 space
658  pointervector.Reserve( 1 );
659  iter = pointervector.Begin();
660  if( iter != pointervector.End() )
661  {
663  }
664 
665  try
666  {
667  int* value = NULL;
668  pointervector[ 1 ] = value;
669  tet_printf("Assertion expected, but not occurred at %s\n", TEST_LOCATION );
671  }
672  catch(Dali::DaliException& e)
673  {
675  DALI_TEST_ASSERT( e, "index < VectorBase::Count()", TEST_LOCATION );
676  }
677  catch(...)
678  {
679  tet_printf("Assertion test failed - wrong Exception\n" );
681  }
682 
683  try
684  {
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 );
689  }
690  catch(Dali::DaliException& e)
691  {
693  DALI_TEST_ASSERT( e, "index < VectorBase::Count()", TEST_LOCATION );
694  }
695  catch(...)
696  {
697  tet_printf("Assertion test failed - wrong Exception\n" );
699  }
700 
701  END_TEST;
702 }
703 
705 {
706  tet_infoline("Testing multiple Dali::Vector's");
707 
708  // create multiple vectors
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 );
727 
728  // add items
729  static unsigned int acidCount = 10000;
730  int* ptr = NULL;
731  for( unsigned int i = 0; i < acidCount; ++i )
732  {
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 );
739  }
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();
752 
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 );
759 
760  // erase items
761  for( unsigned int i = 0; i < acidCount; ++i )
762  {
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() ) );
769  }
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 );
782 
783  END_TEST;
784 }
785 
787 {
788  tet_infoline( "Testing Dali::Vector< int* >PushBack(Element)" );
789 
790  Vector<unsigned int> vector;
793 
794  vector.Reserve( 2u );
796  DALI_TEST_EQUALS( 2u, vector.Capacity(), TEST_LOCATION );
797 
798  vector.PushBack( 0u );
799  vector.PushBack( 1u );
800  vector.PushBack( 2u );
801 
802  DALI_TEST_EQUALS( 3u, vector.Count(), TEST_LOCATION );
803  DALI_TEST_EQUALS( 6u, vector.Capacity(), TEST_LOCATION );
804 
805  vector.PushBack( 3u );
806 
807  DALI_TEST_EQUALS( 4u, vector.Count(), TEST_LOCATION );
808  DALI_TEST_EQUALS( 6u, vector.Capacity(), TEST_LOCATION );
809 
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 );
814 
815  END_TEST;
816 }
817 
819 {
820  tet_infoline( "Testing Dali::Vector< int* >Insert(Iterator, Element)" );
821 
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 )
826  {
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 );
830  }
831 
832  for( unsigned int i = 0u; i < 10u; ++i )
833  {
834  DALI_TEST_EQUALS( i, orderedVector[i], TEST_LOCATION );
835  }
836 
837  // Test insertion out of range in non-empty array throws:
838  try
839  {
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 );
843  }
844  catch( Dali::DaliException& e )
845  {
847  DALI_TEST_ASSERT( e, "( at <= End() ) && ( at >= Begin() )", TEST_LOCATION );
848  }
849  catch( ... )
850  {
851  tet_printf( "Assertion test failed - wrong Exception\n" );
852  tet_result( TET_FAIL );
853  }
854 
855  try
856  {
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 );
860  }
861  catch( Dali::DaliException& e )
862  {
864  DALI_TEST_ASSERT( e, "( at <= End() ) && ( at >= Begin() )", TEST_LOCATION );
865  }
866  catch( ... )
867  {
868  tet_printf( "Assertion test failed - wrong Exception\n" );
869  tet_result( TET_FAIL );
870  }
871 
872  // Test insertion part-way through a largish array retains ordering:
873 
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 )
879  {
880  longerVector.PushBack( i );
881  }
882  for( unsigned int i = insertionPoint; i < finalLength; ++i )
883  {
884  longerVector.PushBack( i + 1 );
885  }
886 
887  // Fill the hole in the sequence:
888  longerVector.Insert( longerVector.Begin() + insertionPoint, insertionPoint );
889 
890  // Check the sequence is monotonically increasing by one every time:
891  for( unsigned int i = 0u; i <= finalLength; ++i )
892  {
893  DALI_TEST_EQUALS( i, longerVector[i], TEST_LOCATION );
894  }
895 
896  // Insert into an empty vector
897  Vector< unsigned int > vector;
898 
899  vector.Insert( vector.End(), orderedVector.Begin(), orderedVector.End() );
900  for( unsigned int i = 0u; i < 10u; ++i )
901  {
902  DALI_TEST_EQUALS( i, vector[i], TEST_LOCATION );
903  }
904 
905  vector.Clear();
906  vector.Insert( vector.Begin(), orderedVector.Begin(), orderedVector.End() );
907  for( unsigned int i = 0u; i < 10u; ++i )
908  {
909  DALI_TEST_EQUALS( i, vector[i], TEST_LOCATION );
910  }
911 
912  // Insert nothing.
913  vector.Insert( vector.Begin(), orderedVector.Begin(), orderedVector.Begin() );
914  for( unsigned int i = 0u; i < 10u; ++i )
915  {
916  DALI_TEST_EQUALS( i, vector[i], TEST_LOCATION );
917  }
918 
919  vector.Insert( vector.Begin() + 5, vector.Begin() + 5, vector.Begin() + 5 );
920  for( unsigned int i = 0u; i < 10u; ++i )
921  {
922  DALI_TEST_EQUALS( i, vector[i], TEST_LOCATION );
923  }
924 
925  // AutoInsert
926  vector.Clear();
927  vector.PushBack( 0u );
928  vector.PushBack( 1u );
929  vector.PushBack( 2u );
930  vector.PushBack( 3u );
931 
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 );
942 
943  END_TEST;
944 }
945 
947 {
948  tet_infoline("Testing Dali::Vector<char>::Insert(Iterator,Iterator,Iterator)");
949 
950  Vector< char > vector;
953  vector.PushBack( 1 );
954  vector.PushBack( 2 );
955  vector.PushBack( 3 );
956  vector.PushBack( 4 );
957  vector.PushBack( 5 );
958 
959  Vector< char > vector2;
960  DALI_TEST_EQUALS( ZERO, vector2.Count(), TEST_LOCATION );
962  vector2.PushBack( 6 );
963  vector2.PushBack( 7 );
964  vector2.PushBack( 8 );
965  vector2.PushBack( 9 );
966  vector2.PushBack( 10 );
967 
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 );
977 
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 );
988 
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 );
1001  END_TEST;
1002 }
1003 
1005 {
1006  tet_infoline("Testing Dali::Vector<char>::Insert(Iterator,Iterator,Iterator) asserts");
1007 
1008  Vector< char > vector;
1009  DALI_TEST_EQUALS( ZERO, vector.Count(), TEST_LOCATION );
1011  vector.PushBack( 1 );
1012  vector.PushBack( 2 );
1013 
1014  Vector< char > vector2;
1015  DALI_TEST_EQUALS( ZERO, vector2.Count(), TEST_LOCATION );
1017  vector2.PushBack( 6 );
1018  vector2.PushBack( 7 );
1019  vector2.PushBack( 8 );
1020  vector2.PushBack( 9 );
1021  vector2.PushBack( 10 );
1022 
1023  try
1024  {
1025  vector.Insert( vector.Begin() + 3u, vector2.Begin(), vector2.End() );
1027  }
1028  catch( Dali::DaliException& e )
1029  {
1031  DALI_TEST_ASSERT( e, "( at <= End() ) && ( at >= Begin() )", TEST_LOCATION );
1032  }
1033  catch( ... )
1034  {
1035  tet_printf("Assertion test failed - wrong Exception\n" );
1037  }
1038 
1039  try
1040  {
1041  vector.Insert( vector.Begin() - 1u, vector2.Begin(), vector2.End() );
1043  }
1044  catch( Dali::DaliException& e )
1045  {
1047  DALI_TEST_ASSERT( e, "( at <= End() ) && ( at >= Begin() )", TEST_LOCATION );
1048  }
1049  catch( ... )
1050  {
1051  tet_printf("Assertion test failed - wrong Exception\n" );
1053  }
1054 
1055  try
1056  {
1057  vector.Insert( vector.End(), vector2.End(), vector2.Begin() );
1059  }
1060  catch( Dali::DaliException& e )
1061  {
1063  DALI_TEST_ASSERT( e, "( from <= to )", TEST_LOCATION );
1064  }
1065  catch( ... )
1066  {
1067  tet_printf("Assertion test failed - wrong Exception\n" );
1069  }
1070 
1071  END_TEST;
1072  }
1073 
1074 
1076 {
1077  tet_infoline("Testing Dali::Vector<char>::Erase(Iterator,Iterator)");
1078 
1079  Vector< char > vector;
1080  DALI_TEST_EQUALS( ZERO, vector.Count(), TEST_LOCATION );
1082 
1083  // Try to delete from empty vector.
1084 
1085  vector.Erase( vector.Begin(), vector.End() );
1086  DALI_TEST_EQUALS( ZERO, vector.Count(), TEST_LOCATION );
1088 
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 );
1100 
1102 
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 );
1110 
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 );
1116 
1117  // try erasing last
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 );
1125 
1126  // try erasing all
1127  vector.PushBack( 100 );
1128  vector.PushBack( 101 );
1129  vector.PushBack( 102 );
1130 
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 );
1136 
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 );
1140 
1141  // try erase from Iterator to the same Iterator.
1142  vector.PushBack( 100 );
1143  vector.PushBack( 101 );
1144  vector.PushBack( 102 );
1145 
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 );
1150 
1151  ret = vector.Erase( vector.Begin() + 1, vector.Begin() + 1 );
1152 
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 );
1157 
1158  DALI_TEST_EQUALS( *ret, 101, TEST_LOCATION );
1159 
1160  END_TEST;
1161 }
1162 
1164 {
1165  tet_infoline("Testing Dali::Vector<char>::Erase(Iterator,Iterator) asserts");
1166 
1167  Vector< char > vector;
1168  DALI_TEST_EQUALS( ZERO, vector.Count(), TEST_LOCATION );
1170 
1171 
1172  // Add some elements.
1173  vector.PushBack( 1 );
1174  vector.PushBack( 2 );
1175 
1176  // first out of bounds
1177  try
1178  {
1179  vector.Erase( vector.Begin() + 3u, vector.Begin() + 4u );
1180  tet_printf( "Assertion expected, but not occurred at %s\n", TEST_LOCATION );
1182  }
1183  catch( Dali::DaliException& e )
1184  {
1186  DALI_TEST_ASSERT( e, "( first <= End() ) && ( first >= Begin() )", TEST_LOCATION );
1187  }
1188  catch( ... )
1189  {
1190  tet_printf("Assertion test failed - wrong Exception\n" );
1192  }
1193 
1194  try
1195  {
1196  vector.Erase( vector.Begin() - 1u, vector.End() );
1197  tet_printf( "Assertion expected, but not occurred at %s\n", TEST_LOCATION );
1199  }
1200  catch( Dali::DaliException& e )
1201  {
1203  DALI_TEST_ASSERT( e, "( first <= End() ) && ( first >= Begin() )", TEST_LOCATION );
1204  }
1205  catch( ... )
1206  {
1207  tet_printf("Assertion test failed - wrong Exception\n" );
1209  }
1210 
1211  // last out of bounds
1212 
1213  try
1214  {
1215  vector.Erase( vector.Begin(), vector.Begin() + 3u );
1216  tet_printf( "Assertion expected, but not occurred at %s\n", TEST_LOCATION );
1218  }
1219  catch( Dali::DaliException& e )
1220  {
1222  DALI_TEST_ASSERT( e, "( last <= End() ) && ( last >= Begin() )", TEST_LOCATION );
1223  }
1224  catch( ... )
1225  {
1226  tet_printf("Assertion test failed - wrong Exception\n" );
1228  }
1229 
1230  try
1231  {
1232  vector.Erase( vector.Begin(), vector.Begin() - 1u );
1233  tet_printf( "Assertion expected, but not occurred at %s\n", TEST_LOCATION );
1235  }
1236  catch( Dali::DaliException& e )
1237  {
1239  DALI_TEST_ASSERT( e, "( last <= End() ) && ( last >= Begin() )", TEST_LOCATION );
1240  }
1241  catch( ... )
1242  {
1243  tet_printf("Assertion test failed - wrong Exception\n" );
1245  }
1246 
1247  vector.PushBack( 3 );
1248 
1249  // first > last
1250  try
1251  {
1252  vector.Erase( vector.Begin() + 2u, vector.Begin() + 1u );
1253  tet_printf( "Assertion expected, but not occurred at %s\n", TEST_LOCATION );
1255  }
1256  catch( Dali::DaliException& e )
1257  {
1259  DALI_TEST_ASSERT( e, "( first <= last )", TEST_LOCATION );
1260  }
1261  catch( ... )
1262  {
1263  tet_printf("Assertion test failed - wrong Exception\n" );
1265  }
1266 
1267  END_TEST;
1268 }
1269 
1271 {
1272  tet_infoline("Testing Dali::Vector< Vector2 >");
1273 
1274  Vector< Vector2 > classvector;
1275  DALI_TEST_EQUALS( ZERO, classvector.Count(), TEST_LOCATION );
1276  DALI_TEST_EQUALS( ZERO, classvector.Capacity(), TEST_LOCATION );
1277 
1278  classvector.PushBack( Vector2() );
1279 
1280  DALI_TEST_EQUALS( 1u, classvector.Count(), TEST_LOCATION );
1281  DALI_TEST_GREATER( classvector.Capacity(), ZERO, TEST_LOCATION );
1282 
1283  classvector.PushBack( Vector2( 0.1f, 0.2f ) );
1284 
1285  DALI_TEST_EQUALS( 2u, classvector.Count(), TEST_LOCATION );
1286 
1287  DALI_TEST_EQUALS( Vector2(), classvector[ 0 ], TEST_LOCATION );
1288  DALI_TEST_EQUALS( Vector2( 0.1f, 0.2f ), classvector[ 1 ], TEST_LOCATION );
1289 
1290  tet_result(TET_PASS); // for now
1291  END_TEST;
1292 }
1293 
1295 {
1296  tet_infoline("Testing Dali::Vector< Vector3 >");
1297 
1298  Vector< Vector3 > classvector;
1299  DALI_TEST_EQUALS( ZERO, classvector.Count(), TEST_LOCATION );
1300  DALI_TEST_EQUALS( ZERO, classvector.Capacity(), TEST_LOCATION );
1301 
1302  classvector.PushBack( Vector3() );
1303 
1304  DALI_TEST_EQUALS( 1u, classvector.Count(), TEST_LOCATION );
1305  DALI_TEST_GREATER( classvector.Capacity(), ZERO, TEST_LOCATION );
1306 
1307  classvector.PushBack( Vector3( 0.1f, 0.2f, 0.3f ) );
1308 
1309  DALI_TEST_EQUALS( 2u, classvector.Count(), TEST_LOCATION );
1310 
1311  DALI_TEST_EQUALS( Vector3(), classvector[ 0 ], TEST_LOCATION );
1312  DALI_TEST_EQUALS( Vector3( 0.1f, 0.2f, 0.3f ), classvector[ 1 ], TEST_LOCATION );
1313 
1314  tet_result(TET_PASS); // for now
1315  END_TEST;
1316 }
1317 
1319 {
1320  tet_infoline("Testing Dali::Vector< Matrix >");
1321 
1322  Vector< Matrix > classvector;
1323  DALI_TEST_EQUALS( ZERO, classvector.Count(), TEST_LOCATION );
1324  DALI_TEST_EQUALS( ZERO, classvector.Capacity(), TEST_LOCATION );
1325 
1326  classvector.PushBack( Matrix() );
1327 
1328  DALI_TEST_EQUALS( 1u, classvector.Count(), TEST_LOCATION );
1329  DALI_TEST_GREATER( classvector.Capacity(), ZERO, TEST_LOCATION );
1330 
1331  classvector.PushBack( Matrix::IDENTITY );
1332 
1333  DALI_TEST_EQUALS( 2u, classvector.Count(), TEST_LOCATION );
1334 
1335  DALI_TEST_EQUALS( Matrix(), classvector[ 0 ], TEST_LOCATION );
1336  DALI_TEST_EQUALS( Matrix::IDENTITY, classvector[ 1 ], TEST_LOCATION );
1337 
1338  tet_result(TET_PASS); // for now
1339  END_TEST;
1340 }
1341 
1342 /*
1343  * this does not compile at the moment
1344  * Vector< Actor > classvector; this does not compile yet either
1345  *
1346 namespace
1347 {
1348 
1349 bool gConstructorCalled = false;
1350 bool gDestructorCalled = false;
1351 
1352 struct ComplexType
1353 {
1354  ComplexType()
1355  {
1356  gConstructorCalled = true;
1357  }
1358  ~ComplexType()
1359  {
1360  gDestructorCalled = true;
1361  }
1362 };
1363 
1364 } // anonymous namespace
1365 
1366 int UtcDaliVectorComplex( void)
1367 {
1368  tet_infoline("Testing Dali::Vector< ComplexType > ");
1369 
1370  Vector< ComplexType > classvector;
1371  DALI_TEST_EQUALS( ZERO, classvector.Count(), TEST_LOCATION );
1372  DALI_TEST_EQUALS( ZERO, classvector.Capacity(), TEST_LOCATION );
1373 
1374  DALI_TEST_EQUALS( false, gConstructorCalled, TEST_LOCATION );
1375  DALI_TEST_EQUALS( false, gDestructorCalled, TEST_LOCATION );
1376  classvector.PushBack( ComplexType() );
1377  DALI_TEST_EQUALS( true, gConstructorCalled, TEST_LOCATION );
1378  classvector.Clear();
1379  DALI_TEST_EQUALS( true, gDestructorCalled, TEST_LOCATION );
1380  tet_result(TET_PASS); // for now
1381  END_TEST;
1382 }
1383 */
Dali Docs Home
Read more about Dali