LArSoft
v07_13_02
Liquid Argon Software toolkit - http://larsoft.org/
|
A test environment with some support for service providers. More...
#include "unit_test_base.h"
Public Types | |
using | Configuration_t = ConfigurationClass |
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... | |
Configuration retrieval | |
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... | |
Static Public Member Functions | |
static fhicl::ParameterSet | CompileParameterSet (std::string cfg) |
Compiles a parameter set from a string. More... | |
Protected Member Functions | |
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 |
Sets up the message facility. More... | |
Static Protected Member Functions | |
static fhicl::ParameterSet | ParseParameters (std::string config_path) |
Fills the test configuration from file or from default. More... | |
Protected Attributes | |
ProviderList | providers |
list of available providers More... | |
Private Types | |
using | TesterEnvBase_t = BasicTesterEnvironment< ConfigurationClass > |
using | TesterEnv_t = TesterEnvironment< ConfigurationClass > |
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 747 of file unit_test_base.h.
|
inherited |
Definition at line 564 of file unit_test_base.h.
|
private |
Definition at line 751 of file unit_test_base.h.
|
private |
Definition at line 750 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 814 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 888 of file unit_test_base.h.
|
staticinherited |
Compiles a parameter set from a string.
Definition at line 1086 of file unit_test_base.h.
References fhicl::make_ParameterSet(), and testing::BasicTesterEnvironment< ConfigurationClass >::ParseParameters().
Referenced by testing::BasicTesterEnvironment< ConfigurationClass >::~BasicTesterEnvironment().
|
inlineprotectedinherited |
Returns a read-only version of the configuration.
Definition at line 636 of file unit_test_base.h.
|
protectedvirtualinherited |
Reads and translates the configuration.
Fills the configuration.
The complete configuration (message facility and services) is read and saved, hence accessible by Parameters() method.
The configuration file path is taken by default from the first argument of the test. If that first argument is not present or empty, the default configuration path is received from the configurer. If the configuration path is still empty, a hard-coded configuration is used; otherwise, the FHiCL file specified in that path is parsed and used as full configuration.
Definition at line 1136 of file unit_test_base.h.
References testing::BasicTesterEnvironment< ConfigurationClass >::SetupMessageFacility().
|
inlineprotectedvirtualinherited |
Creates a full configuration for the test.
Definition at line 648 of file unit_test_base.h.
References lar::standalone::SetupMessageFacility().
|
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 916 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 933 of file unit_test_base.h.
References trkf::fill().
|
inlineinherited |
Returns the full configuration.
Definition at line 606 of file unit_test_base.h.
|
staticprotectedinherited |
Fills the test configuration from file or from default.
Returns the configuration from a FHiCL file.
If a FHiCL configuration file is specified, the configuration of the test is read from it according to the parameter set path of the test. Otherwise, it is parsed from the default one provided by the configurer.Parses from file and returns a FHiCL data structure
config_path | full path of the FHiCL configuration file |
Definition at line 1102 of file unit_test_base.h.
References fhicl::make_ParameterSet(), and fhicl::parse_document().
Referenced by testing::BasicTesterEnvironment< ConfigurationClass >::CompileParameterSet().
|
inline |
Return the specified provider (throws if not available)
Definition at line 924 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 952 of file unit_test_base.h.
|
inlineinherited |
Returns the configuration of the specified service.
Definition at line 609 of file unit_test_base.h.
References fhicl::ParameterSet::get().
|
protectedvirtualinherited |
The complete initialization, ran at construction by default.
Definition at line 1185 of file unit_test_base.h.
References lar::standalone::SetupMessageFacility().
|
protectedvirtualinherited |
Sets up the message facility.
Sets the message facility up.
Message facility configuration is expected in "services.message" parameter set. If not there, the default configuration is used.
Definition at line 1151 of file unit_test_base.h.
References fhicl::ParameterSet::get_if_present(), LOG_TRACE, mf::SetApplicationName(), mf::SetContextIteration(), mf::SetContextSinglet(), mf::StartMessageFacility(), and fhicl::ParameterSet::to_indented_string().
|
inlineprotectedvirtualinherited |
Sets up the message facility.
Sets the message facility up.
Message facility configuration is expected in "services.message" parameter set. If not there, the default configuration is used.
Definition at line 655 of file unit_test_base.h.
References lar::standalone::SetupMessageFacility().
Referenced by testing::BasicTesterEnvironment< ConfigurationClass >::Configure().
|
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 773 of file unit_test_base.h.
References testing::details::CommandLineArguments::args.
|
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 838 of file unit_test_base.h.
References testing::details::CommandLineArguments::args.
|
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 795 of file unit_test_base.h.
References testing::details::CommandLineArguments::args.
|
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 865 of file unit_test_base.h.
References testing::details::CommandLineArguments::args.
|
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 908 of file unit_test_base.h.
|
inlineinherited |
Returns the configuration of the specified test.
Definition at line 616 of file unit_test_base.h.
References fhicl::ParameterSet::get().
|
inlineinherited |
Returns the configuration of the main test (undefined if no main test)
Definition at line 623 of file unit_test_base.h.
|
protected |
list of available providers
Definition at line 961 of file unit_test_base.h.