Test pixman_region32_init_from_image in region-test
authorAlexander Larsson <alexl@redhat.com>
Fri, 19 Feb 2010 10:22:52 +0000 (11:22 +0100)
committerAlexander Larsson <alexl@redhat.com>
Fri, 19 Feb 2010 10:25:41 +0000 (11:25 +0100)
test/Makefile.am
test/region-test.c

index 5f6ba13..3229f96 100644 (file)
@@ -13,12 +13,14 @@ TESTPROGRAMS =                      \
        composite
 
 fetch_test_LDADD = $(TEST_LDADD)
-region_test_LDADD = $(TEST_LDADD)
 composite_LDADD = $(TEST_LDADD)
 trap_crasher_LDADD = $(TEST_LDADD)
 oob_test_LDADD = $(TEST_LDADD)
 window_test_LDADD = $(TEST_LDADD)
 
+region_test_LDADD = $(TEST_LDADD)
+region_test_SOURCES = region-test.c utils.c utils.h
+
 blitters_test_LDADD = $(TEST_LDADD)
 blitters_test_SOURCES = blitters-test.c utils.c utils.h
 
index 3568969..9d5a41e 100644 (file)
@@ -1,7 +1,7 @@
 #include <assert.h>
 #include <stdlib.h>
 #include <stdio.h>
-#include "pixman.h"
+#include "utils.h"
 
 int
 main ()
@@ -22,8 +22,15 @@ main ()
        { 2, 6, 7, 6 },
        { 4, 1, 6, 1 },
     };
-    int i;
+    int i, j;
     pixman_box32_t *b;
+    pixman_image_t *image, *fill;
+    pixman_color_t white = {
+       0xffff,
+       0xffff,
+       0xffff,
+       0xffff
+    };
 
     /* This used to go into an infinite loop before pixman-region.c
      * was fixed to not use explict "short" variables
@@ -74,5 +81,43 @@ main ()
 
     assert (i == 0);
 
+    fill = pixman_image_create_solid_fill (&white);
+    for (i = 0; i < 100; i++)
+    {
+       int image_size = 128;
+
+       pixman_region32_init (&r1);
+
+       /* Add some random rectangles */
+       for (j = 0; j < 64; j++)
+           pixman_region32_union_rect (&r1, &r1,
+                                       lcg_rand_n (image_size),
+                                       lcg_rand_n (image_size),
+                                       lcg_rand_n (25),
+                                       lcg_rand_n (25));
+
+       /* Clip to image size */
+       pixman_region32_init_rect (&r2, 0, 0, image_size, image_size);
+       pixman_region32_intersect (&r1, &r1, &r2);
+       pixman_region32_fini (&r2);
+
+       /* render region to a1 mask */
+       image = pixman_image_create_bits (PIXMAN_a1, image_size, image_size, NULL, 0);
+       pixman_image_set_clip_region32 (image, &r1);
+       pixman_image_composite32 (PIXMAN_OP_SRC,
+                                 fill, NULL, image,
+                                 0, 0, 0, 0, 0, 0,
+                                 image_size, image_size);
+       pixman_region32_init_from_image (&r2, image);
+
+       pixman_image_unref (image);
+
+       assert (pixman_region32_equal (&r1, &r2));
+       pixman_region32_fini (&r1);
+       pixman_region32_fini (&r2);
+
+    }
+    pixman_image_unref (fill);
+
     return 0;
 }