test_combiner_fifo.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, FifoCombiner)
27 {
28  using Source1 = mf::UserSource<int_M, int_M>;
29  using Source2 = mf::UserSource<double_M, double_M>;
32 
33  std::size_t callback_counts = 0;
34  Source1 src1;
35  Source2 src2;
36  Sink snk;
37  Combiner combiner(Combiner::Policy(1));
38  combiner.connect_to_sources(src1, src2);
39  combiner.connect_to_sink(snk);
40  snk.set_processing_function(
41  [&](const int_M& i1, const int_M& i2, const double_M& d1, const double_M& d2) -> bool
42  {
43  ++callback_counts;
44  if (i1 != 1) throw std::domain_error("i1 != 1");
45  if (i2 != 2) throw std::domain_error("i2 != 2");
46  if (d1 != 3.14) throw std::domain_error("d1 != 3.14");
47  if (d2 != 6.28) throw ExpectedException("d2 != 6.28");
48  return true;
49  }
50  );
51  src1(int_M(1), int_M(2));
52  src2(double_M(3.14), double_M(6.28));
53  src2(double_M(3.14), double_M(0));
54  ASSERT_THROW(src1(int_M(1), int_M(2)), ExpectedException);
55  ASSERT_EQ(2u, callback_counts);
56 }
57 
TEST(fkie_message_filters, FifoCombiner)
Primary namespace.
Definition: buffer.h:33
NotDefaultConstructable< int > int_M
Definition: test.h:47
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.
NotDefaultConstructable< double > double_M
Definition: test.h:48
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