httpd-apreq-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From j...@apache.org
Subject svn commit: r153591 - in httpd/apreq/branches/multi-env-unstable: CHANGES Makefile.am t/CuTest.c t/CuTest.h t/Makefile.am t/README t/at.c t/at.h t/cookie.c t/params.c t/parsers.c t/test_apreq.h t/testall.c t/version.c
Date Sun, 13 Feb 2005 03:32:41 GMT
Author: joes
Date: Sat Feb 12 19:32:38 2005
New Revision: 153591

URL: http://svn.apache.org/viewcvs?view=rev&rev=153591
Log:

Replace CuTest-based tests with custom TAP-compliant framework.
This is a straight port of trunk's r153577 to branches/multi-env-unstable.

Added:
    httpd/apreq/branches/multi-env-unstable/t/at.c
    httpd/apreq/branches/multi-env-unstable/t/at.h
Removed:
    httpd/apreq/branches/multi-env-unstable/t/CuTest.c
    httpd/apreq/branches/multi-env-unstable/t/CuTest.h
    httpd/apreq/branches/multi-env-unstable/t/README
    httpd/apreq/branches/multi-env-unstable/t/test_apreq.h
    httpd/apreq/branches/multi-env-unstable/t/testall.c
Modified:
    httpd/apreq/branches/multi-env-unstable/CHANGES
    httpd/apreq/branches/multi-env-unstable/Makefile.am
    httpd/apreq/branches/multi-env-unstable/t/Makefile.am
    httpd/apreq/branches/multi-env-unstable/t/cookie.c
    httpd/apreq/branches/multi-env-unstable/t/params.c
    httpd/apreq/branches/multi-env-unstable/t/parsers.c
    httpd/apreq/branches/multi-env-unstable/t/version.c

Modified: httpd/apreq/branches/multi-env-unstable/CHANGES
URL: http://svn.apache.org/viewcvs/httpd/apreq/branches/multi-env-unstable/CHANGES?view=diff&r1=153590&r2=153591
==============================================================================
--- httpd/apreq/branches/multi-env-unstable/CHANGES (original)
+++ httpd/apreq/branches/multi-env-unstable/CHANGES Sat Feb 12 19:32:38 2005
@@ -5,6 +5,9 @@
 @section v2_05 Changes with libapreq2-2.05
 
 
+- C Tests [joes]
+  Replace CuTest-based tests with custom TAP-compliant framework.
+
 - C API [Max Kellermann]
   Continue the API improvements:
 

Modified: httpd/apreq/branches/multi-env-unstable/Makefile.am
URL: http://svn.apache.org/viewcvs/httpd/apreq/branches/multi-env-unstable/Makefile.am?view=diff&r1=153590&r2=153591
==============================================================================
--- httpd/apreq/branches/multi-env-unstable/Makefile.am (original)
+++ httpd/apreq/branches/multi-env-unstable/Makefile.am Sat Feb 12 19:32:38 2005
@@ -78,13 +78,13 @@
 	-mkdir docs
 	echo GENERATE_TAGFILE=`pwd`/docs/apr.tag | $(APR_DOX)
 
-test: lib_test env_test $(PERL_TEST)
+test: all lib_test env_test $(PERL_TEST)
 
 env_test:
 	cd env; $(MAKE) test
 
-lib_test: check
-	t/testall -v
+lib_test:
+	cd t; $(MAKE) test
 
 perl_install:
 	cd glue/perl; $(MAKE) install

Modified: httpd/apreq/branches/multi-env-unstable/t/Makefile.am
URL: http://svn.apache.org/viewcvs/httpd/apreq/branches/multi-env-unstable/t/Makefile.am?view=diff&r1=153590&r2=153591
==============================================================================
--- httpd/apreq/branches/multi-env-unstable/t/Makefile.am (original)
+++ httpd/apreq/branches/multi-env-unstable/t/Makefile.am Sat Feb 12 19:32:38 2005
@@ -2,11 +2,20 @@
 LIBS = ../src/libapreq2.la @APR_LTLIBS@ @APU_LTLIBS@
 LDFLAGS = @APR_LDFLAGS@ @APU_LDFLAGS@
 
-noinst_LIBRARIES = libapreq2_tests.a
-libapreq2_tests_a_SOURCES = test_apreq.h CuTest.h CuTest.c version.c cookie.c params.c parsers.c
+noinst_LIBRARIES = libapreq2_test.a
+libapreq2_test_a_SOURCES = at.h at.c
 
-check_PROGRAMS = testall
-testall_LDADD  = libapreq2_tests.a
+check_PROGRAMS = version cookie params parsers
+LDADD  = libapreq2_test.a
 
-test:	check
-	./testall -v
+check_SCRIPTS = version.t cookie.t params.t parsers.t
+TESTS = $(check_SCRIPTS)
+TESTS_ENVIRONMENT = @PERL@ -MTest::Harness -e 'runtests(@ARGV)'
+CLEANFILES = $(check_SCRIPTS)
+
+%.t: %
+	echo "#!perl" > $@
+	echo "exec './$*'" >> $@
+
+test: $(check_SCRIPTS)
+	$(TESTS_ENVIRONMENT) $(check_SCRIPTS)

Added: httpd/apreq/branches/multi-env-unstable/t/at.c
URL: http://svn.apache.org/viewcvs/httpd/apreq/branches/multi-env-unstable/t/at.c?view=auto&rev=153591
==============================================================================
--- httpd/apreq/branches/multi-env-unstable/t/at.c (added)
+++ httpd/apreq/branches/multi-env-unstable/t/at.c Sat Feb 12 19:32:38 2005
@@ -0,0 +1,338 @@
+/*
+**  Copyright 2004-2005  The Apache Software Foundation
+**
+**  Licensed under the Apache License, Version 2.0 (the "License");
+**  you may not use this file except in compliance with the License.
+**  You may obtain a copy of the License at
+**
+**      http://www.apache.org/licenses/LICENSE-2.0
+**
+**  Unless required by applicable law or agreed to in writing, software
+**  distributed under the License is distributed on an "AS IS" BASIS,
+**  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+**  See the License for the specific language governing permissions and
+**  limitations under the License.
+*/
+
+#include "apr_file_io.h"
+#include "at.h"
+#include "apr_lib.h"
+#include "apr_strings.h"
+#include "apr_tables.h"
+#include "apr_env.h"
+#include <assert.h>
+
+
+apr_status_t at_begin(at_t *t, int total)
+{
+    char buf[32];
+    apr_snprintf(buf, 32, "1..%d", total);
+    return at_report(t, buf);
+}
+
+static apr_status_t test_cleanup(void *data)
+{
+    at_t *t = data;
+    if (t->current < t->plan)
+        return at_report(t, "Bail out!");
+    else
+        return at_report(t, "END"); 
+}
+
+void at_end(at_t *t)
+{     
+    apr_pool_cleanup_kill(t->pool, t, test_cleanup);
+    test_cleanup(t);
+}
+
+apr_status_t at_comment(at_t *t, const char *fmt, va_list vp)
+{
+    apr_status_t s;
+    char buf[256], *b = buf + 2;
+    char *end;
+    int rv;
+    rv = apr_vsnprintf(b, 250, fmt, vp);
+
+    if (rv <= 0)
+        return APR_EINVAL;
+
+    end = b + rv;
+
+    buf[0] = '#';
+    buf[1] = ' ';
+
+    if (rv == 250) {
+        *end++ = '.';
+        *end++ = '.';
+        *end++ = '.';
+        *end = '\n';
+    }
+    else if (end[-1] != '\n') {
+        *end = '\n';
+    }
+
+    b = buf;
+    while (1) {
+        char *eol;
+
+        eol = strchr(b + 2, '\n');
+        assert(eol != NULL);
+        *eol = 0;
+        s = at_report(t, b);
+        if (s != APR_SUCCESS || eol == end)
+            break;
+
+        b    = eol - 1;
+        b[0] = '#';
+        b[1] = ' ';
+    }
+
+    return s;
+} 
+
+void at_ok(at_t *t, int is_ok, const char *label, const char *file, int line)
+{
+    char format[] = "not ok %d - %s # %s (%s:%d) test %d in %s";
+    char *end = format + 10;
+    char *fmt = is_ok ? format + 4 : format;
+    char buf[256];
+    const char *comment = NULL;
+    int rv, is_fatal = 0, is_skip = 0, is_todo = 0;
+
+    t->current++;
+      
+    if (*t->fatal == t->current) {
+        t->fatal++;
+        is_fatal = 1;
+    }
+
+    if (*t->skip == t->current) {
+        t->skip++;
+        is_skip = 1;
+    }
+
+    if (*t->todo == t->current) {
+        t->todo++;
+        is_todo = 1;
+    }
+
+    if (AT_FLAG_CONCISE(t->flags))
+        format[9] = '\0';
+    else if (is_ok && !AT_FLAG_TRACE(t->flags))
+        format[14] = '\0';
+    else if (is_fatal && ! is_ok)
+        comment = "bail";
+    else
+        comment = is_todo ? "todo" : is_skip ? "skip" : "at";
+
+    rv = apr_snprintf(buf, 256, fmt, t->current + t->prior, 
+                      label, comment,  file, line, t->current, t->name);
+
+    if (rv <= 0)
+        exit(-1);
+
+    end = buf + rv;
+
+    if (rv == 250) {
+        *end++ = '.';
+        *end++ = '.';
+        *end++ = '.';
+        *end = '\0';
+    }
+
+    if (memchr(buf, '\n', rv) != NULL || at_report(t, buf) != APR_SUCCESS)
+        exit(-1);
+
+    if (!is_ok && is_fatal) {
+        if (t->abort != NULL) {
+            at_trace(t, "Abandon %s, omitting tests %d - %d from this run.",
+                     t->name, t->prior + t->current + 1, t->prior + t->plan);
+            longjmp(*t->abort, 0);
+        }
+        else {
+            apr_pool_cleanup_kill(t->pool, t, test_cleanup);
+            at_report(t, "Bail out!");
+            exit(-1);
+        }
+    }
+}
+
+struct at_report_file {
+    at_report_t module;
+    apr_file_t *file;
+};
+
+
+static apr_status_t at_report_file_write(at_report_t *ctx, const char *msg)
+{
+    struct at_report_file *r = (struct at_report_file *)ctx;
+    apr_file_t *f = r->file;
+    apr_size_t len = strlen(msg);
+    apr_status_t s;
+
+    s = apr_file_write_full(f, msg, len, &len);
+    if (s != APR_SUCCESS)
+        return s;
+
+    s = apr_file_putc('\n', f);
+    if (s != APR_SUCCESS)
+        return s;
+
+    return apr_file_flush(f);
+}
+
+at_report_t *at_report_file_make(apr_pool_t *p, apr_file_t *f)
+{
+    struct at_report_file *r = apr_palloc(p, sizeof *r);
+    r->module.func = at_report_file_write;
+    r->file = f;
+    return &r->module;
+}
+
+
+
+struct at_report_local {
+    at_report_t  module;
+    at_t        *t;
+    at_report_t *saved_report;
+    const int   *saved_fatal;
+    int          dummy_fatal;
+    const char  *file;
+    int          line;
+    int          passed;
+    apr_pool_t  *pool;
+};
+
+
+static apr_status_t report_local_cleanup(void *data)
+{
+    struct at_report_local *q = data;
+    dAT = q->t;
+    char label[32];
+
+    apr_snprintf(label, 32, "collected %d passing tests", q->passed);
+
+    AT->report = q->saved_report;
+    AT->fatal = q->saved_fatal;
+
+    at_ok(q->t, 1, label, q->file, q->line);
+    return APR_SUCCESS;
+}
+
+
+static apr_status_t at_report_local_write(at_report_t *ctx, const char *msg)
+{
+    struct at_report_local *q = (struct at_report_local *)ctx;
+    dAT = q->t;
+
+    if (strncmp(msg, "not ok", 6) == 0) {
+        q->saved_report->func(q->saved_report, msg);
+        AT->report = q->saved_report;
+        AT->fatal = q->saved_fatal;
+        apr_pool_cleanup_kill(q->pool, q, report_local_cleanup);
+        at_trace(AT, "Abandon %s, omitting tests %d - %d from this run.",
+                 AT->name, AT->prior + AT->current + 1, AT->prior + AT->plan);
+        longjmp(*AT->abort, 0);
+    }
+    AT->current--;
+    q->passed++;
+    return APR_SUCCESS;
+}
+
+void at_report_local(at_t *AT, apr_pool_t *p, const char *file, int line)
+{
+    struct at_report_local *q = apr_palloc(p, sizeof *q);
+    q->module.func = at_report_local_write;
+    q->t = AT;
+    q->saved_report = AT->report;
+    q->saved_fatal = AT->fatal;
+    q->dummy_fatal = 0;
+    q->file = apr_pstrdup(p, file);
+    q->line = line;
+    q->passed = 0;
+    q->pool = p;
+
+    AT->fatal = &q->dummy_fatal;
+    AT->report = &q->module;
+
+    if (*q->saved_fatal == AT->current + 1)
+        q->saved_fatal++;
+
+    apr_pool_cleanup_register(p, q, report_local_cleanup, 
+                                    report_local_cleanup);
+}
+
+
+at_t *at_create(apr_pool_t *pool, unsigned char flags, at_report_t *report)
+{
+    at_t *t = apr_pcalloc(pool, sizeof *t);
+    t->flags = flags;
+    t->report = report;
+    t->pool = pool;
+
+    apr_pool_cleanup_register(pool, t, test_cleanup, test_cleanup);
+    return t;
+}
+
+
+#define AT_NELTS 4
+
+static int* at_list(apr_pool_t *pool, const char *spec, int *list)
+{
+    apr_array_header_t arr;
+    int prev, current = 0;
+
+    arr.pool = pool;
+    arr.elt_size = sizeof *list;
+    arr.nelts = 0;
+    arr.nalloc = AT_NELTS;
+    arr.elts = (char *)list;
+
+    do {
+        while (*spec && !apr_isdigit(*spec))
+            ++spec;
+
+        prev = current;
+        current = (int)apr_strtoi64(spec, (char **)(void *)&spec, 10);
+        *(int *)apr_array_push(&arr) = current;
+
+    } while (prev >= current);
+
+    return (int *)arr.elts;
+}
+
+
+
+apr_status_t at_run(at_t *AT, const at_test_t *test)
+{
+    int dummy = 0, fbuf[AT_NELTS], sbuf[AT_NELTS], tbuf[AT_NELTS];
+    jmp_buf j;
+
+    AT->current = 0;
+    AT->prior   += AT->plan;
+    AT->name    = test->name;
+    AT->plan    = test->plan;
+
+    if (test->fatals)
+        AT->fatal = at_list(AT->pool, test->fatals, fbuf);
+    else
+        AT->fatal = &dummy;
+
+    if (test->skips)
+        AT->skip = at_list(AT->pool, test->skips, sbuf);
+    else
+        AT->skip = &dummy;
+
+    if (test->todos)
+        AT->todo = at_list(AT->pool, test->todos, tbuf);
+    else
+        AT->todo = &dummy;
+
+    AT->abort = &j;
+    if (setjmp(j) == 0) {
+        test->func(AT);
+        return APR_SUCCESS;
+    }
+    AT->abort = NULL;
+    return APR_EGENERAL;
+}

Added: httpd/apreq/branches/multi-env-unstable/t/at.h
URL: http://svn.apache.org/viewcvs/httpd/apreq/branches/multi-env-unstable/t/at.h?view=auto&rev=153591
==============================================================================
--- httpd/apreq/branches/multi-env-unstable/t/at.h (added)
+++ httpd/apreq/branches/multi-env-unstable/t/at.h Sat Feb 12 19:32:38 2005
@@ -0,0 +1,265 @@
+/*
+**  Copyright 2004-2005  The Apache Software Foundation
+**
+**  Licensed under the Apache License, Version 2.0 (the "License");
+**  you may not use this file except in compliance with the License.
+**  You may obtain a copy of the License at
+**
+**      http://www.apache.org/licenses/LICENSE-2.0
+**
+**  Unless required by applicable law or agreed to in writing, software
+**  distributed under the License is distributed on an "AS IS" BASIS,
+**  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+**  See the License for the specific language governing permissions and
+**  limitations under the License.
+*/
+
+
+/* at.h: TAP-compliant C utilities for the Apache::Test framework. */
+
+#ifndef AT_H
+#define AT_H
+
+#include "apr.h"
+#include "apr_file_io.h"
+#include <stdarg.h>
+#include <stdlib.h>
+#include <setjmp.h>
+
+typedef struct at_t at_t;
+typedef struct at_report_t at_report_t;
+
+typedef apr_status_t (*at_report_function_t)(at_report_t *r, const char *msg);
+typedef void(*at_test_function_t)(at_t *t);
+typedef struct at_test_t at_test_t;
+
+struct at_test_t {
+    const char          *name;
+    at_test_function_t   func;
+    int                  plan;
+    const char          *fatals;
+    const char          *todos;
+    const char          *skips;
+};
+
+struct at_report_t {
+    at_report_function_t func;
+};
+
+/* We only need one at_t struct per test suite, so lets call it *AT.
+ * The mnemonic we follow is that (for lowercase foo) "AT_foo(bar)" 
+ * should be syntactically equivalent to "at_foo(AT, bar)".
+ *
+ * Terminology: test == an at_test_t, 
+ *              check == an assertion which produces TAP.
+ */
+
+#define dAT at_t *AT
+
+struct at_t {
+    int                  current; /* current check for this test */
+    int                  prior;   /* total # of checks prior to this test */
+    const char          *name;    /* name of current test */
+    int                  plan;    /* total # of checks in this test */
+    const int           *fatal;   /* list of unrecoverables */
+    const int           *todo;    /* list of expected failures */
+    const int           *skip;    /* list of ignorabe assertions */
+    at_report_t         *report  ;/* handles the results of each check */
+    unsigned char        flags;   /* verbosity: concise, trace, debug, etc. */
+    apr_pool_t          *pool;    /* creator pool with end-of-test cleanup */
+    jmp_buf             *abort;   /* where fatals go to die */
+};
+
+
+
+static APR_INLINE
+apr_status_t at_report(at_t *t, const char *msg) { 
+    at_report_t *r = t->report;
+    return r->func(r, msg);
+}
+#define AT_report(msg) at_report(AT, msg)
+
+/* The core assertion checker; the rest just wind up invoking this one. */
+void at_ok(at_t *t, int is_ok, const char *label, const char *file, int line);
+#define AT_ok(is_ok, label) at_ok(AT, is_ok, label, __FILE__, __LINE__)
+
+at_t *at_create(apr_pool_t *pool, unsigned char flags, at_report_t *report);
+apr_status_t at_begin(at_t *t, int total);
+#define AT_begin(total) at_begin(AT, total)
+
+apr_status_t at_run(at_t *AT, const at_test_t *test);
+#define AT_run(test) at_run(AT, test)
+
+void at_end(at_t *t);
+#define AT_end() at_end(AT)
+
+
+#define AT_FLAG_DEBUG(f)       ((f) & 4)
+#define AT_FLAG_DEBUG_ON(f)    ((f) |= 4)
+#define AT_FLAG_DEBUG_OFF(f)   ((f) &= ~4)
+#define AT_FLAG_TRACE(f)       ((f) & 2)
+#define AT_FLAG_TRACE_ON(f)    ((f) |= 2)
+#define AT_FLAG_TRACE_OFF(f)   ((f) &= ~2)
+#define AT_FLAG_CONCISE(f)     ((f) & 1)
+#define AT_FLAG_CONCISE_ON(f)  ((f) |= 1)
+#define AT_FLAG_CONCISE_OFF(f) ((f) &= ~1)
+
+#define AT_debug_on()      AT_FLAG_DEBUG_ON(AT->flags)
+#define AT_debug_off()     AT_FLAG_DEBUG_OFF(AT->flags)
+#define AT_trace_on()      AT_FLAG_TRACE_ON(AT->flags)
+#define AT_trace_off()     AT_FLAG_TRACE_OFF(AT->flags)
+#define AT_concise_on()    AT_FLAG_CONCISE_ON(AT->flags)
+#define AT_concise_off()   AT_FLAG_CONCISE_OFF(AT->flags)
+
+
+
+/* Additional reporting utils. 
+   These emit TAP comments, and are not "checks". */
+
+apr_status_t at_comment(at_t *t, const char *fmt, va_list vp);
+
+static APR_INLINE
+void at_debug(at_t *t, const char *fmt, ...) {
+    va_list vp;
+    va_start(vp, fmt);
+    if (AT_FLAG_DEBUG(t->flags))
+        at_comment(t, fmt, vp);
+    va_end(vp);
+}
+
+static APR_INLINE
+void at_trace(at_t *t, const char *fmt, ...) {
+    va_list vp;
+    va_start(vp, fmt);
+    if (AT_FLAG_TRACE(t->flags))
+        at_comment(t, fmt, vp);
+    va_end(vp);
+}
+
+
+
+/* These are "checks". */
+
+static APR_INLINE
+void at_check(at_t *t, int is_ok, const char *label, const char *file,
+           int line, const char *fmt, ...)
+{
+    va_list vp;
+
+    va_start(vp, fmt);
+    if (AT_FLAG_TRACE(t->flags)) {
+        char format[64] = "testing: %s (%s:%d)";
+            at_trace(t, format, label, file, line);
+
+        if (fmt != NULL) {
+            char *f;
+            at_trace(t, " format: %s", fmt);
+            strcpy(format, "   left: ");
+            strcpy(format + sizeof("   left: ") -1, fmt);
+            f = format + strlen(format);
+            strcpy(f+1, format);
+            *f = '\n';
+            memcpy(f+1, "  right: ", sizeof("  right: ") -1);
+            at_comment(t, format, vp);
+        }
+    }
+    va_end(vp);
+    at_ok(t, is_ok, label, file, line);
+}
+
+
+#define AT_mem_ne(a, b, n) do {                                         \
+    unsigned sz = n;                                                    \
+    const void *left = a, *right = b;                                   \
+    char fmt[] =  ", as %u-byte struct pointers";                       \
+    char buf[256] = #a " != " #b;                                       \
+    const unsigned blen = sizeof(#a " != " #b);                         \
+    apr_snprintf(buf + blen - 1, 256 - blen, fmt, sz);                  \
+    apr_snprintf(fmt, sizeof(fmt), "%%.%us", sz);                       \
+    at_check(AT, memcmp(left, right, sz), buf, __FILE__, __LINE__,      \
+           fmt, left, right);                                           \
+} while (0)                                                             \
+
+#define AT_mem_eq(a, b, n) do {                                         \
+    unsigned sz = n;                                                    \
+    const void *left = a, *right = b;                                   \
+    char fmt[] =  ", as %u-byte struct pointers";                       \
+    char buf[256] = #a " == " #b;                                       \
+    const unsigned blen = sizeof(#a " == " #b);                         \
+    apr_snprintf(buf + blen - 1, 256 - blen , fmt, sz);                 \
+    apr_snprintf(fmt, sizeof(fmt), "%%.%us", sz);                       \
+    at_check(AT, !memcmp(left, right, sz), buf, __FILE__, __LINE__,     \
+           fmt, left, right);                                           \
+} while (0)
+
+
+
+#define AT_str_eq(a, b) do {                                            \
+    const char *left = a, *right = b;                                   \
+    at_check(AT,!strcmp(left, right), #a " == " #b ", as strings",      \
+            __FILE__, __LINE__, "%s", left, right);                     \
+} while (0)
+
+
+#define AT_str_ne(a, b) do {                                           \
+    const char *left = a, *right = b;                                  \
+    at_check(AT, strcmp(left, right), #a " != " #b ", as strings",     \
+            __FILE__, __LINE__, "%s", left, right);                    \
+} while (0)
+
+#define AT_ptr_eq(a, b) do {                                    \
+    const void *left = a, *right = b;                           \
+    at_check(AT, left == right, #a " == " #b ", as pointers",   \
+            __FILE__, __LINE__, "%pp", left, right);            \
+} while (0)
+
+#define AT_ptr_ne(a, b) do {                                    \
+    const void *left = a, *right = b;                           \
+    at_check(AT, left != right, #a " != " #b ", as pointers",   \
+            __FILE__, __LINE__, "%pp", left, right);            \
+} while (0)
+
+
+#define AT_int_eq(a, b) do {                                    \
+    const int left = a, right = b;                              \
+    at_check(AT, left == right, #a " == " #b ", as integers",   \
+            __FILE__, __LINE__, "%d", left, right);             \
+} while (0)
+
+#define AT_int_ne(a, b) do {                                    \
+    const int left = a, right = b;                              \
+    at_check(AT, left != right, #a " != " #b ", as integers",   \
+            __FILE__, __LINE__, "%d", left, right);             \
+} while (0)
+
+#define AT_is_null(a)  AT_ptr_eq(a, NULL)
+#define AT_not_null(a) AT_ptr_ne(a, NULL)
+
+
+/* XXX these two macro checks evaluate a & b more than once, but the 
+ * upshot is that they don't care too much about their types.
+ */
+
+#define AT_EQ(a, b, fmt) at_check(AT, ((a) == (b)), #a " == " #b,\
+                                  __FILE__, __LINE__, fmt, a, b)
+#define AT_NE(a, b, fmt) at_check(AT, ((a) != (b)), #a " != " #b,\
+                                  __FILE__, __LINE__, fmt, a, b)
+
+
+
+/* Report utilities. */
+
+at_report_t *at_report_file_make(apr_pool_t *p, apr_file_t *f);
+APR_INLINE
+static at_report_t *at_report_stdout_make(apr_pool_t *p)
+{
+    apr_file_t *out;
+    apr_file_open_stdout(&out, p);
+    return at_report_file_make(p, out);
+}
+
+void at_report_local(at_t *AT, apr_pool_t *p, const char *file, int line);
+#define AT_localize(p) at_report_local(AT, p, __FILE__, __LINE__)
+
+
+#endif /* AT_H */

Modified: httpd/apreq/branches/multi-env-unstable/t/cookie.c
URL: http://svn.apache.org/viewcvs/httpd/apreq/branches/multi-env-unstable/t/cookie.c?view=diff&r1=153590&r2=153591
==============================================================================
--- httpd/apreq/branches/multi-env-unstable/t/cookie.c (original)
+++ httpd/apreq/branches/multi-env-unstable/t/cookie.c Sat Feb 12 19:32:38 2005
@@ -16,8 +16,8 @@
 
 #include "apreq_env.h"
 #include "apr_strings.h"
-#include "test_apreq.h"
 #include "apreq_cookie.h"
+#include "at.h"
 
 static const char nscookies[] = "a=1; foo=bar; fl=left; fr=right;bad; "
                                 "ns=foo=1&bar=2,frl=right-left; "
@@ -25,122 +25,133 @@
                                 "good_one=1;bad";
 
 static apr_table_t *jar;
+static apr_pool_t *p;
 
-static void jar_make(CuTest *tc)
+static void jar_make(dAT)
 {
-    apr_status_t s;
-
     jar = apr_table_make(p, APREQ_DEFAULT_NELTS);
-    CuAssertPtrNotNull(tc, jar);
-    s = apreq_parse_cookie_header(p, jar, nscookies);
-    CuAssertIntEquals(tc, APREQ_ERROR_NOTOKEN, s);
+    AT_not_null(jar);
+    AT_int_eq(apreq_parse_cookie_header(p, jar, nscookies), APREQ_ERROR_NOTOKEN);
 }
 
 
-static void jar_get(CuTest *tc)
+static void jar_get(dAT)
 {
-    const char *val;
 
-    val = apr_table_get(jar,"a");
-    CuAssertStrEquals(tc,"1",val);
+    AT_str_eq(apr_table_get(jar, "a"), "1");
 
     /* ignore wacky cookies that don't have an '=' sign */
-    val = apr_table_get(jar,"bad");
-    CuAssertPtrEquals(tc,NULL,val);
+    AT_is_null(apr_table_get(jar, "bad"));
+
     /* accept wacky cookies that contain multiple '=' */
-    val = apr_table_get(jar,"ns");
-    CuAssertStrEquals(tc,"foo=1&bar=2",val);
+    AT_str_eq(apr_table_get(jar, "ns"), "foo=1&bar=2");
 
-    val = apr_table_get(jar,"foo");
-    CuAssertStrEquals(tc,"bar",val);
-    val = apr_table_get(jar,"fl");
-    CuAssertStrEquals(tc,"left",val);
-    val = apr_table_get(jar,"fr");
-    CuAssertStrEquals(tc,"right",val);
-    val = apr_table_get(jar,"frl");
-    CuAssertStrEquals(tc,"right-left",val);
-    val = apr_table_get(jar,"flr");
-    CuAssertStrEquals(tc,"left-right",val);
-    val = apr_table_get(jar,"fll");
-    CuAssertStrEquals(tc,"left-left",val);
+    AT_str_eq(apr_table_get(jar,"foo"), "bar");
+    AT_str_eq(apr_table_get(jar,"fl"),  "left");
+    AT_str_eq(apr_table_get(jar,"fr"),  "right");
+    AT_str_eq(apr_table_get(jar,"frl"), "right-left");
+    AT_str_eq(apr_table_get(jar,"flr"), "left-right");
+    AT_str_eq(apr_table_get(jar,"fll"), "left-left");
 }
 
 
-static void netscape_cookie(CuTest *tc)
+static void netscape_cookie(dAT)
 {
     char *val;
     apreq_cookie_t *c;
-    apreq_cookie_version_t version = APREQ_COOKIE_VERSION_NETSCAPE;
 
     *(const char **)&val = apr_table_get(jar, "foo");
-    CuAssertPtrNotNull(tc, val);
+    AT_not_null(val);
+
     c = apreq_value_to_cookie(val);
-    CuAssertStrEquals(tc,"bar",apreq_cookie_value(c));
-    CuAssertIntEquals(tc, version,c->version);
 
-    CuAssertStrEquals(tc,"foo=bar", apreq_cookie_as_string(c,p));
+    AT_str_eq(apreq_cookie_value(c), "bar");
+    AT_int_eq(c->version, APREQ_COOKIE_VERSION_NETSCAPE);
+    AT_str_eq(apreq_cookie_as_string(c, p), "foo=bar");
+
     c->domain = apr_pstrdup(p, "example.com");
-    CuAssertStrEquals(tc,"foo=bar; domain=example.com", 
-                      apreq_cookie_as_string(c,p));
+    AT_str_eq(apreq_cookie_as_string(c, p), "foo=bar; domain=example.com");
 
     c->path = apr_pstrdup(p, "/quux");
-    CuAssertStrEquals(tc, "foo=bar; path=/quux; domain=example.com",
-                      apreq_cookie_as_string(c,p));
+    AT_str_eq(apreq_cookie_as_string(c, p), 
+              "foo=bar; path=/quux; domain=example.com");
+
     apreq_cookie_expires(c, "+1y");
-    CuAssertStrEquals(tc,apr_pstrcat(p,
-                         "foo=bar; path=/quux; domain=example.com; expires=", 
-                         apreq_expires(p,"+1y",APREQ_EXPIRES_NSCOOKIE), NULL), 
-                      apreq_cookie_as_string(c,p));
+    val = apr_pstrcat(p, "foo=bar; path=/quux; domain=example.com; expires=", 
+                      apreq_expires(p, "+1y", APREQ_EXPIRES_NSCOOKIE), NULL);
+    AT_str_eq(apreq_cookie_as_string(c, p), val);
 }
 
 
-static void rfc_cookie(CuTest *tc)
+static void rfc_cookie(dAT)
 {
     apreq_cookie_t *c = apreq_make_cookie(p,"rfc",3,"out",3);
+    char *val;
     long expires; 
 
-    CuAssertStrEquals(tc,"out",apreq_cookie_value(c));
+    AT_str_eq(apreq_cookie_value(c), "out");
+
     c->version = APREQ_COOKIE_VERSION_RFC;
+    AT_str_eq(apreq_cookie_as_string(c,p),"rfc=out; Version=1");
 
-    CuAssertStrEquals(tc,"rfc=out; Version=1", apreq_cookie_as_string(c,p));
     c->domain = apr_pstrdup(p, "example.com");
-    CuAssertStrEquals(tc,"rfc=out; Version=1; domain=\"example.com\"", 
-                      apreq_cookie_as_string(c,p));
+    AT_str_eq(apreq_cookie_as_string(c,p),
+              "rfc=out; Version=1; domain=\"example.com\"");
 
     c->path = apr_pstrdup(p, "/quux");
-    CuAssertStrEquals(tc, 
-              "rfc=out; Version=1; path=\"/quux\"; domain=\"example.com\"",
-                      apreq_cookie_as_string(c,p));
+    AT_str_eq(apreq_cookie_as_string(c,p),
+              "rfc=out; Version=1; path=\"/quux\"; domain=\"example.com\"");
 
     apreq_cookie_expires(c, "+3m");
     expires = apreq_atoi64t("+3m");
-    CuAssertStrEquals(tc,apr_psprintf(p,
-         "rfc=out; Version=1; path=\"/quux\"; domain=\"example.com\"; max-age=%ld",
-               expires), apreq_cookie_as_string(c,p));
-
+    val = apr_psprintf(p, "rfc=out; Version=1; path=\"/quux\"; "
+                       "domain=\"example.com\"; max-age=%ld",
+                       expires);
+    AT_str_eq(apreq_cookie_as_string(c,p), val);
 }
-static void ua_version(CuTest *tc)
+
+static void ua_version(dAT)
 {
-    apreq_cookie_version_t v;
-    char version[] = "$Version=\"1\"";
+    apreq_env_handle_t *ns, *rfc;
 
-    v = apreq_ua_cookie_version(apreq_handle_custom(p, NULL, NULL, NULL, NULL, 0, NULL));
-    CuAssertIntEquals(tc, APREQ_COOKIE_VERSION_NETSCAPE, v);
-    v = apreq_ua_cookie_version(apreq_handle_custom(p, NULL, NULL, version, NULL, 0, NULL));
-    CuAssertIntEquals(tc, APREQ_COOKIE_VERSION_RFC, v);
+    ns  = apreq_handle_custom(p, NULL, NULL, NULL, NULL, 0, NULL);
+    AT_int_eq(apreq_ua_cookie_version(ns), APREQ_COOKIE_VERSION_NETSCAPE);
 
+    rfc = apreq_handle_custom(p, NULL, NULL, "$Version=\"1\"", NULL, 0, NULL);
+    AT_int_eq(apreq_ua_cookie_version(rfc), APREQ_COOKIE_VERSION_RFC);
 }
 
-CuSuite *testcookie(void)
+#define dT(func, plan) {#func, func, plan}
+
+
+int main(int argc, char *argv[])
 {
-    CuSuite *suite = CuSuiteNew("Cookie");
+    unsigned i, plan = 0;
+    dAT;
+    at_test_t test_list [] = {
+        dT(jar_make, 2),
+        dT(jar_get, 9),
+        dT(netscape_cookie, 7),
+        dT(rfc_cookie, 5),
+        dT(ua_version, 2)
+    };
 
-    SUITE_ADD_TEST(suite, jar_make);
-    SUITE_ADD_TEST(suite, jar_get);
-    SUITE_ADD_TEST(suite, netscape_cookie);
-    SUITE_ADD_TEST(suite, rfc_cookie);
-    SUITE_ADD_TEST(suite, ua_version);
+    apr_initialize();
+    atexit(apr_terminate);
 
-    return suite;
-}
+    apr_pool_create(&p, NULL);
+
+    AT = at_create(p, 0, at_report_stdout_make(p)); 
+
+    for (i = 0; i < sizeof(test_list) / sizeof(at_test_t);  ++i)
+        plan += test_list[i].plan;
 
+    AT_begin(plan);
+
+    for (i = 0; i < sizeof(test_list) / sizeof(at_test_t);  ++i)
+        AT_run(&test_list[i]);
+
+    AT_end();
+
+    return 0;
+}

Modified: httpd/apreq/branches/multi-env-unstable/t/params.c
URL: http://svn.apache.org/viewcvs/httpd/apreq/branches/multi-env-unstable/t/params.c?view=diff&r1=153590&r2=153591
==============================================================================
--- httpd/apreq/branches/multi-env-unstable/t/params.c (original)
+++ httpd/apreq/branches/multi-env-unstable/t/params.c Sat Feb 12 19:32:38 2005
@@ -16,63 +16,59 @@
 
 #include "apreq_env.h"
 #include "apr_strings.h"
-#include "test_apreq.h"
+#include "at.h"
+
 
 static const char query_string[] = "a=1;quux=foo+bar&a=2&plus=%2B;"
                                    "uplus=%U002b;okie=dokie;"
                                    "novalue1;novalue2=";
 static apr_table_t *args;
+static apr_pool_t *p;
 
 #define strtoval(s) \
   ((const apreq_value_t *)(s - offsetof(apreq_value_t, data)))
 
-static void request_make(CuTest *tc)
+static void request_make(dAT)
 {
     apr_status_t s;
     args = apr_table_make(p, APREQ_DEFAULT_NELTS);
-    CuAssertPtrNotNull(tc, args);
+    AT_not_null(args);
     s = apreq_parse_query_string(p, args, query_string);
-    CuAssertIntEquals(tc, APR_SUCCESS, s);
-    CuAssertIntEquals(tc,8, apr_table_elts(args)->nelts);
+    AT_int_eq(s, APR_SUCCESS);
+    AT_int_eq(apr_table_elts(args)->nelts, 8);
 }
 
 
-static void request_args_get(CuTest *tc)
+static void request_args_get(dAT)
 {
     const char *val;
     const apreq_value_t *v;
 
-    val = apr_table_get(args,"a");
-    CuAssertStrEquals(tc,"1",val);
+    AT_str_eq(apr_table_get(args,"a"), "1");
+
     val = apr_table_get(args,"quux");
-    CuAssertStrEquals(tc,"foo bar",val);
+    AT_str_eq(val, "foo bar");
     v = strtoval(val);
-    CuAssertIntEquals(tc, 7, v->size);
-    val = apr_table_get(args,"plus");
-    CuAssertStrEquals(tc,"+",val);
-    val = apr_table_get(args,"uplus");
-    CuAssertStrEquals(tc,"+",val);
-    val = apr_table_get(args,"okie");
-    CuAssertStrEquals(tc,"dokie",val);
-    val = apr_table_get(args,"novalue1");
-    CuAssertStrEquals(tc,"",val);
-    val = apr_table_get(args,"novalue2");
-    CuAssertStrEquals(tc,"",val);
+    AT_int_eq(v->size, 7);
 
+    AT_str_eq(apr_table_get(args,"plus"), "+");
+    AT_str_eq(apr_table_get(args,"uplus"), "+");
+    AT_str_eq(apr_table_get(args,"okie"), "dokie");
+    AT_str_eq(apr_table_get(args,"novalue1"), "");
+    AT_str_eq(apr_table_get(args,"novalue2"),"");
 }
 
-static void params_as(CuTest *tc)
+static void params_as(dAT)
 {
     const char *val;
     apr_array_header_t *arr;
     arr = apreq_params_as_array(p,args,"a");
-    CuAssertIntEquals(tc,2,arr->nelts);
+    AT_int_eq(arr->nelts, 2);
     val = apreq_params_as_string(p,args,"a",APREQ_JOIN_AS_IS);
-    CuAssertStrEquals(tc,"1, 2", val);
+    AT_str_eq(val, "1, 2");
 }
 
-
-static void string_decoding_in_place(CuTest *tc)
+static void string_decoding_in_place(dAT)
 {
     char *s1 = apr_palloc(p,4096);
     char *s2 = apr_palloc(p,4096);
@@ -81,24 +77,24 @@
     strcpy(s1, "bend it like beckham");
     strcpy(s2, "dandy %3Edons");
 
-    CuAssertStrEquals(tc,"bend it like beckham",s1);
+    AT_str_eq(s1,"bend it like beckham");
     apreq_unescape(s1);
-    CuAssertStrEquals(tc,"bend it like beckham",s1);
+    AT_str_eq(s1, "bend it like beckham");
     s3 = apreq_escape(p, s1, 20);
-    CuAssertStrEquals(tc,"bend+it+like+beckham",s3);
+    AT_str_eq(s3, "bend+it+like+beckham");
     apreq_unescape(s3);
-    CuAssertStrEquals(tc,"bend it like beckham",s3);
+    AT_str_eq(s3,"bend it like beckham");
 
-    CuAssertStrEquals(tc,"dandy %3Edons",s2);
+    AT_str_eq(s2,"dandy %3Edons");
     apreq_unescape(s2);
-    CuAssertStrEquals(tc,"dandy >dons",s2);
+    AT_str_eq(s2,"dandy >dons");
     s3 = apreq_escape(p, s2, 11);
-    CuAssertStrEquals(tc,"dandy+%3edons",s3);
+    AT_str_eq(s3,"dandy+%3edons");
     apreq_unescape(s3);
-    CuAssertStrEquals(tc,"dandy >dons",s3); 
+    AT_str_eq(s3,"dandy >dons"); 
 }
 
-static void header_attributes(CuTest *tc)
+static void header_attributes(dAT)
 {
     const char *hdr = "text/plain; boundary=\"-foo-\", charset=ISO-8859-1";
     const char *val;
@@ -106,38 +102,37 @@
     apr_status_t s;
 
     s = apreq_header_attribute(hdr, "none", 4, &val, &vlen);
-    CuAssertIntEquals(tc, APR_NOTFOUND, s);
+    AT_int_eq(s, APR_NOTFOUND);
 
     s = apreq_header_attribute(hdr, "set", 3, &val, &vlen);
-    CuAssertIntEquals(tc, APR_NOTFOUND, s);
+    AT_int_eq(s, APR_NOTFOUND);
 
     s = apreq_header_attribute(hdr, "boundary", 8, &val, &vlen);
-    CuAssertIntEquals(tc, APR_SUCCESS, s);
-    CuAssertIntEquals(tc, 5, vlen);
-    CuAssertStrNEquals(tc, "-foo-", val, 5);
+    AT_int_eq(s, APR_SUCCESS);
+    AT_int_eq(vlen, 5);
+    AT_mem_eq(val, "-foo-", 5);
 
     s = apreq_header_attribute(hdr, "charset", 7, &val, &vlen);
-    CuAssertIntEquals(tc, APR_SUCCESS, s);
-    CuAssertIntEquals(tc, 10, vlen);
-    CuAssertStrNEquals(tc, "ISO-8859-1", val, 10);
+    AT_int_eq(s, APR_SUCCESS);
+    AT_int_eq(vlen, 10);
+    AT_mem_eq(val, "ISO-8859-1", 10);
 
     hdr = "max-age=20; no-quote=\"...";
 
     s = apreq_header_attribute(hdr, "max-age", 7, &val, &vlen);
-    CuAssertIntEquals(tc, APR_SUCCESS, s);
-    CuAssertIntEquals(tc, 2, vlen);
-    CuAssertStrNEquals(tc, "20", val, 2);
+    AT_int_eq(s, APR_SUCCESS);
+    AT_int_eq(vlen, 2);
+    AT_mem_eq(val, "20", 2);
 
     s = apreq_header_attribute(hdr, "age", 3, &val, &vlen);
-    CuAssertIntEquals(tc, APREQ_ERROR_BADTOKEN, s);
+    AT_int_eq(s, APREQ_ERROR_BADTOKEN);
 
     s = apreq_header_attribute(hdr, "no-quote", 8, &val, &vlen);
-    CuAssertIntEquals(tc, APREQ_ERROR_BADTOKEN, s);
-
+    AT_int_eq(s, APREQ_ERROR_BADTOKEN);
 
 }
 
-static void make_values(CuTest *tc)
+static void make_values(dAT)
 {
     apreq_value_t *v;
     apr_size_t len = 4;
@@ -147,43 +142,45 @@
     strcpy(val, "bar");
  
     v = apreq_make_value(p, name, len, val, len);
-    CuAssertStrEquals(tc, name, v->name);
-    CuAssertIntEquals(tc, len, v->size);
-    CuAssertStrEquals(tc, val, v->data);
+    AT_str_eq(v->name, name);
+    AT_int_eq(v->size, len);
+    AT_str_eq(v->data, val);
 
 }
 
-static void make_param(CuTest *tc)
+
+static void make_param(dAT)
 {
-    apreq_param_t *param, *result;
+    apreq_param_t *param, *decode;
     apr_status_t s;
     apr_size_t nlen = 3, vlen = 11;
     char *name = apr_palloc(p,nlen+1);
     char *val = apr_palloc(p,vlen+1);
-    char *encode = apr_palloc(p,vlen+nlen+1);
+    char *encode;
     strcpy(name, "foo");
     strcpy(val, "bar > alpha");
  
     param = apreq_make_param(p, name, nlen, val, vlen);
-    CuAssertStrEquals(tc, name, param->v.name);
-    CuAssertIntEquals(tc, vlen, param->v.size);
-    CuAssertStrEquals(tc, val, param->v.data);
+    AT_str_eq(param->v.name, name);
+    AT_int_eq(param->v.size, vlen);
+    AT_str_eq(param->v.data, val);
 
     encode = apreq_encode_param(p, param);
-    CuAssertStrEquals(tc, "foo=bar+%3e+alpha", encode);
+    AT_str_eq(encode, "foo=bar+%3e+alpha");
 
-    s = apreq_decode_param(&result, p, encode, nlen, vlen+2);
-    CuAssertStrEquals(tc, name, result->v.name);
-    CuAssertIntEquals(tc, vlen, result->v.size);
-    CuAssertStrEquals(tc, val, result->v.data);
+    s = apreq_decode_param(&decode, p, encode, nlen, vlen+2);
+    AT_int_eq(s, APR_SUCCESS);
+    AT_str_eq(decode->v.name, name);
+    AT_int_eq(decode->v.size, vlen);
+    AT_str_eq(decode->v.data, val);
 }
 
-static void quote_strings(CuTest *tc)
+static void quote_strings(dAT)
 {
     apr_size_t exp_len, res_len, res_quote_len;
     char *res = apr_palloc(p,24);
     char *res_quote = apr_palloc(p,24);
-    const char *expe = apr_palloc(p,24);
+    const char *expr;
     int i;
     const char * arr[] = {"cest", "\"cest", "ce\"st", "\"cest\""};
     const char * arr_quote[] = 
@@ -193,31 +190,55 @@
 
     for (i=0; i<4; i++) {
         res_len = apreq_quote(res, arr[i], arr_len[i]);
-        CuAssertIntEquals(tc, arr_quote_len[i], res_len);
-        CuAssertStrNEquals(tc, arr_quote[i], res, res_len);
+        AT_int_eq(res_len, arr_quote_len[i]);
+        AT_mem_eq(res, arr_quote[i], res_len);
         res_quote_len = apreq_quote_once(res_quote, res, res_len);
-        CuAssertIntEquals(tc, res_len, res_quote_len);
-        CuAssertStrNEquals(tc, res, res_quote, res_len);
+        AT_int_eq(res_quote_len, res_len);
+        AT_mem_eq(res_quote, res, res_len);
         res_len = apreq_quote_once(res, arr[i], arr_len[i]);
         exp_len = (i == 3) ? arr_len[i] : arr_quote_len[i];
-        expe = (i == 3) ? arr[i] : arr_quote[i];
-        CuAssertIntEquals(tc, exp_len, res_len);
-        CuAssertStrNEquals(tc, expe, res, exp_len);
+        expr = (i == 3) ? arr[i] : arr_quote[i];
+        AT_int_eq(res_len, exp_len);
+        AT_mem_eq(res, expr, exp_len);
     }
 }
 
-CuSuite *testparam(void)
+#define dT(func, plan) {#func, func, plan}
+
+int main(int argc, char *argv[])
 {
-    CuSuite *suite = CuSuiteNew("Param");
+    unsigned i, plan = 0;
+    dAT;
+    at_test_t test_list [] = {
+        dT(request_make, 3),
+        dT(request_args_get, 8),
+        dT(params_as, 2),
+        dT(string_decoding_in_place, 8),
+        dT(header_attributes, 13),
+        dT(make_values, 3),
+        dT(make_param, 8),
+        dT(quote_strings, 24),
+//        dT(test_memmem, 7),
+    };
+
+    apr_initialize();
+    atexit(apr_terminate);
+    apr_pool_create(&p, NULL);
+
+    apreq_initialize(p);
+
+    AT = at_create(p, 0, at_report_stdout_make(p)); 
+    AT_trace_on();
+    for (i = 0; i < sizeof(test_list) / sizeof(at_test_t);  ++i)
+        plan += test_list[i].plan;
+
+    AT_begin(plan);
+
+    for (i = 0; i < sizeof(test_list) / sizeof(at_test_t);  ++i)
+        AT_run(&test_list[i]);
+
+    AT_end();
 
-    SUITE_ADD_TEST(suite, request_make);
-    SUITE_ADD_TEST(suite, request_args_get);
-    SUITE_ADD_TEST(suite, params_as);
-    SUITE_ADD_TEST(suite, string_decoding_in_place);
-    SUITE_ADD_TEST(suite, header_attributes);
-    SUITE_ADD_TEST(suite, make_values);
-    SUITE_ADD_TEST(suite, quote_strings);
-    SUITE_ADD_TEST(suite, make_param);
-    return suite;
+    return 0;
 }
 

Modified: httpd/apreq/branches/multi-env-unstable/t/parsers.c
URL: http://svn.apache.org/viewcvs/httpd/apreq/branches/multi-env-unstable/t/parsers.c?view=diff&r1=153590&r2=153591
==============================================================================
--- httpd/apreq/branches/multi-env-unstable/t/parsers.c (original)
+++ httpd/apreq/branches/multi-env-unstable/t/parsers.c Sat Feb 12 19:32:38 2005
@@ -17,10 +17,12 @@
 #include "apreq_env.h"
 #include "apr_strings.h"
 #include "apr_xml.h"
-#include "test_apreq.h"
+#include "at.h"
 
 #define CRLF "\015\012"
 
+static apr_pool_t *p;
+
 static char url_data[] = "alpha=one&beta=two;omega=last%2";
 
 static char form_data[] = 
@@ -103,7 +105,7 @@
 #define MR_ENCTYPE "multipart/related"
 #define XML_ENCTYPE "application/xml"
 
-static void locate_default_parsers(CuTest *tc)
+static void locate_default_parsers(dAT)
 {
     apreq_parser_function_t f;
 
@@ -111,21 +113,17 @@
     apreq_register_parser(NULL, NULL);
     
     f = apreq_parser(URL_ENCTYPE);
-    CuAssertPtrNotNull(tc, f);
-    CuAssertPtrEquals(tc, apreq_parse_urlencoded, f);
+    AT_EQ(f, apreq_parse_urlencoded, "%pp");
 
     f = apreq_parser(MFD_ENCTYPE);
-    CuAssertPtrNotNull(tc, f);
-    CuAssertPtrEquals(tc, apreq_parse_multipart, f);
+    AT_EQ(f, apreq_parse_multipart, "%pp");
 
     f = apreq_parser(MR_ENCTYPE);
-    CuAssertPtrNotNull(tc, f);
-    CuAssertPtrEquals(tc, apreq_parse_multipart, f);
+    AT_EQ(f, apreq_parse_multipart, "%pp");
 }
 
-static void parse_urlencoded(CuTest *tc)
+static void parse_urlencoded(dAT)
 {
-    const char *val;
     apr_status_t rv;
     apr_bucket_alloc_t *ba;
     apr_bucket_brigade *bb;
@@ -143,7 +141,7 @@
                                    bb->bucket_alloc));
 
     rv = apreq_run_parser(parser, body, bb);
-    CuAssertIntEquals(tc, APR_INCOMPLETE, rv);
+    AT_int_eq(rv, APR_INCOMPLETE);
 
     APR_BRIGADE_INSERT_HEAD(bb,
         apr_bucket_immortal_create("blast",5, 
@@ -152,18 +150,15 @@
            apr_bucket_eos_create(bb->bucket_alloc));
 
     rv = apreq_run_parser(parser, body, bb);
-    CuAssertIntEquals(tc, APR_SUCCESS, rv);
+    AT_int_eq(rv, APR_SUCCESS);
 
-    val = apr_table_get(body,"alpha");
-    CuAssertStrEquals(tc, "one", val);
-    val = apr_table_get(body,"beta");
-    CuAssertStrEquals(tc, "two", val);
-    val = apr_table_get(body,"omega");
-    CuAssertStrEquals(tc, "last+last", val);
+    AT_str_eq(apr_table_get(body,"alpha"), "one");
+    AT_str_eq(apr_table_get(body,"beta"), "two");
+    AT_str_eq(apr_table_get(body,"omega"),"last+last");
 
 }
 
-static void parse_multipart(CuTest *tc)
+static void parse_multipart(dAT)
 {
     apr_size_t i, j;
     apr_bucket_alloc_t *ba;
@@ -173,6 +168,14 @@
 
         ba = apr_bucket_alloc_create(p);
 
+        /* AT_localize checks the inner loop tests itself
+         * (and interprets any such failures as being fatal),
+         * because doing IO to Test::Harness is just too slow
+         * when this many (~1M) tests are involved.
+         */
+
+        AT_localize(p);
+
         for (i = 0; i <= strlen(form_data); ++i) {
             const char *val;
             char *val2;
@@ -207,27 +210,26 @@
 
             tail = apr_brigade_split(bb, f);
             rv = apreq_run_parser(parser, body, bb);
-            CuAssertIntEquals(tc, (j < strlen(form_data)) ? APR_INCOMPLETE : APR_SUCCESS, rv);
+            AT_int_eq(rv, (j < strlen(form_data)) ? APR_INCOMPLETE : APR_SUCCESS);
             rv = apreq_run_parser(parser, body, tail);
-            CuAssertIntEquals(tc, APR_SUCCESS, rv);
-            CuAssertIntEquals(tc, 2, apr_table_elts(body)->nelts);
+            AT_int_eq(rv, APR_SUCCESS);
+            AT_int_eq(apr_table_elts(body)->nelts, 2);
 
             val = apr_table_get(body,"field1");
-
-            CuAssertStrEquals(tc, "Joe owes =80100.", val);
+            AT_str_eq(val, "Joe owes =80100.");
             t = apreq_value_to_param(val)->info;
             val = apr_table_get(t, "content-transfer-encoding");
-            CuAssertStrEquals(tc,"quoted-printable", val);
+            AT_str_eq(val, "quoted-printable");
 
             val = apr_table_get(body, "pics");
-            CuAssertStrEquals(tc, "file1.txt", val);
+            AT_str_eq(val, "file1.txt");
             t = apreq_value_to_param(val)->info;
             vb = apreq_value_to_param(val)->upload;
             apr_brigade_pflatten(vb, &val2, &len, p);
-            CuAssertIntEquals(tc,strlen("... contents of file1.txt ..." CRLF), len);
-            CuAssertStrNEquals(tc,"... contents of file1.txt ..." CRLF, val2, len);
+            AT_int_eq(len, strlen("... contents of file1.txt ..." CRLF));
+            AT_mem_eq(val2 ,"... contents of file1.txt ..." CRLF, len);
             val = apr_table_get(t, "content-type");
-            CuAssertStrEquals(tc, "text/plain", val);
+            AT_str_eq(val, "text/plain");
             apr_brigade_cleanup(vb);
             apr_brigade_cleanup(bb);
         }
@@ -237,7 +239,7 @@
     }
 }
 
-static void parse_disable_uploads(CuTest *tc)
+static void parse_disable_uploads(dAT)
 {
     const char *val;
     apr_table_t *t, *body;
@@ -266,21 +268,21 @@
 
 
     rv = apreq_run_parser(parser, body, bb);
-    CuAssertIntEquals(tc, APR_EGENERAL, rv);
-    CuAssertIntEquals(tc, 1, apr_table_elts(body)->nelts);
+    AT_int_eq(rv, APR_EGENERAL);
+    AT_int_eq(apr_table_elts(body)->nelts, 1);
 
     val = apr_table_get(body,"field1");
-    CuAssertStrEquals(tc, "Joe owes =80100.", val);
+    AT_str_eq(val, "Joe owes =80100.");
     t = apreq_value_to_param(val)->info;
     val = apr_table_get(t, "content-transfer-encoding");
-    CuAssertStrEquals(tc,"quoted-printable", val);
+    AT_str_eq(val, "quoted-printable");
 
     val = apr_table_get(body, "pics");
-    CuAssertPtrEquals(tc, NULL, val);
+    AT_is_null(val);
 }
 
 
-static void parse_generic(CuTest *tc)
+static void parse_generic(dAT)
 {
     char *val;
     apr_size_t vlen;
@@ -303,16 +305,16 @@
                                apreq_parse_generic, 1000, NULL, NULL, NULL);
 
     rv = apreq_run_parser(parser, body, bb);
-    CuAssertIntEquals(tc, APR_SUCCESS, rv);
+    AT_int_eq(rv, APR_SUCCESS);
     dummy = *(apreq_param_t **)parser->ctx;
-    CuAssertPtrNotNull(tc, dummy);
+    AT_not_null(dummy);
     apr_brigade_pflatten(dummy->upload, &val, &vlen, p);
 
-    CuAssertIntEquals(tc, strlen(xml_data), vlen);
-    CuAssertStrNEquals(tc, xml_data, val, vlen);
+    AT_int_eq(vlen, strlen(xml_data));
+    AT_mem_eq(val, xml_data, vlen);
 }
 
-static void hook_discard(CuTest *tc)
+static void hook_discard(dAT)
 {
     apr_status_t rv;
     apreq_param_t *dummy;
@@ -336,15 +338,15 @@
 
 
     rv = apreq_run_parser(parser, body, bb);
-    CuAssertIntEquals(tc, APR_SUCCESS, rv);
+    AT_int_eq(rv, APR_SUCCESS);
     dummy = *(apreq_param_t **)parser->ctx;
-    CuAssertPtrNotNull(tc, dummy);
-    CuAssertPtrNotNull(tc, dummy->upload);
-    CuAssertTrue(tc, APR_BRIGADE_EMPTY(dummy->upload));
+    AT_not_null(dummy);
+    AT_not_null(dummy->upload);
+    AT_ok(APR_BRIGADE_EMPTY(dummy->upload), "brigade has no contents");
 }
 
 
-static void parse_related(CuTest *tc)
+static void parse_related(dAT)
 {
     char ct[] = "multipart/related; boundary=f93dcbA3; "
         "type=application/xml; start=\"<980119.X53GGT@example.com>\"";
@@ -375,45 +377,45 @@
                                1000, NULL, xml_hook, NULL);
 
     rv = apreq_run_parser(parser, body, bb);
-    CuAssertIntEquals(tc, APR_SUCCESS, rv);
+    AT_int_eq(rv, APR_SUCCESS);
 
     val = apr_table_get(body, "<980119.X53GGT@example.com>");
-    CuAssertPtrNotNull(tc, val);
+    AT_not_null(val);
     param = apreq_value_to_param(val);
 
-    CuAssertPtrNotNull(tc, param);
-    CuAssertPtrNotNull(tc, param->info);
+    AT_not_null(param);
+    AT_not_null(param->info);
     val = apr_table_get(param->info, "Content-Length");
-    CuAssertStrEquals(tc, "400", val);
-    CuAssertPtrNotNull(tc, param->upload);
+    AT_str_eq(val, "400");
+    AT_not_null(param->upload);
     apr_brigade_pflatten(param->upload, &val2, &vlen, p);
-    CuAssertIntEquals(tc, 400, vlen);
-    CuAssertStrNEquals(tc,rel_data + 122, val2, 400);
+    AT_int_eq(vlen, 400);
+    AT_mem_eq(val2, rel_data + 122, 400);
 
     doc = *(apr_xml_doc **)xml_hook->ctx;
     apr_xml_to_text(p, doc->root, APR_XML_X2T_FULL,
                     doc->namespaces, &ns_map, &val, &vlen);
-    CuAssertIntEquals(tc, 400 - 22, vlen);
-    CuAssertStrNEquals(tc, rel_data + 122 + 23, val, 400 - 23);
+    AT_int_eq(vlen, 400 - 22);
+    AT_mem_eq(val, rel_data + 122 + 23, 400 - 23);
 
 
     val = apr_table_get(body, "<980119.X25MNC@example.com>");
-    CuAssertPtrNotNull(tc, val);
+    AT_not_null(val);
     param = apreq_value_to_param(val);
-    CuAssertPtrNotNull(tc, param);
-    CuAssertPtrNotNull(tc, param->upload);
+    AT_not_null(param);
+    AT_not_null(param->upload);
     apr_brigade_pflatten(param->upload, &val2, &vlen, p);
-    CuAssertIntEquals(tc, dlen, vlen);
-    CuAssertStrNEquals(tc, data, val2, vlen);
+    AT_int_eq(vlen, dlen);
+    AT_mem_eq(val2, data, vlen);
 
     val = apr_table_get(body, "<980119.X17AXM@example.com>");
-    CuAssertPtrNotNull(tc, val);
+    AT_not_null(val);
     param = apreq_value_to_param(val);
-    CuAssertPtrNotNull(tc, param);
-    CuAssertPtrNotNull(tc, param->upload);
+    AT_not_null(param);
+    AT_not_null(param->upload);
     apr_brigade_pflatten(param->upload, &val2, &vlen, p);
-    CuAssertIntEquals(tc, dlen, vlen);
-    CuAssertStrNEquals(tc, data, val2, vlen);
+    AT_int_eq(vlen, dlen);
+    AT_mem_eq(val2, data, vlen);
 }
 
 typedef struct {
@@ -422,7 +424,7 @@
 } array_elt;
 
 
-static void parse_mixed(CuTest *tc)
+static void parse_mixed(dAT)
 {
     const char *val;
     char *val2;
@@ -447,51 +449,80 @@
                                1000, NULL, NULL, NULL);
 
     rv = apreq_run_parser(parser, body, bb);
-    CuAssertIntEquals(tc, APR_SUCCESS, rv);
+    AT_int_eq(rv, APR_SUCCESS);
 
     val = apr_table_get(body, "submit-name");
-    CuAssertPtrNotNull(tc, val);
-    CuAssertStrEquals(tc, "Larry", val);
+    AT_not_null(val);
+    AT_str_eq(val, "Larry");
 
     val = apr_table_get(body,"field1");
-    CuAssertStrEquals(tc, "Joe owes =80100.", val);
+    AT_str_eq(val, "Joe owes =80100.");
 
     val = apr_table_get(body, "files");
-    CuAssertPtrNotNull(tc, val);
-    CuAssertStrEquals(tc, "file1.txt", val);
+    AT_not_null(val);
+    AT_str_eq(val, "file1.txt");
     param = apreq_value_to_param(val);
 
-    CuAssertPtrNotNull(tc, param->upload);
+    AT_not_null(param->upload);
     apr_brigade_pflatten(param->upload, &val2, &vlen, p);
-    CuAssertIntEquals(tc, strlen("... contents of file1.txt ..."), vlen);
-    CuAssertStrNEquals(tc, "... contents of file1.txt ...", val2, vlen);
+    AT_int_eq(vlen, strlen("... contents of file1.txt ..."));
+    AT_mem_eq(val2, "... contents of file1.txt ...", vlen);
 
     arr = apr_table_elts(body);
-    CuAssertIntEquals(tc, 4, arr->nelts);
+    AT_int_eq(arr->nelts, 4);
 
     elt = (array_elt *)&arr->elts[2 * arr->elt_size];
-    CuAssertStrEquals(tc, "files", elt->key);
-    CuAssertStrEquals(tc, "file2.gif", elt->val);
+    AT_str_eq(elt->key, "files");
+    AT_str_eq(elt->val, "file2.gif");
 
     param = apreq_value_to_param(elt->val);
-    CuAssertPtrNotNull(tc, param->upload);
+    AT_not_null(param->upload);
     apr_brigade_pflatten(param->upload, &val2, &vlen, p);
-    CuAssertIntEquals(tc, strlen("...contents of file2.gif..."), vlen);
-    CuAssertStrNEquals(tc, "...contents of file2.gif...", val2, vlen);
+    AT_int_eq(vlen, strlen("...contents of file2.gif..."));
+    AT_mem_eq(val2, "...contents of file2.gif...", vlen);
 
 }
 
-CuSuite *testparser(void)
+
+#define dT(func, plan) {#func, func, plan}
+
+int main(int argc, char *argv[])
 {
-    CuSuite *suite = CuSuiteNew("Parsers");
-    SUITE_ADD_TEST(suite, locate_default_parsers);
-    SUITE_ADD_TEST(suite, parse_urlencoded);
-    SUITE_ADD_TEST(suite, parse_multipart);
-    SUITE_ADD_TEST(suite, parse_disable_uploads);
-    SUITE_ADD_TEST(suite, parse_generic);
-    SUITE_ADD_TEST(suite, hook_discard);
-    SUITE_ADD_TEST(suite, parse_related);
-    SUITE_ADD_TEST(suite, parse_mixed);
-    return suite;
+    apr_pool_t *test_pool;
+    unsigned i, plan = 0;
+    dAT;
+    at_test_t test_list [] = {        
+        dT(locate_default_parsers, 3),
+        dT(parse_urlencoded, 5),
+        dT(parse_multipart, sizeof form_data),
+        dT(parse_disable_uploads, 5),
+        dT(parse_generic, 4),
+        dT(hook_discard, 4),
+        dT(parse_related, 20),
+        dT(parse_mixed, 15)
+    };
+
+    apr_initialize();
+    atexit(apr_terminate);
+
+    apr_pool_create(&p, NULL);
+    apr_pool_create(&test_pool, NULL);
+    apreq_initialize(p);
+
+
+    AT = at_create(test_pool, 0, at_report_stdout_make(test_pool)); 
+//    AT_trace_on();
+    for (i = 0; i < sizeof(test_list) / sizeof(at_test_t);  ++i)
+        plan += test_list[i].plan;
+
+    AT_begin(plan);
+
+    for (i = 0; i < sizeof(test_list) / sizeof(at_test_t);  ++i)
+        AT_run(&test_list[i]);
+
+    AT_end();
+
+    return 0;
 }
+
 

Modified: httpd/apreq/branches/multi-env-unstable/t/version.c
URL: http://svn.apache.org/viewcvs/httpd/apreq/branches/multi-env-unstable/t/version.c?view=diff&r1=153590&r2=153591
==============================================================================
--- httpd/apreq/branches/multi-env-unstable/t/version.c (original)
+++ httpd/apreq/branches/multi-env-unstable/t/version.c Sat Feb 12 19:32:38 2005
@@ -14,49 +14,56 @@
 **  limitations under the License.
 */
 
+#include "apreq_env.h"
 #include "apreq_version.h"
-#include "test_apreq.h"
-#include "apreq.h"
+#include "at.h"
 
-apr_version_t v;
-const char *vstring;
-
-static void version_string(CuTest *tc)
+static void version_string(dAT)
 {
-    vstring = apreq_version_string();
-    CuAssertPtrNotNull(tc, vstring);
-    CuAssertStrEquals(tc, APREQ_VERSION_STRING, vstring);
+    const char *vstring = apreq_version_string();
+    AT_not_null(vstring);
+    AT_str_eq(vstring, APREQ_VERSION_STRING);
 }
-static void version_major(CuTest *tc)
+static void version_type(dAT)
 {
+    apr_version_t v;
     apreq_version(&v);
-    CuAssertIntEquals(tc, APREQ_MAJOR_VERSION, v.major);
-}
-static void version_minor(CuTest *tc)
-{
-    CuAssertIntEquals(tc, APREQ_MINOR_VERSION, v.minor);
-}
-static void version_patch(CuTest *tc)
-{
-    CuAssertIntEquals(tc, APREQ_PATCH_VERSION, v.patch);
-}
-static void version_is_dev(CuTest *tc)
-{
+    AT_int_eq(v.major, APREQ_MAJOR_VERSION);
+    AT_int_eq(v.minor, APREQ_MINOR_VERSION);
+    AT_int_eq(v.patch, APREQ_PATCH_VERSION);
 #ifdef APREQ_IS_DEV_VERSION
-    CuAssertIntEquals(tc, 1, v.is_dev);
+    AT_int_eq(v.is_dev, 1);
 #else
-    CuAssertIntEquals(tc, 0, v.is_dev);
+    AT_int_eq(v.is_dev, 0);
 #endif
 }
 
-CuSuite *testversion(void)
+int main(int argc, char *argv[])
 {
-    CuSuite *suite = CuSuiteNew("Version");
-    SUITE_ADD_TEST(suite, version_string);
-    SUITE_ADD_TEST(suite, version_major);
-    SUITE_ADD_TEST(suite, version_minor);
-    SUITE_ADD_TEST(suite, version_patch);
-    SUITE_ADD_TEST(suite, version_is_dev);
-    return suite;
-}
+    apr_pool_t *p;
+    unsigned i, plan = 0;
+    dAT;
+    at_test_t test_list [] = {
+        {"version_string", version_string, 2, "1"},
+        {"version_type", version_type, 4}
+    };
 
+    apr_initialize();
+    atexit(apr_terminate);
+
+    apr_pool_create(&p, NULL);
+
+    AT = at_create(p, 0, at_report_stdout_make(p)); 
+
+    for (i = 0; i < sizeof(test_list) / sizeof(at_test_t);  ++i)
+        plan += test_list[i].plan;
+
+    AT_begin(plan);
+
+    for (i = 0; i < sizeof(test_list) / sizeof(at_test_t);  ++i)
+        AT_run(&test_list[i]);
+
+    AT_end();
+
+    return 0;
+}



Mime
View raw message