File indexing completed on 2025-01-18 09:12:42
0001
0002
0003
0004
0005
0006
0007
0008
0009 #include <boost/test/unit_test.hpp>
0010
0011 #include "Acts/MagneticField/MagneticFieldContext.hpp"
0012 #include "Acts/MagneticField/MagneticFieldProvider.hpp"
0013
0014 namespace Acts::Test {
0015
0016
0017 MagneticFieldContext mfContext = MagneticFieldContext();
0018
0019 BOOST_AUTO_TEST_CASE(TypeErasedCacheType) {
0020 bool constructor_called = false;
0021 bool destructor_called = false;
0022
0023 struct MyCache {
0024 MyCache(int value, bool* ctor, bool* dtor) : m_value{value}, m_dtor{dtor} {
0025 (*ctor) = true;
0026 }
0027 ~MyCache() { (*m_dtor) = true; }
0028 int m_value;
0029 bool* m_dtor;
0030 };
0031
0032 BOOST_CHECK(!constructor_called);
0033 BOOST_CHECK(!destructor_called);
0034
0035 {
0036 MagneticFieldProvider::Cache cache{
0037 MagneticFieldProvider::Cache(std::in_place_type<MyCache>, 42,
0038 &constructor_called, &destructor_called)};
0039 BOOST_CHECK(constructor_called);
0040 BOOST_CHECK(!destructor_called);
0041
0042 MyCache& v = cache.as<MyCache>();
0043 BOOST_CHECK_EQUAL(v.m_value, 42);
0044 v.m_value = 65;
0045
0046 MyCache& v2 = cache.as<MyCache>();
0047 BOOST_CHECK_EQUAL(v2.m_value, 65);
0048 }
0049
0050 BOOST_CHECK(constructor_called);
0051 BOOST_CHECK(destructor_called);
0052 }
0053
0054 }