Skip to content

Commit 9672aab

Browse files
author
Benjamin Otte
committed
tests: Integrate xlib-expose-event test into usual tests
Previously the test was using the preamble vfunc and generating output itself. Now it uses the draw function and ignores any but the xlib backends.
1 parent 36e0a3d commit 9672aab

File tree

1 file changed

+15
-48
lines changed

1 file changed

+15
-48
lines changed

test/xlib-expose-event.c

+15-48
Original file line numberDiff line numberDiff line change
@@ -175,57 +175,27 @@ draw (const cairo_test_context_t *ctx,
175175
}
176176

177177
static cairo_test_status_t
178-
compare (const cairo_test_context_t *ctx, cairo_surface_t *surface)
179-
{
180-
cairo_t *cr;
181-
cairo_surface_t *image, *reference, *diff;
182-
cairo_status_t status;
183-
buffer_diff_result_t result;
184-
185-
diff = cairo_image_surface_create (CAIRO_FORMAT_RGB24, SIZE, SIZE);
186-
187-
/* copy the pixmap to an image buffer */
188-
image = cairo_image_surface_create (CAIRO_FORMAT_RGB24, SIZE, SIZE);
189-
cr = cairo_create (image);
190-
cairo_set_source_surface (cr, surface, 0, 0);
191-
cairo_paint (cr);
192-
cairo_destroy (cr);
193-
cairo_surface_write_to_png (image, "xlib-expose-event.out.png");
194-
195-
reference = cairo_test_create_surface_from_png (ctx, "xlib-expose-event.ref.png");
196-
status = image_diff (ctx, reference, image, diff, &result);
197-
198-
cairo_surface_destroy (reference);
199-
cairo_surface_destroy (image);
200-
cairo_surface_destroy (diff);
201-
202-
return status == CAIRO_STATUS_SUCCESS && ! result.pixels_changed ?
203-
CAIRO_TEST_SUCCESS : CAIRO_TEST_FAILURE;
204-
}
205-
206-
static cairo_test_status_t
207-
preamble (cairo_test_context_t *ctx)
178+
draw_func (cairo_t *cr, int width, int height)
208179
{
209180
Display *dpy;
210181
Drawable drawable;
211182
int screen;
212183
cairo_surface_t *surface;
213184
cairo_rectangle_t region[4];
214185
int i, j;
215-
cairo_test_status_t result = CAIRO_TEST_UNTESTED;
186+
const cairo_test_context_t *ctx;
187+
188+
ctx = cairo_test_get_context (cr);
189+
surface = cairo_get_target (cr);
216190

217-
if (! cairo_test_is_target_enabled (ctx, "xlib"))
218-
goto CLEANUP_TEST;
191+
if (cairo_surface_get_type (surface) != CAIRO_SURFACE_TYPE_XLIB)
192+
return CAIRO_TEST_UNTESTED;
219193

220-
dpy = XOpenDisplay (NULL);
221-
if (dpy == NULL) {
222-
cairo_test_log (ctx, "xlib-expose-event: Cannot open display, skipping\n");
223-
goto CLEANUP_TEST;
224-
}
194+
dpy = cairo_xlib_surface_get_display (surface);
225195

226196
if (! check_visual (dpy)) {
227197
cairo_test_log (ctx, "xlib-expose-event: default visual is not RGB24 or BGR24, skipping\n");
228-
goto CLEANUP_DISPLAY;
198+
return CAIRO_TEST_UNTESTED;
229199
}
230200

231201
screen = DefaultScreen (dpy);
@@ -263,22 +233,19 @@ preamble (cairo_test_context_t *ctx)
263233
}
264234
}
265235

266-
result = compare (ctx, surface);
267-
236+
cairo_set_source_surface (cr, surface, 0, 0);
268237
cairo_surface_destroy (surface);
238+
cairo_set_operator (cr, CAIRO_OPERATOR_SOURCE);
239+
cairo_paint (cr);
269240

270241
XFreePixmap (dpy, drawable);
271242

272-
CLEANUP_DISPLAY:
273-
XCloseDisplay (dpy);
274-
275-
CLEANUP_TEST:
276-
return result;
243+
return CAIRO_TEST_SUCCESS;
277244
}
278245

279246
CAIRO_TEST (xlib_expose_event,
280247
"Emulate a typical expose event",
281248
"xlib", /* keywords */
282249
NULL, /* requirements */
283-
0, 0,
284-
preamble, NULL)
250+
SIZE, SIZE,
251+
NULL, draw_func)

0 commit comments

Comments
 (0)