[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 | * MatrixContainerUnitTest.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/MatrixContainer.hpp"
|
---|
| 31 |
|
---|
[feb7df] | 32 | #include "MatrixContainerUnitTest.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( MatrixContainerTest );
|
---|
| 42 |
|
---|
| 43 |
|
---|
| 44 | void MatrixContainerTest::setUp()
|
---|
| 45 | {
|
---|
[1b145f] | 46 | MC = new MatrixContainer();
|
---|
[feb7df] | 47 | };
|
---|
| 48 |
|
---|
| 49 |
|
---|
| 50 | void MatrixContainerTest::tearDown()
|
---|
| 51 | {
|
---|
[1b145f] | 52 | delete MC;
|
---|
| 53 | };
|
---|
| 54 |
|
---|
| 55 | /** UnitTest for operator==()
|
---|
| 56 | */
|
---|
| 57 | void MatrixContainerTest::EqualityTest()
|
---|
| 58 | {
|
---|
| 59 | // compare to self
|
---|
| 60 | CPPUNIT_ASSERT( *MC == *MC );
|
---|
| 61 |
|
---|
| 62 | // create other instance
|
---|
| 63 | MatrixContainer *MC2 = new MatrixContainer();
|
---|
| 64 | CPPUNIT_ASSERT( *MC == *MC2 );
|
---|
| 65 | MC2->MatrixCounter = 2;
|
---|
| 66 | CPPUNIT_ASSERT( *MC != *MC2 );
|
---|
| 67 | delete MC2;
|
---|
[feb7df] | 68 | };
|
---|
| 69 |
|
---|
| 70 | /** UnitTest for serialization
|
---|
| 71 | */
|
---|
| 72 | void MatrixContainerTest::SerializationTest()
|
---|
| 73 | {
|
---|
[2d5fee] | 74 | // write element to stream
|
---|
| 75 | std::stringstream stream;
|
---|
| 76 | boost::archive::text_oarchive oa(stream);
|
---|
| 77 | oa << MC;
|
---|
| 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 | MatrixContainer *MC2;
|
---|
[feb7df] | 85 |
|
---|
[2d5fee] | 86 | ia >> MC2;
|
---|
| 87 |
|
---|
| 88 | CPPUNIT_ASSERT (*MC == *MC2);
|
---|
| 89 |
|
---|
| 90 | delete MC2;
|
---|
[feb7df] | 91 | };
|
---|