test_sequencer.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"
24 
26 {
27  using IntegerStamped = Stamped<int>;
28  using Source = mf::UserSource<IntegerStamped>;
29  using Sequencer = mf::Sequencer<Source::Output>;
31 
32  std::size_t callback_counts = 0;
33  ros::Time last_ts;
34  Source src;
35  Sequencer seq(ros::Duration(10, 0));
36  Sink snk;
37  snk.set_processing_function(
38  [&](const IntegerStamped& i) -> bool
39  {
40  ++callback_counts;
41  if (i.header.stamp < last_ts) throw std::logic_error("Time stamp order violated");
42  last_ts = i.header.stamp;
43  return true;
44  }
45  );
46  mf::chain(src, seq, snk);
47 
48  src(IntegerStamped(0, "", ros::Time(100, 0)));
49  src(IntegerStamped(0, "", ros::Time(95, 0)));
50  src(IntegerStamped(0, "", ros::Time(98, 0)));
51  src(IntegerStamped(0, "", ros::Time(92, 0)));
52  src(IntegerStamped(0, "", ros::Time(91, 0)));
53  src(IntegerStamped(0, "", ros::Time(97, 0)));
54  src(IntegerStamped(0, "", ros::Time(50, 0)));
55  ASSERT_EQ(0u, callback_counts);
56  src(IntegerStamped(0, "", ros::Time(105, 0)));
57  ASSERT_EQ(3u, callback_counts);
58  src(IntegerStamped(0, "", ros::Time(120, 0)));
59  ASSERT_EQ(7u, callback_counts);
60  ASSERT_EQ(ros::Time(105, 0), last_ts);
61  seq.flush();
62  ASSERT_EQ(8u, callback_counts);
63  src(IntegerStamped(0, "", ros::Time(119, 0)));
64  seq.flush();
65  ASSERT_EQ(8u, callback_counts);
66 }
Enforce correct temporal order.
Definition: sequencer.h:43
TEST(fkie_message_filters, Sequencer)
Primary namespace.
Definition: buffer.h:33
void chain(Filter1 &flt1, Filter2 &flt2, MoreFilters &... filters) noexcept
Convenience function to chain multiple filters.
Definition: filter_impl.h:53
Manually operated data source.
Definition: user_source.h:37
Simplified filter with user-defined callback function.
Definition: test.h:52


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