6 make_random_region (pixman_region32_t *region)
10 pixman_region32_init (region);
12 n_boxes = prng_rand_n (64);
18 x = (int32_t)prng_rand() >> 2;
19 y = (int32_t)prng_rand() >> 2;
23 pixman_region32_union_rect (region, region, x, y, w, h);
28 print_box (pixman_box32_t *box)
30 printf (" %d %d %d %d\n", box->x1, box->y1, box->x2, box->y2);
34 random_coord (pixman_region32_t *region, pixman_bool_t x)
36 pixman_box32_t *b, *bb;
42 bb = pixman_region32_rectangles (region, &n_boxes);
45 b = bb + prng_rand_n (n_boxes);
50 b = pixman_region32_extents (region);
65 switch (prng_rand_n (5))
68 return begin - prng_rand();
70 return end + prng_rand ();
76 return (end - begin) / 2 + begin;
82 compute_crc32_u32 (uint32_t crc32, uint32_t v)
84 if (!is_little_endian())
86 v = ((v & 0xff000000) >> 24) |
87 ((v & 0x00ff0000) >> 8) |
88 ((v & 0x0000ff00) << 8) |
89 ((v & 0x000000ff) << 24);
92 return compute_crc32 (crc32, &v, sizeof (int32_t));
96 crc32_box32 (uint32_t crc32, pixman_box32_t *box)
98 crc32 = compute_crc32_u32 (crc32, box->x1);
99 crc32 = compute_crc32_u32 (crc32, box->y1);
100 crc32 = compute_crc32_u32 (crc32, box->x2);
101 crc32 = compute_crc32_u32 (crc32, box->y2);
107 test_region_contains_rectangle (int i, int verbose)
110 pixman_box32_t rbox = { 0, 0, 0, 0 };
111 pixman_region32_t region;
112 uint32_t r, r1, r2, r3, r4, crc32;
116 make_random_region (®ion);
118 box.x1 = random_coord (®ion, TRUE);
119 box.x2 = box.x1 + prng_rand ();
120 box.y1 = random_coord (®ion, FALSE);
121 box.y2 = box.y1 + prng_rand ();
126 pixman_box32_t *boxes;
128 boxes = pixman_region32_rectangles (®ion, &n_rects);
130 printf ("region:\n");
139 r1 = pixman_region32_contains_point (®ion, box.x1, box.y1, &rbox);
140 crc32 = crc32_box32 (crc32, &rbox);
141 r2 = pixman_region32_contains_point (®ion, box.x1, box.y2, &rbox);
142 crc32 = crc32_box32 (crc32, &rbox);
143 r3 = pixman_region32_contains_point (®ion, box.x2, box.y1, &rbox);
144 crc32 = crc32_box32 (crc32, &rbox);
145 r4 = pixman_region32_contains_point (®ion, box.x2, box.y2, &rbox);
146 crc32 = crc32_box32 (crc32, &rbox);
148 r = pixman_region32_contains_rectangle (®ion, &box);
149 r = (i << 8) | (r << 4) | (r1 << 3) | (r2 << 2) | (r3 << 1) | (r4 << 0);
151 crc32 = compute_crc32_u32 (crc32, r);
154 printf ("results: %d %d %d %d %d\n", (r & 0xf0) >> 4, r1, r2, r3, r4);
156 pixman_region32_fini (®ion);
162 main (int argc, const char *argv[])
164 return fuzzer_test_main ("region_contains",
167 test_region_contains_rectangle,