OpenWalnut  1.5.0dev
WSubject_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 WSUBJECT_TEST_H
26 #define WSUBJECT_TEST_H
27 
28 #include <memory>
29 #include <string>
30 
31 #include <cxxtest/TestSuite.h>
32 
33 #include "../WDataSet.h"
34 #include "../WSubject.h"
35 
36 /**
37  * The tests for our subject class.
38  */
39 class WSubjectTest : public CxxTest::TestSuite
40 {
41 public:
42  /**
43  * Test instantiation of objects of WSubject class
44  */
45  void testInstantiation( void )
46  {
47  TS_ASSERT_THROWS_NOTHING( WSubject() );
48  }
49 
50  /**
51  * Test instantiation of objects of WSubject class with name
52  */
54  {
56  TS_ASSERT_THROWS_NOTHING( WSubject subject( testInfo ) );
57  }
58 
59  /**
60  * Test whether we have put the info where it belongs and intialized the rest.
61  */
63  {
65  WSubject dummySubject( testInfo );
66  TS_ASSERT_EQUALS( testInfo, dummySubject.m_personalInfo );
67  }
68 
69 
70  /**
71  * Test whether we can retrieve the right info with getName function.
72  */
73  void testGetName()
74  {
76  testInfo.setSubjectID( 1 );
77  testInfo.setLastName( "Testname" );
78  WSubject dummySubject( testInfo );
79  TS_ASSERT_EQUALS( testInfo.getLastName()+", " , dummySubject.getName() );
80  }
81 
82  /**
83  * Test adding and iterating of data sets.
84  */
86  {
87  std::shared_ptr< WDataSet > dummyDataSet;
88  dummyDataSet = std::shared_ptr< WDataSet >( new WDataSet );
89  std::string filename = "Hallo";
90  dummyDataSet->setFilename( filename );
91 
92  WSubject dummySubject;
93  dummySubject.addDataSet( dummyDataSet );
94  TS_ASSERT_EQUALS( 1, dummySubject.m_datasets.size() );
95 
96  // iterate the list and find all textures
98  int count = 0;
99  for( WSubject::DatasetConstIterator iter = a->get().begin(); iter != a->get().end(); ++iter )
100  {
101  count++;
102  TS_ASSERT_EQUALS( filename, ( *iter )->getFilename() );
103  TS_ASSERT_EQUALS( dummyDataSet, ( *iter ) );
104  }
105 
106  TS_ASSERT( count == 1 );
107  }
108 
109  /**
110  * Test getting number of datasets.
111  */
113  {
114  std::shared_ptr< WDataSet > dummyDataSet;
115  dummyDataSet = std::shared_ptr< WDataSet >( new WDataSet );
116  std::string filename = "Hallo";
117  dummyDataSet->setFilename( filename );
118 
119  WSubject dummySubject;
120  TS_ASSERT_EQUALS( 0, dummySubject.m_datasets.size() );
121  dummySubject.addDataSet( dummyDataSet );
122  TS_ASSERT_EQUALS( 1, dummySubject.m_datasets.size() );
123  dummySubject.addDataSet( dummyDataSet );
124  TS_ASSERT_EQUALS( 2, dummySubject.m_datasets.size() );
125  dummySubject.addDataSet( dummyDataSet );
126  TS_ASSERT_EQUALS( 3, dummySubject.m_datasets.size() );
127  }
128 };
129 
130 #endif // WSUBJECT_TEST_H
Base class for all data set types.
Definition: WDataSet.h:50
A structure that holds all relevant information about the subject.
std::string getLastName() const
Returns the last or family name of the person.
void setSubjectID(uint64_t subjectID)
Sets the subjectID of the person.
static WPersonalInformation createDummyInformation()
Returns an empty dummy WPersonalInformation object.
void setLastName(std::string lastName)
Sets the last or family name of the person if the object is no dummy anymore.
std::shared_ptr< WSharedObjectTicketRead< T > > ReadTicket
Type for read tickets.
Definition: WSharedObject.h:65
size_t size() const
The size of the container.
The tests for our subject class.
Definition: WSubject_test.h:40
void testGetNumberOfDataSet()
Test getting number of datasets.
void testGetName()
Test whether we can retrieve the right info with getName function.
Definition: WSubject_test.h:73
void TestConstructorWithInfo()
Test whether we have put the info where it belongs and intialized the rest.
Definition: WSubject_test.h:62
void testInstantiation(void)
Test instantiation of objects of WSubject class.
Definition: WSubject_test.h:45
void testAddGetDataSet()
Test adding and iterating of data sets.
Definition: WSubject_test.h:85
void testInstantiationWithName(void)
Test instantiation of objects of WSubject class with name.
Definition: WSubject_test.h:53
Container for all WDataSets belonging to one subject or patient.
Definition: WSubject.h:46
DatasetSharedContainerType m_datasets
A container for all WDataSet.
Definition: WSubject.h:163
DatasetContainerType::const_iterator DatasetConstIterator
The dataset const iterator.
Definition: WSubject.h:79
DatasetSharedContainerType::ReadTicket getDatasets() const
Returns read-access to the dataset list.
Definition: WSubject.cpp:99
WPersonalInformation m_personalInfo
Information on the person represented by this WSubject.
Definition: WSubject.h:176
std::string getName() const
Returns the name of the subject.
Definition: WSubject.cpp:55
void addDataSet(std::shared_ptr< WDataSet > dataset)
Insert a new dataset referenced by a pointer.
Definition: WSubject.cpp:65