Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
SurfaceBoundsJsonConverterTests.cpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file SurfaceBoundsJsonConverterTests.cpp
1 // This file is part of the Acts project.
2 //
3 // Copyright (C) 2021 CERN for the benefit of the Acts project
4 //
5 // This Source Code Form is subject to the terms of the Mozilla Public
6 // License, v. 2.0. If a copy of the MPL was not distributed with this
7 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 
9 #include <boost/test/unit_test.hpp>
10 
14 
15 #include <algorithm>
16 #include <fstream>
17 #include <memory>
18 #include <string>
19 #include <vector>
20 
21 #include <nlohmann/json.hpp>
22 
23 using namespace Acts;
24 
25 BOOST_AUTO_TEST_SUITE(SurfaceBoundsJsonConversion)
26 
27 BOOST_AUTO_TEST_CASE(SurfaceBoundsRoundTripTests) {
28  std::ofstream out;
29 
30  // As all SurfaceBounds have the same streaming API only a one is
31  // tested here, all others are tests are identical
32 
33  auto rectangeRef = std::make_shared<const RectangleBounds>(4., 6.);
34  nlohmann::json rectangleOut =
36  out.open("RectangleBounds.json");
37  out << rectangleOut.dump(2);
38  out.close();
39 
40  auto in = std::ifstream("RectangleBounds.json",
41  std::ifstream::in | std::ifstream::binary);
42  BOOST_CHECK(in.good());
43  nlohmann::json rectangleIn;
44  in >> rectangleIn;
45  in.close();
46 
47  auto rectangleTest =
48  SurfaceBoundsJsonConverter::fromJson<RectangleBounds>(rectangleIn);
49 
50  BOOST_CHECK(rectangeRef->values() == rectangleTest->values());
51 }
52 
53 BOOST_AUTO_TEST_CASE(SurfaceBoundsDetrayConversion) {
54  auto rectangeRef = std::make_shared<const RectangleBounds>(4., 6.);
55  nlohmann::json rectangleOutDetray =
57 
58  std::vector<ActsScalar> boundariesRef = {4, 6};
59  BOOST_CHECK(rectangleOutDetray["shape"].get<unsigned int>() == 5u);
60  BOOST_CHECK(rectangleOutDetray["boundaries"].get<std::vector<ActsScalar>>() ==
61  boundariesRef);
62 }
63 
64 BOOST_AUTO_TEST_SUITE_END()