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 // GArSoft libraries
20 #include "test/Geometry/GeometryTestAlg.h"
21 #include "test/Geometry/geometry_unit_test_base.h"
22 #include "Geometry/GeometryCore.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.
37 
38 /*
39  * GeometryTesterFixture, configured with the object above, is used in a
40  * non-Boost-unit-test context.
41  * It provides:
42  * - `geo::GeometryCore const* Geometry()`
43  * - `geo::GeometryCore const* GlobalGeometry()` (static member)
44  */
46 
47 
48 //------------------------------------------------------------------------------
49 //--- The tests
50 //---
51 
52 /** ****************************************************************************
53  * @brief Runs the test
54  * @param argc number of arguments in argv
55  * @param argv arguments to the function
56  * @return number of detected errors (0 on success)
57  * @throw cet::exception most of error situations throw
58  *
59  * The arguments in argv are:
60  * 0. name of the executable ("Geometry_test")
61  * 1. path to the FHiCL configuration file
62  * 2. FHiCL path to the configuration of the geometry test
63  * (default: physics.analysers.geotest)
64  * 3. FHiCL path to the configuration of the geometry
65  * (default: services.Geometry)
66  *
67  */
68 //------------------------------------------------------------------------------
69 int main(int argc, char const** argv) {
70 
71  StandardGeometryConfiguration config("geometry_test");
72  config.SetMainTesterParameterSetName("geotest");
73 
74  //
75  // parameter parsing
76  //
77  int iParam = 0;
78 
79  // first argument: configuration file (mandatory)
80  if (++iParam < argc) config.SetConfigurationPath(argv[iParam]);
81 
82  // second argument: path of the parameter set for geometry test configuration
83  // (optional; default: "physics.analysers.geotest")
84  if (++iParam < argc) config.SetMainTesterParameterSetPath(argv[iParam]);
85 
86  // third argument: path of the parameter set for geometry configuration
87  // (optional; default: "services.Geometry" from the inherited object)
88  if (++iParam < argc) config.SetGeometryParameterSetPath(argv[iParam]);
89 
90  //
91  // testing environment setup
92  //
94 
95  //
96  // run the test algorithm
97  //
98 
99  // 1. we initialize it from the configuration in the environment,
100  gar::geo::GeometryTestAlg Tester(TestEnvironment.TesterParameters());
101 
102  // 2. we set it up with the geometry from the environment
103  Tester.Setup(*(TestEnvironment.Provider<gar::geo::GeometryCore>()));
104 
105  // 3. then we run it!
106  unsigned int nErrors = Tester.Run();
107 
108  // 4. And finally we cross fingers.
109  if (nErrors > 0) {
110  mf::LogError("geometry_test") << nErrors << " errors detected!";
111  }
112 
113  return nErrors;
114 } // main()
Performs tests on the geometry as seen by Geometry service.
Description of geometry of one entire detector.
Definition: GeometryCore.h:436
MaybeLogger_< ELseverityLevel::ELsev_error, false > LogError
static Config * config
Definition: config.cpp:1054
Environment for a geometry test.
int main(int argc, char const **argv)
Runs the test.
Class holding a configuration for a test environment.
testing::TesterEnvironment< testing::BasicEnvironmentConfiguration > TestEnvironment
virtual void Setup(geo::GeometryCore const &new_geo)
Runs the test.
testing::GeometryTesterEnvironment< StandardGeometryConfiguration > StandardGeometryTestEnvironment