Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
MaterialMapJsonConverterTests.cpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file MaterialMapJsonConverterTests.cpp
1 // This file is part of the Acts project.
2 //
3 // Copyright (C) 2019-2023 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 
16 
17 #include <fstream>
18 #include <memory>
19 
20 #include <nlohmann/json.hpp>
21 
22 namespace Acts {
23 class IVolumeMaterial;
24 } // namespace Acts
25 
27  public:
28  void decorate([[maybe_unused]] const Acts::ISurfaceMaterial &material,
29  [[maybe_unused]] nlohmann::json &json) const override{};
30 
31  void decorate([[maybe_unused]] const Acts::IVolumeMaterial &material,
32  [[maybe_unused]] nlohmann::json &json) const override{};
33 };
34 
35 BOOST_AUTO_TEST_SUITE(MaterialMapJsonConverter)
36 
37 BOOST_AUTO_TEST_CASE(RoundtripFromFile) {
38  // read reference map from file
39  std::ifstream refFile(Acts::Test::getDataPath("material-map.json"));
40  nlohmann::json refJson;
41  refFile >> refJson;
42 
43  DummyDecorator decorator;
44  // convert to the material map and back again
46  Acts::MaterialMapJsonConverter converter(converterCfg, Acts::Logging::INFO);
47  auto materialMap = converter.jsonToMaterialMaps(refJson);
48  nlohmann::json encodedJson =
49  converter.materialMapsToJson(materialMap, &decorator);
50 
51  // verify identical encoded JSON values
52  BOOST_CHECK_EQUAL(refJson, encodedJson);
53 }
54 
55 BOOST_AUTO_TEST_SUITE_END()