| [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 | * FragmentJobUnitTest.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 "FragmentJobUnitTest.hpp" | 
|---|
|  | 29 |  | 
|---|
|  | 30 | #include "FragmentJob.hpp" | 
|---|
| [7b22e9] | 31 | #include "FragmentResult.hpp" | 
|---|
|  | 32 | #include "JobId.hpp" | 
|---|
| [57876b] | 33 |  | 
|---|
|  | 34 | #include "CodePatterns/Assert.hpp" | 
|---|
|  | 35 |  | 
|---|
|  | 36 | #ifdef HAVE_TESTRUNNER | 
|---|
|  | 37 | #include "UnitTestMain.hpp" | 
|---|
|  | 38 | #endif /*HAVE_TESTRUNNER*/ | 
|---|
|  | 39 |  | 
|---|
|  | 40 | /********************************************** Test classes **************************************/ | 
|---|
|  | 41 |  | 
|---|
|  | 42 | // Registers the fixture into the 'registry' | 
|---|
|  | 43 | CPPUNIT_TEST_SUITE_REGISTRATION( FragmentJobTest ); | 
|---|
|  | 44 |  | 
|---|
|  | 45 |  | 
|---|
|  | 46 | void FragmentJobTest::setUp() | 
|---|
|  | 47 | { | 
|---|
|  | 48 | // Throw assertions | 
|---|
|  | 49 | ASSERT_DO(Assert::Throw); | 
|---|
|  | 50 |  | 
|---|
|  | 51 | command = std::string("do something"); | 
|---|
|  | 52 | } | 
|---|
|  | 53 |  | 
|---|
|  | 54 |  | 
|---|
|  | 55 | void FragmentJobTest::tearDown() | 
|---|
|  | 56 | { | 
|---|
|  | 57 | } | 
|---|
|  | 58 |  | 
|---|
|  | 59 | /** UnitTest for operator== | 
|---|
|  | 60 | */ | 
|---|
|  | 61 | void FragmentJobTest::equalityTest() | 
|---|
|  | 62 | { | 
|---|
|  | 63 | FragmentJob testJob(command, 1); | 
|---|
|  | 64 | FragmentJob sameIdJob(command, 1); | 
|---|
|  | 65 | FragmentJob otherIdJob(command, 2); | 
|---|
|  | 66 | FragmentJob copiedJob(testJob); | 
|---|
|  | 67 | FragmentJob copiedchangedJob(testJob); | 
|---|
|  | 68 | copiedchangedJob.setId(3); | 
|---|
|  | 69 |  | 
|---|
|  | 70 | CPPUNIT_ASSERT( testJob == sameIdJob ); | 
|---|
|  | 71 | CPPUNIT_ASSERT( testJob != otherIdJob ); | 
|---|
|  | 72 | CPPUNIT_ASSERT( testJob == copiedJob ); | 
|---|
|  | 73 | CPPUNIT_ASSERT( testJob != copiedchangedJob ); | 
|---|
|  | 74 | } | 
|---|
|  | 75 |  | 
|---|
| [7b22e9] | 76 | /** UnitTest for Work() | 
|---|
|  | 77 | */ | 
|---|
|  | 78 | void FragmentJobTest::WorkTest() | 
|---|
|  | 79 | { | 
|---|
|  | 80 | FragmentJob testJob(command, 1); | 
|---|
|  | 81 | FragmentJob othertestJob(command, 2); | 
|---|
|  | 82 |  | 
|---|
|  | 83 | FragmentResult testResult(testJob.Work()); | 
|---|
|  | 84 | FragmentResult othertestResult(othertestJob.Work()); | 
|---|
|  | 85 |  | 
|---|
|  | 86 | CPPUNIT_ASSERT_EQUAL( (JobId_t)1, testResult.getId() ); | 
|---|
|  | 87 | CPPUNIT_ASSERT_EQUAL( (JobId_t)2, othertestResult.getId() ); | 
|---|
|  | 88 | } | 
|---|
|  | 89 |  | 
|---|
| [57876b] | 90 | /** UnitTest for serialization | 
|---|
|  | 91 | */ | 
|---|
|  | 92 | void FragmentJobTest::serializationTest() | 
|---|
|  | 93 | { | 
|---|
|  | 94 | FragmentJob testJob(command, 1); | 
|---|
|  | 95 | // write element to stream | 
|---|
|  | 96 | std::stringstream stream; | 
|---|
|  | 97 | boost::archive::text_oarchive oa(stream); | 
|---|
|  | 98 | oa << testJob; | 
|---|
|  | 99 |  | 
|---|
|  | 100 | //std::cout << "Contents of archive is " << stream.str() << std::endl; | 
|---|
|  | 101 |  | 
|---|
|  | 102 | // create and open an archive for input | 
|---|
|  | 103 | boost::archive::text_iarchive ia(stream); | 
|---|
|  | 104 | // read class state from archive | 
|---|
|  | 105 | FragmentJob otherJob; | 
|---|
|  | 106 |  | 
|---|
|  | 107 | ia >> otherJob; | 
|---|
|  | 108 |  | 
|---|
|  | 109 | CPPUNIT_ASSERT (testJob == otherJob); | 
|---|
|  | 110 | } | 
|---|
|  | 111 |  | 
|---|