[librsvg] tests/loading.c: New tests for the loading machinery



commit cc669a6f28290b25720235212b13c515a83936b6
Author: Federico Mena Quintero <federico gnome org>
Date:   Tue Oct 3 14:16:06 2017 -0500

    tests/loading.c: New tests for the loading machinery
    
    We start with a test to load an SVG one byte at a time, using
    rsvg_handle_write().

 tests/Makefile.am |    7 +++++-
 tests/loading.c   |   62 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 68 insertions(+), 1 deletions(-)
---
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 75cc736..65def69 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -4,7 +4,8 @@ test_programs = \
        rsvg-test       \
        crash           \
        render-crash    \
-       dimensions
+       dimensions      \
+       loading
 
 # Removed "styles" from the above; it is broken right now
 
@@ -32,6 +33,10 @@ dimensions_SOURCES = \
        dimensions.c    \
        $(test_utils_common_sources)
 
+loading_SOURCES =                      \
+       loading.c                       \
+       $(test_utils_common_sources)
+
 LDADD = $(top_builddir)/librsvg-@RSVG_API_MAJOR_VERSION@.la            \
        $(LIBRSVG_LIBS)                                                 \
        $(LIBM)
diff --git a/tests/loading.c b/tests/loading.c
new file mode 100644
index 0000000..3f68dd8
--- /dev/null
+++ b/tests/loading.c
@@ -0,0 +1,62 @@
+/* -*- Mode: C; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/* vim: set ts=4 nowrap ai expandtab sw=4: */
+
+#include "config.h"
+
+#include <stdio.h>
+#include <glib.h>
+#include "rsvg.h"
+#include "rsvg-compat.h"
+#include "test-utils.h"
+
+static void
+load_one_byte_at_a_time (gconstpointer data)
+{
+    const char *fixture = data;
+    char *filename = g_build_filename (test_utils_get_test_data_path (), fixture, NULL);
+    guchar buf[1];
+    gboolean done;
+
+    RsvgHandle *handle;
+    FILE *file;
+
+    file = fopen (filename, "rb");
+    g_assert (file != NULL);
+
+    handle = rsvg_handle_new_with_flags (RSVG_HANDLE_FLAGS_NONE);
+
+    done = FALSE;
+
+    do {
+        if (fread (buf, 1, 1, file) == 1) {
+            g_assert (rsvg_handle_write (handle, buf, 1, NULL) != FALSE);
+        } else {
+            g_assert (ferror (file) == 0);
+
+            if (feof (file)) {
+                done = TRUE;
+            }
+        }
+    } while (!done);
+
+    g_assert (rsvg_handle_close (handle, NULL) != FALSE);
+
+    g_object_unref (handle);
+}
+
+int
+main (int argc, char **argv)
+{
+    int result;
+
+    RSVG_G_TYPE_INIT;
+    g_test_init (&argc, &argv, NULL);
+
+    g_test_add_data_func ("/load-one-byte-at-a-time", "loading/gnome-cool.svg", load_one_byte_at_a_time);
+
+    result = g_test_run ();
+
+    rsvg_cleanup ();
+
+    return result;
+}


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