From 0123317f016df001bcf5cb8a8d0046c92fe70924 Mon Sep 17 00:00:00 2001 From: Will Toohey Date: Mon, 30 Jun 2025 19:44:24 +1000 Subject: [PATCH] tests: xml tests, and a discovered regression --- src/avs.cpp | 25 +------- src/avs.h | 41 +++++++++++++ src/avs_standalone.cpp | 13 ++++- src/tests.cpp | 54 +++++++++++++----- .../data2/graphic/psd_result.ifs | Bin 0 -> 1124 bytes .../psd_result_ifs/afp/afplist.merged.xml | 6 ++ 6 files changed, 99 insertions(+), 40 deletions(-) create mode 100644 testcases_data_mods/bst_regression/data2/graphic/psd_result.ifs create mode 100644 testcases_data_mods/bst_regression/data2/graphic/psd_result_ifs/afp/afplist.merged.xml diff --git a/src/avs.cpp b/src/avs.cpp index 4c29573..70cf299 100644 --- a/src/avs.cpp +++ b/src/avs.cpp @@ -394,30 +394,7 @@ bool rapidxml_from_avs_filepath( return false; } - // if it's not binary, don't even bother parsing with avs - char* xml = NULL; - if (is_binary_prop(f)) { - auto prop = prop_from_file_handle(f); - if (!prop) - return false; - - xml = prop_to_xml_string(prop, doc_to_allocate_with); - prop_free(prop); - } - else { - xml = avs_file_to_string(f, doc_to_allocate_with); - } - avs_fs_close(f); - - try { - // parse_declaration_node: to get the header - doc.parse(xml); - } catch (const rapidxml::parse_error& e) { - log_warning("Couldn't parse xml (%s byte %d)", e.what(), (int)(e.where() - xml)); - return false; - } - - return true; + return rapidxml_from_avs_file(f, doc, doc_to_allocate_with); } // the given property MUST have been created with an 8-byte aligned memory diff --git a/src/avs.h b/src/avs.h index fb5737c..7138441 100644 --- a/src/avs.h +++ b/src/avs.h @@ -6,6 +6,8 @@ #include using std::string; +#include "log.hpp" + #include "3rd_party/rapidxml.hpp" /* @@ -238,3 +240,42 @@ static inline uint16_t avs_open_mode_read() { return 0; } } + +// just used by rapidxml_from_avs_file + +bool is_binary_prop(AVS_FILE f); +char* prop_to_xml_string(property_t prop, rapidxml::xml_document<>& allocator); + +// parse_declaration_node: to get the header +template +bool rapidxml_from_avs_file( + AVS_FILE f, + rapidxml::xml_document<>& doc, + rapidxml::xml_document<>& doc_to_allocate_with +) { + // if it's not binary, don't even bother parsing with avs + char* xml = NULL; + if (is_binary_prop(f)) { + auto prop = prop_from_file_handle(f); + if (!prop) + return false; + + xml = prop_to_xml_string(prop, doc_to_allocate_with); + prop_free(prop); + } + else { + xml = avs_file_to_string(f, doc_to_allocate_with); + } + avs_fs_close(f); + + try { + doc.parse(xml); + } catch (const rapidxml::parse_error& e) { + log_warning("Couldn't parse xml (%s byte %d)", e.what(), (int)(e.where() - xml)); + auto f = fopen("debug.xml", "wb"); + fwrite(xml, strlen(xml), 1, f); + return false; + } + + return true; +} diff --git a/src/avs_standalone.cpp b/src/avs_standalone.cpp index 8c53f20..a9e122b 100644 --- a/src/avs_standalone.cpp +++ b/src/avs_standalone.cpp @@ -134,7 +134,10 @@ static const char *boot_cfg = R"( - misc + + misc + 0 + 0 @@ -154,10 +157,14 @@ LONG WINAPI exc_handler(_EXCEPTION_POINTERS *ExceptionInfo) { case DBG_PRINTEXCEPTION_C: break; default: - fprintf(stderr, "Unhandled exception %lX\n", ExceptionInfo->ExceptionRecord->ExceptionCode); + log_warning("Unhandled exception code 0x%lX at %p\n", + ExceptionInfo->ExceptionRecord->ExceptionCode, + ExceptionInfo->ExceptionRecord->ExceptionAddress + ); break; } return EXCEPTION_CONTINUE_SEARCH; } -} + +} // namespace avs_standalone diff --git a/src/tests.cpp b/src/tests.cpp index 5d7c660..6b8c5e0 100644 --- a/src/tests.cpp +++ b/src/tests.cpp @@ -1,3 +1,4 @@ +#include #include #include @@ -7,6 +8,8 @@ #include "avs_standalone.hpp" #include "modpath_handler.h" +#include "3rd_party/rapidxml_print.hpp" + using ::testing::Contains; using ::testing::Optional; @@ -156,43 +159,68 @@ TEST(Xml, MergingWorks) { 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(xml_text); + bool res = rapidxml_from_avs_file(f, xml_doc, xml_doc); + ASSERT_TRUE(res); auto node = xml_doc.first_node(); - ASSERT_TRUE(node); + ASSERT_NE(node, nullptr); EXPECT_STREQ(node->name(), "afplist"); node = node->first_node(); - ASSERT_TRUE(node); + ASSERT_NE(node, nullptr); EXPECT_STREQ(node->name(), "afp"); auto attr = node->first_attribute("name"); - ASSERT_TRUE(attr); + ASSERT_NE(attr, nullptr); EXPECT_STREQ(attr->value(), "hare"); auto geo = node->first_node("geo"); - ASSERT_TRUE(geo); + ASSERT_NE(geo, nullptr); EXPECT_STREQ(geo->value(), "5 10 15"); node = node->next_sibling(); - ASSERT_TRUE(node); + ASSERT_NE(node, nullptr); EXPECT_STREQ(node->name(), "afp"); attr = node->first_attribute("name"); - ASSERT_TRUE(attr); + ASSERT_NE(attr, nullptr); EXPECT_STREQ(attr->value(), "hare2"); geo = node->first_node("geo"); - ASSERT_TRUE(geo); + ASSERT_NE(geo, nullptr); EXPECT_STREQ(geo->value(), "20 25 30"); node = node->next_sibling(); - ASSERT_FALSE(node); + ASSERT_EQ(node, nullptr); +} + +TEST(Regression, BeatStreamAfpXml) { + // M:mounting /data2/graphic/psd_result.ifs to /afp22/data2/graphic/psd_result.ifs with type imagefs and args (null) + int mnt = hook_avs_fs_mount("/afp22/data2/graphic/psd_result.ifs", "/data2/graphic/psd_result.ifs", "imagefs", nullptr); + ASSERT_GT(mnt, 0); + + auto f = hook_avs_fs_open("/afp22/data2/graphic/psd_result.ifs/afp/afplist.xml", avs_open_mode_read(), 420); + ASSERT_GT(f, 0); + rapidxml::xml_document<> xml_doc; + bool res = rapidxml_from_avs_file(f, xml_doc, xml_doc); + ASSERT_TRUE(res); + + auto node = xml_doc.first_node(); + ASSERT_NE(node, nullptr); + EXPECT_STREQ(node->name(), "afplist"); + + node = node->last_node(); + ASSERT_NE(node, nullptr); + EXPECT_STREQ(node->name(), "afp"); + + auto attr = node->first_attribute("name"); + ASSERT_NE(attr, nullptr); + EXPECT_STREQ(attr->value(), "hare"); + + auto geo = node->first_node("geo"); + ASSERT_NE(geo, nullptr); + EXPECT_STREQ(geo->value(), "5 10 15"); } diff --git a/testcases_data_mods/bst_regression/data2/graphic/psd_result.ifs b/testcases_data_mods/bst_regression/data2/graphic/psd_result.ifs new file mode 100644 index 0000000000000000000000000000000000000000..44ea5ade68a88f796b096207cc79ca756751ce6c GIT binary patch literal 1124 zcmc~<+uzB+{QplzQj7ru14{q{1H+bzg5@S^b{*##*S}QyWG&3Kz^S1gDDJ|@x?5ZO z0VCVAH?J=Ra50~n={kFW?*IDV&Dg}dBNiG#ihBqsYPHBRC%t9%)G?-6bsP0a*}B8zbs zTqTLwi5ZE-8CcxQT9RJ`@gb@|SQ9goU~c6Ax`%^-lYtND3f4534G{Gl47?CW!$?2( z05=#LL__nh1tU8+GalgPTzAln4a&dJOxtpExF04=sK APXGV_ literal 0 HcmV?d00001 diff --git a/testcases_data_mods/bst_regression/data2/graphic/psd_result_ifs/afp/afplist.merged.xml b/testcases_data_mods/bst_regression/data2/graphic/psd_result_ifs/afp/afplist.merged.xml new file mode 100644 index 0000000..8b18da7 --- /dev/null +++ b/testcases_data_mods/bst_regression/data2/graphic/psd_result_ifs/afp/afplist.merged.xml @@ -0,0 +1,6 @@ + + + + 5 10 15 + +