cantera/test/general/test_xml.cpp
Ray Speth b0e5b13913 Remove redundant, unnamed root XML node from parsed documents
XML_Node::build will make that node the root node (i.e. the 'ctml' node)
of the tree, instead of giving that node a child node containing the actual
root node.
2015-04-20 18:34:39 -04:00

30 lines
814 B
C++

#include "gtest/gtest.h"
#include "cantera/base/xml.h"
#include <fstream>
namespace Cantera
{
TEST(XML_Node, read_write)
{
// Check that we can re-read our own XML output
XML_Node node1, node2;
std::stringstream out;
std::ifstream xmlfile("../data/air-no-reactions.xml");
node1.build(xmlfile);
node1.write(out);
node2.build(out);
ASSERT_EQ(node2.name(), "ctml");
ASSERT_TRUE(node2.hasChild("speciesData"));
std::vector<XML_Node*> species1, species2;
species1 = node1.child("speciesData").getChildren("species");
species2 = node2.child("speciesData").getChildren("species");
ASSERT_EQ(species1.size(), species2.size());
for (size_t i = 0; i < species1.size(); i++) {
ASSERT_EQ(species1[i]->attrib("name"), species2[i]->attrib("name"));
}
}
}