OpenWalnut  1.5.0dev
WMixinVector_test.h
1 //---------------------------------------------------------------------------
2 //
3 // Project: OpenWalnut ( http://www.openwalnut.org )
4 //
5 // Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
6 // For more information see http://www.openwalnut.org/copying
7 //
8 // This file is part of OpenWalnut.
9 //
10 // OpenWalnut is free software: you can redistribute it and/or modify
11 // it under the terms of the GNU Lesser General Public License as published by
12 // the Free Software Foundation, either version 3 of the License, or
13 // (at your option) any later version.
14 //
15 // OpenWalnut is distributed in the hope that it will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 // GNU Lesser General Public License for more details.
19 //
20 // You should have received a copy of the GNU Lesser General Public License
21 // along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
22 //
23 //---------------------------------------------------------------------------
24 
25 #ifndef WMIXINVECTOR_TEST_H
26 #define WMIXINVECTOR_TEST_H
27 
28 #include <string>
29 #include <vector>
30 
31 #include <cxxtest/TestSuite.h>
32 
33 #include "../WMixinVector.h"
34 #include "WMixinVectorTraits.h"
35 
36 // \cond Suppress_Doxygen
37 // This is just a dummy class to test if the default constructor is called when
38 // not specified by WMixinVector instanziation.
39 class A {public: A(){m_x = 3.1415;} bool operator==(double x){return m_x == x;} double m_x; }; // NOLINT
40 // \endcond
41 
42 /**
43  * Unit tests the WMixinVector copy from OSG
44  * \warning THIS IS FAR AWAY FROM BEING A COMPLETE UNIT TEST SUIT FOR WMIXINVECTOR!!!
45  */
46 class WMixinVectorTest : public CxxTest::TestSuite
47 {
48 public:
49  /**
50  * Test the default Ctor
51  */
52  void testDefaultCtor( void )
53  {
54  TS_ASSERT_THROWS_NOTHING( WMixinVector< double >() );
55  }
56 
57  /**
58  * You may initialize a vector with a given size and optionally with
59  * a default value of the elments.
60  */
61  void testSizeValueCtor( void )
62  {
63  WMixinVector< std::string > stringV( 2, "bla" );
64  TS_ASSERT( stringV.size() == 2 );
65  TS_ASSERT_EQUALS( stringV[0], "bla" );
66  TS_ASSERT_EQUALS( stringV[1], "bla" );
67  WMixinVector< A > aV( 5 );
68  TS_ASSERT_EQUALS( aV.size(), 5 );
69  for( size_t i = 0; i < 5; ++i )
70  {
71  TS_ASSERT_EQUALS( aV[i], 3.1415 );
72  }
73  }
74 
75  /**
76  * If you have another WMixinVector a copy construction should be possible
77  */
79  {
80  WMixinVector< int > intV( 4, -1 );
81  WMixinVector< int > intV2( intV );
82  TS_ASSERT_EQUALS( intV, intV2 );
83  intV[0] = 0;
84  TS_ASSERT_DIFFERS( intV, intV2 );
85  }
86 
87  /**
88  * If you have a std::vector< T > copy construction should still be possible.
89  */
91  {
92  std::vector< char > charV( 5, 's' );
93  WMixinVector< char > charV2( charV );
94  TS_ASSERT_EQUALS( charV, charV2 );
95  charV[0] = 'a';
96  TS_ASSERT_DIFFERS( charV, charV2 );
97  }
98 
99  /**
100  * A creation should also be possible out of iterators
101  */
103  {
104  int myints[] = { 16, 2, 77, 29 }; // NOLINT
105  WMixinVector< int > v( myints, myints + sizeof( myints ) / sizeof( int ) );
106  TS_ASSERT_EQUALS( v.size(), 4 );
107  TS_ASSERT_EQUALS( v[0], 16 );
108  TS_ASSERT_EQUALS( v[1], 2 );
109  TS_ASSERT_EQUALS( v[2], 77 );
110  TS_ASSERT_EQUALS( v[3], 29 );
111  }
112 };
113 
114 #endif // WMIXINVECTOR_TEST_H
Unit tests the WMixinVector copy from OSG.
void testCopyCtorOnRealSTDVector(void)
If you have a std::vector< T > copy construction should still be possible.
void testCopyCtorOnWMixinVector(void)
If you have another WMixinVector a copy construction should be possible.
void testDefaultCtor(void)
Test the default Ctor.
void testIteratorConstructor(void)
A creation should also be possible out of iterators.
void testSizeValueCtor(void)
You may initialize a vector with a given size and optionally with a default value of the elments.
This is taken from OpenSceneGraph <osg/MixinVector> but copy and pasted in order to reduce dependency...
Definition: WMixinVector.h:48
size_type size() const
Wrapper around std::vector member function.
Definition: WMixinVector.h:267