tdb: Vectorize _tdb_store
[samba.git] / lib / tdb / test / tap-to-subunit.h
1 #ifndef TAP_TO_SUBUNIT_H
2 #define TAP_TO_SUBUNIT_H
3 /*
4  * tap-style wrapper for subunit.
5  *
6  * Copyright (c) 2011 Rusty Russell
7  * All rights reserved.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions
11  * are met:
12  * 1. Redistributions of source code must retain the above copyright
13  *    notice, this list of conditions and the following disclaimer.
14  * 2. Redistributions in binary form must reproduce the above copyright
15  *    notice, this list of conditions and the following disclaimer in the
16  *    documentation and/or other materials provided with the distribution.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
19  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
22  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28  * SUCH DAMAGE.
29  */
30 #include "replace.h"
31
32 /**
33  * plan_tests - announce the number of tests you plan to run
34  * @tests: the number of tests
35  *
36  * This should be the first call in your test program: it allows tracing
37  * of failures which mean that not all tests are run.
38  *
39  * If you don't know how many tests will actually be run, assume all of them
40  * and use skip() if you don't actually run some tests.
41  *
42  * Example:
43  *      plan_tests(13);
44  */
45 void plan_tests(unsigned int tests);
46
47 /**
48  * ok1 - Simple conditional test
49  * @e: the expression which we expect to be true.
50  *
51  * This is the simplest kind of test: if the expression is true, the
52  * test passes.  The name of the test which is printed will simply be
53  * file name, line number, and the expression itself.
54  *
55  * Example:
56  *      ok1(somefunc() == 1);
57  */
58 # define ok1(e) ((e) ?                                                  \
59                  _gen_result(1, __func__, __FILE__, __LINE__, "%s", #e) : \
60                  _gen_result(0, __func__, __FILE__, __LINE__, "%s", #e))
61
62 /**
63  * ok - Conditional test with a name
64  * @e: the expression which we expect to be true.
65  * @...: the printf-style name of the test.
66  *
67  * If the expression is true, the test passes.  The name of the test will be
68  * the filename, line number, and the printf-style string.  This can be clearer
69  * than simply the expression itself.
70  *
71  * Example:
72  *      ok1(somefunc() == 1);
73  *      ok(somefunc() == 0, "Second somefunc() should fail");
74  */
75 # define ok(e, ...) ((e) ?                                              \
76                      _gen_result(1, __func__, __FILE__, __LINE__,       \
77                                  __VA_ARGS__) :                         \
78                      _gen_result(0, __func__, __FILE__, __LINE__,       \
79                                  __VA_ARGS__))
80
81 /**
82  * pass - Note that a test passed
83  * @...: the printf-style name of the test.
84  *
85  * For complicated code paths, it can be easiest to simply call pass() in one
86  * branch and fail() in another.
87  *
88  * Example:
89  *      int x = somefunc();
90  *      if (x > 0)
91  *              pass("somefunc() returned a valid value");
92  *      else
93  *              fail("somefunc() returned an invalid value");
94  */
95 # define pass(...) ok(1, __VA_ARGS__)
96
97 /**
98  * fail - Note that a test failed
99  * @...: the printf-style name of the test.
100  *
101  * For complicated code paths, it can be easiest to simply call pass() in one
102  * branch and fail() in another.
103  */
104 # define fail(...) ok(0, __VA_ARGS__)
105
106 unsigned int _gen_result(int, const char *, const char *, unsigned int,
107    const char *, ...) PRINTF_ATTRIBUTE(5, 6);
108
109 /**
110  * diag - print a diagnostic message (use instead of printf/fprintf)
111  * @fmt: the format of the printf-style message
112  *
113  * diag ensures that the output will not be considered to be a test
114  * result by the TAP test harness.  It will append '\n' for you.
115  *
116  * Example:
117  *      diag("Now running complex tests");
118  */
119 void diag(const char *fmt, ...) PRINTF_ATTRIBUTE(1, 2);
120
121 /**
122  * skip - print a diagnostic message (use instead of printf/fprintf)
123  * @n: number of tests you're skipping.
124  * @fmt: the format of the reason you're skipping the tests.
125  *
126  * Sometimes tests cannot be run because the test system lacks some feature:
127  * you should explicitly document that you're skipping tests using skip().
128  *
129  * From the Test::More documentation:
130  *   If it's something the user might not be able to do, use SKIP.  This
131  *   includes optional modules that aren't installed, running under an OS that
132  *   doesn't have some feature (like fork() or symlinks), or maybe you need an
133  *   Internet connection and one isn't available.
134  *
135  * Example:
136  *      #ifdef HAVE_SOME_FEATURE
137  *      ok1(somefunc());
138  *      #else
139  *      skip(1, "Don't have SOME_FEATURE");
140  *      #endif
141  */
142 void skip(unsigned int n, const char *fmt, ...) PRINTF_ATTRIBUTE(2, 3);
143
144 /**
145  * exit_status - the value that main should return.
146  *
147  * For maximum compatibility your test program should return a particular exit
148  * code (ie. 0 if all tests were run, and every test which was expected to
149  * succeed succeeded).
150  *
151  * Example:
152  *      exit(exit_status());
153  */
154 int exit_status(void);
155 #endif /* CCAN_TAP_H */