DebugUtils_test.cc
Go to the documentation of this file.
1 /**
2  * @file DebugUtils_test.cc
3  * @brief Unit test for some of the utilities in `DebugUtils.h`.
4  * @author Gianluca Petrillo (petrillo@fnal.gov)
5  * @date March 22, 2019
6  * @see `larcorealg/CoreUtils/DebugUtils.h`
7  *
8  * Test of backtrace print functions is on its own: `printBacktrace_test.cc`.
9  */
10 
11 // Boost libraries
12 #define BOOST_TEST_MODULE ( DebugUtils_test )
13 #include <boost/test/unit_test.hpp>
14 
15 // LArSoft libraries
17 
18 // C/C++ standard libraries
19 #include <type_traits>
20 #include <array>
21 
22 
23 //------------------------------------------------------------------------------
24 //--- static tests (would fail at compile time)
25 //------------------------------------------------------------------------------
26 
27 /*
28  * This is not a real test, but rather an example.
29  * If `DoTest` is `true`, compilation will fail.
30  *
31  * The purpose of the example is to see what is the exact type `element_type`
32  * of the collection type passed to `OurClass`, but only when the collection
33  * type is not constant.
34  *
35  * In addition, `DoTest` needs to be changed to `true` for this to actually
36  * happen.
37  */
38 
39 template <typename Coll>
40 struct OurClass {
41 
42  using Collection_t = Coll;
43 
44  using value_type = typename Collection_t::element_type;
45 
47  <value_type, std::is_const_v<std::remove_reference_t<Coll>>>
49 
50 }; // struct OurClass
51 
52 
54 
55  // this should never trigger a static assertion failure:
56  (void) OurClass<std::unique_ptr<double>>();
57 
58  // this triggers a static assertion failure (#if 1, which we disabled)
59 #if 0
60  (void) OurClass<std::unique_ptr<int[10]> const>();
61 #endif
62 
63 } // static_assert_on_test()
64 
65 
66 //------------------------------------------------------------------------------
67 
68 BOOST_AUTO_TEST_CASE(ReferencesTestCase) {
69 
71 
72 } // BOOST_AUTO_TEST_CASE(ReferencesTestCase)
73 
74 //------------------------------------------------------------------------------
typename Collection_t::element_type value_type
BOOST_AUTO_TEST_CASE(ReferencesTestCase)
Functions to help debugging by instrumenting code.
lar::debug::static_assert_on< value_type, std::is_const_v< std::remove_reference_t< Coll > > > debugVar
Coll Collection_t
void static_assert_on_test()