16 #include <boost/test/unit_test.hpp>
29 for(
typename T::const_iterator k = v.begin(); k != v.end(); ++k) {
43 const std::string maincfg =
"_main.cfg";
47 const std::size_t strip_len = (maincfg +
"/data/").length();
48 BOOST_REQUIRE(gamedata_rev.length() > strip_len);
49 gamedata_rev.resize(gamedata_rev.length() - strip_len);
51 BOOST_CHECK_EQUAL( gamedata_rev,
gamedata );
59 BOOST_CHECK(
is_root(
"/../.././") );
60 BOOST_CHECK(
is_root(
"/.././../.") );
88 BOOST_CHECK_EQUAL(
base_name(
"foo/bar/baz.cfg"),
"baz.cfg" );
91 BOOST_CHECK_EQUAL(
base_name(
"foo/bar"),
"bar" );
109 const std::string
path =
"data/test/test/filesystem/enum";
111 const std::vector<std::string> expected_filenames {
120 const std::vector<std::string> expected_dirnames {
125 std::vector<std::string> files, dirs;
126 std::vector<std::string> expected_filepaths, expected_dirpaths;
128 for(
const std::string&
n : expected_filenames) {
129 expected_filepaths.push_back(
gamedata +
"/" +
path +
"/" +
n);
132 for(
const std::string&
n : expected_dirnames) {
133 expected_dirpaths.push_back(
gamedata +
"/" +
path +
"/" +
n);
139 get_files_in_dir(
path, &files, &dirs, name_mode::ENTIRE_FILE_PATH, filter_mode::NO_FILTER, reorder_mode::DO_REORDER);
141 BOOST_CHECK( files == expected_filepaths );
142 BOOST_CHECK( dirs == expected_dirpaths );
164 gamedata +
"/data/core/images/wesnoth-icon.png" );
167 gamedata +
"/data/core/music/silence.ogg" );
170 gamedata +
"/data/core/sounds/explosion.ogg" );
173 "data/core/images/wesnoth-icon.png" );
193 BOOST_CHECK_EQUAL(
get_wml_location(
".", std::string(
"")).value_or(
""),
"." );
195 BOOST_CHECK_EQUAL(
get_wml_location(
"~/").value_or(
""), userdata +
"/data/" );
198 BOOST_CHECK( !
get_wml_location(
"why_would_anyone_ever_name_a_file_like_this").has_value() );
239 BOOST_AUTO_TEST_SUITE_END()
A config object defines a single node in a WML file, with access to child nodes.
config & mandatory_child(config_key_type key, int n=0)
Returns the nth child with the given key, or throws an error if there is none.
Singleton class to manage game config file caching.
void add_define(const std::string &define)
Add a entry to preproc defines map.
static config_cache & instance()
Get reference to the singleton object.
void clear_defines()
Clear stored defines map to default values.
void get_config(const std::string &path, config &cfg, abstract_validator *validator=nullptr)
Gets a config object from given path.
A class grating read only view to a vector of config objects, viewed as one config with all children ...
static game_config_view wrap(const config &cfg)
Declarations for File-IO.
Standard logging facilities (interface).
bool is_bzip2_file(const std::string &filename)
Returns true if the file ends with '.bz2'.
bool is_relative(const std::string &path)
Returns whether the path seems to be relative.
bool is_root(const std::string &path)
Returns whether the path is the root of the file hierarchy.
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)
Get a list of all files and/or directories in a given directory.
std::string get_user_data_dir()
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_gzip_file(const std::string &filename)
Returns true if the file ends with '.gz'.
static bool file_exists(const bfs::path &fpath)
bool is_directory(const std::string &fname)
Returns true if the given file is a directory.
utils::optional< std::string > get_wml_location(const std::string &path, const utils::optional< std::string > ¤t_dir)
Returns a translated path to the actual file or directory, if it exists.
bool is_compressed_file(const std::string &filename)
utils::optional< 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, if it exists.
std::string directory_name(const std::string &file)
Returns the directory name of a file, with filename stripped.
utils::optional< 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, if it exists.
std::string nearest_extant_parent(const std::string &file)
Finds the nearest parent in existence for a file or directory.
bool looks_like_pbl(const std::string &file)
utils::optional< std::string > get_independent_binary_file_path(const std::string &type, const std::string &filename)
Returns an asset path to filename for binary path-independent use in saved games.
void load_config(const config &v)
The paths manager is responsible for recording the various paths that binary files may be located at.
BOOST_AUTO_TEST_SUITE(filesystem)
const std::string & gamedata
BOOST_AUTO_TEST_CASE(test_fs_game_path_reverse_engineering)
static map_location::direction n