proto_stream_test.cc
Go to the documentation of this file.
00001 /*
00002  * Copyright 2016 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/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 }  // namespace
00065 }  // namespace io
00066 }  // namespace cartographer


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