Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removes maliput::test_utilities dependency. #106

Merged
merged 2 commits into from
Oct 10, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@

#include <gmock/gmock.h>
#include <gtest/gtest.h>
#include <maliput/test_utilities/maliput_types_compare.h>
#include <maliput/api/compare.h>

#include "maliput_multilane/builder.h"
#include "maliput_multilane/connection.h"
Expand Down Expand Up @@ -124,7 +124,7 @@ class HBoundsMatcher : public MatcherInterface<const api::HBounds&> {
: elevation_bounds_(elevation_bounds), tolerance_(tolerance) {}

bool MatchAndExplain(const api::HBounds& other, MatchResultListener*) const override {
return api::test::IsHBoundsClose(elevation_bounds_, other, tolerance_);
return !api::IsHBoundsClose(elevation_bounds_, other, tolerance_).message.has_value();
}

void DescribeTo(std::ostream* os) const override {
Expand Down
1 change: 0 additions & 1 deletion src/maliput_multilane_test_utilities/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ target_link_libraries(test_utilities
PUBLIC
maliput::api
maliput::common
maliput::test_utilities
maliput::math
maliput_multilane
PRIVATE
Expand Down
1 change: 1 addition & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ macro(add_dependencies_to_test target)
target_include_directories(${target}
PRIVATE
${PROJECT_SOURCE_DIR}/include
${PROJECT_SOURCE_DIR}/test
)

set(MULTILANE_RESOURCE_ROOT ${PROJECT_SOURCE_DIR}/resources/)
Expand Down
48 changes: 48 additions & 0 deletions test/assert_compare.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// BSD 3-Clause License
//
// Copyright (c) 2023, Woven by Toyota. All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice, this
// list of conditions and the following disclaimer.
//
// * Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// * Neither the name of the copyright holder nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#pragma once

#include <gtest/gtest.h>
#include <maliput/common/compare.h>

namespace maliput {
namespace multilane {
namespace test {

template <typename T>
::testing::AssertionResult AssertCompare(const maliput::common::ComparisonResult<T>& res) {
if (!res.message.has_value()) {
return ::testing::AssertionSuccess();
}
return ::testing::AssertionFailure() << res.message.value();
}

} // namespace test
} // namespace multilane
} // namespace maliput
119 changes: 66 additions & 53 deletions test/maliput_multilane/multilane_arc_road_curve_test.cc

Large diffs are not rendered by default.

75 changes: 41 additions & 34 deletions test/maliput_multilane/multilane_builder_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -38,21 +38,22 @@
#include <vector>

#include <gtest/gtest.h>
#include <maliput/api/compare.h>
#include <maliput/api/lane_data.h>
#include <maliput/common/assertion_error.h>
#include <maliput/common/maliput_copyable.h>
#include <maliput/math/quaternion.h>
#include <maliput/math/vector.h>
#include <maliput/test_utilities/check_id_indexing.h>
#include <maliput/test_utilities/maliput_types_compare.h>

#include "assert_compare.h"
#include "maliput_multilane_test_utilities/multilane_types_compare.h"

namespace maliput {
namespace multilane {
namespace {

using Which = api::LaneEnd::Which;
using maliput::multilane::test::AssertCompare;

// StartReference::Spec using an Endpoint.
GTEST_TEST(StartReferenceSpecTest, Endpoint) {
Expand Down Expand Up @@ -179,7 +180,7 @@ GTEST_TEST(MultilaneBuilderTest, ParameterConstructor) {
Builder builder(kLaneWidth, kElevationBounds, kLinearTolerance, kAngularTolerance, kScaleLength, kComputationPolicy,
std::make_unique<GroupFactory>());
EXPECT_EQ(builder.get_lane_width(), kLaneWidth);
EXPECT_TRUE(api::test::IsHBoundsClose(builder.get_elevation_bounds(), kElevationBounds, 0.));
EXPECT_TRUE(AssertCompare(api::IsHBoundsClose(builder.get_elevation_bounds(), kElevationBounds, 0.)));
EXPECT_EQ(builder.get_linear_tolerance(), kLinearTolerance);
EXPECT_EQ(builder.get_angular_tolerance(), kAngularTolerance);
EXPECT_EQ(builder.get_scale_length(), kScaleLength);
Expand Down Expand Up @@ -343,7 +344,8 @@ GTEST_TEST(MultilaneBuilderTest, Fig8) {
EXPECT_EQ(bp->GetBSide()->size(), 1);
}

EXPECT_TRUE(api::test::CheckIdIndexing(rg.get()));
const auto check_id_indexing = api::CheckIdIndexing(rg.get());
EXPECT_FALSE(check_id_indexing.has_value()) << check_id_indexing.value();
};

GTEST_TEST(MultilaneBuilderTest, QuadRing) {
Expand Down Expand Up @@ -457,7 +459,8 @@ GTEST_TEST(MultilaneBuilderTest, QuadRing) {
}
}

EXPECT_TRUE(api::test::CheckIdIndexing(rg.get()));
const auto check_id_indexing = api::CheckIdIndexing(rg.get());
EXPECT_FALSE(check_id_indexing.has_value()) << check_id_indexing.value();
};

// Holds common properties for reference-to-reference curve primitive tests.
Expand Down Expand Up @@ -510,8 +513,8 @@ TEST_F(MultilaneBuilderReferenceCurvePrimitivesTest, LineSegment) {
// applied.
const math::Vector3 lane_start_geo =
start_reference_curve + (kRefR0 + static_cast<double>(i) * kLaneWidth) * r_versor;
EXPECT_TRUE(api::test::IsInertialPositionClose(lane->ToInertialPosition({0., 0., 0.}),
api::InertialPosition::FromXyz(lane_start_geo), kLinearTolerance));
EXPECT_TRUE(AssertCompare(api::IsInertialPositionClose(
lane->ToInertialPosition({0., 0., 0.}), api::InertialPosition::FromXyz(lane_start_geo), kLinearTolerance)));
// Checks lane start and end BranchPoint.
const api::BranchPoint* const start_bp = lane->GetBranchPoint(api::LaneEnd::kStart);
EXPECT_EQ(start_bp->GetASide()->size(), 1);
Expand Down Expand Up @@ -557,8 +560,9 @@ TEST_F(MultilaneBuilderReferenceCurvePrimitivesTest, ArcSegment) {
// applied.
const math::Vector3 lane_start_inertial =
start_reference_curve + (kRefR0 + static_cast<double>(i) * kLaneWidth) * r_versor;
EXPECT_TRUE(api::test::IsInertialPositionClose(
lane->ToInertialPosition({0., 0., 0.}), api::InertialPosition::FromXyz(lane_start_inertial), kLinearTolerance));
EXPECT_TRUE(AssertCompare(api::IsInertialPositionClose(lane->ToInertialPosition({0., 0., 0.}),
api::InertialPosition::FromXyz(lane_start_inertial),
kLinearTolerance)));
// Checks lane start and end BranchPoint.
const api::BranchPoint* const start_bp = lane->GetBranchPoint(api::LaneEnd::kStart);
EXPECT_EQ(start_bp->GetASide()->size(), 1);
Expand Down Expand Up @@ -712,8 +716,9 @@ TEST_F(MultilaneBuilderLaneToLanePrimitivesTest, FlatLineSegment) {
// applied.
const math::Vector3 lane_start_inertial =
start_reference_curve + (-kRefR0 + static_cast<double>(i) * kLaneWidth) * r_versor;
EXPECT_TRUE(api::test::IsInertialPositionClose(
lane->ToInertialPosition({0., 0., 0.}), api::InertialPosition::FromXyz(lane_start_inertial), kLinearTolerance));
EXPECT_TRUE(AssertCompare(api::IsInertialPositionClose(lane->ToInertialPosition({0., 0., 0.}),
api::InertialPosition::FromXyz(lane_start_inertial),
kLinearTolerance)));
// Checks lane start and end BranchPoint.
const api::BranchPoint* const start_bp = lane->GetBranchPoint(api::LaneEnd::kStart);
EXPECT_EQ(start_bp->GetASide()->size(), 1);
Expand Down Expand Up @@ -763,13 +768,13 @@ TEST_F(MultilaneBuilderLaneToLanePrimitivesTest, ElevatedEndLineSegment) {
// Checks lane start inertial position to verify that spacing is correctly
// applied.
const math::Vector3 r_offset = (-kRefR0 + static_cast<double>(i) * kLaneWidth) * r_versor;
EXPECT_TRUE(api::test::IsInertialPositionClose(lane->ToInertialPosition({0., 0., 0.}),
api::InertialPosition::FromXyz(start_reference_curve + r_offset),
kLinearTolerance));
EXPECT_TRUE(AssertCompare(api::IsInertialPositionClose(
lane->ToInertialPosition({0., 0., 0.}), api::InertialPosition::FromXyz(start_reference_curve + r_offset),
kLinearTolerance)));
// Checks lane end inertial position to verify elevation is correctly applied.
EXPECT_TRUE(api::test::IsInertialPositionClose(lane->ToInertialPosition({lane->length(), 0., 0.}),
api::InertialPosition::FromXyz(end_reference_curve + r_offset),
kLinearTolerance));
EXPECT_TRUE(AssertCompare(api::IsInertialPositionClose(
lane->ToInertialPosition({lane->length(), 0., 0.}),
api::InertialPosition::FromXyz(end_reference_curve + r_offset), kLinearTolerance)));
// Checks lane start and end BranchPoint.
const api::BranchPoint* const start_bp = lane->GetBranchPoint(api::LaneEnd::kStart);
EXPECT_EQ(start_bp->GetASide()->size(), 1);
Expand Down Expand Up @@ -816,8 +821,9 @@ TEST_F(MultilaneBuilderLaneToLanePrimitivesTest, ArcSegment) {
// applied.
const math::Vector3 lane_start_inertial =
start_reference_curve + (-kRefR0 + static_cast<double>(i) * kLaneWidth) * r_versor;
EXPECT_TRUE(api::test::IsInertialPositionClose(
lane->ToInertialPosition({0., 0., 0.}), api::InertialPosition::FromXyz(lane_start_inertial), kLinearTolerance));
EXPECT_TRUE(AssertCompare(api::IsInertialPositionClose(lane->ToInertialPosition({0., 0., 0.}),
api::InertialPosition::FromXyz(lane_start_inertial),
kLinearTolerance)));
// Checks lane start and end BranchPoint.
const api::BranchPoint* const start_bp = lane->GetBranchPoint(api::LaneEnd::kStart);
EXPECT_EQ(start_bp->GetASide()->size(), 1);
Expand Down Expand Up @@ -867,14 +873,14 @@ TEST_F(MultilaneBuilderLaneToLanePrimitivesTest, ElevatedEndArcSegment) {
// Checks lane start inertial position to verify that spacing is correctly
// applied.
const math::Vector3 r_offset_start = (-kRefR0 + static_cast<double>(i) * kLaneWidth) * r_versor_start;
EXPECT_TRUE(api::test::IsInertialPositionClose(
EXPECT_TRUE(AssertCompare(api::IsInertialPositionClose(
lane->ToInertialPosition({0., 0., 0.}), api::InertialPosition::FromXyz(start_reference_curve + r_offset_start),
kLinearTolerance));
kLinearTolerance)));
// Checks lane end inertial position to verify elevation is correctly applied.
const math::Vector3 r_offset_end = (-kRefR0 + static_cast<double>(i) * kLaneWidth) * r_versor_end;
EXPECT_TRUE(api::test::IsInertialPositionClose(lane->ToInertialPosition({lane->length(), 0., 0.}),
api::InertialPosition::FromXyz(end_reference_curve + r_offset_end),
kLinearTolerance));
EXPECT_TRUE(AssertCompare(api::IsInertialPositionClose(
lane->ToInertialPosition({lane->length(), 0., 0.}),
api::InertialPosition::FromXyz(end_reference_curve + r_offset_end), kLinearTolerance)));
// Checks lane start and end BranchPoint.
const api::BranchPoint* const start_bp = lane->GetBranchPoint(api::LaneEnd::kStart);
EXPECT_EQ(start_bp->GetASide()->size(), 1);
Expand Down Expand Up @@ -976,21 +982,21 @@ class TurnBuildProcedure : public BuildProcedure {
for (double r = lbounds.min(); r <= lbounds.max(); r += lane_width / 10) {
// Since the curved lane heading at the origin is opposite to that of
// the straight lane by construction, the r-offset sign is reversed.
EXPECT_TRUE(api::test::IsInertialPositionClose(straight_lane->ToInertialPosition({kS, r, kH}),
curved_lane->ToInertialPosition({kS, -r, kH}),
road_geometry.linear_tolerance()))
EXPECT_TRUE(AssertCompare(api::IsInertialPositionClose(straight_lane->ToInertialPosition({kS, r, kH}),
curved_lane->ToInertialPosition({kS, -r, kH}),
road_geometry.linear_tolerance())))
<< "Position discontinuity at r = " << r;
// Since the curved lane heading at the origin is opposite to that of
// the straight lane by construction, the resulting orientation is
// rotated pi radians about the h-axis.
const api::Rotation rrotation = curved_lane->GetOrientation({kS, -r, kH});
const math::Quaternion pi_rotation(M_PI, math::Vector3(0., 0., 1.));
EXPECT_TRUE(api::test::IsRotationClose(straight_lane->GetOrientation({kS, r, kH}),
// Applies a pi radians rotation around the h-axis to the curved
// lane orientation (i.e. apply an intrinsic pi radians rotation
// about the lane local z-axis, effectively post-multiplying).
api::Rotation::FromQuat(rrotation.quat() * pi_rotation),
road_geometry.angular_tolerance()))
EXPECT_TRUE(AssertCompare(api::IsRotationClose(straight_lane->GetOrientation({kS, r, kH}),
// Applies a pi radians rotation around the h-axis to the curved
// lane orientation (i.e. apply an intrinsic pi radians rotation
// about the lane local z-axis, effectively post-multiplying).
api::Rotation::FromQuat(rrotation.quat() * pi_rotation),
road_geometry.angular_tolerance())))
<< " Orientation discontinuity at r = " << r;
}
}
Expand Down Expand Up @@ -1418,7 +1424,8 @@ class MultilaneBuilderMultilaneCrossTest : public ::testing::Test {
}
EXPECT_EQ(rg->num_branch_points(), 20);

EXPECT_TRUE(api::test::CheckIdIndexing(rg.get()));
const auto check_id_indexing = api::CheckIdIndexing(rg.get());
EXPECT_FALSE(check_id_indexing.has_value()) << check_id_indexing.value();
}
};

Expand Down
Loading
Loading