test_defaults.cpp
Go to the documentation of this file.
1 #include <gtest/gtest.h>
2 #include <ros/ros.h>
3 #include <rosparam_handler/DefaultsParameters.h>
4 
5 typedef rosparam_handler::DefaultsParameters ParamType;
6 typedef rosparam_handler::DefaultsConfig ConfigType;
7 
8 TEST(RosparamHandler, Defaults) {
9  ParamType testParams(ros::NodeHandle("~"));
10  ASSERT_NO_THROW(testParams.fromParamServer());
11 
12  ASSERT_EQ(1, testParams.int_param_w_default);
13  ASSERT_DOUBLE_EQ(1.1, testParams.double_param_w_default);
14  ASSERT_EQ("Hello World", testParams.str_param_w_default);
15  ASSERT_EQ(true, testParams.bool_param_w_default);
16 
17  ASSERT_EQ(std::vector<int>({1, 2, 3}), testParams.vector_int_param_w_default);
18  ASSERT_EQ(std::vector<double>({1.1, 1.2, 1.3}), testParams.vector_double_param_w_default);
19  ASSERT_EQ(std::vector<bool>({false, true}), testParams.vector_bool_param_w_default);
20  ASSERT_EQ(std::vector<std::string>({"Hello", "World"}), testParams.vector_string_param_w_default);
21 
22  std::map<std::string, std::string> tmp{{"Hello", "World"}};
23  ASSERT_EQ(tmp, testParams.map_param_w_default);
24 
25  ASSERT_EQ(1, testParams.enum_param_w_default);
26 }
27 
28 TEST(RosparamHandler, DefaultsOnParamServer) {
29  ros::NodeHandle nh("~");
30  ParamType testParams(nh);
31  ASSERT_NO_THROW(testParams.fromParamServer());
32 
33  // values should now be set on param server
34  {
35  int int_param;
36  ASSERT_TRUE(nh.getParam("int_param_w_default", int_param));
37  ASSERT_EQ(int_param, testParams.int_param_w_default);
38  }
39  {
40  double double_param;
41  ASSERT_TRUE(nh.getParam("double_param_w_default", double_param));
42  EXPECT_EQ(double_param, testParams.double_param_w_default);
43  }
44  {
45  bool bool_param;
46  ASSERT_TRUE(nh.getParam("bool_param_w_default", bool_param));
47  EXPECT_EQ(bool_param, testParams.bool_param_w_default);
48  }
49  {
50  std::string string_param;
51  ASSERT_TRUE(nh.getParam("str_param_w_default", string_param));
52  EXPECT_EQ(string_param, testParams.str_param_w_default);
53  }
54  {
55  std::vector<int> vector_int_param;
56  ASSERT_TRUE(nh.getParam("vector_int_param_w_default", vector_int_param));
57  EXPECT_EQ(vector_int_param, testParams.vector_int_param_w_default);
58  }
59  {
60  std::vector<double> vector_double_param;
61  ASSERT_TRUE(nh.getParam("vector_double_param_w_default", vector_double_param));
62  EXPECT_EQ(vector_double_param, testParams.vector_double_param_w_default);
63  }
64  {
65  std::vector<bool> vector_bool_param;
66  ASSERT_TRUE(nh.getParam("vector_bool_param_w_default", vector_bool_param));
67  EXPECT_EQ(vector_bool_param, testParams.vector_bool_param_w_default);
68  }
69  {
70  std::vector<std::string> vector_string_param;
71  ASSERT_TRUE(nh.getParam("vector_string_param_w_default", vector_string_param));
72  EXPECT_EQ(vector_string_param, testParams.vector_string_param_w_default);
73  }
74  {
75  std::map<std::string, std::string> map_param_w_default;
76  ASSERT_TRUE(nh.getParam("map_param_w_default", map_param_w_default));
77  EXPECT_EQ(map_param_w_default, testParams.map_param_w_default);
78  }
79  {
80  int enum_param;
81  ASSERT_TRUE(nh.getParam("enum_param_w_default", enum_param));
82  EXPECT_EQ(enum_param, testParams.enum_param_w_default);
83  }
84 }
85 
86 TEST(RosparamHandler, SetParamOnServer) {
87  ros::NodeHandle nh("~");
88  ParamType testParams(nh);
89  ASSERT_NO_THROW(testParams.fromParamServer());
90 
91  testParams.int_param_w_default = 2;
92  testParams.double_param_w_default = 2.2;
93  testParams.str_param_w_default = "World Hello";
94  testParams.bool_param_w_default = false;
95  testParams.vector_int_param_w_default = std::vector<int>{3, 2, 1};
96  testParams.vector_double_param_w_default = std::vector<double>{1.3, 1.2, 1.2};
97  testParams.vector_bool_param_w_default = std::vector<bool>{true, false};
98  testParams.vector_string_param_w_default = std::vector<std::string>{"World", "Hello"};
99  testParams.map_param_w_default = std::map<std::string, std::string>{{"World", "Hello"}};
100  testParams.enum_param_w_default = 2;
101 
102  testParams.toParamServer();
103 
104  // values should now be set on param server
105  {
106  int int_param;
107  ASSERT_TRUE(nh.getParam("int_param_w_default", int_param));
108  ASSERT_EQ(int_param, testParams.int_param_w_default);
109  }
110  {
111  double double_param;
112  ASSERT_TRUE(nh.getParam("double_param_w_default", double_param));
113  EXPECT_EQ(double_param, testParams.double_param_w_default);
114  }
115  {
116  bool bool_param;
117  ASSERT_TRUE(nh.getParam("bool_param_w_default", bool_param));
118  EXPECT_EQ(bool_param, testParams.bool_param_w_default);
119  }
120  {
121  std::string string_param;
122  ASSERT_TRUE(nh.getParam("str_param_w_default", string_param));
123  EXPECT_EQ(string_param, testParams.str_param_w_default);
124  }
125  {
126  std::vector<int> vector_int_param;
127  ASSERT_TRUE(nh.getParam("vector_int_param_w_default", vector_int_param));
128  EXPECT_EQ(vector_int_param, testParams.vector_int_param_w_default);
129  }
130  {
131  std::vector<double> vector_double_param;
132  ASSERT_TRUE(nh.getParam("vector_double_param_w_default", vector_double_param));
133  EXPECT_EQ(vector_double_param, testParams.vector_double_param_w_default);
134  }
135  {
136  std::vector<bool> vector_bool_param;
137  ASSERT_TRUE(nh.getParam("vector_bool_param_w_default", vector_bool_param));
138  EXPECT_EQ(vector_bool_param, testParams.vector_bool_param_w_default);
139  }
140  {
141  std::vector<std::string> vector_string_param;
142  ASSERT_TRUE(nh.getParam("vector_string_param_w_default", vector_string_param));
143  EXPECT_EQ(vector_string_param, testParams.vector_string_param_w_default);
144  }
145  {
146  std::map<std::string, std::string> map_param_w_default;
147  ASSERT_TRUE(nh.getParam("map_param_w_default", map_param_w_default));
148  EXPECT_EQ(map_param_w_default, testParams.map_param_w_default);
149  }
150  {
151  int enum_param;
152  ASSERT_TRUE(nh.getParam("enum_param_w_default", enum_param));
153  EXPECT_EQ(enum_param, testParams.enum_param_w_default);
154  }
155 }
rosparam_handler::DefaultsConfig ConfigType
TEST(RosparamHandler, Defaults)
bool getParam(const std::string &key, std::string &s) const
rosparam_handler::DefaultsParameters ParamType


rosparam_handler
Author(s): Claudio Bandera
autogenerated on Mon Jun 10 2019 14:48:10