From c24c6167e66e0ab5e4ee8fe32e68eb320e31f69d Mon Sep 17 00:00:00 2001 From: Jim Garlick Date: Tue, 21 Aug 2018 11:39:49 -0700 Subject: [PATCH] test: add libkvs/getroot unit test --- src/common/libkvs/Makefile.am | 5 ++ src/common/libkvs/test/kvs_getroot.c | 82 ++++++++++++++++++++++++++++ 2 files changed, 87 insertions(+) create mode 100644 src/common/libkvs/test/kvs_getroot.c diff --git a/src/common/libkvs/Makefile.am b/src/common/libkvs/Makefile.am index e7acffc1e230..0d6cf078e185 100644 --- a/src/common/libkvs/Makefile.am +++ b/src/common/libkvs/Makefile.am @@ -42,6 +42,7 @@ TESTS = \ test_kvs_dir.t \ test_kvs_commit.t \ test_kvs_watch.t \ + test_kvs_getroot.t \ test_treeobj.t check_PROGRAMS = \ @@ -89,6 +90,10 @@ test_kvs_watch_t_SOURCES = test/kvs_watch.c test_kvs_watch_t_CPPFLAGS = $(test_cppflags) test_kvs_watch_t_LDADD = $(test_ldadd) $(LIBDL) +test_kvs_getroot_t_SOURCES = test/kvs_getroot.c +test_kvs_getroot_t_CPPFLAGS = $(test_cppflags) +test_kvs_getroot_t_LDADD = $(test_ldadd) $(LIBDL) + test_treeobj_t_SOURCES = test/treeobj.c test_treeobj_t_CPPFLAGS = $(test_cppflags) test_treeobj_t_LDADD = $(test_ldadd) $(LIBDL) diff --git a/src/common/libkvs/test/kvs_getroot.c b/src/common/libkvs/test/kvs_getroot.c new file mode 100644 index 000000000000..3b19a2be84ba --- /dev/null +++ b/src/common/libkvs/test/kvs_getroot.c @@ -0,0 +1,82 @@ +#if HAVE_CONFIG_H +#include "config.h" +#endif + +#include +#include +#include + +#include "src/common/libflux/flux.h" +#include "kvs_getroot.h" +#include "src/common/libtap/tap.h" + +void errors (void) +{ + flux_t *h = (flux_t *)(uintptr_t)42; // fake but non-NULL + flux_future_t *f; + const char *s; + int i; + uint32_t u32; + + /* check simple error cases */ + if (!(f = flux_future_create (NULL, NULL))) + BAIL_OUT ("flux_future_create failed"); + + errno = 0; + ok (flux_kvs_getroot (NULL, "foo", 0) == NULL && errno == EINVAL, + "flux_kvs_getroot h=NULL fails with EINVAL"); + errno = 0; + ok (flux_kvs_getroot (h, "foo", 0xff) == NULL && errno == EINVAL, + "flux_kvs_getroot flags=(inval) fails with EINVAL"); + errno = 0; + ok (flux_kvs_getroot_get_blobref (NULL, &s) < 0 && errno == EINVAL, + "flux_kvs_getroot_get_blobref f=NULL fails with EINVAL"); + errno = 0; + ok (flux_kvs_getroot_get_blobref (f, NULL) < 0 && errno == EINVAL, + "flux_kvs_getroot_get_blobref blobref=NULL fails with EINVAL"); + errno = 0; + ok (flux_kvs_getroot_get_sequence (NULL, &i) < 0 && errno == EINVAL, + "flux_kvs_getroot_get_sequence f=NULL fails with EINVAL"); + errno = 0; + ok (flux_kvs_getroot_get_sequence (f, NULL) < 0 && errno == EINVAL, + "flux_kvs_getroot_get_sequence sequence=NULL fails with EINVAL"); + errno = 0; + ok (flux_kvs_getroot_get_owner (NULL, &u32) < 0 && errno == EINVAL, + "flux_kvs_getroot_get_owner f=NULL fails with EINVAL"); + errno = 0; + ok (flux_kvs_getroot_get_owner (f, NULL) < 0 && errno == EINVAL, + "flux_kvs_getroot_get_owner owner=NULL fails with EINVAL"); + errno = 0; + ok (flux_kvs_getroot_get_treeobj (NULL, &s) < 0 && errno == EINVAL, + "flux_kvs_getroot_get_treeobj f=NULL fails with EINVAL"); + errno = 0; + ok (flux_kvs_getroot_get_treeobj (f, NULL) < 0 && errno == EINVAL, + "flux_kvs_getroot_get_treeobj treeobj=NULL fails with EINVAL"); + errno = 0; + ok (flux_kvs_getroot_get_treeobj (f, &s) < 0 && errno == EINVAL, + "flux_kvs_getroot_get_treeobj f=(non-getroot) fails with EINVAL"); + errno = 0; + ok (flux_kvs_getroot_cancel (NULL) < 0 && errno == EINVAL, + "flux_kvs_getroot_cancel f=NULL fails with EINVAL"); + errno = 0; + ok (flux_kvs_getroot_cancel (f) < 0 && errno == EINVAL, + "flux_kvs_getroot_cancel f=(non-getroot) fails with EINVAL"); + + flux_future_destroy (f); +} + +int main (int argc, char *argv[]) +{ + + plan (NO_PLAN); + + errors (); + + done_testing(); + return (0); +} + +/* + * vi:tabstop=4 shiftwidth=4 expandtab + */ +