OpenWalnut  1.5.0dev
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 #include <memory>
29 
30 #include <cxxtest/TestSuite.h>
31 
32 #include "../../common/WLogger.h"
33 #include "../WDataHandler.h"
34 #include "../WSubject.h"
35 
36 /**
37  * Test important functionality of WDataHandler class
38  */
39 class WDataHandlerTest : public CxxTest::TestSuite
40 {
41 public:
42  /**
43  * Setup logger and other stuff for each test.
44  */
45  void setUp()
46  {
48  }
49 
50  /**
51  * Instatiation should throw nothing.
52  */
54  {
55  TS_ASSERT_THROWS_NOTHING( WDataHandler() );
56  }
57 
58  /**
59  * Singleton getter should create an instance
60  */
62  {
63  TS_ASSERT_THROWS_NOTHING( WDataHandler::getDataHandler() );
64  TS_ASSERT( WDataHandler::getDataHandler().get() );
65  }
66 
67  /**
68  * Test adding and iterating subjects
69  */
71  {
72  std::shared_ptr< WDataHandler > dh = WDataHandler::getDataHandler();
73 
75  testInfo.setSubjectID( 1 );
76  testInfo.setLastName( "Testname" );
77 
78  WSubject* s = new WSubject( testInfo );
79  TS_ASSERT_THROWS_NOTHING( dh->addSubject( std::shared_ptr< WSubject >( s ) ) );
80  TS_ASSERT_EQUALS( 2, dh->m_subjects.size() ); // note: this is 2 since the datahandler always provides a default subject
81 
82  // test iteration
84 
85  // iterate the list and find all textures
86  int count = 0;
87  for( WDataHandler::SubjectContainerType::const_iterator iter = a->get().begin(); iter != a->get().end(); ++iter )
88  {
89  count++;
90 
91  // the second one needs to be the added subject
92  TS_ASSERT( ( count == 1 ) || ( s == ( *iter ).get() ) );
93  }
94 
95  TS_ASSERT( count == 2 );
96  }
97 
98  /**
99  * Test the remove and clean functionality.
100  */
102  {
103  std::shared_ptr< WDataHandler > dh = WDataHandler::getDataHandler();
104 
106  testInfo.setSubjectID( 2 );
107  testInfo.setLastName( "Testname2" );
108 
109  std::shared_ptr< WSubject > s( new WSubject( testInfo ) );
110  dh->addSubject( s );
111 
112  // now there should be 3 subjects (one from testAddSubjects, the above added one and the default subject)
113  TS_ASSERT_EQUALS( 3, dh->m_subjects.size() ); // note: this is 2 since the datahandler always provides a default subject
114  dh->removeSubject( s );
115  TS_ASSERT_EQUALS( 2, dh->m_subjects.size() ); // note: this is 2 since the datahandler always provides a default subject
116  dh->clear();
117  TS_ASSERT_EQUALS( 0, dh->m_subjects.size() ); // note: this is 2 since the datahandler always provides a default subject
118  }
119 };
120 
121 #endif // WDATAHANDLER_TEST_H
122 
Test important functionality of WDataHandler class.
void testRemoveSubjects()
Test the remove and clean functionality.
void testInstantiation()
Instatiation should throw nothing.
void testSingleton()
Singleton getter should create an instance.
void setUp()
Setup logger and other stuff for each test.
void testAddSubjects()
Test adding and iterating subjects.
Provides the environment for storing and accessing different subjects.
Definition: WDataHandler.h:49
static std::shared_ptr< WDataHandler > getDataHandler()
As WDataHandler is a singleton -> return instance.
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
A structure that holds all relevant information about the subject.
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
Container for all WDataSets belonging to one subject or patient.
Definition: WSubject.h:46