add_odometry_data_handler_test.cc
Go to the documentation of this file.
1 /*
2  * Copyright 2018 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 
20 #include "google/protobuf/text_format.h"
21 #include "gtest/gtest.h"
22 
23 namespace cartographer {
24 namespace cloud {
25 namespace handlers {
26 namespace {
27 
28 using ::testing::_;
29 using ::testing::Eq;
30 using ::testing::Pointee;
31 using ::testing::Truly;
32 
33 const std::string kMessage = R"(
34  sensor_metadata {
35  trajectory_id: 1
36  sensor_id: "sensor_id"
37  }
38  odometry_data {
39  timestamp: 2
40  pose {
41  translation {
42  x: 3 y: 4 z: 5
43  }
44  rotation {
45  w: 6 x: 7 y: 8 z: 9
46  }
47  }
48  })";
49 
50 using AddOdometryDataHandlerTest =
51  testing::HandlerTest<AddOdometryDataSignature, AddOdometryDataHandler>;
52 
53 TEST_F(AddOdometryDataHandlerTest, NoLocalSlamUploader) {
54  proto::AddOdometryDataRequest request;
55  EXPECT_TRUE(
56  google::protobuf::TextFormat::ParseFromString(kMessage, &request));
57  SetNoLocalTrajectoryUploader();
58  EXPECT_CALL(*mock_map_builder_context_,
59  DoEnqueueSensorData(
60  Eq(request.sensor_metadata().trajectory_id()),
61  Pointee(Truly(testing::BuildDataPredicateEquals(request)))));
62  test_server_->SendWrite(request);
63  test_server_->SendWritesDone();
64  test_server_->SendFinish();
65 }
66 
67 TEST_F(AddOdometryDataHandlerTest, WithMockLocalSlamUploader) {
68  proto::AddOdometryDataRequest request;
69  EXPECT_TRUE(
70  google::protobuf::TextFormat::ParseFromString(kMessage, &request));
71  SetMockLocalTrajectoryUploader();
72  EXPECT_CALL(*mock_map_builder_context_,
73  DoEnqueueSensorData(
74  Eq(request.sensor_metadata().trajectory_id()),
75  Pointee(Truly(testing::BuildDataPredicateEquals(request)))));
76  proto::SensorData sensor_data;
77  *sensor_data.mutable_sensor_metadata() = request.sensor_metadata();
78  *sensor_data.mutable_odometry_data() = request.odometry_data();
79  EXPECT_CALL(*mock_local_trajectory_uploader_,
80  DoEnqueueSensorData(Pointee(
81  Truly(testing::BuildProtoPredicateEquals(&sensor_data)))));
82  test_server_->SendWrite(request);
83  test_server_->SendWritesDone();
84  test_server_->SendFinish();
85 }
86 
87 } // namespace
88 } // namespace handlers
89 } // namespace cloud
90 } // namespace cartographer
DataPredicateType BuildDataPredicateEquals(const T &proto)
ProtoPredicateType BuildProtoPredicateEquals(const google::protobuf::Message *proto)


cartographer
Author(s): The Cartographer Authors
autogenerated on Mon Feb 28 2022 22:00:58