test_rosparam.cpp
Go to the documentation of this file.
1 // Unit tests for rosparam tag
2 // Author: Max Schwarz <max.schwarz@ais.uni-bonn.de>
3 
4 #include <catch_ros/catch.hpp>
5 
6 #include "../../src/launch/launch_config.h"
7 
8 #include "core_utils.h"
9 #include "param_utils.h"
10 
11 using namespace rosmon::launch;
12 
13 TEST_CASE("rosparam basic", "[rosparam]")
14 {
15  LaunchConfig config;
16  config.parseString(R"EOF(
17  <launch>
18 <rosparam>
19 test_ns:
20  param1: true
21  param2: hello
22  param3: 3
23  param4: 10.0
24  param5: "3"
25 </rosparam>
26  </launch>
27  )EOF");
28 
29  config.evaluateParameters();
30 
31  CAPTURE(config.parameters());
32 
33  auto& params = config.parameters();
34  checkTypedParam<bool>(params, "/test_ns/param1", XmlRpc::XmlRpcValue::TypeBoolean, true);
35  checkTypedParam<std::string>(params, "/test_ns/param2", XmlRpc::XmlRpcValue::TypeString, "hello");
36  checkTypedParam<int>(params, "/test_ns/param3", XmlRpc::XmlRpcValue::TypeInt, 3);
37  checkTypedParam<double>(params, "/test_ns/param4", XmlRpc::XmlRpcValue::TypeDouble, 10.0);
38  checkTypedParam<std::string>(params, "/test_ns/param5", XmlRpc::XmlRpcValue::TypeString, "3");
39 }
40 
41 TEST_CASE("rosparam empty", "[rosparam]")
42 {
43  LaunchConfig config;
44  config.parseString(R"EOF(
45  <launch>
46 <rosparam>
47 </rosparam>
48 
49  <rosparam command="load" file="$(find rosmon_core)/test/empty.yaml" />
50  </launch>
51  )EOF");
52 }
53 
54 TEST_CASE("rosparam invalid YAML", "[rosparam]")
55 {
57  <launch>
58 <rosparam>
59 hello: {{ invalid }} test
60 </rosparam>
61  </launch>
62  )EOF");
63 }
64 
65 TEST_CASE("rosparam naming", "[rosparam]")
66 {
67  LaunchConfig config;
68  config.parseString(R"EOF(
69  <launch>
70  <rosparam param="a_list">[1, 2, 3, 4]</rosparam>
71 
72  <arg name="whitelist" default="[3, 2]"/>
73  <rosparam param="whitelist" subst_value="True">$(arg whitelist)</rosparam>
74 
75 <rosparam ns="namespace">
76 a: false
77 </rosparam>
78  </launch>
79  )EOF");
80 
81  config.evaluateParameters();
82 
83  CAPTURE(config.parameters());
84 
85  {
86  INFO("looking for: a_list");
87 
88  auto it = config.parameters().find("/a_list");
89  REQUIRE(it != config.parameters().end());
90 
91  auto value = it->second;
92 
93  REQUIRE(value.getType() == XmlRpc::XmlRpcValue::TypeArray);
94  REQUIRE(value.size() == 4);
95  }
96 
97  {
98  INFO("looking for: whitelist");
99 
100  auto it = config.parameters().find("/whitelist");
101  REQUIRE(it != config.parameters().end());
102 
103  auto value = it->second;
104 
105  REQUIRE(value.getType() == XmlRpc::XmlRpcValue::TypeArray);
106  REQUIRE(value.size() == 2);
107  }
108 
109  checkTypedParam<bool>(config.parameters(), "/namespace/a", XmlRpc::XmlRpcValue::TypeBoolean, false);
110 }
111 
112 TEST_CASE("rosparam explicit types", "[rosparam]")
113 {
114  LaunchConfig config;
115  config.parseString(R"EOF(
116  <launch>
117 <rosparam>
118 test_ns:
119  param1: !!str 1
120  param2: !!float 1
121  param3: !!binary "aGVsbG8K"
122 </rosparam>
123  </launch>
124  )EOF");
125 
126  config.evaluateParameters();
127 
128  CAPTURE(config.parameters());
129 
130  auto& params = config.parameters();
131  checkTypedParam<std::string>(params, "/test_ns/param1", XmlRpc::XmlRpcValue::TypeString, "1");
132  checkTypedParam<double>(params, "/test_ns/param2", XmlRpc::XmlRpcValue::TypeDouble, 1.0);
133 
134  auto binParam = getTypedParam<XmlRpc::XmlRpcValue::BinaryData>(params, "/test_ns/param3", XmlRpc::XmlRpcValue::TypeBase64);
135  XmlRpc::XmlRpcValue::BinaryData expected{'h', 'e', 'l', 'l', 'o', '\n'};
136  CHECK(binParam == expected);
137 }
138 
139 TEST_CASE("rosparam angle extensions", "[rosparam]")
140 {
141  LaunchConfig config;
142  config.parseString(R"EOF(
143  <launch>
144 <rosparam>
145 test_ns:
146  param1: rad(2*pi)
147  param2: deg(180)
148  param3: !degrees 181.0
149  param4: !radians 3.14169
150 </rosparam>
151  </launch>
152  )EOF");
153 
154  config.evaluateParameters();
155 
156  CAPTURE(config.parameters());
157 
158  auto& params = config.parameters();
159 
160  double param1 = getTypedParam<double>(params, "/test_ns/param1", XmlRpc::XmlRpcValue::TypeDouble);
161  CHECK(param1 == Approx(2.0 * M_PI));
162 
163  double param2 = getTypedParam<double>(params, "/test_ns/param2", XmlRpc::XmlRpcValue::TypeDouble);
164  CHECK(param2 == Approx(180.0 * M_PI / 180.0));
165 
166  double param3 = getTypedParam<double>(params, "/test_ns/param3", XmlRpc::XmlRpcValue::TypeDouble);
167  CHECK(param3 == Approx(181.0 * M_PI / 180.0));
168 
169  double param4 = getTypedParam<double>(params, "/test_ns/param4", XmlRpc::XmlRpcValue::TypeDouble);
170  CHECK(param4 == Approx(3.14169));
171 }
auto & params
Definition: test_param.cpp:220
const std::map< std::string, XmlRpc::XmlRpcValue > & parameters() const
static void requireParsingException(const std::string &input)
Definition: core_utils.h:11
void parseString(const std::string &input, bool onlyArguments=false)
std::vector< char > BinaryData
TEST_CASE("rosparam basic","[rosparam]")


rosmon_core
Author(s): Max Schwarz
autogenerated on Wed Jul 10 2019 03:10:12