multiple_init_fini.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  * Repeatedly create and destroy a node. Do some stuff in between to be sure things are working
34  */
35 
36 #include <string>
37 
38 #include <gtest/gtest.h>
39 
40 #include <time.h>
41 #include <stdlib.h>
42 
43 #include "ros/ros.h"
44 #include "ros/callback_queue.h"
45 
46 #include <test_roscpp/TestArray.h>
47 
48 int g_argc;
49 char** g_argv;
50 
51 bool g_got_callback = false;
52 
53 void callback(const test_roscpp::TestArrayConstPtr&)
54 {
55  g_got_callback = true;
56 }
57 
58 TEST(roscpp, multipleInitAndFini)
59 {
60  int try_count = 10;
61  if ( g_argc > 1 )
62  {
63  try_count = atoi(g_argv[1]);
64  }
65 
66  for ( int i = 0; i < try_count; ++i )
67  {
68  g_got_callback = false;
69 
70  ros::init( g_argc, g_argv, "multiple_init_fini" );
71  ros::NodeHandle nh;
72 
73  ros::Subscriber sub = nh.subscribe("test", 1, callback);
74  ASSERT_TRUE(sub);
75 
76  ros::Publisher pub = nh.advertise<test_roscpp::TestArray>( "test", 1 );
77  ASSERT_TRUE(pub);
78 
79  pub.publish(test_roscpp::TestArray());
81 
82  ASSERT_TRUE(g_got_callback) << "did not receive a message in iteration " << i;
83 
84  ros::shutdown();
85  }
86 }
87 
88 int
89 main(int argc, char** argv)
90 {
91  testing::InitGoogleTest(&argc, argv);
92  g_argc = argc;
93  g_argv = argv;
94  return RUN_ALL_TESTS();
95 }
ros::Publisher
ros::init
ROSCPP_DECL void init(const M_string &remappings, const std::string &name, uint32_t options=0)
ros.h
time.h
g_got_callback
bool g_got_callback
Definition: multiple_init_fini.cpp:51
ros::shutdown
ROSCPP_DECL void shutdown()
ros::Publisher::publish
void publish(const boost::shared_ptr< M > &message) const
ros::NodeHandle::advertise
Publisher advertise(AdvertiseOptions &ops)
roscpp
main
int main(int argc, char **argv)
Definition: multiple_init_fini.cpp:89
ros::NodeHandle::subscribe
Subscriber subscribe(const std::string &topic, uint32_t queue_size, const boost::function< void(C)> &callback, const VoidConstPtr &tracked_object=VoidConstPtr(), const TransportHints &transport_hints=TransportHints())
callback_queue.h
callback
void callback(const test_roscpp::TestArrayConstPtr &)
Definition: multiple_init_fini.cpp:53
g_argc
int g_argc
Definition: multiple_init_fini.cpp:48
TEST
TEST(roscpp, multipleInitAndFini)
Definition: multiple_init_fini.cpp:58
ros::WallDuration
g_argv
char ** g_argv
Definition: multiple_init_fini.cpp:49
ros::CallbackQueue::callAvailable
void callAvailable()
ros::NodeHandle
ros::Subscriber
ros::getGlobalCallbackQueue
ROSCPP_DECL CallbackQueue * getGlobalCallbackQueue()


test_roscpp
Author(s): Morgan Quigley, Josh Faust, Brian Gerkey, Troy Straszheim, Dirk Thomas , Jacob Perron
autogenerated on Thu Nov 23 2023 04:02:02