| 1 | /*
 | 
|---|
| 2 |  * Project: MoleCuilder
 | 
|---|
| 3 |  * Description: creates and alters molecular systems
 | 
|---|
| 4 |  * Copyright (C)  2010 University of Bonn. All rights reserved.
 | 
|---|
| 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 | 
 | 
|---|
| 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 | 
 | 
|---|
| 30 | #include "Fragmentation/KeySetsContainer.hpp"
 | 
|---|
| 31 | 
 | 
|---|
| 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 | {
 | 
|---|
| 46 |   Keys = new KeySetsContainer();
 | 
|---|
| 47 | };
 | 
|---|
| 48 | 
 | 
|---|
| 49 | 
 | 
|---|
| 50 | void KeySetsContainerTest::tearDown()
 | 
|---|
| 51 | {
 | 
|---|
| 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;
 | 
|---|
| 68 | };
 | 
|---|
| 69 | 
 | 
|---|
| 70 | /** UnitTest for serialization
 | 
|---|
| 71 |  */
 | 
|---|
| 72 | void KeySetsContainerTest::SerializationTest()
 | 
|---|
| 73 | {
 | 
|---|
| 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;
 | 
|---|
| 85 | 
 | 
|---|
| 86 |   ia >> Keys2;
 | 
|---|
| 87 | 
 | 
|---|
| 88 |   CPPUNIT_ASSERT (*Keys == *Keys2);
 | 
|---|
| 89 | 
 | 
|---|
| 90 |   delete Keys2;
 | 
|---|
| 91 | };
 | 
|---|