test_simple.cpp
Go to the documentation of this file.
1 /*********************************************************************
2 * Software License Agreement (BSD License)
3 *
4 * Copyright (c) 2010, Willow Garage, Inc.
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 *
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above
14 * copyright notice, this list of conditions and the following
15 * disclaimer in the documentation and/or other materials provided
16 * with the distribution.
17 * * Neither the name of the Willow Garage nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32 * POSSIBILITY OF SUCH DAMAGE.
33 *********************************************************************/
34 
35 #include <gtest/gtest.h>
36 
37 #include "ros/time.h"
38 #include <ros/init.h>
40 
41 using namespace message_filters;
42 
43 struct Msg
44 {
45 };
48 
49 struct Filter : public SimpleFilter<Msg>
50 {
52 
53  void add(const EventType& evt)
54  {
55  signalMessage(evt);
56  }
57 };
58 
59 class Helper
60 {
61 public:
63  {
64  counts_.assign(0);
65  }
66 
67  void cb0(const MsgConstPtr&)
68  {
69  ++counts_[0];
70  }
71 
72  void cb1(const Msg&)
73  {
74  ++counts_[1];
75  }
76 
78  {
79  ++counts_[2];
80  }
81 
83  {
84  ++counts_[3];
85  }
86 
87  void cb4(Msg)
88  {
89  ++counts_[4];
90  }
91 
92  void cb5(const MsgPtr&)
93  {
94  ++counts_[5];
95  }
96 
97  void cb6(MsgPtr)
98  {
99  ++counts_[6];
100  }
101 
103  {
104  ++counts_[7];
105  }
106 
107  boost::array<int32_t, 30> counts_;
108 };
109 
110 TEST(SimpleFilter, callbackTypes)
111 {
112  Helper h;
113  Filter f;
114  f.registerCallback(boost::bind(&Helper::cb0, &h, _1));
115  f.registerCallback<const Msg&>(boost::bind(&Helper::cb1, &h, _1));
116  f.registerCallback<MsgConstPtr>(boost::bind(&Helper::cb2, &h, _1));
117  f.registerCallback<const ros::MessageEvent<Msg const>&>(boost::bind(&Helper::cb3, &h, _1));
118  f.registerCallback<Msg>(boost::bind(&Helper::cb4, &h, _1));
119  f.registerCallback<const MsgPtr&>(boost::bind(&Helper::cb5, &h, _1));
120  f.registerCallback<MsgPtr>(boost::bind(&Helper::cb6, &h, _1));
121  f.registerCallback<const ros::MessageEvent<Msg>&>(boost::bind(&Helper::cb7, &h, _1));
122 
123  f.add(Filter::EventType(boost::make_shared<Msg>()));
124  EXPECT_EQ(h.counts_[0], 1);
125  EXPECT_EQ(h.counts_[1], 1);
126  EXPECT_EQ(h.counts_[2], 1);
127  EXPECT_EQ(h.counts_[3], 1);
128  EXPECT_EQ(h.counts_[4], 1);
129  EXPECT_EQ(h.counts_[5], 1);
130  EXPECT_EQ(h.counts_[6], 1);
131  EXPECT_EQ(h.counts_[7], 1);
132 }
133 
134 struct OldFilter
135 {
136  Connection registerCallback(const boost::function<void(const MsgConstPtr&)>&)
137  {
138  return Connection();
139  }
140 };
141 
142 TEST(SimpleFilter, oldRegisterWithNewFilter)
143 {
144  OldFilter f;
145  Helper h;
146  f.registerCallback(boost::bind(&Helper::cb3, &h, _1));
147 }
148 
149 int main(int argc, char **argv){
150  testing::InitGoogleTest(&argc, argv);
151  ros::init(argc, argv, "blah");
152  ros::Time::init();
153 
154  return RUN_ALL_TESTS();
155 }
156 
157 
158 
f
void cb1(const Msg &)
Definition: test_simple.cpp:72
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
void add(const EventType &evt)
Definition: test_simple.cpp:53
TEST(SimpleFilter, callbackTypes)
void cb6(MsgPtr)
Definition: test_simple.cpp:97
void cb3(const ros::MessageEvent< Msg const > &)
Definition: test_simple.cpp:82
void cb0(const MsgConstPtr &)
Definition: test_simple.cpp:67
void cb5(const MsgPtr &)
Definition: test_simple.cpp:92
boost::array< int32_t, 30 > counts_
static void init()
boost::shared_ptr< Msg > MsgPtr
Definition: test_simple.cpp:46
Connection registerCallback(const boost::function< void(const MsgConstPtr &)> &)
boost::shared_ptr< Msg const > MsgConstPtr
Definition: test_simple.cpp:47
int main(int argc, char **argv)
void cb2(MsgConstPtr)
Definition: test_simple.cpp:77
Convenience base-class for simple filters which output a single message.
Definition: simple_filter.h:60
ros::MessageEvent< Msg const > EventType
Definition: test_simple.cpp:51
Encapsulates a connection from one filter to another (or to a user-specified callback) ...
Definition: connection.h:48
void cb7(const ros::MessageEvent< Msg > &)
void cb4(Msg)
Definition: test_simple.cpp:87
Connection registerCallback(const C &callback)
Register a callback to be called when this filter has passed.
Definition: simple_filter.h:73


message_filters
Author(s): Josh Faust, Vijay Pradeep
autogenerated on Wed Mar 21 2018 07:13:44