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 9int _check_if(int expression, const char *file, int line, const char *expression_string, const char *format, ...) 10 __attribute__ ((format (printf, 5, 6))); 11 12#define check_int(a, b) \ 13 check_if(a != b, NULL) 14 15/* 16 * if expression evaluates to true, check_if increments the failure_count and prints: 17 * 18 * check_if(a!=a, NULL); 19 * ==> "/path/to/file:line: a!=a" 20 * 21 * check_if(a!=a, "This shouldn't be happening"); 22 * ==> "/path/to/file:line: This shouldn't be happening" 23 * 24 * check_if(a!=a, "This has happened %d times now", 3); 25 * ==> "/path/to/file:line: This has happened 3 times now" 26*/ 27 28#define check_if(expression, format, ...) \ 29 _check_if(expression, __FILE__, __LINE__, #expression, format , ## __VA_ARGS__) 30 31#define check_if_not(expression, format, ...) \ 32 check_if(!(expression), format, ## __VA_ARGS__) 33 34// first check if err is what we were expecting to get back 35// then check if err is even in the set of errors documented for the function 36#define check_err(err, expected_err, possible_return_values) \ 37 do { \ 38 check_if(err != expected_err, "unexpected error %s (%d), expected %s (%d)", translate_ccapi_error(err), err, translate_ccapi_error(expected_err), expected_err); \ 39 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); \ 40 } while( 0 ) 41 42int array_contains_int(cc_int32 *array, int size, cc_int32 value); 43 44#endif /* _TEST_CCAPI_CHECK_H_ */ 45