]> CyberLeo.Net >> Repos - FreeBSD/stable/10.git/blob - lib/libnv/tests/nv_tests.cc
MFC r327029:
[FreeBSD/stable/10.git] / lib / libnv / tests / nv_tests.cc
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$");
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  */
42 ATF_TEST_CASE_WITHOUT_HEAD(nvlist_create__is_empty);
43 ATF_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
62 ATF_TEST_CASE_WITHOUT_HEAD(nvlist_add_null__single_insert);
63 ATF_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
92 ATF_TEST_CASE_WITHOUT_HEAD(nvlist_add_bool__single_insert);
93 ATF_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
124 ATF_TEST_CASE_WITHOUT_HEAD(nvlist_add_number__single_insert);
125 ATF_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
157 ATF_TEST_CASE_WITHOUT_HEAD(nvlist_add_string__single_insert);
158 ATF_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
194 ATF_TEST_CASE_WITHOUT_HEAD(nvlist_add_nvlist__single_insert);
195 ATF_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
237 ATF_TEST_CASE_WITHOUT_HEAD(nvlist_add_nvlist__child_with_error);
238 ATF_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
253 ATF_TEST_CASE_WITHOUT_HEAD(nvlist_add_binary__single_insert);
254 ATF_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
298 ATF_TEST_CASE_WITHOUT_HEAD(nvlist_clone__empty_nvlist);
299 ATF_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
315 ATF_TEST_CASE_WITHOUT_HEAD(nvlist_clone__nonempty_nvlist);
316 ATF_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
347 static const char * const test_subnvlist_key = "nvlist";
348
349 static const char * const test_string_key = "string";
350 static const char * const test_string_val = "59525";
351
352 static nvlist_t*
353 create_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
369 static void
370 verify_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
398 ATF_TEST_CASE_WITHOUT_HEAD(nvlist_clone__nested_nvlist);
399 ATF_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
414 ATF_TEST_CASE_WITHOUT_HEAD(nvlist_clone__error_nvlist);
415 ATF_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
430 ATF_TEST_CASE_WITHOUT_HEAD(nvlist_pack__empty_nvlist);
431 ATF_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);
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
453 static void
454 verify_null(const nvlist_t *nvl, int type)
455 {
456
457         ATF_REQUIRE_EQ(type, NV_TYPE_NULL);
458 }
459
460 static void
461 verify_number(const nvlist_t *nvl, const char *name, int type, uint64_t value)
462 {
463
464         ATF_REQUIRE_EQ(type, NV_TYPE_NUMBER);
465         ATF_REQUIRE_EQ(nvlist_get_number(nvl, name), value);
466 }
467
468 static void
469 verify_string(const nvlist_t *nvl, const char *name, int type,
470     const char * value)
471 {
472
473         ATF_REQUIRE_EQ(type, NV_TYPE_STRING);
474         ATF_REQUIRE_EQ(strcmp(nvlist_get_string(nvl, name), value), 0);
475 }
476
477 static void
478 verify_nvlist(const nvlist_t *nvl, const char *name, int type)
479 {
480
481         ATF_REQUIRE_EQ(type, NV_TYPE_NVLIST);
482         verify_test_nvlist(nvlist_get_nvlist(nvl, name));
483 }
484
485 static void
486 verify_binary(const nvlist_t *nvl, const char *name, int type,
487     const void * value, size_t size)
488 {
489         const void *actual_value;
490         size_t actual_size;
491
492         ATF_REQUIRE_EQ(type, NV_TYPE_BINARY);
493         actual_value = nvlist_get_binary(nvl, name, &actual_size);
494         ATF_REQUIRE_EQ(size, actual_size);
495         ATF_REQUIRE_EQ(memcmp(value, actual_value, size), 0);
496 }
497
498 ATF_TEST_CASE_WITHOUT_HEAD(nvlist_pack__multiple_values);
499 ATF_TEST_CASE_BODY(nvlist_pack__multiple_values)
500 {
501         std::ostringstream msg;
502         std::set<std::string> keys_seen;
503         nvlist_t *nvl, *unpacked, *nvvalue;
504         const char *nullkey, *numkey, *strkey, *nvkey, *binkey, *name;
505         int numvalue;
506         const char * strvalue;
507         void *binvalue, *packed, *it;
508         size_t binsize, packed_size;
509         int type;
510
511         nvl = nvlist_create(0);
512
513         nullkey = "null";
514         nvlist_add_null(nvl, nullkey);
515
516         numkey = "number";
517         numvalue = 939853984;
518         nvlist_add_number(nvl, numkey, numvalue);
519
520         strkey = "string";
521         strvalue = "jfieutijf";
522         nvlist_add_string(nvl, strkey, strvalue);
523
524         nvkey = "nvlist";
525         nvvalue = create_test_nvlist();
526         nvlist_move_nvlist(nvl, nvkey, nvvalue);
527
528         binkey = "binary";
529         binsize = 4;
530         binvalue = malloc(binsize);
531         memset(binvalue, 'b', binsize);
532         nvlist_move_binary(nvl, binkey, binvalue, binsize);
533
534         packed = nvlist_pack(nvl, &packed_size);
535         ATF_REQUIRE(packed != NULL);
536
537         unpacked = nvlist_unpack(packed, packed_size);
538         ATF_REQUIRE(unpacked != 0);
539
540         it = NULL;
541         while ((name = nvlist_next(unpacked, &type, &it)) != NULL) {
542                 /* Ensure that we see every key only once. */
543                 ATF_REQUIRE_EQ(keys_seen.count(name), 0);
544
545                 if (strcmp(name, nullkey) == 0)
546                         verify_null(unpacked, type);
547                 else if (strcmp(name, numkey) == 0)
548                         verify_number(unpacked, name, type, numvalue);
549                 else if (strcmp(name, strkey) == 0)
550                         verify_string(unpacked, name, type, strvalue);
551                 else if (strcmp(name, nvkey) == 0)
552                         verify_nvlist(unpacked, name, type);
553                 else if (strcmp(name, binkey) == 0)
554                         verify_binary(unpacked, name, type, binvalue, binsize);
555                 else {
556                         msg << "Unexpected key :'" << name << "'";
557                         ATF_FAIL(msg.str().c_str());
558                 }
559
560                 keys_seen.insert(name);
561         }
562
563         /* Ensure that we saw every key. */
564         ATF_REQUIRE_EQ(keys_seen.size(), 5);
565
566         nvlist_destroy(nvl);
567         nvlist_destroy(unpacked);
568         free(packed);
569 }
570
571 ATF_TEST_CASE_WITHOUT_HEAD(nvlist_pack__error_nvlist);
572 ATF_TEST_CASE_BODY(nvlist_pack__error_nvlist)
573 {
574         nvlist_t *nvl;
575         void *packed;
576         size_t size;
577
578         nvl = nvlist_create(0);
579         ATF_REQUIRE(nvl != NULL);
580
581         nvlist_set_error(nvl, ENOMEM);
582
583         packed = nvlist_pack(nvl, &size);
584         ATF_REQUIRE(packed == NULL);
585
586         nvlist_destroy(nvl);
587 }
588
589 ATF_TEST_CASE_WITHOUT_HEAD(nvlist_unpack__duplicate_key);
590 ATF_TEST_CASE_BODY(nvlist_unpack__duplicate_key)
591 {
592         nvlist_t *nvl, *unpacked;
593         const char *key1, *key2;
594         void *packed, *keypos;
595         size_t size, keylen;
596
597         nvl = nvlist_create(0);
598
599         key1 = "key1";
600         keylen = strlen(key1);
601         nvlist_add_number(nvl, key1, 5);
602
603         key2 = "key2";
604         ATF_REQUIRE_EQ(keylen, strlen(key2));
605         nvlist_add_number(nvl, key2, 10);
606
607         packed = nvlist_pack(nvl, &size);
608         ATF_REQUIRE(packed != NULL);
609
610         /*
611          * Mangle the packed nvlist by replacing key1 with key2, creating a
612          * packed nvlist with a duplicate key.
613          */
614         keypos = memmem(packed, size, key1, keylen);
615         ATF_REQUIRE(keypos != NULL);
616         memcpy(keypos, key2, keylen);
617
618         unpacked = nvlist_unpack(packed, size);
619         ATF_REQUIRE(nvlist_error(unpacked) != 0);
620
621         free(packed);
622         nvlist_destroy(nvl);
623         nvlist_destroy(unpacked);
624 }
625
626 ATF_TEST_CASE_WITHOUT_HEAD(nvlist_move_string__single_insert);
627 ATF_TEST_CASE_BODY(nvlist_move_string__single_insert)
628 {
629         nvlist_t *nvl;
630         const char *key;
631         char *value;
632
633         nvl = nvlist_create(0);
634         ATF_REQUIRE(nvl != NULL);
635
636         key = "testkey";
637         value = strdup("testval");
638         ATF_REQUIRE(value != NULL);
639
640         nvlist_move_string(nvl, key, value);
641         ATF_REQUIRE_EQ(nvlist_get_string(nvl, key), value);
642
643         nvlist_destroy(nvl);
644 }
645
646 ATF_TEST_CASE_WITHOUT_HEAD(nvlist_move_nvlist__null_child);
647 ATF_TEST_CASE_BODY(nvlist_move_nvlist__null_child)
648 {
649         nvlist_t *parent;
650
651         parent = nvlist_create(0);
652
653         nvlist_move_nvlist(parent, "test", NULL);
654
655         ATF_REQUIRE(nvlist_error(parent) != 0);
656
657         nvlist_destroy(parent);
658 }
659
660 ATF_TEST_CASE_WITHOUT_HEAD(nvlist_move_nvlist__child_with_error);
661 ATF_TEST_CASE_BODY(nvlist_move_nvlist__child_with_error)
662 {
663         nvlist_t *nvl, *parent;
664
665         nvl = nvlist_create(0);
666         parent = nvlist_create(0);
667
668         nvlist_set_error(nvl, EBADF);
669         nvlist_move_nvlist(parent, "test", nvl);
670         ATF_REQUIRE_EQ(nvlist_error(parent), EBADF);
671
672         nvlist_destroy(parent);
673 }
674
675 ATF_TEST_CASE_WITHOUT_HEAD(nvlist_move_nvlist__single_insert);
676 ATF_TEST_CASE_BODY(nvlist_move_nvlist__single_insert)
677 {
678         nvlist_t *nvl;
679         const char *key;
680         nvlist_t *value;
681
682         nvl = nvlist_create(0);
683         ATF_REQUIRE(nvl != NULL);
684
685         key = "testkey";
686         value = nvlist_create(0);
687         ATF_REQUIRE(value != NULL);
688
689         nvlist_move_nvlist(nvl, key, value);
690         ATF_REQUIRE_EQ(nvlist_get_nvlist(nvl, key), value);
691
692         nvlist_destroy(nvl);
693 }
694
695 ATF_TEST_CASE_WITHOUT_HEAD(nvlist_move_binary__single_insert);
696 ATF_TEST_CASE_BODY(nvlist_move_binary__single_insert)
697 {
698         nvlist_t *nvl;
699         const char *key;
700         void *value;
701         size_t size, actual_size;
702
703         nvl = nvlist_create(0);
704         ATF_REQUIRE(nvl != NULL);
705
706         key = "testkey";
707         size = 73;
708         value = malloc(size);
709         ATF_REQUIRE(value != NULL);
710
711         nvlist_move_binary(nvl, key, value, size);
712         ATF_REQUIRE_EQ(nvlist_get_binary(nvl, key, &actual_size), value);
713         ATF_REQUIRE_EQ(size, actual_size);
714
715         nvlist_destroy(nvl);
716 }
717
718 ATF_TEST_CASE_WITHOUT_HEAD(nvlist_take_bool__single_remove);
719 ATF_TEST_CASE_BODY(nvlist_take_bool__single_remove)
720 {
721         nvlist_t *nvl;
722         const char *testkey;
723         bool testval;
724
725         nvl = nvlist_create(0);
726         ATF_REQUIRE(nvl != NULL);
727
728         testkey = "boolkey";
729         testval = false;
730         nvlist_add_bool(nvl, testkey, testval);
731
732         ATF_REQUIRE_EQ(nvlist_take_bool(nvl, testkey), testval);
733         ATF_REQUIRE(nvlist_empty(nvl));
734
735         nvlist_destroy(nvl);
736 }
737
738 ATF_TEST_CASE_WITHOUT_HEAD(nvlist_take_bool__other_keys_unchanged);
739 ATF_TEST_CASE_BODY(nvlist_take_bool__other_keys_unchanged)
740 {
741         nvlist_t *nvl;
742         const char *testkey, *otherkey1, *otherkey2;
743         bool testval, otherval1;
744         nvlist_t *otherval2;
745
746         nvl = nvlist_create(0);
747         ATF_REQUIRE(nvl != NULL);
748
749         testkey = "boolkey";
750         testval = true;
751         nvlist_add_bool(nvl, testkey, testval);
752
753         otherkey1 = "key1";
754         otherval1 = false;
755         nvlist_add_bool(nvl, otherkey1, otherval1);
756
757         otherkey2 = "key2";
758         otherval2 = create_test_nvlist();
759         nvlist_move_nvlist(nvl, otherkey2, otherval2);
760
761         ATF_REQUIRE_EQ(nvlist_take_bool(nvl, testkey), testval);
762
763         ATF_REQUIRE(nvlist_exists_bool(nvl, otherkey1));
764         ATF_REQUIRE_EQ(nvlist_get_bool(nvl, otherkey1), otherval1);
765
766         ATF_REQUIRE(nvlist_exists_nvlist(nvl, otherkey2));
767         verify_test_nvlist(nvlist_get_nvlist(nvl, otherkey2));
768
769         nvlist_destroy(nvl);
770 }
771
772 ATF_TEST_CASE_WITHOUT_HEAD(nvlist_take_number__single_remove);
773 ATF_TEST_CASE_BODY(nvlist_take_number__single_remove)
774 {
775         nvlist_t *nvl;
776         const char *testkey;
777         uint64_t testval;
778
779         nvl = nvlist_create(0);
780         ATF_REQUIRE(nvl != NULL);
781
782         testkey = "numkey";
783         testval = std::numeric_limits<uint64_t>::max();
784         nvlist_add_number(nvl, testkey, testval);
785
786         ATF_REQUIRE_EQ(nvlist_take_number(nvl, testkey), testval);
787         ATF_REQUIRE(nvlist_empty(nvl));
788
789         nvlist_destroy(nvl);
790 }
791
792 ATF_TEST_CASE_WITHOUT_HEAD(nvlist_take_number__other_keys_unchanged);
793 ATF_TEST_CASE_BODY(nvlist_take_number__other_keys_unchanged)
794 {
795         nvlist_t *nvl;
796         const char *testkey, *otherkey1, *otherkey2;
797         uint64_t testval, otherval1;
798         const char *otherval2;
799
800         nvl = nvlist_create(0);
801         ATF_REQUIRE(nvl != NULL);
802
803         otherkey1 = "key1";
804         otherval1 = 5;
805         nvlist_add_number(nvl, otherkey1, otherval1);
806
807         testkey = "numkey";
808         testval = 1654;
809         nvlist_add_number(nvl, testkey, testval);
810
811         otherkey2 = "key2";
812         otherval2 = "string";
813         nvlist_add_string(nvl, otherkey2, otherval2);
814
815         ATF_REQUIRE_EQ(nvlist_take_number(nvl, testkey), testval);
816
817         ATF_REQUIRE(nvlist_exists_number(nvl, otherkey1));
818         ATF_REQUIRE_EQ(nvlist_get_number(nvl, otherkey1), otherval1);
819
820         ATF_REQUIRE(nvlist_exists_string(nvl, otherkey2));
821         ATF_REQUIRE_EQ(strcmp(nvlist_get_string(nvl, otherkey2), otherval2), 0);
822
823         nvlist_destroy(nvl);
824 }
825
826 ATF_TEST_CASE_WITHOUT_HEAD(nvlist_take_string__single_remove);
827 ATF_TEST_CASE_BODY(nvlist_take_string__single_remove)
828 {
829         nvlist_t *nvl;
830         const char *testkey;
831         const char *testval;
832
833         nvl = nvlist_create(0);
834         ATF_REQUIRE(nvl != NULL);
835
836         testkey = "numkey";
837         testval = "nvlist";
838         nvlist_add_string(nvl, testkey, testval);
839
840         ATF_REQUIRE_EQ(strcmp(nvlist_take_string(nvl, testkey), testval), 0);
841         ATF_REQUIRE(nvlist_empty(nvl));
842
843         nvlist_destroy(nvl);
844 }
845
846 ATF_TEST_CASE_WITHOUT_HEAD(nvlist_take_string__other_keys_unchanged);
847 ATF_TEST_CASE_BODY(nvlist_take_string__other_keys_unchanged)
848 {
849         nvlist_t *nvl;
850         const char *testkey, *otherkey1, *otherkey2;
851         const char *testval, *otherval1;
852         bool otherval2;
853
854         nvl = nvlist_create(0);
855         ATF_REQUIRE(nvl != NULL);
856
857         otherkey1 = "key1";
858         otherval1 = "fjdifjdk";
859         nvlist_add_string(nvl, otherkey1, otherval1);
860
861         otherkey2 = "key2";
862         otherval2 = true;
863         nvlist_add_bool(nvl, otherkey2, otherval2);
864
865         testkey = "strkey";
866         testval = "1654";
867         nvlist_add_string(nvl, testkey, testval);
868
869         ATF_REQUIRE_EQ(strcmp(nvlist_take_string(nvl, testkey), testval), 0);
870
871         ATF_REQUIRE(nvlist_exists_string(nvl, otherkey1));
872         ATF_REQUIRE_EQ(strcmp(nvlist_get_string(nvl, otherkey1), otherval1), 0);
873
874         ATF_REQUIRE(nvlist_exists_bool(nvl, otherkey2));
875         ATF_REQUIRE_EQ(nvlist_get_bool(nvl, otherkey2), otherval2);
876
877         nvlist_destroy(nvl);
878 }
879
880 ATF_TEST_CASE_WITHOUT_HEAD(nvlist_take_nvlist__single_remove);
881 ATF_TEST_CASE_BODY(nvlist_take_nvlist__single_remove)
882 {
883         nvlist_t *nvl;
884         const char *testkey;
885         nvlist_t *testval;
886
887         nvl = nvlist_create(0);
888         ATF_REQUIRE(nvl != NULL);
889
890         testkey = "numkey";
891         testval = create_test_nvlist();
892         nvlist_move_nvlist(nvl, testkey, testval);
893
894         verify_test_nvlist(nvlist_take_nvlist(nvl, testkey));
895         ATF_REQUIRE(nvlist_empty(nvl));
896
897         nvlist_destroy(nvl);
898 }
899
900 ATF_TEST_CASE_WITHOUT_HEAD(nvlist_take_nvlist__other_keys_unchanged);
901 ATF_TEST_CASE_BODY(nvlist_take_nvlist__other_keys_unchanged)
902 {
903         nvlist_t *nvl;
904         const char *testkey, *otherkey1, *otherkey2;
905         nvlist_t *testval, *otherval1;
906
907         nvl = nvlist_create(0);
908         ATF_REQUIRE(nvl != NULL);
909
910         testkey = "strkey";
911         testval = create_test_nvlist();
912         nvlist_move_nvlist(nvl, testkey, testval);
913
914         otherkey1 = "key1";
915         otherval1 = nvlist_create(0);
916         nvlist_move_nvlist(nvl, otherkey1, otherval1);
917
918         otherkey2 = "key2";
919         nvlist_add_null(nvl, otherkey2);
920
921         verify_test_nvlist(nvlist_take_nvlist(nvl, testkey));
922
923         ATF_REQUIRE(nvlist_exists_nvlist(nvl, otherkey1));
924         ATF_REQUIRE(nvlist_empty(nvlist_get_nvlist(nvl, otherkey1)));
925
926         ATF_REQUIRE(nvlist_exists_null(nvl, otherkey2));
927
928         nvlist_destroy(nvl);
929 }
930
931 ATF_TEST_CASE_WITHOUT_HEAD(nvlist_take_binary__single_remove);
932 ATF_TEST_CASE_BODY(nvlist_take_binary__single_remove)
933 {
934         nvlist_t *nvl;
935         const char *testkey;
936         void *testval;
937         const void *actual_val;
938         size_t testsize, actual_size;
939
940         nvl = nvlist_create(0);
941         ATF_REQUIRE(nvl != NULL);
942
943         testkey = "numkey";
944         testsize = 457;
945         testval = malloc(testsize);
946         memset(testval, '5', testsize);
947         nvlist_move_binary(nvl, testkey, testval, testsize);
948
949         actual_val = nvlist_take_binary(nvl, testkey, &actual_size);
950         ATF_REQUIRE_EQ(testsize, actual_size);
951         ATF_REQUIRE_EQ(memcmp(actual_val, testval, testsize), 0);
952         ATF_REQUIRE(nvlist_empty(nvl));
953
954         nvlist_destroy(nvl);
955 }
956
957 ATF_TEST_CASE_WITHOUT_HEAD(nvlist_take_binary__other_keys_unchanged);
958 ATF_TEST_CASE_BODY(nvlist_take_binary__other_keys_unchanged)
959 {
960         nvlist_t *nvl;
961         const char *testkey, *otherkey1, *otherkey2;
962         const void *actual_value;
963         char testval[] = "gjiertj";
964         char otherval1[] = "fdreg";
965         size_t testsize, othersize, actual_size;
966         bool otherval2;
967
968         nvl = nvlist_create(0);
969         ATF_REQUIRE(nvl != NULL);
970
971         otherkey1 = "key1";
972         othersize = sizeof(otherval1);
973         nvlist_add_binary(nvl, otherkey1, otherval1, othersize);
974
975         otherkey2 = "key2";
976         otherval2 = true;
977         nvlist_add_bool(nvl, otherkey2, otherval2);
978
979         testkey = "strkey";
980         testsize = sizeof(testval);
981         nvlist_add_binary(nvl, testkey, testval, testsize);
982
983         actual_value = nvlist_take_binary(nvl, testkey, &actual_size);
984         ATF_REQUIRE_EQ(testsize, actual_size);
985         ATF_REQUIRE_EQ(memcmp(actual_value, testval, testsize), 0);
986
987         ATF_REQUIRE(nvlist_exists_binary(nvl, otherkey1));
988         actual_value = nvlist_get_binary(nvl, otherkey1, &actual_size);
989         ATF_REQUIRE_EQ(othersize, actual_size);
990         ATF_REQUIRE_EQ(memcmp(actual_value, otherval1, othersize), 0);
991
992         ATF_REQUIRE(nvlist_exists_bool(nvl, otherkey2));
993         ATF_REQUIRE_EQ(nvlist_get_bool(nvl, otherkey2), otherval2);
994
995         nvlist_destroy(nvl);
996 }
997
998 ATF_TEST_CASE_WITHOUT_HEAD(nvlist_free__single_null);
999 ATF_TEST_CASE_BODY(nvlist_free__single_null)
1000 {
1001         nvlist_t *nvl;
1002         const char *key;
1003
1004         nvl = nvlist_create(0);
1005         key = "test";
1006         nvlist_add_null(nvl, key);
1007
1008         nvlist_free(nvl, key);
1009         ATF_REQUIRE(nvlist_empty(nvl));
1010
1011         nvlist_destroy(nvl);
1012 }
1013
1014 ATF_TEST_CASE_WITHOUT_HEAD(nvlist_free__single_bool);
1015 ATF_TEST_CASE_BODY(nvlist_free__single_bool)
1016 {
1017         nvlist_t *nvl;
1018         const char *key;
1019
1020         nvl = nvlist_create(0);
1021         key = "test";
1022         nvlist_add_bool(nvl, key, true);
1023
1024         nvlist_free(nvl, key);
1025         ATF_REQUIRE(nvlist_empty(nvl));
1026
1027         nvlist_destroy(nvl);
1028 }
1029
1030 ATF_TEST_CASE_WITHOUT_HEAD(nvlist_free__single_number);
1031 ATF_TEST_CASE_BODY(nvlist_free__single_number)
1032 {
1033         nvlist_t *nvl;
1034         const char *key;
1035
1036         nvl = nvlist_create(0);
1037         key = "test";
1038         nvlist_add_number(nvl, key, 584);
1039
1040         nvlist_free(nvl, key);
1041         ATF_REQUIRE(nvlist_empty(nvl));
1042
1043         nvlist_destroy(nvl);
1044 }
1045
1046 ATF_TEST_CASE_WITHOUT_HEAD(nvlist_free__single_string);
1047 ATF_TEST_CASE_BODY(nvlist_free__single_string)
1048 {
1049         nvlist_t *nvl;
1050         const char *key;
1051
1052         nvl = nvlist_create(0);
1053         key = "test";
1054         nvlist_add_string(nvl, key, "gjkfkjd");
1055
1056         nvlist_free(nvl, key);
1057         ATF_REQUIRE(nvlist_empty(nvl));
1058
1059         nvlist_destroy(nvl);
1060 }
1061
1062 ATF_TEST_CASE_WITHOUT_HEAD(nvlist_free__single_nvlist);
1063 ATF_TEST_CASE_BODY(nvlist_free__single_nvlist)
1064 {
1065         nvlist_t *nvl;
1066         const char *key;
1067
1068         nvl = nvlist_create(0);
1069         key = "test";
1070         nvlist_add_nvlist(nvl, key, nvlist_create(0));
1071
1072         nvlist_free(nvl, key);
1073         ATF_REQUIRE(nvlist_empty(nvl));
1074
1075         nvlist_destroy(nvl);
1076 }
1077
1078 ATF_TEST_CASE_WITHOUT_HEAD(nvlist_free__single_binary);
1079 ATF_TEST_CASE_BODY(nvlist_free__single_binary)
1080 {
1081         nvlist_t *nvl;
1082         const char *key;
1083
1084         nvl = nvlist_create(0);
1085         key = "test";
1086         nvlist_add_binary(nvl, key, "jgjgfd", 6);
1087
1088         nvlist_free(nvl, key);
1089         ATF_REQUIRE(nvlist_empty(nvl));
1090
1091         nvlist_destroy(nvl);
1092 }
1093
1094 ATF_TEST_CASE_WITHOUT_HEAD(nvlist_free_null__single_null);
1095 ATF_TEST_CASE_BODY(nvlist_free_null__single_null)
1096 {
1097         nvlist_t *nvl;
1098         const char *key;
1099
1100         nvl = nvlist_create(0);
1101         key = "test";
1102         nvlist_add_null(nvl, key);
1103
1104         nvlist_free_null(nvl, key);
1105         ATF_REQUIRE(nvlist_empty(nvl));
1106
1107         nvlist_destroy(nvl);
1108 }
1109
1110 ATF_TEST_CASE_WITHOUT_HEAD(nvlist_free_bool__single_bool);
1111 ATF_TEST_CASE_BODY(nvlist_free_bool__single_bool)
1112 {
1113         nvlist_t *nvl;
1114         const char *key;
1115
1116         nvl = nvlist_create(0);
1117         key = "test";
1118         nvlist_add_bool(nvl, key, true);
1119
1120         nvlist_free_bool(nvl, key);
1121         ATF_REQUIRE(nvlist_empty(nvl));
1122
1123         nvlist_destroy(nvl);
1124 }
1125
1126 ATF_TEST_CASE_WITHOUT_HEAD(nvlist_free_number__single_number);
1127 ATF_TEST_CASE_BODY(nvlist_free_number__single_number)
1128 {
1129         nvlist_t *nvl;
1130         const char *key;
1131
1132         nvl = nvlist_create(0);
1133         key = "test";
1134         nvlist_add_number(nvl, key, 584);
1135
1136         nvlist_free_number(nvl, key);
1137         ATF_REQUIRE(nvlist_empty(nvl));
1138
1139         nvlist_destroy(nvl);
1140 }
1141
1142 ATF_TEST_CASE_WITHOUT_HEAD(nvlist_free_string__single_string);
1143 ATF_TEST_CASE_BODY(nvlist_free_string__single_string)
1144 {
1145         nvlist_t *nvl;
1146         const char *key;
1147
1148         nvl = nvlist_create(0);
1149         key = "test";
1150         nvlist_add_string(nvl, key, "gjkfkjd");
1151
1152         nvlist_free_string(nvl, key);
1153         ATF_REQUIRE(nvlist_empty(nvl));
1154
1155         nvlist_destroy(nvl);
1156 }
1157
1158 ATF_TEST_CASE_WITHOUT_HEAD(nvlist_free_nvlist__single_nvlist);
1159 ATF_TEST_CASE_BODY(nvlist_free_nvlist__single_nvlist)
1160 {
1161         nvlist_t *nvl;
1162         const char *key;
1163
1164         nvl = nvlist_create(0);
1165         key = "test";
1166         nvlist_add_nvlist(nvl, key, nvlist_create(0));
1167
1168         nvlist_free_nvlist(nvl, key);
1169         ATF_REQUIRE(nvlist_empty(nvl));
1170
1171         nvlist_destroy(nvl);
1172 }
1173
1174 ATF_TEST_CASE_WITHOUT_HEAD(nvlist_free_binary__single_binary);
1175 ATF_TEST_CASE_BODY(nvlist_free_binary__single_binary)
1176 {
1177         nvlist_t *nvl;
1178         const char *key;
1179
1180         nvl = nvlist_create(0);
1181         key = "test";
1182         nvlist_add_binary(nvl, key, "jgjgfd", 6);
1183
1184         nvlist_free_binary(nvl, key);
1185         ATF_REQUIRE(nvlist_empty(nvl));
1186
1187         nvlist_destroy(nvl);
1188 }
1189
1190 ATF_INIT_TEST_CASES(tp)
1191 {
1192         ATF_ADD_TEST_CASE(tp, nvlist_create__is_empty);
1193         ATF_ADD_TEST_CASE(tp, nvlist_add_null__single_insert);
1194         ATF_ADD_TEST_CASE(tp, nvlist_add_bool__single_insert);
1195         ATF_ADD_TEST_CASE(tp, nvlist_add_number__single_insert);
1196         ATF_ADD_TEST_CASE(tp, nvlist_add_string__single_insert);
1197         ATF_ADD_TEST_CASE(tp, nvlist_add_nvlist__single_insert);
1198         ATF_ADD_TEST_CASE(tp, nvlist_add_nvlist__child_with_error);
1199         ATF_ADD_TEST_CASE(tp, nvlist_add_binary__single_insert);
1200
1201         ATF_ADD_TEST_CASE(tp, nvlist_clone__empty_nvlist);
1202         ATF_ADD_TEST_CASE(tp, nvlist_clone__nonempty_nvlist);
1203         ATF_ADD_TEST_CASE(tp, nvlist_clone__nested_nvlist);
1204         ATF_ADD_TEST_CASE(tp, nvlist_clone__error_nvlist);
1205
1206         ATF_ADD_TEST_CASE(tp, nvlist_pack__empty_nvlist);
1207         ATF_ADD_TEST_CASE(tp, nvlist_pack__multiple_values);
1208         ATF_ADD_TEST_CASE(tp, nvlist_pack__error_nvlist);
1209         ATF_ADD_TEST_CASE(tp, nvlist_unpack__duplicate_key);
1210
1211         ATF_ADD_TEST_CASE(tp, nvlist_move_string__single_insert);
1212         ATF_ADD_TEST_CASE(tp, nvlist_move_nvlist__single_insert);
1213         ATF_ADD_TEST_CASE(tp, nvlist_move_nvlist__null_child);
1214         ATF_ADD_TEST_CASE(tp, nvlist_move_nvlist__child_with_error);
1215         ATF_ADD_TEST_CASE(tp, nvlist_move_binary__single_insert);
1216
1217         ATF_ADD_TEST_CASE(tp, nvlist_take_bool__single_remove);
1218         ATF_ADD_TEST_CASE(tp, nvlist_take_bool__other_keys_unchanged);
1219         ATF_ADD_TEST_CASE(tp, nvlist_take_number__single_remove);
1220         ATF_ADD_TEST_CASE(tp, nvlist_take_number__other_keys_unchanged);
1221         ATF_ADD_TEST_CASE(tp, nvlist_take_string__single_remove);
1222         ATF_ADD_TEST_CASE(tp, nvlist_take_string__other_keys_unchanged);
1223         ATF_ADD_TEST_CASE(tp, nvlist_take_nvlist__single_remove);
1224         ATF_ADD_TEST_CASE(tp, nvlist_take_nvlist__other_keys_unchanged);
1225         ATF_ADD_TEST_CASE(tp, nvlist_take_binary__single_remove);
1226         ATF_ADD_TEST_CASE(tp, nvlist_take_binary__other_keys_unchanged);
1227
1228         ATF_ADD_TEST_CASE(tp, nvlist_free__single_null);
1229         ATF_ADD_TEST_CASE(tp, nvlist_free__single_bool);
1230         ATF_ADD_TEST_CASE(tp, nvlist_free__single_number);
1231         ATF_ADD_TEST_CASE(tp, nvlist_free__single_string);
1232         ATF_ADD_TEST_CASE(tp, nvlist_free__single_nvlist);
1233         ATF_ADD_TEST_CASE(tp, nvlist_free__single_binary);
1234
1235         ATF_ADD_TEST_CASE(tp, nvlist_free_null__single_null);
1236         ATF_ADD_TEST_CASE(tp, nvlist_free_bool__single_bool);
1237         ATF_ADD_TEST_CASE(tp, nvlist_free_number__single_number);
1238         ATF_ADD_TEST_CASE(tp, nvlist_free_string__single_string);
1239         ATF_ADD_TEST_CASE(tp, nvlist_free_nvlist__single_nvlist);
1240         ATF_ADD_TEST_CASE(tp, nvlist_free_binary__single_binary);
1241 }