[PATCH xrandr-utils 4/6] Add unit test suite and a basic test of the geometry structs.

Bryce Harrington bryce at canonical.com
Wed Dec 21 18:47:11 PST 2011


This follows the style of the X server test suite, using autoconf's
built-in support for make check using asserts.

The first test trivially checks the geometry structures.

Signed-off-by: Bryce Harrington <bryce at canonical.com>
---
 configure.ac     |    1 +
 test/.gitignore  |    2 +
 test/Makefile.am |   14 +++++++++
 test/README      |   14 +++++++++
 test/geometry.c  |   84 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 5 files changed, 115 insertions(+), 0 deletions(-)
 create mode 100644 test/.gitignore
 create mode 100644 test/Makefile.am
 create mode 100644 test/README
 create mode 100644 test/geometry.c

diff --git a/configure.ac b/configure.ac
index 7ebefd8..7d11ec0 100644
--- a/configure.ac
+++ b/configure.ac
@@ -58,5 +58,6 @@ AC_CONFIG_FILES([
 	examples/Makefile
 	man/Makefile
 	src/Makefile
+	test/Makefile
 	xrandr-utils.pc])
 AC_OUTPUT
diff --git a/test/.gitignore b/test/.gitignore
new file mode 100644
index 0000000..953f2c7
--- /dev/null
+++ b/test/.gitignore
@@ -0,0 +1,2 @@
+geometry
+xrandr
diff --git a/test/Makefile.am b/test/Makefile.am
new file mode 100644
index 0000000..2f299bd
--- /dev/null
+++ b/test/Makefile.am
@@ -0,0 +1,14 @@
+check_PROGRAMS = geometry
+
+TESTS = $(check_PROGRAMS)
+
+AM_CFLAGS = \
+	$(RANDRUTILS_CFLAGS) \
+	$(MALLOC_ZERO_CFLAGS) \
+	$(CWARNFLAGS)
+
+INCLUDES = -I$(top_srcdir)/include/X11/extensions
+
+TEST_LDADD = @RANDRUTILS_LIBS@
+
+geometry_LDADD = $(TEST_LDADD)
diff --git a/test/README b/test/README
new file mode 100644
index 0000000..720a315
--- /dev/null
+++ b/test/README
@@ -0,0 +1,14 @@
+                       libXrandrUtils test suite
+
+This suite contains a set of tests to verify the behavior of the
+XrandrUtils API.  This suite follows the conventions of the X server
+test suite.
+
+= How to run the tests =
+Run "make check" in the test directory.  This will compile the tests and
+execute them in the order specified by the TESTS variable in
+test/Makefile.am.
+
+== Adding a new test ==
+When adding a new test, ensure that you add a short description of what
+the test does and what the expected outcome is.
diff --git a/test/geometry.c b/test/geometry.c
new file mode 100644
index 0000000..1db2eda
--- /dev/null
+++ b/test/geometry.c
@@ -0,0 +1,84 @@
+/**
+ * Copyright © 2011 Canonical, Ltd.
+ *
+ *  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 (including the next
+ *  paragraph) 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.
+ */
+
+/**
+ * Test that API calls generate the expected RANDR operations would be
+ * sent to X.
+ */
+
+#include <assert.h>
+
+#include "XrandrUtils.h"
+
+/**
+ * Verify XRUPoint struct members
+ */
+static void geometry_point(void)
+{
+    XRUPoint p;
+    p.x = 1;
+    p.y = -1;
+
+    assert(p.x == 1);
+    assert(p.y == -1);
+}
+
+/**
+ * Verify XRUBox struct members
+ */
+static void geometry_box(void)
+{
+    XRUBox b;
+    b.x1 = b.y1 = 0;
+    b.x2 = b.y2 = 100;
+
+    assert(b.x1 == 0);
+    assert(b.y1 == 0);
+    assert(b.x2 == 100);
+    assert(b.y2 == 100);
+}
+
+/**
+ * Verify XRURectangle
+ */
+static void geometry_rectangle(void)
+{
+    XRURectangle r;
+    r.x = r.y = 0;
+    r.width = 640;
+    r.height = 480;
+
+    assert(r.x == 0);
+    assert(r.y == 0);
+    assert(r.width == 640);
+    assert(r.height == 480);
+}
+
+int main(int argc, char** argv)
+{
+    geometry_point();
+    geometry_box();
+    geometry_rectangle();
+
+    return 0;
+}
-- 
1.7.4.1



More information about the xorg-devel mailing list