Classes | Namespaces | Macros | Functions
ProviderPack_test.cc File Reference
#include <cetlib/quiet_unit_test.hpp>
#include <boost/test/test_tools.hpp>
#include "CoreUtils/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 99 of file ProviderPack_test.cc.

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