| [feb7df] | 1 | /* | 
|---|
|  | 2 | * Project: MoleCuilder | 
|---|
|  | 3 | * Description: creates and alters molecular systems | 
|---|
| [0aa122] | 4 | * Copyright (C)  2010-2012 University of Bonn. All rights reserved. | 
|---|
| [feb7df] | 5 | * Please see the LICENSE file or "Copyright notice" in builder.cpp for details. | 
|---|
|  | 6 | */ | 
|---|
|  | 7 |  | 
|---|
|  | 8 | /* | 
|---|
|  | 9 | * KeySetsContainerUnitTest.cpp | 
|---|
|  | 10 | * | 
|---|
|  | 11 | *  Created on: Sep 16, 2011 | 
|---|
|  | 12 | *      Author: heber | 
|---|
|  | 13 | */ | 
|---|
|  | 14 |  | 
|---|
|  | 15 | // include config.h | 
|---|
|  | 16 | #ifdef HAVE_CONFIG_H | 
|---|
|  | 17 | #include <config.h> | 
|---|
|  | 18 | #endif | 
|---|
|  | 19 |  | 
|---|
|  | 20 | using namespace std; | 
|---|
|  | 21 |  | 
|---|
|  | 22 | #include <cppunit/CompilerOutputter.h> | 
|---|
|  | 23 | #include <cppunit/extensions/TestFactoryRegistry.h> | 
|---|
|  | 24 | #include <cppunit/ui/text/TestRunner.h> | 
|---|
|  | 25 |  | 
|---|
| [2d5fee] | 26 | // include headers that implement a archive in simple text format | 
|---|
|  | 27 | #include <boost/archive/text_oarchive.hpp> | 
|---|
|  | 28 | #include <boost/archive/text_iarchive.hpp> | 
|---|
|  | 29 |  | 
|---|
| [1b145f] | 30 | #include "Fragmentation/KeySetsContainer.hpp" | 
|---|
|  | 31 |  | 
|---|
| [feb7df] | 32 | #include "KeySetsContainerUnitTest.hpp" | 
|---|
|  | 33 |  | 
|---|
|  | 34 | #ifdef HAVE_TESTRUNNER | 
|---|
|  | 35 | #include "UnitTestMain.hpp" | 
|---|
|  | 36 | #endif /*HAVE_TESTRUNNER*/ | 
|---|
|  | 37 |  | 
|---|
|  | 38 | /********************************************** Test classes **************************************/ | 
|---|
|  | 39 |  | 
|---|
|  | 40 | // Registers the fixture into the 'registry' | 
|---|
|  | 41 | CPPUNIT_TEST_SUITE_REGISTRATION( KeySetsContainerTest ); | 
|---|
|  | 42 |  | 
|---|
|  | 43 |  | 
|---|
|  | 44 | void KeySetsContainerTest::setUp() | 
|---|
|  | 45 | { | 
|---|
| [1b145f] | 46 | Keys = new KeySetsContainer(); | 
|---|
| [feb7df] | 47 | }; | 
|---|
|  | 48 |  | 
|---|
|  | 49 |  | 
|---|
|  | 50 | void KeySetsContainerTest::tearDown() | 
|---|
|  | 51 | { | 
|---|
| [1b145f] | 52 | delete Keys; | 
|---|
|  | 53 | }; | 
|---|
|  | 54 |  | 
|---|
|  | 55 | /** UnitTest for operator==() | 
|---|
|  | 56 | */ | 
|---|
|  | 57 | void KeySetsContainerTest::EqualityTest() | 
|---|
|  | 58 | { | 
|---|
|  | 59 | // compare to self | 
|---|
|  | 60 | CPPUNIT_ASSERT( *Keys == *Keys ); | 
|---|
|  | 61 |  | 
|---|
|  | 62 | // create other instance | 
|---|
|  | 63 | KeySetsContainer *Keys2 = new KeySetsContainer(); | 
|---|
|  | 64 | CPPUNIT_ASSERT( *Keys == *Keys2 ); | 
|---|
|  | 65 | Keys2->Order = 2; | 
|---|
|  | 66 | CPPUNIT_ASSERT( *Keys != *Keys2 ); | 
|---|
|  | 67 | delete Keys2; | 
|---|
| [feb7df] | 68 | }; | 
|---|
|  | 69 |  | 
|---|
|  | 70 | /** UnitTest for serialization | 
|---|
|  | 71 | */ | 
|---|
|  | 72 | void KeySetsContainerTest::SerializationTest() | 
|---|
|  | 73 | { | 
|---|
| [2d5fee] | 74 | // write element to stream | 
|---|
|  | 75 | std::stringstream stream; | 
|---|
|  | 76 | boost::archive::text_oarchive oa(stream); | 
|---|
|  | 77 | oa << Keys; | 
|---|
|  | 78 |  | 
|---|
|  | 79 | std::cout << "Contents of archive is " << stream.str() << std::endl; | 
|---|
|  | 80 |  | 
|---|
|  | 81 | // create and open an archive for input | 
|---|
|  | 82 | boost::archive::text_iarchive ia(stream); | 
|---|
|  | 83 | // read class state from archive | 
|---|
|  | 84 | KeySetsContainer *Keys2; | 
|---|
| [feb7df] | 85 |  | 
|---|
| [2d5fee] | 86 | ia >> Keys2; | 
|---|
|  | 87 |  | 
|---|
|  | 88 | CPPUNIT_ASSERT (*Keys == *Keys2); | 
|---|
|  | 89 |  | 
|---|
|  | 90 | delete Keys2; | 
|---|
| [feb7df] | 91 | }; | 
|---|