]> granicus.if.org Git - graphviz/commitdiff
tests: SvgAnalyzer: add generation of the 'xmlns' and' xmlns:xlink' attributes
authorMagnus Jacobsson <Magnus.Jacobsson@berotec.se>
Tue, 26 Jul 2022 19:40:01 +0000 (21:40 +0200)
committerMagnus Jacobsson <Magnus.Jacobsson@berotec.se>
Tue, 16 Aug 2022 10:21:45 +0000 (12:21 +0200)
tests/svg_element.cpp
tests/test_svg_analyzer.cpp

index 2e33b33a9687822dce94fa126ec8aa71917d65a0..639fa955482aa1220c6365f297dfb350f418b5f6 100644 (file)
@@ -88,14 +88,14 @@ void SVG::SVGElement::to_string_impl(std::string &output,
     // ignore for now
     break;
   case SVG::SVGElementType::Svg:
-    attributes_str +=
-        fmt::format(R"(width="{}pt" height="{}pt")"
-                    "\n"
-                    R"( viewBox="{:.2f} {:.2f} {:.2f} {:.2f}")",
-                    std::lround(px_to_pt(attributes.width)),
-                    std::lround(px_to_pt(attributes.height)),
-                    attributes.viewBox.x, attributes.viewBox.y,
-                    attributes.viewBox.width, attributes.viewBox.height);
+    attributes_str += fmt::format(
+        R"(width="{}pt" height="{}pt")"
+        "\n"
+        R"( viewBox="{:.2f} {:.2f} {:.2f} {:.2f}" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink")",
+        std::lround(px_to_pt(attributes.width)),
+        std::lround(px_to_pt(attributes.height)), attributes.viewBox.x,
+        attributes.viewBox.y, attributes.viewBox.width,
+        attributes.viewBox.height);
     break;
   case SVG::SVGElementType::Text:
     // ignore for now
index ff49e0dca9948ab6f6e5aca15b1df8f9787e1580..a77530f4fb417099373c1a44f42c301c6b06025f 100644 (file)
@@ -123,9 +123,9 @@ TEST_CASE(
     boost::split(recreated_svg_lines, recreated_svg, boost::is_any_of("\n"));
     for (std::size_t i = 0; i < original_svg_lines.size(); i++) {
       REQUIRE(i < recreated_svg_lines.size());
-      if (recreated_svg_lines[i].starts_with("<svg width=\"")) {
+      if (recreated_svg_lines[i] == "<g class=\"graph\">") {
         // stop comparison here since we do not yet handle all attributes on the
-        // 'svg' element
+        // 'g' element
         break;
       }
       REQUIRE(recreated_svg_lines[i] == original_svg_lines[i]);
@@ -133,10 +133,6 @@ TEST_CASE(
 
     // do some sanity checks of the parts of the recreated SVG that we cannot
     // yet compare with the original SVG
-    CHECK(recreated_svg.find("<svg width=\"") != std::string::npos);
-    CHECK(recreated_svg.find("\" height=\"") != std::string::npos);
-    CHECK(recreated_svg.find("\n viewBox=\"") != std::string::npos);
-    CHECK(recreated_svg.find("</svg>") != std::string::npos);
     CHECK(recreated_svg.find("<g class=\"graph\">") != std::string::npos);
     CHECK(recreated_svg.find("<g class=\"node\">") != std::string::npos);
     CHECK(recreated_svg.find("<g class=\"edge\">") != std::string::npos);