[test] Add test case for a leaky dashed rectangle.
[cairo/haiku.git] / test / surface-pattern-big-scale-down.c
blobc938d9982cd028eea984b610d297062b7b89c525
1 /*
2 * Copyright © 2006 Mozilla Corporation
4 * Permission to use, copy, modify, distribute, and sell this software
5 * and its documentation for any purpose is hereby granted without
6 * fee, provided that the above copyright notice appear in all copies
7 * and that both that copyright notice and this permission notice
8 * appear in supporting documentation, and that the name of
9 * Mozilla Corporation not be used in advertising or publicity pertaining to
10 * distribution of the software without specific, written prior
11 * permission. Mozilla Corporation makes no representations about the
12 * suitability of this software for any purpose. It is provided "as
13 * is" without express or implied warranty.
15 * MOZILLA CORPORATION DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
16 * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
17 * FITNESS, IN NO EVENT SHALL MOZILLA CORPORATION BE LIABLE FOR ANY SPECIAL,
18 * INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
19 * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
20 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
21 * IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
23 * Author: Vladimir Vukicevic <vladimir@pobox.com>
26 #include "cairo-test.h"
28 static cairo_test_draw_function_t draw;
30 #define SRC_WIDTH 2048
31 #define SRC_HEIGHT 32
33 cairo_test_t test = {
34 "surface-pattern-big-scale-down",
35 "Test scaled-down transformed not-repeated surface patterns with large images and offsets",
36 512, 16,
37 draw
40 static void
41 setup_source_surface (cairo_surface_t *surface, int w, int h)
43 cairo_t *cr = cairo_create (surface);
45 cairo_set_source_rgb (cr, 1.0, 0.0, 0.0);
46 cairo_rectangle (cr, 0, 0, w/2, h/2);
47 cairo_fill (cr);
49 cairo_set_source_rgb (cr, 0.0, 1.0, 0.0);
50 cairo_rectangle (cr, w/2, 0, w/2, h/2);
51 cairo_fill (cr);
53 cairo_set_source_rgb (cr, 0.0, 0.0, 1.0);
54 cairo_rectangle (cr, 0, h/2, w/2, h/2);
55 cairo_fill (cr);
57 cairo_set_source_rgb (cr, 1.0, 1.0, 0.0);
58 cairo_rectangle (cr, w/2, h/2, w/2, h/2);
59 cairo_fill (cr);
61 cairo_destroy (cr);
64 static void
65 draw_n (cairo_t *cr, cairo_pattern_t *pat, double dest_size, int n)
67 cairo_matrix_t mat;
69 cairo_matrix_init_scale (&mat, SRC_WIDTH / dest_size, SRC_HEIGHT / dest_size);
70 cairo_matrix_translate (&mat, n * -dest_size, 0.0);
71 cairo_pattern_set_matrix (pat, &mat);
73 cairo_set_source (cr, pat);
74 cairo_new_path (cr);
75 cairo_rectangle (cr, n * dest_size, 0.0, dest_size, dest_size);
76 cairo_fill (cr);
79 static cairo_test_status_t
80 draw (cairo_t *cr, int width, int height)
82 cairo_surface_t *surface;
83 cairo_pattern_t *pat;
85 cairo_set_source_rgb (cr, 0, 0, 0);
86 cairo_paint (cr);
88 surface = cairo_image_surface_create (CAIRO_FORMAT_RGB24, SRC_WIDTH, SRC_HEIGHT);
89 setup_source_surface (surface, SRC_WIDTH, SRC_HEIGHT);
91 pat = cairo_pattern_create_for_surface (surface);
92 cairo_surface_destroy (surface);
94 /* We want to draw at a position such that n * SRC_WIDTH * (SRC_WIDTH/16.0) > 32768.
95 * x = n * 16.
97 * To show the bug, we want to draw on either side of the boundary;
98 * in our case here, n = 16 results in 32768, and n = 17 results in > 32768.
100 * Drawing at 16 and 17 is sufficient to show the problem.
103 #if 1
104 /* n = 16 */
105 draw_n (cr, pat, 16.0, 16);
107 /* n = 17 */
108 draw_n (cr, pat, 16.0, 17);
109 #else
111 int n;
112 for (n = 0; n < 32; n++)
113 draw_n (cr, pat, 16.0, n);
115 #endif
117 cairo_pattern_destroy (pat);
119 return CAIRO_TEST_SUCCESS;
123 main (void)
125 return cairo_test (&test);