/* * 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. */ /* * FactoryUnitTest.cpp * * Created on: Jan 03, 2011 * Author: heber */ // include config.h #ifdef HAVE_CONFIG_H #include #endif #include #include #include #include "CodePatterns/Assert.hpp" #include "FactoryUnitTest.hpp" #include "stubs/CommonStub.hpp" #include "stubs/FactoryStub.hpp" #include #ifdef HAVE_TESTRUNNER #include "UnitTestMain.hpp" #endif /*HAVE_TESTRUNNER*/ /********************************************** Test classes **************************************/ // Registers the fixture into the 'registry' CPPUNIT_TEST_SUITE_REGISTRATION( FactoryTest ); void FactoryTest::setUp() { rndA = FactoryStub::getInstance(). PrototypeTable[FactoryStub::Aclass]->create(); rndB = FactoryStub::getInstance(). PrototypeTable[FactoryStub::Bclass]->create(); rndA_1 = NULL; } void FactoryTest::tearDown() { delete rndA; delete rndB; delete rndA_1; FactoryStub::purgeInstance(); } void FactoryTest::DistributionTest() { // check the injectiveness of enum and string map for (FactoryStub::NameMap::const_iterator iter = FactoryStub::getInstance().names.begin(); iter != FactoryStub::getInstance().names.end(); ++iter) { CPPUNIT_ASSERT_EQUAL( iter->second, FactoryStub::getInstance().getName( FactoryStub::getInstance().getEnum( iter->second ) ) ); } // check distributions in the table CPPUNIT_ASSERT_EQUAL( std::string(typeid(teststubs::Aclass).name()), rndA->name() ); CPPUNIT_ASSERT_EQUAL( std::string(typeid(teststubs::Bclass).name()), rndB->name() ); } void FactoryTest::getProductEnumTest() { rndA_1 = FactoryStub::getInstance().getProduct(FactoryStub::Aclass); CPPUNIT_ASSERT( typeid(*rndA) == typeid(*rndA_1) ); } void FactoryTest::getProductNameTest() { rndA_1 = FactoryStub::getInstance().getProduct(std::string("Aclass")); CPPUNIT_ASSERT( typeid(*rndA) == typeid(*rndA_1) ); } void FactoryTest::getProductTypeTest() { rndA_1 = FactoryStub::getInstance().getProduct( typeid(teststubs::Aclass) ); CPPUNIT_ASSERT( typeid(*rndA) == typeid(*rndA_1) ); }