Implement tests for various data adding handlers (#881)
parent
92fa1782f3
commit
86a8944589
|
@ -20,6 +20,7 @@
|
||||||
#include "cartographer_grpc/framework/retry.h"
|
#include "cartographer_grpc/framework/retry.h"
|
||||||
#include "cartographer_grpc/framework/rpc_handler_interface.h"
|
#include "cartographer_grpc/framework/rpc_handler_interface.h"
|
||||||
#include "cartographer_grpc/framework/type_traits.h"
|
#include "cartographer_grpc/framework/type_traits.h"
|
||||||
|
#include "glog/logging.h"
|
||||||
#include "grpc++/grpc++.h"
|
#include "grpc++/grpc++.h"
|
||||||
#include "grpc++/impl/codegen/client_unary_call.h"
|
#include "grpc++/impl/codegen/client_unary_call.h"
|
||||||
#include "grpc++/impl/codegen/sync_stream.h"
|
#include "grpc++/impl/codegen/sync_stream.h"
|
||||||
|
|
|
@ -0,0 +1,90 @@
|
||||||
|
/*
|
||||||
|
* 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_fixed_frame_pose_data_handler.h"
|
||||||
|
#include "cartographer_grpc/testing/add_data_handler_test.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::Eq;
|
||||||
|
using ::testing::Pointee;
|
||||||
|
using ::testing::Truly;
|
||||||
|
|
||||||
|
const std::string kMessage = R"PROTO(
|
||||||
|
sensor_metadata {
|
||||||
|
trajectory_id: 1
|
||||||
|
sensor_id: "sensor_id"
|
||||||
|
}
|
||||||
|
fixed_frame_pose_data {
|
||||||
|
timestamp: 2
|
||||||
|
pose {
|
||||||
|
translation {
|
||||||
|
x: 3
|
||||||
|
y: 4
|
||||||
|
z: 5
|
||||||
|
}
|
||||||
|
rotation {
|
||||||
|
x: 6
|
||||||
|
y: 7
|
||||||
|
z: 8
|
||||||
|
w: 9
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})PROTO";
|
||||||
|
|
||||||
|
using AddFixedFramePoseDataHandlerTest =
|
||||||
|
testing::AddDataHandlerTest<AddFixedFramePoseDataHandler>;
|
||||||
|
|
||||||
|
TEST_F(AddFixedFramePoseDataHandlerTest, NoLocalSlamUploader) {
|
||||||
|
proto::AddFixedFramePoseDataRequest request;
|
||||||
|
EXPECT_TRUE(
|
||||||
|
google::protobuf::TextFormat::ParseFromString(kMessage, &request));
|
||||||
|
SetNoLocalTrajectoryUploader();
|
||||||
|
EXPECT_CALL(*mock_map_builder_context_,
|
||||||
|
DoEnqueueSensorData(
|
||||||
|
Eq(request.sensor_metadata().trajectory_id()),
|
||||||
|
Pointee(Truly(testing::BuildDataPredicateEquals(request)))));
|
||||||
|
test_server_->SendWrite(request);
|
||||||
|
test_server_->SendWritesDone();
|
||||||
|
test_server_->SendFinish();
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(AddFixedFramePoseDataHandlerTest, WithMockLocalSlamUploader) {
|
||||||
|
proto::AddFixedFramePoseDataRequest request;
|
||||||
|
EXPECT_TRUE(
|
||||||
|
google::protobuf::TextFormat::ParseFromString(kMessage, &request));
|
||||||
|
SetMockLocalTrajectoryUploader();
|
||||||
|
EXPECT_CALL(*mock_map_builder_context_,
|
||||||
|
DoEnqueueSensorData(
|
||||||
|
Eq(request.sensor_metadata().trajectory_id()),
|
||||||
|
Pointee(Truly(testing::BuildDataPredicateEquals(request)))));
|
||||||
|
EXPECT_CALL(*mock_local_trajectory_uploader_,
|
||||||
|
DoEnqueueDataRequest(Pointee(
|
||||||
|
Truly(testing::BuildProtoPredicateEquals(&request)))));
|
||||||
|
test_server_->SendWrite(request);
|
||||||
|
test_server_->SendWritesDone();
|
||||||
|
test_server_->SendFinish();
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace
|
||||||
|
} // namespace handlers
|
||||||
|
} // namespace cartographer_grpc
|
|
@ -15,13 +15,9 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "cartographer_grpc/handlers/add_imu_data_handler.h"
|
#include "cartographer_grpc/handlers/add_imu_data_handler.h"
|
||||||
#include "cartographer/common/make_unique.h"
|
#include "cartographer_grpc/testing/add_data_handler_test.h"
|
||||||
#include "cartographer/sensor/dispatchable.h"
|
#include "cartographer_grpc/testing/test_helpers.h"
|
||||||
#include "cartographer_grpc/framework/testing/rpc_handler_test_server.h"
|
|
||||||
#include "cartographer_grpc/testing/mock_local_trajectory_uploader.h"
|
|
||||||
#include "cartographer_grpc/testing/mock_map_builder_context.h"
|
|
||||||
#include "google/protobuf/text_format.h"
|
#include "google/protobuf/text_format.h"
|
||||||
#include "google/protobuf/util/message_differencer.h"
|
|
||||||
#include "gtest/gtest.h"
|
#include "gtest/gtest.h"
|
||||||
|
|
||||||
namespace cartographer_grpc {
|
namespace cartographer_grpc {
|
||||||
|
@ -31,8 +27,6 @@ namespace {
|
||||||
using ::testing::_;
|
using ::testing::_;
|
||||||
using ::testing::Eq;
|
using ::testing::Eq;
|
||||||
using ::testing::Pointee;
|
using ::testing::Pointee;
|
||||||
using ::testing::Return;
|
|
||||||
using ::testing::Test;
|
|
||||||
using ::testing::Truly;
|
using ::testing::Truly;
|
||||||
|
|
||||||
const std::string kMessage = R"PROTO(
|
const std::string kMessage = R"PROTO(
|
||||||
|
@ -54,87 +48,35 @@ const std::string kMessage = R"PROTO(
|
||||||
}
|
}
|
||||||
})PROTO";
|
})PROTO";
|
||||||
|
|
||||||
using DataPredicateType =
|
using AddImuDataHandlerTest = testing::AddDataHandlerTest<AddImuDataHandler>;
|
||||||
std::function<bool(const cartographer::sensor::Data &)>;
|
|
||||||
using ProtoPredicateType =
|
|
||||||
std::function<bool(const google::protobuf::Message &)>;
|
|
||||||
|
|
||||||
class AddImuDataHandlerTest : public Test {
|
|
||||||
public:
|
|
||||||
void SetUp() override {
|
|
||||||
test_server_ = cartographer::common::make_unique<
|
|
||||||
framework::testing::RpcHandlerTestServer<AddImuDataHandler>>(
|
|
||||||
cartographer::common::make_unique<testing::MockMapBuilderContext>());
|
|
||||||
mock_map_builder_context_ =
|
|
||||||
test_server_
|
|
||||||
->GetUnsynchronizedContext<testing::MockMapBuilderContext>();
|
|
||||||
mock_local_trajectory_uploader_ = cartographer::common::make_unique<
|
|
||||||
testing::MockLocalTrajectoryUploader>();
|
|
||||||
EXPECT_TRUE(
|
|
||||||
google::protobuf::TextFormat::ParseFromString(kMessage, &request_));
|
|
||||||
}
|
|
||||||
|
|
||||||
void SetNoLocalTrajectoryUploader() {
|
|
||||||
EXPECT_CALL(*mock_map_builder_context_, local_trajectory_uploader())
|
|
||||||
.WillOnce(Return(nullptr));
|
|
||||||
}
|
|
||||||
|
|
||||||
void SetMockLocalTrajectoryUploader() {
|
|
||||||
EXPECT_CALL(*mock_map_builder_context_, local_trajectory_uploader())
|
|
||||||
.WillRepeatedly(Return(mock_local_trajectory_uploader_.get()));
|
|
||||||
}
|
|
||||||
|
|
||||||
protected:
|
|
||||||
std::unique_ptr<framework::testing::RpcHandlerTestServer<AddImuDataHandler>>
|
|
||||||
test_server_;
|
|
||||||
testing::MockMapBuilderContext *mock_map_builder_context_;
|
|
||||||
std::unique_ptr<testing::MockLocalTrajectoryUploader>
|
|
||||||
mock_local_trajectory_uploader_;
|
|
||||||
proto::AddImuDataRequest request_;
|
|
||||||
};
|
|
||||||
|
|
||||||
DataPredicateType BuildDataPredicateEquals(
|
|
||||||
const proto::AddImuDataRequest &proto) {
|
|
||||||
return [proto](const cartographer::sensor::Data &data) {
|
|
||||||
const auto *dispatchable =
|
|
||||||
dynamic_cast<const cartographer::sensor::Dispatchable<
|
|
||||||
cartographer::sensor::ImuData> *>(&data);
|
|
||||||
CHECK_NOTNULL(dispatchable);
|
|
||||||
return google::protobuf::util::MessageDifferencer::Equals(
|
|
||||||
cartographer::sensor::ToProto(dispatchable->data()),
|
|
||||||
proto.imu_data()) &&
|
|
||||||
dispatchable->GetSensorId() == proto.sensor_metadata().sensor_id();
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
ProtoPredicateType BuildProtoPredicateEquals(
|
|
||||||
const google::protobuf::Message *proto) {
|
|
||||||
return [proto](const google::protobuf::Message &message) {
|
|
||||||
return google::protobuf::util::MessageDifferencer::Equals(*proto, message);
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(AddImuDataHandlerTest, NoLocalSlamUploader) {
|
TEST_F(AddImuDataHandlerTest, NoLocalSlamUploader) {
|
||||||
|
proto::AddImuDataRequest request;
|
||||||
|
EXPECT_TRUE(
|
||||||
|
google::protobuf::TextFormat::ParseFromString(kMessage, &request));
|
||||||
SetNoLocalTrajectoryUploader();
|
SetNoLocalTrajectoryUploader();
|
||||||
EXPECT_CALL(
|
EXPECT_CALL(*mock_map_builder_context_,
|
||||||
*mock_map_builder_context_,
|
DoEnqueueSensorData(
|
||||||
DoEnqueueSensorData(Eq(request_.sensor_metadata().trajectory_id()),
|
Eq(request.sensor_metadata().trajectory_id()),
|
||||||
Pointee(Truly(BuildDataPredicateEquals(request_)))));
|
Pointee(Truly(testing::BuildDataPredicateEquals(request)))));
|
||||||
test_server_->SendWrite(request_);
|
test_server_->SendWrite(request);
|
||||||
test_server_->SendWritesDone();
|
test_server_->SendWritesDone();
|
||||||
test_server_->SendFinish();
|
test_server_->SendFinish();
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(AddImuDataHandlerTest, WithMockLocalSlamUploader) {
|
TEST_F(AddImuDataHandlerTest, WithMockLocalSlamUploader) {
|
||||||
|
proto::AddImuDataRequest request;
|
||||||
|
EXPECT_TRUE(
|
||||||
|
google::protobuf::TextFormat::ParseFromString(kMessage, &request));
|
||||||
SetMockLocalTrajectoryUploader();
|
SetMockLocalTrajectoryUploader();
|
||||||
EXPECT_CALL(
|
EXPECT_CALL(*mock_map_builder_context_,
|
||||||
*mock_map_builder_context_,
|
DoEnqueueSensorData(
|
||||||
DoEnqueueSensorData(Eq(request_.sensor_metadata().trajectory_id()),
|
Eq(request.sensor_metadata().trajectory_id()),
|
||||||
Pointee(Truly(BuildDataPredicateEquals(request_)))));
|
Pointee(Truly(testing::BuildDataPredicateEquals(request)))));
|
||||||
EXPECT_CALL(*mock_local_trajectory_uploader_,
|
EXPECT_CALL(*mock_local_trajectory_uploader_,
|
||||||
DoEnqueueDataRequest(
|
DoEnqueueDataRequest(Pointee(
|
||||||
Pointee(Truly(BuildProtoPredicateEquals(&request_)))));
|
Truly(testing::BuildProtoPredicateEquals(&request)))));
|
||||||
test_server_->SendWrite(request_);
|
test_server_->SendWrite(request);
|
||||||
test_server_->SendWritesDone();
|
test_server_->SendWritesDone();
|
||||||
test_server_->SendFinish();
|
test_server_->SendFinish();
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,95 @@
|
||||||
|
/*
|
||||||
|
* 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_landmark_data_handler.h"
|
||||||
|
#include "cartographer_grpc/testing/add_data_handler_test.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::Eq;
|
||||||
|
using ::testing::Pointee;
|
||||||
|
using ::testing::Truly;
|
||||||
|
|
||||||
|
const std::string kMessage = R"PROTO(
|
||||||
|
sensor_metadata {
|
||||||
|
trajectory_id: 1
|
||||||
|
sensor_id: "sensor_id"
|
||||||
|
}
|
||||||
|
landmark_data {
|
||||||
|
timestamp: 2
|
||||||
|
landmark_observations {
|
||||||
|
id: "3"
|
||||||
|
landmark_to_tracking_transform {
|
||||||
|
translation {
|
||||||
|
x: 4
|
||||||
|
y: 5
|
||||||
|
z: 6
|
||||||
|
}
|
||||||
|
rotation {
|
||||||
|
x: 7
|
||||||
|
y: 8
|
||||||
|
z: 9
|
||||||
|
w: 10
|
||||||
|
}
|
||||||
|
}
|
||||||
|
translation_weight: 11.0
|
||||||
|
rotation_weight: 12.0
|
||||||
|
}
|
||||||
|
})PROTO";
|
||||||
|
|
||||||
|
using AddLandmarkDataHandlerTest =
|
||||||
|
testing::AddDataHandlerTest<AddLandmarkDataHandler>;
|
||||||
|
|
||||||
|
TEST_F(AddLandmarkDataHandlerTest, NoLocalSlamUploader) {
|
||||||
|
proto::AddLandmarkDataRequest request;
|
||||||
|
EXPECT_TRUE(
|
||||||
|
google::protobuf::TextFormat::ParseFromString(kMessage, &request));
|
||||||
|
SetNoLocalTrajectoryUploader();
|
||||||
|
EXPECT_CALL(*mock_map_builder_context_,
|
||||||
|
DoEnqueueSensorData(
|
||||||
|
Eq(request.sensor_metadata().trajectory_id()),
|
||||||
|
Pointee(Truly(testing::BuildDataPredicateEquals(request)))));
|
||||||
|
test_server_->SendWrite(request);
|
||||||
|
test_server_->SendWritesDone();
|
||||||
|
test_server_->SendFinish();
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(AddLandmarkDataHandlerTest, WithMockLocalSlamUploader) {
|
||||||
|
proto::AddLandmarkDataRequest request;
|
||||||
|
EXPECT_TRUE(
|
||||||
|
google::protobuf::TextFormat::ParseFromString(kMessage, &request));
|
||||||
|
SetMockLocalTrajectoryUploader();
|
||||||
|
EXPECT_CALL(*mock_map_builder_context_,
|
||||||
|
DoEnqueueSensorData(
|
||||||
|
Eq(request.sensor_metadata().trajectory_id()),
|
||||||
|
Pointee(Truly(testing::BuildDataPredicateEquals(request)))));
|
||||||
|
EXPECT_CALL(*mock_local_trajectory_uploader_,
|
||||||
|
DoEnqueueDataRequest(Pointee(
|
||||||
|
Truly(testing::BuildProtoPredicateEquals(&request)))));
|
||||||
|
test_server_->SendWrite(request);
|
||||||
|
test_server_->SendWritesDone();
|
||||||
|
test_server_->SendFinish();
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace
|
||||||
|
} // namespace handlers
|
||||||
|
} // namespace cartographer_grpc
|
|
@ -0,0 +1,90 @@
|
||||||
|
/*
|
||||||
|
* 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_odometry_data_handler.h"
|
||||||
|
#include "cartographer_grpc/testing/add_data_handler_test.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::Eq;
|
||||||
|
using ::testing::Pointee;
|
||||||
|
using ::testing::Truly;
|
||||||
|
|
||||||
|
const std::string kMessage = R"PROTO(
|
||||||
|
sensor_metadata {
|
||||||
|
trajectory_id: 1
|
||||||
|
sensor_id: "sensor_id"
|
||||||
|
}
|
||||||
|
odometry_data {
|
||||||
|
timestamp: 2
|
||||||
|
pose {
|
||||||
|
translation {
|
||||||
|
x: 3
|
||||||
|
y: 4
|
||||||
|
z: 5
|
||||||
|
}
|
||||||
|
rotation {
|
||||||
|
x: 6
|
||||||
|
y: 7
|
||||||
|
z: 8
|
||||||
|
w: 9
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})PROTO";
|
||||||
|
|
||||||
|
using AddOdometryDataHandlerTest =
|
||||||
|
testing::AddDataHandlerTest<AddOdometryDataHandler>;
|
||||||
|
|
||||||
|
TEST_F(AddOdometryDataHandlerTest, NoLocalSlamUploader) {
|
||||||
|
proto::AddOdometryDataRequest request;
|
||||||
|
EXPECT_TRUE(
|
||||||
|
google::protobuf::TextFormat::ParseFromString(kMessage, &request));
|
||||||
|
SetNoLocalTrajectoryUploader();
|
||||||
|
EXPECT_CALL(*mock_map_builder_context_,
|
||||||
|
DoEnqueueSensorData(
|
||||||
|
Eq(request.sensor_metadata().trajectory_id()),
|
||||||
|
Pointee(Truly(testing::BuildDataPredicateEquals(request)))));
|
||||||
|
test_server_->SendWrite(request);
|
||||||
|
test_server_->SendWritesDone();
|
||||||
|
test_server_->SendFinish();
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(AddOdometryDataHandlerTest, WithMockLocalSlamUploader) {
|
||||||
|
proto::AddOdometryDataRequest request;
|
||||||
|
EXPECT_TRUE(
|
||||||
|
google::protobuf::TextFormat::ParseFromString(kMessage, &request));
|
||||||
|
SetMockLocalTrajectoryUploader();
|
||||||
|
EXPECT_CALL(*mock_map_builder_context_,
|
||||||
|
DoEnqueueSensorData(
|
||||||
|
Eq(request.sensor_metadata().trajectory_id()),
|
||||||
|
Pointee(Truly(testing::BuildDataPredicateEquals(request)))));
|
||||||
|
EXPECT_CALL(*mock_local_trajectory_uploader_,
|
||||||
|
DoEnqueueDataRequest(Pointee(
|
||||||
|
Truly(testing::BuildProtoPredicateEquals(&request)))));
|
||||||
|
test_server_->SendWrite(request);
|
||||||
|
test_server_->SendWritesDone();
|
||||||
|
test_server_->SendFinish();
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace
|
||||||
|
} // namespace handlers
|
||||||
|
} // namespace cartographer_grpc
|
|
@ -0,0 +1,70 @@
|
||||||
|
/*
|
||||||
|
* 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_rangefinder_data_handler.h"
|
||||||
|
#include "cartographer_grpc/testing/add_data_handler_test.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::Eq;
|
||||||
|
using ::testing::Pointee;
|
||||||
|
using ::testing::Truly;
|
||||||
|
|
||||||
|
const std::string kMessage = R"PROTO(
|
||||||
|
sensor_metadata {
|
||||||
|
trajectory_id: 1
|
||||||
|
sensor_id: "sensor_id"
|
||||||
|
}
|
||||||
|
timed_point_cloud_data {
|
||||||
|
timestamp: 2
|
||||||
|
origin {
|
||||||
|
x: 3.f
|
||||||
|
y: 4.f
|
||||||
|
z: 5.f
|
||||||
|
}
|
||||||
|
point_data {
|
||||||
|
x: 6.f
|
||||||
|
y: 7.f
|
||||||
|
z: 8.f
|
||||||
|
t: 9.f
|
||||||
|
}
|
||||||
|
})PROTO";
|
||||||
|
|
||||||
|
using AddRangefinderDataHandlerTest =
|
||||||
|
testing::AddDataHandlerTest<AddRangefinderDataHandler>;
|
||||||
|
|
||||||
|
TEST_F(AddRangefinderDataHandlerTest, NoLocalSlamUploader) {
|
||||||
|
proto::AddRangefinderDataRequest request;
|
||||||
|
EXPECT_TRUE(
|
||||||
|
google::protobuf::TextFormat::ParseFromString(kMessage, &request));
|
||||||
|
EXPECT_CALL(*mock_map_builder_context_,
|
||||||
|
DoEnqueueSensorData(
|
||||||
|
Eq(request.sensor_metadata().trajectory_id()),
|
||||||
|
Pointee(Truly(testing::BuildDataPredicateEquals(request)))));
|
||||||
|
test_server_->SendWrite(request);
|
||||||
|
test_server_->SendWritesDone();
|
||||||
|
test_server_->SendFinish();
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace
|
||||||
|
} // namespace handlers
|
||||||
|
} // namespace cartographer_grpc
|
|
@ -0,0 +1,66 @@
|
||||||
|
/*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef CARTOGRAPHER_GRPC_TESTING_ADD_DATA_HANDLER_TEST_H
|
||||||
|
#define CARTOGRAPHER_GRPC_TESTING_ADD_DATA_HANDLER_TEST_H
|
||||||
|
|
||||||
|
#include "cartographer/common/make_unique.h"
|
||||||
|
#include "cartographer_grpc/framework/testing/rpc_handler_test_server.h"
|
||||||
|
#include "cartographer_grpc/testing/mock_local_trajectory_uploader.h"
|
||||||
|
#include "cartographer_grpc/testing/mock_map_builder_context.h"
|
||||||
|
#include "gtest/gtest.h"
|
||||||
|
|
||||||
|
namespace cartographer_grpc {
|
||||||
|
namespace testing {
|
||||||
|
|
||||||
|
using ::testing::Return;
|
||||||
|
using ::testing::Test;
|
||||||
|
|
||||||
|
template <typename HandlerType>
|
||||||
|
class AddDataHandlerTest : public Test {
|
||||||
|
public:
|
||||||
|
void SetUp() override {
|
||||||
|
test_server_ = cartographer::common::make_unique<
|
||||||
|
framework::testing::RpcHandlerTestServer<HandlerType>>(
|
||||||
|
cartographer::common::make_unique<MockMapBuilderContext>());
|
||||||
|
mock_map_builder_context_ =
|
||||||
|
test_server_
|
||||||
|
->template GetUnsynchronizedContext<MockMapBuilderContext>();
|
||||||
|
mock_local_trajectory_uploader_ =
|
||||||
|
cartographer::common::make_unique<MockLocalTrajectoryUploader>();
|
||||||
|
}
|
||||||
|
|
||||||
|
void SetNoLocalTrajectoryUploader() {
|
||||||
|
EXPECT_CALL(*mock_map_builder_context_, local_trajectory_uploader())
|
||||||
|
.WillOnce(Return(nullptr));
|
||||||
|
}
|
||||||
|
|
||||||
|
void SetMockLocalTrajectoryUploader() {
|
||||||
|
EXPECT_CALL(*mock_map_builder_context_, local_trajectory_uploader())
|
||||||
|
.WillRepeatedly(Return(mock_local_trajectory_uploader_.get()));
|
||||||
|
}
|
||||||
|
|
||||||
|
protected:
|
||||||
|
std::unique_ptr<framework::testing::RpcHandlerTestServer<HandlerType>>
|
||||||
|
test_server_;
|
||||||
|
MockMapBuilderContext *mock_map_builder_context_;
|
||||||
|
std::unique_ptr<MockLocalTrajectoryUploader> mock_local_trajectory_uploader_;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace testing
|
||||||
|
} // namespace cartographer_grpc
|
||||||
|
|
||||||
|
#endif // CARTOGRAPHER_GRPC_TESTING_ADD_DATA_HANDLER_TEST_H
|
|
@ -0,0 +1,105 @@
|
||||||
|
/*
|
||||||
|
* 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/testing/test_helpers.h"
|
||||||
|
|
||||||
|
namespace cartographer_grpc {
|
||||||
|
namespace testing {
|
||||||
|
|
||||||
|
template <>
|
||||||
|
DataPredicateType BuildDataPredicateEquals<proto::AddImuDataRequest>(
|
||||||
|
const proto::AddImuDataRequest &proto) {
|
||||||
|
return [proto](const cartographer::sensor::Data &data) {
|
||||||
|
const auto *dispatchable =
|
||||||
|
dynamic_cast<const cartographer::sensor::Dispatchable<
|
||||||
|
cartographer::sensor::ImuData> *>(&data);
|
||||||
|
CHECK_NOTNULL(dispatchable);
|
||||||
|
return google::protobuf::util::MessageDifferencer::Equals(
|
||||||
|
cartographer::sensor::ToProto(dispatchable->data()),
|
||||||
|
proto.imu_data()) &&
|
||||||
|
dispatchable->GetSensorId() == proto.sensor_metadata().sensor_id();
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
template <>
|
||||||
|
DataPredicateType BuildDataPredicateEquals<proto::AddFixedFramePoseDataRequest>(
|
||||||
|
const proto::AddFixedFramePoseDataRequest &proto) {
|
||||||
|
return [proto](const cartographer::sensor::Data &data) {
|
||||||
|
const auto *dispatchable =
|
||||||
|
dynamic_cast<const cartographer::sensor::Dispatchable<
|
||||||
|
cartographer::sensor::FixedFramePoseData> *>(&data);
|
||||||
|
CHECK_NOTNULL(dispatchable);
|
||||||
|
return google::protobuf::util::MessageDifferencer::Equals(
|
||||||
|
cartographer::sensor::ToProto(dispatchable->data()),
|
||||||
|
proto.fixed_frame_pose_data()) &&
|
||||||
|
dispatchable->GetSensorId() == proto.sensor_metadata().sensor_id();
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
template <>
|
||||||
|
DataPredicateType BuildDataPredicateEquals<proto::AddOdometryDataRequest>(
|
||||||
|
const proto::AddOdometryDataRequest &proto) {
|
||||||
|
return [proto](const cartographer::sensor::Data &data) {
|
||||||
|
const auto *dispatchable =
|
||||||
|
dynamic_cast<const cartographer::sensor::Dispatchable<
|
||||||
|
cartographer::sensor::OdometryData> *>(&data);
|
||||||
|
CHECK_NOTNULL(dispatchable);
|
||||||
|
return google::protobuf::util::MessageDifferencer::Equals(
|
||||||
|
cartographer::sensor::ToProto(dispatchable->data()),
|
||||||
|
proto.odometry_data()) &&
|
||||||
|
dispatchable->GetSensorId() == proto.sensor_metadata().sensor_id();
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
template <>
|
||||||
|
DataPredicateType BuildDataPredicateEquals<proto::AddLandmarkDataRequest>(
|
||||||
|
const proto::AddLandmarkDataRequest &proto) {
|
||||||
|
return [proto](const cartographer::sensor::Data &data) {
|
||||||
|
const auto *dispatchable =
|
||||||
|
dynamic_cast<const cartographer::sensor::Dispatchable<
|
||||||
|
cartographer::sensor::LandmarkData> *>(&data);
|
||||||
|
CHECK_NOTNULL(dispatchable);
|
||||||
|
return google::protobuf::util::MessageDifferencer::Equals(
|
||||||
|
cartographer::sensor::ToProto(dispatchable->data()),
|
||||||
|
proto.landmark_data()) &&
|
||||||
|
dispatchable->GetSensorId() == proto.sensor_metadata().sensor_id();
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
template <>
|
||||||
|
DataPredicateType BuildDataPredicateEquals<proto::AddRangefinderDataRequest>(
|
||||||
|
const proto::AddRangefinderDataRequest &proto) {
|
||||||
|
return [proto](const cartographer::sensor::Data &data) {
|
||||||
|
const auto *dispatchable =
|
||||||
|
dynamic_cast<const cartographer::sensor::Dispatchable<
|
||||||
|
cartographer::sensor::TimedPointCloudData> *>(&data);
|
||||||
|
CHECK_NOTNULL(dispatchable);
|
||||||
|
return google::protobuf::util::MessageDifferencer::Equals(
|
||||||
|
cartographer::sensor::ToProto(dispatchable->data()),
|
||||||
|
proto.timed_point_cloud_data()) &&
|
||||||
|
dispatchable->GetSensorId() == proto.sensor_metadata().sensor_id();
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
ProtoPredicateType BuildProtoPredicateEquals(
|
||||||
|
const google::protobuf::Message *proto) {
|
||||||
|
return [proto](const google::protobuf::Message &message) {
|
||||||
|
return google::protobuf::util::MessageDifferencer::Equals(*proto, message);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace testing
|
||||||
|
} // namespace cartographer_grpc
|
|
@ -0,0 +1,57 @@
|
||||||
|
/*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef CARTOGRAPHER_GRPC_TESTING_TEST_HELPERS_H
|
||||||
|
#define CARTOGRAPHER_GRPC_TESTING_TEST_HELPERS_H
|
||||||
|
|
||||||
|
#include "cartographer/sensor/dispatchable.h"
|
||||||
|
#include "cartographer_grpc/proto/map_builder_service.pb.h"
|
||||||
|
#include "google/protobuf/util/message_differencer.h"
|
||||||
|
|
||||||
|
namespace cartographer_grpc {
|
||||||
|
namespace testing {
|
||||||
|
|
||||||
|
using DataPredicateType =
|
||||||
|
std::function<bool(const cartographer::sensor::Data &)>;
|
||||||
|
using ProtoPredicateType =
|
||||||
|
std::function<bool(const google::protobuf::Message &)>;
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
DataPredicateType BuildDataPredicateEquals(const T &proto);
|
||||||
|
|
||||||
|
template <>
|
||||||
|
DataPredicateType BuildDataPredicateEquals<proto::AddImuDataRequest>(
|
||||||
|
const proto::AddImuDataRequest &proto);
|
||||||
|
template <>
|
||||||
|
DataPredicateType BuildDataPredicateEquals<proto::AddFixedFramePoseDataRequest>(
|
||||||
|
const proto::AddFixedFramePoseDataRequest &proto);
|
||||||
|
template <>
|
||||||
|
DataPredicateType BuildDataPredicateEquals<proto::AddOdometryDataRequest>(
|
||||||
|
const proto::AddOdometryDataRequest &proto);
|
||||||
|
template <>
|
||||||
|
DataPredicateType BuildDataPredicateEquals<proto::AddLandmarkDataRequest>(
|
||||||
|
const proto::AddLandmarkDataRequest &proto);
|
||||||
|
template <>
|
||||||
|
DataPredicateType BuildDataPredicateEquals<proto::AddRangefinderDataRequest>(
|
||||||
|
const proto::AddRangefinderDataRequest &proto);
|
||||||
|
|
||||||
|
ProtoPredicateType BuildProtoPredicateEquals(
|
||||||
|
const google::protobuf::Message *proto);
|
||||||
|
|
||||||
|
} // namespace testing
|
||||||
|
} // namespace cartographer_grpc
|
||||||
|
|
||||||
|
#endif // CARTOGRAPHER_GRPC_TESTING_TEST_HELPERS_H
|
Loading…
Reference in New Issue