nv_tests.cc revision 279440
1/*-
2 * Copyright (c) 2014-2015 Sandvine Inc.  All rights reserved.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 *    notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 *    notice, this list of conditions and the following disclaimer in the
12 *    documentation and/or other materials provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 */
26
27#include <sys/cdefs.h>
28__FBSDID("$FreeBSD: head/lib/libnv/tests/nv_tests.cc 279440 2015-03-01 00:37:23Z rstone $");
29
30#include <atf-c++.hpp>
31#include <nv.h>
32
33#include <errno.h>
34#include <limits>
35#include <set>
36#include <sstream>
37#include <string>
38
39/*
40 * Test that a newly created nvlist has no errors, and is empty.
41 */
42ATF_TEST_CASE_WITHOUT_HEAD(nvlist_create__is_empty);
43ATF_TEST_CASE_BODY(nvlist_create__is_empty)
44{
45	nvlist_t *nvl;
46	int type;
47	void *it;
48
49	nvl = nvlist_create(0);
50
51	ATF_REQUIRE(nvl != NULL);
52
53	ATF_REQUIRE_EQ(nvlist_error(nvl), 0);
54	ATF_REQUIRE(nvlist_empty(nvl));
55
56	it = NULL;
57	ATF_REQUIRE_EQ(nvlist_next(nvl, &type, &it), NULL);
58
59	nvlist_destroy(nvl);
60}
61
62ATF_TEST_CASE_WITHOUT_HEAD(nvlist_add_null__single_insert);
63ATF_TEST_CASE_BODY(nvlist_add_null__single_insert)
64{
65	nvlist_t *nvl;
66	void *it;
67	const char *key;
68	int type;
69
70	key = "key";
71	nvl = nvlist_create(0);
72
73	ATF_REQUIRE(nvl != NULL);
74	ATF_REQUIRE(!nvlist_exists(nvl, key));
75
76	nvlist_add_null(nvl, key);
77
78	ATF_REQUIRE(!nvlist_empty(nvl));
79	ATF_REQUIRE(nvlist_exists(nvl, key));
80	ATF_REQUIRE(nvlist_existsf(nvl, "%s", key));
81	ATF_REQUIRE(nvlist_exists_null(nvl, key));
82	ATF_REQUIRE(nvlist_existsf_null(nvl, "key"));
83
84	/* Iterate over the nvlist; ensure that it has only our one key. */
85	it = NULL;
86	ATF_REQUIRE_EQ(strcmp(nvlist_next(nvl, &type, &it), key), 0);
87	ATF_REQUIRE_EQ(type, NV_TYPE_NULL);
88	ATF_REQUIRE_EQ(nvlist_next(nvl, &type,&it), NULL);
89
90	nvlist_destroy(nvl);
91}
92
93ATF_TEST_CASE_WITHOUT_HEAD(nvlist_add_bool__single_insert);
94ATF_TEST_CASE_BODY(nvlist_add_bool__single_insert)
95{
96	nvlist_t *nvl;
97	void *it;
98	const char *key;
99	int type;
100
101	key = "name";
102	nvl = nvlist_create(0);
103
104	ATF_REQUIRE(nvl != NULL);
105	ATF_REQUIRE(!nvlist_exists(nvl, key));
106
107	nvlist_add_bool(nvl, key, true);
108
109	ATF_REQUIRE(!nvlist_empty(nvl));
110	ATF_REQUIRE(nvlist_exists(nvl, key));
111	ATF_REQUIRE(nvlist_existsf(nvl, "%s%s", "na", "me"));
112	ATF_REQUIRE(nvlist_exists_bool(nvl, key));
113	ATF_REQUIRE(nvlist_existsf_bool(nvl, "%s%c", "nam", 'e'));
114	ATF_REQUIRE_EQ(nvlist_get_bool(nvl, key), true);
115	ATF_REQUIRE_EQ(nvlist_getf_bool(nvl, "%c%s", 'n', "ame"), true);
116
117	/* Iterate over the nvlist; ensure that it has only our one key. */
118	it = NULL;
119	ATF_REQUIRE_EQ(strcmp(nvlist_next(nvl, &type, &it), key), 0);
120	ATF_REQUIRE_EQ(type, NV_TYPE_BOOL);
121	ATF_REQUIRE_EQ(nvlist_next(nvl, &type,&it), NULL);
122
123	nvlist_destroy(nvl);
124}
125
126ATF_TEST_CASE_WITHOUT_HEAD(nvlist_add_number__single_insert);
127ATF_TEST_CASE_BODY(nvlist_add_number__single_insert)
128{
129	nvlist_t *nvl;
130	void *it;
131	const char *key;
132	uint64_t value;
133	int type;
134
135	key = "foo123";
136	value = 71965;
137	nvl = nvlist_create(0);
138
139	ATF_REQUIRE(nvl != NULL);
140	ATF_REQUIRE(!nvlist_exists(nvl, key));
141
142	nvlist_add_number(nvl, key, value);
143
144	ATF_REQUIRE(!nvlist_empty(nvl));
145	ATF_REQUIRE(nvlist_exists(nvl, key));
146	ATF_REQUIRE(nvlist_existsf(nvl, "%s%d", "foo", 123));
147	ATF_REQUIRE(nvlist_exists_number(nvl, key));
148	ATF_REQUIRE(nvlist_existsf_number(nvl, "%s", key));
149	ATF_REQUIRE_EQ(nvlist_get_number(nvl, key), value);
150	ATF_REQUIRE_EQ(nvlist_getf_number(nvl, "%s", key), value);
151
152	/* Iterate over the nvlist; ensure that it has only our one key. */
153	it = NULL;
154	ATF_REQUIRE_EQ(strcmp(nvlist_next(nvl, &type, &it), key), 0);
155	ATF_REQUIRE_EQ(type, NV_TYPE_NUMBER);
156	ATF_REQUIRE_EQ(nvlist_next(nvl, &type,&it), NULL);
157
158	nvlist_destroy(nvl);
159}
160
161ATF_TEST_CASE_WITHOUT_HEAD(nvlist_add_string__single_insert);
162ATF_TEST_CASE_BODY(nvlist_add_string__single_insert)
163{
164	nvlist_t *nvl;
165	void *it;
166	const char *key;
167	const char *value;
168	int type;
169
170	key = "test";
171	value = "fgjdkgjdk";
172	nvl = nvlist_create(0);
173
174	ATF_REQUIRE(nvl != NULL);
175	ATF_REQUIRE(!nvlist_exists(nvl, key));
176
177	nvlist_add_string(nvl, key, value);
178
179	ATF_REQUIRE(!nvlist_empty(nvl));
180	ATF_REQUIRE(nvlist_exists(nvl, key));
181	ATF_REQUIRE(nvlist_existsf(nvl, "%s", key));
182	ATF_REQUIRE(nvlist_exists_string(nvl, key));
183	ATF_REQUIRE(nvlist_existsf_string(nvl, "%s", key));
184	ATF_REQUIRE_EQ(strcmp(nvlist_get_string(nvl, key), value), 0);
185	ATF_REQUIRE_EQ(strcmp(nvlist_getf_string(nvl, "%s", key), value), 0);
186
187	/* nvlist_add_* is required to clone the value, so check for that. */
188	ATF_REQUIRE(nvlist_get_string(nvl, key) != value);
189
190	/* Iterate over the nvlist; ensure that it has only our one key. */
191	it = NULL;
192	ATF_REQUIRE_EQ(strcmp(nvlist_next(nvl, &type, &it), key), 0);
193	ATF_REQUIRE_EQ(type, NV_TYPE_STRING);
194	ATF_REQUIRE_EQ(nvlist_next(nvl, &type,&it), NULL);
195
196	nvlist_destroy(nvl);
197}
198
199ATF_TEST_CASE_WITHOUT_HEAD(nvlist_add_nvlist__single_insert);
200ATF_TEST_CASE_BODY(nvlist_add_nvlist__single_insert)
201{
202	nvlist_t *nvl;
203	void *it;
204	const char *key, *subkey;
205	nvlist_t *sublist;
206	const nvlist_t *value;
207	int type;
208
209	key = "test";
210	subkey = "subkey";
211	sublist = nvlist_create(0);
212	nvl = nvlist_create(0);
213
214	ATF_REQUIRE(nvl != NULL);
215	ATF_REQUIRE(!nvlist_exists(nvl, key));
216
217	nvlist_add_null(sublist, subkey);
218	nvlist_add_nvlist(nvl, key, sublist);
219
220	ATF_REQUIRE(!nvlist_empty(nvl));
221	ATF_REQUIRE(nvlist_exists(nvl, key));
222	ATF_REQUIRE(nvlist_existsf(nvl, "%s", key));
223	ATF_REQUIRE(nvlist_exists_nvlist(nvl, key));
224	ATF_REQUIRE(nvlist_existsf_nvlist(nvl, "%s", key));
225
226	value = nvlist_get_nvlist(nvl, key);
227	ATF_REQUIRE(nvlist_exists_null(value, subkey));
228
229	/* nvlist_add_* is required to clone the value, so check for that. */
230	ATF_REQUIRE(sublist != value);
231
232	value = nvlist_getf_nvlist(nvl, "%s", key);
233	ATF_REQUIRE(nvlist_exists_null(value, subkey));
234	ATF_REQUIRE(sublist != value);
235
236	/* Iterate over the nvlist; ensure that it has only our one key. */
237	it = NULL;
238	ATF_REQUIRE_EQ(strcmp(nvlist_next(nvl, &type, &it), key), 0);
239	ATF_REQUIRE_EQ(type, NV_TYPE_NVLIST);
240	ATF_REQUIRE_EQ(nvlist_next(nvl, &type,&it), NULL);
241
242	nvlist_destroy(sublist);
243	nvlist_destroy(nvl);
244}
245
246ATF_TEST_CASE_WITHOUT_HEAD(nvlist_add_nvlist__child_with_error);
247ATF_TEST_CASE_BODY(nvlist_add_nvlist__child_with_error)
248{
249	nvlist_t *nvl, *parent;
250
251	nvl = nvlist_create(0);
252	parent = nvlist_create(0);
253
254	nvlist_set_error(nvl, EBADF);
255	nvlist_add_nvlist(parent, "test", nvl);
256	ATF_REQUIRE_EQ(nvlist_error(parent), EBADF);
257
258	nvlist_destroy(nvl);
259	nvlist_destroy(parent);
260}
261
262ATF_TEST_CASE_WITHOUT_HEAD(nvlist_add_binary__single_insert);
263ATF_TEST_CASE_BODY(nvlist_add_binary__single_insert)
264{
265	nvlist_t *nvl;
266	void *it;
267	const char *key;
268	void *value;
269	const void *ret_value;
270	size_t value_size, ret_size;
271	int type;
272
273	key = "binary";
274	value_size = 13;
275	value = malloc(value_size);
276	memset(value, 0xa5, value_size);
277	nvl = nvlist_create(0);
278
279	ATF_REQUIRE(nvl != NULL);
280	ATF_REQUIRE(!nvlist_exists(nvl, key));
281
282	nvlist_add_binary(nvl, key, value, value_size);
283
284	ATF_REQUIRE(!nvlist_empty(nvl));
285	ATF_REQUIRE(nvlist_exists(nvl, key));
286	ATF_REQUIRE(nvlist_existsf(nvl, "%s", key));
287	ATF_REQUIRE(nvlist_exists_binary(nvl, key));
288	ATF_REQUIRE(nvlist_existsf_binary(nvl, "%s", key));
289
290	ret_value = nvlist_get_binary(nvl, key, &ret_size);
291	ATF_REQUIRE_EQ(value_size, ret_size);
292	ATF_REQUIRE_EQ(memcmp(value, ret_value, ret_size), 0);
293
294	/* nvlist_add_* is required to clone the value, so check for that. */
295	ATF_REQUIRE(value != ret_value);
296
297	ret_value = nvlist_getf_binary(nvl, &ret_size, "%s", key);
298	ATF_REQUIRE_EQ(value_size, ret_size);
299	ATF_REQUIRE_EQ(memcmp(value, ret_value, ret_size), 0);
300	ATF_REQUIRE(value != ret_value);
301
302	/* Iterate over the nvlist; ensure that it has only our one key. */
303	it = NULL;
304	ATF_REQUIRE_EQ(strcmp(nvlist_next(nvl, &type, &it), key), 0);
305	ATF_REQUIRE_EQ(type, NV_TYPE_BINARY);
306	ATF_REQUIRE_EQ(nvlist_next(nvl, &type,&it), NULL);
307
308	nvlist_destroy(nvl);
309	free(value);
310}
311
312ATF_TEST_CASE_WITHOUT_HEAD(nvlist_clone__empty_nvlist);
313ATF_TEST_CASE_BODY(nvlist_clone__empty_nvlist)
314{
315	nvlist_t *nvl, *clone;
316
317	nvl = nvlist_create(0);
318	ATF_REQUIRE(nvl != NULL);
319
320	clone = nvlist_clone(nvl);
321	ATF_REQUIRE(clone != NULL);
322	ATF_REQUIRE(clone != nvl);
323	ATF_REQUIRE(nvlist_empty(clone));
324
325	nvlist_destroy(clone);
326	nvlist_destroy(nvl);
327}
328
329ATF_TEST_CASE_WITHOUT_HEAD(nvlist_clone__nonempty_nvlist);
330ATF_TEST_CASE_BODY(nvlist_clone__nonempty_nvlist)
331{
332	nvlist_t *nvl, *clone;
333	const char *key;
334	void *it;
335	uint64_t value;
336	int type;
337
338	nvl = nvlist_create(0);
339	ATF_REQUIRE(nvl != NULL);
340
341	key = "testkey";
342	value = 684874;
343	nvlist_add_number(nvl, key, value);
344
345	clone = nvlist_clone(nvl);
346	ATF_REQUIRE(clone != NULL);
347	ATF_REQUIRE(clone != nvl);
348	ATF_REQUIRE(nvlist_exists_number(clone, key));
349	ATF_REQUIRE_EQ(nvlist_get_number(clone, key), value);
350
351	/* Iterate over the nvlist; ensure that it has only our one key. */
352	it = NULL;
353	ATF_REQUIRE_EQ(strcmp(nvlist_next(clone, &type, &it), key), 0);
354	ATF_REQUIRE_EQ(type, NV_TYPE_NUMBER);
355	ATF_REQUIRE_EQ(nvlist_next(clone, &type, &it), NULL);
356
357	nvlist_destroy(clone);
358	nvlist_destroy(nvl);
359}
360
361static const char * const test_subnvlist_key = "nvlist";
362
363static const char * const test_string_key = "string";
364static const char * const test_string_val = "59525";
365
366static nvlist_t*
367create_test_nvlist(void)
368{
369	nvlist_t *nvl, *sublist;
370
371	nvl = nvlist_create(0);
372	ATF_REQUIRE(nvl != NULL);
373
374	sublist = nvlist_create(0);
375	ATF_REQUIRE(sublist != NULL);
376
377	nvlist_add_string(sublist, test_string_key, test_string_val);
378	nvlist_move_nvlist(nvl, test_subnvlist_key, sublist);
379
380	return (nvl);
381}
382
383static void
384verify_test_nvlist(const nvlist_t *nvl)
385{
386	void *it;
387	const nvlist_t *value;
388	int type;
389
390	ATF_REQUIRE(nvlist_exists_nvlist(nvl, test_subnvlist_key));
391
392	value = nvlist_get_nvlist(nvl, test_subnvlist_key);
393
394	ATF_REQUIRE(nvlist_exists_string(value, test_string_key));
395	ATF_REQUIRE_EQ(strcmp(nvlist_get_string(value, test_string_key), test_string_val), 0);
396	ATF_REQUIRE(nvlist_get_string(value, test_string_key) != test_string_val);
397
398	/* Iterate over both nvlists; ensure that each has only the one key. */
399	it = NULL;
400	ATF_REQUIRE_EQ(strcmp(nvlist_next(value, &type, &it),
401	    test_string_key), 0);
402	ATF_REQUIRE_EQ(type, NV_TYPE_STRING);
403	ATF_REQUIRE_EQ(nvlist_next(value, &type, &it), NULL);
404
405	it = NULL;
406	ATF_REQUIRE_EQ(strcmp(nvlist_next(nvl, &type, &it),
407	    test_subnvlist_key), 0);
408	ATF_REQUIRE_EQ(type, NV_TYPE_NVLIST);
409	ATF_REQUIRE_EQ(nvlist_next(nvl, &type, &it), NULL);
410}
411
412ATF_TEST_CASE_WITHOUT_HEAD(nvlist_clone__nested_nvlist);
413ATF_TEST_CASE_BODY(nvlist_clone__nested_nvlist)
414{
415	nvlist_t *nvl, *clone;
416
417	nvl = create_test_nvlist();
418	clone = nvlist_clone(nvl);
419
420	ATF_REQUIRE(clone != NULL);
421	ATF_REQUIRE(clone != nvl);
422	verify_test_nvlist(clone);
423
424	nvlist_destroy(clone);
425	nvlist_destroy(nvl);
426}
427
428ATF_TEST_CASE_WITHOUT_HEAD(nvlist_clone__error_nvlist);
429ATF_TEST_CASE_BODY(nvlist_clone__error_nvlist)
430{
431	nvlist_t *nvl, *clone;
432
433	nvl = nvlist_create(0);
434	ATF_REQUIRE(nvl != NULL);
435
436	nvlist_set_error(nvl, ENOMEM);
437
438	clone = nvlist_clone(nvl);
439	ATF_REQUIRE(clone == NULL);
440
441	nvlist_destroy(nvl);
442}
443
444ATF_TEST_CASE_WITHOUT_HEAD(nvlist_pack__empty_nvlist);
445ATF_TEST_CASE_BODY(nvlist_pack__empty_nvlist)
446{
447	nvlist_t *nvl, *unpacked;
448	void *packed;
449	size_t packed_size;
450
451	nvl = nvlist_create(0);
452	ATF_REQUIRE(nvl != NULL);
453
454	packed = nvlist_pack(nvl, &packed_size);
455	ATF_REQUIRE(packed != NULL);
456
457	unpacked = nvlist_unpack(packed, packed_size);
458	ATF_REQUIRE(unpacked != NULL);
459	ATF_REQUIRE(unpacked != nvl);
460	ATF_REQUIRE(nvlist_empty(unpacked));
461
462	nvlist_destroy(unpacked);
463	nvlist_destroy(nvl);
464	free(packed);
465}
466
467static void
468verify_null(const nvlist_t *nvl, int type)
469{
470
471	ATF_REQUIRE_EQ(type, NV_TYPE_NULL);
472}
473
474static void
475verify_number(const nvlist_t *nvl, const char *name, int type, uint64_t value)
476{
477
478	ATF_REQUIRE_EQ(type, NV_TYPE_NUMBER);
479	ATF_REQUIRE_EQ(nvlist_get_number(nvl, name), value);
480}
481
482static void
483verify_string(const nvlist_t *nvl, const char *name, int type,
484    const char * value)
485{
486
487	ATF_REQUIRE_EQ(type, NV_TYPE_STRING);
488	ATF_REQUIRE_EQ(strcmp(nvlist_get_string(nvl, name), value), 0);
489}
490
491static void
492verify_nvlist(const nvlist_t *nvl, const char *name, int type)
493{
494
495	ATF_REQUIRE_EQ(type, NV_TYPE_NVLIST);
496	verify_test_nvlist(nvlist_get_nvlist(nvl, name));
497}
498
499static void
500verify_binary(const nvlist_t *nvl, const char *name, int type,
501    const void * value, size_t size)
502{
503	const void *actual_value;
504	size_t actual_size;
505
506	ATF_REQUIRE_EQ(type, NV_TYPE_BINARY);
507	actual_value = nvlist_get_binary(nvl, name, &actual_size);
508	ATF_REQUIRE_EQ(size, actual_size);
509	ATF_REQUIRE_EQ(memcmp(value, actual_value, size), 0);
510}
511
512ATF_TEST_CASE_WITHOUT_HEAD(nvlist_pack__multiple_values);
513ATF_TEST_CASE_BODY(nvlist_pack__multiple_values)
514{
515	std::ostringstream msg;
516	std::set<std::string> keys_seen;
517	nvlist_t *nvl, *unpacked, *nvvalue;
518	const char *nullkey, *numkey, *strkey, *nvkey, *binkey, *name;
519	int numvalue;
520	const char * strvalue;
521	void *binvalue, *packed, *it;
522	size_t binsize, packed_size;
523	int type;
524
525	nvl = nvlist_create(0);
526
527	nullkey = "null";
528	nvlist_add_null(nvl, nullkey);
529
530	numkey = "number";
531	numvalue = 939853984;
532	nvlist_add_number(nvl, numkey, numvalue);
533
534	strkey = "string";
535	strvalue = "jfieutijf";
536	nvlist_add_string(nvl, strkey, strvalue);
537
538	nvkey = "nvlist";
539	nvvalue = create_test_nvlist();
540	nvlist_move_nvlist(nvl, nvkey, nvvalue);
541
542	binkey = "binary";
543	binsize = 4;
544	binvalue = malloc(binsize);
545	memset(binvalue, 'b', binsize);
546	nvlist_move_binary(nvl, binkey, binvalue, binsize);
547
548	packed = nvlist_pack(nvl, &packed_size);
549	ATF_REQUIRE(packed != NULL);
550
551	unpacked = nvlist_unpack(packed, packed_size);
552	ATF_REQUIRE(unpacked != 0);
553
554	it = NULL;
555	while ((name = nvlist_next(unpacked, &type, &it)) != NULL) {
556		/* Ensure that we see every key only once. */
557		ATF_REQUIRE_EQ(keys_seen.count(name), 0);
558
559		if (strcmp(name, nullkey) == 0)
560			verify_null(unpacked, type);
561		else if (strcmp(name, numkey) == 0)
562			verify_number(unpacked, name, type, numvalue);
563		else if (strcmp(name, strkey) == 0)
564			verify_string(unpacked, name, type, strvalue);
565		else if (strcmp(name, nvkey) == 0)
566			verify_nvlist(unpacked, name, type);
567		else if (strcmp(name, binkey) == 0)
568			verify_binary(unpacked, name, type, binvalue, binsize);
569		else {
570			msg << "Unexpected key :'" << name << "'";
571			ATF_FAIL(msg.str().c_str());
572		}
573
574		keys_seen.insert(name);
575	}
576
577	/* Ensure that we saw every key. */
578	ATF_REQUIRE_EQ(keys_seen.size(), 5);
579
580	nvlist_destroy(nvl);
581	nvlist_destroy(unpacked);
582	free(packed);
583}
584
585ATF_TEST_CASE_WITHOUT_HEAD(nvlist_pack__error_nvlist);
586ATF_TEST_CASE_BODY(nvlist_pack__error_nvlist)
587{
588	nvlist_t *nvl;
589	void *packed;
590	size_t size;
591
592	nvl = nvlist_create(0);
593	ATF_REQUIRE(nvl != NULL);
594
595	nvlist_set_error(nvl, ENOMEM);
596
597	packed = nvlist_pack(nvl, &size);
598	ATF_REQUIRE(packed == NULL);
599
600	nvlist_destroy(nvl);
601}
602
603ATF_TEST_CASE_WITHOUT_HEAD(nvlist_unpack__duplicate_key);
604ATF_TEST_CASE_BODY(nvlist_unpack__duplicate_key)
605{
606	nvlist_t *nvl, *unpacked;
607	const char *key1, *key2;
608	void *packed, *keypos;
609	size_t size, keylen;
610
611	nvl = nvlist_create(0);
612
613	key1 = "key1";
614	keylen = strlen(key1);
615	nvlist_add_number(nvl, key1, 5);
616
617	key2 = "key2";
618	ATF_REQUIRE_EQ(keylen, strlen(key2));
619	nvlist_add_number(nvl, key2, 10);
620
621	packed = nvlist_pack(nvl, &size);
622
623	/*
624	 * Mangle the packed nvlist by replacing key1 with key2, creating a
625	 * packed nvlist with a duplicate key.
626	 */
627	keypos = memmem(packed, size, key1, keylen);
628	ATF_REQUIRE(keypos != NULL);
629	memcpy(keypos, key2, keylen);
630
631	unpacked = nvlist_unpack(packed, size);
632	ATF_REQUIRE(nvlist_error(unpacked) != 0);
633
634	free(packed);
635	nvlist_destroy(nvl);
636	nvlist_destroy(unpacked);
637}
638
639ATF_TEST_CASE_WITHOUT_HEAD(nvlist_move_string__single_insert);
640ATF_TEST_CASE_BODY(nvlist_move_string__single_insert)
641{
642	nvlist_t *nvl;
643	const char *key;
644	char *value;
645
646	nvl = nvlist_create(0);
647	ATF_REQUIRE(nvl != NULL);
648
649	key = "testkey";
650	value = strdup("testval");
651	ATF_REQUIRE(value != NULL);
652
653	nvlist_move_string(nvl, key, value);
654	ATF_REQUIRE_EQ(nvlist_get_string(nvl, key), value);
655
656	nvlist_destroy(nvl);
657}
658
659ATF_TEST_CASE_WITHOUT_HEAD(nvlist_move_nvlist__null_child);
660ATF_TEST_CASE_BODY(nvlist_move_nvlist__null_child)
661{
662	nvlist_t *parent;
663
664	parent = nvlist_create(0);
665
666	nvlist_move_nvlist(parent, "test", NULL);
667
668	ATF_REQUIRE(nvlist_error(parent) != 0);
669
670	nvlist_destroy(parent);
671}
672
673ATF_TEST_CASE_WITHOUT_HEAD(nvlist_move_nvlist__child_with_error);
674ATF_TEST_CASE_BODY(nvlist_move_nvlist__child_with_error)
675{
676	nvlist_t *nvl, *parent;
677
678	nvl = nvlist_create(0);
679	parent = nvlist_create(0);
680
681	nvlist_set_error(nvl, EBADF);
682	nvlist_move_nvlist(parent, "test", nvl);
683	ATF_REQUIRE_EQ(nvlist_error(parent), EBADF);
684
685	nvlist_destroy(parent);
686}
687
688ATF_TEST_CASE_WITHOUT_HEAD(nvlist_move_nvlist__single_insert);
689ATF_TEST_CASE_BODY(nvlist_move_nvlist__single_insert)
690{
691	nvlist_t *nvl;
692	const char *key;
693	nvlist_t *value;
694
695	nvl = nvlist_create(0);
696	ATF_REQUIRE(nvl != NULL);
697
698	key = "testkey";
699	value = nvlist_create(0);
700	ATF_REQUIRE(value != NULL);
701
702	nvlist_move_nvlist(nvl, key, value);
703	ATF_REQUIRE_EQ(nvlist_get_nvlist(nvl, key), value);
704
705	nvlist_destroy(nvl);
706}
707
708ATF_TEST_CASE_WITHOUT_HEAD(nvlist_move_binary__single_insert);
709ATF_TEST_CASE_BODY(nvlist_move_binary__single_insert)
710{
711	nvlist_t *nvl;
712	const char *key;
713	void *value;
714	size_t size, actual_size;
715
716	nvl = nvlist_create(0);
717	ATF_REQUIRE(nvl != NULL);
718
719	key = "testkey";
720	size = 73;
721	value = malloc(size);
722	ATF_REQUIRE(value != NULL);
723
724	nvlist_move_binary(nvl, key, value, size);
725	ATF_REQUIRE_EQ(nvlist_get_binary(nvl, key, &actual_size), value);
726	ATF_REQUIRE_EQ(size, actual_size);
727
728	nvlist_destroy(nvl);
729}
730
731ATF_TEST_CASE_WITHOUT_HEAD(nvlist_take_bool__single_remove);
732ATF_TEST_CASE_BODY(nvlist_take_bool__single_remove)
733{
734	nvlist_t *nvl;
735	const char *testkey;
736	bool testval;
737
738	nvl = nvlist_create(0);
739	ATF_REQUIRE(nvl != NULL);
740
741	testkey = "boolkey";
742	testval = false;
743	nvlist_add_bool(nvl, testkey, testval);
744
745	ATF_REQUIRE_EQ(nvlist_take_bool(nvl, testkey), testval);
746	ATF_REQUIRE(nvlist_empty(nvl));
747
748	nvlist_destroy(nvl);
749}
750
751ATF_TEST_CASE_WITHOUT_HEAD(nvlist_take_bool__other_keys_unchanged);
752ATF_TEST_CASE_BODY(nvlist_take_bool__other_keys_unchanged)
753{
754	nvlist_t *nvl;
755	const char *testkey, *otherkey1, *otherkey2;
756	bool testval, otherval1;
757	nvlist_t *otherval2;
758
759	nvl = nvlist_create(0);
760	ATF_REQUIRE(nvl != NULL);
761
762	testkey = "boolkey";
763	testval = true;
764	nvlist_add_bool(nvl, testkey, testval);
765
766	otherkey1 = "key1";
767	otherval1 = false;
768	nvlist_add_bool(nvl, otherkey1, otherval1);
769
770	otherkey2 = "key2";
771	otherval2 = create_test_nvlist();
772	nvlist_move_nvlist(nvl, otherkey2, otherval2);
773
774	ATF_REQUIRE_EQ(nvlist_take_bool(nvl, testkey), testval);
775
776	ATF_REQUIRE(nvlist_exists_bool(nvl, otherkey1));
777	ATF_REQUIRE_EQ(nvlist_get_bool(nvl, otherkey1), otherval1);
778
779	ATF_REQUIRE(nvlist_exists_nvlist(nvl, otherkey2));
780	verify_test_nvlist(nvlist_get_nvlist(nvl, otherkey2));
781
782	nvlist_destroy(nvl);
783}
784
785ATF_TEST_CASE_WITHOUT_HEAD(nvlist_take_number__single_remove);
786ATF_TEST_CASE_BODY(nvlist_take_number__single_remove)
787{
788	nvlist_t *nvl;
789	const char *testkey;
790	uint64_t testval;
791
792	nvl = nvlist_create(0);
793	ATF_REQUIRE(nvl != NULL);
794
795	testkey = "numkey";
796	testval = std::numeric_limits<uint64_t>::max();
797	nvlist_add_number(nvl, testkey, testval);
798
799	ATF_REQUIRE_EQ(nvlist_take_number(nvl, testkey), testval);
800	ATF_REQUIRE(nvlist_empty(nvl));
801
802	nvlist_destroy(nvl);
803}
804
805ATF_TEST_CASE_WITHOUT_HEAD(nvlist_take_number__other_keys_unchanged);
806ATF_TEST_CASE_BODY(nvlist_take_number__other_keys_unchanged)
807{
808	nvlist_t *nvl;
809	const char *testkey, *otherkey1, *otherkey2;
810	uint64_t testval, otherval1;
811	const char *otherval2;
812
813	nvl = nvlist_create(0);
814	ATF_REQUIRE(nvl != NULL);
815
816	otherkey1 = "key1";
817	otherval1 = 5;
818	nvlist_add_number(nvl, otherkey1, otherval1);
819
820	testkey = "numkey";
821	testval = 1654;
822	nvlist_add_number(nvl, testkey, testval);
823
824	otherkey2 = "key2";
825	otherval2 = "string";
826	nvlist_add_string(nvl, otherkey2, otherval2);
827
828	ATF_REQUIRE_EQ(nvlist_take_number(nvl, testkey), testval);
829
830	ATF_REQUIRE(nvlist_exists_number(nvl, otherkey1));
831	ATF_REQUIRE_EQ(nvlist_get_number(nvl, otherkey1), otherval1);
832
833	ATF_REQUIRE(nvlist_exists_string(nvl, otherkey2));
834	ATF_REQUIRE_EQ(strcmp(nvlist_get_string(nvl, otherkey2), otherval2), 0);
835
836	nvlist_destroy(nvl);
837}
838
839ATF_TEST_CASE_WITHOUT_HEAD(nvlist_take_string__single_remove);
840ATF_TEST_CASE_BODY(nvlist_take_string__single_remove)
841{
842	nvlist_t *nvl;
843	const char *testkey;
844	const char *testval;
845
846	nvl = nvlist_create(0);
847	ATF_REQUIRE(nvl != NULL);
848
849	testkey = "numkey";
850	testval = "nvlist";
851	nvlist_add_string(nvl, testkey, testval);
852
853	ATF_REQUIRE_EQ(strcmp(nvlist_take_string(nvl, testkey), testval), 0);
854	ATF_REQUIRE(nvlist_empty(nvl));
855
856	nvlist_destroy(nvl);
857}
858
859ATF_TEST_CASE_WITHOUT_HEAD(nvlist_take_string__other_keys_unchanged);
860ATF_TEST_CASE_BODY(nvlist_take_string__other_keys_unchanged)
861{
862	nvlist_t *nvl;
863	const char *testkey, *otherkey1, *otherkey2;
864	const char *testval, *otherval1;
865	bool otherval2;
866
867	nvl = nvlist_create(0);
868	ATF_REQUIRE(nvl != NULL);
869
870	otherkey1 = "key1";
871	otherval1 = "fjdifjdk";
872	nvlist_add_string(nvl, otherkey1, otherval1);
873
874	otherkey2 = "key2";
875	otherval2 = true;
876	nvlist_add_bool(nvl, otherkey2, otherval2);
877
878	testkey = "strkey";
879	testval = "1654";
880	nvlist_add_string(nvl, testkey, testval);
881
882	ATF_REQUIRE_EQ(strcmp(nvlist_take_string(nvl, testkey), testval), 0);
883
884	ATF_REQUIRE(nvlist_exists_string(nvl, otherkey1));
885	ATF_REQUIRE_EQ(strcmp(nvlist_get_string(nvl, otherkey1), otherval1), 0);
886
887	ATF_REQUIRE(nvlist_exists_bool(nvl, otherkey2));
888	ATF_REQUIRE_EQ(nvlist_get_bool(nvl, otherkey2), otherval2);
889
890	nvlist_destroy(nvl);
891}
892
893ATF_TEST_CASE_WITHOUT_HEAD(nvlist_take_nvlist__single_remove);
894ATF_TEST_CASE_BODY(nvlist_take_nvlist__single_remove)
895{
896	nvlist_t *nvl;
897	const char *testkey;
898	nvlist_t *testval;
899
900	nvl = nvlist_create(0);
901	ATF_REQUIRE(nvl != NULL);
902
903	testkey = "numkey";
904	testval = create_test_nvlist();
905	nvlist_move_nvlist(nvl, testkey, testval);
906
907	verify_test_nvlist(nvlist_take_nvlist(nvl, testkey));
908	ATF_REQUIRE(nvlist_empty(nvl));
909
910	nvlist_destroy(nvl);
911}
912
913ATF_TEST_CASE_WITHOUT_HEAD(nvlist_take_nvlist__other_keys_unchanged);
914ATF_TEST_CASE_BODY(nvlist_take_nvlist__other_keys_unchanged)
915{
916	nvlist_t *nvl;
917	const char *testkey, *otherkey1, *otherkey2;
918	nvlist_t *testval, *otherval1;
919
920	nvl = nvlist_create(0);
921	ATF_REQUIRE(nvl != NULL);
922
923	testkey = "strkey";
924	testval = create_test_nvlist();
925	nvlist_move_nvlist(nvl, testkey, testval);
926
927	otherkey1 = "key1";
928	otherval1 = nvlist_create(0);
929	nvlist_move_nvlist(nvl, otherkey1, otherval1);
930
931	otherkey2 = "key2";
932	nvlist_add_null(nvl, otherkey2);
933
934	verify_test_nvlist(nvlist_take_nvlist(nvl, testkey));
935
936	ATF_REQUIRE(nvlist_exists_nvlist(nvl, otherkey1));
937	ATF_REQUIRE(nvlist_empty(nvlist_get_nvlist(nvl, otherkey1)));
938
939	ATF_REQUIRE(nvlist_exists_null(nvl, otherkey2));
940
941	nvlist_destroy(nvl);
942}
943
944ATF_TEST_CASE_WITHOUT_HEAD(nvlist_take_binary__single_remove);
945ATF_TEST_CASE_BODY(nvlist_take_binary__single_remove)
946{
947	nvlist_t *nvl;
948	const char *testkey;
949	void *testval;
950	const void *actual_val;
951	size_t testsize, actual_size;
952
953	nvl = nvlist_create(0);
954	ATF_REQUIRE(nvl != NULL);
955
956	testkey = "numkey";
957	testsize = 457;
958	testval = malloc(testsize);
959	memset(testval, '5', testsize);
960	nvlist_move_binary(nvl, testkey, testval, testsize);
961
962	actual_val = nvlist_take_binary(nvl, testkey, &actual_size);
963	ATF_REQUIRE_EQ(testsize, actual_size);
964	ATF_REQUIRE_EQ(memcmp(actual_val, testval, testsize), 0);
965	ATF_REQUIRE(nvlist_empty(nvl));
966
967	nvlist_destroy(nvl);
968}
969
970ATF_TEST_CASE_WITHOUT_HEAD(nvlist_take_binary__other_keys_unchanged);
971ATF_TEST_CASE_BODY(nvlist_take_binary__other_keys_unchanged)
972{
973	nvlist_t *nvl;
974	const char *testkey, *otherkey1, *otherkey2;
975	const void *actual_value;
976	char testval[] = "gjiertj";
977	char otherval1[] = "fdreg";
978	size_t testsize, othersize, actual_size;
979	bool otherval2;
980
981	nvl = nvlist_create(0);
982	ATF_REQUIRE(nvl != NULL);
983
984	otherkey1 = "key1";
985	othersize = sizeof(otherval1);
986	nvlist_add_binary(nvl, otherkey1, otherval1, othersize);
987
988	otherkey2 = "key2";
989	otherval2 = true;
990	nvlist_add_bool(nvl, otherkey2, otherval2);
991
992	testkey = "strkey";
993	testsize = sizeof(testval);
994	nvlist_add_binary(nvl, testkey, testval, testsize);
995
996	actual_value = nvlist_take_binary(nvl, testkey, &actual_size);
997	ATF_REQUIRE_EQ(testsize, actual_size);
998	ATF_REQUIRE_EQ(memcmp(actual_value, testval, testsize), 0);
999
1000	ATF_REQUIRE(nvlist_exists_binary(nvl, otherkey1));
1001	actual_value = nvlist_get_binary(nvl, otherkey1, &actual_size);
1002	ATF_REQUIRE_EQ(othersize, actual_size);
1003	ATF_REQUIRE_EQ(memcmp(actual_value, otherval1, othersize), 0);
1004
1005	ATF_REQUIRE(nvlist_exists_bool(nvl, otherkey2));
1006	ATF_REQUIRE_EQ(nvlist_get_bool(nvl, otherkey2), otherval2);
1007
1008	nvlist_destroy(nvl);
1009}
1010
1011ATF_TEST_CASE_WITHOUT_HEAD(nvlist_free__single_null);
1012ATF_TEST_CASE_BODY(nvlist_free__single_null)
1013{
1014	nvlist_t *nvl;
1015	const char *key;
1016
1017	nvl = nvlist_create(0);
1018	key = "test";
1019	nvlist_add_null(nvl, key);
1020
1021	nvlist_free(nvl, key);
1022	ATF_REQUIRE(nvlist_empty(nvl));
1023
1024	nvlist_destroy(nvl);
1025}
1026
1027ATF_TEST_CASE_WITHOUT_HEAD(nvlist_free__single_bool);
1028ATF_TEST_CASE_BODY(nvlist_free__single_bool)
1029{
1030	nvlist_t *nvl;
1031	const char *key;
1032
1033	nvl = nvlist_create(0);
1034	key = "test";
1035	nvlist_add_bool(nvl, key, true);
1036
1037	nvlist_free(nvl, key);
1038	ATF_REQUIRE(nvlist_empty(nvl));
1039
1040	nvlist_destroy(nvl);
1041}
1042
1043ATF_TEST_CASE_WITHOUT_HEAD(nvlist_free__single_number);
1044ATF_TEST_CASE_BODY(nvlist_free__single_number)
1045{
1046	nvlist_t *nvl;
1047	const char *key;
1048
1049	nvl = nvlist_create(0);
1050	key = "test";
1051	nvlist_add_number(nvl, key, 584);
1052
1053	nvlist_free(nvl, key);
1054	ATF_REQUIRE(nvlist_empty(nvl));
1055
1056	nvlist_destroy(nvl);
1057}
1058
1059ATF_TEST_CASE_WITHOUT_HEAD(nvlist_free__single_string);
1060ATF_TEST_CASE_BODY(nvlist_free__single_string)
1061{
1062	nvlist_t *nvl;
1063	const char *key;
1064
1065	nvl = nvlist_create(0);
1066	key = "test";
1067	nvlist_add_string(nvl, key, "gjkfkjd");
1068
1069	nvlist_free(nvl, key);
1070	ATF_REQUIRE(nvlist_empty(nvl));
1071
1072	nvlist_destroy(nvl);
1073}
1074
1075ATF_TEST_CASE_WITHOUT_HEAD(nvlist_free__single_nvlist);
1076ATF_TEST_CASE_BODY(nvlist_free__single_nvlist)
1077{
1078	nvlist_t *nvl;
1079	const char *key;
1080
1081	nvl = nvlist_create(0);
1082	key = "test";
1083	nvlist_add_nvlist(nvl, key, nvlist_create(0));
1084
1085	nvlist_free(nvl, key);
1086	ATF_REQUIRE(nvlist_empty(nvl));
1087
1088	nvlist_destroy(nvl);
1089}
1090
1091ATF_TEST_CASE_WITHOUT_HEAD(nvlist_free__single_binary);
1092ATF_TEST_CASE_BODY(nvlist_free__single_binary)
1093{
1094	nvlist_t *nvl;
1095	const char *key;
1096
1097	nvl = nvlist_create(0);
1098	key = "test";
1099	nvlist_add_binary(nvl, key, "jgjgfd", 6);
1100
1101	nvlist_free(nvl, key);
1102	ATF_REQUIRE(nvlist_empty(nvl));
1103
1104	nvlist_destroy(nvl);
1105}
1106
1107ATF_TEST_CASE_WITHOUT_HEAD(nvlist_free_null__single_null);
1108ATF_TEST_CASE_BODY(nvlist_free_null__single_null)
1109{
1110	nvlist_t *nvl;
1111	const char *key;
1112
1113	nvl = nvlist_create(0);
1114	key = "test";
1115	nvlist_add_null(nvl, key);
1116
1117	nvlist_free_null(nvl, key);
1118	ATF_REQUIRE(nvlist_empty(nvl));
1119
1120	nvlist_destroy(nvl);
1121}
1122
1123ATF_TEST_CASE_WITHOUT_HEAD(nvlist_free_bool__single_bool);
1124ATF_TEST_CASE_BODY(nvlist_free_bool__single_bool)
1125{
1126	nvlist_t *nvl;
1127	const char *key;
1128
1129	nvl = nvlist_create(0);
1130	key = "test";
1131	nvlist_add_bool(nvl, key, true);
1132
1133	nvlist_free_bool(nvl, key);
1134	ATF_REQUIRE(nvlist_empty(nvl));
1135
1136	nvlist_destroy(nvl);
1137}
1138
1139ATF_TEST_CASE_WITHOUT_HEAD(nvlist_free_number__single_number);
1140ATF_TEST_CASE_BODY(nvlist_free_number__single_number)
1141{
1142	nvlist_t *nvl;
1143	const char *key;
1144
1145	nvl = nvlist_create(0);
1146	key = "test";
1147	nvlist_add_number(nvl, key, 584);
1148
1149	nvlist_free_number(nvl, key);
1150	ATF_REQUIRE(nvlist_empty(nvl));
1151
1152	nvlist_destroy(nvl);
1153}
1154
1155ATF_TEST_CASE_WITHOUT_HEAD(nvlist_free_string__single_string);
1156ATF_TEST_CASE_BODY(nvlist_free_string__single_string)
1157{
1158	nvlist_t *nvl;
1159	const char *key;
1160
1161	nvl = nvlist_create(0);
1162	key = "test";
1163	nvlist_add_string(nvl, key, "gjkfkjd");
1164
1165	nvlist_free_string(nvl, key);
1166	ATF_REQUIRE(nvlist_empty(nvl));
1167
1168	nvlist_destroy(nvl);
1169}
1170
1171ATF_TEST_CASE_WITHOUT_HEAD(nvlist_free_nvlist__single_nvlist);
1172ATF_TEST_CASE_BODY(nvlist_free_nvlist__single_nvlist)
1173{
1174	nvlist_t *nvl;
1175	const char *key;
1176
1177	nvl = nvlist_create(0);
1178	key = "test";
1179	nvlist_add_nvlist(nvl, key, nvlist_create(0));
1180
1181	nvlist_free_nvlist(nvl, key);
1182	ATF_REQUIRE(nvlist_empty(nvl));
1183
1184	nvlist_destroy(nvl);
1185}
1186
1187ATF_TEST_CASE_WITHOUT_HEAD(nvlist_free_binary__single_binary);
1188ATF_TEST_CASE_BODY(nvlist_free_binary__single_binary)
1189{
1190	nvlist_t *nvl;
1191	const char *key;
1192
1193	nvl = nvlist_create(0);
1194	key = "test";
1195	nvlist_add_binary(nvl, key, "jgjgfd", 6);
1196
1197	nvlist_free_binary(nvl, key);
1198	ATF_REQUIRE(nvlist_empty(nvl));
1199
1200	nvlist_destroy(nvl);
1201}
1202
1203ATF_INIT_TEST_CASES(tp)
1204{
1205	ATF_ADD_TEST_CASE(tp, nvlist_create__is_empty);
1206	ATF_ADD_TEST_CASE(tp, nvlist_add_null__single_insert);
1207	ATF_ADD_TEST_CASE(tp, nvlist_add_bool__single_insert);
1208	ATF_ADD_TEST_CASE(tp, nvlist_add_number__single_insert);
1209	ATF_ADD_TEST_CASE(tp, nvlist_add_string__single_insert);
1210	ATF_ADD_TEST_CASE(tp, nvlist_add_nvlist__single_insert);
1211	ATF_ADD_TEST_CASE(tp, nvlist_add_nvlist__child_with_error);
1212	ATF_ADD_TEST_CASE(tp, nvlist_add_binary__single_insert);
1213
1214	ATF_ADD_TEST_CASE(tp, nvlist_clone__empty_nvlist);
1215	ATF_ADD_TEST_CASE(tp, nvlist_clone__nonempty_nvlist);
1216	ATF_ADD_TEST_CASE(tp, nvlist_clone__nested_nvlist);
1217	ATF_ADD_TEST_CASE(tp, nvlist_clone__error_nvlist);
1218
1219	ATF_ADD_TEST_CASE(tp, nvlist_pack__empty_nvlist);
1220	ATF_ADD_TEST_CASE(tp, nvlist_pack__multiple_values);
1221	ATF_ADD_TEST_CASE(tp, nvlist_pack__error_nvlist);
1222	ATF_ADD_TEST_CASE(tp, nvlist_unpack__duplicate_key);
1223
1224	ATF_ADD_TEST_CASE(tp, nvlist_move_string__single_insert);
1225	ATF_ADD_TEST_CASE(tp, nvlist_move_nvlist__single_insert);
1226	ATF_ADD_TEST_CASE(tp, nvlist_move_nvlist__null_child);
1227	ATF_ADD_TEST_CASE(tp, nvlist_move_nvlist__child_with_error);
1228	ATF_ADD_TEST_CASE(tp, nvlist_move_binary__single_insert);
1229
1230	ATF_ADD_TEST_CASE(tp, nvlist_take_bool__single_remove);
1231	ATF_ADD_TEST_CASE(tp, nvlist_take_bool__other_keys_unchanged);
1232	ATF_ADD_TEST_CASE(tp, nvlist_take_number__single_remove);
1233	ATF_ADD_TEST_CASE(tp, nvlist_take_number__other_keys_unchanged);
1234	ATF_ADD_TEST_CASE(tp, nvlist_take_string__single_remove);
1235	ATF_ADD_TEST_CASE(tp, nvlist_take_string__other_keys_unchanged);
1236	ATF_ADD_TEST_CASE(tp, nvlist_take_nvlist__single_remove);
1237	ATF_ADD_TEST_CASE(tp, nvlist_take_nvlist__other_keys_unchanged);
1238	ATF_ADD_TEST_CASE(tp, nvlist_take_binary__single_remove);
1239	ATF_ADD_TEST_CASE(tp, nvlist_take_binary__other_keys_unchanged);
1240
1241	ATF_ADD_TEST_CASE(tp, nvlist_free__single_null);
1242	ATF_ADD_TEST_CASE(tp, nvlist_free__single_bool);
1243	ATF_ADD_TEST_CASE(tp, nvlist_free__single_number);
1244	ATF_ADD_TEST_CASE(tp, nvlist_free__single_string);
1245	ATF_ADD_TEST_CASE(tp, nvlist_free__single_nvlist);
1246	ATF_ADD_TEST_CASE(tp, nvlist_free__single_binary);
1247
1248	ATF_ADD_TEST_CASE(tp, nvlist_free_null__single_null);
1249	ATF_ADD_TEST_CASE(tp, nvlist_free_bool__single_bool);
1250	ATF_ADD_TEST_CASE(tp, nvlist_free_number__single_number);
1251	ATF_ADD_TEST_CASE(tp, nvlist_free_string__single_string);
1252	ATF_ADD_TEST_CASE(tp, nvlist_free_nvlist__single_nvlist);
1253	ATF_ADD_TEST_CASE(tp, nvlist_free_binary__single_binary);
1254}
1255