Import C TAP Harness 1.2 as a testing harness
[openafs.git] / tests / tap / basic.h
1 /*
2  * Basic utility routines for the TAP protocol.
3  *
4  * Copyright 2009, 2010 Russ Allbery <rra@stanford.edu>
5  * Copyright 2006, 2007, 2008
6  *     Board of Trustees, Leland Stanford Jr. University
7  * Copyright (c) 2004, 2005, 2006
8  *     by Internet Systems Consortium, Inc. ("ISC")
9  * Copyright (c) 1991, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001,
10  *     2002, 2003 by The Internet Software Consortium and Rich Salz
11  *
12  * See LICENSE for licensing terms.
13  */
14
15 #ifndef TAP_BASIC_H
16 #define TAP_BASIC_H 1
17
18 #include <sys/types.h>          /* pid_t */
19
20 /*
21  * __attribute__ is available in gcc 2.5 and later, but only with gcc 2.7
22  * could you use the __format__ form of the attributes, which is what we use
23  * (to avoid confusion with other macros).
24  */
25 #ifndef __attribute__
26 # if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 7)
27 #  define __attribute__(spec)   /* empty */
28 # endif
29 #endif
30
31 /*
32  * BEGIN_DECLS is used at the beginning of declarations so that C++
33  * compilers don't mangle their names.  END_DECLS is used at the end.
34  */
35 #undef BEGIN_DECLS
36 #undef END_DECLS
37 #ifdef __cplusplus
38 # define BEGIN_DECLS    extern "C" {
39 # define END_DECLS      }
40 #else
41 # define BEGIN_DECLS    /* empty */
42 # define END_DECLS      /* empty */
43 #endif
44
45 /*
46  * Used for iterating through arrays.  ARRAY_SIZE returns the number of
47  * elements in the array (useful for a < upper bound in a for loop) and
48  * ARRAY_END returns a pointer to the element past the end (ISO C99 makes it
49  * legal to refer to such a pointer as long as it's never dereferenced).
50  */
51 #define ARRAY_SIZE(array)       (sizeof(array) / sizeof((array)[0]))
52 #define ARRAY_END(array)        (&(array)[ARRAY_SIZE(array)])
53
54 BEGIN_DECLS
55
56 /*
57  * The test count.  Always contains the number that will be used for the next
58  * test status.
59  */
60 extern unsigned long testnum;
61
62 /* Print out the number of tests and set standard output to line buffered. */
63 void plan(unsigned long count);
64
65 /*
66  * Prepare for lazy planning, in which the plan will be  printed automatically
67  * at the end of the test program.
68  */
69 void plan_lazy(void);
70
71 /* Skip the entire test suite.  Call instead of plan. */
72 void skip_all(const char *format, ...)
73     __attribute__((__noreturn__, __format__(printf, 1, 2)));
74
75 /* Basic reporting functions. */
76 void ok(int success, const char *format, ...)
77     __attribute__((__format__(printf, 2, 3)));
78 void skip(const char *reason, ...)
79     __attribute__((__format__(printf, 1, 2)));
80
81 /* Report the same status on, or skip, the next count tests. */
82 void ok_block(unsigned long count, int success, const char *format, ...)
83     __attribute__((__format__(printf, 3, 4)));
84 void skip_block(unsigned long count, const char *reason, ...)
85     __attribute__((__format__(printf, 2, 3)));
86
87 /* Check an expected value against a seen value. */
88 void is_int(long wanted, long seen, const char *format, ...)
89     __attribute__((__format__(printf, 3, 4)));
90 void is_double(double wanted, double seen, const char *format, ...)
91     __attribute__((__format__(printf, 3, 4)));
92 void is_string(const char *wanted, const char *seen, const char *format, ...)
93     __attribute__((__format__(printf, 3, 4)));
94 void is_hex(unsigned long wanted, unsigned long seen, const char *format, ...)
95     __attribute__((__format__(printf, 3, 4)));
96
97 /* Bail out with an error.  sysbail appends strerror(errno). */
98 void bail(const char *format, ...)
99     __attribute__((__noreturn__, __nonnull__, __format__(printf, 1, 2)));
100 void sysbail(const char *format, ...)
101     __attribute__((__noreturn__, __nonnull__, __format__(printf, 1, 2)));
102
103 /* Report a diagnostic to stderr prefixed with #. */
104 void diag(const char *format, ...)
105     __attribute__((__nonnull__, __format__(printf, 1, 2)));
106 void sysdiag(const char *format, ...)
107     __attribute__((__nonnull__, __format__(printf, 1, 2)));
108
109 END_DECLS
110
111 #endif /* LIBTEST_H */