in_memory_proto_stream_test.cc
Go to the documentation of this file.
1 /*
2  * Copyright 2018 The Cartographer Authors
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
18 #include "cartographer/mapping/proto/pose_graph.pb.h"
19 #include "cartographer/mapping/proto/serialization.pb.h"
20 
21 #include "gtest/gtest.h"
22 
23 namespace cartographer {
24 namespace io {
25 namespace {
26 
28 using google::protobuf::Message;
29 using mapping::proto::PoseGraph;
30 using mapping::proto::SerializedData;
31 
32 class InMemoryProtoStreamTest : public ::testing::Test {
33  protected:
34  void SetUp() override {
35  pose_graph_.add_trajectory()->set_trajectory_id(1);
36  serialized_data_.mutable_odometry_data()->set_trajectory_id(2);
37  }
38 
39  PoseGraph pose_graph_;
40  SerializedData serialized_data_;
41 };
42 
43 TEST_F(InMemoryProtoStreamTest, ReadStreamInitializedFromQueue) {
44  std::queue<std::unique_ptr<Message>> proto_queue;
45  proto_queue.push(make_unique<PoseGraph>(pose_graph_));
46  proto_queue.push(make_unique<SerializedData>(serialized_data_));
47 
48  InMemoryProtoStreamReader reader(std::move(proto_queue));
49 
50  PoseGraph actual_pose_graph;
51  EXPECT_FALSE(reader.eof());
52  EXPECT_TRUE(reader.ReadProto(&actual_pose_graph));
53  EXPECT_EQ(1, actual_pose_graph.trajectory(0).trajectory_id());
54 
55  SerializedData actual_serialized_data;
56  EXPECT_FALSE(reader.eof());
57  EXPECT_TRUE(reader.ReadProto(&actual_serialized_data));
58  EXPECT_EQ(2, actual_serialized_data.odometry_data().trajectory_id());
59 
60  EXPECT_TRUE(reader.eof());
61 }
62 
63 TEST_F(InMemoryProtoStreamTest, ReadStreamInitializedIncrementally) {
64  InMemoryProtoStreamReader reader;
65  reader.AddProto(pose_graph_);
66  reader.AddProto(serialized_data_);
67 
68  PoseGraph actual_pose_graph;
69  EXPECT_FALSE(reader.eof());
70  EXPECT_TRUE(reader.ReadProto(&actual_pose_graph));
71  EXPECT_EQ(1, actual_pose_graph.trajectory(0).trajectory_id());
72 
73  SerializedData actual_serialized_data;
74  EXPECT_FALSE(reader.eof());
75  EXPECT_TRUE(reader.ReadProto(&actual_serialized_data));
76  EXPECT_EQ(2, actual_serialized_data.odometry_data().trajectory_id());
77 
78  EXPECT_TRUE(reader.eof());
79 }
80 
81 } // namespace
82 } // namespace io
83 } // namespace cartographer
PoseGraph pose_graph_
_Unique_if< T >::_Single_object make_unique(Args &&... args)
Definition: make_unique.h:46
SerializedData serialized_data_


cartographer
Author(s): The Cartographer Authors
autogenerated on Mon Feb 28 2022 22:00:58