[Xcb-commit] xcb/tests .cvsignore, NONE, 1.1 CheckLog.xsl, NONE, 1.1 Makefile.am, NONE, 1.1 check_all.c, NONE, 1.1 check_public.c, NONE, 1.1 check_suites.h, NONE, 1.1

Jamey Sharp xcb-commit at lists.freedesktop.org
Thu Sep 29 22:39:03 PDT 2005


Update of /cvs/xcb/xcb/tests
In directory gabe:/tmp/cvs-serv18037/tests

Added Files:
	.cvsignore CheckLog.xsl Makefile.am check_all.c check_public.c 
	check_suites.h 
Log Message:
2005-09-30  Trevor Woerner <twoerner.x at gmail.com>

	reviewer: Jamey Sharp <jamey at minilop.net>

	* Makefile.am, configure.ac, src/Makefile.am, tests/Makefile.am,
	  src/check_all.c, src/check_public.c, src/check_suites.h:
	Created a new directory called "tests" where the unit tests
	will reside, separate from other files. Moved the unit
	test files from the "src" directory into the new "tests"
	directory.

	* configure.ac, tests/CheckLog.xsl, tests/.cvsignore,
	  tests/Makefile.am, tests/check_all.c:
	Added an XSLT transform to post-process the XML log file which
	is generated by the unit test suite into an HTML page. Added
	the necessary hooks into the build system to have this
	translation occur when necessary as part of the build process.


--- NEW FILE: .cvsignore ---
Makefile.in
CheckLog.html

--- NEW FILE: check_public.c ---
#include <check.h>
#include <string.h>
#include "check_suites.h"
#include "xcb.h"

/* XCBParseDisplay tests {{{ */

#define parse_display_pass(n,h,d,s) do_parse_display_pass(n,h,d,s,__FILE__,__LINE__)

static void do_parse_display_pass(const char *name, const char *host, const int display, const int screen,
		const char *file, const int line)
{
	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, file, line, "unexpected parse failure");
	_fail_unless(strcmp(host, got_host) == 0, file, line, "parse produced unexpected hostname");
	_fail_unless(display == got_display, file, line, "parse produced unexpected display");
	_fail_unless(screen == got_screen, file, line, "parse produced unexpected screen");

	if(screen)
		return;

	got_host = (char *) -1;
	got_display = got_screen = -42;
	mark_point();
	success = XCBParseDisplay(name, &got_host, &got_display, 0);
	_fail_unless(success, file, line, "unexpected screenless parse failure");
	_fail_unless(strcmp(host, got_host) == 0, file, line, "screenless parse produced unexpected hostname");
	_fail_unless(display == got_display, file, line, "screenless parse produced unexpected display");
}

#define parse_display_fail(n) do_parse_display_fail(n,__FILE__,__LINE__)

static void do_parse_display_fail(const char *name, const char *file, const int line)
{
	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, file, line, "unexpected parse success");
	_fail_unless(got_host == (char *) -1, file, line, "host changed on failure");
	_fail_unless(got_display == -42, file, line, "display changed on failure");
	_fail_unless(got_screen == -42, file, line, "screen changed on failure");

	got_host = (char *) -1;
	got_display = got_screen = -42;
	mark_point();
	success = XCBParseDisplay(name, &got_host, &got_display, 0);
	_fail_unless(!success, file, line, "unexpected screenless parse success");
	_fail_unless(got_host == (char *) -1, file, line, "host changed on failure");
	_fail_unless(got_display == -42, file, line, "display changed on failure");
}

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("");
	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");
	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;
}

--- NEW FILE: CheckLog.xsl ---
<?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>


--- NEW FILE: Makefile.am ---
########################
## 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

--- NEW FILE: check_all.c ---
#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;
}

--- NEW FILE: check_suites.h ---
#include <check.h>

void suite_add_test(Suite *s, TFun tf, const char *name);
Suite *public_suite(void);



More information about the xcb-commit mailing list