22 #include "google/protobuf/text_format.h" 23 #include "gtest/gtest.h" 31 using ::testing::ContainerEq;
33 using ::testing::Return;
34 using ::testing::ReturnRef;
35 using ::testing::Test;
36 using ::testing::Truly;
38 const std::string kMessage = R
"( 47 trajectory_builder_options { 48 trajectory_builder_2d_options { 52 pure_localization: true 53 initial_trajectory_pose { 68 class AddTrajectoryHandlerTest
69 :
public testing::HandlerTest<AddTrajectorySignature,
70 AddTrajectoryHandler> {
72 void SetUp()
override {
75 EXPECT_CALL(*mock_map_builder_context_,
76 GetLocalSlamResultCallbackForSubscriptions())
77 .WillOnce(Return(
nullptr));
78 EXPECT_CALL(*mock_map_builder_context_, map_builder())
83 std::set<mapping::TrajectoryBuilderInterface::SensorId> ParseSensorIds(
84 const proto::AddTrajectoryRequest &request) {
85 std::set<mapping::TrajectoryBuilderInterface::SensorId> expected_sensor_ids;
86 for (
const auto &sensor_id : request.expected_sensor_ids()) {
89 return expected_sensor_ids;
95 TEST_F(AddTrajectoryHandlerTest, NoLocalSlamUploader) {
96 SetNoLocalTrajectoryUploader();
97 proto::AddTrajectoryRequest request;
99 google::protobuf::TextFormat::ParseFromString(kMessage, &request));
101 AddTrajectoryBuilder(ContainerEq(ParseSensorIds(request)),
103 &request.trajectory_builder_options())),
105 .WillOnce(Return(13));
106 test_server_->SendWrite(request);
107 EXPECT_EQ(test_server_->response().trajectory_id(), 13);
110 TEST_F(AddTrajectoryHandlerTest, WithLocalSlamUploader) {
111 SetMockLocalTrajectoryUploader();
112 proto::AddTrajectoryRequest request;
114 google::protobuf::TextFormat::ParseFromString(kMessage, &request));
116 AddTrajectoryBuilder(ContainerEq(ParseSensorIds(request)),
118 &request.trajectory_builder_options())),
120 .WillOnce(Return(13));
121 auto upstream_trajectory_builder_options =
122 request.trajectory_builder_options();
123 upstream_trajectory_builder_options.clear_trajectory_builder_2d_options();
124 upstream_trajectory_builder_options.clear_trajectory_builder_3d_options();
125 upstream_trajectory_builder_options.set_pure_localization(
false);
126 EXPECT_CALL(*mock_local_trajectory_uploader_,
127 AddTrajectory(Eq(13), ParseSensorIds(request),
129 &upstream_trajectory_builder_options))));
130 test_server_->SendWrite(request);
131 EXPECT_EQ(test_server_->response().trajectory_id(), 13);
mapping::TrajectoryBuilderInterface::SensorId FromProto(const proto::SensorId &proto)
std::unique_ptr< mapping::testing::MockMapBuilder > mock_map_builder_
ProtoPredicateType BuildProtoPredicateEquals(const google::protobuf::Message *proto)