From: Magnus Jacobsson Date: Fri, 2 Sep 2022 09:57:40 +0000 (+0200) Subject: tests: SVGAnalyzer: save a copy of the original SVG and give access to it X-Git-Tag: 6.0.1~10^2~14 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=45e37c1765fd3360498e296fdb27f7089c7634a6;p=graphviz tests: SVGAnalyzer: save a copy of the original SVG and give access to it This is needed to be able to verify the SVG re-creating capablility of the SVGAnalyzer. Upcoming commits will extend the SVG analyzer's ability to handle new SVG attributes and add new test cases verifying its ability to re-create correct SVG containing those attributes. This change will facilitate the creation of those tests and keep the code DRY. The copying is necessary since the original SVG is modified by the XML parser in destructive mode. See http://rapidxml.sourceforge.net/manual.html#namespacerapidxml_1destructive_non_destructive and we don't want to use the non-destructive mode since no entity reference translation is done then and we want to avoid having to do that ourselves. --- diff --git a/tests/svg_analyzer.cpp b/tests/svg_analyzer.cpp index 3e5db3edf..9f69376ba 100644 --- a/tests/svg_analyzer.cpp +++ b/tests/svg_analyzer.cpp @@ -11,7 +11,7 @@ #include SVGAnalyzer::SVGAnalyzer(char *text) - : m_svg(SVG::SVGElement(SVG::SVGElementType::Svg)) { + : m_original_svg(text), m_svg(SVG::SVGElement(SVG::SVGElementType::Svg)) { m_elements_in_process.push_back(&m_svg); SvgppContext context{this}; traverseDocumentWithSvgpp(context, text); @@ -259,6 +259,8 @@ SVGAnalyzer SVGAnalyzer::make_from_dot(const std::string &dot_source, return SVGAnalyzer{result.c_str()}; } +std::string_view SVGAnalyzer::original_svg() const { return m_original_svg; } + void SVGAnalyzer::set_transform(double a, double b, double c, double d, double e, double f) { current_element().attributes.transform = {a, b, c, d, e, f}; diff --git a/tests/svg_analyzer.h b/tests/svg_analyzer.h index 22f7e3be8..dfbf39be4 100644 --- a/tests/svg_analyzer.h +++ b/tests/svg_analyzer.h @@ -72,6 +72,8 @@ public: std::size_t num_rects() const { return m_num_rects; }; std::size_t num_texts() const { return m_num_texts; }; std::size_t num_titles() const { return m_num_titles; }; + /// Return a view of the original SVG + std::string_view original_svg() const; void set_graphviz_version(std::string_view version); void set_graphviz_build_date(std::string_view build_date); std::string svg_string(std::size_t indent_size = 2) const; @@ -111,6 +113,8 @@ private: std::size_t m_num_titles = 0; /// A list of Graphviz recreated graphs std::vector m_graphs; + /// The original SVG document + std::string m_original_svg; /// The top level SVG `svg` element corresponding to the Graphviz graph SVG::SVGElement m_svg; };