summaryrefslogtreecommitdiffstats
path: root/test/test-lib.h
blob: 54c147283b5fc93875a8b8c012c65727376a310c (plain)
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
62
63
64
65
#ifndef TEST_LIB
#define TEST_LIB

#include <config.h>
#include <stdlib.h>

struct lt_config_shared *config_init(void);
void config_clear(struct lt_config_shared *sh);
int fout_read(struct lt_config_shared *sh, char *buf, int size);

enum {
	RE_TEST_TYPE_STR = 1,
	RE_TEST_TYPE_INT = 2,
	RE_TEST_TYPE_PID = 3,
};

enum {
	RE_TEST_OFF_UNDEF = -1,
};

enum {
	RE_TEST_OK = -1,
};

struct re_test_data {
	int type;
	int so;
	int eo;
	char *pat;
};

int re_test(char *line, struct re_test_data *data, int cnt);

#define TEST_START() sh->disabled = 0
#define TEST_STOP()  sh->disabled = 1

#define PASSED() \
do { \
	printf("."); \
	fflush(NULL); \
} while(0)

#define FAILED(fmt, args...) \
do { \
	char lpbuf[1024]; \
	sprintf(lpbuf, "%s:%d failed - %s", \
		__FUNCTION__, \
		__LINE__, \
		fmt); \
	printf(lpbuf, ## args); \
	fflush(NULL); \
	exit(-1); \
} while(0)

#define TEST(testfn) \
do { \
	if (testfn(sh)) { \
		printf("FAILED %s\n", #testfn); \
		return -1; \
	} \
} while(0)

#define BUFSIZE 1000

#endif