]> CyberLeo.Net >> Repos - FreeBSD/releng/10.3.git/blob - lib/libnv/tests/nv_tests.cc
- Copy stable/10@296371 to releng/10.3 in preparation for 10.3-RC1
[FreeBSD/releng/10.3.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
609         /*
610          * Mangle the packed nvlist by replacing key1 with key2, creating a
611          * packed nvlist with a duplicate key.
612          */
613         keypos = memmem(packed, size, key1, keylen);
614         ATF_REQUIRE(keypos != NULL);
615         memcpy(keypos, key2, keylen);
616
617         unpacked = nvlist_unpack(packed, size);
618         ATF_REQUIRE(nvlist_error(unpacked) != 0);
619
620         free(packed);
621         nvlist_destroy(nvl);
622         nvlist_destroy(unpacked);
623 }
624
625 ATF_TEST_CASE_WITHOUT_HEAD(nvlist_move_string__single_insert);
626 ATF_TEST_CASE_BODY(nvlist_move_string__single_insert)
627 {
628         nvlist_t *nvl;
629         const char *key;
630         char *value;
631
632         nvl = nvlist_create(0);
633         ATF_REQUIRE(nvl != NULL);
634
635         key = "testkey";
636         value = strdup("testval");
637         ATF_REQUIRE(value != NULL);
638
639         nvlist_move_string(nvl, key, value);
640         ATF_REQUIRE_EQ(nvlist_get_string(nvl, key), value);
641
642         nvlist_destroy(nvl);
643 }
644
645 ATF_TEST_CASE_WITHOUT_HEAD(nvlist_move_nvlist__null_child);
646 ATF_TEST_CASE_BODY(nvlist_move_nvlist__null_child)
647 {
648         nvlist_t *parent;
649
650         parent = nvlist_create(0);
651
652         nvlist_move_nvlist(parent, "test", NULL);
653
654         ATF_REQUIRE(nvlist_error(parent) != 0);
655
656         nvlist_destroy(parent);
657 }
658
659 ATF_TEST_CASE_WITHOUT_HEAD(nvlist_move_nvlist__child_with_error);
660 ATF_TEST_CASE_BODY(nvlist_move_nvlist__child_with_error)
661 {
662         nvlist_t *nvl, *parent;
663
664         nvl = nvlist_create(0);
665         parent = nvlist_create(0);
666
667         nvlist_set_error(nvl, EBADF);
668         nvlist_move_nvlist(parent, "test", nvl);
669         ATF_REQUIRE_EQ(nvlist_error(parent), EBADF);
670
671         nvlist_destroy(parent);
672 }
673
674 ATF_TEST_CASE_WITHOUT_HEAD(nvlist_move_nvlist__single_insert);
675 ATF_TEST_CASE_BODY(nvlist_move_nvlist__single_insert)
676 {
677         nvlist_t *nvl;
678         const char *key;
679         nvlist_t *value;
680
681         nvl = nvlist_create(0);
682         ATF_REQUIRE(nvl != NULL);
683
684         key = "testkey";
685         value = nvlist_create(0);
686         ATF_REQUIRE(value != NULL);
687
688         nvlist_move_nvlist(nvl, key, value);
689         ATF_REQUIRE_EQ(nvlist_get_nvlist(nvl, key), value);
690
691         nvlist_destroy(nvl);
692 }
693
694 ATF_TEST_CASE_WITHOUT_HEAD(nvlist_move_binary__single_insert);
695 ATF_TEST_CASE_BODY(nvlist_move_binary__single_insert)
696 {
697         nvlist_t *nvl;
698         const char *key;
699         void *value;
700         size_t size, actual_size;
701
702         nvl = nvlist_create(0);
703         ATF_REQUIRE(nvl != NULL);
704
705         key = "testkey";
706         size = 73;
707         value = malloc(size);
708         ATF_REQUIRE(value != NULL);
709
710         nvlist_move_binary(nvl, key, value, size);
711         ATF_REQUIRE_EQ(nvlist_get_binary(nvl, key, &actual_size), value);
712         ATF_REQUIRE_EQ(size, actual_size);
713
714         nvlist_destroy(nvl);
715 }
716
717 ATF_TEST_CASE_WITHOUT_HEAD(nvlist_take_bool__single_remove);
718 ATF_TEST_CASE_BODY(nvlist_take_bool__single_remove)
719 {
720         nvlist_t *nvl;
721         const char *testkey;
722         bool testval;
723
724         nvl = nvlist_create(0);
725         ATF_REQUIRE(nvl != NULL);
726
727         testkey = "boolkey";
728         testval = false;
729         nvlist_add_bool(nvl, testkey, testval);
730
731         ATF_REQUIRE_EQ(nvlist_take_bool(nvl, testkey), testval);
732         ATF_REQUIRE(nvlist_empty(nvl));
733
734         nvlist_destroy(nvl);
735 }
736
737 ATF_TEST_CASE_WITHOUT_HEAD(nvlist_take_bool__other_keys_unchanged);
738 ATF_TEST_CASE_BODY(nvlist_take_bool__other_keys_unchanged)
739 {
740         nvlist_t *nvl;
741         const char *testkey, *otherkey1, *otherkey2;
742         bool testval, otherval1;
743         nvlist_t *otherval2;
744
745         nvl = nvlist_create(0);
746         ATF_REQUIRE(nvl != NULL);
747
748         testkey = "boolkey";
749         testval = true;
750         nvlist_add_bool(nvl, testkey, testval);
751
752         otherkey1 = "key1";
753         otherval1 = false;
754         nvlist_add_bool(nvl, otherkey1, otherval1);
755
756         otherkey2 = "key2";
757         otherval2 = create_test_nvlist();
758         nvlist_move_nvlist(nvl, otherkey2, otherval2);
759
760         ATF_REQUIRE_EQ(nvlist_take_bool(nvl, testkey), testval);
761
762         ATF_REQUIRE(nvlist_exists_bool(nvl, otherkey1));
763         ATF_REQUIRE_EQ(nvlist_get_bool(nvl, otherkey1), otherval1);
764
765         ATF_REQUIRE(nvlist_exists_nvlist(nvl, otherkey2));
766         verify_test_nvlist(nvlist_get_nvlist(nvl, otherkey2));
767
768         nvlist_destroy(nvl);
769 }
770
771 ATF_TEST_CASE_WITHOUT_HEAD(nvlist_take_number__single_remove);
772 ATF_TEST_CASE_BODY(nvlist_take_number__single_remove)
773 {
774         nvlist_t *nvl;
775         const char *testkey;
776         uint64_t testval;
777
778         nvl = nvlist_create(0);
779         ATF_REQUIRE(nvl != NULL);
780
781         testkey = "numkey";
782         testval = std::numeric_limits<uint64_t>::max();
783         nvlist_add_number(nvl, testkey, testval);
784
785         ATF_REQUIRE_EQ(nvlist_take_number(nvl, testkey), testval);
786         ATF_REQUIRE(nvlist_empty(nvl));
787
788         nvlist_destroy(nvl);
789 }
790
791 ATF_TEST_CASE_WITHOUT_HEAD(nvlist_take_number__other_keys_unchanged);
792 ATF_TEST_CASE_BODY(nvlist_take_number__other_keys_unchanged)
793 {
794         nvlist_t *nvl;
795         const char *testkey, *otherkey1, *otherkey2;
796         uint64_t testval, otherval1;
797         const char *otherval2;
798
799         nvl = nvlist_create(0);
800         ATF_REQUIRE(nvl != NULL);
801
802         otherkey1 = "key1";
803         otherval1 = 5;
804         nvlist_add_number(nvl, otherkey1, otherval1);
805
806         testkey = "numkey";
807         testval = 1654;
808         nvlist_add_number(nvl, testkey, testval);
809
810         otherkey2 = "key2";
811         otherval2 = "string";
812         nvlist_add_string(nvl, otherkey2, otherval2);
813
814         ATF_REQUIRE_EQ(nvlist_take_number(nvl, testkey), testval);
815
816         ATF_REQUIRE(nvlist_exists_number(nvl, otherkey1));
817         ATF_REQUIRE_EQ(nvlist_get_number(nvl, otherkey1), otherval1);
818
819         ATF_REQUIRE(nvlist_exists_string(nvl, otherkey2));
820         ATF_REQUIRE_EQ(strcmp(nvlist_get_string(nvl, otherkey2), otherval2), 0);
821
822         nvlist_destroy(nvl);
823 }
824
825 ATF_TEST_CASE_WITHOUT_HEAD(nvlist_take_string__single_remove);
826 ATF_TEST_CASE_BODY(nvlist_take_string__single_remove)
827 {
828         nvlist_t *nvl;
829         const char *testkey;
830         const char *testval;
831
832         nvl = nvlist_create(0);
833         ATF_REQUIRE(nvl != NULL);
834
835         testkey = "numkey";
836         testval = "nvlist";
837         nvlist_add_string(nvl, testkey, testval);
838
839         ATF_REQUIRE_EQ(strcmp(nvlist_take_string(nvl, testkey), testval), 0);
840         ATF_REQUIRE(nvlist_empty(nvl));
841
842         nvlist_destroy(nvl);
843 }
844
845 ATF_TEST_CASE_WITHOUT_HEAD(nvlist_take_string__other_keys_unchanged);
846 ATF_TEST_CASE_BODY(nvlist_take_string__other_keys_unchanged)
847 {
848         nvlist_t *nvl;
849         const char *testkey, *otherkey1, *otherkey2;
850         const char *testval, *otherval1;
851         bool otherval2;
852
853         nvl = nvlist_create(0);
854         ATF_REQUIRE(nvl != NULL);
855
856         otherkey1 = "key1";
857         otherval1 = "fjdifjdk";
858         nvlist_add_string(nvl, otherkey1, otherval1);
859
860         otherkey2 = "key2";
861         otherval2 = true;
862         nvlist_add_bool(nvl, otherkey2, otherval2);
863
864         testkey = "strkey";
865         testval = "1654";
866         nvlist_add_string(nvl, testkey, testval);
867
868         ATF_REQUIRE_EQ(strcmp(nvlist_take_string(nvl, testkey), testval), 0);
869
870         ATF_REQUIRE(nvlist_exists_string(nvl, otherkey1));
871         ATF_REQUIRE_EQ(strcmp(nvlist_get_string(nvl, otherkey1), otherval1), 0);
872
873         ATF_REQUIRE(nvlist_exists_bool(nvl, otherkey2));
874         ATF_REQUIRE_EQ(nvlist_get_bool(nvl, otherkey2), otherval2);
875
876         nvlist_destroy(nvl);
877 }
878
879 ATF_TEST_CASE_WITHOUT_HEAD(nvlist_take_nvlist__single_remove);
880 ATF_TEST_CASE_BODY(nvlist_take_nvlist__single_remove)
881 {
882         nvlist_t *nvl;
883         const char *testkey;
884         nvlist_t *testval;
885
886         nvl = nvlist_create(0);
887         ATF_REQUIRE(nvl != NULL);
888
889         testkey = "numkey";
890         testval = create_test_nvlist();
891         nvlist_move_nvlist(nvl, testkey, testval);
892
893         verify_test_nvlist(nvlist_take_nvlist(nvl, testkey));
894         ATF_REQUIRE(nvlist_empty(nvl));
895
896         nvlist_destroy(nvl);
897 }
898
899 ATF_TEST_CASE_WITHOUT_HEAD(nvlist_take_nvlist__other_keys_unchanged);
900 ATF_TEST_CASE_BODY(nvlist_take_nvlist__other_keys_unchanged)
901 {
902         nvlist_t *nvl;
903         const char *testkey, *otherkey1, *otherkey2;
904         nvlist_t *testval, *otherval1;
905
906         nvl = nvlist_create(0);
907         ATF_REQUIRE(nvl != NULL);
908
909         testkey = "strkey";
910         testval = create_test_nvlist();
911         nvlist_move_nvlist(nvl, testkey, testval);
912
913         otherkey1 = "key1";
914         otherval1 = nvlist_create(0);
915         nvlist_move_nvlist(nvl, otherkey1, otherval1);
916
917         otherkey2 = "key2";
918         nvlist_add_null(nvl, otherkey2);
919
920         verify_test_nvlist(nvlist_take_nvlist(nvl, testkey));
921
922         ATF_REQUIRE(nvlist_exists_nvlist(nvl, otherkey1));
923         ATF_REQUIRE(nvlist_empty(nvlist_get_nvlist(nvl, otherkey1)));
924
925         ATF_REQUIRE(nvlist_exists_null(nvl, otherkey2));
926
927         nvlist_destroy(nvl);
928 }
929
930 ATF_TEST_CASE_WITHOUT_HEAD(nvlist_take_binary__single_remove);
931 ATF_TEST_CASE_BODY(nvlist_take_binary__single_remove)
932 {
933         nvlist_t *nvl;
934         const char *testkey;
935         void *testval;
936         const void *actual_val;
937         size_t testsize, actual_size;
938
939         nvl = nvlist_create(0);
940         ATF_REQUIRE(nvl != NULL);
941
942         testkey = "numkey";
943         testsize = 457;
944         testval = malloc(testsize);
945         memset(testval, '5', testsize);
946         nvlist_move_binary(nvl, testkey, testval, testsize);
947
948         actual_val = nvlist_take_binary(nvl, testkey, &actual_size);
949         ATF_REQUIRE_EQ(testsize, actual_size);
950         ATF_REQUIRE_EQ(memcmp(actual_val, testval, testsize), 0);
951         ATF_REQUIRE(nvlist_empty(nvl));
952
953         nvlist_destroy(nvl);
954 }
955
956 ATF_TEST_CASE_WITHOUT_HEAD(nvlist_take_binary__other_keys_unchanged);
957 ATF_TEST_CASE_BODY(nvlist_take_binary__other_keys_unchanged)
958 {
959         nvlist_t *nvl;
960         const char *testkey, *otherkey1, *otherkey2;
961         const void *actual_value;
962         char testval[] = "gjiertj";
963         char otherval1[] = "fdreg";
964         size_t testsize, othersize, actual_size;
965         bool otherval2;
966
967         nvl = nvlist_create(0);
968         ATF_REQUIRE(nvl != NULL);
969
970         otherkey1 = "key1";
971         othersize = sizeof(otherval1);
972         nvlist_add_binary(nvl, otherkey1, otherval1, othersize);
973
974         otherkey2 = "key2";
975         otherval2 = true;
976         nvlist_add_bool(nvl, otherkey2, otherval2);
977
978         testkey = "strkey";
979         testsize = sizeof(testval);
980         nvlist_add_binary(nvl, testkey, testval, testsize);
981
982         actual_value = nvlist_take_binary(nvl, testkey, &actual_size);
983         ATF_REQUIRE_EQ(testsize, actual_size);
984         ATF_REQUIRE_EQ(memcmp(actual_value, testval, testsize), 0);
985
986         ATF_REQUIRE(nvlist_exists_binary(nvl, otherkey1));
987         actual_value = nvlist_get_binary(nvl, otherkey1, &actual_size);
988         ATF_REQUIRE_EQ(othersize, actual_size);
989         ATF_REQUIRE_EQ(memcmp(actual_value, otherval1, othersize), 0);
990
991         ATF_REQUIRE(nvlist_exists_bool(nvl, otherkey2));
992         ATF_REQUIRE_EQ(nvlist_get_bool(nvl, otherkey2), otherval2);
993
994         nvlist_destroy(nvl);
995 }
996
997 ATF_TEST_CASE_WITHOUT_HEAD(nvlist_free__single_null);
998 ATF_TEST_CASE_BODY(nvlist_free__single_null)
999 {
1000         nvlist_t *nvl;
1001         const char *key;
1002
1003         nvl = nvlist_create(0);
1004         key = "test";
1005         nvlist_add_null(nvl, key);
1006
1007         nvlist_free(nvl, key);
1008         ATF_REQUIRE(nvlist_empty(nvl));
1009
1010         nvlist_destroy(nvl);
1011 }
1012
1013 ATF_TEST_CASE_WITHOUT_HEAD(nvlist_free__single_bool);
1014 ATF_TEST_CASE_BODY(nvlist_free__single_bool)
1015 {
1016         nvlist_t *nvl;
1017         const char *key;
1018
1019         nvl = nvlist_create(0);
1020         key = "test";
1021         nvlist_add_bool(nvl, key, true);
1022
1023         nvlist_free(nvl, key);
1024         ATF_REQUIRE(nvlist_empty(nvl));
1025
1026         nvlist_destroy(nvl);
1027 }
1028
1029 ATF_TEST_CASE_WITHOUT_HEAD(nvlist_free__single_number);
1030 ATF_TEST_CASE_BODY(nvlist_free__single_number)
1031 {
1032         nvlist_t *nvl;
1033         const char *key;
1034
1035         nvl = nvlist_create(0);
1036         key = "test";
1037         nvlist_add_number(nvl, key, 584);
1038
1039         nvlist_free(nvl, key);
1040         ATF_REQUIRE(nvlist_empty(nvl));
1041
1042         nvlist_destroy(nvl);
1043 }
1044
1045 ATF_TEST_CASE_WITHOUT_HEAD(nvlist_free__single_string);
1046 ATF_TEST_CASE_BODY(nvlist_free__single_string)
1047 {
1048         nvlist_t *nvl;
1049         const char *key;
1050
1051         nvl = nvlist_create(0);
1052         key = "test";
1053         nvlist_add_string(nvl, key, "gjkfkjd");
1054
1055         nvlist_free(nvl, key);
1056         ATF_REQUIRE(nvlist_empty(nvl));
1057
1058         nvlist_destroy(nvl);
1059 }
1060
1061 ATF_TEST_CASE_WITHOUT_HEAD(nvlist_free__single_nvlist);
1062 ATF_TEST_CASE_BODY(nvlist_free__single_nvlist)
1063 {
1064         nvlist_t *nvl;
1065         const char *key;
1066
1067         nvl = nvlist_create(0);
1068         key = "test";
1069         nvlist_add_nvlist(nvl, key, nvlist_create(0));
1070
1071         nvlist_free(nvl, key);
1072         ATF_REQUIRE(nvlist_empty(nvl));
1073
1074         nvlist_destroy(nvl);
1075 }
1076
1077 ATF_TEST_CASE_WITHOUT_HEAD(nvlist_free__single_binary);
1078 ATF_TEST_CASE_BODY(nvlist_free__single_binary)
1079 {
1080         nvlist_t *nvl;
1081         const char *key;
1082
1083         nvl = nvlist_create(0);
1084         key = "test";
1085         nvlist_add_binary(nvl, key, "jgjgfd", 6);
1086
1087         nvlist_free(nvl, key);
1088         ATF_REQUIRE(nvlist_empty(nvl));
1089
1090         nvlist_destroy(nvl);
1091 }
1092
1093 ATF_TEST_CASE_WITHOUT_HEAD(nvlist_free_null__single_null);
1094 ATF_TEST_CASE_BODY(nvlist_free_null__single_null)
1095 {
1096         nvlist_t *nvl;
1097         const char *key;
1098
1099         nvl = nvlist_create(0);
1100         key = "test";
1101         nvlist_add_null(nvl, key);
1102
1103         nvlist_free_null(nvl, key);
1104         ATF_REQUIRE(nvlist_empty(nvl));
1105
1106         nvlist_destroy(nvl);
1107 }
1108
1109 ATF_TEST_CASE_WITHOUT_HEAD(nvlist_free_bool__single_bool);
1110 ATF_TEST_CASE_BODY(nvlist_free_bool__single_bool)
1111 {
1112         nvlist_t *nvl;
1113         const char *key;
1114
1115         nvl = nvlist_create(0);
1116         key = "test";
1117         nvlist_add_bool(nvl, key, true);
1118
1119         nvlist_free_bool(nvl, key);
1120         ATF_REQUIRE(nvlist_empty(nvl));
1121
1122         nvlist_destroy(nvl);
1123 }
1124
1125 ATF_TEST_CASE_WITHOUT_HEAD(nvlist_free_number__single_number);
1126 ATF_TEST_CASE_BODY(nvlist_free_number__single_number)
1127 {
1128         nvlist_t *nvl;
1129         const char *key;
1130
1131         nvl = nvlist_create(0);
1132         key = "test";
1133         nvlist_add_number(nvl, key, 584);
1134
1135         nvlist_free_number(nvl, key);
1136         ATF_REQUIRE(nvlist_empty(nvl));
1137
1138         nvlist_destroy(nvl);
1139 }
1140
1141 ATF_TEST_CASE_WITHOUT_HEAD(nvlist_free_string__single_string);
1142 ATF_TEST_CASE_BODY(nvlist_free_string__single_string)
1143 {
1144         nvlist_t *nvl;
1145         const char *key;
1146
1147         nvl = nvlist_create(0);
1148         key = "test";
1149         nvlist_add_string(nvl, key, "gjkfkjd");
1150
1151         nvlist_free_string(nvl, key);
1152         ATF_REQUIRE(nvlist_empty(nvl));
1153
1154         nvlist_destroy(nvl);
1155 }
1156
1157 ATF_TEST_CASE_WITHOUT_HEAD(nvlist_free_nvlist__single_nvlist);
1158 ATF_TEST_CASE_BODY(nvlist_free_nvlist__single_nvlist)
1159 {
1160         nvlist_t *nvl;
1161         const char *key;
1162
1163         nvl = nvlist_create(0);
1164         key = "test";
1165         nvlist_add_nvlist(nvl, key, nvlist_create(0));
1166
1167         nvlist_free_nvlist(nvl, key);
1168         ATF_REQUIRE(nvlist_empty(nvl));
1169
1170         nvlist_destroy(nvl);
1171 }
1172
1173 ATF_TEST_CASE_WITHOUT_HEAD(nvlist_free_binary__single_binary);
1174 ATF_TEST_CASE_BODY(nvlist_free_binary__single_binary)
1175 {
1176         nvlist_t *nvl;
1177         const char *key;
1178
1179         nvl = nvlist_create(0);
1180         key = "test";
1181         nvlist_add_binary(nvl, key, "jgjgfd", 6);
1182
1183         nvlist_free_binary(nvl, key);
1184         ATF_REQUIRE(nvlist_empty(nvl));
1185
1186         nvlist_destroy(nvl);
1187 }
1188
1189 ATF_INIT_TEST_CASES(tp)
1190 {
1191         ATF_ADD_TEST_CASE(tp, nvlist_create__is_empty);
1192         ATF_ADD_TEST_CASE(tp, nvlist_add_null__single_insert);
1193         ATF_ADD_TEST_CASE(tp, nvlist_add_bool__single_insert);
1194         ATF_ADD_TEST_CASE(tp, nvlist_add_number__single_insert);
1195         ATF_ADD_TEST_CASE(tp, nvlist_add_string__single_insert);
1196         ATF_ADD_TEST_CASE(tp, nvlist_add_nvlist__single_insert);
1197         ATF_ADD_TEST_CASE(tp, nvlist_add_nvlist__child_with_error);
1198         ATF_ADD_TEST_CASE(tp, nvlist_add_binary__single_insert);
1199
1200         ATF_ADD_TEST_CASE(tp, nvlist_clone__empty_nvlist);
1201         ATF_ADD_TEST_CASE(tp, nvlist_clone__nonempty_nvlist);
1202         ATF_ADD_TEST_CASE(tp, nvlist_clone__nested_nvlist);
1203         ATF_ADD_TEST_CASE(tp, nvlist_clone__error_nvlist);
1204
1205         ATF_ADD_TEST_CASE(tp, nvlist_pack__empty_nvlist);
1206         ATF_ADD_TEST_CASE(tp, nvlist_pack__multiple_values);
1207         ATF_ADD_TEST_CASE(tp, nvlist_pack__error_nvlist);
1208         ATF_ADD_TEST_CASE(tp, nvlist_unpack__duplicate_key);
1209
1210         ATF_ADD_TEST_CASE(tp, nvlist_move_string__single_insert);
1211         ATF_ADD_TEST_CASE(tp, nvlist_move_nvlist__single_insert);
1212         ATF_ADD_TEST_CASE(tp, nvlist_move_nvlist__null_child);
1213         ATF_ADD_TEST_CASE(tp, nvlist_move_nvlist__child_with_error);
1214         ATF_ADD_TEST_CASE(tp, nvlist_move_binary__single_insert);
1215
1216         ATF_ADD_TEST_CASE(tp, nvlist_take_bool__single_remove);
1217         ATF_ADD_TEST_CASE(tp, nvlist_take_bool__other_keys_unchanged);
1218         ATF_ADD_TEST_CASE(tp, nvlist_take_number__single_remove);
1219         ATF_ADD_TEST_CASE(tp, nvlist_take_number__other_keys_unchanged);
1220         ATF_ADD_TEST_CASE(tp, nvlist_take_string__single_remove);
1221         ATF_ADD_TEST_CASE(tp, nvlist_take_string__other_keys_unchanged);
1222         ATF_ADD_TEST_CASE(tp, nvlist_take_nvlist__single_remove);
1223         ATF_ADD_TEST_CASE(tp, nvlist_take_nvlist__other_keys_unchanged);
1224         ATF_ADD_TEST_CASE(tp, nvlist_take_binary__single_remove);
1225         ATF_ADD_TEST_CASE(tp, nvlist_take_binary__other_keys_unchanged);
1226
1227         ATF_ADD_TEST_CASE(tp, nvlist_free__single_null);
1228         ATF_ADD_TEST_CASE(tp, nvlist_free__single_bool);
1229         ATF_ADD_TEST_CASE(tp, nvlist_free__single_number);
1230         ATF_ADD_TEST_CASE(tp, nvlist_free__single_string);
1231         ATF_ADD_TEST_CASE(tp, nvlist_free__single_nvlist);
1232         ATF_ADD_TEST_CASE(tp, nvlist_free__single_binary);
1233
1234         ATF_ADD_TEST_CASE(tp, nvlist_free_null__single_null);
1235         ATF_ADD_TEST_CASE(tp, nvlist_free_bool__single_bool);
1236         ATF_ADD_TEST_CASE(tp, nvlist_free_number__single_number);
1237         ATF_ADD_TEST_CASE(tp, nvlist_free_string__single_string);
1238         ATF_ADD_TEST_CASE(tp, nvlist_free_nvlist__single_nvlist);
1239         ATF_ADD_TEST_CASE(tp, nvlist_free_binary__single_binary);
1240 }