Code

Merged branch 'master' of git://git.tokkee.org/sysdb.
[sysdb.git] / t / utils / channel_test.c
index 30fc263a263a33b6edfc655bfcb8682174d98e7c..3827c0705f7f78efa3cc77da6fc2bb526f1b6e32 100644 (file)
@@ -29,6 +29,7 @@
 #include "libsysdb_test.h"
 
 #include <check.h>
+#include <errno.h>
 #include <limits.h>
 
 #include <stdint.h>
@@ -137,6 +138,8 @@ START_TEST(test_write_read)
 
        data = 0xffffffff;
        check = sdb_channel_read(chan, &data);
+       fail_unless(check == 0,
+                       "sdb_channel_read() = %d; expected: 0", check);
        /* result depends on endianess */
        fail_unless((data == 0xffffff00) || (data == 0x00ffffff),
                        "sdb_channel_read() returned data %x; "
@@ -146,6 +149,31 @@ START_TEST(test_write_read)
 }
 END_TEST
 
+START_TEST(test_select)
+{
+       struct timespec ts = { 0, 10 };
+       int check;
+       int data;
+
+       chan = sdb_channel_create(0, 1);
+
+       errno = 0;
+       check = sdb_channel_select(chan, &data, NULL, NULL, NULL, &ts);
+       fail_unless(check < ETIMEDOUT,
+                       "sdb_channel_select() = %i; expected: <0", check);
+       fail_unless(errno == ETIMEDOUT,
+                       "sdb_channel_select() set errno to %i; expected: %i (ETIMEDOUT)",
+                       errno, ETIMEDOUT);
+
+       check = sdb_channel_select(chan, NULL, NULL, &data, NULL, NULL);
+       fail_unless(! check, "sdb_channel_select() = %i; expected: 0", check);
+       check = sdb_channel_select(chan, NULL, NULL, &data, NULL, &ts);
+       fail_unless(! check, "sdb_channel_select() = %i; expected: 0", check);
+
+       sdb_channel_destroy(chan);
+}
+END_TEST
+
 START_TEST(test_write_int)
 {
        size_t i;
@@ -320,6 +348,7 @@ util_channel_suite(void)
        tc = tcase_create("core");
        tcase_add_test(tc, test_create);
        tcase_add_test(tc, test_write_read);
+       tcase_add_test(tc, test_select);
        suite_add_tcase(s, tc);
 
        tc = tcase_create("integer");