summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/.cvsignore2
-rw-r--r--tests/CheckLog.xsl104
-rw-r--r--tests/Makefile.am32
-rw-r--r--tests/check_all.c20
-rw-r--r--tests/check_public.c129
-rw-r--r--tests/check_suites.h4
6 files changed, 291 insertions, 0 deletions
diff --git a/tests/.cvsignore b/tests/.cvsignore
new file mode 100644
index 0000000..bfa26dd
--- /dev/null
+++ b/tests/.cvsignore
@@ -0,0 +1,2 @@
+Makefile.in
+CheckLog.html
diff --git a/tests/CheckLog.xsl b/tests/CheckLog.xsl
new file mode 100644
index 0000000..3daebaa
--- /dev/null
+++ b/tests/CheckLog.xsl
@@ -0,0 +1,104 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<xsl:stylesheet
+ version="1.0"
+ xmlns:check="http://check.sourceforge.net/ns"
+ xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+ xmlns="http://www.w3.org/TR/REC-html40">
+
+<xsl:output method="html"/>
+
+<xsl:template match="/">
+<html>
+ <head>
+ <title>Test Suite Results</title>
+ </head>
+
+ <body>
+ <xsl:apply-templates/>
+ </body>
+</html>
+</xsl:template>
+
+<xsl:template match="datetime">
+ <xsl:apply-templates/>
+</xsl:template>
+
+<xsl:template match="duration">
+ <xsl:apply-templates/>
+</xsl:template>
+
+<xsl:template match="check:suite">
+ <xsl:apply-templates select="check:title"/>
+ <center>
+ <table width="80%" border="1">
+ <thead>
+ <tr>
+ <td>Test Path</td>
+ <td>Test Function Location</td>
+ <td>C Identifier</td>
+ <td>Test Case</td>
+ <td>Result</td>
+ </tr>
+ </thead>
+ <tbody>
+ <xsl:apply-templates select="check:test"/>
+ </tbody>
+ </table>
+ </center>
+</xsl:template>
+
+<xsl:template match="check:testsuites">
+ <xsl:apply-templates select="check:suite"/>
+ <h3>Unit Test Statistics</h3>
+ <ul>
+ <li>date/time: <xsl:apply-templates select="check:datetime"/></li>
+ <li>duration: <xsl:apply-templates select="check:duration"/></li>
+ </ul>
+ <hr></hr>
+</xsl:template>
+
+<xsl:template match="check:title">
+ <h2>Test Suite: <xsl:apply-templates/></h2>
+</xsl:template>
+
+<xsl:template match="check:test[@result='success']">
+ <tr bgcolor="lime">
+ <xsl:apply-templates/>
+ </tr>
+</xsl:template>
+
+<xsl:template match="check:test[@result='failure']">
+ <tr bgcolor="red">
+ <xsl:apply-templates/>
+ </tr>
+</xsl:template>
+
+<xsl:template match="check:test[@result='error']">
+ <tr bgcolor="yellow">
+ <xsl:apply-templates/>
+ </tr>
+</xsl:template>
+
+<xsl:template match="check:path">
+ <td><xsl:apply-templates/></td>
+</xsl:template>
+
+<xsl:template match="check:fn">
+ <td><xsl:apply-templates/></td>
+</xsl:template>
+
+<xsl:template match="check:id">
+ <td><xsl:apply-templates/></td>
+</xsl:template>
+
+<xsl:template match="check:description">
+ <td><xsl:apply-templates/></td>
+</xsl:template>
+
+<xsl:template match="check:message">
+ <td><xsl:apply-templates/></td>
+</xsl:template>
+
+</xsl:stylesheet>
+
diff --git a/tests/Makefile.am b/tests/Makefile.am
new file mode 100644
index 0000000..fceaf13
--- /dev/null
+++ b/tests/Makefile.am
@@ -0,0 +1,32 @@
+########################
+## tests/Makefile.am
+########################
+SUBDIRS =
+EXTRA_DIST = CheckLog.xsl
+AM_MAKEFLAGS = -k
+AM_CFLAGS = -Wall -Werror $(XPROTO_CFLAGS) @CHECK_CFLAGS@ -I$(top_srcdir)/src
+LDADD = @CHECK_LIBS@ $(top_builddir)/src/libXCB.la
+
+if HAVE_CHECK
+TESTS = check_all
+check_PROGRAMS = check_all
+check_all_SOURCES = check_all.c check_suites.h check_public.c
+
+all-local::
+ $(RM) CheckLog*.xml
+
+check-local:
+ $(RM) CheckLog.html
+ if test x$(HTML_CHECK_RESULT) = xtrue; then \
+ $(XSLTPROC) $(srcdir)/CheckLog.xsl CheckLog*.xml > CheckLog.html; \
+ else \
+ touch CheckLog.html; \
+ fi
+
+CheckLog.html: $(check_PROGRAMS)
+ $(MAKE) $(AM_MAKEFLAGS) check;
+
+endif
+
+clean-local::
+ $(RM) CheckLog.html CheckLog*.txt CheckLog*.xml
diff --git a/tests/check_all.c b/tests/check_all.c
new file mode 100644
index 0000000..4393422
--- /dev/null
+++ b/tests/check_all.c
@@ -0,0 +1,20 @@
+#include <stdlib.h>
+#include "check_suites.h"
+
+void suite_add_test(Suite *s, TFun tf, const char *name)
+{
+ TCase *tc = tcase_create(name);
+ tcase_add_test(tc, tf);
+ suite_add_tcase(s, tc);
+}
+
+int main(void)
+{
+ int nf;
+ SRunner *sr = srunner_create(public_suite());
+ srunner_set_xml(sr, "CheckLog_xcb.xml");
+ srunner_run_all(sr, CK_NORMAL);
+ nf = srunner_ntests_failed(sr);
+ srunner_free(sr);
+ return (nf == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
+}
diff --git a/tests/check_public.c b/tests/check_public.c
new file mode 100644
index 0000000..9a32ba9
--- /dev/null
+++ b/tests/check_public.c
@@ -0,0 +1,129 @@
+#include <check.h>
+#include <string.h>
+#include <stdlib.h>
+#include "check_suites.h"
+#include "xcb.h"
+
+/* XCBParseDisplay tests {{{ */
+
+static void parse_display_pass(const char *name, const char *host, const int display, const int screen)
+{
+ int success;
+ char *got_host;
+ int got_display, got_screen;
+
+ got_host = (char *) -1;
+ got_display = got_screen = -42;
+ mark_point();
+ success = XCBParseDisplay(name, &got_host, &got_display, &got_screen);
+ fail_unless(success, "unexpected parse failure for '%s'", name);
+ fail_unless(strcmp(host, got_host) == 0, "parse produced unexpected hostname '%s' for '%s': expected '%s'", got_host, name, host);
+ fail_unless(display == got_display, "parse produced unexpected display '%d' for '%s': expected '%d'", got_display, name, display);
+ fail_unless(screen == got_screen, "parse produced unexpected screen '%d' for '%s': expected '%d'", got_screen, name, screen);
+
+ got_host = (char *) -1;
+ got_display = got_screen = -42;
+ mark_point();
+ success = XCBParseDisplay(name, &got_host, &got_display, 0);
+ fail_unless(success, "unexpected screenless parse failure for '%s'", name);
+ fail_unless(strcmp(host, got_host) == 0, "screenless parse produced unexpected hostname '%s' for '%s': expected '%s'", got_host, name, host);
+ fail_unless(display == got_display, "screenless parse produced unexpected display '%d' for '%s': expected '%d'", got_display, name, display);
+}
+
+static void parse_display_fail(const char *name)
+{
+ int success;
+ char *got_host;
+ int got_display, got_screen;
+
+ got_host = (char *) -1;
+ got_display = got_screen = -42;
+ mark_point();
+ success = XCBParseDisplay(name, &got_host, &got_display, &got_screen);
+ fail_unless(!success, "unexpected parse success for '%s'", name);
+ fail_unless(got_host == (char *) -1, "host changed on failure for '%s': got %p", got_host);
+ fail_unless(got_display == -42, "display changed on failure for '%s': got %d", got_display);
+ fail_unless(got_screen == -42, "screen changed on failure for '%s': got %d", got_screen);
+
+ got_host = (char *) -1;
+ got_display = got_screen = -42;
+ mark_point();
+ success = XCBParseDisplay(name, &got_host, &got_display, 0);
+ fail_unless(!success, "unexpected screenless parse success for '%s'", name);
+ fail_unless(got_host == (char *) -1, "host changed on failure for '%s': got %p", got_host);
+ fail_unless(got_display == -42, "display changed on failure for '%s': got %d", got_display);
+}
+
+START_TEST(parse_display_unix)
+{
+ parse_display_pass(":0", "", 0, 0);
+ parse_display_pass(":1", "", 1, 0);
+ parse_display_pass(":0.1", "", 0, 1);
+}
+END_TEST
+
+START_TEST(parse_display_ip)
+{
+ parse_display_pass("x.org:0", "x.org", 0, 0);
+ parse_display_pass("expo:0", "expo", 0, 0);
+ parse_display_pass("bigmachine:1", "bigmachine", 1, 0);
+ parse_display_pass("hydra:0.1", "hydra", 0, 1);
+}
+END_TEST
+
+START_TEST(parse_display_ipv4)
+{
+ parse_display_pass("198.112.45.11:0", "198.112.45.11", 0, 0);
+ parse_display_pass("198.112.45.11:0.1", "198.112.45.11", 0, 1);
+}
+END_TEST
+
+START_TEST(parse_display_ipv6)
+{
+ parse_display_pass("::1:0", "::1", 0, 0);
+ parse_display_pass("::1:0.1", "::1", 0, 1);
+ parse_display_pass("2002:83fc:d052::1:0", "2002:83fc:d052::1", 0, 0);
+ parse_display_pass("2002:83fc:d052::1:0.1", "2002:83fc:d052::1", 0, 1);
+}
+END_TEST
+
+START_TEST(parse_display_decnet)
+{
+ parse_display_pass("myws::0", "myws:", 0, 0);
+ parse_display_pass("big::1", "big:", 1, 0);
+ parse_display_pass("hydra::0.1", "hydra:", 0, 1);
+}
+END_TEST
+
+START_TEST(parse_display_negative)
+{
+ parse_display_fail(0);
+ parse_display_fail("");
+ parse_display_fail(":");
+ parse_display_fail("::");
+ parse_display_fail(":.");
+ parse_display_fail(":a");
+ parse_display_fail(":a.");
+ parse_display_fail(":0.");
+ parse_display_fail(":0.a");
+ parse_display_fail(":0.0.");
+
+ parse_display_fail("localhost");
+ parse_display_fail("localhost:");
+}
+END_TEST
+
+/* }}} */
+
+Suite *public_suite(void)
+{
+ Suite *s = suite_create("Public API");
+ putenv("DISPLAY");
+ suite_add_test(s, parse_display_unix, "XCBParseDisplay unix");
+ suite_add_test(s, parse_display_ip, "XCBParseDisplay ip");
+ suite_add_test(s, parse_display_ipv4, "XCBParseDisplay ipv4");
+ suite_add_test(s, parse_display_ipv6, "XCBParseDisplay ipv6");
+ suite_add_test(s, parse_display_decnet, "XCBParseDisplay decnet");
+ suite_add_test(s, parse_display_negative, "XCBParseDisplay negative");
+ return s;
+}
diff --git a/tests/check_suites.h b/tests/check_suites.h
new file mode 100644
index 0000000..499f1af
--- /dev/null
+++ b/tests/check_suites.h
@@ -0,0 +1,4 @@
+#include <check.h>
+
+void suite_add_test(Suite *s, TFun tf, const char *name);
+Suite *public_suite(void);