~rcr/rirc

ref: 62bd337228e97c54534bb8a9efede99fb2d8a5c5 rirc/test/state.mock.c -rw-r--r-- 1.4 KiB
62bd3372 — Richard Robbins add --tls-cert-client flag 4 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
#include <stdarg.h>

#define MOCK_CHAN_LEN 512
#define MOCK_LINE_LEN 512
#define MOCK_LINE_N   10

static char mock_chan[MOCK_LINE_N][MOCK_CHAN_LEN];
static char mock_line[MOCK_LINE_N][MOCK_LINE_LEN];
static unsigned mock_line_i;
static unsigned mock_line_n;

void
mock_reset_state(void)
{
	mock_line_i = 0;
	mock_line_n = 0;
	memset(mock_chan, 0, MOCK_LINE_N * MOCK_CHAN_LEN);
	memset(mock_line, 0, MOCK_LINE_N * MOCK_LINE_LEN);
}

void
newlinef(struct channel *c, enum buffer_line_type t, const char *f, const char *fmt, ...)
{
	va_list ap;
	int r1;
	int r2;

	UNUSED(f);
	UNUSED(t);

	va_start(ap, fmt);
	r1 = snprintf(mock_chan[mock_line_i], sizeof(mock_chan[mock_line_i]), "%s", c->name);
	r2 = vsnprintf(mock_line[mock_line_i], sizeof(mock_line[mock_line_i]), fmt, ap);
	va_end(ap);

	mock_line_n++;

	if (mock_line_i++ == MOCK_LINE_N)
		mock_line_i = 0;

	assert_gt(r1, 0);
	assert_gt(r2, 0);
}

void
newline(struct channel *c, enum buffer_line_type t, const char *f, const char *fmt)
{
	int r1;
	int r2;

	UNUSED(f);
	UNUSED(t);

	r1 = snprintf(mock_chan[mock_line_i], sizeof(mock_chan[mock_line_i]), "%s", c->name);
	r2 = snprintf(mock_line[mock_line_i], sizeof(mock_line[mock_line_i]), "%s", fmt);

	mock_line_n++;

	if (mock_line_i++ == MOCK_LINE_N)
		mock_line_i = 0;

	assert_gt(r1, 0);
	assert_gt(r2, 0);
}

struct channel* current_channel(void) { return NULL; }
void channel_set_current(struct channel *c) { UNUSED(c); }