[librsvg: 3/5] Move the tests for the legacy API for loading to api.c




commit 020b79c83ba23749019aa946fe1001d897b65d01
Author: Federico Mena Quintero <federico gnome org>
Date:   Fri Oct 9 17:14:25 2020 -0500

    Move the tests for the legacy API for loading to api.c

 tests/Makefile.am |  5 ----
 tests/api.c       | 69 ++++++++++++++++++++++++++++++++++++++++++++
 tests/loading.c   | 85 -------------------------------------------------------
 3 files changed, 69 insertions(+), 90 deletions(-)
---
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 255d0193..4cb7cda5 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -17,7 +17,6 @@ EXTRA_DIST +=         \
 # Keep "errors" at the end; they are the slowest to run
 test_programs =                \
        api             \
-       loading         \
        rsvg-test       \
        crash           \
        render-crash    \
@@ -52,10 +51,6 @@ render_crash_SOURCES = \
        render-crash.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/api.c b/tests/api.c
index b1bf490a..6d083c8a 100644
--- a/tests/api.c
+++ b/tests/api.c
@@ -1524,6 +1524,63 @@ static DimensionsFixtureData dimensions_fixtures[] =
     },
 };
 
+typedef struct
+{
+    const char *test_name;
+    const char *fixture;
+    size_t buf_size;
+} LoadingTestData;
+
+static void
+load_n_bytes_at_a_time (gconstpointer data)
+{
+    const LoadingTestData *fixture_data = data;
+    char *filename = g_build_filename (test_utils_get_test_data_path (), fixture_data->fixture, NULL);
+    guchar *buf = g_new (guchar, fixture_data->buf_size);
+    gboolean done;
+
+    RsvgHandle *handle;
+    FILE *file;
+
+    file = fopen (filename, "rb");
+    g_assert_nonnull (file);
+
+    handle = rsvg_handle_new_with_flags (RSVG_HANDLE_FLAGS_NONE);
+
+    done = FALSE;
+
+    do {
+        size_t num_read;
+
+        num_read = fread (buf, 1, fixture_data->buf_size, file);
+
+        if (num_read > 0) {
+            g_assert_true (rsvg_handle_write (handle, buf, num_read, NULL));
+        } else {
+            g_assert_cmpint (ferror (file), ==, 0);
+
+            if (feof (file)) {
+                done = TRUE;
+            }
+        }
+    } while (!done);
+
+    fclose (file);
+    g_free (filename);
+
+    g_assert_true (rsvg_handle_close (handle, NULL));
+
+    g_object_unref (handle);
+
+    g_free (buf);
+}
+
+static LoadingTestData loading_tests[] = {
+    { "/loading/one-byte-at-a-time", "loading/gnome-cool.svg", 1 },
+    { "/loading/compressed-one-byte-at-a-time", "loading/gnome-cool.svgz", 1 },
+    { "/loading/compressed-two-bytes-at-a-time", "loading/gnome-cool.svgz", 2 } /* to test reading the 
entire gzip header */
+};
+
 /* Tests for the deprecated GdkPixbuf-based API */
 static void
 add_pixbuf_tests (void)
@@ -1596,6 +1653,17 @@ add_geometry_tests (void)
         g_test_add_data_func (dimensions_fixtures[i].test_name, &dimensions_fixtures[i], 
(void*)test_dimensions);
 }
 
+/* Tests for the deprecated API for loading bytes at a time */
+static void
+add_loading_tests (void)
+{
+    int i;
+
+    for (i = 0; i < G_N_ELEMENTS (loading_tests); i++) {
+        g_test_add_data_func (loading_tests[i].test_name, &loading_tests[i], load_n_bytes_at_a_time);
+    }
+}
+
 int
 main (int argc, char **argv)
 {
@@ -1606,6 +1674,7 @@ main (int argc, char **argv)
     add_pixbuf_tests ();
     add_api_tests ();
     add_geometry_tests ();
+    add_loading_tests ();
 
     return g_test_run ();
 }


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