test
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
"
21
#include <
fkie_message_filters/combiner_policies/fifo.h
>
22
#include <
fkie_message_filters/combiner.h
>
23
#include <
fkie_message_filters/simple_user_filter.h
>
24
#include <
fkie_message_filters/user_source.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>
;
30
using
Combiner =
mf::Combiner<mf::combiner_policies::Fifo, Source1::Output, Source2::Output>
;
31
using
Sink =
mf::SimpleUserFilter<int_M, int_M, 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
fkie_message_filters
Definition:
buffer.h:33
NotDefaultConstructable
Definition:
test.h:35
simple_user_filter.h
fkie_message_filters::UserSource
Manually operated data source.
Definition:
user_source.h:55
fkie_message_filters::Combiner::Policy
PolicyTmpl< IOs... > Policy
Class type of the policy that applies to the combiner.
Definition:
combiner.h:105
fkie_message_filters::SimpleUserFilter
Simplified filter with user-defined callback function.
Definition:
simple_user_filter.h:56
fifo.h
ExpectedException
Definition:
test.h:74
double_M
NotDefaultConstructable< double > double_M
Definition:
test.h:48
int_M
NotDefaultConstructable< int > int_M
Definition:
test.h:47
TEST
TEST(fkie_message_filters, FifoCombiner)
Definition:
test_combiner_fifo.cpp:26
fkie_message_filters::Combiner
Combine multiple sources into a single one.
Definition:
combiner.h:90
test.h
user_source.h
combiner.h
fkie_message_filters
Author(s): Timo Röhling
autogenerated on Wed Mar 2 2022 00:18:57