You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@apr.apache.org by da...@apache.org on 2007/08/05 17:38:29 UTC
svn commit: r562894 - in /apr/apr-util/trunk/test: Makefile.in Makefile.win
abts_tests.h testutil.h testxml.c
Author: davi
Date: Sun Aug 5 08:38:28 2007
New Revision: 562894
URL: http://svn.apache.org/viewvc?view=rev&rev=562894
Log:
Cleanup and merge testxml into the abts test suite (testall).
Modified:
apr/apr-util/trunk/test/Makefile.in
apr/apr-util/trunk/test/Makefile.win
apr/apr-util/trunk/test/abts_tests.h
apr/apr-util/trunk/test/testutil.h
apr/apr-util/trunk/test/testxml.c
Modified: apr/apr-util/trunk/test/Makefile.in
URL: http://svn.apache.org/viewvc/apr/apr-util/trunk/test/Makefile.in?view=diff&rev=562894&r1=562893&r2=562894
==============================================================================
--- apr/apr-util/trunk/test/Makefile.in (original)
+++ apr/apr-util/trunk/test/Makefile.in Sun Aug 5 08:38:28 2007
@@ -2,7 +2,7 @@
INCLUDES = @APRUTIL_PRIV_INCLUDES@ @APR_INCLUDES@ @APRUTIL_INCLUDES@
-PROGRAMS = testall testdbm testxml testrmm \
+PROGRAMS = testall testdbm testrmm \
testxlate dbd testssl \
echod sockperf
TARGETS = $(PROGRAMS)
@@ -46,11 +46,6 @@
testdbd: $(testdbd_OBJECTS) $(testdbd_LDADD)
$(LINK_PROG) $(APRUTIL_LDFLAGS) $(testdbd_OBJECTS) $(testdbd_LDADD) $(PROGRAM_DEPENDENCIES)
-testxml_OBJECTS = testxml.lo
-testxml_LDADD = $(TARGET_LIB_PATH)
-testxml: $(testxml_OBJECTS) $(testxml_LDADD)
- $(LINK_PROG) $(APRUTIL_LDFLAGS) $(testxml_OBJECTS) $(testxml_LDADD) $(PROGRAM_DEPENDENCIES)
-
testrmm_OBJECTS = testrmm.lo
testrmm_LDADD = $(TARGET_LIB_PATH)
testrmm: $(testrmm_OBJECTS) $(testrmm_LDADD)
@@ -80,7 +75,8 @@
testall_OBJECTS = teststrmatch.lo testuri.lo testuuid.lo abts.lo testutil.lo \
testbuckets.lo testpass.lo testmd4.lo testmd5.lo testldap.lo \
- testdate.lo testdbd.lo testmemcache.lo testreslist.lo testqueue.lo
+ testdate.lo testdbd.lo testmemcache.lo testreslist.lo testqueue.lo \
+ testxml.lo
testall_LDADD = $(TARGET_LIB_PATH)
testall: $(testall_OBJECTS) $(testall_LDADD)
$(LINK_PROG) $(APRUTIL_LDFLAGS) $(testall_OBJECTS) $(testall_LDADD) $(PROGRAM_DEPENDENCIES)
Modified: apr/apr-util/trunk/test/Makefile.win
URL: http://svn.apache.org/viewvc/apr/apr-util/trunk/test/Makefile.win?view=diff&rev=562894&r1=562893&r2=562894
==============================================================================
--- apr/apr-util/trunk/test/Makefile.win (original)
+++ apr/apr-util/trunk/test/Makefile.win Sun Aug 5 08:38:28 2007
@@ -113,16 +113,14 @@
##! $(OUTPUT_DIR)\teststrmatch.exe \
##! $(OUTPUT_DIR)\testuri.exe \
##! $(OUTPUT_DIR)\testuuid.exe \
-##! $(OUTPUT_DIR)\testxlate.exe \
-##! $(OUTPUT_DIR)\testxml.exe
+##! $(OUTPUT_DIR)\testxlate.exe
ALL_TARGETS = $(OUTPUT_DIR)\testxlate.exe \
$(OUTPUT_DIR)\testdbm.exe \
$(OUTPUT_DIR)\testqueue.exe \
$(OUTPUT_DIR)\testrmm.exe \
$(OUTPUT_DIR)\testmd4.exe \
- $(OUTPUT_DIR)\testmd5.exe \
- $(OUTPUT_DIR)\testxml.exe
+ $(OUTPUT_DIR)\testmd5.exe
all: $(ALL_TARGETS)
Modified: apr/apr-util/trunk/test/abts_tests.h
URL: http://svn.apache.org/viewvc/apr/apr-util/trunk/test/abts_tests.h?view=diff&rev=562894&r1=562893&r2=562894
==============================================================================
--- apr/apr-util/trunk/test/abts_tests.h (original)
+++ apr/apr-util/trunk/test/abts_tests.h Sun Aug 5 08:38:28 2007
@@ -35,7 +35,8 @@
{testdate},
{testmemcache},
{testreslist},
- {testqueue}
+ {testqueue},
+ {testxml}
};
#endif /* APR_TEST_INCLUDES */
Modified: apr/apr-util/trunk/test/testutil.h
URL: http://svn.apache.org/viewvc/apr/apr-util/trunk/test/testutil.h?view=diff&rev=562894&r1=562893&r2=562894
==============================================================================
--- apr/apr-util/trunk/test/testutil.h (original)
+++ apr/apr-util/trunk/test/testutil.h Sun Aug 5 08:38:28 2007
@@ -56,5 +56,6 @@
abts_suite *testmemcache(abts_suite *suite);
abts_suite *testreslist(abts_suite *suite);
abts_suite *testqueue(abts_suite *suite);
+abts_suite *testxml(abts_suite *suite);
#endif /* APR_TEST_INCLUDES */
Modified: apr/apr-util/trunk/test/testxml.c
URL: http://svn.apache.org/viewvc/apr/apr-util/trunk/test/testxml.c?view=diff&rev=562894&r1=562893&r2=562894
==============================================================================
--- apr/apr-util/trunk/test/testxml.c (original)
+++ apr/apr-util/trunk/test/testxml.c Sun Aug 5 08:38:28 2007
@@ -17,203 +17,143 @@
#include "apr.h"
#include "apr_general.h"
#include "apr_xml.h"
+#include "abts.h"
+#include "testutil.h"
-#if APR_HAVE_STDLIB_H
-#include <stdlib.h> /* for exit() */
-#endif
-
-static const char *progname;
-static const char *usage = "%s [xmlfile]\nIt will create "
- "a dummy XML file if none is supplied";
-/*
- * If our platform knows about the tmpnam() external buffer size, create
- * a buffer to pass in. This is needed in a threaded environment, or
- * one that thinks it is (like HP-UX).
- */
-
-#ifdef L_tmpnam
-static char tname_buf[L_tmpnam];
-#else
-static char *tname_buf = NULL;
-#endif
-
-static apr_status_t create_dummy_file_error(apr_pool_t *p, apr_file_t **fd)
+static apr_status_t create_dummy_file_error(abts_case *tc, apr_pool_t *p,
+ apr_file_t **fd)
{
- apr_status_t rv;
- char *tmpfile;
int i;
+ apr_status_t rv;
apr_off_t off = 0L;
- tmpfile = tmpnam(tname_buf);
+ char template[] = "data/testxmldummyerrorXXXXXX";
- if ((tmpfile == NULL) || (*tmpfile == '\0')) {
- fprintf(stderr, "unable to generate temporary filename\n");
- if (errno == 0) {
- errno = ENOENT;
- }
- perror("tmpnam");
- return APR_ENOENT;
- }
- rv = apr_file_open(fd, tmpfile, APR_CREATE|APR_TRUNCATE|APR_DELONCLOSE|
- APR_READ|APR_WRITE|APR_EXCL, APR_OS_DEFAULT, p);
+ rv = apr_file_mktemp(fd, template, APR_CREATE | APR_TRUNCATE | APR_DELONCLOSE |
+ APR_READ | APR_WRITE | APR_EXCL, p);
+ ABTS_INT_EQUAL(tc, rv, APR_SUCCESS);
if (rv != APR_SUCCESS)
return rv;
+
rv = apr_file_puts("<?xml version=\"1.0\" ?>\n<maryx>"
"<had a=\"little\"/><lamb its='fleece "
"was white as snow' />\n", *fd);
- if (rv != APR_SUCCESS)
- return rv;
+ ABTS_INT_EQUAL(tc, rv, APR_SUCCESS);
for (i = 0; i < 5000; i++) {
rv = apr_file_puts("<hmm roast=\"lamb\" "
"for=\"dinner\">yummy</hmm>\n", *fd);
- if (rv != APR_SUCCESS)
- return rv;
+ ABTS_INT_EQUAL(tc, rv, APR_SUCCESS);
}
+
rv = apr_file_puts("</mary>\n", *fd);
- if (rv != APR_SUCCESS)
- return rv;
+ ABTS_INT_EQUAL(tc, rv, APR_SUCCESS);
+
+ rv = apr_file_seek(*fd, APR_SET, &off);
+ ABTS_INT_EQUAL(tc, rv, APR_SUCCESS);
- return apr_file_seek(*fd, APR_SET, &off);
+ return rv;
}
-static apr_status_t create_dummy_file(apr_pool_t *p, apr_file_t **fd)
+static apr_status_t create_dummy_file(abts_case *tc, apr_pool_t *p,
+ apr_file_t **fd)
{
- apr_status_t rv;
- char *tmpfile;
int i;
+ apr_status_t rv;
apr_off_t off = 0L;
- tmpfile = tmpnam(tname_buf);
+ char template[] = "data/testxmldummyXXXXXX";
- if ((tmpfile == NULL) || (*tmpfile == '\0')) {
- fprintf(stderr, "unable to generate temporary filename\n");
- if (errno == 0) {
- errno = ENOENT;
- }
- perror("tmpnam");
- return APR_ENOENT;
- }
- rv = apr_file_open(fd, tmpfile, APR_CREATE|APR_TRUNCATE|APR_DELONCLOSE|
- APR_READ|APR_WRITE|APR_EXCL, APR_OS_DEFAULT, p);
+ rv = apr_file_mktemp(fd, template, APR_CREATE | APR_TRUNCATE | APR_DELONCLOSE |
+ APR_READ | APR_WRITE | APR_EXCL, p);
+ ABTS_INT_EQUAL(tc, rv, APR_SUCCESS);
if (rv != APR_SUCCESS)
return rv;
- rv = apr_file_puts("<?xml version=\"1.0\" ?>\n<mary>"
- "<had a=\"little\"/><lamb its='fleece "
- "was white as snow' />\n", *fd);
- if (rv != APR_SUCCESS)
- return rv;
+
+ rv = apr_file_puts("<?xml version=\"1.0\" ?>\n<mary>\n", *fd);
+ ABTS_INT_EQUAL(tc, rv, APR_SUCCESS);
for (i = 0; i < 5000; i++) {
rv = apr_file_puts("<hmm roast=\"lamb\" "
"for=\"dinner\">yummy</hmm>\n", *fd);
- if (rv != APR_SUCCESS)
- return rv;
+ ABTS_INT_EQUAL(tc, rv, APR_SUCCESS);
}
+
rv = apr_file_puts("</mary>\n", *fd);
- if (rv != APR_SUCCESS)
- return rv;
+ ABTS_INT_EQUAL(tc, rv, APR_SUCCESS);
rv = apr_file_seek(*fd, APR_SET, &off);
+ ABTS_INT_EQUAL(tc, rv, APR_SUCCESS);
+
return rv;
}
-static void dump_xml(apr_xml_elem *e, int level)
+static void dump_xml(abts_case *tc, apr_xml_elem *e, int level)
{
apr_xml_attr *a;
apr_xml_elem *ec;
- printf("%d: element %s\n", level, e->name);
+ if (level == 0) {
+ ABTS_STR_EQUAL(tc, e->name, "mary");
+ } else {
+ ABTS_STR_EQUAL(tc, e->name, "hmm");
+ }
+
if (e->attr) {
a = e->attr;
- printf("%d:\tattrs\t", level);
- while (a) {
- printf("%s=%s\t", a->name, a->value);
- a = a->next;
- }
- printf("\n");
+ ABTS_PTR_NOTNULL(tc, a);
+ ABTS_STR_EQUAL(tc, a->name, "for");
+ ABTS_STR_EQUAL(tc, a->value, "dinner");
+ a = a->next;
+ ABTS_PTR_NOTNULL(tc, a);
+ ABTS_STR_EQUAL(tc, a->name, "roast");
+ ABTS_STR_EQUAL(tc, a->value, "lamb");
}
if (e->first_child) {
ec = e->first_child;
while (ec) {
- dump_xml(ec, level + 1);
+ dump_xml(tc, ec, level + 1);
ec = ec->next;
}
}
}
-static void oops(const char *s1, const char *s2, apr_status_t rv)
+static void test_xml_parser(abts_case *tc, void *data)
{
- if (progname)
- fprintf(stderr, "%s: ", progname);
- fprintf(stderr, s1, s2);
- if (rv != APR_SUCCESS) {
- char buf[120];
-
- fprintf(stderr, " (%s)", apr_strerror(rv, buf, sizeof buf));
- }
- fprintf(stderr, "\n");
- exit(1);
-}
-
-int main(int argc, const char *const * argv)
-{
- apr_pool_t *pool;
apr_file_t *fd;
apr_xml_parser *parser;
apr_xml_doc *doc;
apr_status_t rv;
- char errbuf[2000];
- char errbufXML[2000];
- (void) apr_initialize();
- apr_pool_create(&pool, NULL);
- progname = argv[0];
- if (argc == 1) {
- rv = create_dummy_file(pool, &fd);
- if (rv != APR_SUCCESS) {
- oops("cannot create dummy file", "oops", rv);
- }
- }
- else {
- if (argc == 2) {
- rv = apr_file_open(&fd, argv[1], APR_READ, APR_OS_DEFAULT, pool);
- if (rv != APR_SUCCESS) {
- oops("cannot open: %s", argv[1], rv);
- }
- }
- else {
- oops("usage: %s", usage, 0);
- }
- }
- rv = apr_xml_parse_file(pool, &parser, &doc, fd, 2000);
- if (rv != APR_SUCCESS) {
- fprintf(stderr, "APR Error %s\nXML Error: %s\n",
- apr_strerror(rv, errbuf, sizeof(errbuf)),
- apr_xml_parser_geterror(parser, errbufXML, sizeof(errbufXML)));
- return rv;
- }
- dump_xml(doc->root, 0);
- apr_file_close(fd);
- if (argc == 1) {
- rv = create_dummy_file_error(pool, &fd);
- if (rv != APR_SUCCESS) {
- oops("cannot create error dummy file", "oops", rv);
- }
- rv = apr_xml_parse_file(pool, &parser, &doc, fd, 2000);
- if (rv != APR_SUCCESS) {
- fprintf(stdout, "APR Error %s\nXML Error: %s "
- "(EXPECTED) This is good.\n",
- apr_strerror(rv, errbuf, sizeof(errbuf)),
- apr_xml_parser_geterror(parser, errbufXML, sizeof(errbufXML)));
- rv = APR_SUCCESS; /* reset the return code, as the test is supposed to get this error */
- }
- else {
- fprintf(stderr, "Expected an error, but didn't get one ;( ");
- return APR_EGENERAL;
- }
- }
- apr_pool_destroy(pool);
- apr_terminate();
- return rv;
+ rv = create_dummy_file(tc, p, &fd);
+ ABTS_INT_EQUAL(tc, rv, APR_SUCCESS);
+
+ if (rv != APR_SUCCESS)
+ return;
+
+ rv = apr_xml_parse_file(p, &parser, &doc, fd, 2000);
+ ABTS_INT_EQUAL(tc, rv, APR_SUCCESS);
+
+ dump_xml(tc, doc->root, 0);
+
+ rv = apr_file_close(fd);
+ ABTS_INT_EQUAL(tc, rv, APR_SUCCESS);
+
+ rv = create_dummy_file_error(tc, p, &fd);
+ ABTS_INT_EQUAL(tc, rv, APR_SUCCESS);
+
+ if (rv != APR_SUCCESS)
+ return;
+
+ rv = apr_xml_parse_file(p, &parser, &doc, fd, 2000);
+ ABTS_TRUE(tc, rv != APR_SUCCESS);
+}
+
+abts_suite *testxml(abts_suite *suite)
+{
+ suite = ADD_SUITE(suite);
+
+ abts_run_test(suite, test_xml_parser, NULL);
+
+ return suite;
}