test_combiner_approximate_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, ApproximateTimeCombiner)
27 {
28  using IntegerStamped = Stamped<int>;
29  using Source = mf::UserSource<IntegerStamped>;
32 
33  std::size_t callback_counts = 0;
34  Source src1, src2, src3;
35  Combiner combiner(Combiner::Policy().set_max_age(ros::Duration(10, 0)));
36  Sink snk;
37  combiner.connect_to_sources(src1, src2, src3);
38  combiner.connect_to_sink(snk);
39  snk.set_processing_function(
40  [&](const IntegerStamped& m1, const IntegerStamped& m2, const IntegerStamped& m3) -> bool
41  {
42  ++callback_counts;
43  if (m1 != m2) throw std::domain_error("messages do not match");
44  if (m1 != m3) throw std::domain_error("messages do not match");
45  return true;
46  }
47  );
48  src1(IntegerStamped(0, "", ros::Time(99, 2)));
49  src2(IntegerStamped(1, "", ros::Time(100, 1)));
50  // Extra message
51  src2(IntegerStamped(1, "", ros::Time(100, 20)));
52  src3(IntegerStamped(1, "", ros::Time(100, 2)));
53  src1(IntegerStamped(1, "", ros::Time(100, 0)));
54  src1(IntegerStamped(2, "", ros::Time(101, 0)));
55  src2(IntegerStamped(2, "", ros::Time(101, 2)));
56  src3(IntegerStamped(2, "", ros::Time(101, 1)));
57  ASSERT_EQ(1u, callback_counts);
58  src1(IntegerStamped(3, "", ros::Time(102, 0)));
59  src2(IntegerStamped(3, "", ros::Time(102, 0)));
60  src3(IntegerStamped(3, "", ros::Time(102, 0)));
61  ASSERT_EQ(3u, callback_counts);
62  src1(IntegerStamped(4, "", ros::Time(103, 1)));
63  src2(IntegerStamped(4, "", ros::Time(103, 0)));
64  // missing message
65  ASSERT_EQ(3u, callback_counts);
66  src1(IntegerStamped(5, "", ros::Time(104, 2)));
67  src2(IntegerStamped(5, "", ros::Time(104, 1)));
68  src3(IntegerStamped(5, "", ros::Time(104, 0)));
69  ASSERT_EQ(4u, callback_counts);
70  /* Check that old messages get dropped */
71  src1(IntegerStamped(0, "", ros::Time(105, 0)));
72  src2(IntegerStamped(6, "", ros::Time(116, 0)));
73  src3(IntegerStamped(6, "", ros::Time(116, 0)));
74  src1(IntegerStamped(7, "", ros::Time(130, 0)));
75  src2(IntegerStamped(7, "", ros::Time(130, 0)));
76  src3(IntegerStamped(7, "", ros::Time(130, 0)));
77  ASSERT_EQ(5u, callback_counts);
78 }
Primary namespace.
Definition: buffer.h:33
TEST(fkie_message_filters, ApproximateTimeCombiner)
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