File indexing completed on 2026-11-28 09:15:46
0001
0002
0003
0004
0005
0006
0007
0008
0009 #include <boost/test/unit_test.hpp>
0010
0011 #include "Acts/Definitions/Algebra.hpp"
0012 #include "Acts/Surfaces/CylinderBounds.hpp"
0013 #include "Acts/Surfaces/RectangleBounds.hpp"
0014 #include "ActsPlugins/Json/SurfaceBoundsJsonConverter.hpp"
0015
0016 #include <algorithm>
0017 #include <fstream>
0018 #include <memory>
0019 #include <numbers>
0020 #include <stdexcept>
0021 #include <string>
0022 #include <vector>
0023
0024 #include <nlohmann/json.hpp>
0025
0026 using namespace Acts;
0027
0028 namespace ActsTests {
0029
0030 BOOST_AUTO_TEST_SUITE(JsonSuite)
0031
0032 BOOST_AUTO_TEST_CASE(SurfaceBoundsRoundTripTests) {
0033 std::ofstream out;
0034
0035
0036
0037
0038 auto rectangeRef = std::make_shared<const RectangleBounds>(4., 6.);
0039 nlohmann::json rectangleOut =
0040 SurfaceBoundsJsonConverter::toJson(*rectangeRef);
0041 out.open("RectangleBounds.json");
0042 out << rectangleOut.dump(2);
0043 out.close();
0044
0045 auto in = std::ifstream("RectangleBounds.json",
0046 std::ifstream::in | std::ifstream::binary);
0047 BOOST_CHECK(in.good());
0048 nlohmann::json rectangleIn;
0049 in >> rectangleIn;
0050 in.close();
0051
0052 auto rectangleTest =
0053 SurfaceBoundsJsonConverter::fromJson<RectangleBounds>(rectangleIn);
0054
0055 BOOST_CHECK(rectangeRef->values() == rectangleTest->values());
0056 }
0057
0058 BOOST_AUTO_TEST_CASE(SurfaceBoundsValueCountTests) {
0059 nlohmann::json jShort;
0060 jShort["type"] = "CylinderBounds";
0061 jShort["values"] = std::vector<double>{30., 200., std::numbers::pi};
0062 BOOST_CHECK_THROW(
0063 SurfaceBoundsJsonConverter::fromJson<CylinderBounds>(jShort),
0064 std::invalid_argument);
0065
0066
0067 nlohmann::json jLegacy;
0068 jLegacy["type"] = "CylinderBounds";
0069 jLegacy["values"] =
0070 std::vector<double>{30., 200., std::numbers::pi, 0., 0., 0.};
0071 auto legacy = SurfaceBoundsJsonConverter::fromJson<CylinderBounds>(jLegacy);
0072 BOOST_CHECK_EQUAL(legacy->values().size(), 4u);
0073 BOOST_CHECK_EQUAL(legacy->get(CylinderBounds::eR), 30.);
0074
0075 nlohmann::json jBeveled;
0076 jBeveled["type"] = "CylinderBounds";
0077 jBeveled["values"] =
0078 std::vector<double>{30., 200., std::numbers::pi, 0., 0.1, 0.};
0079 BOOST_CHECK_THROW(
0080 SurfaceBoundsJsonConverter::fromJson<CylinderBounds>(jBeveled),
0081 std::invalid_argument);
0082
0083 nlohmann::json jLong;
0084 jLong["type"] = "RectangleBounds";
0085 jLong["values"] = std::vector<double>{-4., -6., 4., 6., 0.};
0086 BOOST_CHECK_THROW(
0087 SurfaceBoundsJsonConverter::fromJson<RectangleBounds>(jLong),
0088 std::invalid_argument);
0089 }
0090
0091 BOOST_AUTO_TEST_SUITE_END()
0092
0093 }