diff options
author | Paul "LeoNerd" Evans <leonerd@leonerd.org.uk> | 2021-08-17 17:48:43 +0100 |
---|---|---|
committer | Paul "LeoNerd" Evans <leonerd@leonerd.org.uk> | 2021-08-17 17:48:43 +0100 |
commit | 2d70fc7f22c872a4e3b0dde5f0680e468e4b3d19 (patch) | |
tree | ce6f84965f6b052f5cf63f9bb53c30c149be87e6 /t | |
parent | 81ad6a99790c2e42cbe76f09a386acb3338d44d4 (diff) |
Initial attempt at a tickit_watch_signal()
Diffstat (limited to 't')
-rw-r--r-- | t/54tickit-signal.c | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/t/54tickit-signal.c b/t/54tickit-signal.c new file mode 100644 index 0000000..329291d --- /dev/null +++ b/t/54tickit-signal.c @@ -0,0 +1,53 @@ +#include "tickit.h" +#include "tickit-mockterm.h" +#include "taplib.h" + +#include <signal.h> + +static int unbound_count; +static int on_call_incr(Tickit *t, TickitEventFlags flags, void *info, void *user) +{ + if(flags & TICKIT_EV_FIRE) { + int *ip = user; + (*ip)++; + + tickit_stop(t); + } + if(flags & TICKIT_EV_UNBIND) + unbound_count++; + + return 1; +} + +int main(int argc, char *argv[]) +{ + Tickit *t = tickit_new_for_term(tickit_mockterm_new(25, 80)); + + { + int called = 0; + void *w = tickit_watch_signal(t, SIGHUP, TICKIT_BIND_UNBIND, &on_call_incr, &called); + + raise(SIGHUP); + + tickit_run(t); + + is_int(called, 1, "tickit_watch_signal invokes callback"); + + tickit_watch_cancel(t, w); + + is_int(unbound_count, 1, "unbound_count after tickit_watch_cancel"); + } + + /* object destruction */ + { + tickit_watch_signal(t, SIGHUP, TICKIT_BIND_DESTROY, &on_call_incr, NULL); + + unbound_count = 0; + + tickit_unref(t); + + is_int(unbound_count, 1, "unbound_count after tickit_unref"); + } + + return exit_status(); +} |