inspection.cpp
Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2008, Willow Garage, Inc.
00003  * All rights reserved.
00004  *
00005  * Redistribution and use in source and binary forms, with or without
00006  * modification, are permitted provided that the following conditions are met:
00007  *
00008  *     * Redistributions of source code must retain the above copyright
00009  *       notice, this list of conditions and the following disclaimer.
00010  *     * Redistributions in binary form must reproduce the above copyright
00011  *       notice, this list of conditions and the following disclaimer in the
00012  *       documentation and/or other materials provided with the distribution.
00013  *     * Neither the name of Willow Garage, Inc. nor the names of its
00014  *       contributors may be used to endorse or promote products derived from
00015  *       this software without specific prior written permission.
00016  *
00017  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00018  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00019  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00020  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
00021  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00022  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
00023  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00024  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00025  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
00026  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00027  * POSSIBILITY OF SUCH DAMAGE.
00028  */
00029 
00030 /* Author: Brian Gerkey */
00031 
00032 /*
00033  * Test inspection functionality
00034  */
00035 
00036 #include <string>
00037 
00038 #include <gtest/gtest.h>
00039 
00040 #include <ros/ros.h>
00041 #include <ros/names.h>
00042 #include <test_roscpp/TestArray.h>
00043 #include <test_roscpp/TestStringInt.h>
00044 #include <test_roscpp/TestEmpty.h>
00045 
00046 const char* g_node_name = "inspection_test";
00047 
00048 int g_argc;
00049 char* g_argv[8];
00050 
00051 TEST(Inspection, getAdvertisedTopics)
00052 {
00053   ros::NodeHandle nh;
00054 
00055   std::vector<std::string> topics;
00056 
00057   ros::this_node::getAdvertisedTopics(topics);
00058   // Note that it's 1, not 0, because the rosout appender has already snuck
00059   // in and advertised.
00060   ASSERT_EQ((int)topics.size(),1);
00061   ASSERT_EQ(topics[0], "/rosout");
00062 
00063   {
00064     ros::Publisher pub1 = nh.advertise<test_roscpp::TestArray>("topic",1);
00065     ros::Publisher pub2 = nh.advertise<test_roscpp::TestArray>("ns/topic",1);
00066     ros::Publisher pub3 = nh.advertise<test_roscpp::TestArray>("/global/topic",1);
00067 
00068     topics.clear();
00069     ros::this_node::getAdvertisedTopics(topics);
00070     // Note that it's 4, not 3, because the rosout appender has already snuck
00071     // in and advertised.
00072     ASSERT_EQ((int)topics.size(),4);
00073 
00074     // The following tests assume strict ordering of the topics, which is not
00075     // guaranteed by the API.
00076     ASSERT_EQ(topics[0], "/rosout");
00077     ASSERT_EQ(topics[1], "/topic");
00078     ASSERT_EQ(topics[2], "/ns/topic");
00079     ASSERT_EQ(topics[3], "/global/topic");
00080   }
00081 
00082   topics.clear();
00083   ros::this_node::getAdvertisedTopics(topics);
00084   // Note that it's 1, not 0, because the rosout appender has already snuck
00085   // in and advertised.
00086   ASSERT_EQ((int)topics.size(),1);
00087   ASSERT_EQ(topics[0], "/rosout");
00088 }
00089 
00090 TEST(Inspection, commandLineParsing)
00091 {
00092   ASSERT_EQ(g_argc, 5);
00093   ros::M_string remappings = ros::names::getRemappings();
00094 
00095   ASSERT_STREQ(remappings["/foo"].c_str(), "/bar");
00096   ASSERT_STREQ(remappings["/baz"].c_str(), "/bang");
00097   ASSERT_STREQ(remappings["/bomb"].c_str(), "/barn");
00098 }
00099 
00100 int
00101 main(int argc, char** argv)
00102 {
00103   testing::InitGoogleTest(&argc, argv);
00104 
00105   g_argc = 8;
00106 
00107   g_argv[0] = strdup(argv[0]);
00108   g_argv[1] = strdup("foo:=bar");
00109   g_argv[2] = strdup("bat");
00110   g_argv[3] = strdup("baz:=bang");
00111   g_argv[4] = strdup("boom");
00112   g_argv[5] = strdup("baz=bomb");
00113   g_argv[6] = strdup("bomb:=barn");
00114   g_argv[7] = strdup("--bangbang");
00115 
00116   ros::init( g_argc, g_argv, "inspection" );
00117   ros::NodeHandle nh;
00118 
00119   return RUN_ALL_TESTS();
00120 }


test_roscpp
Author(s): Morgan Quigley, Josh Faust, Brian Gerkey, Troy Straszheim
autogenerated on Tue Mar 7 2017 03:45:23