23 #include "cartographer/mapping/proto/internal/legacy_serialized_data.pb.h" 24 #include "cartographer/mapping/proto/pose_graph.pb.h" 25 #include "cartographer/mapping/proto/serialization.pb.h" 26 #include "cartographer/mapping/proto/trajectory_builder_options.pb.h" 27 #include "gmock/gmock.h" 28 #include "google/protobuf/text_format.h" 29 #include "gtest/gtest.h" 35 using ::google::protobuf::TextFormat;
37 using ::testing::SizeIs;
39 class MigrationTest :
public ::testing::Test {
42 writer_.reset(
new ForwardingProtoStreamWriter(
43 [
this](
const google::protobuf::Message* proto) ->
bool {
44 std::string msg_string;
45 TextFormat::PrintToString(*proto, &msg_string);
50 mapping::proto::PoseGraph pose_graph;
51 mapping::proto::AllTrajectoryBuilderOptions all_options;
52 mapping::proto::LegacySerializedData submap;
53 submap.mutable_submap();
54 mapping::proto::LegacySerializedData node;
56 mapping::proto::LegacySerializedData imu_data;
57 imu_data.mutable_imu_data();
58 mapping::proto::LegacySerializedData odometry_data;
59 odometry_data.mutable_odometry_data();
60 mapping::proto::LegacySerializedData fixed_frame_pose;
61 fixed_frame_pose.mutable_fixed_frame_pose_data();
62 mapping::proto::LegacySerializedData trajectory_data;
63 trajectory_data.mutable_trajectory_data();
64 mapping::proto::LegacySerializedData landmark_data;
65 landmark_data.mutable_landmark_data();
72 reader_.AddProto(odometry_data);
73 reader_.AddProto(fixed_frame_pose);
74 reader_.AddProto(trajectory_data);
75 reader_.AddProto(landmark_data);
79 std::unique_ptr<ForwardingProtoStreamWriter>
writer_;
85 TEST_F(MigrationTest, MigrationAddsHeaderAsFirstMessage) {
91 mapping::proto::SerializationHeader header;
93 EXPECT_THAT(header.format_version(), Eq(1));
96 TEST_F(MigrationTest, SerializedDataOrderIsCorrect) {
100 std::vector<mapping::proto::SerializedData> serialized(
107 EXPECT_TRUE(serialized[0].has_pose_graph());
108 EXPECT_TRUE(serialized[1].has_all_trajectory_builder_options());
109 EXPECT_TRUE(serialized[2].has_submap());
110 EXPECT_TRUE(serialized[3].has_node());
111 EXPECT_TRUE(serialized[4].has_trajectory_data());
112 EXPECT_TRUE(serialized[5].has_imu_data());
113 EXPECT_TRUE(serialized[6].has_odometry_data());
114 EXPECT_TRUE(serialized[7].has_fixed_frame_pose_data());
115 EXPECT_TRUE(serialized[8].has_landmark_data());
void MigrateStreamFormatToVersion1(cartographer::io::ProtoStreamReaderInterface *const input, cartographer::io::ProtoStreamWriterInterface *const output)