Macros | Functions
filepath_maker_test.cc File Reference
#include "boost/test/unit_test.hpp"
#include "boost/filesystem.hpp"
#include "cetlib/filepath_maker.h"
#include "cetlib/filesystem.h"
#include "cetlib/getenv.h"
#include "cetlib_except/exception.h"
#include <string>

Go to the source code of this file.

Macros

#define BOOST_TEST_MODULE   (filepath_maker test)
 

Functions

 BOOST_AUTO_TEST_CASE (filepath_maker_t)
 
 BOOST_AUTO_TEST_CASE (filepath_lookup_t1)
 
 BOOST_AUTO_TEST_CASE (filepath_lookup_t2)
 
 BOOST_AUTO_TEST_CASE (filepath_lookup_nonabsolute_t)
 
 BOOST_AUTO_TEST_CASE (filepath_lookup_after1_t1)
 
 BOOST_AUTO_TEST_CASE (filepath_lookup_after1_t2)
 
 BOOST_AUTO_TEST_CASE (filepath_lookup_after1_t3)
 
 BOOST_AUTO_TEST_CASE (filepath_lookup_after1_t4)
 
 BOOST_AUTO_TEST_CASE (filepath_first_absolute_or_lookup_with_dot_t1)
 
 BOOST_AUTO_TEST_CASE (filepath_first_absolute_or_lookup_with_dot_t2)
 
 BOOST_AUTO_TEST_CASE (filepath_first_absolute_or_lookup_with_dot_t3)
 
 BOOST_AUTO_TEST_CASE (filepath_first_absolute_or_lookup_with_dot_t4)
 

Macro Definition Documentation

#define BOOST_TEST_MODULE   (filepath_maker test)

Definition at line 7 of file filepath_maker_test.cc.

Function Documentation

BOOST_AUTO_TEST_CASE ( filepath_maker_t  )

Definition at line 50 of file filepath_maker_test.cc.

51 {
53  auto const files = {"a.txt", "./b.txt", "/c/d.txt"};
54  for (auto const& filename : files) {
55  BOOST_TEST(filename == maker(filename));
56  }
57 }
string filename
Definition: train.py:213
list files
Definition: languages.py:9
def maker(G, ac, typename)
Definition: apa.py:280
BOOST_AUTO_TEST_CASE ( filepath_lookup_t1  )

Definition at line 59 of file filepath_maker_test.cc.

60 {
61  // Check that
63  auto const files = {"a.txt"s, "b.txt"s, "c.txt"s};
64  for (auto const& filename : files) {
65  auto const fullPath1 = maker(filename);
66  // Adding './' or '/' makes no difference when everything is
67  // looked up relative to the specified paths.
68  auto const fullPath2 = maker("./" + filename);
69  auto const fullPath3 = maker("/" + filename);
70  bfs::path const p1{fullPath1};
71  bfs::path const p2{fullPath2};
72  bfs::path const p3{fullPath3};
73  BOOST_TEST(bfs::equivalent(p1, p2));
74  BOOST_TEST(bfs::equivalent(p1, p3));
75  // Check that operator() has created an absolute filepath.
76  BOOST_TEST(cet::is_absolute_filepath(fullPath1));
77  BOOST_TEST(cet::is_absolute_filepath(fullPath2));
78  BOOST_TEST(cet::is_absolute_filepath(fullPath3));
79  // Now check that the file *cannot* be accessed via its absolute filepath.
80  check_exception(maker, current_nested_dir() + '/' + filename);
81  }
82 }
string filename
Definition: train.py:213
list files
Definition: languages.py:9
bool is_absolute_filepath(std::string const &qualified_filename)
Definition: filesystem.cc:23
def maker(G, ac, typename)
Definition: apa.py:280
static QCString * s
Definition: config.cpp:1042
BOOST_AUTO_TEST_CASE ( filepath_lookup_t2  )

Definition at line 84 of file filepath_maker_test.cc.

85 {
87  // Check that we cannot access a file in the current source
88  // directory.
89  check_exception(maker, file_in_current_dir);
90 }
def maker(G, ac, typename)
Definition: apa.py:280
BOOST_AUTO_TEST_CASE ( filepath_lookup_nonabsolute_t  )

Definition at line 92 of file filepath_maker_test.cc.

93 {
95  auto const files = {"a.txt"s, "b.txt"s, "c.txt"s};
96  for (auto const& filename : files) {
97  auto const fullPath1 = maker(filename);
98  // Test that it can be accessed via the absolute path
99  auto const fullPath2 = maker(current_nested_dir() + '/' + filename);
100  bfs::path const p1{fullPath1};
101  bfs::path const p2{fullPath2};
102  BOOST_TEST(bfs::equivalent(p1, p2));
103  // Check that operator() has created an absolute filepath.
104  BOOST_TEST(cet::is_absolute_filepath(fullPath1));
105  BOOST_TEST(cet::is_absolute_filepath(fullPath2));
106  }
107 
108  // Check that we cannot access a file in the current source
109  // directory without specifying the full path...
110  check_exception(maker, file_in_current_dir);
111  // ...but we can access it through its full path.
112  maker(current_dir() + '/' + file_in_current_dir);
113 }
string filename
Definition: train.py:213
list files
Definition: languages.py:9
bool is_absolute_filepath(std::string const &qualified_filename)
Definition: filesystem.cc:23
def maker(G, ac, typename)
Definition: apa.py:280
static QCString * s
Definition: config.cpp:1042
BOOST_AUTO_TEST_CASE ( filepath_lookup_after1_t1  )

Definition at line 115 of file filepath_maker_test.cc.

116 {
118  // For the first file, the maker returns whatever you give it.
119  // There is no checking to see if the file actually exists.
120  auto const file = maker("a.txt");
121  BOOST_TEST(!cet::file_exists(file));
122 }
bool file_exists(std::string const &qualified_filename)
Definition: filesystem.cc:14
def maker(G, ac, typename)
Definition: apa.py:280
BOOST_AUTO_TEST_CASE ( filepath_lookup_after1_t2  )

Definition at line 124 of file filepath_maker_test.cc.

125 {
127  auto const absolute_path = current_dir() + '/' + file_in_current_dir;
128  // Absolute allowed for first file
129  maker(absolute_path);
130  // ... not allowed for second file
131  check_exception(maker, absolute_path);
132 
133  // File relative to path allowed for second file
134  maker("a.txt");
135  // Absolute path not allowed for second file
136  check_exception(maker, current_nested_dir() + "/a.txt");
137 }
def maker(G, ac, typename)
Definition: apa.py:280
BOOST_AUTO_TEST_CASE ( filepath_lookup_after1_t3  )

Definition at line 139 of file filepath_maker_test.cc.

140 {
142  auto const relative_path = "./" + file_in_current_dir;
143  // Dot-prefixed file allowed for first file
144  maker(relative_path);
145  // ... not allowed for second file
146  check_exception(maker, relative_path);
147 
148  // File relative to path allowed for second file
149  maker("a.txt");
150  // Absolute path not allowed for second file
151  check_exception(maker, current_nested_dir() + "/a.txt");
152 }
def maker(G, ac, typename)
Definition: apa.py:280
BOOST_AUTO_TEST_CASE ( filepath_lookup_after1_t4  )

Definition at line 154 of file filepath_maker_test.cc.

155 {
157  // Relative file allowed for first file
158  maker(file_in_current_dir);
159  // ... not allowed for second file
160  check_exception(maker, file_in_current_dir);
161 
162  // File relative to path allowed for second file
163  maker("a.txt");
164  // Absolute path not allowed for second file
165  check_exception(maker, current_nested_dir() + "/a.txt");
166 }
def maker(G, ac, typename)
Definition: apa.py:280
BOOST_AUTO_TEST_CASE ( filepath_first_absolute_or_lookup_with_dot_t1  )

Definition at line 168 of file filepath_maker_test.cc.

169 {
170  // Must provide value of environment variable for this policy, not
171  // its name.
173  // The first file is permitted to be relative the path.
174  auto const file = maker("a.txt");
175  BOOST_TEST(cet::file_exists(file));
176 }
std::string getenv(std::string const &name)
Definition: getenv.cc:15
bool file_exists(std::string const &qualified_filename)
Definition: filesystem.cc:14
def maker(G, ac, typename)
Definition: apa.py:280
BOOST_AUTO_TEST_CASE ( filepath_first_absolute_or_lookup_with_dot_t2  )

Definition at line 178 of file filepath_maker_test.cc.

179 {
181  auto const absolute_path = current_dir() + '/' + file_in_current_dir;
182  // Absolute allowed for first file
183  maker(absolute_path);
184  // ... not allowed for second file
185  check_exception(maker, absolute_path);
186 
187  // File relative to path allowed for second file
188  maker("a.txt");
189  // Absolute path not allowed for second file
190  check_exception(maker, current_nested_dir() + "/a.txt");
191 }
std::string getenv(std::string const &name)
Definition: getenv.cc:15
def maker(G, ac, typename)
Definition: apa.py:280
BOOST_AUTO_TEST_CASE ( filepath_first_absolute_or_lookup_with_dot_t3  )

Definition at line 193 of file filepath_maker_test.cc.

194 {
196  auto const relative_path = "./" + file_in_current_dir;
197  // Dot-prefixed file allowed for first file
198  maker(relative_path);
199  // ... not allowed for second file
200  check_exception(maker, relative_path);
201 
202  // File relative to path allowed for second file
203  maker("a.txt");
204  // Absolute path not allowed for second file
205  check_exception(maker, current_nested_dir() + "/a.txt");
206 }
std::string getenv(std::string const &name)
Definition: getenv.cc:15
def maker(G, ac, typename)
Definition: apa.py:280
BOOST_AUTO_TEST_CASE ( filepath_first_absolute_or_lookup_with_dot_t4  )

Definition at line 208 of file filepath_maker_test.cc.

209 {
211  // Relative file allowed for first file
212  maker(file_in_current_dir);
213  // ... not allowed for second file
214  check_exception(maker, file_in_current_dir);
215 
216  // File relative to path allowed for second file
217  maker("a.txt");
218  // Absolute path not allowed for second file
219  check_exception(maker, current_nested_dir() + "/a.txt");
220 }
std::string getenv(std::string const &name)
Definition: getenv.cc:15
def maker(G, ac, typename)
Definition: apa.py:280