/* * Project: MoleCuilder * Description: creates and alters molecular systems * Copyright (C) 2010 University of Bonn. All rights reserved. * Please see the LICENSE file or "Copyright notice" in builder.cpp for details. */ /* * SystemCommandJobUnitTest.cpp * * Created on: Oct 23, 2011 * Author: heber */ // include config.h #ifdef HAVE_CONFIG_H #include #endif #include #include #include // include headers that implement a archive in simple text format #include #include #include "SystemCommandJobUnitTest.hpp" #include "Jobs/SystemCommandJob.hpp" #include "Results/FragmentResult.hpp" #include "JobId.hpp" #include "CodePatterns/Assert.hpp" #include "CodePatterns/Log.hpp" #ifdef HAVE_TESTRUNNER #include "UnitTestMain.hpp" #endif /*HAVE_TESTRUNNER*/ /********************************************** Test classes **************************************/ const std::string resultstring="nothing"; // Registers the fixture into the 'registry' CPPUNIT_TEST_SUITE_REGISTRATION( SystemCommandJobTest ); void SystemCommandJobTest::setUp() { // Throw assertions ASSERT_DO(Assert::Throw); setVerbosity(3); command = std::string("/bin/true"); outputfile = std::string("do something"); } void SystemCommandJobTest::tearDown() { } /** UnitTest for operator== */ void SystemCommandJobTest::equalityTest() { FragmentJob::ptr testJob( new SystemCommandJob(command, outputfile, 1) ); FragmentJob::ptr sameIdJob( new SystemCommandJob(command, outputfile, 1) ); FragmentJob::ptr otherIdJob( new SystemCommandJob(command, outputfile, 2) ); CPPUNIT_ASSERT( *testJob == *sameIdJob ); CPPUNIT_ASSERT( *testJob != *otherIdJob ); } /** UnitTest for Work() */ void SystemCommandJobTest::WorkTest() { FragmentJob::ptr testJob( new SystemCommandJob(command, outputfile, 1) ); FragmentJob::ptr othertestJob( new SystemCommandJob(command, outputfile, 2) ); FragmentResult::ptr testResult(testJob->Work()); FragmentResult::ptr othertestResult(othertestJob->Work()); CPPUNIT_ASSERT_EQUAL( (JobId_t)1, testResult->getId() ); CPPUNIT_ASSERT_EQUAL( (JobId_t)2, othertestResult->getId() ); } /** UnitTest for serialization */ void SystemCommandJobTest::serializationTest() { FragmentJob::ptr testJob( new SystemCommandJob(command, outputfile, 1) ); // write element to stream std::stringstream stream; boost::archive::text_oarchive oa(stream); oa << testJob; //std::cout << "Contents of archive is " << stream.str() << std::endl; // create and open an archive for input boost::archive::text_iarchive ia(stream); // read class state from archive FragmentJob::ptr otherJob; ia >> otherJob; const FragmentJob * const testJobptr = testJob.get(); const FragmentJob * const otherJobptr = otherJob.get(); const SystemCommandJob * const testSystemJobptr = dynamic_cast(testJobptr); const SystemCommandJob * const otherSystemJobptr = dynamic_cast(otherJobptr); CPPUNIT_ASSERT( testSystemJobptr != NULL ); CPPUNIT_ASSERT( otherSystemJobptr != NULL ); CPPUNIT_ASSERT( *testSystemJobptr == *otherSystemJobptr); // short is the following CPPUNIT_ASSERT( *dynamic_cast(testJob.get()) == *dynamic_cast(otherJob.get()) ); } /** UnitTest for extractString() */ void SystemCommandJobTest::extractStringTest() { SystemCommandJob testJob(command, outputfile, 1); // extract and check that it just returns the string FragmentResult::ptr result = testJob.extractResult(resultstring); CPPUNIT_ASSERT( result->result == resultstring ); }