15 #include <boost/test/unit_test.hpp> 25 for(
typename T::const_iterator k = v.begin(); k != v.end(); ++k) {
26 std::cerr <<
" * " << *k <<
'\n';
39 const std::string maincfg =
"_main.cfg";
43 const std::size_t strip_len = (maincfg +
"/data/").length();
44 BOOST_REQUIRE(gamedata_rev.length() > strip_len);
45 gamedata_rev.resize(gamedata_rev.length() - strip_len);
47 BOOST_CHECK_EQUAL( gamedata_rev, gamedata );
55 BOOST_CHECK(
is_root(
"/../.././") );
56 BOOST_CHECK(
is_root(
"/.././../.") );
77 BOOST_CHECK(
is_directory(gamedata +
"/data/core/../../data/././../data/././core") );
84 BOOST_CHECK_EQUAL(
base_name(
"foo/bar/baz.cfg"),
"baz.cfg" );
87 BOOST_CHECK_EQUAL(
base_name(
"foo/bar"),
"bar" );
105 const std::string
path =
"data/test/test/filesystem/enum";
107 const std::vector<std::string> expected_filenames {
116 const std::vector<std::string> expected_dirnames {
121 std::vector<std::string> files, dirs;
122 std::vector<std::string> expected_filepaths, expected_dirpaths;
124 for(
const std::string&
n : expected_filenames) {
125 expected_filepaths.push_back(gamedata +
"/" + path +
"/" +
n);
128 for(
const std::string&
n : expected_dirnames) {
129 expected_dirpaths.push_back(gamedata +
"/" + path +
"/" +
n);
135 get_files_in_dir(path, &files, &dirs, name_mode::ENTIRE_FILE_PATH, filter_mode::NO_FILTER, reorder_mode::DO_REORDER);
137 BOOST_CHECK( files == expected_filepaths );
138 BOOST_CHECK( dirs == expected_dirpaths );
149 gamedata +
"/images/././././././" );
152 gamedata +
"/data/core/images/wesnoth-icon.png" );
155 gamedata +
"/data/core/music/silence.ogg" );
158 gamedata +
"/data/core/sounds/explosion.ogg" );
161 "data/core/images/wesnoth-icon.png" );
179 BOOST_CHECK_EQUAL(
get_wml_location(
"_main.cfg"), gamedata +
"/data/_main.cfg" );
180 BOOST_CHECK_EQUAL(
get_wml_location(
"core/_main.cfg"), gamedata +
"/data/core/_main.cfg" );
186 BOOST_CHECK(
get_wml_location(
"why_would_anyone_ever_name_a_file_like_this").empty() );
197 BOOST_CHECK_EQUAL(
nearest_extant_parent(gamedata +
"/data/core/THIS_DOES_NOT_EXIST/test"), gamedata +
"/data/core" );
206 BOOST_CHECK(
ends_with(
"foobarbazbat",
"bazbat") );
229 BOOST_AUTO_TEST_SUITE_END()
std::string get_binary_dir_location(const std::string &type, const std::string &filename)
Returns a complete path to the actual directory of a given type or an empty string if the directory i...
bool looks_like_pbl(const std::string &file)
static bool file_exists(const bfs::path &fpath)
bool ends_with(const std::string &str, const std::string &suffix)
const std::string & gamedata
std::string get_binary_file_location(const std::string &type, const std::string &filename)
Returns a complete path to the actual file of a given type or an empty string if the file isn't prese...
BOOST_AUTO_TEST_SUITE(filesystem)
std::string get_user_data_dir()
void get_files_in_dir(const std::string &dir, std::vector< std::string > *files, std::vector< std::string > *dirs, name_mode mode, filter_mode filter, reorder_mode reorder, file_tree_checksum *checksum)
Populates 'files' with all the files and 'dirs' with all the directories in dir.
std::string nearest_extant_parent(const std::string &file)
Finds the nearest parent in existence for a file or directory.
bool is_directory(const std::string &fname)
Returns true if the given file is a directory.
std::string get_independent_image_path(const std::string &filename)
Returns an image path to filename for binary path-independent use in saved games. ...
BOOST_AUTO_TEST_CASE(test_fs_game_path_reverse_engineering)
bool is_gzip_file(const std::string &filename)
Returns true if the file ends with '.gz'.
bool is_relative(const std::string &path)
Returns whether the path seems to be relative.
std::string get_wml_location(const std::string &filename, const std::string ¤t_dir)
Returns a complete path to the actual WML file or directory or an empty string if the file isn't pres...
bool is_compressed_file(const std::string &filename)
bool is_root(const std::string &path)
Returns whether the path is the root of the file hierarchy.
Declarations for File-IO.
std::string base_name(const std::string &file, const bool remove_extension)
Returns the base filename of a file, with directory name stripped.
bool is_bzip2_file(const std::string &filename)
Returns true if the file ends with '.bz2'.
static map_location::DIRECTION n
std::string directory_name(const std::string &file)
Returns the directory name of a file, with filename stripped.