summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorJonathan Bradley <jcb@pikum.xyz>2024-11-01 14:00:19 -0400
committerJonathan Bradley <jcb@pikum.xyz>2024-11-01 14:00:19 -0400
commitf249c81418bc08d5cef7ea33ac5ff2546ba53774 (patch)
tree5e403a85af88114e2e2077c6270c35513bfe5c5b /test
parent2f4944595da6011e15ba2a65637c916665bc95e0 (diff)
pkev: commit test files
Diffstat (limited to 'test')
-rw-r--r--test/pkev.c64
-rw-r--r--test/pkev.cpp65
2 files changed, 129 insertions, 0 deletions
diff --git a/test/pkev.c b/test/pkev.c
new file mode 100644
index 0000000..675de4b
--- /dev/null
+++ b/test/pkev.c
@@ -0,0 +1,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;
+}
+
+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;
+}
diff --git a/test/pkev.cpp b/test/pkev.cpp
new file mode 100644
index 0000000..86c1706
--- /dev/null
+++ b/test/pkev.cpp
@@ -0,0 +1,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;
+}