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