boost_unit_test_base.h
Go to the documentation of this file.
1 /**
2  * @file boost_unit_test_base.h
3  * @brief Base class for tests using Boost unit test library
4  * @date May 22th, 2015
5  * @author petrillo@fnal.gov
6  * @see unit_test_base.h
7  *
8  * Provides an environment for easy set up of a Boost test.
9  * This is based and wraps the objects in unit_test_base.h.
10  * Since the wrapping is implemented by templates, derived classes than share
11  * interface with the unit_test_base.h objects should also work with the
12  * wrappers.
13  *
14  * For an example of usage, see larcore/test/Geometry/geometry_iterator_test.cxx
15  *
16  * This is a pure template header. It will require the same libraries as
17  * unit_test_base.h .
18  *
19  */
20 
21 
22 #ifndef TEST_BOOST_UNIT_TEST_BASE_H
23 #define TEST_BOOST_UNIT_TEST_BASE_H
24 
25 // LArSoft libraries
27 
28 // Boost libraries
29 #include <boost/test/unit_test.hpp>
30 
31 // C/C++ standard libraries
32 #include <string>
33 
34 
35 namespace testing {
36 
37  /** **************************************************************************
38  * @brief Class holding a configuration for a Boost test fixture
39  * @tparam CONFIGURATIONCLASS a base configuration class
40  * @see BasicEnvironmentConfiguration, TesterEnvironment
41  *
42  * This class needs to be fully constructed by the default constructor
43  * in order to be useful as Boost unit test fixture.
44  * It is supposed to be passed as a template parameter to another class
45  * that can store an instance of it and extract configuration information
46  * from it.
47  *
48  * This template just adds to the standard construction of the wrapped class
49  * a configuration that reads the parameters from the command line.
50  * It also hides all the constructors except two.
51  */
52  template <typename CONFIGURATIONCLASS>
53  struct BoostCommandLineConfiguration: public CONFIGURATIONCLASS {
54 
55  using Base_t = CONFIGURATIONCLASS;
56 
57  /// Default constructor; this is what is used in Boost unit test
60 
61  /// Constructor; accepts the name as parameter
64 
65  protected:
66 
67  /// Parses arguments as delivered by Boost
69  {
70  Base_t::ParseCommandLine(
71  boost::unit_test::framework::master_test_suite().argc,
72  boost::unit_test::framework::master_test_suite().argv
73  );
74  }
75 
76  }; // class BoostCommandLineConfiguration<>
77 
78 
79 } // namespace testing
80 
81 #endif // TEST_BOOST_UNIT_TEST_BASE_H
static QCString name
Definition: declinfo.cpp:673
LArSoft test utilities.
std::string string
Definition: nybbler.cc:12
BoostCommandLineConfiguration()
Default constructor; this is what is used in Boost unit test.
Class holding a configuration for a Boost test fixture.
BoostCommandLineConfiguration(std::string name)
Constructor; accepts the name as parameter.
void ParseCommandLineFromBoost()
Parses arguments as delivered by Boost.
Base class for unit tests using FHiCL configuration.