Skip to content

Commit

Permalink
test: Use tempdir to produce BB vis output (#1483)
Browse files Browse the repository at this point in the history
Use a temporary directory to store visualization outputs from the BoundingBox test.
  • Loading branch information
paulgessinger committed Sep 1, 2022
1 parent eb8bd04 commit 42b16ef
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 10 deletions.
34 changes: 24 additions & 10 deletions Tests/UnitTests/Core/Utilities/BoundingBoxTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
#include <random>
#include <set>

#include <boost/filesystem.hpp>

namespace Acts {
namespace Test {

Expand All @@ -37,6 +39,18 @@ using Vector2F = Eigen::Matrix<BoundingBoxScalar, 2, 1>;
using Vector3F = Eigen::Matrix<BoundingBoxScalar, 3, 1>;
using AngleAxis3F = Eigen::AngleAxis<BoundingBoxScalar>;

boost::filesystem::path tmp_path = []() {
auto p = boost::filesystem::temp_directory_path() /
boost::filesystem::unique_path();
boost::filesystem::create_directory(p);
std::cout << "Writing test output to: " << p << std::endl;
return p;
}();

std::ofstream tmp(const std::string& path) {
return std::ofstream{(tmp_path / path).string()};
}

BOOST_AUTO_TEST_CASE(box_construction) {
BOOST_TEST_CONTEXT("2D") {
Object o;
Expand Down Expand Up @@ -279,7 +293,7 @@ BOOST_AUTO_TEST_CASE(intersect_rays) {
PlyVisualization3D<BoundingBoxScalar> ply;

ray3.draw(ply);
std::ofstream os("ray3d.ply");
auto os = tmp("ray3d.ply");
os << ply << std::flush;
os.close();
}
Expand Down Expand Up @@ -442,7 +456,7 @@ BOOST_AUTO_TEST_CASE(ray_obb_intersect) {
BOOST_AUTO_TEST_CASE(frustum_intersect) {
BOOST_TEST_CONTEXT("2D") {
auto make_svg = [](std::string fname, size_t w, size_t h) {
std::ofstream os(fname);
auto os = tmp(fname);
os << "<?xml version=\"1.0\" standalone=\"no\"?>\n";
os << "<svg width=\"" << w << "\" height=\"" << h
<< "\" version=\"1.1\" xmlns=\"http://www.w3.org/2000/svg\">\n";
Expand Down Expand Up @@ -653,7 +667,7 @@ BOOST_AUTO_TEST_CASE(frustum_intersect) {
//}
// os.close();

// os = std::ofstream("frust3D_angle.ply");
// os = tmp("frust3D_angle.ply");
// helper.clear();
// n_vtx = 1;
// Eigen::Affine3f rot;
Expand Down Expand Up @@ -843,7 +857,7 @@ BOOST_AUTO_TEST_CASE(frustum_intersect) {
std::stringstream ss;
ss << "frust3d-3s_test_" << l << ".ply";

os = std::ofstream(ss.str());
os = tmp(ss.str());

helper.clear();

Expand Down Expand Up @@ -902,7 +916,7 @@ BOOST_AUTO_TEST_CASE(frustum_intersect) {
// size_t n_vtx = 1;

// helper.clear();
// os = std::ofstream("frust3d-4s_dir.ply");
// os = tmp("frust3d-4s_dir.ply");

// double angle = M_PI / 4.;
// for (size_t i = 0; i <= s; i++) {
Expand All @@ -928,7 +942,7 @@ BOOST_AUTO_TEST_CASE(frustum_intersect) {

// os << helper << std::flush;
// os.close();
// os = std::ofstream("frust3d-4s_angle.ply");
// os = tmp("frust3d-4s_angle.ply");
// helper.clear();

// n_vtx = 1;
Expand Down Expand Up @@ -1107,7 +1121,7 @@ BOOST_AUTO_TEST_CASE(frustum_intersect) {
std::stringstream ss;
ss << "frust3d-4s_test_" << l << ".ply";

os = std::ofstream(ss.str());
os = tmp(ss.str());

helper.clear();

Expand Down Expand Up @@ -1169,7 +1183,7 @@ BOOST_AUTO_TEST_CASE(frustum_intersect) {

BOOST_CHECK(bb.intersect(fr));

std::ofstream os("frust3d-5s.ply");
auto os = tmp("frust3d-5s.ply");
os << ply << std::flush;
os.close();
}
Expand All @@ -1195,7 +1209,7 @@ BOOST_AUTO_TEST_CASE(frustum_intersect) {

BOOST_CHECK(bb.intersect(fr));

std::ofstream os("frust3d-10s.ply");
auto os = tmp("frust3d-10s.ply");
os << ply << std::flush;
os.close();
}
Expand All @@ -1220,7 +1234,7 @@ BOOST_AUTO_TEST_CASE(frustum_intersect) {

BOOST_CHECK(bb.intersect(fr));

std::ofstream os("frust3d-4s-bigbox.ply");
auto os = tmp("frust3d-4s-bigbox.ply");
os << ply << std::flush;
os.close();
}
Expand Down
3 changes: 3 additions & 0 deletions Tests/UnitTests/Core/Utilities/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ add_unittest(BinAdjustment BinAdjustmentTests.cpp)
add_unittest(BinAdjustmentVolume BinAdjustmentVolumeTests.cpp)
add_unittest(BinningData BinningDataTests.cpp)
add_unittest(BinUtility BinUtilityTests.cpp)

add_unittest(BoundingBox BoundingBoxTest.cpp)
target_link_libraries(ActsUnitTestBoundingBox PRIVATE Boost::filesystem)

add_unittest(Extendable ExtendableTests.cpp)
add_unittest(FiniteStateMachine FiniteStateMachineTests.cpp)
add_unittest(Frustum FrustumTest.cpp)
Expand Down

0 comments on commit 42b16ef

Please sign in to comment.