Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
MagneticFieldProviderTests.cpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file MagneticFieldProviderTests.cpp
1 // This file is part of the Acts project.
2 //
3 // Copyright (C) 2017-2018 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 
13 
14 namespace tt = boost::test_tools;
15 
16 namespace Acts {
17 
18 namespace Test {
19 
20 // Create a test context
22 
23 BOOST_AUTO_TEST_CASE(TypeErasedCacheType) {
24  bool constructor_called = false;
25  bool destructor_called = false;
26 
27  struct MyCache {
28  MyCache(int value, bool* ctor, bool* dtor) : m_value{value}, m_dtor{dtor} {
29  (*ctor) = true;
30  }
31  ~MyCache() { (*m_dtor) = true; }
32  int m_value;
33  bool* m_dtor;
34  };
35 
36  BOOST_CHECK(!constructor_called);
37  BOOST_CHECK(!destructor_called);
38 
39  {
41  MagneticFieldProvider::Cache::make<MyCache>(42, &constructor_called,
42  &destructor_called)};
43  BOOST_CHECK(constructor_called);
44  BOOST_CHECK(!destructor_called);
45 
46  MyCache& v = cache.get<MyCache>();
47  BOOST_CHECK_EQUAL(v.m_value, 42);
48  v.m_value = 65;
49 
50  MyCache& v2 = cache.get<MyCache>();
51  BOOST_CHECK_EQUAL(v2.m_value, 65);
52  }
53 
54  BOOST_CHECK(constructor_called);
55  BOOST_CHECK(destructor_called);
56 }
57 
58 BOOST_AUTO_TEST_CASE(CacheNonCopyable) {
59  struct MyCache {
60  int m_value{0};
61 
62  MyCache() = default;
63  MyCache(int value) : m_value(value) {}
64 
65  MyCache(const MyCache&) = delete;
66  MyCache& operator=(const MyCache&) = delete;
67 
68  MyCache& operator=(MyCache&&) = default;
69  MyCache(MyCache&&) = default;
70  };
71 
72  auto cache = MagneticFieldProvider::Cache::make<MyCache>(42);
73  // MyCache c{42};
74  // std::any a;
75  // a = std::move(c);
76  // a.emplace<MyCache>(42);
77  // a = std::make_any<MyCache>(42);
78 }
79 
80 } // namespace Test
81 
82 } // namespace Acts