proto_stream_test.cc
Go to the documentation of this file.
1 /*
2  * Copyright 2016 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 
19 #include <errno.h>
20 #include <stdio.h>
21 #include <stdlib.h>
22 #include <string.h>
23 
25 #include "cartographer/mapping/proto/trajectory.pb.h"
26 #include "gtest/gtest.h"
27 
28 namespace cartographer {
29 namespace io {
30 namespace {
31 
32 class ProtoStreamTest : public ::testing::Test {
33  protected:
34  void SetUp() override {
35  const string tmpdir = P_tmpdir;
36  test_directory_ = tmpdir + "/proto_stream_test_XXXXXX";
37  ASSERT_NE(mkdtemp(&test_directory_[0]), nullptr) << strerror(errno);
38  }
39 
40  void TearDown() override { remove(test_directory_.c_str()); }
41 
43 };
44 
45 TEST_F(ProtoStreamTest, WriteAndReadBack) {
46  const string test_file = test_directory_ + "/test_trajectory.pbstream";
47  {
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);
53  }
54  ASSERT_TRUE(writer.Close());
55  }
56  {
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());
63  }
64  mapping::proto::Trajectory trajectory;
65  EXPECT_FALSE(reader.ReadProto(&trajectory));
66  }
67  remove(test_file.c_str());
68 }
69 
70 } // namespace
71 } // namespace io
72 } // namespace cartographer
string test_directory_


cartographer
Author(s):
autogenerated on Wed Jun 5 2019 21:57:58