/* * 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. */ /* * ParserXmlUnitTest.cpp * * Created on: Mar 24, 2012 * Author: heber */ // include config.h #ifdef HAVE_CONFIG_H #include #endif #include "ParserXmlUnitTest.hpp" #include #include #include #include "Atom/atom.hpp" #include "Atom/AtomObserver.hpp" #include "CodePatterns/Log.hpp" #include "Descriptors/AtomTypeDescriptor.hpp" #include "Element/element.hpp" #include "Element/periodentafel.hpp" #include "Parser/ChangeTracker.hpp" #include "Parser/XmlParser.hpp" #include "World.hpp" #ifdef HAVE_TESTRUNNER #include "UnitTestMain.hpp" #endif /*HAVE_TESTRUNNER*/ using namespace std; // Registers the fixture into the 'registry' CPPUNIT_TEST_SUITE_REGISTRATION( ParserXmlUnitTest ); static string waterXml = "\ \n\ \n\ \t\n\ \t\t\n\ \t\t\t\n\ \t\t\t\n\ \t\t\t\n\ \t\t\n\ \t\n"; static string waterMultiXml = "\n"; void ParserXmlUnitTest::setUp() { World::getInstance(); parser = new FormatParser(); setVerbosity(2); // we need hydrogens and oxygens in the following tests CPPUNIT_ASSERT(World::getInstance().getPeriode()->FindElement(1) != NULL); CPPUNIT_ASSERT(World::getInstance().getPeriode()->FindElement(8) != NULL); } void ParserXmlUnitTest::tearDown() { delete parser; ChangeTracker::purgeInstance(); AtomObserver::purgeInstance(); World::purgeInstance(); } /************************************ tests ***********************************/ void ParserXmlUnitTest::readwriteXmlTest() { cout << "Testing the XML parser." << endl; stringstream input; input << waterXml; parser->load(&input); input.clear(); CPPUNIT_ASSERT_EQUAL(3, World::getInstance().numAtoms()); // store and parse in again { // std::string first; // std::string second; std::stringstream output; std::vector atoms = World::getInstance().getAllAtoms(); parser->save(&output, atoms); std::cout << output.str(); { delete parser; parser = new FormatParser(); std::stringstream input(waterXml); parser->load(&input); } FormatParser *parser_control = new FormatParser(); parser_control->load(&output); CPPUNIT_ASSERT( parser->data == parser_control->data ); delete parser_control; } }