COOLFluiD  Release kernel
COOLFluiD is a Collaborative Simulation Environment (CSE) focused on complex MultiPhysics simulations.
utest-rapidxml.cpp
Go to the documentation of this file.
1 // Copyright (C) 2010-2013 von Karman Institute for Fluid Dynamics, Belgium
2 //
3 // This software is distributed under the terms of the
4 // GNU Lesser General Public License version 3 (LGPLv3).
5 // See doc/lgpl.txt and doc/gpl.txt for the license text.
6 
7 #define BOOST_TEST_DYN_LINK
8 #define BOOST_TEST_MODULE "Test module for rapidxml"
9 
10 #include <string>
11 #include <iostream>
12 
13 #include <boost/test/unit_test.hpp>
14 #include <boost/algorithm/string.hpp>
15 
16 #include "rapidxml/rapidxml.hpp"
17 
18 using namespace std;
19 using namespace boost;
20 
23 {
24  using namespace rapidxml;
25 
26  std::cout << "Node \'" << node->name() << "\'";
27  std::cout << " w value [" << node->value() << "]\n";
28 
29  for (xml_attribute<> *attr = node->first_attribute(); attr ; attr = attr->next_attribute())
30  {
31  std::cout << " + attribute \'" << attr->name() << "\'' ";
32  std::cout << "with value [" << attr->value() << "]\n";
33  }
34 
35  for (xml_node<> * itr = node->first_node(); itr ; itr = itr->next_sibling() )
36  {
37  print_xml_node(itr);
38  }
39 }
40 
44 {
45  rapidxml::memory_pool<>& mem = *out.document();
46 
47  char* nname = mem.allocate_string(in.name());
48  char* nvalue = mem.allocate_string(in.value());
49 
50  // TESTING
51 // boost::to_upper(nname);
52 // boost::to_upper(nvalue);
53 
54  out.name(nname);
55  out.value(nvalue);
56 
57  // copy names and values of the attributes
58  rapidxml::xml_attribute<>* iattr = in.first_attribute();
59  rapidxml::xml_attribute<>* oattr = out.first_attribute();
60 
61  for ( ; iattr ; iattr = iattr->next_attribute(),
62  oattr = oattr->next_attribute() )
63  {
64  char* aname = mem.allocate_string(iattr->name());
65  char* avalue = mem.allocate_string(iattr->value());
66 
67  // TESTING
68 // boost::to_upper(aname);
69 // boost::to_upper(avalue);
70 
71  oattr->name(aname);
72  oattr->value(avalue);
73  }
74 
75  // copy names and values of the child nodes
76  rapidxml::xml_node<> * inode = in.first_node();
77  rapidxml::xml_node<> * onode = out.first_node();
78 
79  for ( ; inode ; inode = inode->next_sibling(),
80  onode = onode->next_sibling() )
81  {
82  deep_copy_names_values( *inode, *onode );
83  }
84 }
85 
88 {
89  rapidxml::memory_pool<>& mem = *out.document();
90  mem.clone_node(&in,&out);
91  deep_copy_names_values(in,out);
92 }
93 
95 
97 {
100 
103 };
104 
106 
107 BOOST_FIXTURE_TEST_SUITE( RapidXML_TestSuite, RapidXML_Test_Fixture )
108 
109 
112 {
113  using namespace rapidxml;
114 
115  std::string text = ( "<debug lolo=\"1\" koko=\"2\" >"
116  " blabla lalala "
117  "<filename>debug.log</filename>"
118  "<modules NBS=\"3\">"
119  " <module>Finance</module>"
120  " <module>Admin</module>"
121  " <module>HR</module>"
122  "</modules>"
123  "<level>2</level>"
124  " propro " // will be ignored
125  "</debug>" );
126 
127  // creation of first xml doc
128  xml_document<> doc; // character type defaults to char
129 
130  char* ctext = doc.allocate_string(text.c_str());
131 
132  doc.parse< rapidxml::parse_no_data_nodes |
133  rapidxml::parse_trim_whitespace |
134  parse_normalize_whitespace > (ctext);
135 
136  // creation of second xml doc, and copy first to it
137  xml_document<> adoc;
138 
139  deep_copy( doc, adoc );
140 
141  // print document
142  print_xml_node(adoc.first_node());
143 }
144 
146 
147 BOOST_AUTO_TEST_SUITE_END()
148 
149 
RapidXML_Test_Fixture()
common setup for each test case
external boost library namespace
void deep_copy(rapidxml::xml_node<> &in, rapidxml::xml_node<> &out)
deep copies a node into another with all the memory allocated in the second
STL namespace.
void print_xml_node(rapidxml::xml_node<> *node)
prints the xml node to screen
BOOST_AUTO_TEST_CASE(parsing)
~RapidXML_Test_Fixture()
common tear-down for each test case
void deep_copy_names_values(rapidxml::xml_node<> &in, rapidxml::xml_node<> &out)
external library used for XML parsing
Definition: XmlDoc.hpp:16
Send comments to:
COOLFluiD Web Admin