From 43f7d1a6614dcf71503efd55ccad31f5dd5febea Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Sat, 18 May 2019 13:26:55 -0400 Subject: [PATCH] Started the events test suite. --- test/events.c | 53 ++++++++++++++++++++++++++++++++++++++++++++++++ test/meson.build | 1 + 2 files changed, 54 insertions(+) create mode 100644 test/events.c diff --git a/test/events.c b/test/events.c new file mode 100644 index 00000000..d7d27a3d --- /dev/null +++ b/test/events.c @@ -0,0 +1,53 @@ +// 18 may 2019 +#include "test.h" + +struct handler { + bool run; + void *sender; + void *args; +}; + +static void handler(void *sender, void *args, void *data) +{ + struct handler *h = (struct handler *) data; + + h->run = true; + h->sender = sender; + h->args = args; +} + +#define basicTest(name, whichGlobal, whichSender, whichArgs) \ + testingTest(name) \ + { \ + uiEvent *e; \ + uiEventOptions opts; \ + struct handler h; \ + memset(&opts, 0, sizeof (uiEventOptions)); \ + opts.Size = sizeof (uiEventOptions); \ + opts.Global = whichGlobal; \ + e = uiNewEvent(&opts); \ + memset(&h, 0, sizeof (struct handler)); \ + uiEventAddHandler(e, handler, whichSender, &h); \ + uiEventFire(e, whichSender, whichArgs); \ + if (!h.run) \ + testingTErrorf(t, "handler not run"); \ + if (h.sender != whichSender) \ + diff(t, "incorrect sender seen by handler", \ + "%p", h.sender, whichSender); \ + if (h.args != whichArgs) \ + diff(t, "incorrect args seen by handler", \ + "%p", h.args, whichArgs); \ + } +basicTest(BasicEvents_Global_Args, true, NULL, &h) +basicTest(BasicEvents_Global_NoArgs, true, NULL, NULL) +basicTest(BasicEvents_Nonglobal_Args, false, &opts, &h) +basicTest(BasicEvents_Nonglobal_NoArgs, false, &opts, NULL) + +testingTest(AddDeleteEventHandler) +{ +} + +testingTest(EventErrors) +{ + // TODO +} diff --git a/test/meson.build b/test/meson.build index 28cb8033..b18d7122 100644 --- a/test/meson.build +++ b/test/meson.build @@ -1,6 +1,7 @@ # 23 march 2019 libui_test_sources = [ + 'events.c', 'initmain.c', 'main.c', ]