Commit 2b059a5f authored by Philip M. Gollucci's avatar Philip M. Gollucci
Browse files

drop tests and automake code for now

git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1200455 13f79535-47bb-0310-9956-ffa450edef68
parent 18114407
Loading
Loading
Loading
Loading

srclib/libapreq/Makefile.am

deleted100644 → 0
+0 −42
Original line number Diff line number Diff line
EXTRA_DIST = t
AM_CPPFLAGS = @APR_INCLUDES@
BUILT_SOURCES = @APR_LA@ @APU_LA@
lib_LTLIBRARIES = libapreq2.la
libapreq2_la_SOURCES = util.c version.c cookie.c param.c parser.c \
                       parser_urlencoded.c parser_header.c parser_multipart.c \
	               module.c module_custom.c module_cgi.c error.c
libapreq2_la_LDFLAGS = -version-info @APREQ_LIBTOOL_VERSION@ @APR_LTFLAGS@ @APR_LIBS@

test: all
	cd t; $(MAKE) test

if ENABLE_PROFILE

AM_CFLAGS= -pg -fprofile-arcs -ftest-coverage

clean-local:
	-rm *.bb *.bbg *.da *.gcov
	cd t; $(MAKE) clean
else

clean-local:
	cd t; $(MAKE) clean
endif

distclean-am: clean-am distclean-compile distclean-generic \
	distclean-tags
	cd t; $(MAKE) distclean

if BUILD_APR

@APR_LA@:
	cd `@APR_CONFIG@ --srcdir` && $(MAKE)

endif

if BUILD_APU

@APU_LA@: @APR_LA@
	cd `@APU_CONFIG@ --srcdir` && $(MAKE)

endif

srclib/libapreq/t/Makefile.am

deleted100644 → 0
+0 −19
Original line number Diff line number Diff line
AM_CPPFLAGS = @APR_INCLUDES@
AM_LDFLAGS = `@APREQ_CONFIG@ --link-libtool --libs` @APR_LTFLAGS@
noinst_LIBRARIES = libapache_test.a
libapache_test_a_SOURCES = at.h at.c

check_PROGRAMS = version cookie params parsers error util
LDADD  = libapache_test.a

check_SCRIPTS = version.t cookie.t params.t parsers.t error.t util.t
TESTS = $(check_SCRIPTS)
TESTS_ENVIRONMENT = @PERL@ -MTest::Harness -e 'runtests(@ARGV)'
CLEANFILES = $(check_PROGRAMS) $(check_SCRIPTS)

%.t: %
	echo "#!perl" > $@
	echo "exec './$*'" >> $@

test: $(check_SCRIPTS)
	$(TESTS_ENVIRONMENT) $(check_SCRIPTS)

srclib/libapreq/t/at.c

deleted100644 → 0
+0 −394
Original line number Diff line number Diff line
/*
**  Licensed to the Apache Software Foundation (ASF) under one or more
** contributor license agreements.  See the NOTICE file distributed with
** this work for additional information regarding copyright ownership.
** The ASF licenses this file to You 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 "at.h"
#include <errno.h>
#include <ctype.h>

#define AT_SUCCESS 0
#define AT_EGENERAL 14
#define min(a, b) ((a < b) ? a : b)

int at_begin(at_t *t, int total)
{
    char buf[32];
    at_snprintf(buf, 32, "1..%d", total);
    return at_report(t, buf);
}

static int 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)
{
    test_cleanup(t);
    free(t);
}

int at_comment(at_t *t, const char *fmt, va_list vp)
{
    int s;
    char buf[256], *b = buf + 2;
    char *end;
    int rv;
    rv = at_vsnprintf(b, 250, fmt, vp);

    if (rv <= 0)
        return EINVAL;


    end = b + min(rv, 250);

    buf[0] = '#';
    buf[1] = ' ';

    if (rv >= 250) {
        end[-1] = '.';
        *end++ = '.';
        *end++ = '.';
        *end++ = '\n';
        *end = 0;
    }
    else if (end[-1] != '\n') {
        *end++ = '\n';
        *end = 0;
    }

    b = buf;
    while (1) {
        char *eol;

        eol = strchr(b + 2, '\n');
        *eol = 0;
        s = at_report(t, b);
        if (s != AT_SUCCESS || eol == end - 1)
            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_TODO(t->flags))
        is_todo = 1;

    if (AT_FLAG_CONCISE(t->flags))
        format[9] = '\0';
    else if (is_ok && ! is_todo && !AT_FLAG_TRACE(t->flags))
        format[14] = '\0';
    else if (is_fatal && ! is_ok)
        comment = "fatal";
    else
        comment = is_todo ? "todo" : is_skip ? "skip" : "at";

    rv = at_snprintf(buf, 256, fmt, t->current + t->prior,
                     label, comment,  file, line, t->current, t->name);

    if (rv <= 0)
        exit(-1);

    end = buf + min(rv, 250);

    if (rv >= 250) {
        *end++ = '.';
        *end++ = '.';
        *end++ = '.';
        *end = '\0';
    }

    if (memchr(buf, '\n', rv) != NULL || at_report(t, buf) != AT_SUCCESS)
        exit(-1);

    if (!is_ok && is_fatal) {
        while (t->current++ < t->plan) {
            at_snprintf(buf, 256, "not ok %d # skipped: aborting test %s",
                        t->prior + t->current, t->name);
            at_report(t, buf);
        }
        longjmp(*t->abort, 0);
    }
}

struct at_report_file {
    at_report_t module;
    FILE *file;
};

static int at_report_file_write(at_report_t *ctx, const char *msg)
{
    struct at_report_file *r = (struct at_report_file *)ctx;
    FILE *f = r->file;
    size_t len = strlen(msg);
    size_t bytes_written;
    int status;

    bytes_written = fwrite(msg, sizeof(char), len, f);
    if (bytes_written != len)
        return errno;

    status = putc('\n', f);
    if (status == EOF)
        return errno;

    return fflush(f);
}

at_report_t *at_report_file_make(FILE *f)
{
    struct at_report_file *r = malloc(sizeof *r);
    r->module.func = at_report_file_write;
    r->file = f;
    return &r->module;
}

void at_report_file_cleanup(at_report_t *r)
{
    free(r);
}

struct at_report_local {
    at_report_t  module;
    at_t        *t;
    at_report_t *saved_report;
    const int   *saved_fatal;
    const int   *saved_skip;
    const int   *saved_todo;
    int          dummy_fatal;
    char        *file;
    int          line;
    int          passed;
};

static int report_local_cleanup(void *data)
{
    struct at_report_local *q = data;
    dAT = q->t;
    char label[32];

    at_snprintf(label, 32, "collected %d passing tests", q->passed);

    AT->report = q->saved_report;
    AT->fatal  = q->saved_fatal;
    AT->skip   = q->saved_skip;
    AT->todo   = q->saved_todo;

    at_ok(q->t, 1, label, q->file, q->line);

    free(q->file);
    free(q);

    return AT_SUCCESS;
}

void at_report_delocalize(at_t *AT) {
    report_local_cleanup(AT->report);
}

static int at_report_local_write(at_report_t *ctx, const char *msg)
{
    char buf[256];
    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);
        report_local_cleanup(q);
        while (AT->current++ < AT->plan) {
            at_snprintf(buf, 256, "not ok %d # skipped: aborting test %s",
                        AT->prior + AT->current, AT->name);
            at_report(AT, buf);
        }
        longjmp(*AT->abort, 0);
    }
    else if (strncmp(msg, "ok", 2) == 0) {
        AT->current--;
        q->passed++;
    }
    return AT_SUCCESS;
}

void at_report_local(at_t *AT, const char *file, int line)
{
    struct at_report_local *q = malloc(sizeof *q);
    size_t len;

    q->module.func = at_report_local_write;
    q->t = AT;
    q->saved_report = AT->report;
    q->saved_fatal = AT->fatal;
    q->saved_skip = AT->skip;
    q->saved_todo = AT->todo;
    q->dummy_fatal = 0;
    q->line = line;
    q->passed = 0;

    len = strlen(file) + 1;
    q->file = (char*)malloc(len);
    memcpy(q->file, file, len);

    AT->fatal = AT->skip = AT->todo = &q->dummy_fatal;
    AT->report = &q->module;

    if (*q->saved_fatal == AT->current + 1)
        q->saved_fatal++;

}

at_t *at_create(unsigned char flags, at_report_t *report)
{
    at_t *t = calloc(sizeof *t, 1);
    t->flags = flags;
    t->report = report;
    return t;
}

static int* at_list(const char *spec)
{
    int prev, current = 0, count = 0, idx = 0, *elts;
    const char *start = spec;

    do {
        while (*spec && !isdigit((unsigned char)*spec))
            ++spec;
        prev = current;
        current = (int)strtol(spec, (char **)(void *)&spec, 10);
        ++count;

    } while (prev <= current);

    elts = malloc(++count * sizeof *elts);
    spec = start;
    current = 0;

    do {
        while (*spec && !isdigit((unsigned char)*spec))
            ++spec;
        prev = current;
        current = (int)strtol(spec, (char **)(void *)&spec, 10);
        elts[idx++] = current;

    } while (prev <= current);

    elts[idx] = 0; /* sentinel */

    return elts;
}

#define at_free_lists do { if (flist) free((void *)flist);       \
                           if (slist) free((void *)slist);       \
                           if (tlist) free((void *)tlist); } while (0)

int at_run(at_t *AT, const at_test_t *test)
{
    int dummy = 0;
    const int *flist = NULL, *slist = NULL, *tlist = NULL;
    jmp_buf j;

    AT->current = 0;
    AT->prior   += AT->plan;
    AT->name    = test->name;
    AT->plan    = test->plan;

    if (test->fatals)
        flist = AT->fatal = at_list(test->fatals);
    else
        AT->fatal = &dummy;

    if (test->skips)
        slist = AT->skip = at_list(test->skips);
    else
        AT->skip = &dummy;

    if (test->todos)
        tlist = AT->todo = at_list(test->todos);
    else
        AT->todo = &dummy;

    AT->abort = &j;
    if (setjmp(j) == 0) {
        test->func(AT, test->ctx);
        at_free_lists;
        return AT_SUCCESS;
    }
    at_free_lists;
    AT->abort = NULL;
    return AT_EGENERAL;
}

int at_snprintf(char *buf, int size, const char *format, ...)
{
    va_list args;
    int status;
    va_start(args, format);
    status = at_vsnprintf(buf, size, format, args);
    va_end(args);
    return status;
}

int at_vsnprintf(char *buf, int size, const char *format, va_list args)
{
#ifdef _MSC_VER
    int status = _vsnprintf(buf, size, format, args);
    /* Make Microsoft's _vsnprintf behave like C99 vsnprintf on overflow:
     * NULL-terminate, and return the number of chars printed minus one. */
    if (status < 0) {
        if (errno != EINVAL) {
            status = size - 1;
            buf[status] = '\0';
        }
    }
    return status;
#else 
    return vsnprintf(buf, size, format, args);
#endif /* _MSC_VER */
}

srclib/libapreq/t/at.h

deleted100644 → 0
+0 −301
Original line number Diff line number Diff line
/*
**  Licensed to the Apache Software Foundation (ASF) under one or more
** contributor license agreements.  See the NOTICE file distributed with
** this work for additional information regarding copyright ownership.
** The ASF licenses this file to You 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 <stdarg.h>
#include <stdlib.h>
#include <setjmp.h>
#include <stdio.h>
#include <string.h>

typedef struct at_t at_t;
typedef struct at_report_t at_report_t;

typedef int (*at_report_function_t)(at_report_t *r, const char *msg);
typedef void(*at_test_function_t)(at_t *t, void *ctx);
typedef struct at_test_t at_test_t;

struct at_test_t {
    const char          *name;
    at_test_function_t   func;
    int                  plan;
    void                *ctx;
    const char          *fatals;
    const char          *skips;
    const char          *todos;
};

struct at_report_t {
    at_report_function_t func;
};

/* Private, portable snprintf implementation. 
 */
int at_snprintf(char *buf, int size, const char *format, ...);
int at_vsnprintf(char *buf, int size, const char *format, va_list args); 

/* 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           *skip;    /* list of ignorabe assertions */
    const int           *todo;    /* list of expected failures */
    at_report_t         *report  ;/* handles the results of each check */
    unsigned char        flags;   /* verbosity: concise, trace, debug, etc. */
    jmp_buf             *abort;   /* where fatals go to die */
};



static inline
int 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(unsigned char flags, at_report_t *report);
int at_begin(at_t *t, int total);
#define AT_begin(total) at_begin(AT, total)

int 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_TODO(f)       ((f) & 8)
#define AT_FLAG_TODO_ON(f)    ((f) |= 8)
#define AT_FLAG_TODO_OFF(f)   ((f) &= ~8)
#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_todo_on()       AT_FLAG_TODO_ON(AT->flags)
#define AT_todo_off()      AT_FLAG_TODO_OFF(AT->flags)
#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". */

int at_comment(at_t *t, const char *fmt, va_list vp);

static 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 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 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[32] = "testing: %s (%s:%d)";
        at_trace(t, format, label, file, line);

        if (fmt != NULL) {
            char *f;
            at_snprintf(format, sizeof format, " format: %s", fmt);
            at_trace(t, "%s", format);
            memcpy(format, "   left:", 8);
            f = format + strlen(format);
            at_snprintf(f, sizeof format - strlen(format), "\n  right: %s", fmt);
            at_comment(t, format, vp);
        }
    }
    else if (AT_FLAG_DEBUG(t->flags) && !is_ok) {
        char format[32] = "testing: %s (%s:%d)";
        at_debug(t, format, label, file, line);

        if (fmt != NULL) {
            char *f;
            at_snprintf(format, sizeof format, " format: %s", fmt);
            at_debug(t, "%s", format);
            memcpy(format, "   left:", 8);
            f = format + strlen(format);
            at_snprintf(f, sizeof format - strlen(format), "\n  right: %s", fmt);
            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);                         \
    at_snprintf(buf + blen - 1, 256 - blen, fmt, sz);                   \
    at_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);                         \
    at_snprintf(buf + blen - 1, 256 - blen , fmt, sz);                  \
    at_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__, "%p", 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__, "%p", 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)


static inline
void at_skip(at_t *t, int n, const char *reason, const char *file, int line) {
    char buf[256];
    while (n-- > 0) {
        ++t->current;
        at_snprintf(buf, 256, "ok %d - %s (%d) #skipped: %s (%s:%d)",
                    t->current + t->prior, t->name, t->current, reason, file, line);
        at_report(t, buf);
    }
}

#define AT_skip(n, reason) at_skip(AT, n, reason, __FILE__, __LINE__)


/* Report utilities. */

at_report_t *at_report_file_make(FILE *f);
inline
static at_report_t *at_report_stdout_make(void)
{
    return at_report_file_make(stdout);
}
void at_report_file_cleanup(at_report_t *r);
#define at_report_stdout_cleanup(r) at_report_file_cleanup(r)

void at_report_local(at_t *AT, const char *file, int line);
#define AT_localize() at_report_local(AT, __FILE__, __LINE__)
void at_report_delocalize(at_t *AT);
#define AT_delocalize() at_report_delocalize(AT)

#endif /* AT_H */

srclib/libapreq/t/cookie.c

deleted100644 → 0
+0 −246

File deleted.

Preview size limit exceeded, changes collapsed.

Loading