Classes | Namespaces | Macros | Functions
ProviderPack_test.cc File Reference
#include <boost/test/unit_test.hpp>
#include "lardata/DetectorInfo/ProviderPack.h"
#include <string>
#include <ostream>

Go to the source code of this file.

Classes

struct  svc::ProviderA
 A service provider class. More...
 
struct  svc::ProviderB
 A service provider class. More...
 
struct  svc::ProviderC
 A service provider class. More...
 
struct  svc::ProviderD
 A service provider class. More...
 

Namespaces

 svc
 

Macros

#define PROVIDERPACK_TEST_SKIP_COMPILATION_ERRORS   1
 
#define BOOST_TEST_MODULE   ( ProviderPack_test )
 

Functions

 BOOST_AUTO_TEST_CASE (test_ProviderPack)
 

Macro Definition Documentation

#define BOOST_TEST_MODULE   ( ProviderPack_test )

Definition at line 26 of file ProviderPack_test.cc.

#define PROVIDERPACK_TEST_SKIP_COMPILATION_ERRORS   1

Definition at line 13 of file ProviderPack_test.cc.

Function Documentation

BOOST_AUTO_TEST_CASE ( test_ProviderPack  )

Definition at line 98 of file ProviderPack_test.cc.

98  {
99 
100  // instantiate a ProviderPack with two classes
101  svc::ProviderA providerA;
102  svc::ProviderB providerB;
103  svc::ProviderC providerC;
104  auto SP1 = lar::makeProviderPack(&providerA, &providerB, &providerC);
105 
106  // get element A
107  static_assert
108  (decltype(SP1)::has<svc::ProviderA>(), "We don't believe to have ProviderA!!");
109  auto myA = SP1.get<svc::ProviderA>();
110  static_assert(std::is_same<decltype(myA), svc::ProviderA const*>(),
111  "Failed to get the element of type A");
112  BOOST_TEST(myA == &providerA);
113 
114  // get element B
115  static_assert
116  (decltype(SP1)::has<svc::ProviderB>(), "We don't believe to have ProviderB!!");
117  auto myB = SP1.get<svc::ProviderB>();
118  static_assert(std::is_same<decltype(myB), svc::ProviderB const*>(),
119  "Failed to get the element of type B");
120  BOOST_TEST(myB == &providerB);
121 
122  // get element C
123  static_assert
124  (decltype(SP1)::has<svc::ProviderC>(), "We don't believe to have ProviderC!!");
125  auto myC = SP1.get<svc::ProviderC>();
126  static_assert(std::is_same<decltype(myC), svc::ProviderC const*>(),
127  "Failed to get the element of type C");
128  BOOST_TEST(myC == &providerC);
129 
130 
131  // set element A
132  svc::ProviderA providerA2;
133  SP1.set(&providerA2);
134  myA = SP1.get<svc::ProviderA>();
135  BOOST_TEST(myA == &providerA2);
136 
137  // get element D
138  // should be a compilation error
139 #if PROVIDERPACK_TEST_SKIP_COMPILATION_ERRORS
140  BOOST_TEST_MESSAGE(" (test to get a non-existing provider type skipped)");
141 #else
142  SP1.get<svc::ProviderD>();
143 #endif // !PROVIDERPACK_TEST_SKIP_COMPILATION_ERRORS
144 
145  // check what we believe we have
146  static_assert
147  (!decltype(SP1)::has<svc::ProviderD>(), "We believe to have ProviderD!!");
148 
149  // default constructor: all null
151  BOOST_TEST(SP2.get<svc::ProviderA>() == nullptr);
152  BOOST_TEST(SP2.get<svc::ProviderB>() == nullptr);
153 
154  // extraction constructor
156  BOOST_TEST(SP3.get<svc::ProviderA>() == SP1.get<svc::ProviderA>());
157  BOOST_TEST(SP3.get<svc::ProviderB>() == SP1.get<svc::ProviderB>());
158 
159  // multiple elements of the same type
160  // should be a compilation error
161 #if PROVIDERPACK_TEST_SKIP_COMPILATION_ERRORS
162  BOOST_TEST_MESSAGE
163  (" (test to create a pack with many providers with same type skipped)");
164 #else
166  <svc::ProviderA, svc::ProviderB, svc::ProviderA, svc::ProviderD> SP3;
167 #endif // !PROVIDERPACK_TEST_SKIP_COMPILATION_ERRORS
168 
169 
170 } // BOOST_AUTO_TEST_CASE(test_ProviderPack)
A service provider class.
Provider const * get() const
Returns the provider with the specified type.
Definition: ProviderPack.h:193
A service provider class.
ProviderPack< Providers... > makeProviderPack(Providers const *...providers)
Function to create a ProviderPack from the function arguments.
Definition: ProviderPack.h:272
A service provider class.
A service provider class.
Container for a list of pointers to providers.
Definition: ProviderPack.h:114