ATLAS Offline Software
UnitTestDir.cxx
Go to the documentation of this file.
1 // - 2012.
2 // Distributed under the Boost Software License, Version 1.0.
3 // (See accompanying file LICENSE_1_0.txt or copy at
4 // http://www.boost.org/LICENSE_1_0.txt)
5 
6 // Please feel free to contact me (krumnack@iastate.edu) for bug
7 // reports, feature suggestions, praise and complaints.
8 
9 
10 //
11 // includes
12 //
13 
15 
16 #include <cstdlib>
17 #include <TSystem.h>
18 #include <TString.h>
19 #include <RootCoreUtils/Assert.h>
20 #include <RootCoreUtils/ThrowMsg.h>
21 
22 //
23 // method implementations
24 //
25 
26 namespace RCU
27 {
29  testInvariant () const
30  {
31  //RCU_INVARIANT (this != 0);
32  }
33 
34 
35 
37  UnitTestDir (const std::string& package, const std::string& name)
38  : m_cleanup (getenv ("ROOTCORE_AUTO_UT") != 0)
39  {
40  TString output = "/tmp";
41  {
42  const char *tmpdir = getenv ("TMPDIR");
43  if (tmpdir)
44  output = tmpdir;
45  };
46  output += ("/ut-" + package + "-" + name + ".$$").c_str();
47  gSystem->ExpandPathName (output);
48  m_path = output.Data ();
49 
50  if (gSystem->MakeDirectory (output.Data()) != 0)
51  RCU_THROW_MSG (("could not create output directory " + output).Data());
52  }
53 
54 
55 
58  {
59  RCU_DESTROY_INVARIANT (this);
60 
61  if (m_cleanup)
62  gSystem->Exec (("rm -rf " + m_path).c_str());
63  else
64  RCU_PRINT_MSG ("unit test data located at " + m_path);
65  }
66 
67 
68 
69  const std::string& UnitTestDir ::
70  path () const
71  {
72  RCU_READ_INVARIANT (this);
73  return m_path;
74  }
75 
76 
77 
79  cleanup () const
80  {
81  RCU_READ_INVARIANT (this);
82  return m_cleanup;
83  }
84 
85 
86 
88  cleanup (bool val_cleanup)
89  {
90  RCU_CHANGE_INVARIANT (this);
91  m_cleanup = val_cleanup;
92  }
93 }
RCU::UnitTestDir::UnitTestDir
UnitTestDir(const std::string &package, const std::string &name)
effects: standard constructor guarantee: strong failures: out of memory failures: directory creation ...
Definition: UnitTestDir.cxx:37
Data
@ Data
Definition: BaseObject.h:11
RCU::UnitTestDir::testInvariant
void testInvariant() const
effects: test the invariant of this object guarantee: no-fail
Definition: UnitTestDir.cxx:29
RCU::UnitTestDir::m_path
std::string m_path
description: members directly corresponding to accessors
Definition: UnitTestDir.h:78
RCU
This module defines a variety of assert style macros.
Definition: Assert.cxx:26
Assert.h
RCU::UnitTestDir::~UnitTestDir
~UnitTestDir()
effects: standard destructor guarantee: no-fail
Definition: UnitTestDir.cxx:57
UnitTestDir.h
beamspotman.tmpdir
string tmpdir
Definition: beamspotman.py:412
merge.output
output
Definition: merge.py:17
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:221
ThrowMsg.h
RCU_PRINT_MSG
#define RCU_PRINT_MSG(message)
Definition: PrintMsg.h:49
RCU::UnitTestDir::m_cleanup
bool m_cleanup
Definition: UnitTestDir.h:80
RCU::UnitTestDir::cleanup
bool cleanup() const
description: whether we clean up on completion guarantee: no-fail
Definition: UnitTestDir.cxx:79
SCT_ConditionsAlgorithms::CoveritySafe::getenv
std::string getenv(const std::string &variableName)
get an environment variable
Definition: SCT_ConditionsUtilities.cxx:17
RCU_DESTROY_INVARIANT
#define RCU_DESTROY_INVARIANT(x)
Definition: Assert.h:235
RCU::UnitTestDir::path
const std::string & path() const
description: the path to the directory guarantee: no-fail
Definition: UnitTestDir.cxx:70
RCU_CHANGE_INVARIANT
#define RCU_CHANGE_INVARIANT(x)
Definition: Assert.h:231
RCU_THROW_MSG
#define RCU_THROW_MSG(message)
Definition: PrintMsg.h:58
RCU_READ_INVARIANT
#define RCU_READ_INVARIANT(x)
Definition: Assert.h:229