diff --git a/tests/.gitignore b/tests/.gitignore index e4a8fd8..bc51654 100644 --- a/tests/.gitignore +++ b/tests/.gitignore @@ -1,5 +1,6 @@ *.trs *.log +active complete cronrun signal diff --git a/tests/Makefile.am b/tests/Makefile.am index a3c2f78..ec1c6da 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -2,6 +2,7 @@ EXTRA_DIST = check.h CLEANFILES = *~ *.trs *.log TESTS = +TESTS += active TESTS += complete TESTS += cronrun TESTS += signal diff --git a/tests/active.c b/tests/active.c new file mode 100644 index 0000000..78da403 --- /dev/null +++ b/tests/active.c @@ -0,0 +1,47 @@ +#include "check.h" +#include +#include + +#define TIMEOUT1 2 /* 2 sec */ +#define TIMEOUT2 4 /* 4 sec */ +#define DAYLY (24 * 60 * 60) /* Seconds in one day */ + +uev_t timer1; +uev_t timer2; +uev_t cron1; +uev_t cron2; + +static void cb(uev_t *w, void *UNUSED(arg), int UNUSED(events)) +{ + fail_unless(w == &timer1); + + fail_unless(uev_timer_active(&timer2)); + fail_unless(uev_cron_active(&cron1)); + fail_unless(uev_cron_active(&cron2)); + + uev_timer_stop(&timer2); + uev_timer_stop(&cron2); + + fail_unless(!uev_timer_active(&timer2)); + fail_unless(!uev_cron_active(&cron2)); + + uev_exit(w->ctx); +} + +int main(void) +{ + uev_ctx_t ctx; + struct timeval tomorrow; + + gettimeofday(&tomorrow, NULL); + tomorrow.tv_sec += 24 * 60 * 60; + + uev_init(&ctx); + uev_timer_init(&ctx, &timer1, cb, NULL, TIMEOUT1 * 1000, 0); + uev_timer_init(&ctx, &timer2, cb, NULL, TIMEOUT2 * 1000, 0); + + uev_cron_init(&ctx, &cron1, cb, NULL, tomorrow.tv_sec, 24 * 60 * 60); + uev_cron_init(&ctx, &cron2, cb, NULL, tomorrow.tv_sec, 24 * 60 * 60); + + return uev_run(&ctx, 0); +}