1 | /*
|
---|
2 | * ParserUnitTest.cpp
|
---|
3 | *
|
---|
4 | * Created on: Mar 3, 2010
|
---|
5 | * Author: metzler
|
---|
6 | */
|
---|
7 |
|
---|
8 | #include "ParserUnitTest.hpp"
|
---|
9 |
|
---|
10 | #include <cppunit/CompilerOutputter.h>
|
---|
11 | #include <cppunit/extensions/TestFactoryRegistry.h>
|
---|
12 | #include <cppunit/ui/text/TestRunner.h>
|
---|
13 |
|
---|
14 | #include "Parser/XyzParser.hpp"
|
---|
15 | #include "Parser/TremoloParser.hpp"
|
---|
16 | #include "World.hpp"
|
---|
17 | #include "atom.hpp"
|
---|
18 | #include "element.hpp"
|
---|
19 | #include "periodentafel.hpp"
|
---|
20 | #include "Descriptors/AtomTypeDescriptor.hpp"
|
---|
21 |
|
---|
22 | #ifdef HAVE_TESTRUNNER
|
---|
23 | #include "UnitTestMain.hpp"
|
---|
24 | #endif /*HAVE_TESTRUNNER*/
|
---|
25 |
|
---|
26 | using namespace std;
|
---|
27 |
|
---|
28 | // Registers the fixture into the 'registry'
|
---|
29 | CPPUNIT_TEST_SUITE_REGISTRATION( ParserUnitTest );
|
---|
30 |
|
---|
31 |
|
---|
32 | void ParserUnitTest::setUp() {
|
---|
33 | element* oxygen = new element();
|
---|
34 | oxygen->symbol[0] = 'O';
|
---|
35 | oxygen->Z = 8;
|
---|
36 | World::getInstance().getPeriode()->AddElement(oxygen);
|
---|
37 |
|
---|
38 | element* hydrogen = new element();
|
---|
39 | hydrogen->symbol[0] = 'H';
|
---|
40 | hydrogen->Z = 1;
|
---|
41 | World::getInstance().getPeriode()->AddElement(hydrogen);
|
---|
42 | }
|
---|
43 |
|
---|
44 | void ParserUnitTest::tearDown() {
|
---|
45 | World::purgeInstance();
|
---|
46 | }
|
---|
47 |
|
---|
48 | /************************************ tests ***********************************/
|
---|
49 |
|
---|
50 | void ParserUnitTest::rewriteAnXyzTest() {
|
---|
51 | cout << "Testing the XYZ parser." << endl;
|
---|
52 | XyzParser* testParser = new XyzParser();
|
---|
53 | string waterXyz = "3\nH2O: water molecule\nO\t0.000000\t0.000000\t0.000000\nH\t0.758602\t0.000000\t0.504284\nH\t0.758602\t0.000000\t-0.504284\n";
|
---|
54 | stringstream input;
|
---|
55 | input << waterXyz;
|
---|
56 | testParser->load(&input);
|
---|
57 |
|
---|
58 | CPPUNIT_ASSERT_EQUAL(3, World::getInstance().numAtoms());
|
---|
59 |
|
---|
60 | string newWaterXyz = "";
|
---|
61 | stringstream output;
|
---|
62 | testParser->save(&output);
|
---|
63 | newWaterXyz = output.str();
|
---|
64 |
|
---|
65 | CPPUNIT_ASSERT(waterXyz == newWaterXyz);
|
---|
66 | }
|
---|
67 |
|
---|
68 | void ParserUnitTest::readTremoloPreliminaryCommentsTest() {
|
---|
69 | cout << "Testing the tremolo parser." << endl;
|
---|
70 | TremoloParser* testParser = new TremoloParser();
|
---|
71 | stringstream input, output;
|
---|
72 | string waterTremolo;
|
---|
73 |
|
---|
74 | // Atomdata beginning with "# ATOMDATA"
|
---|
75 | waterTremolo = "# ATOMDATA\tId\tname\tType\tx=3\n";
|
---|
76 | input << waterTremolo;
|
---|
77 | testParser->load(&input);
|
---|
78 | testParser->save(&output);
|
---|
79 | CPPUNIT_ASSERT(waterTremolo == output.str());
|
---|
80 | input.clear();
|
---|
81 | output.clear();
|
---|
82 |
|
---|
83 | // Atomdata beginning with "#ATOMDATA"
|
---|
84 | waterTremolo = "#\n#ATOMDATA Id name Type x=3\n1 hydrogen H 3.0 4.5 0.1\n\n";
|
---|
85 | input << waterTremolo;
|
---|
86 | testParser->load(&input);
|
---|
87 | testParser->save(&output);
|
---|
88 | CPPUNIT_ASSERT(output.str().find("hydrogen") != string::npos);
|
---|
89 | input.clear();
|
---|
90 | output.clear();
|
---|
91 |
|
---|
92 | // Invalid key in Atomdata line
|
---|
93 | waterTremolo = "#\n#ATOMDATA Id name foo Type x=3\n\n\n";
|
---|
94 | input << waterTremolo;
|
---|
95 | testParser->load(&input);
|
---|
96 | //TODO: proove invalidity
|
---|
97 | input.clear();
|
---|
98 | }
|
---|
99 |
|
---|
100 | void ParserUnitTest::readTremoloCoordinatesTest() {
|
---|
101 | TremoloParser* testParser = new TremoloParser();
|
---|
102 | stringstream input;
|
---|
103 | string waterTremolo;
|
---|
104 |
|
---|
105 | // One simple data line
|
---|
106 | waterTremolo = "#\n#ATOMDATA Id name Type x=3\n1 hydrogen H 3.0 4.5 0.1\n\n";
|
---|
107 | input << waterTremolo;
|
---|
108 | testParser->load(&input);
|
---|
109 | CPPUNIT_ASSERT(World::getInstance().getAtom(AtomByType(1))->x[0] == 3.0);
|
---|
110 | input.clear();
|
---|
111 | }
|
---|
112 |
|
---|
113 | void ParserUnitTest::readTremoloVelocityTest() {
|
---|
114 | TremoloParser* testParser = new TremoloParser();
|
---|
115 | stringstream input;
|
---|
116 | string waterTremolo;
|
---|
117 |
|
---|
118 | // One simple data line
|
---|
119 | waterTremolo = "#\n#ATOMDATA Id name Type u=3\n1 hydrogen H 3.0 4.5 0.1\n\n";
|
---|
120 | input << waterTremolo;
|
---|
121 | testParser->load(&input);
|
---|
122 | CPPUNIT_ASSERT(World::getInstance().getAtom(AtomByType(1))->v[0] == 3.0);
|
---|
123 | input.clear();
|
---|
124 | }
|
---|
125 |
|
---|
126 | void ParserUnitTest::readTremoloNeighborInformationTest() {
|
---|
127 | TremoloParser* testParser = new TremoloParser();
|
---|
128 | stringstream input;
|
---|
129 | string waterTremolo;
|
---|
130 |
|
---|
131 | // Neighbor data
|
---|
132 | waterTremolo = "#\n#ATOMDATA Id Type neighbors=2\n1 H 3 0\n2 H 3 0\n3 O 1 2\n";
|
---|
133 | input << waterTremolo;
|
---|
134 | testParser->load(&input);
|
---|
135 |
|
---|
136 | CPPUNIT_ASSERT_EQUAL(3, World::getInstance().numAtoms());
|
---|
137 | CPPUNIT_ASSERT(World::getInstance().getAtom(AtomByType(8))->
|
---|
138 | IsBondedTo(World::getInstance().getAtom(AtomByType(1))));
|
---|
139 | input.clear();
|
---|
140 | }
|
---|
141 |
|
---|
142 | void ParserUnitTest::readAndWriteTremoloImprDataInformationTest() {
|
---|
143 | TremoloParser* testParser = new TremoloParser();
|
---|
144 | stringstream input, output;
|
---|
145 | string waterTremolo;
|
---|
146 |
|
---|
147 | // Neighbor data
|
---|
148 | waterTremolo = "#\n#ATOMDATA Id Type imprData\n8 H 9-10\n9 H 10-8,8-10\n10 O -\n";
|
---|
149 | input << waterTremolo;
|
---|
150 | testParser->load(&input);
|
---|
151 | testParser->save(&output);
|
---|
152 | CPPUNIT_ASSERT_EQUAL(3, World::getInstance().numAtoms());
|
---|
153 | CPPUNIT_ASSERT(output.str().find("2-0,0-2") != string::npos);
|
---|
154 | input.clear();
|
---|
155 | output.clear();
|
---|
156 | }
|
---|
157 |
|
---|
158 | void ParserUnitTest::readAndWriteTremoloTorsionInformationTest() {
|
---|
159 | TremoloParser* testParser = new TremoloParser();
|
---|
160 | stringstream input, output;
|
---|
161 | string waterTremolo;
|
---|
162 |
|
---|
163 | // Neighbor data
|
---|
164 | waterTremolo = "#\n#ATOMDATA Id Type torsion\n8 H 9-10\n9 H 10-8,8-10\n10 O -\n";
|
---|
165 | input << waterTremolo;
|
---|
166 | testParser->load(&input);
|
---|
167 | testParser->save(&output);
|
---|
168 | CPPUNIT_ASSERT_EQUAL(3, World::getInstance().numAtoms());
|
---|
169 | CPPUNIT_ASSERT(output.str().find("2-0,0-2") != string::npos);
|
---|
170 | input.clear();
|
---|
171 | output.clear();
|
---|
172 | }
|
---|
173 |
|
---|
174 | void ParserUnitTest::writeTremoloTest() {
|
---|
175 | TremoloParser* testParser = new TremoloParser();
|
---|
176 | stringstream output;
|
---|
177 |
|
---|
178 | // with the maximum number of fields and minimal information, default values are printed
|
---|
179 | atom* newAtom = World::getInstance().createAtom();
|
---|
180 | newAtom->type = World::getInstance().getPeriode()->FindElement(1);
|
---|
181 | testParser->setFieldsForSave("x=3 u=3 F stress Id neighbors=5 imprData GroupMeasureTypeNo Type extType name resName chainID resSeq occupancy tempFactor segID Charge charge GrpTypeNo torsion");
|
---|
182 | testParser->save(&output);
|
---|
183 | CPPUNIT_ASSERT(output.str() == "# ATOMDATA\tx=3\tu=3\tF\tstress\tId\tneighbors=5\timprData\tGroupMeasureTypeNo\tType\textType\tname\tresName\tchainID\tresSeq\toccupancy\ttempFactor\tsegID\tCharge\tcharge\tGrpTypeNo\ttorsion\n0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t0\t-\t0\tH\t-\t-\t-\t0\t0\t0\t0\t0\t0\t0\t0\t-\t\n");
|
---|
184 |
|
---|
185 | cout << "testing the tremolo parser is done" << endl;
|
---|
186 | }
|
---|