test_combiner_exact_time.cpp
Go to the documentation of this file.
1 /****************************************************************************
2  *
3  * fkie_message_filters
4  * Copyright © 2018-2020 Fraunhofer FKIE
5  * Author: Timo Röhling
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  ****************************************************************************/
20 #include "test.h"
25 
26 TEST(fkie_message_filters, ExactTimeCombiner)
27 {
28  using IntegerStamped = Stamped<int>;
29  using Source = mf::UserSource<IntegerStamped>;
32 
33  std::size_t callback_counts = 0;
34  Source src1, src2;
35  Combiner combiner(Combiner::Policy().set_max_age(ros::Duration(10, 0)));
36  Sink snk;
37  combiner.connect_to_sources(src1, src2);
38  combiner.connect_to_sink(snk);
39  snk.set_processing_function(
40  [&](const IntegerStamped& m1, const IntegerStamped& m2) -> bool
41  {
42  ++callback_counts;
43  if (m1.header.stamp != m2.header.stamp) throw std::domain_error("timestamps do not match");
44  return true;
45  }
46  );
47  // Check that matching messages will be passed together
48  src1(IntegerStamped(0, "", ros::Time(11, 0)));
49  src1(IntegerStamped(0, "", ros::Time(15, 0)));
50  src1(IntegerStamped(0, "", ros::Time(19, 0)));
51  src1(IntegerStamped(0, "", ros::Time(22, 0)));
52  ASSERT_EQ(0u, callback_counts);
53  src2(IntegerStamped(0, "", ros::Time(11, 0)));
54  ASSERT_EQ(0u, callback_counts);
55  src2(IntegerStamped(0, "", ros::Time(15, 0)));
56  ASSERT_EQ(1u, callback_counts);
57  src2(IntegerStamped(0, "", ros::Time(18, 0)));
58  ASSERT_EQ(1u, callback_counts);
59  src2(IntegerStamped(0, "", ros::Time(19, 0)));
60  ASSERT_EQ(2u, callback_counts);
61  src2(IntegerStamped(0, "", ros::Time(23, 0)));
62  ASSERT_EQ(2u, callback_counts);
63  src1(IntegerStamped(0, "", ros::Time(23, 0)));
64  ASSERT_EQ(3u, callback_counts);
65  // Check that old messages will be discarded after max age
66  src1(IntegerStamped(0, "", ros::Time(30, 0)));
67  src1(IntegerStamped(0, "", ros::Time(50, 0)));
68  src2(IntegerStamped(0, "", ros::Time(30, 0)));
69  ASSERT_EQ(3u, callback_counts);
70  // Check that old messages will be discarded after successful match
71  src1(IntegerStamped(0, "", ros::Time(60, 0)));
72  src1(IntegerStamped(0, "", ros::Time(61, 0)));
73  src2(IntegerStamped(0, "", ros::Time(61, 0)));
74  src2(IntegerStamped(0, "", ros::Time(60, 0)));
75  ASSERT_EQ(4u, callback_counts);
76 }
77 
TEST(fkie_message_filters, ExactTimeCombiner)
Primary namespace.
Definition: buffer.h:33
Combine multiple sources into a single one.
Definition: combiner.h:72
Manually operated data source.
Definition: user_source.h:37
Simplified filter with user-defined callback function.
Definition: test.h:52
PolicyTmpl< IOs... > Policy
Class type of the policy that applies to the combiner.
Definition: combiner.h:87


fkie_message_filters
Author(s): Timo Röhling
autogenerated on Mon Feb 28 2022 22:21:43