/* $Header: /cvsroot/dhcp-agent/dhcp-agent/tests/tests.h,v 1.1 2002/12/30 00:47:52 actmodern Exp $
 * 
 * Copyright 2002 Thamer Alharbash <tmh@whitefang.com>
 * 
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 
 * 1. Redistributions of source code must retain the above copyright
 * notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 * notice, this list of conditions and the following disclaimer in
 * the documentation and/or other materials provided with the
 * distribution.
 * 3. The names of the authors may not be used to endorse or promote
 * products derived from this software without specific prior
 * written permission.
 * 
 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
 * 
 */

#ifndef TESTS_H
#define TESTS_H

/* types */

/* test function. */
typedef int (*test_t)(const char *name);

typedef struct {
    const char *name;
    test_t test_func;
} test_table;

/* exit values. */
#define TESTS_EXIT_FAILURE 1
#define TESTS_EXIT_SUCCESS 0
#define TESTS_EXIT_IGNORE 77

/* macros. */

#define TEST_ERROR(name, x) { fprintf(stderr, "test error (%s):\n", name); fprintf(stderr, "%s\n", x); }
#define TEST_MSG(x)   { fprintf(stdout, "%s\n", x); }

#define TEST_NELMS(x) (sizeof(x)/sizeof(x[0]))

#define DO_TESTS(x)   { \
    int i; \
    for(i = 0;i < TEST_NELMS(x);i++) { \
        if(x[i].test_func(x[i].name)) \
            exit(TESTS_EXIT_FAILURE); \
   } \
}

#endif /* TESTS_H */


syntax highlighted by Code2HTML, v. 0.9.1