OpenWalnut 1.2.5
|
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 WDATAHANDLER_TEST_H 00026 #define WDATAHANDLER_TEST_H 00027 00028 #include <boost/shared_ptr.hpp> 00029 00030 #include <cxxtest/TestSuite.h> 00031 00032 #include "../../common/WLogger.h" 00033 #include "../WSubject.h" 00034 #include "../WDataHandler.h" 00035 00036 /** 00037 * Test important functionality of WDataHandler class 00038 */ 00039 class WDataHandlerTest : public CxxTest::TestSuite 00040 { 00041 public: 00042 00043 /** 00044 * Setup logger and other stuff for each test. 00045 */ 00046 void setUp() 00047 { 00048 WLogger::startup(); 00049 } 00050 00051 /** 00052 * Instatiation should throw nothing. 00053 */ 00054 void testInstantiation() 00055 { 00056 TS_ASSERT_THROWS_NOTHING( WDataHandler() ); 00057 } 00058 00059 /** 00060 * Singleton getter should create an instance 00061 */ 00062 void testSingleton() 00063 { 00064 TS_ASSERT_THROWS_NOTHING( WDataHandler::getDataHandler() ); 00065 TS_ASSERT( WDataHandler::getDataHandler().get() ); 00066 } 00067 00068 /** 00069 * Test adding and iterating subjects 00070 */ 00071 void testAddSubjects() 00072 { 00073 boost::shared_ptr< WDataHandler > dh = WDataHandler::getDataHandler(); 00074 00075 WPersonalInformation testInfo( WPersonalInformation::createDummyInformation() ); 00076 testInfo.setSubjectID( 1 ); 00077 testInfo.setLastName( "Testname" ); 00078 00079 WSubject* s = new WSubject( testInfo ); 00080 TS_ASSERT_THROWS_NOTHING( dh->addSubject( boost::shared_ptr< WSubject >( s ) ) ); 00081 TS_ASSERT_EQUALS( 2, dh->m_subjects.size() ); // note: this is 2 since the datahandler always provides a default subject 00082 00083 // test iteration 00084 WDataHandler::SubjectSharedContainerType::ReadTicket a = dh->getSubjects(); 00085 00086 // iterate the list and find all textures 00087 int count = 0; 00088 for( WDataHandler::SubjectContainerType::const_iterator iter = a->get().begin(); iter != a->get().end(); ++iter ) 00089 { 00090 count++; 00091 00092 // the second one needs to be the added subject 00093 TS_ASSERT( ( count == 1 ) || ( s == ( *iter ).get() ) ); 00094 } 00095 00096 TS_ASSERT( count == 2 ); 00097 } 00098 00099 /** 00100 * Test the remove and clean functionality. 00101 */ 00102 void testRemoveSubjects() 00103 { 00104 boost::shared_ptr< WDataHandler > dh = WDataHandler::getDataHandler(); 00105 00106 WPersonalInformation testInfo( WPersonalInformation::createDummyInformation() ); 00107 testInfo.setSubjectID( 2 ); 00108 testInfo.setLastName( "Testname2" ); 00109 00110 boost::shared_ptr< WSubject > s = boost::shared_ptr< WSubject >( new WSubject( testInfo ) ); 00111 dh->addSubject( s ); 00112 00113 // now there should be 3 subjects (one from testAddSubjects, the above added one and the default subject) 00114 TS_ASSERT_EQUALS( 3, dh->m_subjects.size() ); // note: this is 2 since the datahandler always provides a default subject 00115 dh->removeSubject( s ); 00116 TS_ASSERT_EQUALS( 2, dh->m_subjects.size() ); // note: this is 2 since the datahandler always provides a default subject 00117 dh->clear(); 00118 TS_ASSERT_EQUALS( 0, dh->m_subjects.size() ); // note: this is 2 since the datahandler always provides a default subject 00119 } 00120 }; 00121 00122 #endif // WDATAHANDLER_TEST_H 00123