LArSoft
v07_13_02
Liquid Argon Software toolkit - http://larsoft.org/
|
Environment for a test. More...
#include "unit_test_base.h"
Classes | |
struct | Options_t |
Test environment options. More... | |
Public Types | |
using | Configuration_t = ConfigurationClass |
Public Member Functions | |
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) | |
Setup from a configuration. 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... | |
Private Member Functions | |
void | ParseEnvironmentOptions () |
Parses the configuration, looking for the test environment options. More... | |
Private Attributes | |
Configuration_t | config |
instance of the configurer More... | |
Options_t | options |
options for the test environment More... | |
fhicl::ParameterSet | params |
full configuration of the test More... | |
Environment for a test.
ConfigurationClass | a class providing compile-time configuration |
The test environment is set up on construction.
The environment provides:
This class or a derived one can be used as global fixture for unit tests.
Unfortunately Boost does not give any control on the initialization of the object, so everything must be ready to go as hard coded. The ConfigurationClass class tries to alleviate that. That is another, small static class that BasicTesterEnvironment uses to get its parameters.
The requirements for the ConfigurationClass are:
std::string ApplicationName()
: the application namestd::string ConfigurationPath()
: path to the configuration filestd::string MainTesterParameterSetName()
: name of the configuration of the main test (commodity)std::string DefaultTesterConfiguration()
returning a FHiCL string to be parsed to extract the default test configurationWhether the configuration comes from a file or from the two provided defaults, it is always expected within the parameter set paths: the default configuration must also contain that path.
Note that there is no room for polymorphism here since the setup happens on construction. Some methods are declared virtual in order to allow to tweak some steps of the set up, but it's not trivial to create a derived class that works correctly: the derived class must declare a new default constructor, and that default constructor must call the protected constructor (BasicTesterEnvironment<ConfigurationClass>(no_setup))
Definition at line 561 of file unit_test_base.h.
using testing::BasicTesterEnvironment< ConfigurationClass >::Configuration_t = ConfigurationClass |
Definition at line 564 of file unit_test_base.h.
|
inline |
Constructor: sets everything up and declares the test started.
bSetup | (default: true ) call Setup() after construction |
The configuration is from a default-constructed ConfigurationClass. This is suitable for use as Boost unit test fixture.
Definition at line 573 of file unit_test_base.h.
|
inline |
Setup from a configuration.
configurer | an instance of ConfigurationClass |
bSetup | (default: true ) call Setup() after construction |
The configuration is from the specified configurer class.
This constructor allows to use a non-default-constructed configuration. This can't be used (at best of my knowledge) when using this class as Boost unit test fixture.
In the r-value-reference constructor, the configurer is moved.
Definition at line 590 of file unit_test_base.h.
|
inline |
Setup from a configuration.
configurer | an instance of ConfigurationClass |
bSetup | (default: true ) call Setup() after construction |
The configuration is from the specified configurer class.
This constructor allows to use a non-default-constructed configuration. This can't be used (at best of my knowledge) when using this class as Boost unit test fixture.
In the r-value-reference constructor, the configurer is moved.
Definition at line 593 of file unit_test_base.h.
|
virtual |
Destructor: closing remarks.
Definition at line 1072 of file unit_test_base.h.
References testing::BasicTesterEnvironment< ConfigurationClass >::CompileParameterSet().
|
static |
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().
|
inlineprotected |
Returns a read-only version of the configuration.
Definition at line 636 of file unit_test_base.h.
|
protectedvirtual |
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().
|
inlineprotectedvirtual |
Creates a full configuration for the test.
Definition at line 648 of file unit_test_base.h.
References lar::standalone::SetupMessageFacility().
|
inline |
Returns the full configuration.
Definition at line 606 of file unit_test_base.h.
|
private |
Parses the configuration, looking for the test environment options.
Definition at line 1222 of file unit_test_base.h.
References fhicl::ParameterSet::get().
|
staticprotected |
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 |
Returns the configuration of the specified service.
Definition at line 609 of file unit_test_base.h.
References fhicl::ParameterSet::get().
|
protectedvirtual |
The complete initialization, ran at construction by default.
Definition at line 1185 of file unit_test_base.h.
References lar::standalone::SetupMessageFacility().
|
protectedvirtual |
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().
|
inlineprotectedvirtual |
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 |
Returns the configuration of the specified test.
Definition at line 616 of file unit_test_base.h.
References fhicl::ParameterSet::get().
|
inline |
Returns the configuration of the main test (undefined if no main test)
Definition at line 623 of file unit_test_base.h.
|
private |
instance of the configurer
Definition at line 675 of file unit_test_base.h.
|
private |
options for the test environment
Definition at line 676 of file unit_test_base.h.
|
private |
full configuration of the test
Definition at line 681 of file unit_test_base.h.