param_tests.cpp
Go to the documentation of this file.
1 #include <rtt/os/startstop.h>
2 #include <rtt/Logger.hpp>
3 #include <rtt/TaskContext.hpp>
6 
8 
9 #include <geometry_msgs/typekit/Vector3.h>
10 
11 #include <ros/init.h>
12 #include <ros/names.h>
13 #include <ros/param.h>
14 #include <ros/this_node.h>
15 
16 #include <gtest/gtest.h>
17 
18 using namespace RTT;
19 using namespace rtt_rosparam;
20 
21 // helper function to compare PropertyBags
22 namespace RTT {
23  bool operator==(const PropertyBag &left, const PropertyBag &right) {
24  std::set<base::PropertyBase *> right_seen;
25 
26  for(PropertyBag::const_iterator left_it = left.begin(); left_it != left.end(); ++left_it) {
27  base::PropertyBase *left_prop = *left_it;
28  base::PropertyBase *right_prop = right.getProperty(left_prop->getName());
29  if (right_prop) {
30  right_seen.insert(right_prop);
31  if (left_prop->getType() != right_prop->getType()) return false;
32 
33  // Recurse if both properties are PropertyBags
34  Property<PropertyBag> left_bag;
35  left_bag = left_prop;
36  Property<PropertyBag> right_bag;
37  right_bag = right_prop;
38  if (left_bag.ready() && right_bag.ready()) {
39  if (!(left_bag == right_bag)) return false;
40  continue;
41  }
42 
43  // Otherwise,...
44  // ... we believe that the values are the same for now (TODO)
45  }
46  }
47 
48  // check that all values of the right bag have been visited
49  if (right_seen.size() != right.size()) return false;
50 
51  return true;
52  }
53 }
54 
55 class ParamTest : public ::testing::Test {
56  protected:
57  virtual void SetUp() {
58  // Import packages
59  ASSERT_TRUE(RTT::ComponentLoader::Instance()->import("rtt_rosparam", "" ));
60  ASSERT_TRUE(RTT::ComponentLoader::Instance()->import("rtt_geometry_msgs", "" ));
61 
62  tc = new TaskContext("rtt_rosparam_component");
63 
64  // Primitive parameters
65  tc->addProperty("string", props.string_);
66  tc->addProperty("double", props.double_);
67  tc->addProperty("float", props.float_);
68  tc->addProperty("int", props.int_);
69  tc->addProperty("uint", props.uint_);
70  tc->addProperty("char", props.char_);
71  tc->addProperty("uchar", props.uchar_);
72  tc->addProperty("bool", props.bool_);
73 
74  // Vector parameters
75  tc->addProperty("vstring", props.v_string_);
76  tc->addProperty("vdouble", props.v_double_);
77  tc->addProperty("vfloat", props.v_float_);
78  tc->addProperty("vint", props.v_int_);
79  tc->addProperty("vuint", props.v_uint_);
80  tc->addProperty("vchar", props.v_char_);
81  tc->addProperty("vuchar", props.v_uchar_);
82  tc->addProperty("vbool", props.v_bool_);
83 
84  tc->addProperty("eigenvectordouble", props.eigenvector_double_);
85  tc->addProperty("eigenvectorfloat", props.eigenvector_float_);
86 
87  // Struct parameters
88  tc->addProperty("bag", props.bag_);
89  tc->addProperty("vector3", props.vector3_);
90 
91  // Delete parameters that might be left from previous executions
92  deleteParameters();
93 
94  // Load rosparam service and get pointers
95  ASSERT_TRUE(tc->loadService("rosparam"));
96  ASSERT_TRUE((rosparam = tc->getProvider<ROSParam>("rosparam")).get());
97  ASSERT_TRUE((service = tc->provides()->getService("rosparam")).get());
98  }
99 
100  virtual void TearDown() {
101  deleteParameters();
102  delete tc;
103  }
104 
105  struct Values {
106  // Primitive parameters
107  std::string string_;
108  double double_;
109  float float_;
110  int int_;
111  unsigned int uint_;
112  char char_;
113  unsigned char uchar_;
114  bool bool_;
115 
116  // Vector parameters_
117  std::vector<std::string> v_string_;
118  std::vector<double> v_double_;
119  std::vector<float> v_float_;
120  std::vector<int> v_int_;
121  std::vector<unsigned int> v_uint_;
122  std::vector<char> v_char_;
123  std::vector<unsigned char> v_uchar_;
124  std::vector<bool> v_bool_;
125 
126  Eigen::VectorXd eigenvector_double_;
127  Eigen::VectorXf eigenvector_float_;
128 
129  // Struct parameters
131  geometry_msgs::Vector3 vector3_;
132 
133  Values() {
134  reset();
135  }
136 
137  void initialize() {
138  // Primitive parameters
139  string_ = "foobar";
140  double_ = 5.5;
141  float_ = 6.5f;
142  int_ = -7;
143  uint_ = 8u;
144  char_ = 'c';
145  uchar_ = 255u;
146  bool_ = true;
147 
148  // Vector parameters
149  v_string_.push_back(string_);
150  v_double_.push_back(double_);
151  v_float_.push_back(float_);
152  v_int_.push_back(int_);
153  v_uint_.push_back(uint_);
154  v_char_.push_back(char_);
155  v_uchar_.push_back(uchar_);
156  v_bool_.push_back(bool_);
157 
158  eigenvector_double_ = Eigen::Vector3d(5.0, 6.0, 7.0);
159  eigenvector_float_ = Eigen::Vector3f(8.0f, 9.0f, 10.0f);
160 
161  // Struct parameters
162  bag_.clear();
163  bag_.ownProperty(new RTT::Property<std::string>("string", "", "yet another value"));
164  bag_.ownProperty(new RTT::Property<int>("int", "", 20));
165 
166  vector3_.x = 20.0;
167  vector3_.y = 21.0;
168  vector3_.z = 22.0;
169  }
170 
171  void reset() {
172  string_.clear();
173  double_ = 0.0;
174  float_ = 0.0f;
175  int_ = 0;
176  uint_ = 0u;
177  char_ = 0;
178  uchar_ = 0u;
179  bool_ = false;
180 
181  v_string_.clear();
182  v_double_.clear();
183  v_float_.clear();
184  v_int_.clear();
185  v_uint_.clear();
186  v_char_.clear();
187  v_uchar_.clear();
188  v_bool_.clear();
189 
190  eigenvector_double_.setZero(0);
191  eigenvector_float_.setZero(0);
192 
193  bag_.clear();
194  bag_.ownProperty(new RTT::Property<std::string>("string", "", std::string()));
195  bag_.ownProperty(new RTT::Property<int>("int", "", 0));
196 
197  vector3_= geometry_msgs::Vector3();
198  }
199  } props, params;
200 
201 
202  void getParameters(const std::string &prefix, Values &data, bool only_ros_types = false) {
203  EXPECT_TRUE(ros::param::get(prefix + "string", data.string_));
204  EXPECT_TRUE(ros::param::get(prefix + "double", data.double_));
205  EXPECT_TRUE(ros::param::get(prefix + "float", data.float_));
206  EXPECT_TRUE(ros::param::get(prefix + "int", data.int_));
207  if (!only_ros_types) {
208  int temp;
209  EXPECT_TRUE(ros::param::get(prefix + "uint", temp));
210  data.uint_ = static_cast<unsigned int>(temp);
211  EXPECT_TRUE(ros::param::get(prefix + "char", temp));
212  data.char_ = static_cast<char>(temp);
213  EXPECT_TRUE(ros::param::get(prefix + "uchar", temp));
214  data.uchar_ = static_cast<unsigned char>(temp);
215  }
216  EXPECT_TRUE(ros::param::get(prefix + "bool", data.bool_));
217 
218  EXPECT_TRUE(ros::param::get(prefix + "vstring", data.v_string_));
219  EXPECT_TRUE(ros::param::get(prefix + "vdouble", data.v_double_));
220  EXPECT_TRUE(ros::param::get(prefix + "vfloat", data.v_float_));
221  EXPECT_TRUE(ros::param::get(prefix + "vint", data.v_int_));
222  if (!only_ros_types) {
223  std::vector<int> vtemp;
224  EXPECT_TRUE(ros::param::get(prefix + "vuint", vtemp));
225  data.v_uint_.assign(vtemp.begin(), vtemp.end());
226  EXPECT_TRUE(ros::param::get(prefix + "vchar", vtemp));
227  data.v_char_.assign(vtemp.begin(), vtemp.end());
228  EXPECT_TRUE(ros::param::get(prefix + "vuchar", vtemp));
229  data.v_uchar_.assign(vtemp.begin(), vtemp.end());
230  }
231  EXPECT_TRUE(ros::param::get(prefix + "vbool", data.v_bool_));
232 
233  std::vector<double> v_temp_double;
234  EXPECT_TRUE(ros::param::get(prefix + "eigenvectordouble", v_temp_double));
235  data.eigenvector_double_ = Eigen::Map<Eigen::VectorXd>(v_temp_double.data(), v_temp_double.size());
236  std::vector<float> v_temp_float;
237  EXPECT_TRUE(ros::param::get(prefix + "eigenvectorfloat", v_temp_float));
238  data.eigenvector_float_ = Eigen::Map<Eigen::VectorXf>(v_temp_float.data(), v_temp_float.size());
239 
240  if (!only_ros_types) {
241  data.bag_.clear();
242  XmlRpc::XmlRpcValue bag_xmlrpc;
243  ros::param::get(prefix + "bag", bag_xmlrpc);
244  if (bag_xmlrpc.valid() && bag_xmlrpc.getType() == XmlRpc::XmlRpcValue::TypeStruct) {
245  for(XmlRpc::XmlRpcValue::iterator it = bag_xmlrpc.begin(); it != bag_xmlrpc.end(); ++it) {
246  switch(it->second.getType()) {
248  data.bag_.ownProperty(new RTT::Property<std::string>(it->first, "", it->second));
249  break;
251  data.bag_.ownProperty(new RTT::Property<int>(it->first, "", it->second));
252  break;
253  default:
254  break;
255  }
256  }
257  }
258 
259  EXPECT_TRUE(ros::param::get(prefix + "vector3/x", data.vector3_.x));
260  EXPECT_TRUE(ros::param::get(prefix + "vector3/y", data.vector3_.y));
261  EXPECT_TRUE(ros::param::get(prefix + "vector3/z", data.vector3_.z));
262  }
263  }
264 
265  void setParameters(const std::string &prefix, const Values &data) {
266  ros::param::set(prefix + "string", data.string_);
267  ros::param::set(prefix + "double", data.double_);
268  ros::param::set(prefix + "float", data.float_);
269  ros::param::set(prefix + "int", data.int_);
270  int temp;
271  ros::param::set(prefix + "uint", temp = data.uint_);
272  ros::param::set(prefix + "char", temp = data.char_);
273  ros::param::set(prefix + "uchar", temp = data.uchar_);
274  ros::param::set(prefix + "bool", data.bool_);
275 
276  ros::param::set(prefix + "vstring", data.v_string_);
277  ros::param::set(prefix + "vdouble", data.v_double_);
278  ros::param::set(prefix + "vfloat", data.v_float_);
279  ros::param::set(prefix + "vint", data.v_int_);
280  std::vector<int> vtemp;
281  vtemp.assign(data.v_uint_.begin(), data.v_uint_.end());
282  ros::param::set(prefix + "vuint", vtemp);
283  vtemp.assign(data.v_char_.begin(), data.v_char_.end());
284  ros::param::set(prefix + "vchar", vtemp);
285  vtemp.assign(data.v_uchar_.begin(), data.v_uchar_.end());
286  ros::param::set(prefix + "vuchar", vtemp);
287  ros::param::set(prefix + "vbool", data.v_bool_);
288 
289  std::vector<double> v_temp_double(data.eigenvector_double_.data(), data.eigenvector_double_.data() + data.eigenvector_double_.size());
290  ros::param::set(prefix + "eigenvectordouble", v_temp_double);
291  std::vector<float> v_temp_float(data.eigenvector_float_.data(), data.eigenvector_float_.data() + data.eigenvector_float_.size());
292  ros::param::set(prefix + "eigenvectorfloat", v_temp_float);
293 
294  XmlRpc::XmlRpcValue bag_xmlrpc;
295  (void) bag_xmlrpc.begin(); // force struct type
296  RTT::Property<std::string> bag_string = data.bag_.getProperty("string");
297  if (bag_string.ready()) bag_xmlrpc["string"] = bag_string.rvalue();
298  RTT::Property<int> bag_int = data.bag_.getProperty("int");
299  if (bag_string.ready()) bag_xmlrpc["int"] = bag_int.rvalue();
300  ros::param::set(prefix + "bag", bag_xmlrpc);
301 
302  ros::param::set(prefix + "vector3/x", data.vector3_.x);
303  ros::param::set(prefix + "vector3/y", data.vector3_.y);
304  ros::param::set(prefix + "vector3/z", data.vector3_.z);
305  }
306 
308  for(RTT::PropertyBag::const_iterator prop_it = tc->properties()->begin();
309  prop_it != tc->properties()->end(); ++prop_it)
310  {
311  RTT::base::PropertyBase *prop = *prop_it;
312  ros::param::del(prop->getName()); // RELATIVE
313  ros::param::del(std::string("/") + prop->getName()); // ABSOLUTE
314 // ros::param::del(std::string("~") + prop->getName()); // PRIVATE
315  ros::param::del(tc->getName() + "/" + prop->getName()); // COMPONENT_RELATIVE
316  ros::param::del(std::string("/") + tc->getName() + "/" + prop->getName()); // COMPONENT_ABSOLUTE
317 // ros::param::del(std::string("~") + tc->getName() + "/" + prop->getName()); // COMPONENT_PRIVATE
318  }
319  ros::param::del("~");
320  }
321 
322  void compareValues(const Values &expected, const Values &actual, const std::string &test_name, bool only_ros_types = false) {
323  EXPECT_EQ(expected.string_, actual.string_) << "string values do not match in " << test_name;
324  EXPECT_EQ(expected.double_, actual.double_) << "double values do not match in " << test_name;
325  EXPECT_EQ(expected.float_, actual.float_) << "float values do not match in " << test_name;
326  EXPECT_EQ(expected.int_, actual.int_) << "int values do not match in " << test_name;
327  if (!only_ros_types) {
328  EXPECT_EQ(expected.uint_, actual.uint_) << "unsigned int values do not match in " << test_name;
329  EXPECT_EQ(expected.char_, actual.char_) << "char values do not match in " << test_name;
330  EXPECT_EQ(expected.uchar_, actual.uchar_) << "unsigned char values do not match in " << test_name;
331  }
332  EXPECT_EQ(expected.bool_, actual.bool_) << "bool values do not match in " << test_name;
333  EXPECT_EQ(expected.v_string_, actual.v_string_) << "string vectors do not match in " << test_name;
334  EXPECT_EQ(expected.v_double_, actual.v_double_) << "double vectors do not match in " << test_name;
335  EXPECT_EQ(expected.v_float_, actual.v_float_) << "float vectors do not match in " << test_name;
336  EXPECT_EQ(expected.v_int_, actual.v_int_) << "int vectors does do match in " << test_name;
337  if (!only_ros_types) {
338  EXPECT_EQ(expected.v_uint_, actual.v_uint_) << "unsigned int vectors do not match in " << test_name;
339  EXPECT_EQ(expected.v_char_, actual.v_char_) << "char vectors do not match in " << test_name;
340  EXPECT_EQ(expected.v_uchar_, actual.v_uchar_) << "unsigned char vectors do not match in " << test_name;
341  }
342  EXPECT_EQ(expected.v_bool_, actual.v_bool_) << "bool vectors do not match in " << test_name;
343 
344  EXPECT_EQ(expected.eigenvector_double_, actual.eigenvector_double_) << "Eigen::VectorXd values do not match in " << test_name;
345  EXPECT_EQ(expected.eigenvector_float_, actual.eigenvector_float_) << "Eigen::VectorXf values do not match in " << test_name;
346  if (!only_ros_types) {
347  EXPECT_EQ(expected.bag_, actual.bag_) << "PropertyBag contents do not match in " << test_name;
348  EXPECT_EQ(expected.vector3_.x, actual.vector3_.x) << "geometry_msgs/Vector3 values do not match in " << test_name;
349  EXPECT_EQ(expected.vector3_.y, actual.vector3_.y) << "geometry_msgs/Vector3 values do not match in " << test_name;
350  EXPECT_EQ(expected.vector3_.z, actual.vector3_.z) << "geometry_msgs/Vector3 values do not match in " << test_name;
351  }
352  }
353 
357 };
358 
359 TEST_F(ParamTest, Constants)
360 {
361  EXPECT_EQ(RELATIVE, Constant<int>(service->getValue("RELATIVE")).get());
362  EXPECT_EQ(ABSOLUTE, Constant<int>(service->getValue("ABSOLUTE")).get());
363  EXPECT_EQ(PRIVATE, Constant<int>(service->getValue("PRIVATE")).get());
364  EXPECT_EQ(COMPONENT_PRIVATE, Constant<int>(service->getValue("COMPONENT_PRIVATE")).get());
365  EXPECT_EQ(COMPONENT_RELATIVE, Constant<int>(service->getValue("COMPONENT_RELATIVE")).get());
366  EXPECT_EQ(COMPONENT_ABSOLUTE, Constant<int>(service->getValue("COMPONENT_ABSOLUTE")).get());
367  EXPECT_EQ(COMPONENT, Constant<int>(service->getValue("COMPONENT")).get());
368 }
369 
370 TEST_F(ParamTest, SetAllPropertiesOnParameterServer)
371 {
372  // initialize properties to some values
373  props.initialize();
374 
375  // setAllRelative()
376  EXPECT_TRUE(rosparam->setAllRelative());
377  getParameters("", params);
378  compareValues(props, params, "setAllRelative()");
379  params.reset();
380 
381 // // setAllAbsolute()
382 // EXPECT_TRUE(rosparam->setAllAbsolute());
383 // getParameters("/", params);
384 // compareValues(props, params, "setAllAbsolute()");
385 // params.reset();
386 
387  // setAllPrivate()
388  EXPECT_TRUE(rosparam->setAllPrivate());
389  getParameters("~", params);
390  compareValues(props, params, "setAllPrivate()");
391  params.reset();
392 
393  // setAllComponentRelative()
394  EXPECT_TRUE(rosparam->setAllComponentRelative());
395  getParameters(tc->getName() + "/", params);
396  compareValues(props, params, "setAllComponentRelative()");
397  params.reset();
398 
399  // setAllComponentAbsolute()
400  EXPECT_TRUE(rosparam->setAllComponentAbsolute());
401  getParameters("/" + tc->getName() + "/", params);
402  compareValues(props, params, "setAllComponentAbsolute()");
403  params.reset();
404 
405  // setAllComponentPrivate()
406  EXPECT_TRUE(rosparam->setAllComponentPrivate());
407  getParameters("~" + tc->getName() + "/", params);
408  compareValues(props, params, "setAllComponentPrivate()");
409  params.reset();
410 }
411 
412 TEST_F(ParamTest, GetAllPropertiesFromParameterServer)
413 {
414  // initialize parameters to some values
415  params.initialize();
416 
417  // getAllRelative()
418  setParameters("", params);
419  props.reset();
420  EXPECT_TRUE(rosparam->getAllRelative());
421  compareValues(params, props, "getAllRelative()");
422 
423  // getAllAbsolute()
424  setParameters("/", params);
425  props.reset();
426  EXPECT_TRUE(rosparam->getAllAbsolute());
427  compareValues(params, props, "getAllAbsolute()");
428 
429  // getAllPrivate()
430  setParameters("~", params);
431  props.reset();
432  EXPECT_TRUE(rosparam->getAllPrivate());
433  compareValues(params, props, "getAllPrivate()");
434 
435  // getAllComponentRelative()
436  setParameters("" + tc->getName() + "/", params);
437  props.reset();
438  EXPECT_TRUE(rosparam->getAllComponentRelative());
439  compareValues(params, props, "getAllComponentRelative()");
440 
441  // getAllComponentAbsolute()
442  setParameters("/" + tc->getName() + "/", params);
443  props.reset();
444  EXPECT_TRUE(rosparam->getAllComponentAbsolute());
445  compareValues(params, props, "getAllComponentAbsolute()");
446 
447  // getAllComponentPrivate()
448  setParameters("~" + tc->getName() + "/", params);
449  props.reset();
450  EXPECT_TRUE(rosparam->getAllComponentPrivate());
451  compareValues(params, props, "getAllComponentPrivate()");
452 }
453 
454 TEST_F(ParamTest, SetSinglePropertyOnParameterServer)
455 {
456  // initialize properties to some values
457  props.initialize();
458 
459  // setRelative()
460  for (PropertyBag::const_iterator prop_it = tc->properties()->begin();
461  prop_it != tc->properties()->end(); ++prop_it) {
462  EXPECT_TRUE(rosparam->setRelative((*prop_it)->getName()));
463  }
464  getParameters("", params);
465  compareValues(props, params, "setRelative()");
466  params.reset();
467 
468 // // setAbsolute()
469 // for (PropertyBag::const_iterator prop_it = tc->properties()->begin();
470 // prop_it != tc->properties()->end(); ++prop_it) {
471 // EXPECT_TRUE(rosparam->setAbsolute((*prop_it)->getName()));
472 // }
473 // getParameters("/", params);
474 // compareValues(props, params, "setAbsolute()");
475 // params.reset();
476 
477  // setPrivate()
478  for (PropertyBag::const_iterator prop_it = tc->properties()->begin();
479  prop_it != tc->properties()->end(); ++prop_it) {
480  EXPECT_TRUE(rosparam->setPrivate((*prop_it)->getName()));
481  }
482  getParameters("~", params);
483  compareValues(props, params, "setPrivate()");
484  params.reset();
485 
486  // setComponentRelative()
487  for (PropertyBag::const_iterator prop_it = tc->properties()->begin();
488  prop_it != tc->properties()->end(); ++prop_it) {
489  EXPECT_TRUE(rosparam->setComponentRelative((*prop_it)->getName()));
490  }
491  getParameters(tc->getName() + "/", params);
492  compareValues(props, params, "setComponentRelative()");
493  params.reset();
494 
495  // setComponentAbsolute()
496  for (PropertyBag::const_iterator prop_it = tc->properties()->begin();
497  prop_it != tc->properties()->end(); ++prop_it) {
498  EXPECT_TRUE(rosparam->setComponentAbsolute((*prop_it)->getName()));
499  }
500  getParameters("/" + tc->getName() + "/", params);
501  compareValues(props, params, "setComponentAbsolute()");
502  params.reset();
503 
504  // setComponentPrivate()
505  for (PropertyBag::const_iterator prop_it = tc->properties()->begin();
506  prop_it != tc->properties()->end(); ++prop_it) {
507  EXPECT_TRUE(rosparam->setComponentPrivate((*prop_it)->getName()));
508  }
509  getParameters("~" + tc->getName() + "/", params);
510  compareValues(props, params, "setComponentPrivate()");
511  params.reset();
512 }
513 
514 TEST_F(ParamTest, GetSinglePropertyFromParameterServer)
515 {
516  // initialize parameters to some values
517  params.initialize();
518 
519  // getRelative()
520  setParameters("", params);
521  props.reset();
522  for (PropertyBag::const_iterator prop_it = tc->properties()->begin();
523  prop_it != tc->properties()->end(); ++prop_it) {
524  EXPECT_TRUE(rosparam->getRelative((*prop_it)->getName()));
525  }
526  compareValues(params, props, "getRelative()");
527 
528  // getAbsolute()
529  setParameters("/", params);
530  props.reset();
531  for (PropertyBag::const_iterator prop_it = tc->properties()->begin();
532  prop_it != tc->properties()->end(); ++prop_it) {
533  EXPECT_TRUE(rosparam->getAbsolute((*prop_it)->getName()));
534  }
535  compareValues(params, props, "getAbsolute()");
536 
537  // getPrivate()
538  setParameters("~", params);
539  props.reset();
540  for (PropertyBag::const_iterator prop_it = tc->properties()->begin();
541  prop_it != tc->properties()->end(); ++prop_it) {
542  EXPECT_TRUE(rosparam->getPrivate((*prop_it)->getName()));
543  }
544  compareValues(params, props, "getPrivate()");
545 
546  // getComponentRelative()
547  setParameters("" + tc->getName() + "/", params);
548  props.reset();
549  for (PropertyBag::const_iterator prop_it = tc->properties()->begin();
550  prop_it != tc->properties()->end(); ++prop_it) {
551  EXPECT_TRUE(rosparam->getComponentRelative((*prop_it)->getName()));
552  }
553  compareValues(params, props, "getComponentRelative()");
554 
555  // getComponentAbsolute()
556  setParameters("/" + tc->getName() + "/", params);
557  props.reset();
558  for (PropertyBag::const_iterator prop_it = tc->properties()->begin();
559  prop_it != tc->properties()->end(); ++prop_it) {
560  EXPECT_TRUE(rosparam->getComponentAbsolute((*prop_it)->getName()));
561  }
562  compareValues(params, props, "getComponentAbsolute()");
563 
564  // getComponentPrivate()
565  setParameters("~" + tc->getName() + "/", params);
566  props.reset();
567  for (PropertyBag::const_iterator prop_it = tc->properties()->begin();
568  prop_it != tc->properties()->end(); ++prop_it) {
569  EXPECT_TRUE(rosparam->getComponentPrivate((*prop_it)->getName()));
570  }
571  compareValues(params, props, "getComponentPrivate()");
572 }
573 
574 TEST_F(ParamTest, SetValueOnParameterServer)
575 {
576  // initialize properties to some values
577  props.initialize();
578 
579  // fetch parameters one by one
580  rosparam->setStringComponentPrivate("string", props.string_);
581  rosparam->setDoubleComponentPrivate("double", props.double_);
582  rosparam->setFloatComponentPrivate("float", props.float_);
583  rosparam->setIntComponentPrivate("int", props.int_);
584  rosparam->setBoolComponentPrivate("bool", props.bool_);
585  rosparam->setVectorOfStringComponentPrivate("vstring", props.v_string_);
586  rosparam->setVectorOfDoubleComponentPrivate("vdouble", props.v_double_);
587  rosparam->setVectorOfFloatComponentPrivate("vfloat", props.v_float_);
588  rosparam->setVectorOfIntComponentPrivate("vint", props.v_int_);
589  rosparam->setVectorOfBoolComponentPrivate("vbool", props.v_bool_);
590  rosparam->setEigenVectorXdComponentPrivate("eigenvectordouble", props.eigenvector_double_);
591  rosparam->setEigenVectorXfComponentPrivate("eigenvectorfloat", props.eigenvector_float_);
592  getParameters("~" + tc->getName() + "/", params, /* only_ros_types = */ true);
593  compareValues(props, params, "set[Type]ComponentPrivate()", /* only_ros_types = */ true);
594 }
595 
596 TEST_F(ParamTest, GetValueFromParameterServer)
597 {
598  // initialize parameters to some values
599  params.initialize();
600  setParameters("~" + tc->getName() + "/", params);
601 
602  // fetch parameters one by one
603  props.reset();
604  EXPECT_TRUE(rosparam->getStringComponentPrivate("string", props.string_));
605  EXPECT_TRUE(rosparam->getDoubleComponentPrivate("double", props.double_));
606  EXPECT_TRUE(rosparam->getFloatComponentPrivate("float", props.float_));
607  EXPECT_TRUE(rosparam->getIntComponentPrivate("int", props.int_));
608  EXPECT_TRUE(rosparam->getBoolComponentPrivate("bool", props.bool_));
609  EXPECT_TRUE(rosparam->getVectorOfStringComponentPrivate("vstring", props.v_string_));
610  EXPECT_TRUE(rosparam->getVectorOfDoubleComponentPrivate("vdouble", props.v_double_));
611  EXPECT_TRUE(rosparam->getVectorOfFloatComponentPrivate("vfloat", props.v_float_));
612  EXPECT_TRUE(rosparam->getVectorOfIntComponentPrivate("vint", props.v_int_));
613  EXPECT_TRUE(rosparam->getVectorOfBoolComponentPrivate("vbool", props.v_bool_));
614  EXPECT_TRUE(rosparam->getEigenVectorXdComponentPrivate("eigenvectordouble", props.eigenvector_double_));
615  EXPECT_TRUE(rosparam->getEigenVectorXfComponentPrivate("eigenvectorfloat", props.eigenvector_float_));
616  compareValues(params, props, "get[Type]ComponentPrivate()", /* only_ros_types = */ true);
617 }
618 
619 int main(int argc, char** argv) {
620  testing::InitGoogleTest(&argc, argv);
621 
622  // Start ROS node
623  ros::M_string remappings;
624  remappings["__ns"] = "rtt_rosparam_namespace";
625  ros::init(remappings, "rtt_rosparam_tests_node", ros::init_options::AnonymousName);
626 
627  // Initialize Orocos
628  __os_init(argc, argv);
629 
630  RTT::Logger::log().setStdStream(std::cerr);
632 // RTT::Logger::log().setLogLevel(RTT::Logger::Debug);
633 
634  return RUN_ALL_TESTS();
635 }
636 
iterator end()
ValueStruct::iterator iterator
f
unsigned char uchar_
int __os_init(int argc, char **argv)
Eigen::VectorXd eigenvector_double_
boost::shared_ptr< Service > service
bool valid() const
COMPONENT_ABSOLUTE
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
std::vector< unsigned char > v_uchar_
const_reference_t rvalue() const
Type const & getType() const
static boost::shared_ptr< ComponentLoader > Instance()
PRIVATE
RTT::PropertyBag bag_
geometry_msgs::Vector3 vector3_
std::string string_
std::map< std::string, std::string > M_string
bool ownProperty(base::PropertyBase *p)
std::vector< char > v_char_
ROSCPP_DECL void set(const std::string &key, const XmlRpc::XmlRpcValue &v)
int main(int argc, char **argv)
virtual void TearDown()
void getParameters(const std::string &prefix, Values &data, bool only_ros_types=false)
Eigen::VectorXf eigenvector_float_
std::vector< unsigned int > v_uint_
TaskContext * tc
virtual void SetUp()
Definition: param_tests.cpp:57
ROSCPP_DECL bool get(const std::string &key, std::string &s)
void mayLogStdOut(bool tf)
std::vector< bool > v_bool_
virtual std::string getType() const =0
std::vector< float > v_float_
Properties::const_iterator const_iterator
TEST_F(ParamTest, Constants)
static bool operator==(const ConnPolicy &, const ConnPolicy &)
void compareValues(const Values &expected, const Values &actual, const std::string &test_name, bool only_ros_types=false)
std::vector< double > v_double_
ROSCPP_DECL bool del(const std::string &key)
base::PropertyBase * getProperty(const std::string &name) const
ABSOLUTE
static Logger & log()
COMPONENT_PRIVATE
boost::shared_ptr< ROSParam > rosparam
const std::string & getName() const
void setParameters(const std::string &prefix, const Values &data)
std::vector< std::string > v_string_
std::vector< int > v_int_
void deleteParameters()
void setStdStream(std::ostream &stdos)
size_t size() const
unsigned int uint_
COMPONENT_RELATIVE
iterator begin()
COMPONENT
RELATIVE


rtt_rosparam_tests
Author(s): Johannes Meyer
autogenerated on Sat Jun 8 2019 18:06:09