diff --git a/tests/subsurface-shot-test.c b/tests/subsurface-shot-test.c index 017f5446..9a9a7fd6 100644 --- a/tests/subsurface-shot-test.c +++ b/tests/subsurface-shot-test.c @@ -115,71 +115,6 @@ color(pixman_color_t *tmp, uint8_t r, uint8_t g, uint8_t b) return tmp; } -static void -write_visual_diff(pixman_image_t *ref_image, - struct buffer *shot, - const struct rectangle *clip, - const char *test_name, - int seq_no, - const struct range *fuzz) -{ - char *fname; - char *ext_test_name; - pixman_image_t *diff; - int ret; - - ret = asprintf(&ext_test_name, "%s-diff", test_name); - assert(ret >= 0); - - fname = screenshot_output_filename(ext_test_name, seq_no); - diff = visualize_image_difference(ref_image, shot->image, clip, fuzz); - write_image_as_png(diff, fname); - - pixman_image_unref(diff); - free(fname); - free(ext_test_name); -} - -static int -check_screen(struct client *client, - const char *ref_image, - int ref_seq_no, - const struct rectangle *clip, - int seq_no) -{ - const char *test_name = get_test_name(); - const struct range gl_fuzz = { 0, 1 }; - struct buffer *shot; - pixman_image_t *ref; - char *ref_fname; - char *shot_fname; - bool match; - - ref_fname = screenshot_reference_filename(ref_image, ref_seq_no); - shot_fname = screenshot_output_filename(test_name, seq_no); - - ref = load_image_from_png(ref_fname); - assert(ref); - - shot = capture_screenshot_of_output(client); - assert(shot); - - match = check_images_match(ref, shot->image, clip, &gl_fuzz); - testlog("ref %s vs. shot %s: %s\n", ref_fname, shot_fname, - match ? "PASS" : "FAIL"); - - write_image_as_png(shot->image, shot_fname); - if (!match) - write_visual_diff(ref, shot, clip, test_name, seq_no, &gl_fuzz); - - buffer_destroy(shot); - pixman_image_unref(ref); - free(ref_fname); - free(shot_fname); - - return match ? 0 : -1; -} - static struct buffer * surface_commit_color(struct client *client, struct wl_surface *surface, pixman_color_t *color, int width, int height) diff --git a/tests/weston-test-client-helper.c b/tests/weston-test-client-helper.c index 927523cb..06cf5e07 100644 --- a/tests/weston-test-client-helper.c +++ b/tests/weston-test-client-helper.c @@ -1,5 +1,6 @@ /* * Copyright © 2012 Intel Corporation + * Copyright 2017 Collabora, Ltd. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the @@ -1516,3 +1517,68 @@ capture_screenshot_of_output(struct client *client) return buffer; } + +static void +write_visual_diff(pixman_image_t *ref_image, + struct buffer *shot, + const struct rectangle *clip, + const char *test_name, + int seq_no, + const struct range *fuzz) +{ + char *fname; + char *ext_test_name; + pixman_image_t *diff; + int ret; + + ret = asprintf(&ext_test_name, "%s-diff", test_name); + assert(ret >= 0); + + fname = screenshot_output_filename(ext_test_name, seq_no); + diff = visualize_image_difference(ref_image, shot->image, clip, fuzz); + write_image_as_png(diff, fname); + + pixman_image_unref(diff); + free(fname); + free(ext_test_name); +} + +int +check_screen(struct client *client, + const char *ref_image, + int ref_seq_no, + const struct rectangle *clip, + int seq_no) +{ + const char *test_name = get_test_name(); + const struct range gl_fuzz = { 0, 1 }; + struct buffer *shot; + pixman_image_t *ref; + char *ref_fname; + char *shot_fname; + bool match; + + ref_fname = screenshot_reference_filename(ref_image, ref_seq_no); + shot_fname = screenshot_output_filename(test_name, seq_no); + + ref = load_image_from_png(ref_fname); + assert(ref); + + shot = capture_screenshot_of_output(client); + assert(shot); + + match = check_images_match(ref, shot->image, clip, &gl_fuzz); + testlog("ref %s vs. shot %s: %s\n", ref_fname, shot_fname, + match ? "PASS" : "FAIL"); + + write_image_as_png(shot->image, shot_fname); + if (!match) + write_visual_diff(ref, shot, clip, test_name, seq_no, &gl_fuzz); + + buffer_destroy(shot); + pixman_image_unref(ref); + free(ref_fname); + free(shot_fname); + + return match ? 0 : -1; +} diff --git a/tests/weston-test-client-helper.h b/tests/weston-test-client-helper.h index 45e6db93..046c1cf9 100644 --- a/tests/weston-test-client-helper.h +++ b/tests/weston-test-client-helper.h @@ -246,4 +246,11 @@ load_image_from_png(const char *fname); struct buffer * capture_screenshot_of_output(struct client *client); +int +check_screen(struct client *client, + const char *ref_image, + int ref_seq_no, + const struct rectangle *clip, + int seq_no); + #endif