]> granicus.if.org Git - graphviz/commitdiff
add a test case for #2272
authorMatthew Fernandez <matthew.fernandez@gmail.com>
Thu, 8 Sep 2022 02:46:10 +0000 (19:46 -0700)
committerMatthew Fernandez <matthew.fernandez@gmail.com>
Thu, 8 Sep 2022 02:46:10 +0000 (19:46 -0700)
tests/2272.c [new file with mode: 0644]
tests/test_regression.py

diff --git a/tests/2272.c b/tests/2272.c
new file mode 100644 (file)
index 0000000..72024a8
--- /dev/null
@@ -0,0 +1,28 @@
+/// \file
+/// \brief test case for repeated use of agmemread() with unterminated strings
+///
+/// See test_regression.py:test_2272
+
+#include <assert.h>
+#include <graphviz/cgraph.h>
+
+#ifdef NDEBUG
+#error "this code is not intended to be compiled with assertions disabled"
+#endif
+
+int main(void) {
+
+  // parse a graph with an unterminated string
+  Agraph_t *g = agmemread("graph { a[label=\"abc");
+
+  // this should have failed
+  assert(g == NULL && "unterminated string was not rejected");
+
+  // try parsing this graph again
+  g = agmemread("graph { a[label=\"abc");
+
+  // this one should fail too
+  assert(g == NULL);
+
+  return 0;
+}
index 6316adf24bd999965ef24000db6cf34c69cb1873..c7dac5474f2e29a5450fafd6e65555b442768e73 100644 (file)
@@ -1969,3 +1969,22 @@ def test_2270(tmp_path: Path):
   # it should have produced output in the expected location
   output = tmp_path / "hello.gv.core.dot.plain"
   assert output.exists(), "-O resulted in an unexpected output filename"
+
+@pytest.mark.xfail()
+def test_2272():
+  """
+  using `agmemread` with an unterminated string should not fail assertions
+  https://gitlab.com/graphviz/graphviz/-/issues/2272
+  """
+
+  # FIXME: Remove skip when
+  # https://gitlab.com/graphviz/graphviz/-/issues/1777 is fixed
+  if os.getenv("build_system") == "msbuild":
+    pytest.skip("Windows MSBuild release does not contain any header files (#1777)")
+
+  # find co-located test source
+  c_src = (Path(__file__).parent / "2272.c").resolve()
+  assert c_src.exists(), "missing test case"
+
+  # run the test
+  run_c(c_src, link=["cgraph", "gvc"])