in_memory_proto_stream_test.cc
Go to the documentation of this file.
00001 /*
00002  * Copyright 2018 The Cartographer Authors
00003  *
00004  * Licensed under the Apache License, Version 2.0 (the "License");
00005  * you may not use this file except in compliance with the License.
00006  * You may obtain a copy of the License at
00007  *
00008  *      http://www.apache.org/licenses/LICENSE-2.0
00009  *
00010  * Unless required by applicable law or agreed to in writing, software
00011  * distributed under the License is distributed on an "AS IS" BASIS,
00012  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  * See the License for the specific language governing permissions and
00014  * limitations under the License.
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 }  // namespace
00082 }  // namespace io
00083 }  // namespace cartographer


cartographer
Author(s): The Cartographer Authors
autogenerated on Thu May 9 2019 02:27:35