~rcr/rirc

ref: 3b5b3941da19ad208c1f79b6f09525f50677ec4e rirc/test/io.mock.c -rw-r--r-- 1.2 KiB
3b5b3941 — Richard Robbins fix docs 2 months ago
                                                                                
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#include <stdarg.h>

#define MOCK_SEND_LEN 512
#define MOCK_SEND_N   10

static char mock_send[MOCK_SEND_N][MOCK_SEND_LEN];
static unsigned mock_send_i;
static unsigned mock_send_n;
static int cxed;

void
mock_reset_io(void)
{
	mock_send_i = 0;
	mock_send_n = 0;
	memset(mock_send, 0, MOCK_SEND_LEN * MOCK_SEND_N);
	cxed = 0;
}

int
io_sendf(struct connection *c, const char *fmt, ...)
{
	va_list ap;

	UNUSED(c);

	va_start(ap, fmt);
	assert_gt(vsnprintf(mock_send[mock_send_i], sizeof(mock_send[0]), fmt, ap), 0);
	va_end(ap);

	mock_send_n++;

	if (mock_send_i++ == MOCK_SEND_N)
		mock_send_i = 0;

	return 0;
}

struct connection*
connection(const void *o, const char *h, const char *p, uint32_t f)
{
	UNUSED(o);
	UNUSED(h);
	UNUSED(p);
	UNUSED(f);
	return NULL;
}

int
io_cx(struct connection *c)
{
	UNUSED(c);

	if (cxed)
		return -1;

	cxed = 1;
	return 0;
}

int
io_dx(struct connection *c)
{
	UNUSED(c);

	if (cxed) {
		cxed = 0;
		return 0;
	}

	return -1;
}

const char*
io_err(int err)
{
	UNUSED(err);

	return (cxed ? "cxed" : "dxed");
}

unsigned io_tty_cols(void) { return 0; }
unsigned io_tty_rows(void) { return 0; }
void connection_free(struct connection *c) { UNUSED(c); }
void io_init(void) { ; }
void io_start(void) { ; }
void io_stop(void) { ; }