test_helpers.h
Go to the documentation of this file.
00001 /*
00002  * Copyright 2016 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_SENSOR_INTERNAL_TEST_HELPERS_H_
00018 #define CARTOGRAPHER_SENSOR_INTERNAL_TEST_HELPERS_H_
00019 
00020 #include <string>
00021 #include <tuple>
00022 
00023 #include "absl/memory/memory.h"
00024 #include "cartographer/common/time.h"
00025 #include "cartographer/sensor/collator_interface.h"
00026 #include "cartographer/sensor/imu_data.h"
00027 #include "cartographer/sensor/internal/dispatchable.h"
00028 #include "cartographer/sensor/odometry_data.h"
00029 #include "cartographer/sensor/timed_point_cloud_data.h"
00030 #include "gmock/gmock.h"
00031 
00032 namespace cartographer {
00033 namespace sensor {
00034 
00035 MATCHER_P(Near, point, std::string(negation ? "Doesn't" : "Does") + " match.") {
00036   return arg.isApprox(point, 0.001f);
00037 }
00038 
00039 namespace testing {
00040 
00041 typedef std::tuple<int /* trajectory_id */, std::string /* sensor_id */,
00042                    common::Time>
00043     CollatorOutput;
00044 
00045 struct CollatorInput {
00046   static CollatorInput CreateImuData(int trajectory_id,
00047                                      const std::string& sensor_id, int time) {
00048     return CollatorInput{
00049         trajectory_id,
00050         MakeDispatchable(sensor_id, ImuData{common::FromUniversal(time)}),
00051         CollatorOutput{trajectory_id, sensor_id, common::FromUniversal(time)}};
00052   }
00053   static CollatorInput CreateTimedPointCloudData(int trajectory_id,
00054                                                  const std::string& sensor_id,
00055                                                  int time) {
00056     return CollatorInput{
00057         trajectory_id,
00058         MakeDispatchable(
00059             sensor_id,
00060             TimedPointCloudData{
00061                 common::FromUniversal(time), Eigen::Vector3f::Zero(), {}}),
00062         CollatorOutput{trajectory_id, sensor_id, common::FromUniversal(time)}};
00063   }
00064   static CollatorInput CreateOdometryData(int trajectory_id,
00065                                           const std::string& sensor_id,
00066                                           int time) {
00067     return CollatorInput{
00068         trajectory_id,
00069         MakeDispatchable(sensor_id,
00070                          OdometryData{common::FromUniversal(time),
00071                                       transform::Rigid3d::Identity()}),
00072         CollatorOutput{trajectory_id, sensor_id, common::FromUniversal(time)}};
00073   }
00074   void MoveToCollator(CollatorInterface* collator) {
00075     collator->AddSensorData(trajectory_id, std::move(data));
00076   }
00077 
00078   const int trajectory_id;
00079   std::unique_ptr<Data> data;
00080   const CollatorOutput expected_output;
00081 };
00082 
00083 }  // namespace testing
00084 }  // namespace sensor
00085 }  // namespace cartographer
00086 
00087 #endif  // CARTOGRAPHER_SENSOR_INTERNAL_TEST_HELPERS_H_


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