[sapwood] extract the tests for SapwoodPixmap
- From: Sven Herzberg <herzi src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [sapwood] extract the tests for SapwoodPixmap
- Date: Fri, 6 Aug 2010 12:06:48 +0000 (UTC)
commit 161a09f3ed08344bc5d474ddb896658761317c52
Author: Sven Herzberg <herzi gnome-de org>
Date: Fri Aug 6 11:45:33 2010 +0200
extract the tests for SapwoodPixmap
* tests/Makefile.am: updated
* tests/test-sapwood.c -> tests/test-sapwood-pixmap.c: have a dedicated
file for these tests
* tests/test-sapwood.c: only have a small core
* tests/test-sapwood.h: list the new function to add the SapwoodPixmap
tests
tests/Makefile.am | 1 +
tests/test-sapwood-pixmap.c | 282 +++++++++++++++++++++++++++++++++++++++++++
tests/test-sapwood.c | 253 +--------------------------------------
tests/test-sapwood.h | 3 +-
4 files changed, 287 insertions(+), 252 deletions(-)
---
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 230d3d0..bb9bfce 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -31,6 +31,7 @@ test_sapwood_SOURCES=\
test-framework.h \
test-sapwood.c \
test-sapwood.h \
+ test-sapwood-pixmap.c \
test-theme-pixbuf.c \
$(NULL)
diff --git a/tests/test-sapwood-pixmap.c b/tests/test-sapwood-pixmap.c
new file mode 100644
index 0000000..3da2f7c
--- /dev/null
+++ b/tests/test-sapwood-pixmap.c
@@ -0,0 +1,282 @@
+/* This file is part of sapwood
+ *
+ * Copyright (C) 2010 Sven Herzberg
+ *
+ * This work is provided "as is"; redistribution and modification
+ * in whole or in part, in any medium, physical or electronic is
+ * permitted without restriction.
+ *
+ * This work is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ *
+ * In no event shall the authors or contributors be liable for any
+ * direct, indirect, incidental, special, exemplary, or consequential
+ * damages (including, but not limited to, procurement of substitute
+ * goods or services; loss of use, data, or profits; or business
+ * interruption) however caused and on any theory of liability, whether
+ * in contract, strict liability, or tort (including negligence or
+ * otherwise) arising in any way out of the use of this software, even
+ * if advised of the possibility of such damage.
+ */
+
+#include "test-sapwood.h"
+
+#include <errno.h> /* errno */
+#include <stdlib.h> /* realpath() */
+#include <gdk/gdkx.h> /* GDK_DISPLAY_XDISPLAY() */
+#include <sapwood-pixmap.h>
+
+#include "test-framework.h"
+
+static void
+test_larger (void)
+{
+ SapwoodPixmap* pixmap;
+ SapwoodRect rects[9];
+ GdkDrawable * drawable = NULL;
+ GdkPixbuf * result;
+ GdkPixbuf * expected;
+ 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 "cropping-label1.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);
+
+ gdk_error_trap_push ();
+
+ sapwood_pixmap_render_rects (pixmap,
+ GTK_TYPE_BUTTON,
+ drawable,
+ 0, 0,
+ 200, 200,
+ NULL,
+ 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.png", &error);
+ g_assert_no_error (error);
+ g_test_queue_unref (expected);
+
+ assert_cmp_pixbuf (result, ==, expected);
+}
+
+static void
+test_larger_masked (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, 200, 200, 1);
+ g_test_queue_unref (mask);
+
+ gdk_error_trap_push ();
+
+ sapwood_pixmap_render_rects (pixmap,
+ GTK_TYPE_BUTTON,
+ drawable,
+ 0, 0,
+ 200, 200,
+ mask,
+ 0, 0,
+ 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),
+ 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);
+}
+
+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);
+}
+
+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);
+}
+
+/* vim:set et sw=2 cino=t0,f0,(0,{s,>2s,n-1s,^-1s,e2s: */
diff --git a/tests/test-sapwood.c b/tests/test-sapwood.c
index a64b819..3d4542d 100644
--- a/tests/test-sapwood.c
+++ b/tests/test-sapwood.c
@@ -20,255 +20,9 @@
* if advised of the possibility of such damage.
*/
-#include <errno.h> /* errno */
-#include <stdlib.h> /* realpath() */
-#include <sapwood-pixmap.h>
-#include <gdk/gdkx.h> /* GDK_DISPLAY_XDISPLAY() */
-
-#include "test-framework.h"
#include "test-sapwood.h"
-static void
-test_larger (void)
-{
- SapwoodPixmap* pixmap;
- SapwoodRect rects[9];
- GdkDrawable * drawable = NULL;
- GdkPixbuf * result;
- GdkPixbuf * expected;
- 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 "cropping-label1.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);
-
- gdk_error_trap_push ();
-
- sapwood_pixmap_render_rects (pixmap,
- GTK_TYPE_BUTTON,
- drawable,
- 0, 0,
- 200, 200,
- NULL,
- 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.png", &error);
- g_assert_no_error (error);
- g_test_queue_unref (expected);
-
- assert_cmp_pixbuf (result, ==, expected);
-}
-
-static void
-test_larger_masked (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, 200, 200, 1);
- g_test_queue_unref (mask);
-
- gdk_error_trap_push ();
-
- sapwood_pixmap_render_rects (pixmap,
- GTK_TYPE_BUTTON,
- drawable,
- 0, 0,
- 200, 200,
- mask,
- 0, 0,
- 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),
- 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);
-}
-
-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);
-}
+#include <gtk/gtk.h>
int
main (int argc,
@@ -276,10 +30,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);
- g_test_add_func ("/sapwood/pixmap/render-rects/larger-masked-offset", test_larger_masked_offset);
-
+ test_sapwood_pixmap ();
test_theme_pixbuf ();
return g_test_run ();
diff --git a/tests/test-sapwood.h b/tests/test-sapwood.h
index ea3633c..d10d902 100644
--- a/tests/test-sapwood.h
+++ b/tests/test-sapwood.h
@@ -27,7 +27,8 @@
G_BEGIN_DECLS
-void test_theme_pixbuf (void);
+void test_sapwood_pixmap (void);
+void test_theme_pixbuf (void);
G_END_DECLS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]