A test environment with some support for service providers. More...
#include <unit_test_base.h>
Public Member Functions | |
template<typename Prov , typename... Args> | |
Prov * | SetupProvider (Args &&...args) |
Sets a service provider up by calling its testing::setupProvider() More... | |
template<typename Prov , typename... Args> | |
Prov * | SetupProviderFromService (std::string name, Args &&...args) |
Sets a service provider up by calling its testing::setupProvider() More... | |
template<typename Prov > | |
Prov * | AcquireProvider (std::unique_ptr< Prov > &&prov) |
Acquires a service provider. More... | |
template<typename Interface , typename Prov , typename... Args> | |
Prov * | SetupProviderFor (Args &&...args) |
Sets a provider up, recording it as implementation of Interface. More... | |
template<typename Interface , typename Prov , typename... Args> | |
Prov * | SetupProviderFromServiceFor (std::string name, Args &&...args) |
Sets a provider up, recording it as implementation of Interface. More... | |
template<typename Interface , typename Prov > | |
Prov * | AcquireProviderFor (std::unique_ptr< Prov > &&prov) |
Acquires a service provider implementing an interface. More... | |
template<typename Prov > | |
Prov * | SimpleProviderSetup () |
Oversimplified provider setup. More... | |
template<typename Prov > | |
void | DropProvider () |
Removes and destroys the specified provider. More... | |
template<typename Prov > | |
Prov const * | Provider () const |
Return the specified provider (throws if not available) More... | |
template<typename... Provs> | |
void | FillProviderPack (lar::ProviderPack< Provs...> &pack) const |
Fills the specified provider pack with providers. More... | |
template<typename Prov > | |
Prov::providers_type | ProviderPackFor () const |
Returns a provider pack for the specified provider. More... | |
Public Member Functions inherited from testing::BasicTesterEnvironment< ConfigurationClass > | |
BasicTesterEnvironment (bool bSetup=true) | |
Constructor: sets everything up and declares the test started. More... | |
virtual | ~BasicTesterEnvironment () |
Destructor: closing remarks. More... | |
BasicTesterEnvironment (Configuration_t const &configurer, bool bSetup=true) | |
Setup from a configuration. More... | |
BasicTesterEnvironment (Configuration_t &&configurer, bool bSetup=true) | |
fhicl::ParameterSet const & | Parameters () const |
Returns the full configuration. More... | |
fhicl::ParameterSet | ServiceParameters (std::string service_name) const |
Returns the configuration of the specified service. More... | |
fhicl::ParameterSet | TesterParameters (std::string test_name) const |
Returns the configuration of the specified test. More... | |
fhicl::ParameterSet | TesterParameters () const |
Returns the configuration of the main test (undefined if no main test) More... | |
Protected Attributes | |
ProviderList | providers |
list of available providers More... | |
Private Types | |
using | TesterEnvBase_t = BasicTesterEnvironment< ConfigurationClass > |
using | TesterEnv_t = TesterEnvironment< ConfigurationClass > |
Additional Inherited Members | |
Public Types inherited from testing::BasicTesterEnvironment< ConfigurationClass > | |
using | Configuration_t = ConfigurationClass |
Static Public Member Functions inherited from testing::BasicTesterEnvironment< ConfigurationClass > | |
static fhicl::ParameterSet | CompileParameterSet (std::string cfg) |
Compiles a parameter set from a string. More... | |
Protected Member Functions inherited from testing::BasicTesterEnvironment< ConfigurationClass > | |
Configuration_t const & | Config () const |
Returns a read-only version of the configuration. More... | |
virtual void | Setup () |
The complete initialization, ran at construction by default. More... | |
virtual void | Configure () |
Reads and translates the configuration. More... | |
virtual fhicl::ParameterSet | DefaultParameters () const |
Creates a full configuration for the test. More... | |
virtual void | SetupMessageFacility (fhicl::ParameterSet const &pset, std::string appl_name="") const |
Sets up the message facility. More... | |
virtual void | SetupMessageFacility () const |
Static Protected Member Functions inherited from testing::BasicTesterEnvironment< ConfigurationClass > | |
static fhicl::ParameterSet | ParseParameters (std::string config_path) |
Fills the test configuration from file or from default. More... | |
A test environment with some support for service providers.
ConfigurationClass | a class providing compile-time configuration |
This test environment extends BasicTesterEnvironment with some basic support for service providers.
This environment makes it available the method Provider<Prov>()
, which returns a pointer to the provider of type Prov.
All providers must be set up after the test environment is constructed. The environment provides the following facilities:
The set up methods support a For
variant (e.g. SetupProviderFor()
) to register the provider also under the type of its interface. For example, if LArPropertiesStandard
is an implementation of LArProperties
, the call:
env.SetupProviderFor<LArProperties, LArPropertiesStandard>(pset);
will set up a LArPropertiesStandard
provider just like
env.SetupProvider<LArPropertiesStandard>(pset);
would, and it makes the provider available as LArProperties
too, so that both calls:
env.Provider<LArProperties>(); env.Provider<LArPropertiesStandard>();
are valid and return the same provider.
The providers must be set up after the test environment is constructed. This also means an additional complication for fixtures that require to be constructed in a final state, as it is the case for Boost unit test suite fixtures. In these cases, a class should publicly derive from TesterEnvironment, and the necessary setup should be added into the constructor of this derived class.
Note that, as in the case of BasicTesterEnvironment, in this case there is no room for polymorphism here since the setup need to happen on construction.
Definition at line 746 of file unit_test_base.h.
|
private |
Definition at line 750 of file unit_test_base.h.
|
private |
Definition at line 749 of file unit_test_base.h.
|
inline |
Acquires a service provider.
Prov | type of provider |
prov | the provider to be acquired |
runtime_error | if the provider already exists |
This method registers and takes ownership of the specified provider. It is similar to SetupProvider() except that user is in charge of the preliminary creation and setup of the provider.
Definition at line 813 of file unit_test_base.h.
|
inline |
Acquires a service provider implementing an interface.
Prov | type of provider |
Interface | type provider alias |
prov | the provider to be acquired |
This method registers and takes ownership of the specified provider, like AcquireProvider() does. It also registers the provider as an implementation of Interface class, as SetupProviderFor does. It is similar to SetupProvider() except that user is in charge of the preliminar creation and setup of the provider.
Definition at line 887 of file unit_test_base.h.
|
inline |
Removes and destroys the specified provider.
Prov | type of provider to be destroyed |
runtime_error | if the provider was not present |
Definition at line 915 of file unit_test_base.h.
|
inline |
Fills the specified provider pack with providers.
runtime_error | and everything provider() method can throw |
Definition at line 932 of file unit_test_base.h.
|
inline |
Return the specified provider (throws if not available)
Definition at line 923 of file unit_test_base.h.
|
inline |
Returns a provider pack for the specified provider.
Prov | type of the provider |
runtime_error | and everything provider() method can throw |
The provider is required to have a providers_type
type defined as an specialisation of lar::ProviderPack.
Definition at line 951 of file unit_test_base.h.
|
inline |
Sets a service provider up by calling its testing::setupProvider()
Prov | type of provider |
Args | type of arguments for the setup function |
args | arguments for the setup function |
runtime_error | if the provider already exists |
A provider of type Prov is created, set up and recorded. Provider setup is delegated to testing::setupProvider
function specific to the provider itself (that is, testing::setupProvider<Prov>(args...)
) to which the setup arguments are forwarded. If the provider already exists, an exception is thrown.
Definition at line 772 of file unit_test_base.h.
|
inline |
Sets a provider up, recording it as implementation of Interface.
Interface | type of provider interface being implemented |
Prov | type of provider |
Args | type of arguments for the setup function |
args | arguments for the setup function |
This method performs the same type of setup as SetupProvider(). In addition, it registers the provider as an implementation of Interface. This means that the provider can be obtained not only with provider<Prov>()
, which returns a pointer to the actual class Prov, but also as provider<Interface>()
, which returns a pointer to the base class Interface.
Definition at line 837 of file unit_test_base.h.
|
inline |
Sets a service provider up by calling its testing::setupProvider()
Prov | type of provider |
Args | type of arguments for the setup function |
name | the service name (for configuration retrieval) |
args | arguments for the setup function |
runtime_error | if the provider already exists |
A provider of type Prov is created, set up and recorded. Provider setup is attempted by constructing the provider with a parameter set from the registered configuration of service with specified name
.
Definition at line 794 of file unit_test_base.h.
|
inline |
Sets a provider up, recording it as implementation of Interface.
Interface | type of provider interface being implemented |
Prov | type of provider |
Args | type of arguments for the setup function |
name | the service name (for configuration retrieval) |
args | arguments for the setup function |
runtime_error | if the provider already exists |
This method performs the same type of setup as SetupProviderFromService(). In addition, it registers the provider as an implementation of Interface. This means that the provider can be obtained not only with provider<Prov>()
, which returns a pointer to the actual class Prov, but also as provider<Interface>()
, which returns a pointer to the base class Interface.
Definition at line 864 of file unit_test_base.h.
|
inline |
Oversimplified provider setup.
Prov | provider type |
This is a one-step setup of the specified provider.
It is available only if Prov provider comes with an implementation of testing::SimpleEnvironmentSetupClass that explains how to set up an environment.
Definition at line 907 of file unit_test_base.h.
|
protected |
list of available providers
Definition at line 960 of file unit_test_base.h.