Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-11-05 08:55:25

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/MagneticField/MagneticFieldContext.hpp"
0012 #include "Acts/MagneticField/MagneticFieldProvider.hpp"
0013 
0014 using namespace Acts;
0015 
0016 namespace ActssTests {
0017 
0018 // Create a test context
0019 MagneticFieldContext mfContext = MagneticFieldContext();
0020 
0021 BOOST_AUTO_TEST_SUITE(MagneticFieldSuite)
0022 
0023 BOOST_AUTO_TEST_CASE(TypeErasedCacheType) {
0024   bool constructor_called = false;
0025   bool destructor_called = false;
0026 
0027   struct MyCache {
0028     MyCache(int value, bool* ctor, bool* dtor) : m_value{value}, m_dtor{dtor} {
0029       (*ctor) = true;
0030     }
0031     ~MyCache() { (*m_dtor) = true; }
0032     int m_value;
0033     bool* m_dtor;
0034   };
0035 
0036   BOOST_CHECK(!constructor_called);
0037   BOOST_CHECK(!destructor_called);
0038 
0039   {
0040     MagneticFieldProvider::Cache cache{
0041         MagneticFieldProvider::Cache(std::in_place_type<MyCache>, 42,
0042                                      &constructor_called, &destructor_called)};
0043     BOOST_CHECK(constructor_called);
0044     BOOST_CHECK(!destructor_called);
0045 
0046     MyCache& v = cache.as<MyCache>();
0047     BOOST_CHECK_EQUAL(v.m_value, 42);
0048     v.m_value = 65;
0049 
0050     MyCache& v2 = cache.as<MyCache>();
0051     BOOST_CHECK_EQUAL(v2.m_value, 65);
0052   }
0053 
0054   BOOST_CHECK(constructor_called);
0055   BOOST_CHECK(destructor_called);
0056 }
0057 
0058 BOOST_AUTO_TEST_SUITE_END()
0059 
0060 }  // namespace ActssTests