Blame test/line-width-overlap.c

Packit 324a5c
/* -*- Mode: c; c-basic-offset: 4; indent-tabs-mode: t; tab-width: 8; -*- */
Packit 324a5c
/*
Packit 324a5c
 * Copyright 2011 Red Hat Inc.
Packit 324a5c
 *
Packit 324a5c
 * Permission is hereby granted, free of charge, to any person
Packit 324a5c
 * obtaining a copy of this software and associated documentation
Packit 324a5c
 * files (the "Software"), to deal in the Software without
Packit 324a5c
 * restriction, including without limitation the rights to use, copy,
Packit 324a5c
 * modify, merge, publish, distribute, sublicense, and/or sell copies
Packit 324a5c
 * of the Software, and to permit persons to whom the Software is
Packit 324a5c
 * furnished to do so, subject to the following conditions:
Packit 324a5c
 *
Packit 324a5c
 * The above copyright notice and this permission notice shall be
Packit 324a5c
 * included in all copies or substantial portions of the Software.
Packit 324a5c
 *
Packit 324a5c
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
Packit 324a5c
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
Packit 324a5c
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
Packit 324a5c
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
Packit 324a5c
 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
Packit 324a5c
 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
Packit 324a5c
 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
Packit 324a5c
 * SOFTWARE.
Packit 324a5c
 *
Packit 324a5c
 * Author: Benjamin Otte <otte@redhat.com>
Packit 324a5c
 */
Packit 324a5c
Packit 324a5c
/*
Packit 324a5c
 * Test case taken from the WebKit test suite, failure originally reported
Packit 324a5c
 * by Zan Dobersek <zandobersek@gmail.com>. WebKit test is
Packit 324a5c
 * LayoutTests/canvas/philip/tests/2d.path.rect.selfintersect.html
Packit 324a5c
 */
Packit 324a5c
Packit 324a5c
#include "cairo-test.h"
Packit 324a5c
Packit 324a5c
#include <math.h>
Packit 324a5c
Packit 324a5c
#define LINE_WIDTH 60
Packit 324a5c
#define SIZE 100
Packit 324a5c
#define RECT_SIZE 10
Packit 324a5c
Packit 324a5c
static cairo_test_status_t
Packit 324a5c
draw (cairo_t *cr, int width, int height)
Packit 324a5c
{
Packit 324a5c
    /* fill with green so RGB and RGBA tests can share the ref image */
Packit 324a5c
    cairo_set_source_rgb (cr, 0, 1, 0);
Packit 324a5c
    cairo_paint (cr);
Packit 324a5c
Packit 324a5c
    /* red to see eventual bugs immediately */
Packit 324a5c
    cairo_set_source_rgb (cr, 1, 0, 0);
Packit 324a5c
Packit 324a5c
    /* big line width */
Packit 324a5c
    cairo_set_line_width (cr, LINE_WIDTH);
Packit 324a5c
Packit 324a5c
    /* rectangle that is smaller than the line width in center of image */
Packit 324a5c
    cairo_rectangle (cr,
Packit 324a5c
                     (SIZE - RECT_SIZE) / 2,
Packit 324a5c
                     (SIZE - RECT_SIZE) / 2,
Packit 324a5c
                     RECT_SIZE,
Packit 324a5c
                     RECT_SIZE);
Packit 324a5c
Packit 324a5c
    cairo_stroke (cr);
Packit 324a5c
Packit 324a5c
    return CAIRO_TEST_SUCCESS;
Packit 324a5c
}
Packit 324a5c
Packit 324a5c
/* and again slightly offset to trigger another path */
Packit 324a5c
static cairo_test_status_t
Packit 324a5c
draw_offset (cairo_t *cr, int width, int height)
Packit 324a5c
{
Packit 324a5c
    cairo_translate (cr, .5, .5);
Packit 324a5c
    return draw (cr, width, height);
Packit 324a5c
}
Packit 324a5c
Packit 324a5c
static cairo_test_status_t
Packit 324a5c
draw_rotated (cairo_t *cr, int width, int height)
Packit 324a5c
{
Packit 324a5c
    cairo_translate (cr, SIZE/2, SIZE/2);
Packit 324a5c
    cairo_rotate (cr, M_PI/4);
Packit 324a5c
    cairo_translate (cr, -SIZE/2, -SIZE/2);
Packit 324a5c
Packit 324a5c
    return draw (cr, width, height);
Packit 324a5c
}
Packit 324a5c
Packit 324a5c
static cairo_test_status_t
Packit 324a5c
draw_flipped (cairo_t *cr, int width, int height)
Packit 324a5c
{
Packit 324a5c
    cairo_translate (cr, SIZE/2, SIZE/2);
Packit 324a5c
    cairo_scale (cr, -1, 1);
Packit 324a5c
    cairo_translate (cr, -SIZE/2, -SIZE/2);
Packit 324a5c
Packit 324a5c
    return draw (cr, width, height);
Packit 324a5c
}
Packit 324a5c
Packit 324a5c
static cairo_test_status_t
Packit 324a5c
draw_flopped (cairo_t *cr, int width, int height)
Packit 324a5c
{
Packit 324a5c
    cairo_translate (cr, SIZE/2, SIZE/2);
Packit 324a5c
    cairo_scale (cr, 1, -1);
Packit 324a5c
    cairo_translate (cr, -SIZE/2, -SIZE/2);
Packit 324a5c
Packit 324a5c
    return draw (cr, width, height);
Packit 324a5c
}
Packit 324a5c
Packit 324a5c
static cairo_test_status_t
Packit 324a5c
draw_dashed (cairo_t *cr, int width, int height)
Packit 324a5c
{
Packit 324a5c
    const double dashes[] = { 4 };
Packit 324a5c
    cairo_set_dash (cr, dashes, 1, 0);
Packit 324a5c
    cairo_set_line_cap (cr, CAIRO_LINE_CAP_BUTT);
Packit 324a5c
    return draw (cr, width, height);
Packit 324a5c
}
Packit 324a5c
Packit 324a5c
CAIRO_TEST (line_width_overlap,
Packit 324a5c
	    "Test overlapping lines due to large line width",
Packit 324a5c
	    "stroke", /* keywords */
Packit 324a5c
	    NULL, /* requirements */
Packit 324a5c
	    SIZE, SIZE,
Packit 324a5c
	    NULL, draw)
Packit 324a5c
CAIRO_TEST (line_width_overlap_offset,
Packit 324a5c
	    "Test overlapping lines due to large line width",
Packit 324a5c
	    "stroke", /* keywords */
Packit 324a5c
	    NULL, /* requirements */
Packit 324a5c
	    SIZE, SIZE,
Packit 324a5c
	    NULL, draw_offset)
Packit 324a5c
CAIRO_TEST (line_width_overlap_rotated,
Packit 324a5c
	    "Test overlapping lines due to large line width",
Packit 324a5c
	    "stroke", /* keywords */
Packit 324a5c
	    NULL, /* requirements */
Packit 324a5c
	    SIZE, SIZE,
Packit 324a5c
	    NULL, draw_rotated)
Packit 324a5c
CAIRO_TEST (line_width_overlap_flipped,
Packit 324a5c
	    "Test overlapping lines due to large line width",
Packit 324a5c
	    "stroke", /* keywords */
Packit 324a5c
	    NULL, /* requirements */
Packit 324a5c
	    SIZE, SIZE,
Packit 324a5c
	    NULL, draw_flipped)
Packit 324a5c
CAIRO_TEST (line_width_overlap_flopped,
Packit 324a5c
	    "Test overlapping lines due to large line width",
Packit 324a5c
	    "stroke", /* keywords */
Packit 324a5c
	    NULL, /* requirements */
Packit 324a5c
	    SIZE, SIZE,
Packit 324a5c
	    NULL, draw_flopped)
Packit 324a5c
CAIRO_TEST (line_width_overlap_dashed,
Packit 324a5c
	    "Test overlapping lines due to large line width",
Packit 324a5c
	    "stroke", /* keywords */
Packit 324a5c
	    NULL, /* requirements */
Packit 324a5c
	    SIZE, SIZE,
Packit 324a5c
	    NULL, draw_dashed)