Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #include "cartographer/io/internal/in_memory_proto_stream.h"
00018
00019 #include "cartographer/mapping/proto/pose_graph.pb.h"
00020 #include "cartographer/mapping/proto/serialization.pb.h"
00021 #include "gtest/gtest.h"
00022
00023 namespace cartographer {
00024 namespace io {
00025 namespace {
00026
00027 using absl::make_unique;
00028 using google::protobuf::Message;
00029 using mapping::proto::PoseGraph;
00030 using mapping::proto::SerializedData;
00031
00032 class InMemoryProtoStreamTest : public ::testing::Test {
00033 protected:
00034 void SetUp() override {
00035 pose_graph_.add_trajectory()->set_trajectory_id(1);
00036 serialized_data_.mutable_odometry_data()->set_trajectory_id(2);
00037 }
00038
00039 PoseGraph pose_graph_;
00040 SerializedData serialized_data_;
00041 };
00042
00043 TEST_F(InMemoryProtoStreamTest, ReadStreamInitializedFromQueue) {
00044 std::queue<std::unique_ptr<Message>> proto_queue;
00045 proto_queue.push(make_unique<PoseGraph>(pose_graph_));
00046 proto_queue.push(make_unique<SerializedData>(serialized_data_));
00047
00048 InMemoryProtoStreamReader reader(std::move(proto_queue));
00049
00050 PoseGraph actual_pose_graph;
00051 EXPECT_FALSE(reader.eof());
00052 EXPECT_TRUE(reader.ReadProto(&actual_pose_graph));
00053 EXPECT_EQ(1, actual_pose_graph.trajectory(0).trajectory_id());
00054
00055 SerializedData actual_serialized_data;
00056 EXPECT_FALSE(reader.eof());
00057 EXPECT_TRUE(reader.ReadProto(&actual_serialized_data));
00058 EXPECT_EQ(2, actual_serialized_data.odometry_data().trajectory_id());
00059
00060 EXPECT_TRUE(reader.eof());
00061 }
00062
00063 TEST_F(InMemoryProtoStreamTest, ReadStreamInitializedIncrementally) {
00064 InMemoryProtoStreamReader reader;
00065 reader.AddProto(pose_graph_);
00066 reader.AddProto(serialized_data_);
00067
00068 PoseGraph actual_pose_graph;
00069 EXPECT_FALSE(reader.eof());
00070 EXPECT_TRUE(reader.ReadProto(&actual_pose_graph));
00071 EXPECT_EQ(1, actual_pose_graph.trajectory(0).trajectory_id());
00072
00073 SerializedData actual_serialized_data;
00074 EXPECT_FALSE(reader.eof());
00075 EXPECT_TRUE(reader.ReadProto(&actual_serialized_data));
00076 EXPECT_EQ(2, actual_serialized_data.odometry_data().trajectory_id());
00077
00078 EXPECT_TRUE(reader.eof());
00079 }
00080
00081 }
00082 }
00083 }