Simple test of yaz_cond_wait
authorAdam Dickmeiss <adam@indexdata.dk>
Tue, 27 Apr 2010 13:59:21 +0000 (15:59 +0200)
committerAdam Dickmeiss <adam@indexdata.dk>
Tue, 27 Apr 2010 13:59:21 +0000 (15:59 +0200)
test/test_mutex.c

index 843ea8f..9cef383 100644 (file)
@@ -7,10 +7,11 @@
 #include <stdio.h>
 
 #include <yaz/mutex.h>
 #include <stdio.h>
 
 #include <yaz/mutex.h>
+#include <sys/time.h>
 #include <yaz/test.h>
 #include <yaz/log.h>
 
 #include <yaz/test.h>
 #include <yaz/log.h>
 
-static void tst(void)
+static void tst_mutex(void)
 {
     YAZ_MUTEX p = 0;
 
 {
     YAZ_MUTEX p = 0;
 
@@ -32,11 +33,45 @@ static void tst(void)
     yaz_mutex_destroy(&p); /* OK to "destroy" NULL handle */
 }
 
     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();
 int main (int argc, char **argv)
 {
     YAZ_CHECK_INIT(argc, argv);
     YAZ_CHECK_LOG();
-    tst();
+    tst_mutex();
+    tst_cond();
     YAZ_CHECK_TERM;
 }
 
     YAZ_CHECK_TERM;
 }