geometry_test.cxx
Go to the documentation of this file.
1 /**
2  * @file geometry_test.cxx
3  * @brief Unit test for geometry functionalities on a standard detector
4  * @date May 5th, 2015
5  * @author petrillo@fnal.gov
6  *
7  * Usage:
8  * geometry_test [ConfigurationFile [GeometryTestParameterSet]]
9  *
10  * By default, GeometryTestParameterSet is set to "physics.analysers.geotest".
11  *
12  * This unit test uses geometry_unit_test_base.h to build an environment with a
13  * geometry set up.
14  * For an example of use with Boost unit test module, see
15  * geometry_iterator_test.cxx .
16  */
17 
18 
19 // LArSoft libraries
20 #include "test/Geometry/GeometryTestAlg.h"
21 #include "test/Geometry/geometry_unit_test_base.h"
24 
25 // utility libraries
27 
28 
29 //------------------------------------------------------------------------------
30 //--- The test environment
31 //---
32 
33 // we define here all the configuration that is needed;
34 // we use an existing class provided for this purpose, since our test
35 // environment allows us to tailor it at run time.
38 
39 /*
40  * GeometryTesterFixture, configured with the object above, is used in a
41  * non-Boost-unit-test context.
42  * It provides:
43  * - `geo::GeometryCore const* Geometry()`
44  * - `geo::GeometryCore const* GlobalGeometry()` (static member)
45  */
48 
49 
50 //------------------------------------------------------------------------------
51 //--- The tests
52 //---
53 
54 /** ****************************************************************************
55  * @brief Runs the test
56  * @param argc number of arguments in argv
57  * @param argv arguments to the function
58  * @return number of detected errors (0 on success)
59  * @throw cet::exception most of error situations throw
60  *
61  * The arguments in argv are:
62  * 0. name of the executable ("Geometry_test")
63  * 1. path to the FHiCL configuration file
64  * 2. FHiCL path to the configuration of the geometry test
65  * (default: physics.analysers.geotest)
66  * 3. FHiCL path to the configuration of the geometry
67  * (default: services.Geometry)
68  *
69  */
70 //------------------------------------------------------------------------------
71 int main(int argc, char const** argv) {
72 
73  StandardGeometryConfiguration config("geometry_test");
74  config.SetMainTesterParameterSetName("geotest");
75 
76  //
77  // parameter parsing
78  //
79  int iParam = 0;
80 
81  // first argument: configuration file (mandatory)
82  if (++iParam < argc) config.SetConfigurationPath(argv[iParam]);
83 
84  // second argument: path of the parameter set for geometry test configuration
85  // (optional; default: "physics.analysers.geotest")
86  if (++iParam < argc) config.SetMainTesterParameterSetPath(argv[iParam]);
87 
88  // third argument: path of the parameter set for geometry configuration
89  // (optional; default: "services.Geometry" from the inherited object)
90  if (++iParam < argc) config.SetGeometryParameterSetPath(argv[iParam]);
91 
92  //
93  // testing environment setup
94  //
96 
97  //
98  // run the test algorithm
99  //
100 
101  // 1. we initialize it from the configuration in the environment,
102  geo::GeometryTestAlg Tester(TestEnvironment.TesterParameters());
103 
104  // 2. we set it up with the geometry from the environment
105  Tester.Setup(*(TestEnvironment.Provider<geo::GeometryCore>()));
106 
107  // 3. then we run it!
108  unsigned int nErrors = Tester.Run();
109 
110  // 4. And finally we cross fingers.
111  if (nErrors > 0) {
112  mf::LogError("geometry_test") << nErrors << " errors detected!";
113  }
114 
115  return nErrors;
116 } // main()
MaybeLogger_< ELseverityLevel::ELsev_error, false > LogError
Performs tests on the geometry as seen by Geometry service.
static Config * config
Definition: config.cpp:1054
Environment for a geometry test.
virtual void Setup(geo::GeometryCore const &new_geo)
Runs the test.
Description of geometry of one entire detector.
int main(int argc, char const **argv)
Runs the test.
Class holding a configuration for a test environment.
testing::TesterEnvironment< testing::BasicEnvironmentConfiguration > TestEnvironment
testing::GeometryTesterEnvironment< StandardGeometryConfiguration > StandardGeometryTestEnvironment
Access the description of detector geometry.