OpenSDN source code
test_xml.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2014 Juniper Networks, Inc. All rights reserved.
3  * Copyright Contributors to the OpenSDN project
4  */
5 
6 #ifndef vnsw_agent_test_xml_test_xml_h
7 #define vnsw_agent_test_xml_test_xml_h
8 
9 #include <iostream>
10 #include <vector>
11 #include <pugixml/pugixml.hpp>
12 #include <boost/uuid/uuid.hpp>
13 
14 #include <base/util.h>
15 
16 class AgentUtXmlTestCase;
17 class AgentUtXmlNode;
19 
20 namespace AgentUtXmlUtils {
21 bool GetStringAttribute(const pugi::xml_node &node, const std::string &name,
22  std::string *value);
23 bool GetUintAttribute(const pugi::xml_node &node, const std::string &name,
24  uint16_t *value);
25 bool GetIntAttribute(const pugi::xml_node &node, const std::string &name,
26  int *value);
27 bool GetBoolAttribute(const pugi::xml_node &node, const std::string &name,
28  bool *value);
29 void NovaIntfAdd(bool op_delete, const boost::uuids::uuid &id,
30  const Ip4Address &ip, const boost::uuids::uuid &vm_uuid,
31  const boost::uuids::uuid vn_uuid, const std::string &name,
32  const std::string &mac, const std::string vm_name);
33 void LinkXmlNode(pugi::xml_node *parent, const std::string &ltype,
34  const std::string lname, const std::string &rtype,
35  const std::string rname);
36 pugi::xml_node AddXmlNodeWithAttr(pugi::xml_node *parent, const char *attr);
37 pugi::xml_node AddXmlNodeWithValue(pugi::xml_node *parent, const char *name,
38  const std::string &value);
39 pugi::xml_node AddXmlNodeWithIntValue(pugi::xml_node *parent, const char *name,
40  int val);
41 }
42 
44 private:
45  typedef std::vector<AgentUtXmlTestCase *> AgentUtXmlTestList;
46 public:
47  typedef boost::function<AgentUtXmlNode *(const std::string type,
48  const std::string &name,
49  const boost::uuids::uuid &id,
50  const pugi::xml_node &node,
51  AgentUtXmlTestCase *test_case)>
53 
54  typedef boost::function<AgentUtXmlValidationNode *
55  (const std::string &type, const std::string &name,
56  const boost::uuids::uuid &id, const pugi::xml_node &node)>
58 
59  typedef std::map<std::string, AgentUtXmlTestConfigCreateFn>
61  typedef std::map<std::string, AgentUtXmlTestValidateCreateFn>
63 
64  AgentUtXmlTest(const std::string &file_name);
65  virtual ~AgentUtXmlTest();
66 
67  bool Load();
68  bool ReadXml();
69  void ToString(std::string *str);
70  bool Run();
71  bool Run(std::string test_case);
72  void AddConfigEntry(const std::string &name,
74  void AddValidateEntry(const std::string &name,
76  AgentUtXmlTestConfigCreateFn GetConfigCreateFn(const std::string &name);
77  AgentUtXmlTestValidateCreateFn GetValidateCreateFn(const std::string &name);
78 private:
79  std::string file_name_;
80  std::string name_;
81  pugi::xml_document doc_;
86 };
87 
89 private:
90  typedef std::vector<AgentUtXmlNode *> AgentUtXmlNodeList;
91 public:
92  AgentUtXmlTestCase(const std::string &name, const pugi::xml_node &node,
94  virtual ~AgentUtXmlTestCase();
95  AgentUtXmlTest *test() { return test_; }
96 
97  virtual bool ReadXml();
98  virtual bool Run();
99  virtual void ToString(std::string *str);
100  void set_verbose(bool val) { verbose_ = val; }
101  bool verbose() const { return verbose_; }
102  const std::string &name() const { return name_; }
103 private:
104  std::string name_;
105  pugi::xml_node xml_node_;
107  pugi::xml_document gen_doc_;
109  bool verbose_;
111 };
112 
114 public:
115  AgentUtXmlNode(const std::string &name, const pugi::xml_node &node,
117  AgentUtXmlNode(const std::string &name, const pugi::xml_node &node,
119  virtual ~AgentUtXmlNode();
120 
121  virtual bool ReadXml() = 0;
122  virtual bool ToXml(pugi::xml_node *parent) = 0;
123  virtual std::string NodeType() = 0;
124  virtual void ToString(std::string *str);
125  virtual bool Run() { assert(0); return false; }
126 
127  void set_gen_xml(bool val) { gen_xml_ = val; }
128  bool gen_xml() const { return gen_xml_; }
129  bool op_delete() const { return op_delete_; }
130  void set_op_delete(bool val) { op_delete_ = val; }
131  const std::string &name() const { return name_; }
132  const pugi::xml_node &node() const { return node_; }
134 protected:
135  pugi::xml_node gen_node_;
136 private:
137  pugi::xml_node node_;
138  std::string name_;
140  bool gen_xml_;
143 };
144 
146 // Task control nodes
149 public:
150  AgentUtXmlTask(const pugi::xml_node &node, AgentUtXmlTestCase *test_case);
151  virtual ~AgentUtXmlTask();
152 
153  virtual bool ReadXml();
154  virtual bool ToXml(pugi::xml_node *parent);
155  virtual std::string NodeType();
156  virtual void ToString(std::string *str);
157  virtual bool Run();
158 
159 private:
160  pugi::xml_node xml_;
161  std::string stop_;
163 };
164 
166 // Link nodes
169 public:
170  AgentUtXmlLink(const pugi::xml_node &node, AgentUtXmlTestCase *test_case);
171  virtual ~AgentUtXmlLink();
172 
173  virtual bool ReadXml();
174  virtual bool ToXml(pugi::xml_node *parent);
175  virtual std::string NodeType();
176  virtual void ToString(std::string *str);
177 
178 private:
179  pugi::xml_node xml_;
180  std::string l_node_;
181  std::string l_name_;
182  std::string r_node_;
183  std::string r_name_;
185 };
186 
188 // Config nodes
191 public:
192  AgentUtXmlConfig(const std::string &name, const boost::uuids::uuid &uuid,
193  const pugi::xml_node &node, AgentUtXmlTestCase *test_case);
194  AgentUtXmlConfig(const std::string &name, const boost::uuids::uuid &uuid,
195  const pugi::xml_node &node, bool gen_xml,
197  virtual ~AgentUtXmlConfig();
198 
199  virtual bool ReadXml();
200  virtual void ToString(std::string *str);
201  const boost::uuids::uuid &id() const { return id_; }
202 protected:
203  void AddIdPerms(pugi::xml_node *parent);
204 private:
207 };
208 
209 #endif //vnsw_agent_test_xml_test_xml_h
boost::asio::ip::address_v4 Ip4Address
Definition: address.h:15
boost::uuids::uuid id_
Definition: test_xml.h:205
virtual ~AgentUtXmlConfig()
Definition: test_xml.cc:607
DISALLOW_COPY_AND_ASSIGN(AgentUtXmlConfig)
virtual bool ReadXml()
Definition: test_xml.cc:610
AgentUtXmlConfig(const std::string &name, const boost::uuids::uuid &uuid, const pugi::xml_node &node, AgentUtXmlTestCase *test_case)
virtual void ToString(std::string *str)
Definition: test_xml.cc:614
AgentUtXmlConfig(const std::string &name, const boost::uuids::uuid &uuid, const pugi::xml_node &node, bool gen_xml, AgentUtXmlTestCase *test_case)
void AddIdPerms(pugi::xml_node *parent)
Definition: test_xml.cc:651
const boost::uuids::uuid & id() const
Definition: test_xml.h:201
void set_gen_xml(bool val)
Definition: test_xml.h:127
virtual bool Run()
Definition: test_xml.h:125
bool op_delete_
Definition: test_xml.h:139
AgentUtXmlTestCase * test_case_
Definition: test_xml.h:141
void set_op_delete(bool val)
Definition: test_xml.h:130
const pugi::xml_node & node() const
Definition: test_xml.h:132
pugi::xml_node gen_node_
Definition: test_xml.h:135
AgentUtXmlNode(const std::string &name, const pugi::xml_node &node, bool gen_xml, AgentUtXmlTestCase *test_case)
bool op_delete() const
Definition: test_xml.h:129
DISALLOW_COPY_AND_ASSIGN(AgentUtXmlNode)
virtual bool ReadXml()=0
Definition: test_xml.cc:467
virtual void ToString(std::string *str)
Definition: test_xml.cc:479
AgentUtXmlTestCase * test_case()
Definition: test_xml.h:133
AgentUtXmlNode(const std::string &name, const pugi::xml_node &node, AgentUtXmlTestCase *test_case)
virtual ~AgentUtXmlNode()
Definition: test_xml.cc:464
std::string name_
Definition: test_xml.h:138
virtual bool ToXml(pugi::xml_node *parent)=0
virtual std::string NodeType()=0
bool gen_xml() const
Definition: test_xml.h:128
pugi::xml_node node_
Definition: test_xml.h:137
const std::string & name() const
Definition: test_xml.h:131
virtual bool ToXml(pugi::xml_node *parent)
Definition: test_xml.cc:509
virtual bool ReadXml()
Definition: test_xml.cc:504
DISALLOW_COPY_AND_ASSIGN(AgentUtXmlTask)
virtual bool Run()
Definition: test_xml.cc:526
AgentUtXmlTask(const pugi::xml_node &node, AgentUtXmlTestCase *test_case)
Definition: test_xml.cc:496
virtual std::string NodeType()
Definition: test_xml.cc:522
virtual ~AgentUtXmlTask()
Definition: test_xml.cc:501
pugi::xml_node xml_
Definition: test_xml.h:160
virtual void ToString(std::string *str)
Definition: test_xml.cc:513
std::string stop_
Definition: test_xml.h:161
virtual void ToString(std::string *str)
Definition: test_xml.cc:437
void set_verbose(bool val)
Definition: test_xml.h:100
DISALLOW_COPY_AND_ASSIGN(AgentUtXmlTestCase)
AgentUtXmlTest * test_
Definition: test_xml.h:108
std::vector< AgentUtXmlNode * > AgentUtXmlNodeList
Definition: test_xml.h:90
pugi::xml_document gen_doc_
Definition: test_xml.h:107
bool verbose() const
Definition: test_xml.h:101
virtual bool Run()
Definition: test_xml.cc:404
AgentUtXmlTest * test()
Definition: test_xml.h:95
virtual bool ReadXml()
Definition: test_xml.cc:333
pugi::xml_node xml_node_
Definition: test_xml.h:105
AgentUtXmlTestCase(const std::string &name, const pugi::xml_node &node, AgentUtXmlTest *test)
Definition: test_xml.cc:319
std::string name_
Definition: test_xml.h:104
AgentUtXmlNodeList node_list_
Definition: test_xml.h:106
const std::string & name() const
Definition: test_xml.h:102
virtual ~AgentUtXmlTestCase()
Definition: test_xml.cc:326
AgentUtXmlTestList test_list_
Definition: test_xml.h:82
pugi::xml_document doc_
Definition: test_xml.h:81
boost::function< AgentUtXmlNode *(const std::string type, const std::string &name, const boost::uuids::uuid &id, const pugi::xml_node &node, AgentUtXmlTestCase *test_case)> AgentUtXmlTestConfigCreateFn
Definition: test_xml.h:52
std::string file_name_
Definition: test_xml.h:79
AgentUtXmlTestConfigFactory config_factory_
Definition: test_xml.h:83
std::vector< AgentUtXmlTestCase * > AgentUtXmlTestList
Definition: test_xml.h:45
boost::function< AgentUtXmlValidationNode *(const std::string &type, const std::string &name, const boost::uuids::uuid &id, const pugi::xml_node &node)> AgentUtXmlTestValidateCreateFn
Definition: test_xml.h:57
std::map< std::string, AgentUtXmlTestConfigCreateFn > AgentUtXmlTestConfigFactory
Definition: test_xml.h:60
std::map< std::string, AgentUtXmlTestValidateCreateFn > AgentUtXmlTestValidateFactory
Definition: test_xml.h:62
AgentUtXmlTest(const std::string &file_name)
Definition: test_xml.cc:139
void AddValidateEntry(const std::string &name, AgentUtXmlTestValidateCreateFn fn)
Definition: test_xml.cc:155
virtual ~AgentUtXmlTest()
Definition: test_xml.cc:142
AgentUtXmlTestConfigCreateFn GetConfigCreateFn(const std::string &name)
Definition: test_xml.cc:161
bool ReadXml()
Definition: test_xml.cc:179
AgentUtXmlTestValidateFactory validate_factory_
Definition: test_xml.h:84
std::string name_
Definition: test_xml.h:80
DISALLOW_COPY_AND_ASSIGN(AgentUtXmlTest)
void ToString(std::string *str)
Definition: test_xml.cc:243
AgentUtXmlTestValidateCreateFn GetValidateCreateFn(const std::string &name)
Definition: test_xml.cc:171
void AddConfigEntry(const std::string &name, AgentUtXmlTestConfigCreateFn fn)
Definition: test_xml.cc:150
uint8_t type
Definition: load_balance.h:2
bool GetIntAttribute(const xml_node &node, const string &name, int *value)
Definition: test_xml.cc:50
bool GetUintAttribute(const xml_node &node, const string &name, uint16_t *value)
Definition: test_xml.cc:38
xml_node AddXmlNodeWithValue(xml_node *parent, const char *name, const string &value)
Definition: test_xml.cc:119
xml_node AddXmlNodeWithIntValue(xml_node *parent, const char *name, int val)
Definition: test_xml.cc:126
void LinkXmlNode(xml_node *parent, const string &ltype, const string lname, const string &rtype, const string rname)
Definition: test_xml.cc:91
xml_node AddXmlNodeWithAttr(xml_node *parent, const char *attr)
Definition: test_xml.cc:113
bool GetStringAttribute(const xml_node &node, const string &name, string *value)
Definition: test_xml.cc:26
void NovaIntfAdd(bool op_delete, const uuid &id, const Ip4Address &ip, const uuid &vm_uuid, const uuid vn_uuid, const string &name, const string &mac, const string vm_name)
Definition: test_xml.cc:76
bool GetBoolAttribute(const xml_node &node, const string &name, bool *value)
Definition: test_xml.cc:61
boost::uuids::uuid uuid