[GenericPoseGraph] Move 'EqualsProto' matcher to test_helpers. (#1271)

master
Alexander Belyaev 2018-07-13 15:05:22 +02:00 committed by GitHub
parent a08037dc47
commit d4376e765b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 43 additions and 17 deletions

View File

@ -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<decltype(arg)>::type;
typename std::remove_cv<ConstProtoType>::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_

View File

@ -16,10 +16,7 @@
#include "cartographer/pose_graph/pose_2d.h" #include "cartographer/pose_graph/pose_2d.h"
#include "gmock/gmock.h" #include "cartographer/pose_graph/internal/testing/test_helpers.h"
#include "google/protobuf/text_format.h"
#include "google/protobuf/util/message_differencer.h"
#include "gtest/gtest.h"
namespace cartographer { namespace cartographer {
namespace pose_graph { namespace pose_graph {
@ -36,20 +33,9 @@ constexpr char kExpectedNode[] = R"PROTO(
} }
)PROTO"; )PROTO";
// TODO(pifon): Move this to a separate header. TEST(Pose2DTest, ToProto) {
MATCHER_P(EqualsProto, expected_proto_string, "") {
using ConstProtoType = typename std::remove_reference<decltype(arg)>::type;
typename std::remove_cv<ConstProtoType>::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) {
Pose2D pose_2d("flat_world", true, Eigen::Vector2d(1., 2.), 5.); 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 } // namespace