8#include <framework/logging/Logger.h>
10#include <framework/utilities/TestHelpers.h>
12#include <framework/gearbox/Gearbox.h>
16#include <boost/math/special_functions/sign.hpp>
22using namespace std::filesystem;
29 std::vector<std::string> backends;
30 backends.emplace_back(
"file:");
31 gearbox.setBackends(backends);
33 B2INFO(
"Start open gearbox.");
34 gearbox.open(
"geometry/Belle2.xml");
35 B2INFO(
"Finished open gearbox.");
45 m_oldpwd(current_path().string())
47 char* temporaryDirName = strdup((temp_directory_path() /
"basf2_XXXXXX").c_str());
48 auto directory = mkdtemp(temporaryDirName);
50 B2ERROR(
"Cannot create temporary directory: " << strerror(errno));
51 free(temporaryDirName);
54 path tmpdir = directory;
57 free(temporaryDirName);
73 return fabs(remainder(expected - actual, 2 * M_PI)) < absError;
78 if (std::isnan(expected) or std::isnan(actual))
return false;
79 using boost::math::sign;
80 int expectedSign = sign(expected);
81 int actualSign = sign(actual);
82 return expectedSign == actualSign;
97 const ROOT::Math::XYZVector& actual,
100 bool xNear = std::fabs(expected.X() - actual.X()) < tolerance;
101 bool yNear = std::fabs(expected.Y() - actual.Y()) < tolerance;
102 bool zNear = std::fabs(expected.Z() - actual.Z()) < tolerance;
103 return xNear and yNear and zNear;
109 <<
"ROOT::Math::XYZVector("
110 << vector3.X() <<
", "
111 << vector3.Y() <<
", "
112 << vector3.Z() <<
")";
Singleton class responsible for loading detector parameters from an XML file.
std::string getTempDir() const
Returns path of temporary directory.
std::string m_tmpdir
path of temporary director.
std::string m_oldpwd
previous working directory.
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.
static Gearbox & getInstance()
Return reference to the Gearbox instance.
Some utilities to help with writing unit tests.
bool isPositive(double expected)
Predicate checking that a value is bigger than zero.
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.
void PrintTo(const ROOT::Math::XYZVector &vector3, ::std::ostream &output)
Print function for the google test framework to print a ROOT::Math::XYZVector to an output stream.