test_callbacks_cpp.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2009, 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 the 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 
31 #include <bondcpp/bond.h>
32 #include <gtest/gtest.h>
33 
34 #ifndef _WIN32
35 # include <uuid/uuid.h>
36 #else
37 # include <rpc.h>
38 #endif
39 
40 #include <ros/spinner.h>
41 
42 #include <test_bond/TestBond.h>
43 
44 #include <string>
45 
46 const char TOPIC[] = "test_bond_topic";
47 std::string genId()
48 {
49 #ifndef _WIN32
50  uuid_t uuid;
51  uuid_generate_random(uuid);
52  char uuid_str[40];
53  uuid_unparse(uuid, uuid_str);
54  return std::string(uuid_str);
55 #else
56  UUID uuid;
57  UuidCreate(&uuid);
58  RPC_CSTR str;
59  UuidToStringA(&uuid, &str);
60  std::string return_string(reinterpret_cast<char *>(str));
61  RpcStringFreeA(&str);
62  return return_string;
63 #endif
64 }
65 
66 TEST(TestCallbacksCpp, dieInLifeCallback)
67 {
68  std::string id = genId();
69  bond::Bond a(TOPIC, id);
70  bond::Bond b(TOPIC, id);
71 
72  a.setFormedCallback(boost::bind(&bond::Bond::breakBond, &a));
73 
74  a.start();
75  b.start();
76 
77  EXPECT_TRUE(a.waitUntilFormed(ros::Duration(5.0)));
78  EXPECT_TRUE(b.waitUntilBroken(ros::Duration(3.0)));
79 }
80 
81 int main(int argc, char ** argv)
82 {
83  testing::InitGoogleTest(&argc, argv);
84  ros::init(argc, argv, "test_callbacks_cpp", true);
85  ros::AsyncSpinner spinner(1);
86  spinner.start();
87  ros::NodeHandle nh;
88  int ret = RUN_ALL_TESTS();
89  spinner.stop();
90  return ret;
91 };
void breakBond()
std::string genId()
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
TEST(TestCallbacksCpp, dieInLifeCallback)
bool waitUntilBroken(ros::Duration timeout=ros::Duration(-1))
bool waitUntilFormed(ros::Duration timeout=ros::Duration(-1))
void start()
int main(int argc, char **argv)
const char TOPIC[]
void setFormedCallback(boost::function< void(void)> on_formed)


test_bond
Author(s): Stuart Glaser
autogenerated on Wed Sep 2 2020 03:40:47