test_cloud_accum.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2018, the mcl_3dl authors
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  *
8  * * Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  * * Redistributions in binary form must reproduce the above copyright
11  * notice, this list of conditions and the following disclaimer in the
12  * documentation and/or other materials provided with the distribution.
13  * * Neither the name of the copyright holder nor the names of its
14  * contributors may be used to endorse or promote products derived from
15  * this software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
21  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27  * POSSIBILITY OF SUCH DAMAGE.
28  */
29 
30 #include <vector>
31 #include <string>
32 
33 #include <sensor_msgs/PointCloud2.h>
34 
35 #include <mcl_3dl/cloud_accum.h>
36 
37 #include <gtest/gtest.h>
38 
39 TEST(CloudAccumulationLogic, PassThrough)
40 {
42  std::string seq;
43  const sensor_msgs::PointCloud2::Ptr msg(new sensor_msgs::PointCloud2);
44 
45  const auto process = [&seq]()
46  {
47  seq += "p";
48  };
49  const auto accumulateOK = [&seq, msg](const sensor_msgs::PointCloud2::ConstPtr& msg2) -> bool
50  {
51  EXPECT_EQ(msg, msg2);
52  seq += "a";
53  return true;
54  };
55  const auto accumulateNG = [&seq, msg](const sensor_msgs::PointCloud2::ConstPtr& msg2) -> bool
56  {
57  EXPECT_EQ(msg, msg2);
58  seq += "a'";
59  return false;
60  };
61  const auto clear = [&seq]()
62  {
63  seq += "c";
64  };
65  accum.push("1", msg, process, accumulateOK, clear);
66  ASSERT_EQ(std::string("cap"), seq);
67 
68  accum.push("2", msg, process, accumulateNG, clear);
69  ASSERT_EQ(std::string("capca'"), seq);
70 }
71 
72 TEST(CloudAccumulationLogic, Accumulate)
73 {
75  std::string seq;
76  const sensor_msgs::PointCloud2::Ptr msg(new sensor_msgs::PointCloud2);
77 
78  const auto process = [&seq]()
79  {
80  seq += "p";
81  };
82  const auto accumulateOK = [&seq, msg](const sensor_msgs::PointCloud2::ConstPtr& msg2) -> bool
83  {
84  EXPECT_EQ(msg, msg2);
85  seq += "a";
86  return true;
87  };
88  const auto accumulateNG = [&seq, msg](const sensor_msgs::PointCloud2::ConstPtr& msg2) -> bool
89  {
90  EXPECT_EQ(msg, msg2);
91  seq += "a'";
92  return false;
93  };
94  const auto clear = [&seq]()
95  {
96  seq += "c";
97  };
98 
99  accum.push("1", msg, process, accumulateOK, clear);
100  ASSERT_EQ(std::string("a"), seq);
101 
102  accum.push("2", msg, process, accumulateOK, clear);
103  ASSERT_EQ(std::string("aa"), seq);
104 
105  accum.push("1", msg, process, accumulateOK, clear);
106  ASSERT_EQ(std::string("aaa"), seq);
107 
108  accum.push("2", msg, process, accumulateOK, clear);
109  ASSERT_EQ(std::string("aaaa"), seq);
110 
111  // (accum_cloud_ + 1) of sensor 1 messages received.
112  // Process and start next accumulation.
113  accum.push("1", msg, process, accumulateOK, clear);
114  ASSERT_EQ(std::string("aaaapca"), seq);
115 
116  accum.push("2", msg, process, accumulateOK, clear);
117  ASSERT_EQ(std::string("aaaapcaa"), seq);
118 
119  // Sensor 2 publishes extra message.
120  accum.push("2", msg, process, accumulateOK, clear);
121  ASSERT_EQ(std::string("aaaapcaaa"), seq);
122 
123  accum.push("1", msg, process, accumulateOK, clear);
124  ASSERT_EQ(std::string("aaaapcaaaa"), seq);
125 
126  accum.push("2", msg, process, accumulateOK, clear);
127  ASSERT_EQ(std::string("aaaapcaaaaa"), seq);
128 
129  // Process and start next accumulation.
130  accum.push("1", msg, process, accumulateOK, clear);
131  ASSERT_EQ(std::string("aaaapcaaaaapca"), seq);
132 
133  // Failed to accumulate. Clear and start new accumulation.
134  accum.push("2", msg, process, accumulateNG, clear);
135  ASSERT_EQ(std::string("aaaapcaaaaapcaa'c"), seq);
136 
137  accum.push("2", msg, process, accumulateOK, clear);
138  ASSERT_EQ(std::string("aaaapcaaaaapcaa'ca"), seq);
139 
140  accum.push("1", msg, process, accumulateOK, clear);
141  ASSERT_EQ(std::string("aaaapcaaaaapcaa'caa"), seq);
142 
143  // Sensor 2 stopped publishing message.
144  accum.push("1", msg, process, accumulateOK, clear);
145  ASSERT_EQ(std::string("aaaapcaaaaapcaa'caaa"), seq);
146 
147  accum.push("1", msg, process, accumulateOK, clear);
148  ASSERT_EQ(std::string("aaaapcaaaaapcaa'caaaa"), seq);
149 
150  accum.push("1", msg, process, accumulateOK, clear);
151  ASSERT_EQ(std::string("aaaapcaaaaapcaa'caaaaa"), seq);
152 
153  accum.push("1", msg, process, accumulateOK, clear);
154  ASSERT_EQ(std::string("aaaapcaaaaapcaa'caaaaaa"), seq);
155 
156  // Exceeds accum_max_. Force processing and start next accumulation.
157  accum.push("1", msg, process, accumulateOK, clear);
158  ASSERT_EQ(std::string("aaaapcaaaaapcaa'caaaaaapca"), seq);
159 
160  accum.push("1", msg, process, accumulateNG, clear);
161  ASSERT_EQ(std::string("aaaapcaaaaapcaa'caaaaaapcaa'c"), seq);
162 }
163 
164 int main(int argc, char** argv)
165 {
166  testing::InitGoogleTest(&argc, argv);
167 
168  return RUN_ALL_TESTS();
169 }
msg
TEST(CloudAccumulationLogic, PassThrough)
void push(const std::string &key, const sensor_msgs::PointCloud2::ConstPtr &msg, std::function< void()> process, std::function< bool(const sensor_msgs::PointCloud2::ConstPtr &)> accumulate, std::function< void()> clear) final
Definition: cloud_accum.cpp:53
int main(int argc, char **argv)
void push(const std::string &key, const sensor_msgs::PointCloud2::ConstPtr &msg, std::function< void()> process, std::function< bool(const sensor_msgs::PointCloud2::ConstPtr &)> accumulate, std::function< void()> clear) final
Definition: cloud_accum.cpp:41


mcl_3dl
Author(s): Atsushi Watanabe
autogenerated on Wed May 12 2021 02:16:29