get_master_information.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2008, Willow Garage, Inc.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  *
8  * * Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  * * Redistributions in binary form must reproduce the above copyright
11  * notice, this list of conditions and the following disclaimer in the
12  * documentation and/or other materials provided with the distribution.
13  * * Neither the name of Willow Garage, Inc. nor the names of its
14  * contributors may be used to endorse or promote products derived from
15  * this software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
21  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27  * POSSIBILITY OF SUCH DAMAGE.
28  */
29 
30 /* Author: Josh Faust */
31 
32 /*
33  * Test getting various information from the master, like the published topics
34  */
35 
36 #include <string>
37 #include <sstream>
38 #include <fstream>
39 #include <set>
40 
41 #include <gtest/gtest.h>
42 
43 #include <time.h>
44 #include <stdlib.h>
45 
46 #include "ros/ros.h"
47 #include "test_roscpp/TestEmpty.h"
48 
49 TEST(masterInfo, getPublishedTopics)
50 {
51  ros::NodeHandle nh;
52 
53  typedef std::set<std::string> S_string;
54  S_string advertised_topics;
55  advertised_topics.insert( "/test_topic_1" );
56  advertised_topics.insert( "/test_topic_2" );
57  advertised_topics.insert( "/test_topic_3" );
58  advertised_topics.insert( "/test_topic_4" );
59  advertised_topics.insert( "/test_topic_5" );
60  advertised_topics.insert( "/test_topic_6" );
61  advertised_topics.insert( "/test_topic_7" );
62  advertised_topics.insert( "/test_topic_8" );
63 
64  std::vector<ros::Publisher> pubs;
65 
66  S_string::iterator adv_it = advertised_topics.begin();
67  S_string::iterator adv_end = advertised_topics.end();
68  for ( ; adv_it != adv_end; ++adv_it )
69  {
70  const std::string& topic = *adv_it;
71  pubs.push_back(nh.advertise<test_roscpp::TestEmpty>( topic, 0 ));
72  }
73 
74  ros::master::V_TopicInfo master_topics;
75  ros::master::getTopics(master_topics);
76 
77  adv_it = advertised_topics.begin();
78  adv_end = advertised_topics.end();
79  for ( ; adv_it != adv_end; ++adv_it )
80  {
81  const std::string& topic = *adv_it;
82  bool found = false;
83 
84  ros::master::V_TopicInfo::iterator master_it = master_topics.begin();
85  ros::master::V_TopicInfo::iterator master_end = master_topics.end();
86  for ( ; master_it != master_end; ++master_it )
87  {
88  const ros::master::TopicInfo& info = *master_it;
89  if ( topic == info.name )
90  {
91  found = true;
92  break;
93  }
94  }
95 
96  ASSERT_TRUE( found );
97  }
98 }
99 
100 
101 int
102 main(int argc, char** argv)
103 {
104  testing::InitGoogleTest(&argc, argv);
105  ros::init( argc, argv, "get_master_information" );
106  ros::NodeHandle nh;
107 
108  return RUN_ALL_TESTS();
109 }
int main(int argc, char **argv)
std::set< std::string > S_string
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
ROSCPP_DECL bool getTopics(V_TopicInfo &topics)
std::vector< TopicInfo > V_TopicInfo
TEST(masterInfo, getPublishedTopics)
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)


test_roscpp
Author(s): Morgan Quigley, Josh Faust, Brian Gerkey, Troy Straszheim, Dirk Thomas
autogenerated on Mon Nov 2 2020 03:52:46