34 #include <gtest/gtest.h> 45 #include <dynamic_reconfigure/ConfigDescription.h> 46 #include <dynamic_reconfigure/config_tools.h> 48 #include <rtt_dynamic_reconfigure_tests/TestConfig.h> 63 static const dynamic_reconfigure::Group *
getGroup(
const dynamic_reconfigure::ConfigDescription::_groups_type *groups,
const std::string &name)
65 if (!groups)
return 0;
66 for(dynamic_reconfigure::ConfigDescription::_groups_type::const_iterator it = groups->begin(); it != groups->end(); ++it) {
67 if (it->name == name)
return &(*it);
72 static const dynamic_reconfigure::ParamDescription *
getParamDescription(
const dynamic_reconfigure::Group *group,
const std::string &name)
75 for(dynamic_reconfigure::Group::_parameters_type::const_iterator it = group->parameters.begin(); it != group->parameters.end(); ++it) {
76 if (it->name == name)
return &(*it);
84 ASSERT_TRUE(tc.loadService(
"test_reconfigure"));
85 ASSERT_TRUE(tc.provides()->hasService(
"test_reconfigure"));
88 EXPECT_EQ(0, tc.props.int_param);
89 EXPECT_EQ(0, tc.props.double_param);
90 EXPECT_EQ(
"", tc.props.str_param);
91 EXPECT_FALSE(tc.props.bool_param);
94 ASSERT_TRUE(tc.properties()->getPropertyType<
double>(
"non_existent"));
95 EXPECT_EQ(5.0, *(tc.properties()->getPropertyType<
double>(
"non_existent")));
99 ASSERT_TRUE(server.get());
115 std::string str_param;
117 std::string group_param;
119 EXPECT_TRUE(dynamic_reconfigure::ConfigTools::getParameter(description->dflt,
"int_param", temp.int_param));
120 EXPECT_TRUE(dynamic_reconfigure::ConfigTools::getParameter(description->dflt,
"double_param", temp.double_param));
121 EXPECT_TRUE(dynamic_reconfigure::ConfigTools::getParameter(description->dflt,
"str_param", temp.str_param));
122 EXPECT_TRUE(dynamic_reconfigure::ConfigTools::getParameter(description->dflt,
"bool_param", temp.bool_param));
124 EXPECT_TRUE(dynamic_reconfigure::ConfigTools::getParameter(description->min,
"int_param", temp.int_param));
125 EXPECT_TRUE(dynamic_reconfigure::ConfigTools::getParameter(description->min,
"double_param", temp.double_param));
126 EXPECT_TRUE(dynamic_reconfigure::ConfigTools::getParameter(description->min,
"str_param", temp.str_param));
127 EXPECT_TRUE(dynamic_reconfigure::ConfigTools::getParameter(description->min,
"bool_param", temp.bool_param));
129 EXPECT_TRUE(dynamic_reconfigure::ConfigTools::getParameter(description->max,
"int_param", temp.int_param));
130 EXPECT_TRUE(dynamic_reconfigure::ConfigTools::getParameter(description->max,
"double_param", temp.double_param));
131 EXPECT_TRUE(dynamic_reconfigure::ConfigTools::getParameter(description->max,
"str_param", temp.str_param));
132 EXPECT_TRUE(dynamic_reconfigure::ConfigTools::getParameter(description->max,
"bool_param", temp.bool_param));
139 ASSERT_TRUE(tc.loadService(
"test_reconfigure"));
140 ASSERT_TRUE(tc.provides()->hasService(
"test_reconfigure"));
144 EXPECT_EQ(0, *(min.getPropertyType<
int>(
"int_param")));
145 EXPECT_EQ(0.0, *(min.getPropertyType<
double>(
"double_param")));
146 EXPECT_EQ(0.0, *(min.getPropertyType<
double>(
"non_existent")));
158 EXPECT_EQ(
"Hello World", dflt.
getPropertyType<std::string>(
"str_param")->rvalue());
166 ASSERT_TRUE(tc.loadService(
"reconfigure"));
167 ASSERT_TRUE(tc.provides()->hasService(
"reconfigure"));
170 EXPECT_FALSE(tc.updatePropertiesCalled);
171 EXPECT_FALSE(tc.updatePropertiesConstCalled);
172 EXPECT_FALSE(tc.notifyPropertiesUpdateCalled);
175 dynamic_reconfigure::Reconfigure reconfigure;
176 EXPECT_TRUE(tc.setConfigCallback(
"reconfigure", reconfigure.request, reconfigure.response));
177 EXPECT_FALSE(tc.updatePropertiesCalled);
178 EXPECT_FALSE(tc.updatePropertiesConstCalled);
179 EXPECT_FALSE(tc.notifyPropertiesUpdateCalled);
188 ASSERT_TRUE(tc.loadService(
"reconfigure"));
189 ASSERT_TRUE(tc.provides()->hasService(
"reconfigure"));
192 EXPECT_TRUE(tc.updatePropertiesCalled);
193 EXPECT_FALSE(tc.updatePropertiesConstCalled);
194 EXPECT_FALSE(tc.notifyPropertiesUpdateCalled);
195 tc.updatePropertiesCalled =
false;
198 dynamic_reconfigure::Reconfigure reconfigure;
199 EXPECT_TRUE(tc.setConfigCallback(
"reconfigure", reconfigure.request, reconfigure.response));
200 EXPECT_TRUE(tc.updatePropertiesCalled);
201 EXPECT_FALSE(tc.updatePropertiesConstCalled);
202 EXPECT_FALSE(tc.notifyPropertiesUpdateCalled);
211 ASSERT_TRUE(tc.loadService(
"reconfigure"));
212 ASSERT_TRUE(tc.provides()->hasService(
"reconfigure"));
215 EXPECT_FALSE(tc.updatePropertiesCalled);
216 EXPECT_TRUE(tc.updatePropertiesConstCalled);
217 EXPECT_FALSE(tc.notifyPropertiesUpdateCalled);
218 tc.updatePropertiesConstCalled =
false;
221 dynamic_reconfigure::Reconfigure reconfigure;
222 EXPECT_TRUE(tc.setConfigCallback(
"reconfigure", reconfigure.request, reconfigure.response));
223 EXPECT_FALSE(tc.updatePropertiesCalled);
224 EXPECT_TRUE(tc.updatePropertiesConstCalled);
225 EXPECT_FALSE(tc.notifyPropertiesUpdateCalled);
234 ASSERT_TRUE(tc.loadService(
"reconfigure"));
235 ASSERT_TRUE(tc.provides()->hasService(
"reconfigure"));
238 EXPECT_FALSE(tc.updatePropertiesCalled);
239 EXPECT_FALSE(tc.updatePropertiesConstCalled);
240 EXPECT_TRUE(tc.notifyPropertiesUpdateCalled);
241 tc.notifyPropertiesUpdateCalled =
false;
244 dynamic_reconfigure::Reconfigure reconfigure;
245 EXPECT_TRUE(tc.setConfigCallback(
"reconfigure", reconfigure.request, reconfigure.response));
246 EXPECT_FALSE(tc.updatePropertiesCalled);
247 EXPECT_FALSE(tc.updatePropertiesConstCalled);
248 EXPECT_TRUE(tc.notifyPropertiesUpdateCalled);
254 ASSERT_TRUE(tc.loadService(
"reconfigure"));
255 ASSERT_TRUE(tc.provides()->hasService(
"reconfigure"));
259 ASSERT_TRUE(server.get());
262 ASSERT_TRUE(tc.provides(
"reconfigure")->properties()->getPropertyType<
RTT::PropertyBag>(
"min"));
263 ASSERT_TRUE(tc.provides(
"reconfigure")->properties()->getPropertyType<
RTT::PropertyBag>(
"max"));
264 ASSERT_TRUE(tc.provides(
"reconfigure")->properties()->getPropertyType<
RTT::PropertyBag>(
"default"));
265 ASSERT_EQ(tc.properties()->size(), tc.provides(
"reconfigure")->properties()->getPropertyType<
RTT::PropertyBag>(
"min")->rvalue().size());
266 ASSERT_EQ(tc.properties()->size(), tc.provides(
"reconfigure")->properties()->getPropertyType<
RTT::PropertyBag>(
"max")->rvalue().size());
267 ASSERT_EQ(tc.properties()->size(), tc.provides(
"reconfigure")->properties()->getPropertyType<
RTT::PropertyBag>(
"default")->rvalue().size());
270 EXPECT_EQ(0, tc.props.int_param);
271 EXPECT_EQ(0.0, tc.props.double_param);
272 EXPECT_EQ(
"", tc.props.str_param);
273 EXPECT_FALSE(tc.props.bool_param);
274 EXPECT_EQ(0.0, tc.props.float_param);
275 EXPECT_EQ(0, tc.props.uint_param);
276 EXPECT_TRUE(tc.props.bag_param.size() == 1);
277 EXPECT_EQ(
"", tc.props.str_param_in_bag);
278 EXPECT_EQ(1.0, tc.props.vector3_param.x);
279 EXPECT_EQ(2.0, tc.props.vector3_param.y);
280 EXPECT_EQ(3.0, tc.props.vector3_param.z);
285 EXPECT_EQ(tc.props.int_param, *(dflt.
getPropertyType<
int>(
"int_param")));
287 EXPECT_EQ(tc.props.double_param, *(dflt.
getPropertyType<
double>(
"double_param")));
289 EXPECT_EQ(tc.props.str_param, dflt.
getPropertyType<std::string>(
"str_param")->rvalue());
291 EXPECT_EQ(tc.props.bool_param, *(dflt.
getPropertyType<
bool>(
"bool_param")));
293 EXPECT_EQ(tc.props.float_param, *(dflt.
getPropertyType<
float>(
"float_param")));
295 EXPECT_EQ(tc.props.uint_param, *(dflt.
getPropertyType<
unsigned int>(
"uint_param")));
299 EXPECT_TRUE(dflt_bag.
size() == 1);
301 EXPECT_EQ(tc.props.str_param_in_bag, dflt_bag.
getPropertyType<std::string>(
"str_param")->rvalue());
305 EXPECT_TRUE(dflt_vector3_bag.
size() == 3);
309 EXPECT_EQ(tc.props.vector3_param.x, dflt_vector3_bag.
getPropertyType<
double>(
"x")->rvalue());
310 EXPECT_EQ(tc.props.vector3_param.y, dflt_vector3_bag.
getPropertyType<
double>(
"y")->rvalue());
311 EXPECT_EQ(tc.props.vector3_param.z, dflt_vector3_bag.
getPropertyType<
double>(
"z")->rvalue());
314 dynamic_reconfigure::ConfigDescriptionPtr description = server->getDescriptionMessage();
315 ASSERT_TRUE(description->groups.size() == 3);
316 EXPECT_EQ(
"Default", description->groups[0].name);
317 EXPECT_EQ(
"", description->groups[0].type);
318 EXPECT_EQ(6, description->groups[0].parameters.size());
319 EXPECT_EQ(0, description->groups[0].parent);
320 EXPECT_EQ(0, description->groups[0].id);
321 EXPECT_EQ(
"bag_param", description->groups[1].name);
322 EXPECT_EQ(
"", description->groups[1].type);
323 EXPECT_EQ(1, description->groups[1].parameters.size());
324 EXPECT_EQ(0, description->groups[1].parent);
325 EXPECT_EQ(1, description->groups[1].id);
326 EXPECT_EQ(
"vector3_param", description->groups[2].name);
327 EXPECT_EQ(
"", description->groups[2].type);
328 EXPECT_EQ(3, description->groups[2].parameters.size());
329 EXPECT_EQ(0, description->groups[2].parent);
330 EXPECT_EQ(2, description->groups[2].id);
336 std::string str_param;
340 std::string str_param_in_bag;
341 geometry_msgs::Vector3 vector3_param;
343 EXPECT_TRUE(dynamic_reconfigure::ConfigTools::getParameter(description->dflt,
"int_param", temp.int_param));
344 EXPECT_TRUE(dynamic_reconfigure::ConfigTools::getParameter(description->dflt,
"double_param", temp.double_param));
345 EXPECT_TRUE(dynamic_reconfigure::ConfigTools::getParameter(description->dflt,
"str_param", temp.str_param));
346 EXPECT_TRUE(dynamic_reconfigure::ConfigTools::getParameter(description->dflt,
"bool_param", temp.bool_param));
347 EXPECT_TRUE(dynamic_reconfigure::ConfigTools::getParameter(description->dflt,
"float_param", temp.float_param));
348 EXPECT_TRUE(dynamic_reconfigure::ConfigTools::getParameter(description->dflt,
"uint_param", temp.uint_param));
349 EXPECT_TRUE(dynamic_reconfigure::ConfigTools::getParameter(description->dflt,
"bag_param__str_param", temp.str_param_in_bag));
350 EXPECT_TRUE(dynamic_reconfigure::ConfigTools::getParameter(description->dflt,
"vector3_param__x", temp.vector3_param.x));
351 EXPECT_TRUE(dynamic_reconfigure::ConfigTools::getParameter(description->dflt,
"vector3_param__y", temp.vector3_param.y));
352 EXPECT_TRUE(dynamic_reconfigure::ConfigTools::getParameter(description->dflt,
"vector3_param__z", temp.vector3_param.z));
353 EXPECT_TRUE(dynamic_reconfigure::ConfigTools::getParameter(description->min,
"int_param", temp.int_param));
354 EXPECT_TRUE(dynamic_reconfigure::ConfigTools::getParameter(description->min,
"double_param", temp.double_param));
355 EXPECT_TRUE(dynamic_reconfigure::ConfigTools::getParameter(description->min,
"str_param", temp.str_param));
356 EXPECT_TRUE(dynamic_reconfigure::ConfigTools::getParameter(description->min,
"bool_param", temp.bool_param));
357 EXPECT_TRUE(dynamic_reconfigure::ConfigTools::getParameter(description->min,
"float_param", temp.float_param));
358 EXPECT_TRUE(dynamic_reconfigure::ConfigTools::getParameter(description->min,
"uint_param", temp.uint_param));
359 EXPECT_TRUE(dynamic_reconfigure::ConfigTools::getParameter(description->min,
"bag_param__str_param", temp.str_param_in_bag));
360 EXPECT_TRUE(dynamic_reconfigure::ConfigTools::getParameter(description->min,
"vector3_param__x", temp.vector3_param.x));
361 EXPECT_TRUE(dynamic_reconfigure::ConfigTools::getParameter(description->min,
"vector3_param__y", temp.vector3_param.y));
362 EXPECT_TRUE(dynamic_reconfigure::ConfigTools::getParameter(description->min,
"vector3_param__z", temp.vector3_param.z));
363 EXPECT_TRUE(dynamic_reconfigure::ConfigTools::getParameter(description->max,
"int_param", temp.int_param));
364 EXPECT_TRUE(dynamic_reconfigure::ConfigTools::getParameter(description->max,
"double_param", temp.double_param));
365 EXPECT_TRUE(dynamic_reconfigure::ConfigTools::getParameter(description->max,
"str_param", temp.str_param));
366 EXPECT_TRUE(dynamic_reconfigure::ConfigTools::getParameter(description->max,
"bool_param", temp.bool_param));
367 EXPECT_TRUE(dynamic_reconfigure::ConfigTools::getParameter(description->max,
"float_param", temp.float_param));
368 EXPECT_TRUE(dynamic_reconfigure::ConfigTools::getParameter(description->max,
"uint_param", temp.uint_param));
369 EXPECT_TRUE(dynamic_reconfigure::ConfigTools::getParameter(description->max,
"bag_param__str_param", temp.str_param_in_bag));
370 EXPECT_TRUE(dynamic_reconfigure::ConfigTools::getParameter(description->max,
"vector3_param__x", temp.vector3_param.x));
371 EXPECT_TRUE(dynamic_reconfigure::ConfigTools::getParameter(description->max,
"vector3_param__y", temp.vector3_param.y));
372 EXPECT_TRUE(dynamic_reconfigure::ConfigTools::getParameter(description->max,
"vector3_param__z", temp.vector3_param.z));
378 ASSERT_TRUE(tc.loadService(
"reconfigure"));
379 ASSERT_TRUE(tc.provides()->hasService(
"reconfigure"));
383 ASSERT_TRUE(server.get());
392 dynamic_reconfigure::ConfigDescriptionPtr description = server->getDescriptionMessage();
395 EXPECT_TRUE(dynamic_reconfigure::ConfigTools::getParameter(description->dflt,
"new_param", str));
396 EXPECT_TRUE(dynamic_reconfigure::ConfigTools::getParameter(description->min,
"new_param", str));
397 EXPECT_TRUE(dynamic_reconfigure::ConfigTools::getParameter(description->max,
"new_param", str));
400 int main(
int argc,
char **argv) {
401 ::testing::InitGoogleTest(&argc, argv);
412 import(
"rtt_dynamic_reconfigure_tests");
414 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)