From e45adb79ab73280e963c849927707089d4031040 Mon Sep 17 00:00:00 2001 From: Adam Dickmeiss Date: Tue, 27 Apr 2010 15:59:21 +0200 Subject: [PATCH] Simple test of yaz_cond_wait --- test/test_mutex.c | 39 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 37 insertions(+), 2 deletions(-) diff --git a/test/test_mutex.c b/test/test_mutex.c index 843ea8f..9cef383 100644 --- a/test/test_mutex.c +++ b/test/test_mutex.c @@ -7,10 +7,11 @@ #include #include +#include #include #include -static void tst(void) +static void tst_mutex(void) { YAZ_MUTEX p = 0; @@ -32,11 +33,45 @@ static void tst(void) yaz_mutex_destroy(&p); /* OK to "destroy" NULL handle */ } +static void tst_cond(void) +{ + YAZ_MUTEX p = 0; + YAZ_COND c; + struct timespec abstime; + struct timeval tval; + int r; + + yaz_mutex_create(&p); + YAZ_CHECK(p); + if (!p) + return; + + yaz_cond_create(&c); + YAZ_CHECK(c); + if (!c) + return; + + r = gettimeofday(&tval, 0); + YAZ_CHECK_EQ(r, 0); + + abstime.tv_sec = tval.tv_sec + 1; /* wait 2 seconds */ + abstime.tv_nsec = tval.tv_usec * 1000; + + r = yaz_cond_wait(c, p, &abstime); + YAZ_CHECK(r != 0); + + yaz_cond_destroy(&c); + YAZ_CHECK(c == 0); + yaz_mutex_destroy(&p); + YAZ_CHECK(p == 0); +} + int main (int argc, char **argv) { YAZ_CHECK_INIT(argc, argv); YAZ_CHECK_LOG(); - tst(); + tst_mutex(); + tst_cond(); YAZ_CHECK_TERM; } -- 1.7.10.4