Go to the documentation of this file.00001 #include <gtest/gtest.h>
00002 #include <ros/ros.h>
00003 #include <dynamic_reconfigure/server.h>
00004
00005 #include <rosparam_handler/DefaultsParameters.h>
00006
00007 typedef rosparam_handler::DefaultsParameters ParamType;
00008 typedef rosparam_handler::DefaultsConfig ConfigType;
00009
00010 class TestDynamicReconfigure : public testing::Test
00011 {
00012 public:
00013
00014 TestDynamicReconfigure()
00015 : nh("~")
00016 , testParams(nh)
00017 , drSrv(nh)
00018 {
00019 auto cb = boost::bind(&TestDynamicReconfigure::configCallback, this, _1, _2);
00020 drSrv.setCallback(cb);
00021 }
00022
00023 ~TestDynamicReconfigure() = default;
00024
00025 void configCallback(ConfigType& config, uint32_t )
00026 {
00027 testParams.fromConfig(config);
00028 }
00029
00030 void rosparamToConfig(ConfigType& config)
00031 {
00032 testParams.toConfig(config);
00033 }
00034
00035 ros::NodeHandle nh;
00036
00037 ParamType testParams;
00038
00039 dynamic_reconfigure::Server<ConfigType> drSrv;
00040 };
00041
00042 TEST_F(TestDynamicReconfigure, DynamicReconf)
00043 {
00044
00045 nh.deleteParam("int_param_w_default");
00046 nh.deleteParam("double_param_w_default");
00047 nh.deleteParam("str_param_w_default");
00048 nh.deleteParam("bool_param_w_default");
00049
00050 ASSERT_NO_THROW(testParams.fromParamServer());
00051
00052 ASSERT_EQ(1, testParams.int_param_w_default);
00053 ASSERT_DOUBLE_EQ(1.1, testParams.double_param_w_default);
00054 ASSERT_EQ("Hello World", testParams.str_param_w_default);
00055 ASSERT_TRUE(testParams.bool_param_w_default);
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067 dynamic_reconfigure::ReconfigureRequest srv_req;
00068 dynamic_reconfigure::ReconfigureResponse srv_resp;
00069 dynamic_reconfigure::Config conf;
00070
00071 dynamic_reconfigure::IntParameter int_param;
00072 int_param.name = "int_param_w_default";
00073 int_param.value = 2;
00074
00075 dynamic_reconfigure::DoubleParameter double_param;
00076 double_param.name = "double_param_w_default";
00077 double_param.value = 2.2;
00078
00079 dynamic_reconfigure::StrParameter str_param;
00080 str_param.name = "str_param_w_default";
00081 str_param.value = "Foo Bar";
00082
00083 dynamic_reconfigure::BoolParameter bool_param;
00084 bool_param.name = "bool_param_w_default";
00085 bool_param.value = false;
00086
00087 conf.ints.push_back(int_param);
00088 conf.doubles.push_back(double_param);
00089 conf.strs.push_back(str_param);
00090 conf.bools.push_back(bool_param);
00091
00092 srv_req.config = conf;
00093
00094 ASSERT_TRUE(ros::service::call(nh.getNamespace() + "/set_parameters", srv_req, srv_resp));
00095
00096 ros::Duration(1).sleep();
00097
00098 EXPECT_EQ(2, testParams.int_param_w_default);
00099 EXPECT_DOUBLE_EQ(2.2, testParams.double_param_w_default);
00100 EXPECT_EQ("Foo Bar", testParams.str_param_w_default);
00101 EXPECT_FALSE(testParams.bool_param_w_default);
00102 }
00103
00104 TEST_F(TestDynamicReconfigure, ToDynamicReconf)
00105 {
00106 ConfigType config;
00107
00108 rosparamToConfig(config);
00109
00110 EXPECT_EQ(testParams.int_param_w_default, config.int_param_w_default);
00111 EXPECT_DOUBLE_EQ(testParams.double_param_w_default, config.double_param_w_default);
00112 EXPECT_EQ(testParams.str_param_w_default, config.str_param_w_default);
00113 EXPECT_FALSE(config.bool_param_w_default);
00114 }