[57876b] | 1 | /*
|
---|
| 2 | * Project: MoleCuilder
|
---|
| 3 | * Description: creates and alters molecular systems
|
---|
| 4 | * Copyright (C) 2011 University of Bonn. All rights reserved.
|
---|
| 5 | * Please see the LICENSE file or "Copyright notice" in builder.cpp for details.
|
---|
| 6 | */
|
---|
| 7 |
|
---|
| 8 | /*
|
---|
| 9 | * FragmentResultUnitTest.cpp
|
---|
| 10 | *
|
---|
| 11 | * Created on: Oct 23, 2011
|
---|
| 12 | * Author: heber
|
---|
| 13 | */
|
---|
| 14 |
|
---|
| 15 | // include config.h
|
---|
| 16 | #ifdef HAVE_CONFIG_H
|
---|
| 17 | #include <config.h>
|
---|
| 18 | #endif
|
---|
| 19 |
|
---|
| 20 | #include <cppunit/CompilerOutputter.h>
|
---|
| 21 | #include <cppunit/extensions/TestFactoryRegistry.h>
|
---|
| 22 | #include <cppunit/ui/text/TestRunner.h>
|
---|
| 23 |
|
---|
| 24 | // include headers that implement a archive in simple text format
|
---|
| 25 | #include <boost/archive/text_oarchive.hpp>
|
---|
| 26 | #include <boost/archive/text_iarchive.hpp>
|
---|
| 27 |
|
---|
| 28 | #include "FragmentResultUnitTest.hpp"
|
---|
| 29 |
|
---|
| 30 | #include "FragmentResult.hpp"
|
---|
| 31 |
|
---|
| 32 | #include "CodePatterns/Assert.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( FragmentResultTest );
|
---|
| 42 |
|
---|
| 43 |
|
---|
| 44 | void FragmentResultTest::setUp()
|
---|
| 45 | {
|
---|
| 46 | // Throw assertions
|
---|
| 47 | ASSERT_DO(Assert::Throw);
|
---|
| 48 | }
|
---|
| 49 |
|
---|
| 50 |
|
---|
| 51 | void FragmentResultTest::tearDown()
|
---|
| 52 | {
|
---|
| 53 | }
|
---|
| 54 |
|
---|
| 55 | /** UnitTest for operator==
|
---|
| 56 | */
|
---|
| 57 | void FragmentResultTest::equalityTest()
|
---|
| 58 | {
|
---|
| 59 | FragmentResult testResult(1);
|
---|
| 60 | FragmentResult sameIdResult(1);
|
---|
| 61 | FragmentResult otherIdResult(2);
|
---|
| 62 | FragmentResult copiedResult(testResult);
|
---|
| 63 | FragmentResult copiedchangedResult(testResult);
|
---|
| 64 | copiedchangedResult.setId(3);
|
---|
| 65 |
|
---|
| 66 | CPPUNIT_ASSERT( testResult == sameIdResult );
|
---|
| 67 | CPPUNIT_ASSERT( testResult != otherIdResult );
|
---|
| 68 | CPPUNIT_ASSERT( testResult == copiedResult );
|
---|
| 69 | CPPUNIT_ASSERT( testResult != copiedchangedResult );
|
---|
| 70 | }
|
---|
| 71 |
|
---|
| 72 | /** UnitTest for serialization
|
---|
| 73 | */
|
---|
| 74 | void FragmentResultTest::serializationTest()
|
---|
| 75 | {
|
---|
| 76 | FragmentResult testResult(1);
|
---|
| 77 | // write element to stream
|
---|
| 78 | std::stringstream stream;
|
---|
| 79 | boost::archive::text_oarchive oa(stream);
|
---|
| 80 | oa << testResult;
|
---|
| 81 |
|
---|
| 82 | //std::cout << "Contents of archive is " << stream.str() << std::endl;
|
---|
| 83 |
|
---|
| 84 | // create and open an archive for input
|
---|
| 85 | boost::archive::text_iarchive ia(stream);
|
---|
| 86 | // read class state from archive
|
---|
| 87 | FragmentResult otherResult(-1);
|
---|
| 88 |
|
---|
| 89 | ia >> otherResult;
|
---|
| 90 |
|
---|
| 91 | CPPUNIT_ASSERT (testResult == otherResult);
|
---|
| 92 | }
|
---|
| 93 |
|
---|