OpenWalnut  1.4.0
WDataSetSingle_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 WDATASETSINGLE_TEST_H
26 #define WDATASETSINGLE_TEST_H
27 
28 #include <stdint.h>
29 #include <vector>
30 
31 #include <cxxtest/TestSuite.h>
32 
33 #include "../WDataSetSingle.h"
34 #include "../WValueSet.h"
35 #include "../WGrid.h"
36 #include "../WGridRegular3D.h"
37 #include "../WDataHandlerEnums.h"
38 #include "../../common/WLogger.h"
39 
40 /**
41  * Test important functionality of WDataSetSingle class
42  */
43 class WDataSetSingleTest : public CxxTest::TestSuite
44 {
45 public:
46  boost::shared_ptr< WGrid > gridDummy; //!< Dummy grid used in the tests.
47  boost::shared_ptr< WValueSetBase > valueSetDummy; //!< Dummy value set used in the tests.
48 
49  /**
50  * Constructs unit test environment.
51  */
52  void setUp( void )
53  {
55 
56  // create dummies, since they are needed in almost every test
57  gridDummy = boost::shared_ptr< WGrid >( new WGridRegular3D( 1, 1, 1 ) );
58  boost::shared_ptr< std::vector< int8_t > > data( new std::vector< int8_t >( 1, 1 ) );
59  valueSetDummy = boost::shared_ptr< WValueSet< int8_t > >( new WValueSet< int8_t >( 0, 1, data, W_DT_INT8 ) );
60  }
61 
62  /**
63  * During instantiation nothing should be thrown.
64  */
65  void testInstantiation( void )
66  {
67  TS_ASSERT_THROWS_NOTHING( WDataSetSingle ds( valueSetDummy, gridDummy ) );
68  }
69 
70  /**
71  * Retrieving a WValueSetBase should always give the original pointer.
72  */
73  void testGetValueSet( void )
74  {
75  boost::shared_ptr< std::vector< double > > data( new std::vector< double >( 1, 3.1415 ) );
76  boost::shared_ptr< WValueSet< double > > other;
77  other = boost::shared_ptr< WValueSet< double > >( new WValueSet< double >( 0, 1, data, W_DT_DOUBLE ) );
78  WDataSetSingle dataSetSingle( valueSetDummy, gridDummy );
79  TS_ASSERT_EQUALS( dataSetSingle.getValueSet(), valueSetDummy );
80  TS_ASSERT_DIFFERS( dataSetSingle.getValueSet(), other );
81  }
82 
83  /**
84  * Retrieving a WGrid should always give the original pointer.
85  */
86  void testGetGrid( void )
87  {
88  boost::shared_ptr< WGrid > other = boost::shared_ptr< WGridRegular3D >( new WGridRegular3D( 1, 1, 1 ) );
89  WDataSetSingle dataSetSingle( valueSetDummy, gridDummy );
90  TS_ASSERT_EQUALS( dataSetSingle.getGrid(), gridDummy );
91  TS_ASSERT_DIFFERS( dataSetSingle.getGrid(), other );
92  }
93 };
94 #endif // WDATASETSINGLE_TEST_H