[librsvg/librsvg-2.40] Backport: tests/render-crash: New test for things that crash the rendering code



commit 721fbee0821551696cf5bf9ab9b609c6f8a2ce5a
Author: Federico Mena Quintero <federico gnome org>
Date:   Wed Jan 11 15:50:26 2017 -0600

    Backport: tests/render-crash: New test for things that crash the
    rendering code
    
    From commit 3a3becd2045ed6b5e264bdfbd7c53c799e5abe7c
    
    Sometimes we don't have rendering bugs in the generated image, but SVG
    files that just crash the rendering code.  Add a test for this.  If you
    put a SVG under tests/fixtures/render-crash, that file is expected to
    render and *not* crash.  The actual rendered image is ignored.

 tests/Makefile.am    |    6 ++++
 tests/render-crash.c |   68 ++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 74 insertions(+), 0 deletions(-)
---
diff --git a/tests/Makefile.am b/tests/Makefile.am
index f25e7d3..1c11db5 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -5,6 +5,7 @@ test_programs =         \
        rsvg-test       \
        crash           \
        styles          \
+       render-crash    \
        dimensions
 
 test_utils_common_sources = \
@@ -19,6 +20,10 @@ crash_SOURCES = \
        crash.c         \
        $(test_utils_common_sources)
 
+render_crash_SOURCES = \
+       render-crash.c  \
+       $(test_utils_common_sources)
+
 styles_SOURCES = \
        styles.c        \
        $(test_utils_common_sources)
@@ -54,6 +59,7 @@ dist_installed_test_data =                                            \
        $(wildcard $(srcdir)/fixtures/reftests/svg1.1/*.svg)            \
        $(wildcard $(srcdir)/fixtures/reftests/svg1.1/*.png)            \
        $(wildcard $(srcdir)/fixtures/reftests/svg1.1/resources/*)      \
+       $(wildcard $(srcdir)/fixtures/render-crash/*.svg)               \
        fixtures/dimensions/bug564527.svg                               \
        fixtures/dimensions/bug614018.svg                               \
        fixtures/dimensions/bug612951.svg                               \
diff --git a/tests/render-crash.c b/tests/render-crash.c
new file mode 100644
index 0000000..6e9678c
--- /dev/null
+++ b/tests/render-crash.c
@@ -0,0 +1,68 @@
+/* vim: set ts=4 nowrap ai expandtab sw=4: */
+
+#include <glib.h>
+#include "rsvg.h"
+#include "rsvg-compat.h"
+#include "test-utils.h"
+
+static void
+test_render_crash (gconstpointer data)
+{
+    GFile *file = G_FILE (data);
+    RsvgHandle *handle;
+    GError *error = NULL;
+    RsvgDimensionData dimensions;
+    cairo_surface_t *surface;
+    cairo_t *cr;
+
+    handle = rsvg_handle_new_from_gfile_sync (file, RSVG_HANDLE_FLAGS_NONE, NULL, &error);
+    g_assert_no_error (error);
+    g_assert (handle != NULL);
+
+    rsvg_handle_get_dimensions (handle, &dimensions);
+    g_assert (dimensions.width > 0);
+    g_assert (dimensions.height > 0);
+    surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32,
+                                         dimensions.width, dimensions.height);
+    cr = cairo_create (surface);
+    g_assert (rsvg_handle_render_cairo (handle, cr));
+
+    cairo_surface_destroy (surface);
+    cairo_destroy (cr);
+
+    g_object_unref (handle);
+}
+
+int
+main (int argc, char *argv[])
+{
+    GFile *base, *crash;
+    int result;
+
+    RSVG_G_TYPE_INIT;
+    g_test_init (&argc, &argv, NULL);
+
+    if (argc < 2) {
+        base = g_file_new_for_path (test_utils_get_test_data_path ());
+        crash = g_file_get_child (base, "render-crash");
+        test_utils_add_test_for_all_files ("/render-crash", crash, crash, test_render_crash, NULL);
+        g_object_unref (base);
+        g_object_unref (crash);
+    } else {
+        guint i;
+
+        for (i = 1; i < argc; i++) {
+            GFile *file = g_file_new_for_commandline_arg (argv[i]);
+
+            test_utils_add_test_for_all_files ("/render-crash", NULL, file, test_render_crash, NULL);
+
+            g_object_unref (file);
+        }
+    }
+
+    result = g_test_run ();
+
+    rsvg_cleanup ();
+
+    return result;
+}


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]