add_landmark_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  landmark_data {
39  timestamp: 2
40  landmark_observations {
41  id: "3"
42  landmark_to_tracking_transform {
43  translation {
44  x: 4 y: 5 z: 6
45  }
46  rotation {
47  w:7 x: 8 y: 9 z: 10
48  }
49  }
50  translation_weight: 11.0
51  rotation_weight: 12.0
52  }
53  })";
54 
55 using AddLandmarkDataHandlerTest =
56  testing::HandlerTest<AddLandmarkDataSignature, AddLandmarkDataHandler>;
57 
58 TEST_F(AddLandmarkDataHandlerTest, NoLocalSlamUploader) {
59  proto::AddLandmarkDataRequest request;
60  EXPECT_TRUE(
61  google::protobuf::TextFormat::ParseFromString(kMessage, &request));
62  SetNoLocalTrajectoryUploader();
63  EXPECT_CALL(*mock_map_builder_context_,
64  DoEnqueueSensorData(
65  Eq(request.sensor_metadata().trajectory_id()),
66  Pointee(Truly(testing::BuildDataPredicateEquals(request)))));
67  test_server_->SendWrite(request);
68  test_server_->SendWritesDone();
69  test_server_->SendFinish();
70 }
71 
72 TEST_F(AddLandmarkDataHandlerTest, WithMockLocalSlamUploader) {
73  proto::AddLandmarkDataRequest request;
74  EXPECT_TRUE(
75  google::protobuf::TextFormat::ParseFromString(kMessage, &request));
76  SetMockLocalTrajectoryUploader();
77  EXPECT_CALL(*mock_map_builder_context_,
78  DoEnqueueSensorData(
79  Eq(request.sensor_metadata().trajectory_id()),
80  Pointee(Truly(testing::BuildDataPredicateEquals(request)))));
81  proto::SensorData sensor_data;
82  *sensor_data.mutable_sensor_metadata() = request.sensor_metadata();
83  *sensor_data.mutable_landmark_data() = request.landmark_data();
84  EXPECT_CALL(*mock_local_trajectory_uploader_,
85  DoEnqueueSensorData(Pointee(
86  Truly(testing::BuildProtoPredicateEquals(&sensor_data)))));
87  test_server_->SendWrite(request);
88  test_server_->SendWritesDone();
89  test_server_->SendFinish();
90 }
91 
92 } // namespace
93 } // namespace handlers
94 } // namespace cloud
95 } // 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