params.cpp
Go to the documentation of this file.
2 
3 #include <string>
4 #include <vector>
5 #include <gtest/gtest.h>
6 
7 TEST(ParamTests, getUnusedParamKeys)
8 {
9  ros::NodeHandle pnh("~");
10  std::string ns = pnh.getNamespace();
11 
12  int int_var;
13  swri::getParam(pnh, "used_int_var_1", int_var);
14  swri::param(pnh, "used_int_var_2", int_var, 2);
15  swri::param(pnh, "unset_int_var", int_var, 2);
16 
17  std::string str_var;
18  swri::getParam(pnh, "used_str_var_1", str_var);
19  swri::param(pnh, "used_str_var_2", str_var, "foo");
20  swri::param(pnh, "unset_str_var", str_var, "foo");
21 
22  double dbl_var;
23  swri::getParam(pnh, "used_dbl_var_1", dbl_var);
24  swri::param(pnh, "used_dbl_var_2", dbl_var, 2.0);
25  swri::param(pnh, "unset_dbl_var", dbl_var, 2.0);
26 
27  bool bool_var;
28  swri::getParam(pnh, "used_bool_var_1", bool_var);
29  swri::param(pnh, "used_bool_var_2", bool_var, true);
30  swri::param(pnh, "unset_bool_var", bool_var, true);
31 
32  std::vector<std::string> unused = swri::getUnusedParamKeys(pnh);
33  ASSERT_EQ(4, unused.size());
34  ASSERT_EQ(ns + "/unused_bool_var", unused[0]);
35  ASSERT_EQ(ns + "/unused_dbl_var", unused[1]);
36  ASSERT_EQ(ns + "/unused_int_var", unused[2]);
37  ASSERT_EQ(ns + "/unused_str_var", unused[3]);
38 }
39 
40 int main(int argc, char **argv)
41 {
42  ros::init(argc, argv, "param_test");
43  testing::InitGoogleTest(&argc, argv);
44  return RUN_ALL_TESTS();
45 }
46 
static std::vector< std::string > getUnusedParamKeys(ros::NodeHandle const &n)
Definition: parameters.h:224
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
TEST(ParamTests, getUnusedParamKeys)
Definition: params.cpp:7
static void param(const ros::NodeHandle &nh, const std::string &name, int &variable, const int default_value)
Definition: parameters.h:102
const std::string & getNamespace() const
static bool getParam(const ros::NodeHandle &nh, const std::string &name, int &variable)
Definition: parameters.h:22
int main(int argc, char **argv)
Definition: params.cpp:40


swri_roscpp
Author(s):
autogenerated on Tue Apr 6 2021 02:50:35