mirror of
https://github.com/troglobit/libuev.git
synced 2026-10-15 10:19:31 +00:00
Add timer.c unit test
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
This commit is contained in:
1 parent
6a21b7a90b
commit
8f2c9f7f0e
2 files changed
+29
No files matched your search
@@ -2,6 +2,7 @@ EXTRA_DIST = check.h
|
||||
CLEANFILES = *~ *.trs *.log
|
||||
|
||||
TESTS =
|
||||
TESTS += timer
|
||||
|
||||
check_PROGRAMS = $(TESTS)
|
||||
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
#include "check.h"
|
||||
#include <time.h>
|
||||
#include <sys/time.h>
|
||||
|
||||
#define TIMEOUT 2 /* 2 sec */
|
||||
struct timeval start;
|
||||
|
||||
static void cb(uev_t *w, void *UNUSED(arg), int UNUSED(events))
|
||||
{
|
||||
struct timeval now;
|
||||
|
||||
gettimeofday(&now, NULL);
|
||||
fail_unless(now.tv_sec == start.tv_sec + TIMEOUT);
|
||||
|
||||
uev_exit(w->ctx);
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
uev_t w;
|
||||
uev_ctx_t ctx;
|
||||
|
||||
uev_init(&ctx);
|
||||
uev_timer_init(&ctx, &w, cb, NULL, TIMEOUT * 1000, 0);
|
||||
gettimeofday(&start, NULL);
|
||||
|
||||
return uev_run(&ctx, 0);
|
||||
}
|
||||
Reference in new issue
Block a user