OpenWalnut  1.4.0
WMixinVector_test.h
00001 //---------------------------------------------------------------------------
00002 //
00003 // Project: OpenWalnut ( http://www.openwalnut.org )
00004 //
00005 // Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
00006 // For more information see http://www.openwalnut.org/copying
00007 //
00008 // This file is part of OpenWalnut.
00009 //
00010 // OpenWalnut is free software: you can redistribute it and/or modify
00011 // it under the terms of the GNU Lesser General Public License as published by
00012 // the Free Software Foundation, either version 3 of the License, or
00013 // (at your option) any later version.
00014 //
00015 // OpenWalnut is distributed in the hope that it will be useful,
00016 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00017 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018 // GNU Lesser General Public License for more details.
00019 //
00020 // You should have received a copy of the GNU Lesser General Public License
00021 // along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
00022 //
00023 //---------------------------------------------------------------------------
00024 
00025 #ifndef WMIXINVECTOR_TEST_H
00026 #define WMIXINVECTOR_TEST_H
00027 
00028 #include <string>
00029 #include <vector>
00030 
00031 #include <cxxtest/TestSuite.h>
00032 
00033 #include "../WMixinVector.h"
00034 #include "WMixinVectorTraits.h"
00035 
00036 // \cond Suppress_Doxygen
00037 // This is just a dummy class to test if the default constructor is called when
00038 // not specified by WMixinVector instanziation.
00039 class A {public: A(){m_x = 3.1415;} bool operator==(double x){return m_x == x;} double m_x; }; // NOLINT
00040 // \endcond
00041 
00042 /**
00043  * Unit tests the WMixinVector copy from OSG
00044  * \warning THIS IS FAR AWAY FROM BEING A COMPLETE UNIT TEST SUIT FOR WMIXINVECTOR!!!
00045  */
00046 class WMixinVectorTest : public CxxTest::TestSuite
00047 {
00048 public:
00049     /**
00050      * Test the default Ctor
00051      */
00052     void testDefaultCtor( void )
00053     {
00054         TS_ASSERT_THROWS_NOTHING( WMixinVector< double >() );
00055     }
00056 
00057     /**
00058      * You may initialize a vector with a given size and optionally with
00059      * a default value of the elments.
00060      */
00061     void testSizeValueCtor( void )
00062     {
00063         WMixinVector< std::string > stringV( 2, "bla" );
00064         TS_ASSERT( stringV.size() == 2 );
00065         TS_ASSERT_EQUALS( stringV[0], "bla" );
00066         TS_ASSERT_EQUALS( stringV[1], "bla" );
00067         WMixinVector< A > aV( 5 );
00068         TS_ASSERT_EQUALS( aV.size(), 5 );
00069         for( size_t i = 0; i < 5; ++i )
00070         {
00071             TS_ASSERT_EQUALS( aV[i], 3.1415 );
00072         }
00073     }
00074 
00075     /**
00076      * If you have another WMixinVector a copy construction should be possible
00077      */
00078     void testCopyCtorOnWMixinVector( void )
00079     {
00080         WMixinVector< int > intV( 4, -1 );
00081         WMixinVector< int > intV2( intV );
00082         TS_ASSERT_EQUALS( intV, intV2 );
00083         intV[0] = 0;
00084         TS_ASSERT_DIFFERS( intV, intV2 );
00085     }
00086 
00087     /**
00088      * If you have a std::vector< T > copy construction should still be possible.
00089      */
00090     void testCopyCtorOnRealSTDVector( void )
00091     {
00092         std::vector< char > charV( 5, 's' );
00093         WMixinVector< char > charV2( charV );
00094         TS_ASSERT_EQUALS( charV, charV2 );
00095         charV[0] = 'a';
00096         TS_ASSERT_DIFFERS( charV, charV2 );
00097     }
00098 
00099     /**
00100      * A creation should also be possible out of iterators
00101      */
00102     void testIteratorConstructor( void )
00103     {
00104          int myints[] = { 16, 2, 77, 29 }; // NOLINT
00105          WMixinVector< int > v( myints, myints + sizeof( myints ) / sizeof( int ) );
00106          TS_ASSERT_EQUALS( v.size(), 4 );
00107          TS_ASSERT_EQUALS( v[0], 16 );
00108          TS_ASSERT_EQUALS( v[1], 2 );
00109          TS_ASSERT_EQUALS( v[2], 77 );
00110          TS_ASSERT_EQUALS( v[3], 29 );
00111     }
00112 };
00113 
00114 #endif  // WMIXINVECTOR_TEST_H