From 1a4b065b93c64c19e8f7050b0ccc47def7fa9115 Mon Sep 17 00:00:00 2001 From: Magnus Jacobsson Date: Sun, 24 Jul 2022 22:26:32 +0200 Subject: [PATCH] tests: SvgAnalyzer: add handling of 'text' elements --- tests/svg_analyzer.cpp | 5 +++++ tests/svg_analyzer.h | 3 +++ tests/svg_analyzer_interface.h | 1 + tests/svgpp_context.cpp | 4 ++++ tests/svgpp_context.h | 1 + tests/svgpp_document_traverser.cpp | 3 ++- tests/test_svg_analyzer.cpp | 6 ++++++ 7 files changed, 22 insertions(+), 1 deletion(-) diff --git a/tests/svg_analyzer.cpp b/tests/svg_analyzer.cpp index 552075c57..9a1e5a106 100644 --- a/tests/svg_analyzer.cpp +++ b/tests/svg_analyzer.cpp @@ -57,6 +57,11 @@ void SVGAnalyzer::on_enter_element_rect() { m_num_rects++; } +void SVGAnalyzer::on_enter_element_text() { + enter_element(SVG::SVGElementType::Text); + m_num_texts++; +} + void SVGAnalyzer::on_enter_element_title() { enter_element(SVG::SVGElementType::Title); m_num_titles++; diff --git a/tests/svg_analyzer.h b/tests/svg_analyzer.h index 4c779a6f6..31f9507df 100644 --- a/tests/svg_analyzer.h +++ b/tests/svg_analyzer.h @@ -23,6 +23,7 @@ public: void on_enter_element_polygon() override; void on_enter_element_polyline() override; void on_enter_element_rect() override; + void on_enter_element_text() override; void on_enter_element_title() override; void on_exit_element() override; std::size_t num_svgs() const { return m_num_svgs; }; @@ -34,6 +35,7 @@ public: std::size_t num_polygons() const { return m_num_polygons; }; std::size_t num_polylines() const { return m_num_polylines; }; 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; }; std::string svg_string(std::size_t indent_size = 2) const; @@ -58,6 +60,7 @@ private: std::size_t m_num_polygons = 0; std::size_t m_num_polylines = 0; std::size_t m_num_rects = 0; + std::size_t m_num_texts = 0; std::size_t m_num_titles = 0; /// The top level SVG `svg` element corresponding to the Graphviz graph SVG::SVGElement m_svg; diff --git a/tests/svg_analyzer_interface.h b/tests/svg_analyzer_interface.h index 53f40f52c..57d24ab74 100644 --- a/tests/svg_analyzer_interface.h +++ b/tests/svg_analyzer_interface.h @@ -21,6 +21,7 @@ public: virtual void on_enter_element_polygon() = 0; virtual void on_enter_element_polyline() = 0; virtual void on_enter_element_rect() = 0; + virtual void on_enter_element_text() = 0; virtual void on_enter_element_title() = 0; virtual void on_exit_element() = 0; }; diff --git a/tests/svgpp_context.cpp b/tests/svgpp_context.cpp index 9d13c607f..f3915e6f6 100644 --- a/tests/svgpp_context.cpp +++ b/tests/svgpp_context.cpp @@ -42,6 +42,10 @@ void SvgppContext::on_enter_element(svgpp::tag::element::rect) { m_svgAnalyzer->on_enter_element_rect(); } +void SvgppContext::on_enter_element(svgpp::tag::element::text) { + m_svgAnalyzer->on_enter_element_text(); +} + void SvgppContext::on_enter_element(svgpp::tag::element::title) { m_svgAnalyzer->on_enter_element_title(); } diff --git a/tests/svgpp_context.h b/tests/svgpp_context.h index 2d64156ce..b086ebce5 100644 --- a/tests/svgpp_context.h +++ b/tests/svgpp_context.h @@ -30,6 +30,7 @@ public: void on_enter_element(svgpp::tag::element::polygon e); void on_enter_element(svgpp::tag::element::polyline e); void on_enter_element(svgpp::tag::element::rect e); + void on_enter_element(svgpp::tag::element::text e); void on_enter_element(svgpp::tag::element::title e); void on_exit_element(); void path_move_to(double x, double y, svgpp::tag::coordinate::absolute); diff --git a/tests/svgpp_document_traverser.cpp b/tests/svgpp_document_traverser.cpp index 47fd50fe2..93f941f13 100644 --- a/tests/svgpp_document_traverser.cpp +++ b/tests/svgpp_document_traverser.cpp @@ -21,7 +21,8 @@ void traverseDocumentWithSvgpp(SvgppContext &context, char *text) { svgpp::tag::element::circle, svgpp::tag::element::ellipse, svgpp::tag::element::line, svgpp::tag::element::path, svgpp::tag::element::polygon, svgpp::tag::element::polyline, - svgpp::tag::element::rect, svgpp::tag::element::title>::type; + svgpp::tag::element::rect, svgpp::tag::element::text, + svgpp::tag::element::title>::type; svgpp::document_traversal< svgpp::processed_elements, diff --git a/tests/test_svg_analyzer.cpp b/tests/test_svg_analyzer.cpp index 20ce416c5..aba839a13 100644 --- a/tests/test_svg_analyzer.cpp +++ b/tests/test_svg_analyzer.cpp @@ -93,6 +93,8 @@ TEST_CASE( const std::size_t expected_num_rects = 0; const std::size_t expected_num_titles = expected_num_graphs + expected_num_nodes + expected_num_edges; + const std::size_t expected_num_texts = + shape == "point" ? 0 : expected_num_nodes; CHECK(svgAnalyzer.num_svgs() == expected_num_svgs); CHECK(svgAnalyzer.num_groups() == expected_num_groups); @@ -104,6 +106,7 @@ TEST_CASE( CHECK(svgAnalyzer.num_polylines() == expected_num_polylines); CHECK(svgAnalyzer.num_rects() == expected_num_rects); CHECK(svgAnalyzer.num_titles() == expected_num_titles); + CHECK(svgAnalyzer.num_texts() == expected_num_texts); const auto indent_size = 0; auto recreated_svg = svgAnalyzer.svg_string(indent_size); @@ -132,6 +135,9 @@ TEST_CASE( CHECK(recreated_svg.find("") != std::string::npos); CHECK(recreated_svg.find("") != std::string::npos); CHECK(recreated_svg.find("") != std::string::npos); + if (shape != "point") { + CHECK(recreated_svg.find("<text/>") != std::string::npos); + } CHECK(recreated_svg.find("<polygon/>") != std::string::npos); CHECK(recreated_svg.find("<path/>") != std::string::npos); } -- 2.40.0