Classes | Namespaces | Macros | Typedefs | Functions | Variables
ServiceUtil_test.cc File Reference

Tests the utilities in ServiceUtil.h. More...

#include "larcorealg/CoreUtils/UncopiableAndUnmovableClass.h"
#include "larcore/CoreUtils/ServiceUtil.h"
#include "canvas/Utilities/Exception.h"
#include "art/Framework/Services/Registry/ServiceScope.h"
#include <boost/test/unit_test.hpp>

Go to the source code of this file.

Classes

struct  MyProvider
 
struct  MyOtherProvider
 
struct  YetAnotherProvider
 
class  MyServiceTemplate< Provider >
 
struct  GlobalServicesClass
 
class  ServiceHandleBase< Service >
 
struct  art::detail::ServiceHelper< MyService >
 
struct  art::detail::ServiceHelper< MyOtherService >
 
struct  art::detail::ServiceHelper< YetAnotherService >
 
struct  art::ServiceHandle< MyService, art::ServiceScope::LEGACY >
 
struct  art::ServiceHandle< MyService const, art::ServiceScope::LEGACY >
 
struct  art::ServiceHandle< MyOtherService, art::ServiceScope::LEGACY >
 
struct  art::ServiceHandle< MyOtherService const, art::ServiceScope::LEGACY >
 
struct  art::ServiceHandle< YetAnotherService, art::ServiceScope::LEGACY >
 
struct  art::ServiceHandle< YetAnotherService const, art::ServiceScope::LEGACY >
 

Namespaces

 lar
 LArSoft-specific namespace.
 
 lar::details
 Namespace hiding implementation details.
 
 art
 
 art::detail
 

Macros

#define BOOST_TEST_MODULE   ( ServiceUtil_test )
 

Typedefs

using MyService = MyServiceTemplate< MyProvider >
 
using MyOtherService = MyServiceTemplate< MyOtherProvider >
 
using YetAnotherService = MyServiceTemplate< YetAnotherProvider >
 

Functions

 BOOST_AUTO_TEST_CASE (providerFromTest)
 
 BOOST_AUTO_TEST_CASE (providersFromTest)
 

Variables

GlobalServicesClass GlobalServices
 

Detailed Description

Tests the utilities in ServiceUtil.h.

Author
Gianluca Petrillo (petri.nosp@m.llo@.nosp@m.fnal..nosp@m.gov)
Date
April 28, 2016
See also
ServiceUtil.h

This test takes no command line argument.

Definition in file ServiceUtil_test.cc.

Macro Definition Documentation

#define BOOST_TEST_MODULE   ( ServiceUtil_test )

Definition at line 19 of file ServiceUtil_test.cc.

Typedef Documentation

Definition at line 56 of file ServiceUtil_test.cc.

Definition at line 55 of file ServiceUtil_test.cc.

Definition at line 57 of file ServiceUtil_test.cc.

Function Documentation

BOOST_AUTO_TEST_CASE ( providerFromTest  )

Definition at line 152 of file ServiceUtil_test.cc.

152  {
153 
154  // on the first try, there is no service provider.
155 
156  GlobalServices.myServicePtr = std::make_unique<MyService>();
157  BOOST_CHECK_EXCEPTION(lar::providerFrom<MyService>(), art::Exception,
158  [](art::Exception const& e)
159  { return e.categoryCode() == art::errors::NotFound; }
160  );
161 
162  // now let's create a "real" provider
163  MyProvider prov;
164  GlobalServices.myServicePtr = std::make_unique<MyService>(&prov);
165  BOOST_TEST(lar::providerFrom<MyService>() == &prov);
166 
167  // that's enough; let's clean up
169 
170 } // BOOST_AUTO_TEST_CASE(providerFromTest)
std::unique_ptr< MyService > myServicePtr
const double e
GlobalServicesClass GlobalServices
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
Definition: Exception.h:66
BOOST_AUTO_TEST_CASE ( providersFromTest  )

Definition at line 174 of file ServiceUtil_test.cc.

174  {
175 
176  // on the first try, there is no "other" service provider.
177 
178  MyProvider prov;
179  GlobalServices.myServicePtr = std::make_unique<MyService>(&prov);
180  GlobalServices.myOtherServicePtr = std::make_unique<MyOtherService>();
181  GlobalServices.yetAnotherServicePtr = std::make_unique<YetAnotherService>();
182 
183  auto provPack1 = lar::providersFrom<MyService>();
184  BOOST_TEST(provPack1.get<MyProvider>() == &prov);
185  BOOST_CHECK_EXCEPTION(lar::providersFrom<MyOtherService>(), art::Exception,
186  [](art::Exception const& e)
187  { return e.categoryCode() == art::errors::NotFound; }
188  );
189  BOOST_CHECK_EXCEPTION(
190  (lar::providersFrom<MyService, MyOtherService>()), art::Exception,
191  [](art::Exception const& e)
192  { return e.categoryCode() == art::errors::NotFound; }
193  );
194 
195  // now let's create a "real" provider
196  MyOtherProvider oprov;
197  YetAnotherProvider yaprov;
198  GlobalServices.myOtherServicePtr = std::make_unique<MyOtherService>(&oprov);
200  = std::make_unique<YetAnotherService>(&yaprov);
201 
202  auto provPack
203  = lar::providersFrom<MyService, MyOtherService, YetAnotherService>();
204 
205  BOOST_TEST((provPack == lar::makeProviderPack(&prov, &oprov, &yaprov)));
206  BOOST_TEST(lar::providerFrom<MyService>() == &prov);
207  BOOST_TEST(lar::providerFrom<MyOtherService>() == &oprov);
208  BOOST_TEST(lar::providerFrom<YetAnotherService>() == &yaprov);
209 
210 
211  // that's enough; let's clean up
213 
214 } // BOOST_AUTO_TEST_CASE(providersFromTest)
std::unique_ptr< MyService > myServicePtr
std::unique_ptr< MyOtherService > myOtherServicePtr
std::unique_ptr< YetAnotherService > yetAnotherServicePtr
const double e
GlobalServicesClass GlobalServices
ProviderPack< Providers... > makeProviderPack(Providers const *...providers)
Function to create a ProviderPack from the function arguments.
Definition: ProviderPack.h:272
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
Definition: Exception.h:66

Variable Documentation

GlobalServicesClass GlobalServices

Definition at line 81 of file ServiceUtil_test.cc.