add_landmark_data_handler_test.cc
Go to the documentation of this file.
00001 /*
00002  * Copyright 2018 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/cloud/internal/handlers/add_landmark_data_handler.h"
00018 
00019 #include "cartographer/cloud/internal/testing/handler_test.h"
00020 #include "cartographer/cloud/internal/testing/test_helpers.h"
00021 #include "google/protobuf/text_format.h"
00022 #include "gtest/gtest.h"
00023 
00024 namespace cartographer {
00025 namespace cloud {
00026 namespace handlers {
00027 namespace {
00028 
00029 using ::testing::_;
00030 using ::testing::Eq;
00031 using ::testing::Pointee;
00032 using ::testing::Truly;
00033 
00034 const std::string kMessage = R"(
00035   sensor_metadata {
00036     trajectory_id: 1
00037     sensor_id: "sensor_id"
00038   }
00039   landmark_data {
00040     timestamp: 2
00041     landmark_observations {
00042       id: "3"
00043       landmark_to_tracking_transform {
00044         translation {
00045           x: 4 y: 5 z: 6
00046         }
00047         rotation {
00048           w:7 x: 8 y: 9 z: 10
00049         }
00050       }
00051       translation_weight: 11.0
00052       rotation_weight: 12.0
00053     }
00054   })";
00055 
00056 using AddLandmarkDataHandlerTest =
00057     testing::HandlerTest<AddLandmarkDataSignature, AddLandmarkDataHandler>;
00058 
00059 TEST_F(AddLandmarkDataHandlerTest, NoLocalSlamUploader) {
00060   proto::AddLandmarkDataRequest request;
00061   EXPECT_TRUE(
00062       google::protobuf::TextFormat::ParseFromString(kMessage, &request));
00063   SetNoLocalTrajectoryUploader();
00064   EXPECT_CALL(
00065       *mock_map_builder_context_,
00066       CheckClientIdForTrajectory(Eq(request.sensor_metadata().client_id()),
00067                                  Eq(request.sensor_metadata().trajectory_id())))
00068       .WillOnce(::testing::Return(true));
00069   EXPECT_CALL(*mock_map_builder_context_,
00070               DoEnqueueSensorData(
00071                   Eq(request.sensor_metadata().trajectory_id()),
00072                   Pointee(Truly(testing::BuildDataPredicateEquals(request)))));
00073   test_server_->SendWrite(request);
00074   test_server_->SendWritesDone();
00075   test_server_->SendFinish();
00076 }
00077 
00078 TEST_F(AddLandmarkDataHandlerTest, WithMockLocalSlamUploader) {
00079   proto::AddLandmarkDataRequest request;
00080   EXPECT_TRUE(
00081       google::protobuf::TextFormat::ParseFromString(kMessage, &request));
00082   SetMockLocalTrajectoryUploader();
00083   EXPECT_CALL(
00084       *mock_map_builder_context_,
00085       CheckClientIdForTrajectory(Eq(request.sensor_metadata().client_id()),
00086                                  Eq(request.sensor_metadata().trajectory_id())))
00087       .WillOnce(::testing::Return(true));
00088   EXPECT_CALL(*mock_map_builder_context_,
00089               DoEnqueueSensorData(
00090                   Eq(request.sensor_metadata().trajectory_id()),
00091                   Pointee(Truly(testing::BuildDataPredicateEquals(request)))));
00092   proto::SensorData sensor_data;
00093   *sensor_data.mutable_sensor_metadata() = request.sensor_metadata();
00094   *sensor_data.mutable_landmark_data() = request.landmark_data();
00095   EXPECT_CALL(*mock_local_trajectory_uploader_,
00096               DoEnqueueSensorData(Pointee(
00097                   Truly(testing::BuildProtoPredicateEquals(&sensor_data)))));
00098   test_server_->SendWrite(request);
00099   test_server_->SendWritesDone();
00100   test_server_->SendFinish();
00101 }
00102 
00103 }  // namespace
00104 }  // namespace handlers
00105 }  // namespace cloud
00106 }  // namespace cartographer


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