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 
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   //make sure we're running on a clean environment
00060   ros::param::del("/ronex");
00061   //nothing in the parameter server -> ronex param id = 0
00062   int ronex_param_id = get_ronex_param_id("");
00063   EXPECT_EQ(ronex_param_id, 0);
00064 
00065   //This serial number is not present on the param server -> returns -1
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   //We now have a ronex with param id = 0 -> next free id is 1.
00077   ronex_param_id = get_ronex_param_id("");
00078   EXPECT_EQ(ronex_param_id, 1);
00079 
00080   //This ronex id is now present on the param server -> returns index = 0
00081   ronex_param_id = get_ronex_param_id("my_beautiful_ronex");
00082   EXPECT_EQ( ronex_param_id, 0);
00083 
00084   //This ronex id doesn't exist - return -1
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 /* For the emacs weenies in the crowd.
00108 Local Variables:
00109 c-basic-offset: 2
00110 End:
00111 */


sr_ronex_utilities
Author(s): Ugo Cupcic, Toni Oliver, Mark Pitchless
autogenerated on Fri Aug 28 2015 13:12:19