[PATCH] Add get-xrender-format test to test cairo_xlib_surface_get_xrender_format

Carl Worth cworth at cworth.org
Sun Jan 27 12:14:51 PST 2008


---
 test/.gitignore           |    1 +
 test/Makefile.am          |    5 ++
 test/get-xrender-format.c |  104 +++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 110 insertions(+), 0 deletions(-)
 create mode 100644 test/get-xrender-format.c

diff --git a/test/.gitignore b/test/.gitignore
index 15e66c2..51b64ac 100644
--- a/test/.gitignore
+++ b/test/.gitignore
@@ -72,6 +72,7 @@ get-and-set
 get-clip
 get-group-target
 get-path-extents
+get-render-format
 glyph-cache-pressure
 gradient-alpha
 gradient-zero-stops
diff --git a/test/Makefile.am b/test/Makefile.am
index fb56d4c..a425e91 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -58,6 +58,7 @@ get-and-set$(EXEEXT)					\
 get-clip$(EXEEXT)					\
 get-group-target$(EXEEXT)				\
 get-path-extents$(EXEEXT)				\
+get-xrender-format$(EXEEXT)				\
 gradient-alpha$(EXEEXT)					\
 gradient-zero-stops$(EXEEXT)				\
 infinite-join$(EXEEXT)					\
@@ -212,6 +213,10 @@ if CAIRO_HAS_XLIB_SURFACE
 TESTS += xlib-surface$(EXEEXT)
 endif

+if CAIRO_HAS_XLIB_XRENDER_SURFACE
+TESTS += get-xrender-format$(EXEEXT)
+endif
+
 if CAIRO_HAS_MULTI_PAGE_SURFACES
 TESTS += multi-page$(EXEEXT)
 endif
diff --git a/test/get-xrender-format.c b/test/get-xrender-format.c
new file mode 100644
index 0000000..3309f40
--- /dev/null
+++ b/test/get-xrender-format.c
@@ -0,0 +1,104 @@
+/*
+ * Copyright © 2008 Red Hat, Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use, copy,
+ * modify, merge, publish, distribute, sublicense, and/or sell copies
+ * of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ *
+ * Author: Carl D. Worth <cworth at cworth.org>
+ */
+
+#include "cairo-test.h"
+
+#include "cairo-xlib.h"
+#include "cairo-xlib-xrender.h"
+
+int
+main (void)
+{
+    Display *dpy;
+    XRenderPictFormat *orig_format, *format;
+    cairo_surface_t *surface;
+    Pixmap pixmap;
+    int screen;
+
+    cairo_test_init ("get-xrender-format");
+
+    dpy = XOpenDisplay (NULL);
+    if (! dpy) {
+	cairo_test_log ("Error: Cannot open display: %s.\n",
+			XDisplayName (NULL));
+	cairo_test_fini ();
+	return CAIRO_TEST_UNTESTED;
+    }
+
+    screen = DefaultScreen (dpy);
+
+    cairo_test_log ("Testing with image surface.\n");
+
+    surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, 1, 1);
+
+    format = cairo_xlib_surface_get_xrender_format (surface);
+    if (format != NULL) {
+	cairo_test_log ("Error: expected NULL for image surface\n");
+	return CAIRO_TEST_FAILURE;
+    }
+
+    cairo_surface_destroy (surface);
+
+    cairo_test_log ("Testing with non-xrender xlib surface.\n");
+
+    pixmap = XCreatePixmap (dpy, DefaultRootWindow (dpy),
+			    1, 1, DefaultDepth (dpy, screen));
+    surface = cairo_xlib_surface_create (dpy, pixmap,
+					 DefaultVisual (dpy, screen),
+					 1, 1);
+    orig_format = XRenderFindVisualFormat (dpy, DefaultVisual (dpy, screen));
+    format = cairo_xlib_surface_get_xrender_format (surface);
+    if (format != orig_format) {
+	cairo_test_log ("Error: did not receive the same format as XRenderFindVisualFormat\n");
+	return CAIRO_TEST_FAILURE;
+    }
+    cairo_surface_destroy (surface);
+    XFreePixmap (dpy, pixmap);
+
+    cairo_test_log ("Testing with xlib xrender surface.\n");
+
+    orig_format = XRenderFindStandardFormat (dpy, PictStandardARGB32);
+    pixmap = XCreatePixmap (dpy, DefaultRootWindow (dpy),
+			    1, 1, 32);
+    surface = cairo_xlib_surface_create_with_xrender_format (dpy,
+							     pixmap,
+							     DefaultScreenOfDisplay (dpy),
+							     orig_format,
+							     1, 1);
+    format = cairo_xlib_surface_get_xrender_format (surface);
+    if (format != orig_format) {
+	cairo_test_log ("Error: did not receive the same format originally set\n");
+	return CAIRO_TEST_FAILURE;
+    }
+
+    cairo_surface_destroy (surface);
+
+    XCloseDisplay (dpy);
+
+    cairo_test_fini ();
+
+    return CAIRO_TEST_SUCCESS;
+}
--
1.5.3.2


--Multipart_Sun_Jan_27_22:34:59_2008-1--

--pgp-sign-Multipart_Sun_Jan_27_22:34:59_2008-1
Content-Type: application/pgp-signature
Content-Transfer-Encoding: 7bit

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)

iD8DBQBHnXeT6JDdNq8qSWgRAlOhAJ9I19ePAiL30wfmpkQ9el+pBkIgxwCeNng6
/bz/AWcjnDFOOeZ0uweQe1o=
=2r53
-----END PGP SIGNATURE-----

--pgp-sign-Multipart_Sun_Jan_27_22:34:59_2008-1--


More information about the cairo mailing list