Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-06-21 07:47:46

0001 // This file is part of the ACTS project.
0002 //
0003 // Copyright (C) 2016 CERN for the benefit of the ACTS project
0004 //
0005 // This Source Code Form is subject to the terms of the Mozilla Public
0006 // License, v. 2.0. If a copy of the MPL was not distributed with this
0007 // file, You can obtain one at https://mozilla.org/MPL/2.0/.
0008 
0009 #include <boost/test/unit_test.hpp>
0010 
0011 #include "Acts/Geometry/BlueprintBuilder.hpp"
0012 #include "Acts/Geometry/BlueprintNode.hpp"
0013 #include "Acts/Geometry/ContainerBlueprintNode.hpp"
0014 #include "Acts/Geometry/LayerBlueprintNode.hpp"
0015 
0016 #include <memory>
0017 #include <optional>
0018 
0019 using namespace Acts::Experimental;
0020 using Acts::Experimental::detail::OnContainerMutatesContainer;
0021 using Acts::Experimental::detail::OnContainerReturnsNode;
0022 using Acts::Experimental::detail::OnLayerMutatesLayer;
0023 using Acts::Experimental::detail::OnLayerReturnsNode;
0024 
0025 namespace ActsTests {
0026 
0027 // Regression coverage for the backward-compatible `onLayer`/`onContainer`
0028 // customizer contract. The customizers were widened from returning the concrete
0029 // node type (`LayerBlueprintNode` / `ContainerBlueprintNode`) to the base
0030 // `BlueprintNode`. The accepting concepts use `std::convertible_to` (not
0031 // `std::same_as`) so that pre-existing client callbacks returning the concrete
0032 // derived pointer still satisfy the contract.
0033 
0034 using Element = int;
0035 
0036 // --- onLayer ---------------------------------------------------------------
0037 
0038 // Old-style callback: returns the concrete LayerBlueprintNode pointer.
0039 [[maybe_unused]] auto oldStyleLayer =
0040     [](const std::optional<Element>&, std::shared_ptr<LayerBlueprintNode> layer)
0041     -> std::shared_ptr<LayerBlueprintNode> { return layer; };
0042 static_assert(OnLayerReturnsNode<Element, decltype(oldStyleLayer)>,
0043               "onLayer callback returning shared_ptr<LayerBlueprintNode> must "
0044               "remain accepted (backward compatibility)");
0045 
0046 // New-style callback: returns the base BlueprintNode pointer (wrap/replace).
0047 [[maybe_unused]] auto newStyleLayer =
0048     [](const std::optional<Element>&, std::shared_ptr<LayerBlueprintNode> layer)
0049     -> std::shared_ptr<BlueprintNode> { return layer; };
0050 static_assert(OnLayerReturnsNode<Element, decltype(newStyleLayer)>,
0051               "onLayer callback returning shared_ptr<BlueprintNode> must be "
0052               "accepted");
0053 
0054 // In-place mutating callback: returns void.
0055 [[maybe_unused]] auto mutateLayer = [](const std::optional<Element>&,
0056                                        LayerBlueprintNode&) {};
0057 static_assert(OnLayerMutatesLayer<Element, decltype(mutateLayer)>,
0058               "void-returning in-place onLayer callback must be accepted");
0059 static_assert(!OnLayerReturnsNode<Element, decltype(mutateLayer)>,
0060               "void-returning callback must not match the node-returning form");
0061 
0062 // --- onContainer -----------------------------------------------------------
0063 
0064 // Old-style callback: returns the concrete ContainerBlueprintNode pointer.
0065 [[maybe_unused]] auto oldStyleContainer =
0066     [](const Element&, std::shared_ptr<ContainerBlueprintNode> container)
0067     -> std::shared_ptr<ContainerBlueprintNode> { return container; };
0068 static_assert(
0069     OnContainerReturnsNode<Element, decltype(oldStyleContainer)>,
0070     "onContainer callback returning shared_ptr<ContainerBlueprintNode> must "
0071     "remain accepted (backward compatibility)");
0072 
0073 // New-style callback: returns the base BlueprintNode pointer (wrap/replace).
0074 [[maybe_unused]] auto newStyleContainer =
0075     [](const Element&, std::shared_ptr<ContainerBlueprintNode> container)
0076     -> std::shared_ptr<BlueprintNode> { return container; };
0077 static_assert(
0078     OnContainerReturnsNode<Element, decltype(newStyleContainer)>,
0079     "onContainer callback returning shared_ptr<BlueprintNode> must be "
0080     "accepted");
0081 
0082 // In-place mutating callback: returns void.
0083 [[maybe_unused]] auto mutateContainer = [](const Element&,
0084                                            ContainerBlueprintNode&) {};
0085 static_assert(OnContainerMutatesContainer<Element, decltype(mutateContainer)>,
0086               "void-returning in-place onContainer callback must be accepted");
0087 static_assert(!OnContainerReturnsNode<Element, decltype(mutateContainer)>,
0088               "void-returning callback must not match the node-returning form");
0089 
0090 BOOST_AUTO_TEST_SUITE(GeometrySuite)
0091 
0092 BOOST_AUTO_TEST_CASE(CustomizerReturnTypeBackwardCompatibility) {
0093   // The substantive checks are the static_asserts above; this case ensures the
0094   // translation unit is exercised by the test runner.
0095   BOOST_CHECK(true);
0096 }
0097 
0098 BOOST_AUTO_TEST_SUITE_END()
0099 
0100 }  // namespace ActsTests