[sapwood] also add a test with a bitmask
- From: Sven Herzberg <herzi src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [sapwood] also add a test with a bitmask
- Date: Fri, 6 Aug 2010 12:05:23 +0000 (UTC)
commit 2e9a155718fcb573887fba99dbe014e039f953d8
Author: Sven Herzberg <sven herzberg lanedo com>
Date: Thu Aug 5 10:41:39 2010 +0200
also add a test with a bitmask
* tests/rendering.c: also implement a test with a bitmask to verify the
alpha channel rendering
* tests/test-larger-masked.png: the result of the new test case
* tests/test-source-alpha75.png: the same file as cropping-label1.png,
but with an overall alpha of 75%
tests/rendering.c | 95 +++++++++++++++++++++++++++++++++++++++++
tests/test-larger-masked.png | Bin 0 -> 952 bytes
tests/test-source-alpha75.png | Bin 0 -> 454 bytes
3 files changed, 95 insertions(+), 0 deletions(-)
---
diff --git a/tests/rendering.c b/tests/rendering.c
index 690b235..7b5d539 100644
--- a/tests/rendering.c
+++ b/tests/rendering.c
@@ -175,6 +175,100 @@ test_larger (void)
assert_cmp_pixbuf (result, ==, expected);
}
+static void
+test_larger_masked (void)
+{
+ SapwoodPixmap* pixmap;
+ SapwoodRect rects[9];
+ GdkColormap * colormap;
+ GdkDrawable * drawable = NULL;
+ GdkPixbuf * result;
+ GdkPixbuf * expected;
+ GdkBitmap * mask;
+ cairo_t * cr;
+ 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;
+ }
+
+ colormap = gdk_screen_get_system_colormap (gdk_screen_get_default ());
+ g_assert (colormap);
+
+ drawable = gdk_pixmap_new (NULL, 200, 200, gdk_colormap_get_visual (colormap)->depth);
+ g_test_queue_unref (drawable);
+ gdk_drawable_set_colormap (drawable, colormap);
+
+ mask = gdk_pixmap_new (NULL, 200, 200, 1);
+ g_test_queue_unref (mask);
+
+ cr = gdk_cairo_create (drawable);
+ cairo_set_source_rgb (cr, 1.0, 1.0, 1.0);
+ cairo_paint (cr);
+ cairo_destroy (cr);
+
+ gdk_error_trap_push ();
+
+ sapwood_pixmap_render_rects (pixmap,
+ GTK_TYPE_BUTTON,
+ drawable,
+ 0, 0,
+ 200, 200,
+ mask,
+ 0, 0,
+ FALSE,
+ 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),
+ 0, 0, 0, 0,
+ 200, 200);
+ 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.png", &error);
+ g_assert_no_error (error);
+ g_test_queue_unref (expected);
+
+ assert_cmp_pixbuf (result, ==, expected);
+}
+
int
main (int argc,
char**argv)
@@ -182,6 +276,7 @@ main (int argc,
gtk_test_init (&argc, &argv, NULL);
g_test_add_func ("/sapwood/pixmap/render-rects/larger", test_larger);
+ g_test_add_func ("/sapwood/pixmap/render-rects/larger-masked", test_larger_masked);
return g_test_run ();
}
diff --git a/tests/test-larger-masked.png b/tests/test-larger-masked.png
new file mode 100644
index 0000000..d35e2e5
Binary files /dev/null and b/tests/test-larger-masked.png differ
diff --git a/tests/test-source-alpha75.png b/tests/test-source-alpha75.png
new file mode 100644
index 0000000..2f289d3
Binary files /dev/null and b/tests/test-source-alpha75.png differ
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]