7 make_random_region (pixman_region32_t *region)
11 pixman_region32_init (region);
13 n_boxes = lcg_rand_n (64);
19 x = (int32_t)lcg_rand_u32() >> 2;
20 y = (int32_t)lcg_rand_u32() >> 2;
21 w = lcg_rand_u32() >> 2;
22 h = lcg_rand_u32() >> 2;
24 pixman_region32_union_rect (region, region, x, y, w, h);
29 print_box (pixman_box32_t *box)
31 printf (" %d %d %d %d\n", box->x1, box->y1, box->x2, box->y2);
35 random_coord (pixman_region32_t *region, pixman_bool_t x)
37 pixman_box32_t *b, *bb;
43 bb = pixman_region32_rectangles (region, &n_boxes);
46 b = bb + lcg_rand_n (n_boxes);
51 b = pixman_region32_extents (region);
66 switch (lcg_rand_n (5))
69 return begin - lcg_rand_u32();
71 return end + lcg_rand_u32 ();
77 return (begin + end) / 2;
83 compute_crc32_u32 (uint32_t crc32, uint32_t v)
85 if (!is_little_endian())
87 v = ((v & 0xff000000) >> 24) |
88 ((v & 0x00ff0000) >> 8) |
89 ((v & 0x0000ff00) << 8) |
90 ((v & 0x000000ff) << 24);
93 return compute_crc32 (crc32, &v, sizeof (int32_t));
97 crc32_box32 (uint32_t crc32, pixman_box32_t *box)
99 crc32 = compute_crc32_u32 (crc32, box->x1);
100 crc32 = compute_crc32_u32 (crc32, box->y1);
101 crc32 = compute_crc32_u32 (crc32, box->x2);
102 crc32 = compute_crc32_u32 (crc32, box->y2);
108 test_region_contains_rectangle (int i, int verbose)
111 pixman_box32_t rbox = { 0, 0, 0, 0 };
112 pixman_region32_t region;
113 uint32_t r, r1, r2, r3, r4, crc32;
117 make_random_region (®ion);
119 box.x1 = random_coord (®ion, TRUE);
120 box.x2 = box.x1 + lcg_rand_u32 ();
121 box.y1 = random_coord (®ion, FALSE);
122 box.y2 = box.y1 + lcg_rand_u32 ();
127 pixman_box32_t *boxes;
129 boxes = pixman_region32_rectangles (®ion, &n_rects);
131 printf ("region:\n");
140 r1 = pixman_region32_contains_point (®ion, box.x1, box.y1, &rbox);
141 crc32 = crc32_box32 (crc32, &rbox);
142 r2 = pixman_region32_contains_point (®ion, box.x1, box.y2, &rbox);
143 crc32 = crc32_box32 (crc32, &rbox);
144 r3 = pixman_region32_contains_point (®ion, box.x2, box.y1, &rbox);
145 crc32 = crc32_box32 (crc32, &rbox);
146 r4 = pixman_region32_contains_point (®ion, box.x2, box.y2, &rbox);
147 crc32 = crc32_box32 (crc32, &rbox);
149 r = pixman_region32_contains_rectangle (®ion, &box);
150 r = (i << 8) | (r << 4) | (r1 << 3) | (r2 << 2) | (r3 << 1) | (r4 << 0);
152 crc32 = compute_crc32_u32 (crc32, r);
155 printf ("results: %d %d %d %d %d\n", (r & 0xf0) >> 4, r1, r2, r3, r4);
157 pixman_region32_fini (®ion);
163 main (int argc, const char *argv[])
165 return fuzzer_test_main ("region_contains",
168 test_region_contains_rectangle,