1 #include <gtest/gtest.h> 3 #include <rosparam_handler/DefaultsParameters.h> 5 typedef rosparam_handler::DefaultsParameters
ParamType;
8 TEST(RosparamHandler, Defaults) {
10 ASSERT_NO_THROW(testParams.fromParamServer());
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);
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);
22 std::map<std::string, std::string> tmp{{
"Hello",
"World"}};
23 ASSERT_EQ(tmp, testParams.map_param_w_default);
25 ASSERT_EQ(1, testParams.enum_param_w_default);
28 TEST(RosparamHandler, DefaultsOnParamServer) {
31 ASSERT_NO_THROW(testParams.fromParamServer());
36 ASSERT_TRUE(nh.
getParam(
"int_param_w_default", int_param));
37 ASSERT_EQ(int_param, testParams.int_param_w_default);
41 ASSERT_TRUE(nh.
getParam(
"double_param_w_default", double_param));
42 EXPECT_EQ(double_param, testParams.double_param_w_default);
46 ASSERT_TRUE(nh.
getParam(
"bool_param_w_default", bool_param));
47 EXPECT_EQ(bool_param, testParams.bool_param_w_default);
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);
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);
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);
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);
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);
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);
81 ASSERT_TRUE(nh.
getParam(
"enum_param_w_default", enum_param));
82 EXPECT_EQ(enum_param, testParams.enum_param_w_default);
86 TEST(RosparamHandler, SetParamOnServer) {
89 ASSERT_NO_THROW(testParams.fromParamServer());
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;
102 testParams.toParamServer();
107 ASSERT_TRUE(nh.
getParam(
"int_param_w_default", int_param));
108 ASSERT_EQ(int_param, testParams.int_param_w_default);
112 ASSERT_TRUE(nh.
getParam(
"double_param_w_default", double_param));
113 EXPECT_EQ(double_param, testParams.double_param_w_default);
117 ASSERT_TRUE(nh.
getParam(
"bool_param_w_default", bool_param));
118 EXPECT_EQ(bool_param, testParams.bool_param_w_default);
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);
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);
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);
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);
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);
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);
152 ASSERT_TRUE(nh.
getParam(
"enum_param_w_default", enum_param));
153 EXPECT_EQ(enum_param, testParams.enum_param_w_default);
rosparam_handler::DefaultsConfig ConfigType
TEST(RosparamHandler, Defaults)
bool getParam(const std::string &key, std::string &s) const
rosparam_handler::DefaultsParameters ParamType