test
test_simple_user_filter.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/simple_user_filter.h
>
22
#include <
fkie_message_filters/user_source.h
>
23
24
TEST
(
fkie_message_filters
, SimpleUserFilter)
25
{
26
using
Source =
mf::UserSource<int_M>
;
27
using
Filter
=
mf::SimpleUserFilter<int_M>
;
28
using
Sink =
mf::SimpleUserFilter<int_M>
;
29
30
std::size_t callback_counts = 0;
31
Source src;
32
Filter
flt;
33
Sink snk;
34
mf::chain
(src, flt, snk);
35
flt.set_processing_function(
36
[](
const
int_M
& i) ->
bool
37
{
38
return
i == 42;
39
}
40
);
41
snk.set_processing_function(
42
[&](
const
int_M
& i) ->
bool
43
{
44
++callback_counts;
45
if
(i != 42)
throw
std::domain_error(
"i != 42"
);
46
return
true
;
47
}
48
);
49
// Check that 42 is passed through and -1 is discarded
50
src(
int_M
(42));
51
src(
int_M
(-1));
52
ASSERT_EQ(1u, callback_counts);
53
}
fkie_message_filters
Definition:
buffer.h:33
fkie_message_filters::chain
void chain(Filter1 &flt1, Filter2 &flt2, MoreFilters &... filters) noexcept
Convenience function to chain multiple filters.
Definition:
filter_impl.h:71
Filter
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::SimpleUserFilter
Simplified filter with user-defined callback function.
Definition:
simple_user_filter.h:56
int_M
NotDefaultConstructable< int > int_M
Definition:
test.h:47
test.h
user_source.h
TEST
TEST(fkie_message_filters, SimpleUserFilter)
Definition:
test_simple_user_filter.cpp:24
fkie_message_filters
Author(s): Timo Röhling
autogenerated on Wed Mar 2 2022 00:18:57