summaryrefslogtreecommitdiff
path: root/test/pkev.cpp
blob: 86c170697c086e94b13ca863a9396ab4c0a5d8f5 (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

#include "../pkev.h"

#include "../pkmacros.h"

#include <cstdio>
#include <string>

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;
}

struct pk_ev_mgr*
test_setup()
{
	memset(&ev_one, 0, sizeof(struct ev));
	memset(&ev_two, 0, sizeof(struct ev));
	struct pk_ev_mgr *evmgr = pk_ev_create();
	if (evmgr == NULL) {
		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 = 1;
	pk_ev_id_T custom_ev_two = 2;

	// register, emit, catch
	{
		// TODO
		struct pk_ev_mgr *evmgr = test_setup();
		pk_ev_register_ev(evmgr, custom_ev_one);
		pk_ev_register_ev(evmgr, custom_ev_two);
		pk_ev_register_cb(evmgr, custom_ev_one, handle_ev_one);
		pk_ev_register_cb(evmgr, custom_ev_one, 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);
		free(evmgr);
		if (ev_one.handled == false || ev_two.handled == false) exit(1);
	}

	return 0;
}