Fix the trailing #endif comment in tests/tap/basic.h
[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 <stdarg.h>             /* va_list */
19 #include <sys/types.h>          /* pid_t */
20
21 /*
22  * __attribute__ is available in gcc 2.5 and later, but only with gcc 2.7
23  * could you use the __format__ form of the attributes, which is what we use
24  * (to avoid confusion with other macros).
25  */
26 #ifndef __attribute__
27 # if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 7)
28 #  define __attribute__(spec)   /* empty */
29 # endif
30 #endif
31
32 /*
33  * BEGIN_DECLS is used at the beginning of declarations so that C++
34  * compilers don't mangle their names.  END_DECLS is used at the end.
35  */
36 #undef BEGIN_DECLS
37 #undef END_DECLS
38 #ifdef __cplusplus
39 # define BEGIN_DECLS    extern "C" {
40 # define END_DECLS      }
41 #else
42 # define BEGIN_DECLS    /* empty */
43 # define END_DECLS      /* empty */
44 #endif
45
46 /*
47  * Used for iterating through arrays.  ARRAY_SIZE returns the number of
48  * elements in the array (useful for a < upper bound in a for loop) and
49  * ARRAY_END returns a pointer to the element past the end (ISO C99 makes it
50  * legal to refer to such a pointer as long as it's never dereferenced).
51  */
52 #define ARRAY_SIZE(array)       (sizeof(array) / sizeof((array)[0]))
53 #define ARRAY_END(array)        (&(array)[ARRAY_SIZE(array)])
54
55 BEGIN_DECLS
56
57 /*
58  * The test count.  Always contains the number that will be used for the next
59  * test status.
60  */
61 extern unsigned long testnum;
62
63 /* Print out the number of tests and set standard output to line buffered. */
64 void plan(unsigned long count);
65
66 /*
67  * Prepare for lazy planning, in which the plan will be  printed automatically
68  * at the end of the test program.
69  */
70 void plan_lazy(void);
71
72 /* Skip the entire test suite.  Call instead of plan. */
73 void skip_all(const char *format, ...)
74     __attribute__((__noreturn__, __format__(printf, 1, 2)));
75
76 /*
77  * Basic reporting functions.  The okv() function is the same as ok() but
78  * takes the test description as a va_list to make it easier to reuse the
79  * reporting infrastructure when writing new tests.
80  */
81 void ok(int success, const char *format, ...)
82     __attribute__((__format__(printf, 2, 3)));
83 void okv(int success, const char *format, va_list args);
84 void skip(const char *reason, ...)
85     __attribute__((__format__(printf, 1, 2)));
86
87 /* Report the same status on, or skip, the next count tests. */
88 void ok_block(unsigned long count, int success, const char *format, ...)
89     __attribute__((__format__(printf, 3, 4)));
90 void skip_block(unsigned long count, const char *reason, ...)
91     __attribute__((__format__(printf, 2, 3)));
92
93 /* Check an expected value against a seen value. */
94 void is_int(long wanted, long seen, const char *format, ...)
95     __attribute__((__format__(printf, 3, 4)));
96 void is_double(double wanted, double seen, const char *format, ...)
97     __attribute__((__format__(printf, 3, 4)));
98 void is_string(const char *wanted, const char *seen, const char *format, ...)
99     __attribute__((__format__(printf, 3, 4)));
100 void is_hex(unsigned long wanted, unsigned long seen, const char *format, ...)
101     __attribute__((__format__(printf, 3, 4)));
102
103 /* Bail out with an error.  sysbail appends strerror(errno). */
104 void bail(const char *format, ...)
105     __attribute__((__noreturn__, __nonnull__, __format__(printf, 1, 2)));
106 void sysbail(const char *format, ...)
107     __attribute__((__noreturn__, __nonnull__, __format__(printf, 1, 2)));
108
109 /* Report a diagnostic to stderr prefixed with #. */
110 void diag(const char *format, ...)
111     __attribute__((__nonnull__, __format__(printf, 1, 2)));
112 void sysdiag(const char *format, ...)
113     __attribute__((__nonnull__, __format__(printf, 1, 2)));
114
115 END_DECLS
116
117 #endif /* TAP_BASIC_H */