OpenWalnut  1.4.0
WDataHandler_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 WDATAHANDLER_TEST_H
26 #define WDATAHANDLER_TEST_H
27 
28 #ifndef Q_MOC_RUN
29 #include <boost/shared_ptr.hpp>
30 #endif
31 
32 #include <cxxtest/TestSuite.h>
33 
34 #include "../../common/WLogger.h"
35 #include "../WSubject.h"
36 #include "../WDataHandler.h"
37 
38 /**
39  * Test important functionality of WDataHandler class
40  */
41 class WDataHandlerTest : public CxxTest::TestSuite
42 {
43 public:
44  /**
45  * Setup logger and other stuff for each test.
46  */
47  void setUp()
48  {
50  }
51 
52  /**
53  * Instatiation should throw nothing.
54  */
56  {
57  TS_ASSERT_THROWS_NOTHING( WDataHandler() );
58  }
59 
60  /**
61  * Singleton getter should create an instance
62  */
64  {
65  TS_ASSERT_THROWS_NOTHING( WDataHandler::getDataHandler() );
66  TS_ASSERT( WDataHandler::getDataHandler().get() );
67  }
68 
69  /**
70  * Test adding and iterating subjects
71  */
73  {
74  boost::shared_ptr< WDataHandler > dh = WDataHandler::getDataHandler();
75 
77  testInfo.setSubjectID( 1 );
78  testInfo.setLastName( "Testname" );
79 
80  WSubject* s = new WSubject( testInfo );
81  TS_ASSERT_THROWS_NOTHING( dh->addSubject( boost::shared_ptr< WSubject >( s ) ) );
82  TS_ASSERT_EQUALS( 2, dh->m_subjects.size() ); // note: this is 2 since the datahandler always provides a default subject
83 
84  // test iteration
86 
87  // iterate the list and find all textures
88  int count = 0;
89  for( WDataHandler::SubjectContainerType::const_iterator iter = a->get().begin(); iter != a->get().end(); ++iter )
90  {
91  count++;
92 
93  // the second one needs to be the added subject
94  TS_ASSERT( ( count == 1 ) || ( s == ( *iter ).get() ) );
95  }
96 
97  TS_ASSERT( count == 2 );
98  }
99 
100  /**
101  * Test the remove and clean functionality.
102  */
104  {
105  boost::shared_ptr< WDataHandler > dh = WDataHandler::getDataHandler();
106 
108  testInfo.setSubjectID( 2 );
109  testInfo.setLastName( "Testname2" );
110 
111  boost::shared_ptr< WSubject > s( new WSubject( testInfo ) );
112  dh->addSubject( s );
113 
114  // now there should be 3 subjects (one from testAddSubjects, the above added one and the default subject)
115  TS_ASSERT_EQUALS( 3, dh->m_subjects.size() ); // note: this is 2 since the datahandler always provides a default subject
116  dh->removeSubject( s );
117  TS_ASSERT_EQUALS( 2, dh->m_subjects.size() ); // note: this is 2 since the datahandler always provides a default subject
118  dh->clear();
119  TS_ASSERT_EQUALS( 0, dh->m_subjects.size() ); // note: this is 2 since the datahandler always provides a default subject
120  }
121 };
122 
123 #endif // WDATAHANDLER_TEST_H
124 
void testRemoveSubjects()
Test the remove and clean functionality.
static WPersonalInformation createDummyInformation()
Returns an empty dummy WPersonalInformation object.
void setSubjectID(uint64_t subjectID)
Sets the subjectID of the person.
void setUp()
Setup logger and other stuff for each test.
Container for all WDataSets belonging to one subject or patient.
Definition: WSubject.h:47
Test important functionality of WDataHandler class.
void setLastName(std::string lastName)
Sets the last or family name of the person if the object is no dummy anymore.
static void startup(std::ostream &output=std::cout, LogLevel level=LL_DEBUG)
Create the first and only instance of the logger as it is a singleton.
Definition: WLogger.cpp:41
void testInstantiation()
Instatiation should throw nothing.
static boost::shared_ptr< WDataHandler > getDataHandler()
As WDataHandler is a singleton -> return instance.
Provides the environment for storing and accessing different subjects.
Definition: WDataHandler.h:56
void testAddSubjects()
Test adding and iterating subjects.
void testSingleton()
Singleton getter should create an instance.
A structure that holds all relevant information about the subject.
boost::shared_ptr< WSharedObjectTicketRead< SubjectContainerType > > ReadTicket
Type for read tickets.
Definition: WSharedObject.h:64