test_model_parser_initxml.cpp
Go to the documentation of this file.
1 /*********************************************************************
2 * Software License Agreement (BSD License)
3 *
4 * Copyright (c) 2018, Open Source Robotics Foundation
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 *
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above
14 * copyright notice, this list of conditions and the following
15 * disclaimer in the documentation and/or other materials provided
16 * with the distribution.
17 * * Neither the name of the Willow Garage nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32 * POSSIBILITY OF SUCH DAMAGE.
33 *********************************************************************/
34 
35 #include <gtest/gtest.h>
36 
37 #include "urdf/model.h"
38 
39 static const std::string good_robot{"<robot name=\"myrobot\">"
40  " <link name=\"dummy\">"
41  " </link>"
42  "</robot>"};
43 
44 TEST(model_parser_initxml, initstring_bad_xml)
45 {
46  const std::string robot{""};
47 
48  urdf::Model model;
49  ASSERT_FALSE(model.initString(robot));
50 }
51 
52 TEST(model_parser_initxml, initstring_good)
53 {
54  urdf::Model model;
55  ASSERT_TRUE(model.initString(good_robot));
56 }
57 
58 TEST(model_parser_initxml, initxml_tinyxml_element_bad)
59 {
60  urdf::Model model;
61  ASSERT_FALSE(model.initXml(reinterpret_cast<TiXmlElement *>(NULL)));
62 }
63 
64 TEST(model_parser_initxml, initxml_tinyxml_element_good)
65 {
66  TiXmlDocument xml_doc;
67  xml_doc.Parse(good_robot.c_str());
68 
69  urdf::Model model;
70  ASSERT_TRUE(model.initXml(xml_doc.RootElement()));
71 }
72 
73 TEST(model_parser_initxml, initxml_tinyxml_document_bad)
74 {
75  urdf::Model model;
76  ASSERT_FALSE(model.initXml(reinterpret_cast<TiXmlDocument *>(NULL)));
77 }
78 
79 TEST(model_parser_initxml, initxml_tinyxml_document_good)
80 {
81  TiXmlDocument xml_doc;
82  xml_doc.Parse(good_robot.c_str());
83 
84  urdf::Model model;
85  ASSERT_TRUE(model.initXml(&xml_doc));
86 }
87 
88 TEST(model_parser_initxml, initxml_tinyxml2_element_bad)
89 {
90  urdf::Model model;
91  ASSERT_FALSE(model.initXml(reinterpret_cast<tinyxml2::XMLElement *>(NULL)));
92 }
93 
94 TEST(model_parser_initxml, initxml_tinyxml2_element_good)
95 {
96  tinyxml2::XMLDocument xml_doc;
97  xml_doc.Parse(good_robot.c_str());
98 
99  urdf::Model model;
100  ASSERT_TRUE(model.initXml(xml_doc.RootElement()));
101 }
102 
103 TEST(model_parser_initxml, initxml_tinyxml2_document_bad)
104 {
105  urdf::Model model;
106  ASSERT_FALSE(model.initXml(reinterpret_cast<tinyxml2::XMLDocument *>(NULL)));
107 }
108 
109 TEST(model_parser_initxml, initxml_tinyxml2_document_good)
110 {
111  tinyxml2::XMLDocument xml_doc;
112  xml_doc.Parse(good_robot.c_str());
113 
114  urdf::Model model;
115  ASSERT_TRUE(model.initXml(&xml_doc));
116 }
117 
118 int main(int argc, char** argv)
119 {
120  testing::InitGoogleTest(&argc, argv);
121  return RUN_ALL_TESTS();
122 }
model.h
TEST
TEST(model_parser_initxml, initstring_bad_xml)
Definition: test_model_parser_initxml.cpp:44
good_robot
static const std::string good_robot
Definition: test_model_parser_initxml.cpp:39
urdf::Model
Definition: model.h:89
urdf::Model::initXml
URDF_EXPORT bool initXml(const tinyxml2::XMLElement *xml)
Load Model from tinyxml2::XMLElement.
Definition: model.cpp:181
urdf::Model::initString
URDF_EXPORT bool initString(const std::string &xmlstring)
Load Model from a XML-string.
Definition: model.cpp:196
main
int main(int argc, char **argv)
Definition: test_model_parser_initxml.cpp:118


urdf
Author(s): Ioan Sucan , Jackie Kay
autogenerated on Wed Jul 20 2022 02:43:43