mirror of
https://github.com/mon/ifs_layeredfs.git
synced 2026-03-21 17:34:09 -05:00
Add some merged XML tests
This commit is contained in:
parent
de14670157
commit
a9028465af
1
.gitignore
vendored
1
.gitignore
vendored
|
|
@ -4,3 +4,4 @@ build64/
|
|||
dist/
|
||||
subprojects/googletest*
|
||||
subprojects/packagecache
|
||||
testcases_data_mods/_cache/
|
||||
|
|
|
|||
|
|
@ -220,6 +220,7 @@ bool rapidxml_from_avs_filepath(
|
|||
rapidxml::xml_document<>& doc,
|
||||
rapidxml::xml_document<>& doc_to_allocate_with
|
||||
);
|
||||
char* avs_file_to_string(AVS_FILE f, rapidxml::xml_document<>& allocator);
|
||||
std::vector<uint8_t> avs_file_to_vec(AVS_FILE f);
|
||||
bool init_avs(void);
|
||||
unsigned char* lz_compress(unsigned char* input, size_t length, size_t *compressed_length);
|
||||
|
|
|
|||
|
|
@ -376,8 +376,8 @@ AVS_FILE hook_avs_fs_open(const char* name, uint16_t mode, int flags) {
|
|||
if(name == NULL || inside_pkfs_hook)
|
||||
return avs_fs_open(name, mode, flags);
|
||||
log_verbose("opening %s mode %d flags %d", name, mode, flags);
|
||||
// only touch reads - new AVS has bitflags (R=1,W=2), old AVS has enum (R=0,W=1,RW=2)
|
||||
if ((avs_loaded_version >= 1400 && mode != 1) || (avs_loaded_version < 1400 && mode != 0)) {
|
||||
// only touch reads
|
||||
if (mode != avs_open_mode_read()) {
|
||||
return avs_fs_open(name, mode, flags);
|
||||
}
|
||||
string path = name;
|
||||
|
|
|
|||
|
|
@ -584,13 +584,16 @@ void merge_xmls(HookFile &file) {
|
|||
auto cache_hasher = CacheHasher(out_hashed);
|
||||
|
||||
cache_hasher.add(starting); // don't forget to take the input into account
|
||||
log_info("Merging into %s", starting.c_str());
|
||||
for (auto &path : to_merge) {
|
||||
log_info(" %s", path.c_str());
|
||||
cache_hasher.add(path);
|
||||
}
|
||||
cache_hasher.finish();
|
||||
|
||||
// no need to merge - timestamps all up to date, dll not newer, files haven't been deleted
|
||||
if(cache_hasher.matches()) {
|
||||
log_info("Merged XML up to date");
|
||||
file.mod_path = out;
|
||||
return;
|
||||
}
|
||||
|
|
@ -601,9 +604,7 @@ void merge_xmls(HookFile &file) {
|
|||
return;
|
||||
}
|
||||
|
||||
log_info("Merging into %s", starting.c_str());
|
||||
for (auto &path : to_merge) {
|
||||
log_info(" %s", path.c_str());
|
||||
rapidxml::xml_document<> rapid_to_merge;
|
||||
auto merge_load_result = rapidxml_from_avs_filepath(path, rapid_to_merge, merged_xml);
|
||||
if (!merge_load_result) {
|
||||
|
|
|
|||
|
|
@ -81,7 +81,10 @@ void cache_mods(void) {
|
|||
static vector<string> game_folders;
|
||||
|
||||
void init_modpath_handler(void) {
|
||||
log_verbose("Top level folders:");
|
||||
for (auto folder : folders_in_folder(".")) {
|
||||
log_verbose(" %s", folder.c_str());
|
||||
|
||||
// data is the normal case we transparently handle
|
||||
if (!strcasecmp(folder.c_str(), "data")) {
|
||||
continue;
|
||||
|
|
@ -91,6 +94,10 @@ void init_modpath_handler(void) {
|
|||
}
|
||||
}
|
||||
|
||||
void modpath_debug_add_folder(const string &folder) {
|
||||
game_folders.push_back(folder + "/");
|
||||
}
|
||||
|
||||
optional<string> normalise_path(const string &_path) {
|
||||
auto path = _path;
|
||||
ramfs_demangler_demangle_if_possible(path);
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ using std::string;
|
|||
using std::vector;
|
||||
|
||||
void init_modpath_handler(void);
|
||||
void modpath_debug_add_folder(const string &folder);
|
||||
void cache_mods(void);
|
||||
vector<string> available_mods();
|
||||
// mutates source string to be all lowercase
|
||||
|
|
|
|||
|
|
@ -149,3 +149,50 @@ TEST(ImageFs, MD5DemanglingWorks) {
|
|||
|
||||
avs_fs_umount_by_desc(desc);
|
||||
}
|
||||
|
||||
TEST(Xml, MergingWorks) {
|
||||
modpath_debug_add_folder("data2"); // also test data2 handling for good measure
|
||||
auto f = hook_avs_fs_open("data2/subfolder/base.xml", avs_open_mode_read(), 420);
|
||||
ASSERT_GT(f, 0);
|
||||
|
||||
rapidxml::xml_document<> xml_doc;
|
||||
auto xml_text = avs_file_to_string(f, xml_doc);
|
||||
|
||||
avs_fs_close(f);
|
||||
|
||||
xml_doc.parse<rapidxml::parse_no_utf8>(xml_text);
|
||||
|
||||
auto node = xml_doc.first_node();
|
||||
ASSERT_TRUE(node);
|
||||
EXPECT_STREQ(node->name(), "afplist");
|
||||
|
||||
|
||||
node = node->first_node();
|
||||
ASSERT_TRUE(node);
|
||||
EXPECT_STREQ(node->name(), "afp");
|
||||
|
||||
auto attr = node->first_attribute("name");
|
||||
ASSERT_TRUE(attr);
|
||||
EXPECT_STREQ(attr->value(), "hare");
|
||||
|
||||
auto geo = node->first_node("geo");
|
||||
ASSERT_TRUE(geo);
|
||||
EXPECT_STREQ(geo->value(), "5 10 15");
|
||||
|
||||
|
||||
node = node->next_sibling();
|
||||
ASSERT_TRUE(node);
|
||||
EXPECT_STREQ(node->name(), "afp");
|
||||
|
||||
attr = node->first_attribute("name");
|
||||
ASSERT_TRUE(attr);
|
||||
EXPECT_STREQ(attr->value(), "hare2");
|
||||
|
||||
geo = node->first_node("geo");
|
||||
ASSERT_TRUE(geo);
|
||||
EXPECT_STREQ(geo->value(), "20 25 30");
|
||||
|
||||
|
||||
node = node->next_sibling();
|
||||
ASSERT_FALSE(node);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,6 @@
|
|||
<?xml version='1.0' encoding='UTF-8'?>
|
||||
<afplist>
|
||||
<afp name="hare2">
|
||||
<geo __type="u16" __count="3">20 25 30</geo>
|
||||
</afp>
|
||||
</afplist>
|
||||
6
testcases_data_mods/xml_merge/data2/subfolder/base.xml
Normal file
6
testcases_data_mods/xml_merge/data2/subfolder/base.xml
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
<?xml version='1.0' encoding='UTF-8'?>
|
||||
<afplist>
|
||||
<afp name="hare">
|
||||
<geo __type="u16" __count="3">5 10 15</geo>
|
||||
</afp>
|
||||
</afplist>
|
||||
Loading…
Reference in New Issue
Block a user