[d2596b] | 1 | /*
|
---|
| 2 | * Project: MoleCuilder
|
---|
| 3 | * Description: creates and alters molecular systems
|
---|
| 4 | * Copyright (C) 2010-2012 University of Bonn. All rights reserved.
|
---|
[94d5ac6] | 5 | *
|
---|
| 6 | *
|
---|
| 7 | * This file is part of MoleCuilder.
|
---|
| 8 | *
|
---|
| 9 | * MoleCuilder is free software: you can redistribute it and/or modify
|
---|
| 10 | * it under the terms of the GNU General Public License as published by
|
---|
| 11 | * the Free Software Foundation, either version 2 of the License, or
|
---|
| 12 | * (at your option) any later version.
|
---|
| 13 | *
|
---|
| 14 | * MoleCuilder is distributed in the hope that it will be useful,
|
---|
| 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 17 | * GNU General Public License for more details.
|
---|
| 18 | *
|
---|
| 19 | * You should have received a copy of the GNU General Public License
|
---|
| 20 | * along with MoleCuilder. If not, see <http://www.gnu.org/licenses/>.
|
---|
[d2596b] | 21 | */
|
---|
| 22 |
|
---|
| 23 | /*
|
---|
| 24 | * ParserXmlUnitTest.cpp
|
---|
| 25 | *
|
---|
| 26 | * Created on: Mar 24, 2012
|
---|
| 27 | * Author: heber
|
---|
| 28 | */
|
---|
| 29 |
|
---|
| 30 | // include config.h
|
---|
| 31 | #ifdef HAVE_CONFIG_H
|
---|
| 32 | #include <config.h>
|
---|
| 33 | #endif
|
---|
| 34 |
|
---|
| 35 | #include "ParserXmlUnitTest.hpp"
|
---|
| 36 |
|
---|
| 37 | #include <cppunit/CompilerOutputter.h>
|
---|
| 38 | #include <cppunit/extensions/TestFactoryRegistry.h>
|
---|
| 39 | #include <cppunit/ui/text/TestRunner.h>
|
---|
| 40 |
|
---|
| 41 | #include "Atom/atom.hpp"
|
---|
[006e1e] | 42 | #include "Atom/AtomObserver.hpp"
|
---|
[d2596b] | 43 | #include "CodePatterns/Log.hpp"
|
---|
| 44 | #include "Descriptors/AtomTypeDescriptor.hpp"
|
---|
[006e1e] | 45 | #include "Element/element.hpp"
|
---|
| 46 | #include "Element/periodentafel.hpp"
|
---|
[d2596b] | 47 | #include "Parser/ChangeTracker.hpp"
|
---|
| 48 | #include "Parser/XmlParser.hpp"
|
---|
[006e1e] | 49 | #include "World.hpp"
|
---|
[d2596b] | 50 |
|
---|
| 51 | #ifdef HAVE_TESTRUNNER
|
---|
| 52 | #include "UnitTestMain.hpp"
|
---|
| 53 | #endif /*HAVE_TESTRUNNER*/
|
---|
| 54 |
|
---|
| 55 | using namespace std;
|
---|
| 56 |
|
---|
| 57 | // Registers the fixture into the 'registry'
|
---|
| 58 | CPPUNIT_TEST_SUITE_REGISTRATION( ParserXmlUnitTest );
|
---|
| 59 |
|
---|
| 60 | static string waterXml = "\
|
---|
| 61 | <?xml version=\"1.0\" encoding=\"UTF-8\"?>\n\
|
---|
| 62 | <!DOCTYPE scafacos_test SYSTEM 'scafacos_test.dtd'>\n\
|
---|
| 63 | \t<scafacos_test name=\"cloud-wall\" description=\"A 3D-periodic system of two walls charges and a random cloud of charges.\" reference_method=\"ewald\" error_potential=\"1.0e-13\" error_field=\"1.0e-13\">\n\
|
---|
| 64 | \t\t<configuration offset=\"0 0 0\" box_a=\"10 0 0\" box_b=\"0 10 0\" box_c=\"0 0 10\" periodicity=\"1 1 1\" epsilon=\"metallic\">\n\
|
---|
| 65 | \t\t\t<particle position=\"0 0 4.5\" q=\"1\" potential=\"1.318858869367693\" field=\"0.27973426575304 -0.1382533033408908 5.200985873286221\"/>\n\
|
---|
| 66 | \t\t\t<particle position=\"0 0 5.5\" q=\"1\" potential=\"1.318858869367693\" field=\"0.27973426575304 -0.1382533033408908 5.200985873286221\"/>\n\
|
---|
| 67 | \t\t\t<particle position=\"0 0 6.5\" q=\"1\" potential=\"1.318858869367693\" field=\"0.27973426575304 -0.1382533033408908 5.200985873286221\"/>\n\
|
---|
| 68 | \t\t</configuration>\n\
|
---|
| 69 | \t</scafacos_test>\n";
|
---|
| 70 | static string waterMultiXml = "\n";
|
---|
| 71 |
|
---|
| 72 | void ParserXmlUnitTest::setUp() {
|
---|
| 73 | World::getInstance();
|
---|
| 74 |
|
---|
| 75 | parser = new FormatParser<xml>();
|
---|
| 76 |
|
---|
| 77 | setVerbosity(2);
|
---|
| 78 |
|
---|
| 79 | // we need hydrogens and oxygens in the following tests
|
---|
| 80 | CPPUNIT_ASSERT(World::getInstance().getPeriode()->FindElement(1) != NULL);
|
---|
| 81 | CPPUNIT_ASSERT(World::getInstance().getPeriode()->FindElement(8) != NULL);
|
---|
| 82 | }
|
---|
| 83 |
|
---|
| 84 | void ParserXmlUnitTest::tearDown()
|
---|
| 85 | {
|
---|
| 86 | delete parser;
|
---|
| 87 | ChangeTracker::purgeInstance();
|
---|
[006e1e] | 88 | AtomObserver::purgeInstance();
|
---|
[d2596b] | 89 | World::purgeInstance();
|
---|
| 90 | }
|
---|
| 91 |
|
---|
| 92 | /************************************ tests ***********************************/
|
---|
| 93 |
|
---|
| 94 | void ParserXmlUnitTest::readwriteXmlTest() {
|
---|
| 95 | cout << "Testing the XML parser." << endl;
|
---|
| 96 | stringstream input;
|
---|
| 97 | input << waterXml;
|
---|
| 98 | parser->load(&input);
|
---|
| 99 | input.clear();
|
---|
| 100 |
|
---|
| 101 | CPPUNIT_ASSERT_EQUAL(3, World::getInstance().numAtoms());
|
---|
| 102 |
|
---|
| 103 | // store and parse in again
|
---|
| 104 | {
|
---|
| 105 | // std::string first;
|
---|
| 106 | // std::string second;
|
---|
| 107 | std::stringstream output;
|
---|
| 108 | std::vector<atom *> atoms = World::getInstance().getAllAtoms();
|
---|
| 109 | parser->save(&output, atoms);
|
---|
| 110 | std::cout << output.str();
|
---|
| 111 |
|
---|
| 112 | {
|
---|
| 113 | delete parser;
|
---|
| 114 | parser = new FormatParser<xml>();
|
---|
| 115 | std::stringstream input(waterXml);
|
---|
| 116 | parser->load(&input);
|
---|
| 117 | }
|
---|
| 118 |
|
---|
| 119 | FormatParser<xml> *parser_control = new FormatParser<xml>();
|
---|
| 120 | parser_control->load(&output);
|
---|
| 121 | CPPUNIT_ASSERT( parser->data == parser_control->data );
|
---|
| 122 | delete parser_control;
|
---|
| 123 | }
|
---|
| 124 | }
|
---|