xref: /freebsd/crypto/krb5/src/ccapi/test/test_ccapi_check.h (revision 7f2fe78b9dd5f51c821d771b63d2e096f6fd49e9)
1 #ifndef _TEST_CCAPI_CHECK_H_
2 #define _TEST_CCAPI_CHECK_H_
3 
4 #include <stdio.h>
5 #include <stdarg.h>
6 #include "test_ccapi_log.h"
7 #include "test_ccapi_globals.h"
8 
9 int _check_if(int expression, const char *file, int line, const char *expression_string, const char *format, ...);
10 
11 #define check_int(a, b) \
12 		check_if(a != b, NULL)
13 
14 /*
15  *	if expression evaluates to true, check_if increments the failure_count and prints:
16  *
17  *	check_if(a!=a, NULL);
18  *	==> "/path/to/file:line: a!=a"
19  *
20  *	check_if(a!=a, "This shouldn't be happening");
21  *	==> "/path/to/file:line: This shouldn't be happening"
22  *
23  *	check_if(a!=a, "This has happened %d times now", 3);
24  *	==> "/path/to/file:line: This has happened 3 times now"
25 */
26 
27 #define check_if(expression, format, ...) \
28 		_check_if(expression, __FILE__, __LINE__, #expression, format , ## __VA_ARGS__)
29 
30 #define check_if_not(expression, format, ...) \
31 		check_if(!(expression), format, ## __VA_ARGS__)
32 
33 // first check if err is what we were expecting to get back
34 // then check if err is even in the set of errors documented for the function
35 #define check_err(err, expected_err, possible_return_values) \
36 		do { \
37 			check_if(err != expected_err, "unexpected error %s (%d), expected %s (%d)", translate_ccapi_error(err), err, translate_ccapi_error(expected_err), expected_err); \
38 			check_if_not(array_contains_int(possible_return_values, possible_ret_val_count, err), "error not documented as a possible return value: %s (%d)", translate_ccapi_error(err), err); \
39 		} while( 0 )
40 
41 int array_contains_int(cc_int32 *array, int size, cc_int32 value);
42 
43 #endif /* _TEST_CCAPI_CHECK_H_ */
44