12 #include <boost/serialization/serialization.hpp> 16 #include <geometry_msgs/typekit/Vector3.h> 23 #include <gtest/gtest.h> 31 std::set<base::PropertyBase *> right_seen;
37 right_seen.insert(right_prop);
44 right_bag = right_prop;
46 if (!(left_bag == right_bag))
return false;
56 if (right_seen.size() != right.
size())
return false;
63 namespace serialization {
64 template<
class Archive>
65 void serialize(Archive & a, std::pair<std::string, int> &pair,
unsigned int) {
66 using boost::serialization::make_nvp;
67 a & make_nvp(
"first", pair.first);
68 a & make_nvp(
"second", pair.second);
76 typedef std::pair<std::string, int> StringIntPair;
80 StringIntPairTypeInfo()
87 StringIntPairVecTypeInfo()
111 tc->addProperty(
"string", props.string_);
112 tc->addProperty(
"double", props.double_);
113 tc->addProperty(
"float", props.float_);
114 tc->addProperty(
"int", props.int_);
115 tc->addProperty(
"uint", props.uint_);
116 tc->addProperty(
"char", props.char_);
117 tc->addProperty(
"uchar", props.uchar_);
118 tc->addProperty(
"bool", props.bool_);
121 tc->addProperty(
"vstring", props.v_string_);
122 tc->addProperty(
"vdouble", props.v_double_);
123 tc->addProperty(
"vfloat", props.v_float_);
124 tc->addProperty(
"vint", props.v_int_);
125 tc->addProperty(
"vuint", props.v_uint_);
126 tc->addProperty(
"vchar", props.v_char_);
127 tc->addProperty(
"vuchar", props.v_uchar_);
128 tc->addProperty(
"vbool", props.v_bool_);
129 #ifdef RTT_ROSPARAM_EIGEN_SUPPORT 130 tc->addProperty(
"eigenvectordouble", props.eigenvector_double_);
131 tc->addProperty(
"eigenvectorfloat", props.eigenvector_float_);
134 tc->addProperty(
"bag", props.bag_);
135 tc->addProperty(
"vector3", props.vector3_);
136 tc->addProperty(
"pair", props.pair_);
137 tc->addProperty(
"pair_vector", props.pair_vector_);
143 ASSERT_TRUE(tc->loadService(
"rosparam"));
144 ASSERT_TRUE((rosparam = tc->getProvider<
ROSParam>(
"rosparam")).get());
145 ASSERT_TRUE((service = tc->provides()->getService(
"rosparam")).
get());
173 #ifdef RTT_ROSPARAM_EIGEN_SUPPORT 174 Eigen::VectorXd eigenvector_double_;
175 Eigen::VectorXf eigenvector_float_;
200 v_string_.push_back(string_);
201 v_double_.push_back(double_);
202 v_float_.push_back(float_);
203 v_int_.push_back(int_);
204 v_uint_.push_back(uint_);
205 v_char_.push_back(char_);
206 v_uchar_.push_back(uchar_);
207 v_bool_.push_back(bool_);
209 #ifdef RTT_ROSPARAM_EIGEN_SUPPORT 210 eigenvector_double_ = Eigen::Vector3d(5.0, 6.0, 7.0);
211 eigenvector_float_ = Eigen::Vector3f(8.0
f, 9.0
f, 10.0
f);
223 pair_ = std::make_pair(
"abc", 6);
225 pair_vector_.clear();
226 pair_vector_.push_back(std::make_pair(
"one", 1));
227 pair_vector_.push_back(std::make_pair(
"two", 2));
242 v_string_.push_back(string_);
243 v_double_.push_back(double_);
244 v_float_.push_back(float_);
245 v_int_.push_back(int_);
246 v_uint_.push_back(uint_);
247 v_char_.push_back(char_);
248 v_uchar_.push_back(uchar_);
249 v_bool_.push_back(bool_);
251 #ifdef RTT_ROSPARAM_EIGEN_SUPPORT 252 eigenvector_double_ = Eigen::Vector3d(9.6, 3.4, 2.5);
253 eigenvector_float_ = Eigen::Vector3f(2.3
f, 7.6
f, 5.2
f);
285 #ifdef RTT_ROSPARAM_EIGEN_SUPPORT 286 eigenvector_double_.setZero(0);
287 eigenvector_float_.setZero(0);
294 vector3_= geometry_msgs::Vector3();
296 pair_ = std::make_pair(
"", 0);
297 pair_vector_.clear();
307 if (!only_ros_types) {
310 data.
uint_ =
static_cast<unsigned int>(temp);
312 data.
char_ =
static_cast<char>(temp);
314 data.
uchar_ =
static_cast<unsigned char>(temp);
322 if (!only_ros_types) {
323 std::vector<int> vtemp;
325 data.
v_uint_.assign(vtemp.begin(), vtemp.end());
327 data.
v_char_.assign(vtemp.begin(), vtemp.end());
329 data.
v_uchar_.assign(vtemp.begin(), vtemp.end());
333 #ifdef RTT_ROSPARAM_EIGEN_SUPPORT 334 std::vector<double> v_temp_double;
335 EXPECT_TRUE(
ros::param::get(prefix +
"eigenvectordouble", v_temp_double));
336 data.eigenvector_double_ = Eigen::Map<Eigen::VectorXd>(v_temp_double.data(), v_temp_double.size());
337 std::vector<float> v_temp_float;
338 EXPECT_TRUE(
ros::param::get(prefix +
"eigenvectorfloat", v_temp_float));
339 data.eigenvector_float_ = Eigen::Map<Eigen::VectorXf>(v_temp_float.data(), v_temp_float.size());
342 if (!only_ros_types) {
348 switch(it->second.getType()) {
375 for (
int i = 0; i < vec_xmlrpc.
size(); ++i)
382 bool hasFirst = pair_xml.
hasMember(
"first"),
383 hasSecond = pair_xml.
hasMember(
"second");
384 EXPECT_TRUE(hasFirst);
385 EXPECT_TRUE(hasSecond);
387 if (hasFirst && hasSecond)
390 pair.first =
static_cast<std::string
>(pair_xml[
"first"]);
391 pair.second = pair_xml[
"second"];
416 std::vector<int> vtemp;
425 #ifdef RTT_ROSPARAM_EIGEN_SUPPORT 426 std::vector<double> v_temp_double(data.eigenvector_double_.data(), data.eigenvector_double_.data() + data.eigenvector_double_.size());
428 std::vector<float> v_temp_float(data.eigenvector_float_.data(), data.eigenvector_float_.data() + data.eigenvector_float_.size());
433 (void) bag_xmlrpc.
begin();
435 if (bag_string.
ready()) bag_xmlrpc[
"string"] = bag_string.
rvalue();
437 if (bag_string.
ready()) bag_xmlrpc[
"int"] = bag_int.
rvalue();
451 for (std::vector<StringIntPair>::const_iterator pairIt = data.
pair_vector_.begin(); pairIt != data.
pair_vector_.end(); ++pairIt)
456 vec_xmlrpc[idx++] = pair_xmlrpc;
465 prop_it != tc->properties()->end(); ++prop_it)
479 EXPECT_EQ(expected.
string_, actual.
string_) <<
"string values do not match in " << test_name;
480 EXPECT_EQ(expected.
double_, actual.
double_) <<
"double values do not match in " << test_name;
481 EXPECT_EQ(expected.
float_, actual.
float_) <<
"float values do not match in " << test_name;
482 EXPECT_EQ(expected.
int_, actual.
int_) <<
"int values do not match in " << test_name;
483 if (!only_ros_types) {
484 EXPECT_EQ(expected.
uint_, actual.
uint_) <<
"unsigned int values do not match in " << test_name;
485 EXPECT_EQ(expected.
char_, actual.
char_) <<
"char values do not match in " << test_name;
486 EXPECT_EQ(expected.
uchar_, actual.
uchar_) <<
"unsigned char values do not match in " << test_name;
488 EXPECT_EQ(expected.
bool_, actual.
bool_) <<
"bool values do not match in " << test_name;
489 EXPECT_EQ(expected.
v_string_, actual.
v_string_) <<
"string vectors do not match in " << test_name;
490 EXPECT_EQ(expected.
v_double_, actual.
v_double_) <<
"double vectors do not match in " << test_name;
491 EXPECT_EQ(expected.
v_float_, actual.
v_float_) <<
"float vectors do not match in " << test_name;
492 EXPECT_EQ(expected.
v_int_, actual.
v_int_) <<
"int vectors does do match in " << test_name;
493 if (!only_ros_types) {
494 EXPECT_EQ(expected.
v_uint_, actual.
v_uint_) <<
"unsigned int vectors do not match in " << test_name;
495 EXPECT_EQ(expected.
v_char_, actual.
v_char_) <<
"char vectors do not match in " << test_name;
496 EXPECT_EQ(expected.
v_uchar_, actual.
v_uchar_) <<
"unsigned char vectors do not match in " << test_name;
498 EXPECT_EQ(expected.
v_bool_, actual.
v_bool_) <<
"bool vectors do not match in " << test_name;
500 #ifdef RTT_ROSPARAM_EIGEN_SUPPORT 501 EXPECT_EQ(expected.eigenvector_double_, actual.eigenvector_double_) <<
"Eigen::VectorXd values do not match in " << test_name;
502 EXPECT_EQ(expected.eigenvector_float_, actual.eigenvector_float_) <<
"Eigen::VectorXf values do not match in " << test_name;
504 if (!only_ros_types) {
505 EXPECT_EQ(expected.
bag_, actual.
bag_) <<
"PropertyBag contents do not match in " << test_name;
506 EXPECT_EQ(expected.
vector3_.x, actual.
vector3_.x) <<
"geometry_msgs/Vector3 values do not match in " << test_name;
507 EXPECT_EQ(expected.
vector3_.y, actual.
vector3_.y) <<
"geometry_msgs/Vector3 values do not match in " << test_name;
508 EXPECT_EQ(expected.
vector3_.z, actual.
vector3_.z) <<
"geometry_msgs/Vector3 values do not match in " << test_name;
510 EXPECT_EQ(expected.
pair_, actual.
pair_) <<
"std::pair<std::string, int> values does not match in " << test_name;
511 EXPECT_EQ(expected.
pair_vector_, actual.
pair_vector_) <<
"std::vector<std::pair<std::string, int>> values does not match in " << test_name;
537 EXPECT_TRUE(rosparam->setAllRelative());
538 getParameters(
"", params);
539 compareValues(props, params,
"setAllRelative()");
549 EXPECT_TRUE(rosparam->setAllPrivate());
550 getParameters(
"~", params);
551 compareValues(props, params,
"setAllPrivate()");
555 EXPECT_TRUE(rosparam->setAllComponentRelative());
556 getParameters(tc->getName() +
"/", params);
557 compareValues(props, params,
"setAllComponentRelative()");
561 EXPECT_TRUE(rosparam->setAllComponentAbsolute());
562 getParameters(
"/" + tc->getName() +
"/", params);
563 compareValues(props, params,
"setAllComponentAbsolute()");
567 EXPECT_TRUE(rosparam->setAllComponentPrivate());
568 getParameters(
"~" + tc->getName() +
"/", params);
569 compareValues(props, params,
"setAllComponentPrivate()");
579 setParameters(
"", params);
581 EXPECT_TRUE(rosparam->getAllRelative());
582 compareValues(params, props,
"getAllRelative()");
585 setParameters(
"/", params);
587 EXPECT_TRUE(rosparam->getAllAbsolute());
588 compareValues(params, props,
"getAllAbsolute()");
591 setParameters(
"~", params);
593 EXPECT_TRUE(rosparam->getAllPrivate());
594 compareValues(params, props,
"getAllPrivate()");
597 setParameters(
"" + tc->getName() +
"/", params);
599 EXPECT_TRUE(rosparam->getAllComponentRelative());
600 compareValues(params, props,
"getAllComponentRelative()");
603 setParameters(
"/" + tc->getName() +
"/", params);
605 EXPECT_TRUE(rosparam->getAllComponentAbsolute());
606 compareValues(params, props,
"getAllComponentAbsolute()");
609 setParameters(
"~" + tc->getName() +
"/", params);
611 EXPECT_TRUE(rosparam->getAllComponentPrivate());
612 compareValues(params, props,
"getAllComponentPrivate()");
622 prop_it != tc->properties()->end(); ++prop_it) {
623 EXPECT_TRUE(rosparam->setRelative((*prop_it)->getName()));
625 getParameters(
"", params);
626 compareValues(props, params,
"setRelative()");
640 prop_it != tc->properties()->end(); ++prop_it) {
641 EXPECT_TRUE(rosparam->setPrivate((*prop_it)->getName()));
643 getParameters(
"~", params);
644 compareValues(props, params,
"setPrivate()");
649 prop_it != tc->properties()->end(); ++prop_it) {
650 EXPECT_TRUE(rosparam->setComponentRelative((*prop_it)->getName()));
652 getParameters(tc->getName() +
"/", params);
653 compareValues(props, params,
"setComponentRelative()");
658 prop_it != tc->properties()->end(); ++prop_it) {
659 EXPECT_TRUE(rosparam->setComponentAbsolute((*prop_it)->getName()));
661 getParameters(
"/" + tc->getName() +
"/", params);
662 compareValues(props, params,
"setComponentAbsolute()");
667 prop_it != tc->properties()->end(); ++prop_it) {
668 EXPECT_TRUE(rosparam->setComponentPrivate((*prop_it)->getName()));
670 getParameters(
"~" + tc->getName() +
"/", params);
671 compareValues(props, params,
"setComponentPrivate()");
681 setParameters(
"", params);
684 prop_it != tc->properties()->end(); ++prop_it) {
685 EXPECT_TRUE(rosparam->getRelative((*prop_it)->getName()));
687 compareValues(params, props,
"getRelative()");
690 setParameters(
"/", params);
693 prop_it != tc->properties()->end(); ++prop_it) {
694 EXPECT_TRUE(rosparam->getAbsolute((*prop_it)->getName()));
696 compareValues(params, props,
"getAbsolute()");
699 setParameters(
"~", params);
702 prop_it != tc->properties()->end(); ++prop_it) {
703 EXPECT_TRUE(rosparam->getPrivate((*prop_it)->getName()));
705 compareValues(params, props,
"getPrivate()");
708 setParameters(
"" + tc->getName() +
"/", params);
711 prop_it != tc->properties()->end(); ++prop_it) {
712 EXPECT_TRUE(rosparam->getComponentRelative((*prop_it)->getName()));
714 compareValues(params, props,
"getComponentRelative()");
717 setParameters(
"/" + tc->getName() +
"/", params);
720 prop_it != tc->properties()->end(); ++prop_it) {
721 EXPECT_TRUE(rosparam->getComponentAbsolute((*prop_it)->getName()));
723 compareValues(params, props,
"getComponentAbsolute()");
726 setParameters(
"~" + tc->getName() +
"/", params);
729 prop_it != tc->properties()->end(); ++prop_it) {
730 EXPECT_TRUE(rosparam->getComponentPrivate((*prop_it)->getName()));
732 compareValues(params, props,
"getComponentPrivate()");
741 rosparam->setStringComponentPrivate(
"string", props.string_);
742 rosparam->setDoubleComponentPrivate(
"double", props.double_);
743 rosparam->setFloatComponentPrivate(
"float", props.float_);
744 rosparam->setIntComponentPrivate(
"int", props.int_);
745 rosparam->setBoolComponentPrivate(
"bool", props.bool_);
746 rosparam->setVectorOfStringComponentPrivate(
"vstring", props.v_string_);
747 rosparam->setVectorOfDoubleComponentPrivate(
"vdouble", props.v_double_);
748 rosparam->setVectorOfFloatComponentPrivate(
"vfloat", props.v_float_);
749 rosparam->setVectorOfIntComponentPrivate(
"vint", props.v_int_);
750 rosparam->setVectorOfBoolComponentPrivate(
"vbool", props.v_bool_);
751 #ifdef RTT_ROSPARAM_EIGEN_SUPPORT 752 rosparam->setEigenVectorXdComponentPrivate(
"eigenvectordouble", props.eigenvector_double_);
753 rosparam->setEigenVectorXfComponentPrivate(
"eigenvectorfloat", props.eigenvector_float_);
755 getParameters(
"~" + tc->getName() +
"/", params,
true);
756 compareValues(props, params,
"set[Type]ComponentPrivate()",
true);
766 EXPECT_EQ(rosparam->addRosParamPropertyBool(
"bool_parameter").value(), props.bool_);
768 EXPECT_EQ(rosparam->addRosParamPropertyDouble(
"double_parameter").value(), props.double_);
770 EXPECT_EQ(rosparam->addRosParamPropertyFloat(
"float_parameter").value(), props.float_);
772 EXPECT_EQ(rosparam->addRosParamPropertyInt(
"int_parameter").value(), props.int_);
774 EXPECT_EQ(rosparam->addRosParamPropertyString(
"string_parameter").value(), props.string_);
777 props.initialize_alternative();
784 std::string in_string;
785 tc->properties()->getPropertyType<
bool>(
"bool_parameter")->
set(props.bool_);
787 EXPECT_EQ(in_bool, props.bool_);
788 tc->properties()->getPropertyType<
double>(
"double_parameter")->
set(props.double_);
790 EXPECT_EQ(in_double, props.double_);
791 tc->properties()->getPropertyType<
float>(
"float_parameter")->
set(props.float_);
793 EXPECT_EQ(in_float, props.float_);
794 tc->properties()->getPropertyType<
int>(
"int_parameter")->
set(props.int_);
796 EXPECT_EQ(in_int, props.int_);
797 tc->properties()->getPropertyType<std::string>(
"string_parameter")->
set(props.string_);
799 EXPECT_EQ(in_string, props.string_);
806 setParameters(
"~" + tc->getName() +
"/", params);
810 EXPECT_TRUE(rosparam->getStringComponentPrivate(
"string", props.string_));
811 EXPECT_TRUE(rosparam->getDoubleComponentPrivate(
"double", props.double_));
812 EXPECT_TRUE(rosparam->getFloatComponentPrivate(
"float", props.float_));
813 EXPECT_TRUE(rosparam->getIntComponentPrivate(
"int", props.int_));
814 EXPECT_TRUE(rosparam->getBoolComponentPrivate(
"bool", props.bool_));
815 EXPECT_TRUE(rosparam->getVectorOfStringComponentPrivate(
"vstring", props.v_string_));
816 EXPECT_TRUE(rosparam->getVectorOfDoubleComponentPrivate(
"vdouble", props.v_double_));
817 EXPECT_TRUE(rosparam->getVectorOfFloatComponentPrivate(
"vfloat", props.v_float_));
818 EXPECT_TRUE(rosparam->getVectorOfIntComponentPrivate(
"vint", props.v_int_));
819 EXPECT_TRUE(rosparam->getVectorOfBoolComponentPrivate(
"vbool", props.v_bool_));
820 #ifdef RTT_ROSPARAM_EIGEN_SUPPORT 821 EXPECT_TRUE(rosparam->getEigenVectorXdComponentPrivate(
"eigenvectordouble", props.eigenvector_double_));
822 EXPECT_TRUE(rosparam->getEigenVectorXfComponentPrivate(
"eigenvectorfloat", props.eigenvector_float_));
824 compareValues(params, props,
"get[Type]ComponentPrivate()",
true);
827 int main(
int argc,
char** argv) {
828 testing::InitGoogleTest(&argc, argv);
832 remappings[
"__ns"] =
"rtt_rosparam_namespace";
842 return RUN_ALL_TESTS();
void serialize(Archive &a, std::pair< std::string, int > &pair, unsigned int)
static void SetUpTestCase()
ValueStruct::iterator iterator
std::vector< StringIntPair > pair_vector_
int __os_init(int argc, char **argv)
boost::shared_ptr< Service > service
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()
geometry_msgs::Vector3 vector3_
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)
void getParameters(const std::string &prefix, Values &data, bool only_ros_types=false)
std::vector< unsigned int > v_uint_
ROSCPP_DECL bool get(const std::string &key, std::string &s)
void mayLogStdOut(bool tf)
void initialize_alternative()
std::vector< bool > v_bool_
virtual std::string getType() const =0
std::vector< float > v_float_
TypeInfoRepository::shared_ptr Types()
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
bool hasMember(const std::string &name) const
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 setStdStream(std::ostream &stdos)