4 #define _XOPEN_SOURCE 500
12 char *unit_name
, *reason
= NULL
;
13 unsigned int passed
, failed
;
15 /* Print formated string into automtically reallocated @uffer.
16 * @buffer automatically reallocated buffer. Must be &NULL or preallocated
18 * @format format string as for printf(3)
19 * @ap list of variadic arguments, after call will be in udefined state
20 * @Returns number of bytes printed. In case of errror, -1 and NULL @buffer*/
21 int test_vasprintf(char **buffer
, const char *format
, va_list ap
);
24 /* Print formated string into automtically reallocated @uffer.
25 * @buffer automatically reallocated buffer. Must be &NULL or preallocated
27 * @format format string as for printf(3)
28 * @... variadic arguments
29 * @Returns number of bytes printed. In case of errror, -1 and NULL @buffer*/
30 int test_asprintf(char **buffer
, const char *format
, ...);
33 /* I/O. Return 0, in case of error -1. */
34 int test_mmap_file(const char *file
, int *fd
, void **buffer
, size_t *length
);
35 int test_munmap_file(int fd
, void *buffer
, size_t length
);
37 #define INIT_TEST(name) { \
38 setlocale(LC_ALL, "C"); \
40 passed = failed = 0; \
41 printf("Testing unit: %s\n", unit_name); \
44 #define SUM_TEST() { \
45 printf("Test results: unit = %s, passed = %u, failed = %u\n\n", \
46 unit_name, passed, failed); \
47 exit(failed ? EXIT_FAILURE : EXIT_SUCCESS ); \
54 #define FAILURE_REASON(...) { \
56 test_asprintf(&reason, __VA_ARGS__); \
59 #define FAIL_TEST(...) { \
60 FAILURE_REASON(__VA_ARGS__); \
64 #define ABORT_UNIT(message) { \
65 printf("Unit %s procedure aborted: %s\n", unit_name, (message)); \
70 #define TEST(name, function, ...) { \
71 const char *message; \
72 free(reason); reason = NULL; \
73 int status = (function)(__VA_ARGS__); \
81 printf("\t%s: %s\n", (name), message); \
82 if (status) printf("\t\treason: %s\n", reason); \
83 free(reason); reason = NULL; \
86 #define TEST_CALLOC(pointer) { \
87 (pointer) = calloc(1, sizeof(*(pointer))); \
89 ABORT_UNIT("No enough memory"); \
92 #define TEST_FILL_STRING(pointer) { \
93 (pointer) = strdup("DATA"); \
95 ABORT_UNIT("No enough memory"); \
98 #define TEST_FILL_INT(pointer) { \
99 (pointer) = malloc(sizeof(*(pointer))); \
101 ABORT_UNIT("No enough memory"); \