]> granicus.if.org Git - graphviz/commitdiff
tests: SvgAnalyzer: add Graphviz version and build date to the generated SVG string
authorMagnus Jacobsson <Magnus.Jacobsson@berotec.se>
Mon, 25 Jul 2022 14:00:31 +0000 (16:00 +0200)
committerMagnus Jacobsson <Magnus.Jacobsson@berotec.se>
Tue, 16 Aug 2022 10:21:45 +0000 (12:21 +0200)
tests/svg_analyzer.cpp
tests/svg_analyzer.h
tests/svg_element.cpp
tests/svg_element.h
tests/test_svg_analyzer.cpp

index 6e18fc91d7b1d5b86b9c5ba18390e7cc24d3ab08..5224d7a938478408cb5c18acf807f99db1ae7cac 100644 (file)
@@ -93,6 +93,14 @@ void SVGAnalyzer::set_text(std::string_view text) {
   element.text = text;
 }
 
+void SVGAnalyzer::set_graphviz_version(std::string_view version) {
+  m_svg.graphviz_version = version;
+}
+
+void SVGAnalyzer::set_graphviz_build_date(std::string_view build_date) {
+  m_svg.graphviz_build_date = build_date;
+}
+
 std::string SVGAnalyzer::svg_string(std::size_t indent_size) const {
   std::string output{};
   output += m_svg.to_string(indent_size);
index 208a57b2feeaea283314c0c7c31f5d8885ff4ade..be537585fd9de0c3c7baeede770c542dc26ecb6d 100644 (file)
@@ -39,6 +39,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; };
+  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;
 
 private:
index df0517f00dc4a5b9ff3d36c1f7453974ad1fdf5b..a0d32efa5a9d1cd64e635f8ce463c97ff5e90aa3 100644 (file)
@@ -36,6 +36,9 @@ std::string SVG::SVGElement::to_string(std::size_t indent_size = 2) const {
             "\n";
   output += R"( "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">)"
             "\n";
+  output += fmt::format("<!-- Generated by graphviz version {} "
+                        "({})\n -->\n",
+                        graphviz_version, graphviz_build_date);
   to_string_impl(output, indent_size, 0);
   return output;
 }
index 7ab2210bba5c373c48b6b986bb56ecc14fbcb04f..42e15cb58f1bd8f6838cdf34a1a0f29f705758ca 100644 (file)
@@ -33,7 +33,11 @@ public:
 
   std::string to_string(std::size_t indent_size) const;
 
+  /// The Graphviz build date
+  std::string graphviz_build_date;
   std::vector<SVGElement> children;
+  /// The Graphviz release version
+  std::string graphviz_version;
   /// The SVG element text node contents. Not to be confused with an SVG `text`
   /// element
   std::string text;
index 6e5f57bab2c2d5a799731a22b8a477d7708c0790..f052a55a809a08fae0a8b56a07753624551b664e 100644 (file)
@@ -25,13 +25,17 @@ TEST_CASE(
   auto g = CGraph::AGraph{dot};
 
   const auto demand_loading = false;
-  auto gvc = GVC::GVContext(lt_preloaded_symbols, demand_loading);
+  auto gvc = GVC::GVContext{lt_preloaded_symbols, demand_loading};
+  const auto graphviz_version = gvc.version();
+  const auto graphviz_build_date = gvc.buildDate();
 
   const auto layout = GVC::GVLayout(std::move(gvc), std::move(g), "dot");
 
   const auto result = layout.render("svg");
   const std::string original_svg{result.string_view()};
   SVGAnalyzer svgAnalyzer{result.c_str()};
+  svgAnalyzer.set_graphviz_version(graphviz_version);
+  svgAnalyzer.set_graphviz_build_date(graphviz_build_date);
 
   const std::size_t expected_num_graphs = 1;
   const std::size_t expected_num_nodes = 2;
@@ -120,9 +124,8 @@ TEST_CASE(
     for (std::size_t i = 0; i < original_svg_lines.size(); i++) {
       REQUIRE(i < recreated_svg_lines.size());
       if (recreated_svg_lines[i] == "<svg>") {
-        // stop comparison here since we do not yet handle the Graphviz version
-        // and build date comment and the graph title comment that comes before
-        // the 'svg' element
+        // stop comparison here since we do not yet handle the graph title
+        // comment that comes before the 'svg' element
         break;
       }
       REQUIRE(recreated_svg_lines[i] == original_svg_lines[i]);