Skip to content

Commit

Permalink
libkvs/test: Add extra treeobj corner case tests
Browse files Browse the repository at this point in the history
  • Loading branch information
chu11 committed Aug 22, 2017
1 parent a3cacf1 commit f2b1388
Showing 1 changed file with 40 additions and 2 deletions.
42 changes: 40 additions & 2 deletions src/common/libkvs/test/treeobj.c
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ void test_valref (void)
errno = 0;
ok (treeobj_get_blobref (valref, 0) == NULL && errno == EINVAL,
"treeobj_get_blobref [0] fails with EINVAL");
ok (treeobj_append_blobref (valref, "foo") < 0 && errno == EINVAL,
"treeobj_append_blobref returns EINVAL on bad blobref");
ok (treeobj_append_blobref (valref, blobrefs[0]) == 0,
"treeobj_append_blobref works");
ok (treeobj_validate (valref) == 0,
Expand Down Expand Up @@ -172,6 +174,13 @@ void test_val (void)
ok (memcmp (buf, outbuf, outlen) == 0,
"and returned data same as input");
free (outbuf);
ok (treeobj_decode_val (val, (void **)&outbuf, NULL) == 0,
"treeobj_decode_val works w/o len input");
free (outbuf);
ok (treeobj_decode_val (val, NULL, &outlen) == 0,
"treeobj_decode_val works w/o data pointer input");
ok (outlen == sizeof (buf),
"and returned size same as input");

ok ((val2 = treeobj_create_val (NULL, 0)) != NULL,
"treeobj_create_val NULL, 0 works");
Expand Down Expand Up @@ -239,6 +248,8 @@ void test_dirref (void)
errno = 0;
ok (treeobj_get_blobref (dirref, 0) == NULL && errno == EINVAL,
"treeobj_get_blobref [0] fails with EINVAL");
ok (treeobj_append_blobref (dirref, "foo") < 0 && errno == EINVAL,
"treeobj_append_blobref returns EINVAL on bad blobref");
ok (treeobj_append_blobref (dirref, blobrefs[0]) == 0,
"treeobj_append_blobref works");
ok (treeobj_validate (dirref) == 0,
Expand Down Expand Up @@ -325,6 +336,15 @@ void test_dir (void)
"treeobj_validate likes populated dir");

errno = 0;
ok (treeobj_get_entry (val1, "foo") == NULL && errno == EINVAL,
"treeobj_get_entry fails with EINVAL on non-dir treeobj");
errno = 0;
ok (treeobj_delete_entry (val1, "foo") < 0 && errno == EINVAL,
"treeobj_delete_entry fails with EINVAL on non-dir treeobj");
errno = 0;
ok (treeobj_insert_entry (val1, "foo", val1) < 0 && errno == EINVAL,
"treeobj_insert_entry fails with EINVAL on non-dir treeobj");
errno = 0;
ok (treeobj_insert_entry (dir, NULL, val1) < 0 && errno == EINVAL,
"treeobj_insert_entry fails with EINVAL on NULL key");
errno = 0;
Expand Down Expand Up @@ -449,21 +469,35 @@ void test_symlink (void)
json_decref (o);
}

void test_validate (void)
void test_corner_cases (void)
{
json_t *val, *valref, *dir, *symlink;
json_t *array, *object;
char *outbuf;
int outlen;

val = treeobj_create_val ("a", 1);
if (!val)
BAIL_OUT ("can't continue without test value");

ok (treeobj_append_blobref (val, blobrefs[0]) < 0 && errno == EINVAL,
"treeobj_append_blobref returns EINVAL on bad treeobj");

ok (treeobj_get_blobref (val, 0) == NULL && errno == EINVAL,
"treeobj_get_blobref returns EINVAL on bad treeobj");

/* Modify val to have bad type */
json_object_set_new (val, "type", json_string ("foo"));

ok (treeobj_validate (val) < 0 && errno == EINVAL,
"treeobj_validate detects invalid type");

ok (treeobj_get_count (val) < 0 && errno == EINVAL,
"treeobj_get_count detects invalid type");

ok (treeobj_decode (treeobj_encode (val)) == NULL && errno == EPROTO,
"treeobj_decode returns EPROTO on bad treeobj");

json_decref (val);

valref = treeobj_create_valref (NULL);
Expand Down Expand Up @@ -492,6 +526,10 @@ void test_validate (void)
if (!dir)
BAIL_OUT ("can't continue without test value");

ok (treeobj_decode_val (dir, (void **)&outbuf, &outlen) < 0
&& errno == EINVAL,
"treeobj_decode_val returns EINVAL on non-val treeobj");

/* Modify valref to have bad blobref */
object = json_object ();
json_object_set_new (object, "a", json_string ("foo"));
Expand Down Expand Up @@ -532,7 +570,7 @@ int main(int argc, char** argv)
test_dir ();
test_copy_dir ();
test_symlink ();
test_validate ();
test_corner_cases ();

test_codec ();

Expand Down

0 comments on commit f2b1388

Please sign in to comment.