12 #include <gtest/gtest.h> 23 #include <dynamic_reconfigure/ConfigDescription.h> 24 #include <dynamic_reconfigure/config_tools.h> 26 #include <rtt_dynamic_reconfigure_tests/TestConfig.h> 41 static const dynamic_reconfigure::Group *
getGroup(
const dynamic_reconfigure::ConfigDescription::_groups_type *groups,
const std::string &name)
43 if (!groups)
return 0;
44 for(dynamic_reconfigure::ConfigDescription::_groups_type::const_iterator it = groups->begin(); it != groups->end(); ++it) {
45 if (it->name == name)
return &(*it);
50 static const dynamic_reconfigure::ParamDescription *
getParamDescription(
const dynamic_reconfigure::Group *group,
const std::string &name)
53 for(dynamic_reconfigure::Group::_parameters_type::const_iterator it = group->parameters.begin(); it != group->parameters.end(); ++it) {
54 if (it->name == name)
return &(*it);
62 ASSERT_TRUE(tc.loadService(
"test_reconfigure"));
63 ASSERT_TRUE(tc.provides()->hasService(
"test_reconfigure"));
66 EXPECT_EQ(0, tc.props.int_param);
67 EXPECT_EQ(0, tc.props.double_param);
68 EXPECT_EQ(
"", tc.props.str_param);
69 EXPECT_FALSE(tc.props.bool_param);
72 ASSERT_TRUE(tc.properties()->getPropertyType<
double>(
"non_existent"));
73 EXPECT_EQ(5.0, *(tc.properties()->getPropertyType<
double>(
"non_existent")));
77 ASSERT_TRUE(server.get());
93 std::string str_param;
95 std::string group_param;
97 EXPECT_TRUE(dynamic_reconfigure::ConfigTools::getParameter(description->dflt,
"int_param", temp.int_param));
98 EXPECT_TRUE(dynamic_reconfigure::ConfigTools::getParameter(description->dflt,
"double_param", temp.double_param));
99 EXPECT_TRUE(dynamic_reconfigure::ConfigTools::getParameter(description->dflt,
"str_param", temp.str_param));
100 EXPECT_TRUE(dynamic_reconfigure::ConfigTools::getParameter(description->dflt,
"bool_param", temp.bool_param));
102 EXPECT_TRUE(dynamic_reconfigure::ConfigTools::getParameter(description->min,
"int_param", temp.int_param));
103 EXPECT_TRUE(dynamic_reconfigure::ConfigTools::getParameter(description->min,
"double_param", temp.double_param));
104 EXPECT_TRUE(dynamic_reconfigure::ConfigTools::getParameter(description->min,
"str_param", temp.str_param));
105 EXPECT_TRUE(dynamic_reconfigure::ConfigTools::getParameter(description->min,
"bool_param", temp.bool_param));
107 EXPECT_TRUE(dynamic_reconfigure::ConfigTools::getParameter(description->max,
"int_param", temp.int_param));
108 EXPECT_TRUE(dynamic_reconfigure::ConfigTools::getParameter(description->max,
"double_param", temp.double_param));
109 EXPECT_TRUE(dynamic_reconfigure::ConfigTools::getParameter(description->max,
"str_param", temp.str_param));
110 EXPECT_TRUE(dynamic_reconfigure::ConfigTools::getParameter(description->max,
"bool_param", temp.bool_param));
117 ASSERT_TRUE(tc.loadService(
"test_reconfigure"));
118 ASSERT_TRUE(tc.provides()->hasService(
"test_reconfigure"));
122 EXPECT_EQ(0, *(min.getPropertyType<
int>(
"int_param")));
123 EXPECT_EQ(0.0, *(min.getPropertyType<
double>(
"double_param")));
124 EXPECT_EQ(0.0, *(min.getPropertyType<
double>(
"non_existent")));
136 EXPECT_EQ(
"Hello World", dflt.
getPropertyType<std::string>(
"str_param")->rvalue());
144 ASSERT_TRUE(tc.loadService(
"reconfigure"));
145 ASSERT_TRUE(tc.provides()->hasService(
"reconfigure"));
148 EXPECT_FALSE(tc.updatePropertiesCalled);
149 EXPECT_FALSE(tc.updatePropertiesConstCalled);
150 EXPECT_FALSE(tc.notifyPropertiesUpdateCalled);
153 dynamic_reconfigure::Reconfigure reconfigure;
154 EXPECT_TRUE(tc.setConfigCallback(
"reconfigure", reconfigure.request, reconfigure.response));
155 EXPECT_FALSE(tc.updatePropertiesCalled);
156 EXPECT_FALSE(tc.updatePropertiesConstCalled);
157 EXPECT_FALSE(tc.notifyPropertiesUpdateCalled);
166 ASSERT_TRUE(tc.loadService(
"reconfigure"));
167 ASSERT_TRUE(tc.provides()->hasService(
"reconfigure"));
170 EXPECT_TRUE(tc.updatePropertiesCalled);
171 EXPECT_FALSE(tc.updatePropertiesConstCalled);
172 EXPECT_FALSE(tc.notifyPropertiesUpdateCalled);
173 tc.updatePropertiesCalled =
false;
176 dynamic_reconfigure::Reconfigure reconfigure;
177 EXPECT_TRUE(tc.setConfigCallback(
"reconfigure", reconfigure.request, reconfigure.response));
178 EXPECT_TRUE(tc.updatePropertiesCalled);
179 EXPECT_FALSE(tc.updatePropertiesConstCalled);
180 EXPECT_FALSE(tc.notifyPropertiesUpdateCalled);
189 ASSERT_TRUE(tc.loadService(
"reconfigure"));
190 ASSERT_TRUE(tc.provides()->hasService(
"reconfigure"));
193 EXPECT_FALSE(tc.updatePropertiesCalled);
194 EXPECT_TRUE(tc.updatePropertiesConstCalled);
195 EXPECT_FALSE(tc.notifyPropertiesUpdateCalled);
196 tc.updatePropertiesConstCalled =
false;
199 dynamic_reconfigure::Reconfigure reconfigure;
200 EXPECT_TRUE(tc.setConfigCallback(
"reconfigure", reconfigure.request, reconfigure.response));
201 EXPECT_FALSE(tc.updatePropertiesCalled);
202 EXPECT_TRUE(tc.updatePropertiesConstCalled);
203 EXPECT_FALSE(tc.notifyPropertiesUpdateCalled);
212 ASSERT_TRUE(tc.loadService(
"reconfigure"));
213 ASSERT_TRUE(tc.provides()->hasService(
"reconfigure"));
216 EXPECT_FALSE(tc.updatePropertiesCalled);
217 EXPECT_FALSE(tc.updatePropertiesConstCalled);
218 EXPECT_TRUE(tc.notifyPropertiesUpdateCalled);
219 tc.notifyPropertiesUpdateCalled =
false;
222 dynamic_reconfigure::Reconfigure reconfigure;
223 EXPECT_TRUE(tc.setConfigCallback(
"reconfigure", reconfigure.request, reconfigure.response));
224 EXPECT_FALSE(tc.updatePropertiesCalled);
225 EXPECT_FALSE(tc.updatePropertiesConstCalled);
226 EXPECT_TRUE(tc.notifyPropertiesUpdateCalled);
232 ASSERT_TRUE(tc.loadService(
"reconfigure"));
233 ASSERT_TRUE(tc.provides()->hasService(
"reconfigure"));
237 ASSERT_TRUE(server.get());
240 ASSERT_TRUE(tc.provides(
"reconfigure")->properties()->getPropertyType<
RTT::PropertyBag>(
"min"));
241 ASSERT_TRUE(tc.provides(
"reconfigure")->properties()->getPropertyType<
RTT::PropertyBag>(
"max"));
242 ASSERT_TRUE(tc.provides(
"reconfigure")->properties()->getPropertyType<
RTT::PropertyBag>(
"default"));
243 ASSERT_EQ(tc.properties()->size(), tc.provides(
"reconfigure")->properties()->getPropertyType<
RTT::PropertyBag>(
"min")->rvalue().size());
244 ASSERT_EQ(tc.properties()->size(), tc.provides(
"reconfigure")->properties()->getPropertyType<
RTT::PropertyBag>(
"max")->rvalue().size());
245 ASSERT_EQ(tc.properties()->size(), tc.provides(
"reconfigure")->properties()->getPropertyType<
RTT::PropertyBag>(
"default")->rvalue().size());
248 EXPECT_EQ(0, tc.props.int_param);
249 EXPECT_EQ(0.0, tc.props.double_param);
250 EXPECT_EQ(
"", tc.props.str_param);
251 EXPECT_FALSE(tc.props.bool_param);
252 EXPECT_EQ(0.0, tc.props.float_param);
253 EXPECT_EQ(0, tc.props.uint_param);
254 EXPECT_TRUE(tc.props.bag_param.size() == 1);
255 EXPECT_EQ(
"", tc.props.str_param_in_bag);
256 EXPECT_EQ(1.0, tc.props.vector3_param.x);
257 EXPECT_EQ(2.0, tc.props.vector3_param.y);
258 EXPECT_EQ(3.0, tc.props.vector3_param.z);
263 EXPECT_EQ(tc.props.int_param, *(dflt.
getPropertyType<
int>(
"int_param")));
265 EXPECT_EQ(tc.props.double_param, *(dflt.
getPropertyType<
double>(
"double_param")));
267 EXPECT_EQ(tc.props.str_param, dflt.
getPropertyType<std::string>(
"str_param")->rvalue());
269 EXPECT_EQ(tc.props.bool_param, *(dflt.
getPropertyType<
bool>(
"bool_param")));
271 EXPECT_EQ(tc.props.float_param, *(dflt.
getPropertyType<
float>(
"float_param")));
273 EXPECT_EQ(tc.props.uint_param, *(dflt.
getPropertyType<
unsigned int>(
"uint_param")));
277 EXPECT_TRUE(dflt_bag.
size() == 1);
279 EXPECT_EQ(tc.props.str_param_in_bag, dflt_bag.
getPropertyType<std::string>(
"str_param")->rvalue());
283 EXPECT_TRUE(dflt_vector3_bag.
size() == 3);
287 EXPECT_EQ(tc.props.vector3_param.x, dflt_vector3_bag.
getPropertyType<
double>(
"x")->rvalue());
288 EXPECT_EQ(tc.props.vector3_param.y, dflt_vector3_bag.
getPropertyType<
double>(
"y")->rvalue());
289 EXPECT_EQ(tc.props.vector3_param.z, dflt_vector3_bag.
getPropertyType<
double>(
"z")->rvalue());
292 dynamic_reconfigure::ConfigDescriptionPtr description = server->getDescriptionMessage();
293 ASSERT_TRUE(description->groups.size() == 3);
294 EXPECT_EQ(
"Default", description->groups[0].name);
295 EXPECT_EQ(
"", description->groups[0].type);
296 EXPECT_EQ(6, description->groups[0].parameters.size());
297 EXPECT_EQ(0, description->groups[0].parent);
298 EXPECT_EQ(0, description->groups[0].id);
299 EXPECT_EQ(
"bag_param", description->groups[1].name);
300 EXPECT_EQ(
"", description->groups[1].type);
301 EXPECT_EQ(1, description->groups[1].parameters.size());
302 EXPECT_EQ(0, description->groups[1].parent);
303 EXPECT_EQ(1, description->groups[1].id);
304 EXPECT_EQ(
"vector3_param", description->groups[2].name);
305 EXPECT_EQ(
"", description->groups[2].type);
306 EXPECT_EQ(3, description->groups[2].parameters.size());
307 EXPECT_EQ(0, description->groups[2].parent);
308 EXPECT_EQ(2, description->groups[2].id);
314 std::string str_param;
318 std::string str_param_in_bag;
319 geometry_msgs::Vector3 vector3_param;
321 EXPECT_TRUE(dynamic_reconfigure::ConfigTools::getParameter(description->dflt,
"int_param", temp.int_param));
322 EXPECT_TRUE(dynamic_reconfigure::ConfigTools::getParameter(description->dflt,
"double_param", temp.double_param));
323 EXPECT_TRUE(dynamic_reconfigure::ConfigTools::getParameter(description->dflt,
"str_param", temp.str_param));
324 EXPECT_TRUE(dynamic_reconfigure::ConfigTools::getParameter(description->dflt,
"bool_param", temp.bool_param));
325 EXPECT_TRUE(dynamic_reconfigure::ConfigTools::getParameter(description->dflt,
"float_param", temp.float_param));
326 EXPECT_TRUE(dynamic_reconfigure::ConfigTools::getParameter(description->dflt,
"uint_param", temp.uint_param));
327 EXPECT_TRUE(dynamic_reconfigure::ConfigTools::getParameter(description->dflt,
"bag_param__str_param", temp.str_param_in_bag));
328 EXPECT_TRUE(dynamic_reconfigure::ConfigTools::getParameter(description->dflt,
"vector3_param__x", temp.vector3_param.x));
329 EXPECT_TRUE(dynamic_reconfigure::ConfigTools::getParameter(description->dflt,
"vector3_param__y", temp.vector3_param.y));
330 EXPECT_TRUE(dynamic_reconfigure::ConfigTools::getParameter(description->dflt,
"vector3_param__z", temp.vector3_param.z));
331 EXPECT_TRUE(dynamic_reconfigure::ConfigTools::getParameter(description->min,
"int_param", temp.int_param));
332 EXPECT_TRUE(dynamic_reconfigure::ConfigTools::getParameter(description->min,
"double_param", temp.double_param));
333 EXPECT_TRUE(dynamic_reconfigure::ConfigTools::getParameter(description->min,
"str_param", temp.str_param));
334 EXPECT_TRUE(dynamic_reconfigure::ConfigTools::getParameter(description->min,
"bool_param", temp.bool_param));
335 EXPECT_TRUE(dynamic_reconfigure::ConfigTools::getParameter(description->min,
"float_param", temp.float_param));
336 EXPECT_TRUE(dynamic_reconfigure::ConfigTools::getParameter(description->min,
"uint_param", temp.uint_param));
337 EXPECT_TRUE(dynamic_reconfigure::ConfigTools::getParameter(description->min,
"bag_param__str_param", temp.str_param_in_bag));
338 EXPECT_TRUE(dynamic_reconfigure::ConfigTools::getParameter(description->min,
"vector3_param__x", temp.vector3_param.x));
339 EXPECT_TRUE(dynamic_reconfigure::ConfigTools::getParameter(description->min,
"vector3_param__y", temp.vector3_param.y));
340 EXPECT_TRUE(dynamic_reconfigure::ConfigTools::getParameter(description->min,
"vector3_param__z", temp.vector3_param.z));
341 EXPECT_TRUE(dynamic_reconfigure::ConfigTools::getParameter(description->max,
"int_param", temp.int_param));
342 EXPECT_TRUE(dynamic_reconfigure::ConfigTools::getParameter(description->max,
"double_param", temp.double_param));
343 EXPECT_TRUE(dynamic_reconfigure::ConfigTools::getParameter(description->max,
"str_param", temp.str_param));
344 EXPECT_TRUE(dynamic_reconfigure::ConfigTools::getParameter(description->max,
"bool_param", temp.bool_param));
345 EXPECT_TRUE(dynamic_reconfigure::ConfigTools::getParameter(description->max,
"float_param", temp.float_param));
346 EXPECT_TRUE(dynamic_reconfigure::ConfigTools::getParameter(description->max,
"uint_param", temp.uint_param));
347 EXPECT_TRUE(dynamic_reconfigure::ConfigTools::getParameter(description->max,
"bag_param__str_param", temp.str_param_in_bag));
348 EXPECT_TRUE(dynamic_reconfigure::ConfigTools::getParameter(description->max,
"vector3_param__x", temp.vector3_param.x));
349 EXPECT_TRUE(dynamic_reconfigure::ConfigTools::getParameter(description->max,
"vector3_param__y", temp.vector3_param.y));
350 EXPECT_TRUE(dynamic_reconfigure::ConfigTools::getParameter(description->max,
"vector3_param__z", temp.vector3_param.z));
356 ASSERT_TRUE(tc.loadService(
"reconfigure"));
357 ASSERT_TRUE(tc.provides()->hasService(
"reconfigure"));
361 ASSERT_TRUE(server.get());
370 dynamic_reconfigure::ConfigDescriptionPtr description = server->getDescriptionMessage();
373 EXPECT_TRUE(dynamic_reconfigure::ConfigTools::getParameter(description->dflt,
"new_param", str));
374 EXPECT_TRUE(dynamic_reconfigure::ConfigTools::getParameter(description->min,
"new_param", str));
375 EXPECT_TRUE(dynamic_reconfigure::ConfigTools::getParameter(description->max,
"new_param", str));
378 int main(
int argc,
char **argv) {
379 ::testing::InitGoogleTest(&argc, argv);
390 import(
"rtt_dynamic_reconfigure_tests");
392 return RUN_ALL_TESTS();
Property< T > * getPropertyType(const std::string &name) const
const T & min(const T &a, const T &b)
int __os_init(int argc, char **argv)
PropertyBag * properties()
static boost::shared_ptr< ComponentLoader > Instance()
const T & max(const T &a, const T &b)
bool ownProperty(base::PropertyBase *p)
void mayLogStdOut(bool tf)
void setStdStream(std::ostream &stdos)
static RTT_API Service::shared_ptr Instance()
void setLogLevel(LogLevel ll)