25 #include "cartographer/mapping/proto/trajectory.pb.h" 26 #include "gtest/gtest.h" 32 class ProtoStreamTest :
public ::testing::Test {
34 void SetUp()
override {
35 const string tmpdir = P_tmpdir;
45 TEST_F(ProtoStreamTest, WriteAndReadBack) {
48 ProtoStreamWriter writer(test_file);
49 for (
int i = 0; i != 10; ++i) {
50 mapping::proto::Trajectory trajectory;
51 trajectory.add_node()->set_timestamp(i);
52 writer.WriteProto(trajectory);
54 ASSERT_TRUE(writer.Close());
57 ProtoStreamReader reader(test_file);
58 for (
int i = 0; i != 10; ++i) {
59 mapping::proto::Trajectory trajectory;
60 ASSERT_TRUE(reader.ReadProto(&trajectory));
61 ASSERT_EQ(1, trajectory.node_size());
62 EXPECT_EQ(i, trajectory.node(0).timestamp());
64 mapping::proto::Trajectory trajectory;
65 EXPECT_FALSE(reader.ReadProto(&trajectory));
67 remove(test_file.c_str());