/* * Project: MoleCuilder * Description: creates and alters molecular systems * Copyright (C) 2010-2012 University of Bonn. All rights reserved. * Please see the LICENSE file or "Copyright notice" in builder.cpp for details. */ /* * StringParameterUnitTest.cpp * * Created on: Sep 30, 2011 * Author: heber */ // include config.h #ifdef HAVE_CONFIG_H #include #endif #include "StringParameterUnitTest.hpp" #include #include #include #include "Parser/Parameters/StringParameter.hpp" #include "CodePatterns/Assert.hpp" #ifdef HAVE_TESTRUNNER #include "UnitTestMain.hpp" #endif /*HAVE_TESTRUNNER*/ // Registers the fixture into the 'registry' CPPUNIT_TEST_SUITE_REGISTRATION( StringParameterTest ); void StringParameterTest::setUp() { // failing asserts should be thrown ASSERT_DO(Assert::Throw); } void StringParameterTest::tearDown() { } /************************************ tests ***********************************/ /** Unit test for comparator. * */ void StringParameterTest::comparatorTest() { // create instance StringParameter test("stringParam"); StringParameter samenamedsamevalued("stringParam"); StringParameter samenamedelsevalued("stringParam"); StringParameter elsenamedsamevalued("string2Param"); StringParameter elsenamedelsevalued("string2Param"); test.set(std::string("1")); samenamedsamevalued.set(std::string("1")); samenamedelsevalued.set(std::string("2")); elsenamedsamevalued.set(std::string("1")); elsenamedelsevalued.set(std::string("2")); CPPUNIT_ASSERT( test == samenamedsamevalued ); CPPUNIT_ASSERT( test != samenamedelsevalued ); CPPUNIT_ASSERT( test != elsenamedsamevalued ); CPPUNIT_ASSERT( test != elsenamedelsevalued ); } /** Unit test for clone. * */ void StringParameterTest::cloneTest() { // create instance StringParameter test("intParam"); // check that we throw because of unset parameter #ifndef NDEBUG std::cout << "The following Assert failures are intended and do not indicate a failure of the test." << std::endl; CPPUNIT_ASSERT_THROW(test.clone(), Assert::AssertionFailure); #endif // set parameter test.set(std::string("1")); // is returned as Parameter but we can compare only in true class as // Parameter may also be a DiscreteParameter where comparison is nonsense StringParameter *instance = dynamic_cast< StringParameter *> (test.clone()); // different places in memory CPPUNIT_ASSERT( &test != instance); // but same contents CPPUNIT_ASSERT( test == *instance); }