Implement AddTrajectoryHandlerTest. (#886)

master
Christoph Schütte 2018-02-05 14:50:43 +01:00 committed by Wally B. Feed
parent 28993a8963
commit b0945e4a4d
8 changed files with 158 additions and 16 deletions

View File

@ -87,6 +87,10 @@ class RpcHandlerTestServer : public Server {
WaitForHandlerCompletion(RpcHandlerWrapper<RpcHandlerType>::ON_FINISH); WaitForHandlerCompletion(RpcHandlerWrapper<RpcHandlerType>::ON_FINISH);
} }
const typename RpcHandlerType::ResponseType &response() {
return client_.response();
}
private: private:
using ClientWriter = ::grpc::internal::ClientWriterFactory< using ClientWriter = ::grpc::internal::ClientWriterFactory<
typename RpcHandlerType::RequestType>; typename RpcHandlerType::RequestType>;

View File

@ -15,7 +15,7 @@
*/ */
#include "cartographer_grpc/handlers/add_fixed_frame_pose_data_handler.h" #include "cartographer_grpc/handlers/add_fixed_frame_pose_data_handler.h"
#include "cartographer_grpc/testing/add_data_handler_test.h" #include "cartographer_grpc/testing/handler_test.h"
#include "cartographer_grpc/testing/test_helpers.h" #include "cartographer_grpc/testing/test_helpers.h"
#include "google/protobuf/text_format.h" #include "google/protobuf/text_format.h"
#include "gtest/gtest.h" #include "gtest/gtest.h"
@ -52,7 +52,7 @@ const std::string kMessage = R"PROTO(
})PROTO"; })PROTO";
using AddFixedFramePoseDataHandlerTest = using AddFixedFramePoseDataHandlerTest =
testing::AddDataHandlerTest<AddFixedFramePoseDataHandler>; testing::HandlerTest<AddFixedFramePoseDataHandler>;
TEST_F(AddFixedFramePoseDataHandlerTest, NoLocalSlamUploader) { TEST_F(AddFixedFramePoseDataHandlerTest, NoLocalSlamUploader) {
proto::AddFixedFramePoseDataRequest request; proto::AddFixedFramePoseDataRequest request;

View File

@ -15,7 +15,7 @@
*/ */
#include "cartographer_grpc/handlers/add_imu_data_handler.h" #include "cartographer_grpc/handlers/add_imu_data_handler.h"
#include "cartographer_grpc/testing/add_data_handler_test.h" #include "cartographer_grpc/testing/handler_test.h"
#include "cartographer_grpc/testing/test_helpers.h" #include "cartographer_grpc/testing/test_helpers.h"
#include "google/protobuf/text_format.h" #include "google/protobuf/text_format.h"
#include "gtest/gtest.h" #include "gtest/gtest.h"
@ -48,7 +48,7 @@ const std::string kMessage = R"PROTO(
} }
})PROTO"; })PROTO";
using AddImuDataHandlerTest = testing::AddDataHandlerTest<AddImuDataHandler>; using AddImuDataHandlerTest = testing::HandlerTest<AddImuDataHandler>;
TEST_F(AddImuDataHandlerTest, NoLocalSlamUploader) { TEST_F(AddImuDataHandlerTest, NoLocalSlamUploader) {
proto::AddImuDataRequest request; proto::AddImuDataRequest request;

View File

@ -15,7 +15,7 @@
*/ */
#include "cartographer_grpc/handlers/add_landmark_data_handler.h" #include "cartographer_grpc/handlers/add_landmark_data_handler.h"
#include "cartographer_grpc/testing/add_data_handler_test.h" #include "cartographer_grpc/testing/handler_test.h"
#include "cartographer_grpc/testing/test_helpers.h" #include "cartographer_grpc/testing/test_helpers.h"
#include "google/protobuf/text_format.h" #include "google/protobuf/text_format.h"
#include "gtest/gtest.h" #include "gtest/gtest.h"
@ -56,8 +56,7 @@ const std::string kMessage = R"PROTO(
} }
})PROTO"; })PROTO";
using AddLandmarkDataHandlerTest = using AddLandmarkDataHandlerTest = testing::HandlerTest<AddLandmarkDataHandler>;
testing::AddDataHandlerTest<AddLandmarkDataHandler>;
TEST_F(AddLandmarkDataHandlerTest, NoLocalSlamUploader) { TEST_F(AddLandmarkDataHandlerTest, NoLocalSlamUploader) {
proto::AddLandmarkDataRequest request; proto::AddLandmarkDataRequest request;

View File

@ -15,7 +15,7 @@
*/ */
#include "cartographer_grpc/handlers/add_odometry_data_handler.h" #include "cartographer_grpc/handlers/add_odometry_data_handler.h"
#include "cartographer_grpc/testing/add_data_handler_test.h" #include "cartographer_grpc/testing/handler_test.h"
#include "cartographer_grpc/testing/test_helpers.h" #include "cartographer_grpc/testing/test_helpers.h"
#include "google/protobuf/text_format.h" #include "google/protobuf/text_format.h"
#include "gtest/gtest.h" #include "gtest/gtest.h"
@ -51,8 +51,7 @@ const std::string kMessage = R"PROTO(
} }
})PROTO"; })PROTO";
using AddOdometryDataHandlerTest = using AddOdometryDataHandlerTest = testing::HandlerTest<AddOdometryDataHandler>;
testing::AddDataHandlerTest<AddOdometryDataHandler>;
TEST_F(AddOdometryDataHandlerTest, NoLocalSlamUploader) { TEST_F(AddOdometryDataHandlerTest, NoLocalSlamUploader) {
proto::AddOdometryDataRequest request; proto::AddOdometryDataRequest request;

View File

@ -15,7 +15,7 @@
*/ */
#include "cartographer_grpc/handlers/add_rangefinder_data_handler.h" #include "cartographer_grpc/handlers/add_rangefinder_data_handler.h"
#include "cartographer_grpc/testing/add_data_handler_test.h" #include "cartographer_grpc/testing/handler_test.h"
#include "cartographer_grpc/testing/test_helpers.h" #include "cartographer_grpc/testing/test_helpers.h"
#include "google/protobuf/text_format.h" #include "google/protobuf/text_format.h"
#include "gtest/gtest.h" #include "gtest/gtest.h"
@ -50,7 +50,7 @@ const std::string kMessage = R"PROTO(
})PROTO"; })PROTO";
using AddRangefinderDataHandlerTest = using AddRangefinderDataHandlerTest =
testing::AddDataHandlerTest<AddRangefinderDataHandler>; testing::HandlerTest<AddRangefinderDataHandler>;
TEST_F(AddRangefinderDataHandlerTest, NoLocalSlamUploader) { TEST_F(AddRangefinderDataHandlerTest, NoLocalSlamUploader) {
proto::AddRangefinderDataRequest request; proto::AddRangefinderDataRequest request;

View File

@ -0,0 +1,140 @@
/*
* Copyright 2018 The Cartographer Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "cartographer_grpc/handlers/add_trajectory_handler.h"
#include "cartographer_grpc/sensor/serialization.h"
#include "cartographer_grpc/testing/handler_test.h"
#include "cartographer_grpc/testing/mock_map_builder.h"
#include "cartographer_grpc/testing/test_helpers.h"
#include "google/protobuf/text_format.h"
#include "gtest/gtest.h"
namespace cartographer_grpc {
namespace handlers {
namespace {
using ::testing::_;
using ::testing::ContainerEq;
using ::testing::Eq;
using ::testing::Return;
using ::testing::ReturnRef;
using ::testing::Test;
using ::testing::Truly;
const std::string kMessage = R"PROTO(
expected_sensor_ids {
id: "range_sensor"
type: RANGE
}
expected_sensor_ids {
id: "imu_sensor"
type: IMU
}
trajectory_builder_options {
trajectory_builder_2d_options {
min_range: 20
max_range: 30
}
pure_localization: true
initial_trajectory_pose {
relative_pose {
translation {
x: 1
y: 2
z: 3
}
rotation {
x: 4
y: 5
z: 6
w: 7
}
}
to_trajectory_id: 8
timestamp: 9
}
}
)PROTO";
class AddTrajectoryHandlerTest
: public testing::HandlerTest<AddTrajectoryHandler> {
public:
void SetUp() override {
testing::HandlerTest<AddTrajectoryHandler>::SetUp();
mock_map_builder_ =
cartographer::common::make_unique<testing::MockMapBuilder>();
EXPECT_CALL(*mock_map_builder_context_,
GetLocalSlamResultCallbackForSubscriptions())
.WillOnce(Return(nullptr));
EXPECT_CALL(*mock_map_builder_context_, map_builder())
.WillOnce(ReturnRef(*mock_map_builder_));
}
protected:
std::set<cartographer::mapping::TrajectoryBuilderInterface::SensorId>
ParseSensorIds(const proto::AddTrajectoryRequest &request) {
std::set<cartographer::mapping::TrajectoryBuilderInterface::SensorId>
expected_sensor_ids;
for (const auto &sensor_id : request.expected_sensor_ids()) {
expected_sensor_ids.insert(sensor::FromProto(sensor_id));
}
return expected_sensor_ids;
}
std::unique_ptr<testing::MockMapBuilder> mock_map_builder_;
};
TEST_F(AddTrajectoryHandlerTest, NoLocalSlamUploader) {
SetNoLocalTrajectoryUploader();
proto::AddTrajectoryRequest request;
EXPECT_TRUE(
google::protobuf::TextFormat::ParseFromString(kMessage, &request));
EXPECT_CALL(*mock_map_builder_,
AddTrajectoryBuilder(ContainerEq(ParseSensorIds(request)),
Truly(testing::BuildProtoPredicateEquals(
&request.trajectory_builder_options())),
_))
.WillOnce(Return(13));
test_server_->SendWrite(request);
EXPECT_EQ(test_server_->response().trajectory_id(), 13);
}
TEST_F(AddTrajectoryHandlerTest, WithLocalSlamUploader) {
SetMockLocalTrajectoryUploader();
proto::AddTrajectoryRequest request;
EXPECT_TRUE(
google::protobuf::TextFormat::ParseFromString(kMessage, &request));
EXPECT_CALL(*mock_map_builder_,
AddTrajectoryBuilder(ContainerEq(ParseSensorIds(request)),
Truly(testing::BuildProtoPredicateEquals(
&request.trajectory_builder_options())),
_))
.WillOnce(Return(13));
auto upstream_trajectory_builder_options =
request.trajectory_builder_options();
upstream_trajectory_builder_options.clear_trajectory_builder_2d_options();
upstream_trajectory_builder_options.clear_trajectory_builder_3d_options();
EXPECT_CALL(*mock_local_trajectory_uploader_,
AddTrajectory(Eq(13), ParseSensorIds(request),
Truly(testing::BuildProtoPredicateEquals(
&upstream_trajectory_builder_options))));
test_server_->SendWrite(request);
EXPECT_EQ(test_server_->response().trajectory_id(), 13);
}
} // namespace
} // namespace handlers
} // namespace cartographer_grpc

View File

@ -14,8 +14,8 @@
* limitations under the License. * limitations under the License.
*/ */
#ifndef CARTOGRAPHER_GRPC_TESTING_ADD_DATA_HANDLER_TEST_H #ifndef CARTOGRAPHER_GRPC_TESTING_HANDLER_TEST_H
#define CARTOGRAPHER_GRPC_TESTING_ADD_DATA_HANDLER_TEST_H #define CARTOGRAPHER_GRPC_TESTING_HANDLER_TEST_H
#include "cartographer/common/make_unique.h" #include "cartographer/common/make_unique.h"
#include "cartographer_grpc/framework/testing/rpc_handler_test_server.h" #include "cartographer_grpc/framework/testing/rpc_handler_test_server.h"
@ -30,7 +30,7 @@ using ::testing::Return;
using ::testing::Test; using ::testing::Test;
template <typename HandlerType> template <typename HandlerType>
class AddDataHandlerTest : public Test { class HandlerTest : public Test {
public: public:
void SetUp() override { void SetUp() override {
test_server_ = cartographer::common::make_unique< test_server_ = cartographer::common::make_unique<
@ -63,4 +63,4 @@ class AddDataHandlerTest : public Test {
} // namespace testing } // namespace testing
} // namespace cartographer_grpc } // namespace cartographer_grpc
#endif // CARTOGRAPHER_GRPC_TESTING_ADD_DATA_HANDLER_TEST_H #endif // CARTOGRAPHER_GRPC_TESTING_HANDLER_TEST_H