[sapwood] test the cropping on the SapwoodPixmap as well
- From: Sven Herzberg <herzi src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [sapwood] test the cropping on the SapwoodPixmap as well
- Date: Fri, 6 Aug 2010 12:07:19 +0000 (UTC)
commit f848305e4ff853c662f7949848e807e8c5592645
Author: Sven Herzberg <herzi gnome-de org>
Date: Fri Aug 6 14:01:50 2010 +0200
test the cropping on the SapwoodPixmap as well
* tests/test-sapwood-pixmap.c: add the new cropping test
tests/test-sapwood-pixmap.c | 84 +++++++++++++++++++++++++++++++++++++++++++
1 files changed, 84 insertions(+), 0 deletions(-)
---
diff --git a/tests/test-sapwood-pixmap.c b/tests/test-sapwood-pixmap.c
index 3da2f7c..ce984f2 100644
--- a/tests/test-sapwood-pixmap.c
+++ b/tests/test-sapwood-pixmap.c
@@ -271,12 +271,96 @@ test_larger_masked_offset (void)
assert_cmp_pixbuf (result, ==, expected);
}
+static void
+test_crop (void)
+{
+ SapwoodPixmap* pixmap;
+ SapwoodRect rects[9];
+ GdkRectangle clip_rect = {0, 0, 50, 50};
+ 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 : 70 - 16;
+ rects[i].dest.y = row < 1 ? 0 : row < 2 ? 16 : 70 - 16;
+ rects[i].dest.width = col == 1 ? 70 - 2 * 16 : 16;
+ rects[i].dest.height = row == 1 ? 70 - 2 * 16 : 16;
+ }
+
+ drawable = create_pixmap (50, 50);
+
+ mask = gdk_pixmap_new (NULL, 50, 50, 1);
+ g_test_queue_unref (mask);
+
+ gdk_error_trap_push ();
+
+ sapwood_pixmap_render_rects (pixmap,
+ GTK_TYPE_BUTTON,
+ drawable,
+ 0, 0,
+ 50, 50,
+ mask,
+ 0, 0,
+ FALSE,
+ &clip_rect,
+ 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,
+ 50, 50);
+ g_test_queue_unref (result);
+
+ expected = gdk_pixbuf_new_from_file (TOP_SRCDIR G_DIR_SEPARATOR_S "tests" G_DIR_SEPARATOR_S "theme-pixbuf-render-cropped.png", &error);
+ g_assert_no_error (error);
+ g_test_queue_unref (expected);
+
+ assert_cmp_pixbuf (result, ==, expected);
+}
+
void
test_sapwood_pixmap (void)
{
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);
+ g_test_add_func ("/sapwood/pixmap/render-rects/crop", test_crop);
}
/* vim:set et sw=2 cino=t0,f0,(0,{s,>2s,n-1s,^-1s,e2s: */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]