 |
Belle II Software
release-05-02-19
|
3 #include <framework/logging/LogSystem.h>
5 #include <gtest/gtest.h>
21 namespace TestHelpers {
81 #define EXPECT_LOGMESSAGE(x, loglevel) \
83 int nmessages_before = Belle2::LogSystem::Instance().getMessageCounter(loglevel); \
87 int nmessages_after = Belle2::LogSystem::Instance().getMessageCounter(loglevel); \
88 EXPECT_TRUE(nmessages_after > nmessages_before) << "Message of level " << #loglevel << " expected, but not found."; \
96 #define EXPECT_B2FATAL(x) EXPECT_EXIT(x, ::testing::ExitedWithCode(1),"")
102 #define EXPECT_B2ERROR(x) EXPECT_LOGMESSAGE(x, Belle2::LogConfig::c_Error)
108 #define EXPECT_B2WARNING(x) EXPECT_LOGMESSAGE(x, Belle2::LogConfig::c_Warning)
117 #define EXPECT_NO_LOGMESSAGE(x, loglevel) \
119 int nmessages_before = Belle2::LogSystem::Instance().getMessageCounter(loglevel); \
123 int nmessages_after = Belle2::LogSystem::Instance().getMessageCounter(loglevel); \
124 EXPECT_TRUE(nmessages_after == nmessages_before) << "Message of level " << #loglevel << " found, but non expected."; \
131 #define EXPECT_NO_B2FATAL(x) EXPECT_NO_LOGMESSAGE(x, Belle2::LogConfig::c_Fatal)
137 #define EXPECT_NO_B2ERROR(x) EXPECT_NO_LOGMESSAGE(x, Belle2::LogConfig::c_Error)
143 #define EXPECT_NO_B2WARNING(x) EXPECT_NO_LOGMESSAGE(x, Belle2::LogConfig::c_Warning)
156 #define TEST_CONTEXT(message) SCOPED_TRACE([&](){std::ostringstream messageStream; messageStream << message; return messageStream.str();}())
162 #define EXPECT_ANGLE_NEAR(expected, actual, tolerance) EXPECT_PRED3(::Belle2::TestHelpers::angleNear, expected, actual, tolerance)
167 #define ASSERT_ANGLE_NEAR(expected, actual, tolerance) ASSERT_PRED3(::Belle2::TestHelpers::angleNear, expected, actual, tolerance)
172 #define EXPECT_SAME_SIGN(expected, actual) EXPECT_PRED2(::Belle2::TestHelpers::sameSign, expected, actual)
177 #define ASSERT_SAME_SIGN(expected, actual) ASSERT_PRED2(::Belle2::TestHelpers::sameSign, expected, actual)
183 #define EXPECT_POSITIVE(expected) EXPECT_PRED1(::Belle2::TestHelpers::isPositive, expected)
188 #define ASSERT_POSITIVE(expected) ASSERT_PRED1(::Belle2::TestHelpers::isPositive, expected)
193 #define EXPECT_NEGATIVE(expected) EXPECT_PRED1(::Belle2::TestHelpers::isNegative, expected)
198 #define ASSERT_NEGATIVE(expected) ASSERT_PRED1(::Belle2::TestHelpers::isNegative, expected)
216 #define EXPECT_ALL_NEAR(expected, actual, tolerance) EXPECT_PRED3(::Belle2::TestHelpers::allNear<decltype(expected)>, expected, actual, tolerance)
234 #define ASSERT_ALL_NEAR(expected, actual, tolerance) ASSERT_PRED3(::Belle2::TestHelpers::allNear<decltype(expected)>, expected, actual, tolerance)
242 namespace TestHelpers {
244 bool angleNear(
double expected,
double actual,
double tolerance);
247 bool sameSign(
double expected,
double actual);
259 bool allNear(
const T& expected,
const T& actual,
double tolerance)
262 return fabs(expected - actual) < tolerance;
267 bool allNear<TVector3>(
const TVector3& expected,
const TVector3& actual,
double tolerance);
270 void PrintTo(
const TVector3& tVector3, ::std::ostream& output);
bool isNegative(double expected)
Predicate checking that a value is smaller than zero.
bool allNear< TVector3 >(const TVector3 &expected, const TVector3 &actual, double tolerance)
Predicate checking that all three components of TVector3 are close by a maximal error of tolerance.
static void TearDownTestCase()
Closes the Gearbox once for all test in this TestCase.
bool angleNear(double expected, double actual, double tolerance)
Predicate checking that two angular values are close to each other modulus a 2 * PI difference.
changes working directory into a newly created directory, and removes it (and contents) on destructio...
std::string m_tmpdir
path of temporary director.
Abstract base class for different kinds of events.
std::string m_oldpwd
previous working directory.
static void SetUpTestCase()
Sets up the Gearbox once for all test in this TestCase.
bool allNear(const T &expected, const T &actual, double tolerance)
Templated version of predicate checking if two combound object containing some floating point are nea...
bool isPositive(double expected)
Predicate checking that a value is bigger than zero.
This class provides a test fixture managing the opening and closing of the Gearbox with the default g...
bool sameSign(double expected, double actual)
Predicate checking that two values have the same sign.
std::string getTempDir() const
Returns path of temporary directory.
void PrintTo(const TVector3 &tVector3, ::std::ostream &output)
Print function for the google test framework to print a TVector3 to an output stream.