region-test.c revision d0321353
1#include <assert.h>
2#include <stdlib.h>
3#include <stdio.h>
4#include "pixman.h"
5
6int
7main ()
8{
9    pixman_region32_t r1;
10    pixman_region32_t r2;
11    pixman_region32_t r3;
12    pixman_box32_t boxes[] = {
13	{ 10, 10, 20, 20 },
14	{ 30, 30, 30, 40 },
15	{ 50, 45, 60, 44 },
16    };
17    pixman_box32_t boxes2[] = {
18	{ 2, 6, 7, 6 },
19	{ 4, 1, 6, 7 },
20    };
21    pixman_box32_t boxes3[] = {
22	{ 2, 6, 7, 6 },
23	{ 4, 1, 6, 1 },
24    };
25    int i;
26    pixman_box32_t *b;
27
28    /* This used to go into an infinite loop before pixman-region.c
29     * was fixed to not use explict "short" variables
30     */
31    pixman_region32_init_rect (&r1, 0, 0, 20, 64000);
32    pixman_region32_init_rect (&r2, 0, 0, 20, 64000);
33    pixman_region32_init_rect (&r3, 0, 0, 20, 64000);
34
35    pixman_region32_subtract (&r1, &r2, &r3);
36
37
38    /* This would produce a region containing an empty
39     * rectangle in it. Such regions are considered malformed,
40     * but using an empty rectangle for initialization should
41     * work.
42     */
43    pixman_region32_init_rects (&r1, boxes, 3);
44
45    b = pixman_region32_rectangles (&r1, &i);
46
47    assert (i == 1);
48
49    while (i--)
50    {
51	assert (b[i].x1 < b[i].x2);
52	assert (b[i].y1 < b[i].y2);
53    }
54
55    /* This would produce a rectangle containing the bounding box
56     * of the two rectangles. The correct result is to eliminate
57     * the broken rectangle.
58     */
59    pixman_region32_init_rects (&r1, boxes2, 2);
60
61    b = pixman_region32_rectangles (&r1, &i);
62
63    assert (i == 1);
64
65    assert (b[0].x1 == 4);
66    assert (b[0].y1 == 1);
67    assert (b[0].x2 == 6);
68    assert (b[0].y2 == 7);
69
70    /* This should produce an empty region */
71    pixman_region32_init_rects (&r1, boxes3, 2);
72
73    b = pixman_region32_rectangles (&r1, &i);
74
75    assert (i == 0);
76
77    return 0;
78}
79