2 * Copyright (c) 2013 The FreeBSD Foundation
5 * This software was developed by Pawel Jakub Dawidek under sponsorship from
6 * the FreeBSD Foundation.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
42 #define CHECK(expr) do { \
44 printf("ok # %d %s:%u\n", ntest, __FILE__, __LINE__); \
46 printf("not ok # %d %s:%u\n", ntest, __FILE__, __LINE__);\
61 nvl = nvlist_create(0);
63 CHECK(!nvlist_exists_string(nvl, "nvlist/string/"));
66 nvlist_move_string(nvl, "nvlist/string/", ptr);
67 CHECK(nvlist_error(nvl) == 0);
68 CHECK(nvlist_exists_string(nvl, "nvlist/string/"));
69 CHECK(ptr == nvlist_get_string(nvl, "nvlist/string/"));
71 CHECK(!nvlist_exists_string(nvl, "nvlist/string/x"));
74 nvlist_move_string(nvl, "nvlist/string/x", ptr);
75 CHECK(nvlist_error(nvl) == 0);
76 CHECK(nvlist_exists_string(nvl, "nvlist/string/x"));
77 CHECK(ptr == nvlist_get_string(nvl, "nvlist/string/x"));
79 CHECK(!nvlist_exists_string(nvl,
80 "nvlist/string/abcdefghijklmnopqrstuvwxyz"));
81 ptr = strdup("abcdefghijklmnopqrstuvwxyz");
83 nvlist_move_string(nvl, "nvlist/string/abcdefghijklmnopqrstuvwxyz",
85 CHECK(nvlist_error(nvl) == 0);
86 CHECK(nvlist_exists_string(nvl,
87 "nvlist/string/abcdefghijklmnopqrstuvwxyz"));
89 nvlist_get_string(nvl, "nvlist/string/abcdefghijklmnopqrstuvwxyz"));
91 CHECK(!nvlist_exists_descriptor(nvl,
92 "nvlist/descriptor/STDERR_FILENO"));
93 fd = dup(STDERR_FILENO);
95 nvlist_move_descriptor(nvl, "nvlist/descriptor/STDERR_FILENO", fd);
96 CHECK(nvlist_error(nvl) == 0);
97 CHECK(nvlist_exists_descriptor(nvl, "nvlist/descriptor/STDERR_FILENO"));
99 nvlist_get_descriptor(nvl, "nvlist/descriptor/STDERR_FILENO"));
101 CHECK(!nvlist_exists_binary(nvl, "nvlist/binary/x"));
105 nvlist_move_binary(nvl, "nvlist/binary/x", ptr, 1);
106 CHECK(nvlist_error(nvl) == 0);
107 CHECK(nvlist_exists_binary(nvl, "nvlist/binary/x"));
108 CHECK(ptr == nvlist_get_binary(nvl, "nvlist/binary/x", NULL));
109 CHECK(ptr == nvlist_get_binary(nvl, "nvlist/binary/x", &size));
112 CHECK(!nvlist_exists_binary(nvl,
113 "nvlist/binary/abcdefghijklmnopqrstuvwxyz"));
114 ptr = malloc(sizeof("abcdefghijklmnopqrstuvwxyz"));
116 memcpy(ptr, "abcdefghijklmnopqrstuvwxyz",
117 sizeof("abcdefghijklmnopqrstuvwxyz"));
118 nvlist_move_binary(nvl, "nvlist/binary/abcdefghijklmnopqrstuvwxyz",
119 ptr, sizeof("abcdefghijklmnopqrstuvwxyz"));
120 CHECK(nvlist_error(nvl) == 0);
121 CHECK(nvlist_exists_binary(nvl,
122 "nvlist/binary/abcdefghijklmnopqrstuvwxyz"));
123 CHECK(ptr == nvlist_get_binary(nvl,
124 "nvlist/binary/abcdefghijklmnopqrstuvwxyz", NULL));
125 CHECK(ptr == nvlist_get_binary(nvl,
126 "nvlist/binary/abcdefghijklmnopqrstuvwxyz", &size));
127 CHECK(size == sizeof("abcdefghijklmnopqrstuvwxyz"));
129 CHECK(!nvlist_exists_nvlist(nvl, "nvlist/nvlist"));
130 ptr = nvlist_clone(nvl);
132 nvlist_move_nvlist(nvl, "nvlist/nvlist", ptr);
133 CHECK(nvlist_error(nvl) == 0);
134 CHECK(nvlist_exists_nvlist(nvl, "nvlist/nvlist"));
135 CHECK(ptr == nvlist_get_nvlist(nvl, "nvlist/nvlist"));
137 CHECK(nvlist_exists_string(nvl, "nvlist/string/"));
138 CHECK(nvlist_exists_string(nvl, "nvlist/string/x"));
139 CHECK(nvlist_exists_string(nvl,
140 "nvlist/string/abcdefghijklmnopqrstuvwxyz"));
141 CHECK(nvlist_exists_descriptor(nvl, "nvlist/descriptor/STDERR_FILENO"));
142 CHECK(nvlist_exists_binary(nvl, "nvlist/binary/x"));
143 CHECK(nvlist_exists_binary(nvl,
144 "nvlist/binary/abcdefghijklmnopqrstuvwxyz"));
145 CHECK(nvlist_exists_nvlist(nvl, "nvlist/nvlist"));
147 cnvl = nvlist_get_nvlist(nvl, "nvlist/nvlist");
148 CHECK(nvlist_exists_string(cnvl, "nvlist/string/"));
149 CHECK(nvlist_exists_string(cnvl, "nvlist/string/x"));
150 CHECK(nvlist_exists_string(cnvl,
151 "nvlist/string/abcdefghijklmnopqrstuvwxyz"));
152 CHECK(nvlist_exists_descriptor(cnvl,
153 "nvlist/descriptor/STDERR_FILENO"));
154 CHECK(nvlist_exists_binary(cnvl, "nvlist/binary/x"));
155 CHECK(nvlist_exists_binary(cnvl,
156 "nvlist/binary/abcdefghijklmnopqrstuvwxyz"));