handler_test.h
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 #ifndef CARTOGRAPHER_CLOUD_INTERNAL_TESTING_HANDLER_TEST_H
00018 #define CARTOGRAPHER_CLOUD_INTERNAL_TESTING_HANDLER_TEST_H
00019 
00020 #include "absl/memory/memory.h"
00021 #include "async_grpc/testing/rpc_handler_test_server.h"
00022 #include "cartographer/mapping/internal/testing/mock_map_builder.h"
00023 #include "cartographer/mapping/internal/testing/mock_pose_graph.h"
00024 #include "gtest/gtest.h"
00025 #include "mock_local_trajectory_uploader.h"
00026 #include "mock_map_builder_context.h"
00027 
00028 namespace cartographer {
00029 namespace cloud {
00030 namespace testing {
00031 
00032 using ::testing::Return;
00033 using ::testing::Test;
00034 
00035 template <typename HandlerConcept, typename HandlerType>
00036 class HandlerTest : public Test {
00037  public:
00038   void SetUp() override {
00039     test_server_ = absl::make_unique<
00040         async_grpc::testing::RpcHandlerTestServer<HandlerConcept, HandlerType>>(
00041         absl::make_unique<MockMapBuilderContext>());
00042     mock_map_builder_context_ =
00043         test_server_
00044             ->template GetUnsynchronizedContext<MockMapBuilderContext>();
00045     mock_local_trajectory_uploader_ =
00046         absl::make_unique<MockLocalTrajectoryUploader>();
00047     mock_map_builder_ = absl::make_unique<mapping::testing::MockMapBuilder>();
00048     mock_pose_graph_ = absl::make_unique<mapping::testing::MockPoseGraph>();
00049 
00050     EXPECT_CALL(*mock_map_builder_context_, map_builder())
00051         .Times(::testing::AnyNumber())
00052         .WillRepeatedly(::testing::ReturnPointee(mock_map_builder_.get()));
00053     EXPECT_CALL(*mock_map_builder_, pose_graph())
00054         .Times(::testing::AnyNumber())
00055         .WillRepeatedly(Return(mock_pose_graph_.get()));
00056   }
00057 
00058   void SetNoLocalTrajectoryUploader() {
00059     EXPECT_CALL(*mock_map_builder_context_, local_trajectory_uploader())
00060         .WillOnce(Return(nullptr));
00061   }
00062 
00063   void SetMockLocalTrajectoryUploader() {
00064     EXPECT_CALL(*mock_map_builder_context_, local_trajectory_uploader())
00065         .WillRepeatedly(Return(mock_local_trajectory_uploader_.get()));
00066   }
00067 
00068  protected:
00069   std::unique_ptr<
00070       async_grpc::testing::RpcHandlerTestServer<HandlerConcept, HandlerType>>
00071       test_server_;
00072   MockMapBuilderContext *mock_map_builder_context_;
00073   std::unique_ptr<MockLocalTrajectoryUploader> mock_local_trajectory_uploader_;
00074   std::unique_ptr<mapping::testing::MockMapBuilder> mock_map_builder_;
00075   std::unique_ptr<mapping::testing::MockPoseGraph> mock_pose_graph_;
00076 };
00077 
00078 }  // namespace testing
00079 }  // namespace cloud
00080 }  // namespace cartographer
00081 
00082 #endif  // CARTOGRAPHER_CLOUD_INTERNAL_TESTING_HANDLER_TEST_H


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