aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorRyan Stone <rstone@FreeBSD.org>2015-03-01 00:21:37 +0000
committerRyan Stone <rstone@FreeBSD.org>2015-03-01 00:21:37 +0000
commit71637d76b1e417ef02ec5efc0c3501b8c05dbaf2 (patch)
tree32f1d2ca44f5aff7ccbbdf31045c5ad21713c883 /lib
parent6c721f8217d7decb524772a7e1e3f1adcf44396f (diff)
downloadsrc-71637d76b1e417ef02ec5efc0c3501b8c05dbaf2.tar.gz
src-71637d76b1e417ef02ec5efc0c3501b8c05dbaf2.zip
Add test cases for nvlist_move_*
Differential Revision: https://reviews.freebsd.org/D1872 Reviewed by: jfv, pjd MFC after: 1 month Sponsored by: Sandvine Inc.
Notes
Notes: svn path=/head/; revision=279427
Diffstat (limited to 'lib')
-rw-r--r--lib/libnv/tests/nv_tests.cc82
1 files changed, 82 insertions, 0 deletions
diff --git a/lib/libnv/tests/nv_tests.cc b/lib/libnv/tests/nv_tests.cc
index a58c00e803a2..fbf5b3849df2 100644
--- a/lib/libnv/tests/nv_tests.cc
+++ b/lib/libnv/tests/nv_tests.cc
@@ -585,6 +585,83 @@ ATF_TEST_CASE_BODY(nvlist_unpack__duplicate_key)
nvlist_destroy(unpacked);
}
+ATF_TEST_CASE_WITHOUT_HEAD(nvlist_move_string__single_insert);
+ATF_TEST_CASE_BODY(nvlist_move_string__single_insert)
+{
+ nvlist_t *nvl;
+ const char *key;
+ char *value;
+
+ nvl = nvlist_create(0);
+ ATF_REQUIRE(nvl != NULL);
+
+ key = "testkey";
+ value = strdup("testval");
+ ATF_REQUIRE(value != NULL);
+
+ nvlist_move_string(nvl, key, value);
+ ATF_REQUIRE_EQ(nvlist_get_string(nvl, key), value);
+
+ nvlist_destroy(nvl);
+}
+
+ATF_TEST_CASE_WITHOUT_HEAD(nvlist_move_nvlist__null_child);
+ATF_TEST_CASE_BODY(nvlist_move_nvlist__null_child)
+{
+ nvlist_t *parent;
+
+ parent = nvlist_create(0);
+
+ nvlist_move_nvlist(parent, "test", NULL);
+
+ ATF_REQUIRE(nvlist_error(parent) != 0);
+
+ nvlist_destroy(parent);
+}
+
+ATF_TEST_CASE_WITHOUT_HEAD(nvlist_move_nvlist__single_insert);
+ATF_TEST_CASE_BODY(nvlist_move_nvlist__single_insert)
+{
+ nvlist_t *nvl;
+ const char *key;
+ nvlist_t *value;
+
+ nvl = nvlist_create(0);
+ ATF_REQUIRE(nvl != NULL);
+
+ key = "testkey";
+ value = nvlist_create(0);
+ ATF_REQUIRE(value != NULL);
+
+ nvlist_move_nvlist(nvl, key, value);
+ ATF_REQUIRE_EQ(nvlist_get_nvlist(nvl, key), value);
+
+ nvlist_destroy(nvl);
+}
+
+ATF_TEST_CASE_WITHOUT_HEAD(nvlist_move_binary__single_insert);
+ATF_TEST_CASE_BODY(nvlist_move_binary__single_insert)
+{
+ nvlist_t *nvl;
+ const char *key;
+ void *value;
+ size_t size, actual_size;
+
+ nvl = nvlist_create(0);
+ ATF_REQUIRE(nvl != NULL);
+
+ key = "testkey";
+ size = 73;
+ value = malloc(size);
+ ATF_REQUIRE(value != NULL);
+
+ nvlist_move_binary(nvl, key, value, size);
+ ATF_REQUIRE_EQ(nvlist_get_binary(nvl, key, &actual_size), value);
+ ATF_REQUIRE_EQ(size, actual_size);
+
+ nvlist_destroy(nvl);
+}
+
ATF_INIT_TEST_CASES(tp)
{
ATF_ADD_TEST_CASE(tp, nvlist_create__is_empty);
@@ -602,6 +679,11 @@ ATF_INIT_TEST_CASES(tp)
ATF_ADD_TEST_CASE(tp, nvlist_pack__empty_nvlist);
ATF_ADD_TEST_CASE(tp, nvlist_pack__multiple_values);
ATF_ADD_TEST_CASE(tp, nvlist_unpack__duplicate_key);
+
+ ATF_ADD_TEST_CASE(tp, nvlist_move_string__single_insert);
+ ATF_ADD_TEST_CASE(tp, nvlist_move_nvlist__single_insert);
+ ATF_ADD_TEST_CASE(tp, nvlist_move_nvlist__null_child);
+ ATF_ADD_TEST_CASE(tp, nvlist_move_binary__single_insert);
}
/*-
* Copyright (c) 2014-2015 Sandvine Inc. All rights reserved.