10#include <framework/logging/LogSystem.h>
12#include <gtest/gtest.h>
14#include <Math/Vector3D.h>
30 namespace TestHelpers {
90#define EXPECT_LOGMESSAGE(x, loglevel) \
92 int nmessages_before = Belle2::LogSystem::Instance().getMessageCounter(loglevel); \
96 int nmessages_after = Belle2::LogSystem::Instance().getMessageCounter(loglevel); \
97 EXPECT_TRUE(nmessages_after > nmessages_before) << "Message of level " << #loglevel << " expected, but not found."; \
105#define EXPECT_B2FATAL(x) EXPECT_EXIT(x, ::testing::ExitedWithCode(1),"")
111#define EXPECT_B2ERROR(x) EXPECT_LOGMESSAGE(x, Belle2::LogConfig::c_Error)
117#define EXPECT_B2WARNING(x) EXPECT_LOGMESSAGE(x, Belle2::LogConfig::c_Warning)
126#define EXPECT_NO_LOGMESSAGE(x, loglevel) \
128 int nmessages_before = Belle2::LogSystem::Instance().getMessageCounter(loglevel); \
132 int nmessages_after = Belle2::LogSystem::Instance().getMessageCounter(loglevel); \
133 EXPECT_TRUE(nmessages_after == nmessages_before) << "Message of level " << #loglevel << " found, but non expected."; \
140#define EXPECT_NO_B2FATAL(x) EXPECT_NO_LOGMESSAGE(x, Belle2::LogConfig::c_Fatal)
146#define EXPECT_NO_B2ERROR(x) EXPECT_NO_LOGMESSAGE(x, Belle2::LogConfig::c_Error)
152#define EXPECT_NO_B2WARNING(x) EXPECT_NO_LOGMESSAGE(x, Belle2::LogConfig::c_Warning)
165#define TEST_CONTEXT(message) SCOPED_TRACE([&](){std::ostringstream messageStream; messageStream << message; return messageStream.str();}())
171#define EXPECT_ANGLE_NEAR(expected, actual, tolerance) EXPECT_PRED3(::Belle2::TestHelpers::angleNear, expected, actual, tolerance)
176#define ASSERT_ANGLE_NEAR(expected, actual, tolerance) ASSERT_PRED3(::Belle2::TestHelpers::angleNear, expected, actual, tolerance)
181#define EXPECT_SAME_SIGN(expected, actual) EXPECT_PRED2(::Belle2::TestHelpers::sameSign, expected, actual)
186#define ASSERT_SAME_SIGN(expected, actual) ASSERT_PRED2(::Belle2::TestHelpers::sameSign, expected, actual)
192#define EXPECT_POSITIVE(expected) EXPECT_PRED1(::Belle2::TestHelpers::isPositive, expected)
197#define ASSERT_POSITIVE(expected) ASSERT_PRED1(::Belle2::TestHelpers::isPositive, expected)
202#define EXPECT_NEGATIVE(expected) EXPECT_PRED1(::Belle2::TestHelpers::isNegative, expected)
207#define ASSERT_NEGATIVE(expected) ASSERT_PRED1(::Belle2::TestHelpers::isNegative, expected)
225#define EXPECT_ALL_NEAR(expected, actual, tolerance) EXPECT_PRED3(::Belle2::TestHelpers::allNear<decltype(expected)>, expected, actual, tolerance)
243#define ASSERT_ALL_NEAR(expected, actual, tolerance) ASSERT_PRED3(::Belle2::TestHelpers::allNear<decltype(expected)>, expected, actual, tolerance)
251 namespace TestHelpers {
253 bool angleNear(
double expected,
double actual,
double tolerance);
256 bool sameSign(
double expected,
double actual);
268 bool allNear(
const T& expected,
const T& actual,
double tolerance)
271 return fabs(expected - actual) < tolerance;
279 void PrintTo(
const TVector3& tVector3, ::std::ostream& output);
changes working directory into a newly created directory, and removes it (and contents) on destructio...
std::string getTempDir() const
Returns path of temporary directory.
std::string m_tmpdir
path of temporary director.
std::string m_oldpwd
previous working directory.
This class provides a test fixture managing the opening and closing of the Gearbox with the default g...
static void SetUpTestCase()
Sets up the Gearbox once for all test in this TestCase.
static void TearDownTestCase()
Closes the Gearbox once for all test in this TestCase.
void PrintTo(const TVector3 &tVector3, ::std::ostream &output)
Print function for the google test framework to print a TVector3 to an output stream.
bool isPositive(double expected)
Predicate checking that a value is bigger than zero.
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 angleNear(double expected, double actual, double tolerance)
Predicate checking that two angular values are close to each other modulus a 2 * PI difference.
bool isNegative(double expected)
Predicate checking that a value is smaller than zero.
bool allNear< ROOT::Math::XYZVector >(const ROOT::Math::XYZVector &expected, const ROOT::Math::XYZVector &actual, double tolerance)
Predicate checking that all three components of XYZVector are close by a maximal error of tolerance.
bool sameSign(double expected, double actual)
Predicate checking that two values have the same sign.
Abstract base class for different kinds of events.