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/proto_stream.h"
00018
00019 #include <errno.h>
00020 #include <stdio.h>
00021 #include <stdlib.h>
00022 #include <string.h>
00023
00024 #include "cartographer/common/port.h"
00025 #include "cartographer/mapping/proto/trajectory.pb.h"
00026 #include "gtest/gtest.h"
00027
00028 namespace cartographer {
00029 namespace io {
00030 namespace {
00031
00032 class ProtoStreamTest : public ::testing::Test {
00033 protected:
00034 void SetUp() override { test_directory_ = "."; }
00035
00036 std::string test_directory_;
00037 };
00038
00039 TEST_F(ProtoStreamTest, WriteAndReadBack) {
00040 const std::string test_file = test_directory_ + "/test_trajectory.pbstream";
00041 {
00042 ProtoStreamWriter writer(test_file);
00043 for (int i = 0; i != 10; ++i) {
00044 mapping::proto::Trajectory trajectory;
00045 trajectory.add_node()->set_timestamp(i);
00046 writer.WriteProto(trajectory);
00047 }
00048 ASSERT_TRUE(writer.Close());
00049 }
00050 {
00051 ProtoStreamReader reader(test_file);
00052 for (int i = 0; i != 10; ++i) {
00053 mapping::proto::Trajectory trajectory;
00054 ASSERT_TRUE(reader.ReadProto(&trajectory));
00055 ASSERT_EQ(1, trajectory.node_size());
00056 EXPECT_EQ(i, trajectory.node(0).timestamp());
00057 }
00058 mapping::proto::Trajectory trajectory;
00059 EXPECT_FALSE(reader.ReadProto(&trajectory));
00060 }
00061 remove(test_file.c_str());
00062 }
00063
00064 }
00065 }
00066 }