[sapwood] and the test for the bitmask with offset



commit c93995beff033d6ee60d172c6cdff070a49d52d2
Author: Sven Herzberg <herzi gnome-de org>
Date:   Thu Aug 5 14:09:16 2010 +0200

    and the test for the bitmask with offset
    
    * tests/test-sapwood.c: test this scenario as well
    * tests/test-larger-masked-offset.png: expected output file

 tests/test-larger-masked-offset.png |  Bin 0 -> 357 bytes
 tests/test-sapwood.c                |   85 ++++++++++++++++++++++++++++++++++-
 2 files changed, 84 insertions(+), 1 deletions(-)
---
diff --git a/tests/test-larger-masked-offset.png b/tests/test-larger-masked-offset.png
new file mode 100644
index 0000000..2066422
Binary files /dev/null and b/tests/test-larger-masked-offset.png differ
diff --git a/tests/test-sapwood.c b/tests/test-sapwood.c
index b2fc719..a64b819 100644
--- a/tests/test-sapwood.c
+++ b/tests/test-sapwood.c
@@ -160,7 +160,7 @@ test_larger_masked (void)
                                200, 200,
                                mask,
                                0, 0,
-                               FALSE,
+                               TRUE,
                                NULL,
                                G_N_ELEMENTS (rects), rects);
 
@@ -188,6 +188,88 @@ test_larger_masked (void)
   assert_cmp_pixbuf (result, ==, expected);
 }
 
+static void
+test_larger_masked_offset (void)
+{
+  SapwoodPixmap* pixmap;
+  SapwoodRect    rects[9];
+  GdkDrawable  * drawable = NULL;
+  GdkPixbuf    * result;
+  GdkPixbuf    * expected;
+  GdkBitmap    * mask;
+  GError       * error = NULL;
+  char           abspath[PATH_MAX + 1];
+  int            code;
+  int            i;
+
+  if (!realpath (TOP_SRCDIR G_DIR_SEPARATOR_S "tests" G_DIR_SEPARATOR_S "test-source-alpha75.png", abspath))
+    {
+      g_warning ("error in realpath(): \"%s\" causes %s",
+                 abspath,
+                 g_strerror (errno));
+    }
+  pixmap = sapwood_pixmap_get_for_file (abspath,
+                                        16, 16, 16, 16,
+                                        &error);
+  g_test_queue_destroy ((GFreeFunc) sapwood_pixmap_free, pixmap);
+  g_assert_no_error (error);
+
+  for (i = 0; i < G_N_ELEMENTS (rects); i++)
+    {
+      int col = i % 3;
+      int row = i / 3;
+
+      sapwood_pixmap_get_pixmap (pixmap, col, row,
+                                 &rects[i].pixmap, &rects[i].pixmask);
+
+      rects[i].dest.x = col < 1 ? 0 : col < 2 ? 16 : 200 - 16;
+      rects[i].dest.y = row < 1 ? 0 : row < 2 ? 16 : 200 - 16;
+      rects[i].dest.width =  col == 1 ? 200 - 2 * 16 : 16;
+      rects[i].dest.height = row == 1 ? 200 - 2 * 16 : 16;
+    }
+
+  drawable = create_pixmap (200, 200);
+
+  mask = gdk_pixmap_new (NULL, 100, 100, 1);
+  g_test_queue_unref (mask);
+
+  gdk_error_trap_push ();
+
+  sapwood_pixmap_render_rects (pixmap,
+                               GTK_TYPE_BUTTON,
+                               drawable,
+                               0, 0,
+                               200, 200,
+                               mask,
+                               -100, -100,
+                               TRUE,
+                               NULL,
+                               G_N_ELEMENTS (rects), rects);
+
+  gdk_flush ();
+  code = gdk_error_trap_pop ();
+  if (code)
+    {
+      XGetErrorText (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()),
+                     code,
+                     abspath,
+                     sizeof (abspath)); /* FIXME: check return code once we know _what_ it returns */
+      g_warning ("X11 error detected: %s (%d)", abspath, code);
+    }
+
+  result = gdk_pixbuf_get_from_drawable (NULL, drawable,
+                                         gdk_drawable_get_colormap (drawable),
+                                         100, 100, 0, 0,
+                                         100, 100);
+  g_test_queue_unref (result);
+
+  expected = gdk_pixbuf_new_from_file (TOP_SRCDIR G_DIR_SEPARATOR_S "tests" G_DIR_SEPARATOR_S "test-larger-masked-offset.png", &error);
+  g_assert_no_error (error);
+  g_test_queue_unref (expected);
+
+  assert_cmp_pixbuf (result, ==, expected);
+}
+
 int
 main (int   argc,
       char**argv)
@@ -196,6 +278,7 @@ main (int   argc,
 
   g_test_add_func ("/sapwood/pixmap/render-rects/larger", test_larger);
   g_test_add_func ("/sapwood/pixmap/render-rects/larger-masked", test_larger_masked);
+  g_test_add_func ("/sapwood/pixmap/render-rects/larger-masked-offset", test_larger_masked_offset);
 
   test_theme_pixbuf ();
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]