COOLFluiD  Release kernel
COOLFluiD is a Collaborative Simulation Environment (CSE) focused on complex MultiPhysics simulations.
utest-xml-signal-frame.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 XML maps manipulation"
9 
10 #include "rapidxml/rapidxml.hpp"
11 #include <boost/test/unit_test.hpp>
12 
13 #include "common/Log.hpp"
14 #include "common/URI.hpp"
15 
17 #include "common/XML/Protocol.hpp"
18 #include "common/XML/XmlDoc.hpp"
20 
21 using namespace cf3::common;
22 using namespace cf3::common::XML;
23 
25 
26 BOOST_AUTO_TEST_SUITE( XmlSignalFrame_TestSuite )
27 
28 
30 BOOST_AUTO_TEST_CASE ( contructors )
31 {
32  XmlDoc first_doc;
33 
34  std::string str_second_map = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
35  "<frame type=\"signal\">"
36  " <map>"
37  " <value key=\"map_A\">"
38  " <map/>"
39  " </value>"
40  " <value key=\"not_a_map\">"
41  " <int>0</int>"
42  " </value>"
43  " <value key=\"map_B\">"
44  " <map/>"
45  " </value>"
46  " </map>"
47  "</frame>";
48 
49  boost::shared_ptr<XmlDoc> second_doc = XML::parse_string(str_second_map);
50 
51  // 1. the node does not contain any map
52  SignalFrame first_frame ( first_doc );
53  rapidxml::xml_node<>* map_node = first_doc.content->first_node( Protocol::Tags::node_map() );
54  BOOST_CHECK ( cf3::is_not_null(map_node) );
55  BOOST_CHECK_EQUAL ( map_node, first_frame.main_map.content.content );
56 
57 
58  // 2. the node contains a non-empty map
59  SignalFrame second_frame ( second_doc.get()->content->first_node( "frame" ) );
60 
61  // "map_A" and "map_B" should have been recognized has maps, but not "not_a_map"
62  BOOST_CHECK ( second_frame.has_map("map_A") );
63  BOOST_CHECK ( second_frame.has_map("map_B") );
64  BOOST_CHECK ( !second_frame.has_map("not_a_map") );
65 
66  // 3. test the constructor that builds a new document
67  URI sender("cpath:/sender");
68  URI receiver("cpath:/receiver");
69  SignalFrame third_frame ( "theTarget", sender, receiver);
70 
71  rapidxml::xml_node<>* frame_node = third_frame.main_map.content.content->parent();
72  rapidxml::xml_attribute<>* tmp_attr;
73 
74  BOOST_CHECK ( frame_node != nullptr );
75  BOOST_CHECK_EQUAL ( std::string(frame_node->name()), std::string( Protocol::Tags::node_frame() ));
76 
77  tmp_attr = frame_node->first_attribute( "target" );
78  BOOST_CHECK ( tmp_attr != nullptr );
79  BOOST_CHECK_EQUAL ( std::string(tmp_attr->value()), std::string("theTarget") );
80 
81  tmp_attr = frame_node->first_attribute( "sender" );
82  BOOST_CHECK ( tmp_attr != nullptr );
83  BOOST_CHECK_EQUAL ( URI(tmp_attr->value()).string(), sender.string() );
84 
85  tmp_attr = frame_node->first_attribute( "receiver" );
86  BOOST_CHECK ( tmp_attr != nullptr );
87  BOOST_CHECK_EQUAL ( URI(tmp_attr->value()).string(), receiver.string());
88 }
89 
91 
93 {
94  URI sender("cpath:/sender");
95  URI receiver("cpath:/receiver");
96  SignalFrame frame ( "theTarget", sender, receiver);
97 
98  BOOST_CHECK ( !frame.has_map("MyMap") );
99 
100  frame.map("MyMap"); // creates the map
101 
102  BOOST_CHECK ( frame.has_map("MyMap") );
103 }
104 
106 
107 BOOST_AUTO_TEST_SUITE_END()
108 
109 
Classes that implement the XML protocol for use in COOLFluiD.
Definition: Component.hpp:43
boost::shared_ptr< XmlDoc > parse_string(const std::string &str)
rapidxml::xml_node< char > * content
Pointer to the underlying XML implementation.
Definition: XmlNode.hpp:50
Manages a set of maps.
Definition: SignalFrame.hpp:31
Uniform Resource Identifier (see http://en.wikipedia.org/wiki/Uniform_Resource_Identifier) ...
BOOST_AUTO_TEST_CASE(contructors)
XmlNode content
The managed node.
Definition: Map.hpp:179
SignalFrame & map(const std::string &name)
static const char * node_map()
Definition: Protocol.cpp:62
void map(Field &field, Eigen::Map< Derived > &v, const Uint row_idx, const Uint var_idx)
Most basic kernel library.
Definition: Action.cpp:19
std::string string() const
Definition: URI.cpp:258
bool is_not_null(T ptr)
predicate for comparison to nullptr
Definition: CF.hpp:147
static const char * node_frame()
Definition: Protocol.cpp:60
bool has_map(const std::string &name) const
Send comments to:
COOLFluiD Web Admin