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, boost::placeholders::_1));
115  f.registerCallback<const Msg&>(boost::bind(&Helper::cb1, &h, boost::placeholders::_1));
116  f.registerCallback<MsgConstPtr>(boost::bind(&Helper::cb2, &h, boost::placeholders::_1));
117  f.registerCallback<const ros::MessageEvent<Msg const>&>(boost::bind(&Helper::cb3, &h, boost::placeholders::_1));
118  f.registerCallback<Msg>(boost::bind(&Helper::cb4, &h, boost::placeholders::_1));
119  f.registerCallback<const MsgPtr&>(boost::bind(&Helper::cb5, &h, boost::placeholders::_1));
120  f.registerCallback<MsgPtr>(boost::bind(&Helper::cb6, &h, boost::placeholders::_1));
121  f.registerCallback<const ros::MessageEvent<Msg>&>(boost::bind(&Helper::cb7, &h, boost::placeholders::_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, boost::placeholders::_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 
Helper::counts_
boost::array< int32_t, 30 > counts_
Definition: test_simple.cpp:107
Helper
Definition: test_chain.cpp:49
Filter
Definition: test_simple.cpp:49
Msg
Definition: msg_cache_unittest.cpp:50
TEST
TEST(SimpleFilter, callbackTypes)
Definition: test_simple.cpp:110
message_filters::Connection
Encapsulates a connection from one filter to another (or to a user-specified callback)
Definition: connection.h:80
boost::shared_ptr< Msg >
ros::init
ROSCPP_DECL void init(const M_string &remappings, const std::string &name, uint32_t options=0)
OldFilter
Definition: test_simple.cpp:134
MsgPtr
boost::shared_ptr< Msg > MsgPtr
Definition: test_simple.cpp:46
time.h
Helper::cb0
void cb0(const MsgConstPtr &)
Definition: test_simple.cpp:67
init.h
Filter::add
void add(const EventType &evt)
Definition: test_simple.cpp:53
simple_filter.h
Helper::cb7
void cb7(const ros::MessageEvent< Msg > &)
Definition: test_simple.cpp:102
Helper::Helper
Helper()
Definition: test_simple.cpp:62
f
f
Helper::cb3
void cb3(const ros::MessageEvent< Msg const > &)
Definition: test_simple.cpp:82
message_filters::SimpleFilter
Convenience base-class for simple filters which output a single message.
Definition: simple_filter.h:92
Helper::cb2
void cb2(MsgConstPtr)
Definition: test_simple.cpp:77
MsgConstPtr
boost::shared_ptr< Msg const > MsgConstPtr
Definition: test_simple.cpp:47
Helper::cb5
void cb5(const MsgPtr &)
Definition: test_simple.cpp:92
main
int main(int argc, char **argv)
Definition: test_simple.cpp:149
Helper::cb1
void cb1(const Msg &)
Definition: test_simple.cpp:72
ros::Time::init
static void init()
Helper::cb4
void cb4(Msg)
Definition: test_simple.cpp:87
Helper::cb6
void cb6(MsgPtr)
Definition: test_simple.cpp:97
message_filters
Definition: cache.h:47
Filter::EventType
ros::MessageEvent< Msg const > EventType
Definition: test_simple.cpp:51
OldFilter::registerCallback
Connection registerCallback(const boost::function< void(const MsgConstPtr &)> &)
Definition: test_simple.cpp:136
ros::MessageEvent


message_filters
Author(s): Josh Faust, Vijay Pradeep, Dirk Thomas , Jacob Perron
autogenerated on Thu Nov 23 2023 04:01:54