From: Magnus Jacobsson Date: Thu, 28 Jul 2022 08:43:07 +0000 (+0200) Subject: tests: SvgAnalyzer: add handling of the 'x' and 'y' attributes X-Git-Tag: 5.0.1~7^2~4 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=3b6a5c2d784b4de4b811a4fc183a4647277b44b7;p=graphviz tests: SvgAnalyzer: add handling of the 'x' and 'y' attributes --- diff --git a/tests/svg_analyzer.cpp b/tests/svg_analyzer.cpp index b691f5128..8fbed7779 100644 --- a/tests/svg_analyzer.cpp +++ b/tests/svg_analyzer.cpp @@ -171,6 +171,10 @@ void SVGAnalyzer::set_width(double width) { current_element().attributes.width = width; } +void SVGAnalyzer::set_x(double x) { current_element().attributes.x = x; } + +void SVGAnalyzer::set_y(double y) { current_element().attributes.y = y; } + 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 586783e11..a83e7081a 100644 --- a/tests/svg_analyzer.h +++ b/tests/svg_analyzer.h @@ -43,6 +43,8 @@ public: double f) override; void set_viewBox(double x, double y, double width, double height) override; void set_width(double width) override; + void set_x(double x) override; + void set_y(double y) override; std::size_t num_svgs() const { return m_num_svgs; }; std::size_t num_groups() const { return m_num_groups; }; std::size_t num_circles() const { return m_num_circles; }; diff --git a/tests/svg_analyzer_interface.h b/tests/svg_analyzer_interface.h index ceba1910c..2df23e0d7 100644 --- a/tests/svg_analyzer_interface.h +++ b/tests/svg_analyzer_interface.h @@ -42,4 +42,6 @@ public: double f) = 0; virtual void set_viewBox(double x, double y, double width, double height) = 0; virtual void set_width(double width) = 0; + virtual void set_x(double x) = 0; + virtual void set_y(double y) = 0; }; diff --git a/tests/svg_element.cpp b/tests/svg_element.cpp index b6326adea..85d980208 100644 --- a/tests/svg_element.cpp +++ b/tests/svg_element.cpp @@ -182,7 +182,8 @@ void SVG::SVGElement::to_string_impl(std::string &output, break; case SVG::SVGElementType::Text: attributes_str += - fmt::format(R"(text-anchor="{}")", attributes.text_anchor); + fmt::format(R"(text-anchor="{}" x="{}" y="{}")", attributes.text_anchor, + attributes.x, attributes.y); break; case SVG::SVGElementType::Title: // Graphviz doesn't generate attributes on 'title' elements diff --git a/tests/svg_element.h b/tests/svg_element.h index ad5091431..e30b8fbe9 100644 --- a/tests/svg_element.h +++ b/tests/svg_element.h @@ -60,6 +60,8 @@ struct SVGAttributes { std::optional transform; SVGRect viewBox; double width; + double x; + double y; }; /** diff --git a/tests/svgpp_context.cpp b/tests/svgpp_context.cpp index 1423505c7..92d825fef 100644 --- a/tests/svgpp_context.cpp +++ b/tests/svgpp_context.cpp @@ -198,14 +198,28 @@ void SvgppContext::set(svgpp::tag::attribute::y2 a, const double v) { (void)v; } -void SvgppContext::set(svgpp::tag::attribute::x a, const double v) { - (void)a; - (void)v; +void SvgppContext::set(svgpp::tag::attribute::x, const double v) { + m_svgAnalyzer->set_x(v); } -void SvgppContext::set(svgpp::tag::attribute::y a, const double v) { - (void)a; - (void)v; +void SvgppContext::set(svgpp::tag::attribute::x, const NumbersRange &range) { + if (boost::size(range) != 1) { + throw std::runtime_error{ + "Multiple value list for the 'x' attribute is not yet implemented"}; + } + m_svgAnalyzer->set_x(*range.begin()); +} + +void SvgppContext::set(svgpp::tag::attribute::y, const double v) { + m_svgAnalyzer->set_y(v); +} + +void SvgppContext::set(svgpp::tag::attribute::y, const NumbersRange &range) { + if (boost::size(range) != 1) { + throw std::runtime_error{ + "Multiple value list for the 'y' attribute is not yet implemented"}; + } + m_svgAnalyzer->set_y(*range.begin()); } void SvgppContext::set(svgpp::tag::attribute::width, const double v) { diff --git a/tests/svgpp_context.h b/tests/svgpp_context.h index 06b00377d..1ec8ed58a 100644 --- a/tests/svgpp_context.h +++ b/tests/svgpp_context.h @@ -162,8 +162,13 @@ public: const std::pair &, std::ptrdiff_t> PointsRange; void set(svgpp::tag::attribute::points points, const PointsRange &range); - void set(svgpp::tag::attribute::x a, double v); - void set(svgpp::tag::attribute::y y, double v); + void set(svgpp::tag::attribute::x, double v); + typedef boost::any_range + NumbersRange; + void set(svgpp::tag::attribute::x, const NumbersRange &range); + void set(svgpp::tag::attribute::y, double v); + void set(svgpp::tag::attribute::y, const NumbersRange &range); void set(svgpp::tag::attribute::width width, double v); void set(svgpp::tag::attribute::height height, double v); void set(svgpp::tag::attribute::id a, boost::iterator_range v); diff --git a/tests/svgpp_document_traverser.cpp b/tests/svgpp_document_traverser.cpp index 45148e019..bd1a12647 100644 --- a/tests/svgpp_document_traverser.cpp +++ b/tests/svgpp_document_traverser.cpp @@ -39,7 +39,9 @@ void traverseDocumentWithSvgpp(SvgppContext &context, char *text) { svgpp::tag::attribute::text_anchor, // svgpp::tag::attribute::transform, // svgpp::tag::attribute::viewBox, // - svgpp::tag::attribute::width // + svgpp::tag::attribute::width, // + svgpp::tag::attribute::x, // + svgpp::tag::attribute::y // >::type; svgpp::document_traversal< diff --git a/tests/test_svg_analyzer.cpp b/tests/test_svg_analyzer.cpp index d9efa0df7..46ae43358 100644 --- a/tests/test_svg_analyzer.cpp +++ b/tests/test_svg_analyzer.cpp @@ -129,7 +129,8 @@ TEST_CASE( // yet handle all attributes on the 'path' element break; } - if (recreated_svg_lines[i] == "a") { + if (recreated_svg_lines[i].starts_with( + "a") != std::string::npos); CHECK(recreated_svg.find("b") != std::string::npos); if (shape != "point") { - CHECK(recreated_svg.find("a") != - std::string::npos); - CHECK(recreated_svg.find("b") != + CHECK(recreated_svg.find("") != std::string::npos); + CHECK(recreated_svg.find("b") != std::string::npos); } CHECK(recreated_svg.find("") != std::string::npos);