16 #include <boost/test/unit_test.hpp>
30 for(
typename T::const_iterator k = v.begin(); k != v.end(); ++k) {
44 const std::string maincfg =
"_main.cfg";
48 const std::size_t strip_len = (maincfg +
"/data/").length();
49 BOOST_REQUIRE(gamedata_rev.length() > strip_len);
50 gamedata_rev.resize(gamedata_rev.length() - strip_len);
52 BOOST_CHECK_EQUAL( gamedata_rev,
gamedata );
60 BOOST_CHECK(
is_root(
"/../.././") );
61 BOOST_CHECK(
is_root(
"/.././../.") );
89 BOOST_CHECK_EQUAL(
base_name(
"foo/bar/baz.cfg"),
"baz.cfg" );
92 BOOST_CHECK_EQUAL(
base_name(
"foo/bar"),
"bar" );
110 const std::string
path =
"data/test/test/filesystem/enum";
112 const std::vector<std::string> expected_filenames {
121 const std::vector<std::string> expected_dirnames {
126 std::vector<std::string> files, dirs;
127 std::vector<std::string> expected_filepaths, expected_dirpaths;
129 for(
const std::string&
n : expected_filenames) {
130 expected_filepaths.push_back(
gamedata +
"/" +
path +
"/" +
n);
133 for(
const std::string&
n : expected_dirnames) {
134 expected_dirpaths.push_back(
gamedata +
"/" +
path +
"/" +
n);
140 get_files_in_dir(
path, &files, &dirs, name_mode::ENTIRE_FILE_PATH, filter_mode::NO_FILTER, reorder_mode::DO_REORDER);
142 BOOST_CHECK( files == expected_filepaths );
143 BOOST_CHECK( dirs == expected_dirpaths );
165 gamedata +
"/data/core/images/wesnoth-icon.png" );
168 gamedata +
"/data/core/music/silence.ogg" );
171 gamedata +
"/data/core/sounds/explosion.ogg" );
174 "data/core/images/wesnoth-icon.png" );
186 std::string
path =
gamedata +
"/data/core/images/wesnoth-icon.png";
188 BOOST_CHECK( outpath.has_value() );
189 BOOST_CHECK_EQUAL( outpath.value(),
"wesnoth-icon.png" );
191 path =
gamedata +
"/images/icons/action/modern/language_25-active.png";
193 BOOST_CHECK( outpath.has_value() );
194 BOOST_CHECK_EQUAL( outpath.value(),
"icons/action/modern/language_25-active.png" );
196 path =
gamedata +
"/data/core/sounds/ambient/campfire.ogg";
198 BOOST_CHECK( outpath.has_value() );
199 BOOST_CHECK_EQUAL( outpath.value(),
"ambient/campfire.ogg" );
201 path =
gamedata +
"/images/this/path/doesn't/exist/campfire.ogg";
213 BOOST_CHECK_EQUAL(
get_wml_location(
".", std::string(
"")).value_or(
""),
"." );
215 BOOST_CHECK_EQUAL(
get_wml_location(
"~/").value_or(
""), userdata +
"/data/" );
218 BOOST_CHECK( !
get_wml_location(
"why_would_anyone_ever_name_a_file_like_this").has_value() );
259 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.
utils::optional< std::string > to_asset_path(const std::string &path, const std::string &addon_id, const std::string &asset_type)
Helper function to convert absolute path to wesnoth relative path.
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