libMesh
libmesh_cppunit.h
Go to the documentation of this file.
1 
2 #ifndef LIBMESH_LIBMESH_CPPUNIT_H
3 #define LIBMESH_LIBMESH_CPPUNIT_H
4 
5 // Ignore unused parameter warnings coming from cppunit headers
6 #include <libmesh/ignore_warnings.h>
7 #include <cppunit/extensions/HelperMacros.h>
8 #include <cppunit/TestCase.h>
9 #include <libmesh/restore_warnings.h>
10 
11 #include <libmesh/libmesh_logging.h>
12 
13 #if defined(LIBMESH_DEFAULT_QUADRUPLE_PRECISION) || \
14  defined(LIBMESH_DEFAULT_TRIPLE_PRECISION)
15 # define LIBMESH_ASSERT_FP_EQUAL(expected,actual,tolerance) \
16  CPPUNIT_ASSERT_DOUBLES_EQUAL(double((expected)-(actual)),0,double(tolerance))
17 #else
18 # define LIBMESH_ASSERT_FP_EQUAL(expected,actual,tolerance) \
19  CPPUNIT_ASSERT_DOUBLES_EQUAL(expected,actual,tolerance)
20 #endif
21 
22 #ifdef LIBMESH_USE_COMPLEX_NUMBERS
23 # define LIBMESH_ASSERT_NUMBERS_EQUAL(expected,actual,tolerance) \
24  do { \
25  LIBMESH_ASSERT_FP_EQUAL(libMesh::libmesh_real(expected),libMesh::libmesh_real(actual),tolerance); \
26  LIBMESH_ASSERT_FP_EQUAL(libMesh::libmesh_imag(expected),libMesh::libmesh_imag(actual),tolerance); \
27  } while (0)
28 #else
29 # define LIBMESH_ASSERT_NUMBERS_EQUAL(expected,actual,tolerance) \
30  LIBMESH_ASSERT_FP_EQUAL(expected,actual,tolerance)
31 #endif
32 
33 // THE CPPUNIT_TEST_SUITE_END macro expands to code that involves
34 // std::auto_ptr, which in turn produces -Wdeprecated-declarations
35 // warnings. These can be ignored in GCC as long as we wrap the
36 // offending code in appropriate pragmas. We can't get away with a
37 // single ignore_warnings.h inclusion at the beginning of this file,
38 // since the libmesh headers pull in a restore_warnings.h at some
39 // point. This should thus be the *last* header included in our test
40 // suite files.
41 #include <libmesh/ignore_warnings.h>
42 #ifdef __clang__
43 #pragma clang diagnostic ignored "-Wdeprecated-declarations"
44 #endif
45 #if defined(__GNUC__) && !defined(__INTEL_COMPILER) && !defined(__clang__)
46 #if (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ > 5)
47 #pragma GCC diagnostic push
48 #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
49 #endif // GCC > 4.5
50 #endif // __GNUC__ && !__INTEL_COMPILER
51 
52 
53 extern libMesh::PerfLog * unitlog;
54 
55 // Our regular libMesh::PerfItem uses fast_push/pop, so doesn't work
56 // well with strings like TestCase::getName() that get destructed
57 // before we're done printing logs. Per-unit-test timings are
58 // coarse-grained so we can enable them regardless of --enable-perflog
59 // setting.
61 {
62 public:
63  UnitPerfItem(std::string label,
64  std::string header,
65  libMesh::PerfLog & my_perflog) :
66  _label(std::move(label)),
67  _header(std::move(header)),
68  _perflog(my_perflog)
69  {
71  }
72 
74  {
76  }
77 
78 private:
79  const std::string _label;
80  const std::string _header;
82 };
83 
84 #define LIBMESH_CPPUNIT_TEST_SUITE(ATestFixtureType) \
85  protected: \
86  std::string libmesh_suite_name = #ATestFixtureType; \
87  CPPUNIT_TEST_SUITE(ATestFixtureType)
88 
89 
90 #define LOG_UNIT_TEST UnitPerfItem TOKENPASTE2(perf_item_, __LINE__)(__func__,this->libmesh_suite_name,*unitlog)
91 
92 
93 #endif // LIBMESH_LIBMESH_CPPUNIT_H
const std::string _label
void pop(const char *label, const char *header="")
Pop the event label off the stack, resuming any lower event.
Definition: perf_log.C:168
libMesh::PerfLog * unitlog
Definition: driver.C:173
UnitPerfItem(std::string label, std::string header, libMesh::PerfLog &my_perflog)
libMesh::PerfLog & _perflog
The PerfLog class allows monitoring of specific events.
Definition: perf_log.h:145
const std::string _header
void push(const char *label, const char *header="")
Push the event label onto the stack, pausing any active event.
Definition: perf_log.C:138