HOPS
HOPS class reference
MHO_TestAssertions.hh
Go to the documentation of this file.
1 #ifndef MHO_TestAssertions_HH__
2 #define MHO_TestAssertions_HH__
3 
12 #include "MHO_Message.hh"
13 #include <sstream>
14 #include <stdexcept>
15 #include <string>
16 
17 #define HOPS_THROW \
18  { \
19  throw std::runtime_error(std::string(__FILE__) + std::string(":") + std::to_string(__LINE__) + std::string(" in ") + \
20  std::string(__PRETTY_FUNCTION__)); \
21  }
22 
23 #define HOPS_ASSERT_THROW(test_cond) \
24  { \
25  if(!(test_cond)) \
26  { \
27  throw std::runtime_error(std::string(__FILE__) + std::string(":") + std::to_string(__LINE__) + \
28  std::string(" in ") + std::string(__PRETTY_FUNCTION__)); \
29  } \
30  }
31 
32 #define HOPS_ASSERT_EQUAL(a, b) \
33  { \
34  if((a) != (b)) \
35  { \
36  throw std::runtime_error(std::string(__FILE__) + std::string(":") + std::to_string(__LINE__) + \
37  std::string(" in ") + std::string(__PRETTY_FUNCTION__) + std::string(": ") + \
38  std::to_string((a)) + std::string(" != ") + std::to_string((b))); \
39  } \
40  }
41 
42 //to_string is unpredictable for floats/doubles, so this instead
43 #define HOPS_ASSERT_FLOAT_LESS_THAN(a, b) \
44  { \
45  std::stringstream ssa; \
46  ssa << a; \
47  std::stringstream ssb; \
48  ssb << b; \
49  if((a) > (b)) \
50  { \
51  throw std::runtime_error(std::string(__FILE__) + std::string(":") + std::to_string(__LINE__) + \
52  std::string(" in ") + std::string(__PRETTY_FUNCTION__) + std::string(": ") + ssa.str() + \
53  std::string(" !< ") + ssb.str()); \
54  } \
55  }
56 
57 #endif