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