diff options
author | Dan Goodliffe <dan@randomdan.homeip.net> | 2023-04-07 18:21:43 +0100 |
---|---|---|
committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2023-04-07 18:21:43 +0100 |
commit | 68a6e87a7a0166031208da90b088791b96e7a0b0 (patch) | |
tree | 4c09eb4886fe133cd42b18011a358dd28abc8d14 | |
parent | Rename Popular to more generic name for reuse (diff) | |
download | gentoobrowse-68a6e87a7a0166031208da90b088791b96e7a0b0.tar.bz2 gentoobrowse-68a6e87a7a0166031208da90b088791b96e7a0b0.tar.xz gentoobrowse-68a6e87a7a0166031208da90b088791b96e7a0b0.zip |
Dump XML documents for analysis, not just HTML docs
-rw-r--r-- | gentoobrowse/src/test.cpp | 54 |
1 files changed, 31 insertions, 23 deletions
diff --git a/gentoobrowse/src/test.cpp b/gentoobrowse/src/test.cpp index 01ffa76..a534cc6 100644 --- a/gentoobrowse/src/test.cpp +++ b/gentoobrowse/src/test.cpp @@ -37,6 +37,13 @@ public: hdr["Accept-Encoding"] = "gzip, deflate, sdch"; hdr["Accept-Language"] = "en-GB,en;q=0.8"; } + auto + getOutputPath(const char * name, const char * ext) + { + auto realname + = std::unique_ptr<char, decltype(&std::free)> {abi::__cxa_demangle(name, 0, 0, nullptr), std::free}; + return (binDir / realname.get()).replace_extension(ext); + } }; template<typename T = void> class ChromiumRequestT : public ChromiumRequest { using ChromiumRequest::ChromiumRequest; @@ -55,11 +62,6 @@ public: standardAssertions(const char * name) override { BOOST_TEST_CONTEXT(__FUNCTION__ << " : " << name) { - auto realname - = std::unique_ptr<char, decltype(&std::free)> {abi::__cxa_demangle(name, 0, 0, nullptr), std::free}; - const auto outputPath {(binDir / realname.get()).replace_extension(".html")}; - std::ofstream {outputPath} << (output.str()); - auto h = getResponseHeaders(); BOOST_REQUIRE_EQUAL(h["Status"], "200 OK"); BOOST_REQUIRE_EQUAL(h["Content-Type"], "text/html"); @@ -71,7 +73,7 @@ public: BOOST_REQUIRE_EQUAL(1, tidyOptSetInt(tdoc, TidyWrapLen, 0)); BOOST_REQUIRE_EQUAL(0, tidyParseSource(tdoc, &tis)); BOOST_CHECK_EQUAL(0, tidyCleanAndRepair(tdoc)); - BOOST_CHECK_EQUAL(0, tidySaveFile(tdoc, outputPath.c_str())); + BOOST_CHECK_EQUAL(0, tidySaveFile(tdoc, getOutputPath(name, ".html").c_str())); BOOST_CHECK_EQUAL(0, tidyRunDiagnostics(tdoc)); tidyRelease(tdoc); } @@ -95,24 +97,28 @@ public: using ChromiumRequestT::ChromiumRequestT; virtual std::unique_ptr<xmlpp::DomParser> - standardAssertions(const char *) override + standardAssertions(const char * name) override { - auto h = getResponseHeaders(); - BOOST_REQUIRE_EQUAL(h["Status"], "200 OK"); - BOOST_REQUIRE_EQUAL(h["Content-Type"], "application/xml"); - BOOST_TEST_INFO(this->output.view()); - BOOST_REQUIRE_NE(this->output.view().find("<?xml version"), std::string_view::npos); auto p = std::make_unique<xmlpp::DomParser>(); - p->parse_stream(this->output); + BOOST_TEST_CONTEXT(__FUNCTION__ << " : " << name) { + auto h = getResponseHeaders(); + BOOST_REQUIRE_EQUAL(h["Status"], "200 OK"); + BOOST_REQUIRE_EQUAL(h["Content-Type"], "application/xml"); + BOOST_REQUIRE_NE(this->output.view().find("<?xml version"), std::string_view::npos); + p->parse_stream(this->output); + p->get_document()->write_to_file_formatted(getOutputPath(name, ".xml")); + } return p; } void xsdAssertions(const char * name, const std::filesystem::path & xsd) { - auto doc = standardAssertions(name); - xmlpp::XsdValidator validator {xsd}; - validator.validate(doc->get_document()); + BOOST_TEST_CONTEXT(__FUNCTION__ << " : " << name) { + auto doc = standardAssertions(name); + xmlpp::XsdValidator validator {xsd}; + validator.validate(doc->get_document()); + } } }; @@ -132,15 +138,17 @@ public: } virtual std::unique_ptr<xmlpp::DomParser> - standardAssertions(const char *) override + standardAssertions(const char * name) override { - auto h = getResponseHeaders(); - BOOST_REQUIRE_EQUAL(h["Status"], "200 OK"); - BOOST_REQUIRE_EQUAL(h["Content-Type"], "application/atom+xml"); - BOOST_TEST_INFO(this->output.view()); - BOOST_REQUIRE_NE(this->output.view().find("<?xml version"), std::string_view::npos); auto p = std::make_unique<xmlpp::DomParser>(); - p->parse_stream(this->output); + BOOST_TEST_CONTEXT(__FUNCTION__ << " : " << name) { + auto h = getResponseHeaders(); + BOOST_REQUIRE_EQUAL(h["Status"], "200 OK"); + BOOST_REQUIRE_EQUAL(h["Content-Type"], "application/atom+xml"); + BOOST_REQUIRE_NE(this->output.view().find("<?xml version"), std::string_view::npos); + p->parse_stream(this->output); + p->get_document()->write_to_file_formatted(getOutputPath(name, ".xml")); + } return p; } }; |