ATLAS Offline Software
Loading...
Searching...
No Matches
RCU::UnitTestDir Class Reference

#include <UnitTestDir.h>

Collaboration diagram for RCU::UnitTestDir:

Public Member Functions

 UnitTestDir (const std::string &package, const std::string &name)
 effects: standard constructor guarantee: strong failures: out of memory failures: directory creation errors
 UnitTestDir (const UnitTestDir &)=delete
 rationale: deleted to avoid copying
UnitTestDiroperator= (const UnitTestDir &)=delete
 ~UnitTestDir ()
 effects: standard destructor guarantee: no-fail
const std::string & path () const
 description: the path to the directory guarantee: no-fail
bool cleanup () const
 description: whether we clean up on completion guarantee: no-fail
void cleanup (bool val_cleanup)

Private Attributes

std::string m_path
 description: members directly corresponding to accessors
bool m_cleanup

Detailed Description

Definition at line 19 of file UnitTestDir.h.

Constructor & Destructor Documentation

◆ UnitTestDir() [1/2]

RCU::UnitTestDir::UnitTestDir ( const std::string & package,
const std::string & name )

effects: standard constructor guarantee: strong failures: out of memory failures: directory creation errors

Definition at line 26 of file UnitTestDir.cxx.

28 : m_cleanup (getenv ("ROOTCORE_AUTO_UT") != nullptr)
29 {
30 std::string tmpdir = "/tmp";
31 if (const char *env = getenv ("TMPDIR"))
32 tmpdir = env;
33
34 // use mkdtemp to create a unique, collision-proof directory
35 const std::string templ = tmpdir + "/ut-" + package + "-" + name + "-XXXXXX";
36 std::vector<char> buffer (templ.begin(), templ.end());
37 buffer.push_back ('\0');
38 if (mkdtemp (buffer.data()) == nullptr)
39 throw std::runtime_error ("could not create output directory from template " + templ);
40 m_path = buffer.data();
41 }

◆ UnitTestDir() [2/2]

RCU::UnitTestDir::UnitTestDir ( const UnitTestDir & )
delete

rationale: deleted to avoid copying

◆ ~UnitTestDir()

RCU::UnitTestDir::~UnitTestDir ( )

effects: standard destructor guarantee: no-fail

Definition at line 45 of file UnitTestDir.cxx.

47 {
48 using namespace msgRootCoreUtils;
49
50 if (m_cleanup)
51 {
52 std::error_code ec;
53 std::filesystem::remove_all (m_path, ec);
54 }
55 else
56 ANA_MSG_INFO ("unit test data located at " << m_path);
57 }
#define ANA_MSG_INFO(xmsg)
Macro printing info messages.
std::string m_path
description: members directly corresponding to accessors
Definition UnitTestDir.h:65

Member Function Documentation

◆ cleanup() [1/2]

bool RCU::UnitTestDir::cleanup ( ) const

description: whether we clean up on completion guarantee: no-fail

Definition at line 69 of file UnitTestDir.cxx.

71 {
72 return m_cleanup;
73 }

◆ cleanup() [2/2]

void RCU::UnitTestDir::cleanup ( bool val_cleanup)

Definition at line 77 of file UnitTestDir.cxx.

79 {
80 m_cleanup = val_cleanup;
81 }

◆ operator=()

UnitTestDir & RCU::UnitTestDir::operator= ( const UnitTestDir & )
delete

◆ path()

const std::string & RCU::UnitTestDir::path ( ) const

description: the path to the directory guarantee: no-fail

Definition at line 61 of file UnitTestDir.cxx.

63 {
64 return m_path;
65 }

Member Data Documentation

◆ m_cleanup

bool RCU::UnitTestDir::m_cleanup
private

Definition at line 67 of file UnitTestDir.h.

◆ m_path

std::string RCU::UnitTestDir::m_path
private

description: members directly corresponding to accessors

Definition at line 65 of file UnitTestDir.h.


The documentation for this class was generated from the following files: