diff --git a/cartographer_grpc/framework/client.h b/cartographer_grpc/framework/client.h index 52b3c63..03e3822 100644 --- a/cartographer_grpc/framework/client.h +++ b/cartographer_grpc/framework/client.h @@ -20,6 +20,7 @@ #include "cartographer_grpc/framework/retry.h" #include "cartographer_grpc/framework/rpc_handler_interface.h" #include "cartographer_grpc/framework/type_traits.h" +#include "glog/logging.h" #include "grpc++/grpc++.h" #include "grpc++/impl/codegen/client_unary_call.h" #include "grpc++/impl/codegen/sync_stream.h" diff --git a/cartographer_grpc/handlers/add_fixed_frame_pose_data_handler_test.cc b/cartographer_grpc/handlers/add_fixed_frame_pose_data_handler_test.cc new file mode 100644 index 0000000..e655e2d --- /dev/null +++ b/cartographer_grpc/handlers/add_fixed_frame_pose_data_handler_test.cc @@ -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; + +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 diff --git a/cartographer_grpc/handlers/add_imu_data_handler_test.cc b/cartographer_grpc/handlers/add_imu_data_handler_test.cc index 4794750..504a74a 100644 --- a/cartographer_grpc/handlers/add_imu_data_handler_test.cc +++ b/cartographer_grpc/handlers/add_imu_data_handler_test.cc @@ -15,13 +15,9 @@ */ #include "cartographer_grpc/handlers/add_imu_data_handler.h" -#include "cartographer/common/make_unique.h" -#include "cartographer/sensor/dispatchable.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 "cartographer_grpc/testing/add_data_handler_test.h" +#include "cartographer_grpc/testing/test_helpers.h" #include "google/protobuf/text_format.h" -#include "google/protobuf/util/message_differencer.h" #include "gtest/gtest.h" namespace cartographer_grpc { @@ -31,8 +27,6 @@ namespace { using ::testing::_; using ::testing::Eq; using ::testing::Pointee; -using ::testing::Return; -using ::testing::Test; using ::testing::Truly; const std::string kMessage = R"PROTO( @@ -54,87 +48,35 @@ const std::string kMessage = R"PROTO( } })PROTO"; -using DataPredicateType = - std::function; -using ProtoPredicateType = - std::function; - -class AddImuDataHandlerTest : public Test { - public: - void SetUp() override { - test_server_ = cartographer::common::make_unique< - framework::testing::RpcHandlerTestServer>( - cartographer::common::make_unique()); - mock_map_builder_context_ = - test_server_ - ->GetUnsynchronizedContext(); - 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> - test_server_; - testing::MockMapBuilderContext *mock_map_builder_context_; - std::unique_ptr - 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 *>(&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); - }; -} +using AddImuDataHandlerTest = testing::AddDataHandlerTest; TEST_F(AddImuDataHandlerTest, NoLocalSlamUploader) { + proto::AddImuDataRequest 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(BuildDataPredicateEquals(request_))))); - test_server_->SendWrite(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(); } TEST_F(AddImuDataHandlerTest, WithMockLocalSlamUploader) { + proto::AddImuDataRequest 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(BuildDataPredicateEquals(request_))))); + 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(BuildProtoPredicateEquals(&request_))))); - test_server_->SendWrite(request_); + DoEnqueueDataRequest(Pointee( + Truly(testing::BuildProtoPredicateEquals(&request))))); + test_server_->SendWrite(request); test_server_->SendWritesDone(); test_server_->SendFinish(); } diff --git a/cartographer_grpc/handlers/add_landmark_data_handler_test.cc b/cartographer_grpc/handlers/add_landmark_data_handler_test.cc new file mode 100644 index 0000000..a3f273d --- /dev/null +++ b/cartographer_grpc/handlers/add_landmark_data_handler_test.cc @@ -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; + +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 diff --git a/cartographer_grpc/handlers/add_odometry_data_handler_test.cc b/cartographer_grpc/handlers/add_odometry_data_handler_test.cc new file mode 100644 index 0000000..8f464c7 --- /dev/null +++ b/cartographer_grpc/handlers/add_odometry_data_handler_test.cc @@ -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; + +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 diff --git a/cartographer_grpc/handlers/add_rangefind_data_handler_test.cc b/cartographer_grpc/handlers/add_rangefind_data_handler_test.cc new file mode 100644 index 0000000..cc820ba --- /dev/null +++ b/cartographer_grpc/handlers/add_rangefind_data_handler_test.cc @@ -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; + +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 diff --git a/cartographer_grpc/testing/add_data_handler_test.h b/cartographer_grpc/testing/add_data_handler_test.h new file mode 100644 index 0000000..00c4781 --- /dev/null +++ b/cartographer_grpc/testing/add_data_handler_test.h @@ -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 +class AddDataHandlerTest : public Test { + public: + void SetUp() override { + test_server_ = cartographer::common::make_unique< + framework::testing::RpcHandlerTestServer>( + cartographer::common::make_unique()); + mock_map_builder_context_ = + test_server_ + ->template GetUnsynchronizedContext(); + mock_local_trajectory_uploader_ = + cartographer::common::make_unique(); + } + + 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> + test_server_; + MockMapBuilderContext *mock_map_builder_context_; + std::unique_ptr mock_local_trajectory_uploader_; +}; + +} // namespace testing +} // namespace cartographer_grpc + +#endif // CARTOGRAPHER_GRPC_TESTING_ADD_DATA_HANDLER_TEST_H diff --git a/cartographer_grpc/testing/test_helpers.cc b/cartographer_grpc/testing/test_helpers.cc new file mode 100644 index 0000000..b439e14 --- /dev/null +++ b/cartographer_grpc/testing/test_helpers.cc @@ -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( + const proto::AddImuDataRequest &proto) { + return [proto](const cartographer::sensor::Data &data) { + const auto *dispatchable = + dynamic_cast *>(&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( + const proto::AddFixedFramePoseDataRequest &proto) { + return [proto](const cartographer::sensor::Data &data) { + const auto *dispatchable = + dynamic_cast *>(&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( + const proto::AddOdometryDataRequest &proto) { + return [proto](const cartographer::sensor::Data &data) { + const auto *dispatchable = + dynamic_cast *>(&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( + const proto::AddLandmarkDataRequest &proto) { + return [proto](const cartographer::sensor::Data &data) { + const auto *dispatchable = + dynamic_cast *>(&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( + const proto::AddRangefinderDataRequest &proto) { + return [proto](const cartographer::sensor::Data &data) { + const auto *dispatchable = + dynamic_cast *>(&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 diff --git a/cartographer_grpc/testing/test_helpers.h b/cartographer_grpc/testing/test_helpers.h new file mode 100644 index 0000000..4e9716d --- /dev/null +++ b/cartographer_grpc/testing/test_helpers.h @@ -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; +using ProtoPredicateType = + std::function; + +template +DataPredicateType BuildDataPredicateEquals(const T &proto); + +template <> +DataPredicateType BuildDataPredicateEquals( + const proto::AddImuDataRequest &proto); +template <> +DataPredicateType BuildDataPredicateEquals( + const proto::AddFixedFramePoseDataRequest &proto); +template <> +DataPredicateType BuildDataPredicateEquals( + const proto::AddOdometryDataRequest &proto); +template <> +DataPredicateType BuildDataPredicateEquals( + const proto::AddLandmarkDataRequest &proto); +template <> +DataPredicateType BuildDataPredicateEquals( + const proto::AddRangefinderDataRequest &proto); + +ProtoPredicateType BuildProtoPredicateEquals( + const google::protobuf::Message *proto); + +} // namespace testing +} // namespace cartographer_grpc + +#endif // CARTOGRAPHER_GRPC_TESTING_TEST_HELPERS_H