diff --git a/cartographer/pose_graph/internal/testing/test_helpers.h b/cartographer/pose_graph/internal/testing/test_helpers.h new file mode 100644 index 0000000..13664d8 --- /dev/null +++ b/cartographer/pose_graph/internal/testing/test_helpers.h @@ -0,0 +1,40 @@ +/* + * 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_POSE_GRAPH_INTERNAL_TESTING_TEST_HELPERS_H_ +#define CARTOGRAPHER_POSE_GRAPH_INTERNAL_TESTING_TEST_HELPERS_H_ + +#include "gmock/gmock.h" +#include "google/protobuf/text_format.h" +#include "google/protobuf/util/message_differencer.h" + +namespace cartographer { +namespace testing { + +MATCHER_P(EqualsProto, expected_proto_string, "") { + using ConstProtoType = typename std::remove_reference::type; + + typename std::remove_cv::type expected_proto; + EXPECT_TRUE(google::protobuf::TextFormat::ParseFromString( + expected_proto_string, &expected_proto)); + return google::protobuf::util::MessageDifferencer::Equals(arg, + expected_proto); +} + +} // namespace testing +} // namespace cartographer + +#endif // CARTOGRAPHER_POSE_GRAPH_INTERNAL_TESTING_TEST_HELPERS_H_ diff --git a/cartographer/pose_graph/pose_2d_test.cc b/cartographer/pose_graph/pose_2d_test.cc index 1e40166..a8c57cc 100644 --- a/cartographer/pose_graph/pose_2d_test.cc +++ b/cartographer/pose_graph/pose_2d_test.cc @@ -16,10 +16,7 @@ #include "cartographer/pose_graph/pose_2d.h" -#include "gmock/gmock.h" -#include "google/protobuf/text_format.h" -#include "google/protobuf/util/message_differencer.h" -#include "gtest/gtest.h" +#include "cartographer/pose_graph/internal/testing/test_helpers.h" namespace cartographer { namespace pose_graph { @@ -36,20 +33,9 @@ constexpr char kExpectedNode[] = R"PROTO( } )PROTO"; -// TODO(pifon): Move this to a separate header. -MATCHER_P(EqualsProto, expected_proto_string, "") { - using ConstProtoType = typename std::remove_reference::type; - - typename std::remove_cv::type expected_proto; - EXPECT_TRUE(google::protobuf::TextFormat::ParseFromString( - expected_proto_string, &expected_proto)); - return google::protobuf::util::MessageDifferencer::Equals(arg, - expected_proto); -} - -TEST(Pose2DTest, SerializeToProto) { +TEST(Pose2DTest, ToProto) { Pose2D pose_2d("flat_world", true, Eigen::Vector2d(1., 2.), 5.); - EXPECT_THAT(pose_2d.ToProto(), EqualsProto(kExpectedNode)); + EXPECT_THAT(pose_2d.ToProto(), testing::EqualsProto(kExpectedNode)); } } // namespace