DP3
fDirectory.h
Go to the documentation of this file.
1 // Copyright (C) 2022 ASTRON (Netherlands Institute for Radio Astronomy)
2 // SPDX-License-Identifier: GPL-3.0-or-later
3 
4 #ifndef DP3_COMMON_TEST_UNIT_FIXTURES_FDIRECTORY_H
5 #define DP3_COMMON_TEST_UNIT_FIXTURES_FDIRECTORY_H
6 
7 #include <cstdlib>
8 #include <string>
9 
10 #include <boost/filesystem.hpp>
11 
12 #include "test_config.h"
13 
14 namespace dp3 {
15 namespace common {
16 namespace test {
17 
25  public:
28  boost::filesystem::create_directories(kPath);
29  boost::filesystem::current_path(kPath);
30  }
31 
34 
38  boost::filesystem::current_path(kWorkDir);
39  boost::filesystem::remove_all(kPath);
40  }
41 
43  static void ExtractResource(const std::string& tgz) {
44  const std::string command = "tar xfz " DP3_RESOURCE_DIR "/" + tgz;
45  const int status = std::system(command.c_str());
46  if (!WIFEXITED(status) || WEXITSTATUS(status) != 0) {
47  throw std::runtime_error("Error while extracting " + tgz);
48  }
49  }
50 
51  private:
52  const boost::filesystem::path kPath = boost::filesystem::unique_path();
53  const boost::filesystem::path kWorkDir = boost::filesystem::current_path();
54 };
55 
56 } // namespace test
57 } // namespace common
58 } // namespace dp3
59 
60 #endif
Definition: fDirectory.h:24
FixtureDirectory & operator=(const FixtureDirectory &)=delete
FixtureDirectory(const FixtureDirectory &)=delete
FixtureDirectory()
Create the temporary directory and set it as working directory.
Definition: fDirectory.h:27
static void ExtractResource(const std::string &tgz)
Extracts a test resource tgz file into the current directory.
Definition: fDirectory.h:43
~FixtureDirectory()
Definition: fDirectory.h:37
This file has generic helper routines for testing steps.
Definition: AntennaConfig.h:53