OpenWalnut  1.4.0
WSubject_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 WSUBJECT_TEST_H
00026 #define WSUBJECT_TEST_H
00027 
00028 #include <string>
00029 #include <cxxtest/TestSuite.h>
00030 
00031 #include "../WSubject.h"
00032 #include "../WDataSet.h"
00033 
00034 /**
00035  * The tests for our subject class.
00036  */
00037 class WSubjectTest : public CxxTest::TestSuite
00038 {
00039 public:
00040     /**
00041      * Test instantiation of objects of WSubject class
00042      */
00043     void testInstantiation( void )
00044     {
00045         TS_ASSERT_THROWS_NOTHING( WSubject() );
00046     }
00047 
00048     /**
00049      * Test instantiation of objects of WSubject class with name
00050      */
00051     void testInstantiationWithName( void )
00052     {
00053         WPersonalInformation testInfo( WPersonalInformation::createDummyInformation() );
00054         TS_ASSERT_THROWS_NOTHING( WSubject( testInfo ) );
00055     }
00056 
00057     /**
00058      * Test whether we have put the info where it belongs and intialized the rest.
00059      */
00060     void TestConstructorWithInfo()
00061     {
00062         WPersonalInformation testInfo( WPersonalInformation::createDummyInformation() );
00063         WSubject dummySubject( testInfo );
00064         TS_ASSERT_EQUALS( testInfo, dummySubject.m_personalInfo );
00065     }
00066 
00067 
00068     /**
00069      * Test whether we can retrieve the right info with getName function.
00070      */
00071     void testGetName()
00072     {
00073         WPersonalInformation testInfo( WPersonalInformation::createDummyInformation() );
00074         testInfo.setSubjectID( 1 );
00075         testInfo.setLastName( "Testname" );
00076         WSubject dummySubject( testInfo );
00077         TS_ASSERT_EQUALS( testInfo.getLastName()+",  " , dummySubject.getName() );
00078     }
00079 
00080     /**
00081      * Test adding and iterating of data sets.
00082      */
00083     void testAddGetDataSet()
00084     {
00085         boost::shared_ptr< WDataSet > dummyDataSet;
00086         dummyDataSet = boost::shared_ptr< WDataSet >( new WDataSet );
00087         std::string filename = "Hallo";
00088         dummyDataSet->setFilename( filename );
00089 
00090         WSubject dummySubject;
00091         dummySubject.addDataSet( dummyDataSet );
00092         TS_ASSERT_EQUALS( 1, dummySubject.m_datasets.size() );
00093 
00094         // iterate the list and find all textures
00095         WSubject::DatasetSharedContainerType::ReadTicket a = dummySubject.getDatasets();
00096         int count = 0;
00097         for( WSubject::DatasetConstIterator iter = a->get().begin(); iter != a->get().end(); ++iter )
00098         {
00099             count++;
00100             TS_ASSERT_EQUALS( filename, ( *iter )->getFilename() );
00101             TS_ASSERT_EQUALS( dummyDataSet, ( *iter ) );
00102         }
00103 
00104         TS_ASSERT( count == 1 );
00105     }
00106 
00107     /**
00108      * Test getting number of datasets.
00109      */
00110     void testGetNumberOfDataSet()
00111     {
00112         boost::shared_ptr< WDataSet > dummyDataSet;
00113         dummyDataSet = boost::shared_ptr< WDataSet >( new WDataSet );
00114         std::string filename = "Hallo";
00115         dummyDataSet->setFilename( filename );
00116 
00117         WSubject dummySubject;
00118         TS_ASSERT_EQUALS( 0, dummySubject.m_datasets.size() );
00119         dummySubject.addDataSet( dummyDataSet );
00120         TS_ASSERT_EQUALS( 1, dummySubject.m_datasets.size() );
00121         dummySubject.addDataSet( dummyDataSet );
00122         TS_ASSERT_EQUALS( 2, dummySubject.m_datasets.size() );
00123         dummySubject.addDataSet( dummyDataSet );
00124         TS_ASSERT_EQUALS( 3, dummySubject.m_datasets.size() );
00125     }
00126 };
00127 
00128 #endif  // WSUBJECT_TEST_H