-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.h
61 lines (43 loc) · 1.35 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
50
51
52
53
54
55
56
57
58
59
60
61
#ifndef TEST_H_
#define TEST_H_
#include <stdbool.h>
#include <stdint.h>
#define TEST_DEF(name) bool name(const void* data,const uint32_t size)
#ifdef ENABLE_TEST_ASSERTION
#define ASSERT_ARRAYEQ(tp,c,val,...) {const tp temp[c] = {__VA_ARGS__}; if (memcmp((void*)temp,(void*)val,c*sizeof(tp)) != 0) return 0; }
#define ASSERT_ARRAYEQ_U16(val,...) ASSERT_ARRAYEQ(uint16_t,16,val,__VA_ARGS__)
#define ASSERT_ARRAYEQ_U32(val,...) ASSERT_ARRAYEQ(uint16_t,32,val,__VA_ARGS__)
#else
#define ASSERT_ARRAYEQ(tp,c,val,...)
#define ASSERT_ARRAYEQ_U16(val,...)
#define ASSERT_ARRAYEQ_U32(val,...)
#endif
#define TEST_SUCCESS() return 1
#define TEST_FAIL() return 0
#define ADD_TEST_ARG(s,name,arg,sz) addToSuite(&s,#name,name,arg,sz)
#define ADD_TEST(s,name) ADD_TEST_ARG(s,name,NULL,0)
#ifdef SIMULATOR
#define PRINTFM(...) printf(__VA_ARGS__)
#else
#define PRINTFM(...)
#endif
typedef bool (*test_fnc)(const void*,const uint32_t);
typedef struct {
char name[100];
test_fnc fun;
void* data;
uint32_t size;
bool enable;
void* next;
} test;
typedef struct {
char name[100];
test* first;
test* last;
} suite;
void createSuite(const char* name,suite* s);
test* addToSuite(suite* s,const char* name,test_fnc fun,void* data,uint32_t size);
void freeSuite(suite* s);
void runSuiteCritical(const suite* s);
bool runSuiteCareless(const suite* s);
#endif