ValidateAtomicNumberConfiguration_test.cc
Go to the documentation of this file.
1 /**
2  * @file ValidateAtomicNumberConfiguration_test.cc
3  * @brief Validates the AtomicNumber service provider configuration
4  * @author Gianluca Petrillo (petrillo@fnal.gov)
5  * @date April 18, 2016
6  * @see AtomicNumber.h
7  * @ingroup AtomicNumber
8  *
9  * This test expects a single configuration file to be specified as first
10  * argument.
11  *
12  */
13 
14 
15 // LArSoft libraries
17 #include "larcorealg/TestUtils/unit_test_base.h" // testing namespace
18 
19 // support libraries
20 #include "fhiclcpp/types/Name.h"
21 
22 // C/C++ standard libraries
23 #include <iostream> // std::cout
24 #include <string>
25 #include <stdexcept> // std::runtime_error
26 
27 
28 // BEGIN AtomicNumber ----------------------------------------------------------
29 /// @ingroup AtomicNumber
30 /// @{
31 
32 //------------------------------------------------------------------------------
33 int main(int argc, char** argv) {
34 
35  //
36  // configuration of the test
37  //
38 
39  // provide a test name;
40  // the path to the configuration file will be taken from the first parameter
42  (argc, argv, "ValidateAtomicNumberConfiguration_test");
43 
44  // set up a basic testing environment with that configuration
45  auto TesterEnv = testing::CreateTesterEnvironment(config);
46 
47  // create a configuration table; here the name is irrelevant
49  (fhicl::Name("AtomicNumberService"));
50 
51  // print the configuration
52  mf::LogVerbatim("ValidateAtomicNumberConfiguration") << std::string(80, '-')
53  << "\nAllowed configuration for AtomicNumber provider:";
54  providerConfig.print_allowed_configuration(std::cout);
55 
56  //
57  // test of the configuration
58  //
59 
60  mf::LogVerbatim("ValidateAtomicNumberConfiguration") << std::string(80, '-')
61  << "\nValidating configuration from '"
62  << config.ServiceParameterSetPath("AtomicNumberService")
63  << "' in '" << config.ConfigurationPath() << "':";
64  // this will trigger validation
65  // and throw fhicl::detail::validationException on error
66  providerConfig.validate_ParameterSet
67  (TesterEnv.ServiceParameters("AtomicNumberService"), { "service_type" });
68 
69  //
70  // done!
71  //
72  return 0;
73 } // main()
74 
75 /// @}
76 // END AtomicNumber ------------------------------------------------------------
void print_allowed_configuration(std::ostream &os, std::string const &tab=std::string(3, ' ')) const
Definition: Table.h:213
MaybeLogger_< ELseverityLevel::ELsev_info, true > LogVerbatim
std::string string
Definition: nybbler.cc:12
Class holding a configuration for a test environment.
Provider returning atomic number of the active material in the TPC.
int main(int argc, char **argv)
std::string ServiceParameterSetPath(std::string name) const
FHiCL path for the configuration of the service.
static Config * config
Definition: config.cpp:1054
TESTENV CreateTesterEnvironment(CONFIG &&config, ARGS...other_args)
Constructs and returns a TesterEnvironment object.
std::string ConfigurationPath() const
Path to the configuration file.