test_helpers.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 #include <boost/shared_ptr.hpp>
25 #include <memory>
26 #include <ros/message_event.h>
27 
28 static std::size_t seq_helper(std::size_t a, std::size_t b, std::size_t c)
29 {
30  return a + b + c;
31 }
32 
33 TEST(fkie_message_filters, SequenceHelpers)
34 {
35  std::size_t result = 0;
36  mf::helpers::for_each_apply<4>(
37  [&](auto Is)
38  {
39  result += Is;
40  }
41  );
42  ASSERT_EQ(6u, result);
43  mf::helpers::for_each_apply<4>(
44  [&](auto Is)
45  {
46  result += Is;
47  }
48  );
49  result = mf::helpers::index_apply<3>(
50  [](auto... Is) -> std::size_t
51  {
52  return seq_helper(Is...);
53  }
54  );
55  ASSERT_EQ(3u, result);
56  result = 0;
57  mf::helpers::select_apply<4>(2,
58  [&](auto Is)
59  {
60  result += Is;
61  }
62  );
63  ASSERT_EQ(2u, result);
64 }
65 
66 TEST(fkie_message_filters, RosHeaderExtraction)
67 {
68  // Verify that the access_ros_header() helper function works with all supported data types
69  using IntegerStamped = Stamped<int>;
70 
71  IntegerStamped i1{0, std::string(), ros::Time(1, 0)};
72  std::shared_ptr<IntegerStamped const> i2 = std::make_shared<IntegerStamped>(0, std::string(), ros::Time(2, 0));
73  boost::shared_ptr<IntegerStamped const> i3 = boost::make_shared<IntegerStamped>(0, std::string(), ros::Time(3, 0));
74  ros::MessageEvent<IntegerStamped const> i4{boost::make_shared<IntegerStamped>(0, std::string(), ros::Time(4, 0)), boost::shared_ptr<ros::M_string>(), ros::Time(4, 0), false, []() -> boost::shared_ptr<IntegerStamped> { return boost::shared_ptr<IntegerStamped>();}};
75 
80 }
static std::size_t seq_helper(std::size_t a, std::size_t b, std::size_t c)
Primary namespace.
Definition: buffer.h:33
TEST(fkie_message_filters, SequenceHelpers)
Definition: test.h:52
ros::Time access_ros_header_stamp(const M &m) noexcept


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