OpenWalnut  1.4.0
WDataSetSingle_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 WDATASETSINGLE_TEST_H
00026 #define WDATASETSINGLE_TEST_H
00027 
00028 #include <stdint.h>
00029 #include <vector>
00030 
00031 #include <cxxtest/TestSuite.h>
00032 
00033 #include "../WDataSetSingle.h"
00034 #include "../WValueSet.h"
00035 #include "../WGrid.h"
00036 #include "../WGridRegular3D.h"
00037 #include "../WDataHandlerEnums.h"
00038 #include "../../common/WLogger.h"
00039 
00040 /**
00041  * Test important functionality of WDataSetSingle class
00042  */
00043 class WDataSetSingleTest : public CxxTest::TestSuite
00044 {
00045 public:
00046     boost::shared_ptr< WGrid > gridDummy; //!< Dummy grid used in the tests.
00047     boost::shared_ptr< WValueSetBase > valueSetDummy; //!< Dummy value set used in the tests.
00048 
00049     /**
00050      * Constructs unit test environment.
00051      */
00052     void setUp( void )
00053     {
00054         WLogger::startup();
00055 
00056         // create dummies, since they are needed in almost every test
00057         gridDummy = boost::shared_ptr< WGrid >( new WGridRegular3D( 1, 1, 1 ) );
00058         boost::shared_ptr< std::vector< int8_t > > data( new std::vector< int8_t >( 1, 1 ) );
00059         valueSetDummy = boost::shared_ptr< WValueSet< int8_t > >( new WValueSet< int8_t >( 0, 1, data, W_DT_INT8 ) );
00060     }
00061 
00062     /**
00063      * During instantiation nothing should be thrown.
00064      */
00065     void testInstantiation( void )
00066     {
00067         TS_ASSERT_THROWS_NOTHING( WDataSetSingle ds( valueSetDummy, gridDummy ) );
00068     }
00069 
00070     /**
00071      * Retrieving a WValueSetBase should always give the original pointer.
00072      */
00073     void testGetValueSet( void )
00074     {
00075         boost::shared_ptr< std::vector< double > > data( new std::vector< double >( 1, 3.1415 ) );
00076         boost::shared_ptr< WValueSet< double > > other;
00077         other = boost::shared_ptr< WValueSet< double > >( new WValueSet< double >( 0, 1, data, W_DT_DOUBLE ) );
00078         WDataSetSingle dataSetSingle( valueSetDummy, gridDummy );
00079         TS_ASSERT_EQUALS( dataSetSingle.getValueSet(), valueSetDummy );
00080         TS_ASSERT_DIFFERS( dataSetSingle.getValueSet(), other );
00081     }
00082 
00083     /**
00084      * Retrieving a WGrid should always give the original pointer.
00085      */
00086     void testGetGrid( void )
00087     {
00088         boost::shared_ptr< WGrid > other = boost::shared_ptr< WGridRegular3D >( new WGridRegular3D( 1, 1, 1 ) );
00089         WDataSetSingle dataSetSingle( valueSetDummy, gridDummy );
00090         TS_ASSERT_EQUALS( dataSetSingle.getGrid(), gridDummy );
00091         TS_ASSERT_DIFFERS( dataSetSingle.getGrid(), other );
00092     }
00093 };
00094 #endif  // WDATASETSINGLE_TEST_H