[librsvg/wip/otte: 39/39] tests: Redo rsvg-test to test all svg files
- From: Benjamin Otte <otte src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [librsvg/wip/otte: 39/39] tests: Redo rsvg-test to test all svg files
- Date: Tue, 20 Oct 2015 12:37:02 +0000 (UTC)
commit 41901d1a52d3bc07b423bcbf954c334bbc45bd95
Author: Benjamin Otte <otte redhat com>
Date: Tue Oct 20 14:30:16 2015 +0200
tests: Redo rsvg-test to test all svg files
.. instead of requiring an rsvg-test.txt file.
As a side effect, this gets rid of failing tests.
tests/rsvg-test.c | 145 ++++++++++++++++++++++++++++++---------------------
tests/rsvg-test.txt | 13 -----
2 files changed, 85 insertions(+), 73 deletions(-)
---
diff --git a/tests/rsvg-test.c b/tests/rsvg-test.c
index 5e7853e..bcf5666 100644
--- a/tests/rsvg-test.c
+++ b/tests/rsvg-test.c
@@ -41,6 +41,8 @@
#include "rsvg-size-callback.h"
#include "rsvg-compat.h"
+#include "test-utils.h"
+
#define TEST_WIDTH 480
#define TEST_LIST_FILENAME TEST_DATA_DIR"/rsvg-test.txt"
@@ -174,24 +176,84 @@ save_image (cairo_surface_t *surface,
g_free (filename);
}
+static gboolean
+is_svg_or_subdir (GFile *file)
+{
+ char *uri;
+ gboolean result;
+
+ if (g_file_query_file_type (file, 0, NULL) == G_FILE_TYPE_DIRECTORY)
+ return TRUE;
+
+ uri = g_file_get_uri (file);
+ result = g_str_has_suffix (uri, ".svg");
+ g_free (uri);
+
+ return result;
+}
+
+static cairo_status_t
+read_from_stream (void *stream,
+ unsigned char *data,
+ unsigned int length)
+
+{
+ gssize result;
+ GError *error = NULL;
+
+ result = g_input_stream_read (stream, data, length, NULL, &error);
+ g_assert_no_error (error);
+ g_assert (result == length);
+
+ return CAIRO_STATUS_SUCCESS;
+}
+
+static cairo_surface_t *
+read_png (const char *test_name)
+{
+ char *reference_uri;
+ GFileInputStream *stream;
+ GFile *file;
+ GError *error = NULL;
+ cairo_surface_t *surface;
+
+ reference_uri = g_strconcat (test_name, "-ref.png", NULL);
+ file = g_file_new_for_uri (reference_uri);
+ stream = g_file_read (file, NULL, &error);
+ g_assert_no_error (error);
+ g_assert (stream);
+
+ surface = cairo_image_surface_create_from_png_stream (read_from_stream, stream);
+
+ g_object_unref (stream);
+ g_object_unref (file);
+
+ return surface;
+}
+
static void
rsvg_cairo_check (gconstpointer data)
{
- char const *test_name = data;
+ GFile *test_file = G_FILE (data);
RsvgHandle *rsvg;
RsvgDimensionData dimensions;
cairo_t *cr;
cairo_surface_t *surface_a, *surface_b, *surface_diff;
buffer_diff_result_t result;
- char *svg_filename;
+ char *test_file_base;
char *reference_png_filename;
unsigned int width_a, height_a, stride_a;
unsigned int width_b, height_b, stride_b;
+ GError *error = NULL;
+
+ test_file_base = g_file_get_uri (test_file);
+ if (g_str_has_suffix (test_file_base, ".svg"))
+ test_file_base[strlen (test_file_base) - strlen (".svg")] = '\0';
- svg_filename = g_strdup_printf ("%s.svg", test_name);
- reference_png_filename = g_strdup_printf ("%s-ref.png", test_name);
+ reference_png_filename = g_strdup_printf ("%s-ref.png", test_file_base);
- rsvg = rsvg_handle_new_from_file (svg_filename, NULL);
+ rsvg = rsvg_handle_new_from_gfile_sync (test_file, 0, NULL, &error);
+ g_assert_no_error (error);
g_assert (rsvg != NULL);
rsvg_handle_get_dimensions (rsvg, &dimensions);
@@ -201,9 +263,9 @@ rsvg_cairo_check (gconstpointer data)
dimensions.width, dimensions.height);
cr = cairo_create (surface_a);
rsvg_handle_render_cairo (rsvg, cr);
- save_image (surface_a, test_name, "-out.png");
+ save_image (surface_a, test_file_base, "-out.png");
- surface_b = cairo_image_surface_create_from_png (reference_png_filename);
+ surface_b = read_png (test_file_base);
width_a = cairo_image_surface_get_width (surface_a);
height_a = cairo_image_surface_get_height (surface_a);
stride_a = cairo_image_surface_get_stride (surface_a);
@@ -226,7 +288,7 @@ rsvg_cairo_check (gconstpointer data)
if (result.pixels_changed && result.max_diff > 1) {
g_test_fail ();
- save_image (surface_diff, test_name, "-diff.png");
+ save_image (surface_diff, test_file_base, "-diff.png");
}
cairo_surface_destroy (surface_diff);
@@ -238,72 +300,35 @@ rsvg_cairo_check (gconstpointer data)
g_object_unref (rsvg);
- g_free (svg_filename);
g_free (reference_png_filename);
}
-static void
-rsvg_cairo_check_xfail (gconstpointer filename)
-{
- g_test_incomplete ("Test is expected to fail.");
- rsvg_cairo_check (filename);
-}
-
int
main (int argc, char **argv)
{
- char *list_content;
- char **list_lines, **strings;
- char *test_name;
- gboolean xfail, ignore;
- int i, j;
- gsize length;
int result;
RSVG_G_TYPE_INIT;
g_test_init (&argc, &argv, NULL);
- if (g_file_get_contents (TEST_LIST_FILENAME, &list_content, &length, NULL)) {
- rsvg_set_default_dpi_x_y (72, 72);
-
- list_lines = g_strsplit (list_content, "\n", 0);
- for (i = 0; list_lines[i] != NULL; i++) {
- strings = g_strsplit_set (list_lines[i], " \t", 0);
- test_name = strings[0];
- if (test_name != NULL
- && strlen (test_name) > 0
- && test_name[0] != '#') {
-
- xfail = FALSE;
- ignore = FALSE;
- for (j = 1; strings[j] != NULL; j++) {
- if (strcmp (strings[j], "X") == 0)
- xfail = TRUE;
- else if (strcmp (strings[j], "I") == 0)
- ignore = TRUE;
- }
- if (!ignore)
- {
- char * test_filename, * test_testname;
+ if (argc < 2) {
+ GFile *base, *tests;
+
+ base = g_file_new_for_path (test_utils_get_test_data_path ());
+ tests = g_file_get_child (base, "reftests");
+ test_utils_add_test_for_all_files ("/rsvg/reftest", tests, tests, rsvg_cairo_check,
is_svg_or_subdir);
+ g_object_unref (tests);
+ g_object_unref (base);
+ } else {
+ guint i;
- test_testname = g_strconcat ("/rsvg/reftest/", test_name, NULL);
- test_filename = g_build_filename (TEST_DATA_DIR, test_name, NULL);
+ for (i = 1; i < argc; i++) {
+ GFile *file = g_file_new_for_commandline_arg (argv[i]);
- if (xfail)
- g_test_add_data_func_full (test_testname, test_filename, rsvg_cairo_check_xfail,
g_free);
- else
- g_test_add_data_func_full (test_testname, test_filename, rsvg_cairo_check, g_free);
+ test_utils_add_test_for_all_files ("/rsvg/reftest", NULL, file, rsvg_cairo_check,
is_svg_or_subdir);
- g_free (test_testname);
- }
- }
- g_strfreev (strings);
- }
- g_strfreev (list_lines);
- g_free (list_content);
- } else {
- g_test_message ("Error opening test list file "TEST_LIST_FILENAME"\n");
- g_assert_not_reached ();
+ g_object_unref (file);
+ }
}
result = g_test_run ();
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]