/* * Project: MoleCuilder * Description: creates and alters molecular systems * Copyright (C) 2012 University of Bonn. All rights reserved. * Copyright (C) 2013 Frederik Heber. All rights reserved. * * * This file is part of MoleCuilder. * * MoleCuilder is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 2 of the License, or * (at your option) any later version. * * MoleCuilder is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with MoleCuilder. If not, see . */ /* * AtomObserverUnitTest.cpp * * Created on: Dec 19, 2011 * Author: heber */ // include config.h #ifdef HAVE_CONFIG_H #include #endif #include "AtomObserverUnitTest.hpp" #include #include #include #include #include "CodePatterns/Log.hpp" #include "World.hpp" #include "Atom/atom.hpp" #include "Atom/AtomObserver.hpp" #include "Element/element.hpp" #include "Element/periodentafel.hpp" #include "stubs/ObserverStub.hpp" #ifdef HAVE_TESTRUNNER #include "UnitTestMain.hpp" #endif /*HAVE_TESTRUNNER*/ /********************************************** Test classes **************************************/ // Registers the fixture into the 'registry' CPPUNIT_TEST_SUITE_REGISTRATION( AtomObserverTest ); // set up and tear down void AtomObserverTest::setUp(){ World::getInstance(); AtomObserver::getInstance(); setVerbosity(3); // observer checks that we don't receive general updates ... observer = new UpdateCountObserver; AtomObserver::getInstance().signOn(observer); // but only specific notifications in others observers for (int i=0;igetId(); } } void AtomObserverTest::tearDown() { AtomObserver::getInstance().signOff(observer); for (int i=0;iupdates ); for (int i=0;iwasNotified ); } } /** Unit test on whether moving atoms informs relay and onward. * */ void AtomObserverTest::AtomMoveTest() { // move an atom atoms[0]->setPosition(Vector(1.,0.,0.)); // check for update for (int i=0;iwasNotified ); } CPPUNIT_ASSERT_EQUAL( (int)0, observer->updates ); } /** Unit test on whether changing atom's element informs relay and onward. * */ void AtomObserverTest::AtomElementTest() { CPPUNIT_ASSERT( atoms[0]->getType()->getAtomicNumber() != 2 ); atoms[0]->setType(2); // check for update for (int i=0;iwasNotified ); } CPPUNIT_ASSERT_EQUAL( (int)0, observer->updates ); }