summaryrefslogtreecommitdiff
path: root/test/pkev.c
blob: c3bfeb96af9524764c07bd645b785dbc87a3e22d (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

#include "../pkev.h"

#include "../pkmacros.h"

#include <stdio.h>

struct ev {
	bool handled;
};

struct ev ev_one = {0};
struct ev ev_two = {0};

void
handle_ev_one()
{
	ev_one.handled = true;
}

void
handle_ev_two()
{
	ev_two.handled = true;
}

const pk_ev_mgr_id_T
test_setup()
{
	memset(&ev_one, 0, sizeof(struct ev));
	memset(&ev_two, 0, sizeof(struct ev));
	pk_ev_init();
	const pk_ev_mgr_id_T evmgr = pk_ev_create_mgr();
	if (evmgr >= 64) {
		PK_LOGV_ERR("%s: failed to create pk_ev_mgr\n", __FILE__);
		exit(1);
	}
	return evmgr;
}

int main(int argc, char *argv[])
{
	(void)argc;
	(void)argv;
	(void)stdout;
	pk_ev_id_T custom_ev_one;
	pk_ev_id_T custom_ev_two;

	// register, emit, catch
	{
		const pk_ev_mgr_id_T evmgr = test_setup();
		custom_ev_one = pk_ev_register_ev(evmgr);
		custom_ev_two = pk_ev_register_ev(evmgr);
		pk_ev_register_cb(evmgr, custom_ev_one, handle_ev_one);
		pk_ev_register_cb(evmgr, custom_ev_two, handle_ev_two);
		pk_ev_emit(evmgr, custom_ev_one);
		pk_ev_emit(evmgr, custom_ev_two);
		PK_LOGV_INF("%s: ev_one: %b, ev_two: %b\n", __FILE__, ev_one.handled, ev_two.handled);
		pk_ev_teardown();
		if (ev_one.handled == false || ev_two.handled == false) exit(1);
	}

	return 0;
}