Back to home page

EIC code displayed by LXR

 
 

    


Warning, file /acts/Tests/UnitTests/Plugins/Json/MaterialMapJsonConverterTests.cpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

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/Material/ISurfaceMaterial.hpp"
0012 #include "Acts/Utilities/Logger.hpp"
0013 #include "ActsPlugins/Json/IVolumeMaterialJsonDecorator.hpp"
0014 #include "ActsPlugins/Json/MaterialMapJsonConverter.hpp"
0015 #include "ActsTests/CommonHelpers/DataDirectory.hpp"
0016 
0017 #include <fstream>
0018 #include <memory>
0019 
0020 #include <nlohmann/json.hpp>
0021 
0022 namespace Acts {
0023 class IVolumeMaterial;
0024 }  // namespace Acts
0025 
0026 using namespace Acts;
0027 
0028 class DummyDecorator : public IVolumeMaterialJsonDecorator {
0029  public:
0030   void decorate([[maybe_unused]] const ISurfaceMaterial &material,
0031                 [[maybe_unused]] nlohmann::json &json) const override {};
0032 
0033   void decorate([[maybe_unused]] const IVolumeMaterial &material,
0034                 [[maybe_unused]] nlohmann::json &json) const override {};
0035 };
0036 
0037 namespace ActsTests {
0038 
0039 BOOST_AUTO_TEST_SUITE(JsonSuite)
0040 
0041 BOOST_AUTO_TEST_CASE(RoundtripFromFile) {
0042   // read reference map from file
0043   std::ifstream refFile(ActsTests::getDataPath("material-map.json"));
0044   nlohmann::json refJson;
0045   refFile >> refJson;
0046 
0047   DummyDecorator decorator;
0048   // convert to the material map and back again
0049   MaterialMapJsonConverter::Config converterCfg;
0050   MaterialMapJsonConverter converter(converterCfg, Logging::INFO);
0051   auto materialMap = converter.jsonToMaterialMaps(refJson);
0052   nlohmann::json encodedJson =
0053       converter.materialMapsToJson(materialMap, &decorator);
0054 
0055   // verify identical encoded JSON values
0056   BOOST_CHECK_EQUAL(refJson, encodedJson);
0057 }
0058 
0059 BOOST_AUTO_TEST_SUITE_END()
0060 
0061 }  // namespace ActsTests