-
Notifications
You must be signed in to change notification settings - Fork 10
/
test.h
49 lines (36 loc) · 1.05 KB
/
test.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include <stdarg.h>
#include <stdio.h>
#include <stdbool.h>
#include <stdint.h>
#include <stddef.h>
#ifdef __cplusplus
extern "C" {
#endif
extern unsigned int num_errors;
void print_buffer(FILE* file, const uint8_t* buffer, size_t length);
bool check(bool value, const char* fmt, ...);
bool check_equal(int a, int b, const char* fmt, ...);
#ifdef __cplusplus
} // extern "C"
void printT(FILE* file, int value) { fprintf(file, "%d", value); }
void printT(FILE* file, unsigned int value) { fprintf(file, "%u", value); }
void printT(FILE* file, size_t value) { fprintf(file, "%zu", value); }
void printT(FILE* file, const void* value) { fprintf(file, "%p", value); }
template<typename A, typename B>
bool check_equal(A a, B b, const char* fmt, ...)
{
if( a == b )
return true;
va_list argptr;
va_start(argptr, fmt);
vfprintf(stderr, fmt, argptr);
va_end(argptr);
fprintf(stderr, "( ");
printT(stderr, a);
fprintf(stderr, " != ");
printT(stderr, b);
fprintf(stderr, ")\n");
num_errors++;
return false;
}
#endif