Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00024 #include <stdint.h>
00025 #include <ros/ros.h>
00026 #include <gtest/gtest.h>
00027 #include <string>
00028
00029 #include "sr_ronex_utilities/sr_ronex_utilities.hpp"
00030
00031 using ronex::set_bit;
00032 using ronex::check_bit;
00033 using ronex::get_ronex_param_id;
00034 using ronex::get_ronex_devices_string;
00035
00036 TEST(RonexUtils, set_bit)
00037 {
00038 uint32_t data = 0;
00039 set_bit(data, 1, true);
00040 EXPECT_EQ(data, 2);
00041
00042 set_bit(data, 1, false);
00043 EXPECT_EQ(data, 0);
00044
00045 set_bit(data, 1, true);
00046 set_bit(data, 2, true);
00047 set_bit(data, 3, true);
00048 EXPECT_EQ(data, 14);
00049
00050 for ( size_t i = 0; i < 32; ++i )
00051 set_bit(data, i, true);
00052 EXPECT_EQ(data, 4294967295);
00053
00054 set_bit(data, 1, true);
00055 EXPECT_TRUE(check_bit(data, 1));
00056
00057 set_bit(data, 4, false);
00058 EXPECT_FALSE(check_bit(data, 4));
00059 }
00060
00061 TEST(RonexUtils, get_ronex_param_id)
00062 {
00063
00064 ros::param::del("/ronex");
00065
00066 int ronex_param_id = get_ronex_param_id("");
00067 EXPECT_EQ(ronex_param_id, 0);
00068
00069
00070 ronex_param_id = get_ronex_param_id("1234");
00071 EXPECT_EQ(ronex_param_id, -1);
00072
00073 std::string param;
00074 ros::param::set("/ronex/devices/0/product_id", "0x20001");
00075 ros::param::set("/ronex/devices/0/product_name", "general_io");
00076 ros::param::set("/ronex/devices/0/ronex_id", "my_beautiful_ronex");
00077 ros::param::set("/ronex/devices/0/path", "/ronex/general_io/my_beautiful_ronex/");
00078 ros::param::set("/ronex/devices/0/serial", "1234");
00079
00080
00081 ronex_param_id = get_ronex_param_id("");
00082 EXPECT_EQ(ronex_param_id, 1);
00083
00084
00085 ronex_param_id = get_ronex_param_id("my_beautiful_ronex");
00086 EXPECT_EQ(ronex_param_id, 0);
00087
00088
00089 ronex_param_id = get_ronex_param_id("do_not_exist");
00090 EXPECT_EQ(ronex_param_id, -1);
00091 }
00092
00093 TEST(RonexUtils, get_ronex_devices_string)
00094 {
00095 std::string keyA("/ronex/devices/3/product_name");
00096
00097 int ronex_parameter_id = 3;
00098 std::string part("product_name");
00099 std::string keyB = get_ronex_devices_string(ronex_parameter_id, part);
00100
00101 EXPECT_EQ(keyA, keyB);
00102 }
00103
00104 int main(int argc, char **argv)
00105 {
00106 testing::InitGoogleTest(&argc, argv);
00107 ros::init(argc, argv, "test_sr_ronex_utilities");
00108 return RUN_ALL_TESTS();
00109 }
00110
00111
00112
00113
00114
00115