test_sr_ronex_utilities.cpp
Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2013, Shadow Robot Company, All rights reserved.
00003  * 
00004  * This library is free software; you can redistribute it and/or
00005  * modify it under the terms of the GNU Lesser General Public
00006  * License as published by the Free Software Foundation; either
00007  * version 3.0 of the License, or (at your option) any later version.
00008  * 
00009  * This library is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
00012  * Lesser General Public License for more details.
00013  * 
00014  * You should have received a copy of the GNU Lesser General Public
00015  * License along with this library.
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   // make sure we're running on a clean environment
00064   ros::param::del("/ronex");
00065   // nothing in the parameter server -> ronex param id = 0
00066   int ronex_param_id = get_ronex_param_id("");
00067   EXPECT_EQ(ronex_param_id, 0);
00068 
00069   // This serial number is not present on the param server -> returns -1
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   // We now have a ronex with param id = 0 -> next free id is 1.
00081   ronex_param_id = get_ronex_param_id("");
00082   EXPECT_EQ(ronex_param_id, 1);
00083 
00084   // This ronex id is now present on the param server -> returns index = 0
00085   ronex_param_id = get_ronex_param_id("my_beautiful_ronex");
00086   EXPECT_EQ(ronex_param_id, 0);
00087 
00088   // This ronex id doesn't exist - return -1
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 /* For the emacs weenies in the crowd.
00112 Local Variables:
00113 c-basic-offset: 2
00114 End:
00115 */


sr_ronex_utilities
Author(s): Ugo Cupcic, Toni Oliver, Mark Pitchless
autogenerated on Thu Jun 6 2019 21:21:58