Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035 #include <gtest/gtest.h>
00036
00037 #include "ros/time.h"
00038 #include <ros/init.h>
00039 #include "message_filters/chain.h"
00040
00041 using namespace message_filters;
00042
00043 struct Msg
00044 {
00045 };
00046 typedef boost::shared_ptr<Msg> MsgPtr;
00047 typedef boost::shared_ptr<Msg const> MsgConstPtr;
00048
00049 class Helper
00050 {
00051 public:
00052 Helper()
00053 : count_(0)
00054 {}
00055
00056 void cb()
00057 {
00058 ++count_;
00059 }
00060
00061 int32_t count_;
00062 };
00063
00064 typedef boost::shared_ptr<PassThrough<Msg> > PassThroughPtr;
00065
00066 TEST(Chain, simple)
00067 {
00068 Helper h;
00069 Chain<Msg> c;
00070 c.addFilter(boost::make_shared<PassThrough<Msg> >());
00071 c.registerCallback(boost::bind(&Helper::cb, &h));
00072
00073 c.add(boost::make_shared<Msg>());
00074 EXPECT_EQ(h.count_, 1);
00075 c.add(boost::make_shared<Msg>());
00076 EXPECT_EQ(h.count_, 2);
00077 }
00078
00079 TEST(Chain, multipleFilters)
00080 {
00081 Helper h;
00082 Chain<Msg> c;
00083 c.addFilter(boost::make_shared<PassThrough<Msg> >());
00084 c.addFilter(boost::make_shared<PassThrough<Msg> >());
00085 c.addFilter(boost::make_shared<PassThrough<Msg> >());
00086 c.addFilter(boost::make_shared<PassThrough<Msg> >());
00087 c.registerCallback(boost::bind(&Helper::cb, &h));
00088
00089 c.add(boost::make_shared<Msg>());
00090 EXPECT_EQ(h.count_, 1);
00091 c.add(boost::make_shared<Msg>());
00092 EXPECT_EQ(h.count_, 2);
00093 }
00094
00095 TEST(Chain, addingFilters)
00096 {
00097 Helper h;
00098 Chain<Msg> c;
00099 c.addFilter(boost::make_shared<PassThrough<Msg> >());
00100 c.addFilter(boost::make_shared<PassThrough<Msg> >());
00101 c.registerCallback(boost::bind(&Helper::cb, &h));
00102
00103 c.add(boost::make_shared<Msg>());
00104 EXPECT_EQ(h.count_, 1);
00105
00106 c.addFilter(boost::make_shared<PassThrough<Msg> >());
00107 c.addFilter(boost::make_shared<PassThrough<Msg> >());
00108
00109 c.add(boost::make_shared<Msg>());
00110 EXPECT_EQ(h.count_, 2);
00111 }
00112
00113 TEST(Chain, inputFilter)
00114 {
00115 Helper h;
00116 Chain<Msg> c;
00117 c.addFilter(boost::make_shared<PassThrough<Msg> >());
00118 c.registerCallback(boost::bind(&Helper::cb, &h));
00119
00120 PassThrough<Msg> p;
00121 c.connectInput(p);
00122 p.add(boost::make_shared<Msg>());
00123 EXPECT_EQ(h.count_, 1);
00124
00125 p.add(boost::make_shared<Msg>());
00126 EXPECT_EQ(h.count_, 2);
00127 }
00128
00129 TEST(Chain, nonSharedPtrFilter)
00130 {
00131 Helper h;
00132 Chain<Msg> c;
00133 PassThrough<Msg> p;
00134 c.addFilter(&p);
00135 c.registerCallback(boost::bind(&Helper::cb, &h));
00136
00137 c.add(boost::make_shared<Msg>());
00138 EXPECT_EQ(h.count_, 1);
00139 c.add(boost::make_shared<Msg>());
00140 EXPECT_EQ(h.count_, 2);
00141 }
00142
00143 TEST(Chain, retrieveFilter)
00144 {
00145 Chain<Msg> c;
00146
00147 ASSERT_FALSE(c.getFilter<PassThrough<Msg> >(0));
00148
00149 c.addFilter(boost::make_shared<PassThrough<Msg> >());
00150
00151 ASSERT_TRUE(c.getFilter<PassThrough<Msg> >(0));
00152 ASSERT_FALSE(c.getFilter<PassThrough<Msg> >(1));
00153 }
00154
00155 TEST(Chain, retrieveFilterThroughBaseClass)
00156 {
00157 Chain<Msg> c;
00158 ChainBase* cb = &c;
00159
00160 ASSERT_FALSE(cb->getFilter<PassThrough<Msg> >(0));
00161
00162 c.addFilter(boost::make_shared<PassThrough<Msg> >());
00163
00164 ASSERT_TRUE(cb->getFilter<PassThrough<Msg> >(0));
00165 ASSERT_FALSE(cb->getFilter<PassThrough<Msg> >(1));
00166 }
00167
00168 struct PTDerived : public PassThrough<Msg>
00169 {
00170
00171 };
00172
00173 TEST(Chain, retrieveBaseClass)
00174 {
00175 Chain<Msg> c;
00176 c.addFilter(boost::make_shared<PTDerived>());
00177 ASSERT_TRUE(c.getFilter<PassThrough<Msg> >(0));
00178 ASSERT_TRUE(c.getFilter<PTDerived>(0));
00179 }
00180
00181 int main(int argc, char **argv){
00182 testing::InitGoogleTest(&argc, argv);
00183 ros::init(argc, argv, "blah");
00184 ros::Time::init();
00185 return RUN_ALL_TESTS();
00186 }
00187
00188