[librsvg: 2/11] Add missing test for rsvg_handle_set_stylesheet()




commit df2dfd7fb22861c9107ff2c6110255059881a6ea
Author: Federico Mena Quintero <federico gnome org>
Date:   Fri Aug 5 20:16:06 2022 -0500

    Add missing test for rsvg_handle_set_stylesheet()
    
    Part-of: <https://gitlab.gnome.org/GNOME/librsvg/-/merge_requests/727>

 tests/api.c                           | 52 +++++++++++++++++++++++++++++++++++
 tests/fixtures/api/stylesheet-ref.svg |  4 +++
 tests/fixtures/api/stylesheet.svg     |  5 ++++
 3 files changed, 61 insertions(+)
---
diff --git a/tests/api.c b/tests/api.c
index 3321803d2..746d052d4 100644
--- a/tests/api.c
+++ b/tests/api.c
@@ -1035,6 +1035,57 @@ get_intrinsic_size_in_pixels_no (void)
     g_object_unref (handle);
 }
 
+static void
+set_stylesheet (void)
+{
+    char *filename = get_test_filename ("stylesheet.svg");
+    char *ref_filename = get_test_filename ("stylesheet-ref.svg");
+    const char *css = "rect { fill: #00ff00; }";
+    GError *error = NULL;
+
+    RsvgHandle *handle = rsvg_handle_new_from_file (filename, &error);
+    g_assert_no_error (error);
+
+    RsvgHandle *ref_handle = rsvg_handle_new_from_file (ref_filename, &error);
+    g_assert_no_error (error);
+
+    cairo_surface_t *output = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, 100, 100);
+    cairo_surface_t *reference = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, 100, 100);
+
+    RsvgRectangle viewport = { 0.0, 0.0, 100.0, 100.0 };
+
+    cairo_t *output_cr = cairo_create (output);
+    cairo_t *ref_cr = cairo_create (reference);
+
+    g_assert (rsvg_handle_set_stylesheet (handle, (const guint8 *) css, strlen (css), &error));
+    g_assert_no_error (error);
+
+    g_assert (rsvg_handle_render_document (handle, output_cr, &viewport, &error));
+    g_assert_no_error (error);
+
+    g_assert (rsvg_handle_render_document (ref_handle, ref_cr, &viewport, &error));
+    g_assert_no_error (error);
+
+    cairo_surface_t *diff = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, 100, 100);
+
+    TestUtilsBufferDiffResult result = {0, 0};
+    test_utils_compare_surfaces (output, reference, diff, &result);
+
+    if (result.pixels_changed && result.max_diff > 0) {
+        g_test_fail ();
+    }
+
+    cairo_surface_destroy (diff);
+    cairo_destroy (ref_cr);
+    cairo_destroy (output_cr);
+    cairo_surface_destroy (reference);
+    cairo_surface_destroy (output);
+    g_object_unref (ref_handle);
+    g_object_unref (handle);
+    g_free (ref_filename);
+    g_free (filename);
+}
+
 static void
 render_document (void)
 {
@@ -1693,6 +1744,7 @@ add_api_tests (void)
     g_test_add_func ("/api/get_intrinsic_dimensions", get_intrinsic_dimensions);
     g_test_add_func ("/api/get_intrinsic_size_in_pixels/yes", get_intrinsic_size_in_pixels_yes);
     g_test_add_func ("/api/get_intrinsic_size_in_pixels/no", get_intrinsic_size_in_pixels_no);
+    g_test_add_func ("/api/set_stylesheet", set_stylesheet);
     g_test_add_func ("/api/render_document", render_document);
     g_test_add_func ("/api/get_geometry_for_layer", get_geometry_for_layer);
     g_test_add_func ("/api/render_layer", render_layer);
diff --git a/tests/fixtures/api/stylesheet-ref.svg b/tests/fixtures/api/stylesheet-ref.svg
new file mode 100644
index 000000000..5f54672dd
--- /dev/null
+++ b/tests/fixtures/api/stylesheet-ref.svg
@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<svg xmlns="http://www.w3.org/2000/svg"; width="100" height="100">
+  <rect id="foo" x="10" y="20" width="30" height="40" fill="#00ff00"/>
+</svg>
diff --git a/tests/fixtures/api/stylesheet.svg b/tests/fixtures/api/stylesheet.svg
new file mode 100644
index 000000000..118ff2fbc
--- /dev/null
+++ b/tests/fixtures/api/stylesheet.svg
@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- This gets styled with stylesheet.css -->
+<svg xmlns="http://www.w3.org/2000/svg"; width="100" height="100">
+  <rect id="foo" x="10" y="20" width="30" height="40" fill="black"/>
+</svg>


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