1 /* $Id: t_ppath.c,v 1.1 2011/08/25 19:09:46 dyoung Exp $ */
3 /* Copyright (c) 2010 David Young. All rights reserved. */
6 __RCSID("$Id: t_ppath.c,v 1.1 2011/08/25 19:09:46 dyoung Exp $");
14 #include <ppath/ppath.h>
15 #include "personnel.h"
17 void test_ppath_extant_inc(void);
18 void test_ppath_extant_dec(void);
19 void test_ppath_component_extant_inc(void);
20 void test_ppath_component_extant_dec(void);
22 __strong_alias(ppath_extant_inc
, test_ppath_extant_inc
);
23 __strong_alias(ppath_extant_dec
, test_ppath_extant_dec
);
24 __strong_alias(ppath_component_extant_inc
, test_ppath_component_extant_inc
);
25 __strong_alias(ppath_component_extant_dec
, test_ppath_component_extant_dec
);
27 static uint64_t nppath
= 0, nppath_component
= 0;
30 dictionary_equals(prop_dictionary_t ld
, prop_dictionary_t rd
)
35 lt
= prop_dictionary_externalize(ld
);
36 rt
= prop_dictionary_externalize(rd
);
38 assert(lt
!= NULL
&& rt
!= NULL
);
40 eq
= (strcmp(lt
, rt
) == 0);
49 assert_no_ppath_extant(void)
51 ATF_CHECK_EQ(nppath
, 0);
55 assert_no_ppath_component_extant(void)
57 ATF_CHECK_EQ(nppath_component
, 0);
61 test_ppath_extant_inc(void)
64 atf_tc_fail("count of extant paths overflowed");
68 test_ppath_extant_dec(void)
71 atf_tc_fail("count of extant path underflowed");
75 test_ppath_component_extant_inc(void)
77 if (++nppath_component
== 0)
78 atf_tc_fail("count of extant path components overflowed");
82 test_ppath_component_extant_dec(void)
84 if (nppath_component
-- == 0)
85 atf_tc_fail("count of extant path components underflowed");
88 ATF_TC(push_until_full
);
90 ATF_TC_HEAD(push_until_full
, tc
)
92 atf_tc_set_md_var(tc
, "descr", "check ppath_push() returns error "
93 "after ppath_t reaches maximum length");
96 ATF_TC_BODY(push_until_full
, tc
)
99 ppath_component_t
*pc
;
102 assert_no_ppath_extant();
103 assert_no_ppath_component_extant();
105 if ((p
= ppath_create()) == NULL
)
106 atf_tc_fail("ppath_create failed");
108 if ((pc
= ppath_idx(0)) == NULL
)
109 atf_tc_fail("ppath_idx failed");
111 for (i
= 0; i
< PPATH_MAX_COMPONENTS
; i
++) {
112 rp
= ppath_push(p
, pc
);
116 rp
= ppath_push(p
, pc
);
117 ATF_CHECK_EQ(rp
, NULL
);
119 rp
= ppath_push(p
, pc
);
120 ATF_CHECK_EQ(rp
, NULL
);
122 ppath_component_release(pc
);
125 assert_no_ppath_extant();
126 assert_no_ppath_component_extant();
129 ATF_TC(pop_until_empty
);
130 ATF_TC_HEAD(pop_until_empty
, tc
)
132 atf_tc_set_md_var(tc
, "descr", "check ppath_pop() returns error "
133 "after ppath_t is empty");
136 ATF_TC_BODY(pop_until_empty
, tc
)
139 ppath_component_t
*pc
, *rpc
;
142 assert_no_ppath_extant();
143 assert_no_ppath_component_extant();
145 if ((p
= ppath_create()) == NULL
)
146 atf_tc_fail("ppath_create failed");
148 if ((pc
= ppath_idx(0)) == NULL
)
149 atf_tc_fail("ppath_idx failed");
151 for (i
= 0; i
< PPATH_MAX_COMPONENTS
; i
++) {
152 rp
= ppath_push(p
, pc
);
156 for (i
= 0; i
< PPATH_MAX_COMPONENTS
; i
++) {
157 rp
= ppath_pop(p
, &rpc
);
159 ATF_CHECK_EQ(rpc
, pc
);
160 ppath_component_release(rpc
);
163 rp
= ppath_pop(p
, &rpc
);
164 ATF_CHECK_EQ(rp
, NULL
);
165 rp
= ppath_pop(p
, &rpc
);
166 ATF_CHECK_EQ(rp
, NULL
);
168 ppath_component_release(pc
);
171 assert_no_ppath_extant();
172 assert_no_ppath_component_extant();
177 ATF_TC_HEAD(length
, tc
)
179 atf_tc_set_md_var(tc
, "descr", "check that ppath_push() "
180 "and ppath_pop() affect ppath_length() correctly");
183 ATF_TC_BODY(length
, tc
)
186 ppath_component_t
*pc
;
189 assert_no_ppath_extant();
190 assert_no_ppath_component_extant();
192 if ((p
= ppath_create()) == NULL
)
193 atf_tc_fail("ppath_create failed");
195 if ((pc
= ppath_idx(0)) == NULL
)
196 atf_tc_fail("ppath_idx failed");
198 for (i
= 0; i
< PPATH_MAX_COMPONENTS
; i
++) {
199 len
= ppath_length(p
);
200 ATF_CHECK_EQ(len
, i
);
201 rp
= ppath_push(p
, pc
);
205 for (i
= 0; i
< PPATH_MAX_COMPONENTS
; i
++) {
206 len
= ppath_length(p
);
207 ATF_CHECK_EQ(len
, PPATH_MAX_COMPONENTS
- i
);
208 rp
= ppath_pop(p
, NULL
);
211 ppath_component_release(pc
);
214 assert_no_ppath_extant();
215 assert_no_ppath_component_extant();
218 ATF_TC(component_at
);
220 ATF_TC_HEAD(component_at
, tc
)
222 atf_tc_set_md_var(tc
, "descr", "check that ppath_component_at() "
223 "returns the expected component");
226 ATF_TC_BODY(component_at
, tc
)
229 ppath_component_t
*pc
;
232 assert_no_ppath_extant();
233 assert_no_ppath_component_extant();
235 if ((p
= ppath_create()) == NULL
)
236 atf_tc_fail("ppath_create failed");
238 for (i
= 0; i
< PPATH_MAX_COMPONENTS
; i
++) {
239 if ((pc
= ppath_idx(i
)) == NULL
)
240 atf_tc_fail("ppath_idx failed");
241 rp
= ppath_push(p
, pc
);
242 ppath_component_release(pc
);
246 for (i
= 0; i
< PPATH_MAX_COMPONENTS
; i
++) {
247 pc
= ppath_component_at(p
, i
);
248 ATF_CHECK_EQ(ppath_component_idx(pc
), (int)i
);
249 ppath_component_release(pc
);
253 assert_no_ppath_extant();
254 assert_no_ppath_component_extant();
259 ATF_TC_HEAD(get_idx_key
, tc
)
261 atf_tc_set_md_var(tc
, "descr", "check that ppath_component_idx() "
262 "and ppath_component_key() return -1 and NULL, respectively, if "
263 "the component is a key or an index, respectively.");
266 ATF_TC_BODY(get_idx_key
, tc
)
268 ppath_component_t
*idx
, *key
;
270 assert_no_ppath_extant();
271 assert_no_ppath_component_extant();
273 if ((idx
= ppath_idx(0)) == NULL
)
274 atf_tc_fail("ppath_idx failed");
275 if ((key
= ppath_key("key")) == NULL
)
276 atf_tc_fail("ppath_idx failed");
278 ATF_CHECK_EQ(ppath_component_key(idx
), NULL
);
279 ATF_CHECK_EQ(ppath_component_idx(key
), -1);
281 ppath_component_release(idx
);
282 ppath_component_release(key
);
284 assert_no_ppath_extant();
285 assert_no_ppath_component_extant();
290 ATF_TC_HEAD(ppath_copy
, tc
)
292 atf_tc_set_md_var(tc
, "descr", "check that ppath_copy() "
293 "creates an exact replica of a path, and that no "
294 "resources are leaked.");
297 ATF_TC_BODY(ppath_copy
, tc
)
299 ppath_component_t
*pc
, *cpc
;
300 ppath_t
*p
, *cp
, *rp
;
303 assert_no_ppath_extant();
304 assert_no_ppath_component_extant();
306 if ((p
= ppath_create()) == NULL
)
307 atf_tc_fail("ppath_create failed");
309 for (i
= 0; i
< PPATH_MAX_COMPONENTS
; i
++) {
310 if ((pc
= ppath_idx(i
)) == NULL
)
311 atf_tc_fail("ppath_idx failed");
312 rp
= ppath_push(p
, pc
);
313 ppath_component_release(pc
);
317 if ((cp
= ppath_copy(p
)) == NULL
)
318 atf_tc_fail("ppath_copy failed");
320 for (i
= 0; i
< PPATH_MAX_COMPONENTS
; i
++) {
321 pc
= ppath_component_at(p
, i
);
322 cpc
= ppath_component_at(cp
, i
);
323 ATF_CHECK_EQ(pc
, cpc
);
324 ppath_component_release(pc
);
325 ppath_component_release(cpc
);
331 assert_no_ppath_extant();
332 assert_no_ppath_component_extant();
337 ATF_TC_HEAD(replace
, tc
)
339 atf_tc_set_md_var(tc
, "descr", "check that ppath_replace_idx() "
340 "and ppath_replace_key() produce the paths we expect without "
341 "leaking resources.");
344 ATF_TC_BODY(replace
, tc
)
346 ppath_component_t
*pc
;
347 ppath_t
*p
, *cp
, *rp
;
350 assert_no_ppath_extant();
351 assert_no_ppath_component_extant();
353 if ((p
= ppath_create()) == NULL
)
354 atf_tc_fail("ppath_create failed");
356 /* index replacement fails on an empty path */
357 rp
= ppath_replace_idx(p
, 0);
358 ATF_CHECK_EQ(rp
, NULL
);
360 /* key replacement fails on an empty path */
361 rp
= ppath_replace_key(p
, "key");
362 ATF_CHECK_EQ(rp
, NULL
);
364 for (i
= 0; i
< PPATH_MAX_COMPONENTS
; i
++) {
365 if ((pc
= ppath_idx(i
)) == NULL
)
366 atf_tc_fail("ppath_idx failed");
367 rp
= ppath_push(p
, pc
);
368 ppath_component_release(pc
);
372 if ((cp
= ppath_copy(p
)) == NULL
)
373 atf_tc_fail("ppath_copy failed");
375 rp
= ppath_pop(cp
, NULL
);
376 ATF_CHECK_EQ(rp
, cp
);
377 rp
= ppath_push_key(cp
, "key");
378 ATF_CHECK_EQ(rp
, cp
);
380 ppath_replace_idx(p
, 0);
382 if ((pc
= ppath_component_at(p
, PPATH_MAX_COMPONENTS
- 1)) == NULL
)
383 atf_tc_fail("ppath_idx failed");
384 ATF_CHECK_EQ(ppath_component_idx(pc
), 0);
385 ppath_component_release(pc
);
387 for (i
= 0; i
< PPATH_MAX_COMPONENTS
- 1; i
++) {
388 if ((pc
= ppath_component_at(p
, i
)) == NULL
)
389 atf_tc_fail("ppath_idx failed");
390 ATF_CHECK_EQ(ppath_component_idx(pc
), (int)i
);
391 ppath_component_release(pc
);
394 for (i
= 0; i
< PPATH_MAX_COMPONENTS
- 1; i
++) {
395 if ((pc
= ppath_component_at(cp
, i
)) == NULL
)
396 atf_tc_fail("ppath_idx failed");
397 ATF_CHECK_EQ(ppath_component_idx(pc
), (int)i
);
398 ppath_component_release(pc
);
401 if ((pc
= ppath_component_at(cp
, PPATH_MAX_COMPONENTS
- 1)) == NULL
)
402 atf_tc_fail("ppath_idx failed");
403 if (ppath_component_key(pc
) == NULL
||
404 strcmp(ppath_component_key(pc
), "key") != 0)
405 atf_tc_fail("last path component expected to be \"key\"");
406 ppath_component_release(pc
);
410 assert_no_ppath_extant();
411 assert_no_ppath_component_extant();
414 ATF_TC(copyset_object_twice_success
);
416 ATF_TC_HEAD(copyset_object_twice_success
, tc
)
418 atf_tc_set_md_var(tc
, "descr",
419 "check that after back-to-back ppath_copyset_object() calls, "
420 "changing the \"u.s. citizen\" property and the first property "
421 "in \"children\" in the \"John Doe\" record in the "
422 "\"personnel\" property list, the properties are changed "
423 "in the new dictionary and unchanged in the old dictionary");
426 ATF_TC_BODY(copyset_object_twice_success
, tc
)
432 prop_dictionary_t d
, od
;
433 prop_object_t nd
= NULL
, ond
;
435 ppath_t
*p
, *p2
, *p3
;
437 assert_no_ppath_extant();
438 assert_no_ppath_component_extant();
440 if ((d
= prop_dictionary_internalize(personnel
)) == NULL
)
441 atf_tc_fail("prop_dictionary_internalize failed");
442 od
= prop_dictionary_copy(d
);
444 if (!dictionary_equals(od
, d
)) {
445 oext
= prop_dictionary_externalize(od
);
446 next
= prop_dictionary_externalize(d
);
447 atf_tc_fail("dictionaries are unequal from the outset, argh! "
448 "original\n%s\nnew\n%s", oext
, next
);
453 if ((p
= ppath_create()) == NULL
|| (p2
= ppath_create()) == NULL
||
454 (p3
= ppath_create()) == NULL
)
455 atf_tc_fail("ppath_create failed");
457 if (ppath_push_key(p
, "John Doe") == NULL
)
458 atf_tc_fail("ppath_push_key failed");
459 if (ppath_push_key(p
, "u.s. citizen") == NULL
)
460 atf_tc_fail("ppath_push_key failed");
462 if (ppath_push_key(p2
, "John Doe") == NULL
)
463 atf_tc_fail("ppath_push_key failed");
464 if (ppath_push_key(p2
, "children") == NULL
)
465 atf_tc_fail("ppath_push_key failed");
466 if (ppath_push_idx(p2
, 0) == NULL
)
467 atf_tc_fail("ppath_push_idx failed");
469 if (ppath_push_key(p3
, "John Doe") == NULL
)
470 atf_tc_fail("ppath_push_key failed");
473 rc
= ppath_get_bool(d
, p
, &v
);
475 ATF_CHECK_EQ(v
, true);
478 rc
= ppath_get_string(d
, p2
, &s
);
480 ATF_CHECK_STREQ(s
, "Jane Doe");
482 rc
= ppath_copyset_bool(d
, &nd
, p
, false);
485 rc
= ppath_get_object(nd
, p3
, &r
);
490 rc
= ppath_copyset_string(d
, &nd
, p2
, "Martha Doe");
493 ATF_CHECK_EQ(nd
, ond
);
495 rc
= ppath_get_object(nd
, p3
, &or);
501 rc
= ppath_get_bool(nd
, p
, &v
);
503 ATF_CHECK_EQ(v
, false);
506 rc
= ppath_get_string(nd
, p2
, &s
);
508 ATF_CHECK_STREQ(s
, "Martha Doe");
510 if (!dictionary_equals(od
, d
)) {
511 oext
= prop_dictionary_externalize(od
);
512 next
= prop_dictionary_externalize(d
);
513 atf_tc_fail("copydel modified original dictionary, "
514 "original\n%s\nnew\n%s", oext
, next
);
519 if (dictionary_equals(od
, nd
)) {
520 oext
= prop_dictionary_externalize(od
);
521 next
= prop_dictionary_externalize(nd
);
522 atf_tc_fail("copydel made no change to the new "
523 "dictionary, original\n%s\nnew\n%s", oext
, next
);
528 rc
= ppath_set_bool(od
, p
, false);
531 rc
= ppath_set_string(od
, p2
, "Martha Doe");
534 if (!dictionary_equals(od
, nd
)) {
535 oext
= prop_dictionary_externalize(od
);
536 next
= prop_dictionary_externalize(nd
);
537 atf_tc_fail("copydel made an out-of-bounds change to the new "
538 "dictionary, original\n%s\nnew\n%s", oext
, next
);
546 prop_object_release(d
);
547 prop_object_release(od
);
548 prop_object_release(nd
);
549 assert_no_ppath_extant();
550 assert_no_ppath_component_extant();
553 ATF_TC(copydel_object_twice_success
);
555 ATF_TC_HEAD(copydel_object_twice_success
, tc
)
557 atf_tc_set_md_var(tc
, "descr",
558 "check that after back-to-back ppath_copydel_object() calls, "
559 "removing the \"u.s. citizen\" property and the first property "
560 "in \"children\" from the \"John Doe\" record in the "
561 "\"personnel\" property list, the properties are missing "
562 "from the new dictionary and unchanged in the old dictionary");
565 ATF_TC_BODY(copydel_object_twice_success
, tc
)
571 prop_dictionary_t d
, od
;
572 prop_object_t nd
= NULL
, ond
;
574 ppath_t
*p
, *p2
, *p3
;
576 assert_no_ppath_extant();
577 assert_no_ppath_component_extant();
579 if ((d
= prop_dictionary_internalize(personnel
)) == NULL
)
580 atf_tc_fail("prop_dictionary_internalize failed");
581 od
= prop_dictionary_copy(d
);
583 if (!dictionary_equals(od
, d
)) {
584 oext
= prop_dictionary_externalize(od
);
585 next
= prop_dictionary_externalize(d
);
586 atf_tc_fail("dictionaries are unequal from the outset, argh! "
587 "original\n%s\nnew\n%s", oext
, next
);
592 if ((p
= ppath_create()) == NULL
|| (p2
= ppath_create()) == NULL
||
593 (p3
= ppath_create()) == NULL
)
594 atf_tc_fail("ppath_create failed");
596 if (ppath_push_key(p
, "John Doe") == NULL
)
597 atf_tc_fail("ppath_push_key failed");
598 if (ppath_push_key(p
, "u.s. citizen") == NULL
)
599 atf_tc_fail("ppath_push_key failed");
601 if (ppath_push_key(p2
, "John Doe") == NULL
)
602 atf_tc_fail("ppath_push_key failed");
603 if (ppath_push_key(p2
, "children") == NULL
)
604 atf_tc_fail("ppath_push_key failed");
605 if (ppath_push_idx(p2
, 0) == NULL
)
606 atf_tc_fail("ppath_push_idx failed");
608 if (ppath_push_key(p3
, "John Doe") == NULL
)
609 atf_tc_fail("ppath_push_key failed");
612 rc
= ppath_get_bool(d
, p
, &v
);
614 ATF_CHECK_EQ(v
, true);
617 rc
= ppath_get_string(d
, p2
, &s
);
619 ATF_CHECK_STREQ(s
, "Jane Doe");
621 rc
= ppath_copydel_bool(d
, &nd
, p
);
626 rc
= ppath_get_object(nd
, p3
, &r
);
629 rc
= ppath_copydel_string(d
, &nd
, p2
);
632 ATF_CHECK_EQ(nd
, ond
);
634 rc
= ppath_get_object(nd
, p3
, &or);
640 rc
= ppath_get_bool(nd
, p
, &v
);
641 ATF_CHECK_EQ(rc
, ENOENT
);
642 ATF_CHECK_EQ(v
, true);
644 if (!dictionary_equals(od
, d
)) {
645 oext
= prop_dictionary_externalize(od
);
646 next
= prop_dictionary_externalize(d
);
647 atf_tc_fail("copydel modified original dictionary, "
648 "original\n%s\nnew\n%s", oext
, next
);
653 if (dictionary_equals(od
, nd
)) {
654 oext
= prop_dictionary_externalize(od
);
655 next
= prop_dictionary_externalize(nd
);
656 atf_tc_fail("copydel made no change to the new "
657 "dictionary, original\n%s\nnew\n%s", oext
, next
);
662 rc
= ppath_delete_bool(od
, p
);
665 rc
= ppath_delete_string(od
, p2
);
668 if (!dictionary_equals(od
, nd
)) {
669 oext
= prop_dictionary_externalize(od
);
670 next
= prop_dictionary_externalize(nd
);
671 atf_tc_fail("copydel made an out-of-bounds change to the new "
672 "dictionary, original\n%s\nnew\n%s", oext
, next
);
680 prop_object_release(d
);
681 prop_object_release(od
);
682 prop_object_release(nd
);
683 assert_no_ppath_extant();
684 assert_no_ppath_component_extant();
687 ATF_TC(copydel_bool_success
);
689 ATF_TC_HEAD(copydel_bool_success
, tc
)
691 atf_tc_set_md_var(tc
, "descr", "check ppath_copydel_bool() deletes "
692 "the \"u.s. citizen\" property in the \"John Doe\" record in the "
693 "\"personnel\" property list and verifies the value is missing "
694 "from the new dictionary and unchanged in the old dictionary");
697 ATF_TC_BODY(copydel_bool_success
, tc
)
702 prop_dictionary_t d
, od
;
703 prop_object_t nd
= NULL
;
706 assert_no_ppath_extant();
707 assert_no_ppath_component_extant();
709 if ((d
= prop_dictionary_internalize(personnel
)) == NULL
)
710 atf_tc_fail("prop_dictionary_internalize failed");
711 od
= prop_dictionary_copy(d
);
713 if (!dictionary_equals(od
, d
)) {
714 oext
= prop_dictionary_externalize(od
);
715 next
= prop_dictionary_externalize(d
);
716 atf_tc_fail("dictionaries are unequal from the outset, argh! "
717 "original\n%s\nnew\n%s", oext
, next
);
722 if ((p
= ppath_create()) == NULL
)
723 atf_tc_fail("ppath_create failed");
725 if (ppath_push_key(p
, "John Doe") == NULL
)
726 atf_tc_fail("ppath_push_key failed");
727 if (ppath_push_key(p
, "u.s. citizen") == NULL
)
728 atf_tc_fail("ppath_push_key failed");
731 rc
= ppath_get_bool(d
, p
, &v
);
733 ATF_CHECK_EQ(v
, true);
735 rc
= ppath_copydel_bool(d
, &nd
, p
);
739 rc
= ppath_get_bool(nd
, p
, &v
);
740 ATF_CHECK_EQ(rc
, ENOENT
);
741 ATF_CHECK_EQ(v
, true);
743 if (!dictionary_equals(od
, d
)) {
744 oext
= prop_dictionary_externalize(od
);
745 next
= prop_dictionary_externalize(d
);
746 atf_tc_fail("copydel modified original dictionary, "
747 "original\n%s\nnew\n%s", oext
, next
);
752 if (dictionary_equals(od
, nd
)) {
753 oext
= prop_dictionary_externalize(od
);
754 next
= prop_dictionary_externalize(nd
);
755 atf_tc_fail("copydel made no change to the new "
756 "dictionary, original\n%s\nnew\n%s", oext
, next
);
761 rc
= ppath_delete_bool(od
, p
);
764 if (!dictionary_equals(od
, nd
)) {
765 oext
= prop_dictionary_externalize(od
);
766 next
= prop_dictionary_externalize(nd
);
767 atf_tc_fail("copydel made an out-of-bounds change to the new "
768 "dictionary, original\n%s\nnew\n%s", oext
, next
);
774 prop_object_release(d
);
775 prop_object_release(od
);
776 prop_object_release(nd
);
777 assert_no_ppath_extant();
778 assert_no_ppath_component_extant();
781 ATF_TC(copyset_bool_success
);
783 ATF_TC_HEAD(copyset_bool_success
, tc
)
785 atf_tc_set_md_var(tc
, "descr", "check ppath_copyset_bool() sets "
786 "the \"u.s. citizen\" property in the \"John Doe\" record in the "
787 "\"personnel\" property list to false and verifies the new value "
788 "in the new dictionary and that the old dictionary is unchanged");
791 ATF_TC_BODY(copyset_bool_success
, tc
)
796 prop_dictionary_t d
, od
;
797 prop_object_t nd
= NULL
;
800 assert_no_ppath_extant();
801 assert_no_ppath_component_extant();
803 if ((d
= prop_dictionary_internalize(personnel
)) == NULL
)
804 atf_tc_fail("prop_dictionary_internalize failed");
805 od
= prop_dictionary_copy(d
);
807 if (!dictionary_equals(od
, d
)) {
808 oext
= prop_dictionary_externalize(od
);
809 next
= prop_dictionary_externalize(d
);
810 atf_tc_fail("dictionaries are unequal from the outset, argh! "
811 "original\n%s\nnew\n%s", oext
, next
);
816 if ((p
= ppath_create()) == NULL
)
817 atf_tc_fail("ppath_create failed");
819 if (ppath_push_key(p
, "John Doe") == NULL
)
820 atf_tc_fail("ppath_push_key failed");
821 if (ppath_push_key(p
, "u.s. citizen") == NULL
)
822 atf_tc_fail("ppath_push_key failed");
825 rc
= ppath_get_bool(d
, p
, &v
);
827 ATF_CHECK_EQ(v
, true);
829 rc
= ppath_copyset_bool(d
, &nd
, p
, false);
833 rc
= ppath_get_bool(nd
, p
, &v
);
835 ATF_CHECK_EQ(v
, false);
837 if (!dictionary_equals(od
, d
)) {
838 oext
= prop_dictionary_externalize(od
);
839 next
= prop_dictionary_externalize(d
);
840 atf_tc_fail("copyset modified original dictionary, "
841 "original\n%s\nnew\n%s", oext
, next
);
846 if (dictionary_equals(od
, nd
)) {
847 oext
= prop_dictionary_externalize(od
);
848 next
= prop_dictionary_externalize(nd
);
849 atf_tc_fail("copyset made no change to the new "
850 "dictionary, original\n%s\nnew\n%s", oext
, next
);
855 rc
= ppath_set_bool(nd
, p
, true);
858 if (!dictionary_equals(od
, nd
)) {
859 oext
= prop_dictionary_externalize(od
);
860 next
= prop_dictionary_externalize(nd
);
861 atf_tc_fail("copyset made an out-of-bounds change to the new "
862 "dictionary, original\n%s\nnew\n%s", oext
, next
);
868 prop_object_release(d
);
869 prop_object_release(od
);
870 prop_object_release(nd
);
871 assert_no_ppath_extant();
872 assert_no_ppath_component_extant();
875 ATF_TC(set_bool_eftype
);
877 ATF_TC_HEAD(set_bool_eftype
, tc
)
879 atf_tc_set_md_var(tc
, "descr", "check ppath_set_bool() does not "
880 "overwrite with a bool "
881 "the \"job title\" property in the \"John Doe\" record in "
883 "\"personnel\" property list");
886 ATF_TC_BODY(set_bool_eftype
, tc
)
893 assert_no_ppath_extant();
894 assert_no_ppath_component_extant();
896 if ((d
= prop_dictionary_internalize(personnel
)) == NULL
)
897 atf_tc_fail("prop_dictionary_internalize failed");
899 if ((p
= ppath_create()) == NULL
)
900 atf_tc_fail("ppath_create failed");
902 if (ppath_push_key(p
, "John Doe") == NULL
)
903 atf_tc_fail("ppath_push_key failed");
904 if (ppath_push_key(p
, "job title") == NULL
)
905 atf_tc_fail("ppath_push_key failed");
908 rc
= ppath_get_bool(d
, p
, &v
);
909 ATF_CHECK_EQ(rc
, EFTYPE
);
910 ATF_CHECK_EQ(v
, false);
912 rc
= ppath_set_bool(d
, p
, false);
913 ATF_CHECK_EQ(rc
, EFTYPE
);
916 rc
= ppath_get_bool(d
, p
, &v
);
917 ATF_CHECK_EQ(rc
, EFTYPE
);
918 ATF_CHECK_EQ(v
, true);
921 prop_object_release(d
);
922 assert_no_ppath_extant();
923 assert_no_ppath_component_extant();
926 ATF_TC(set_bool_enoent
);
928 ATF_TC_HEAD(set_bool_enoent
, tc
)
930 atf_tc_set_md_var(tc
, "descr", "check ppath_set_bool() does not create "
931 "the \"russian citizen\" property in the \"John Doe\" record in "
933 "\"personnel\" property list");
936 ATF_TC_BODY(set_bool_enoent
, tc
)
943 assert_no_ppath_extant();
944 assert_no_ppath_component_extant();
946 if ((d
= prop_dictionary_internalize(personnel
)) == NULL
)
947 atf_tc_fail("prop_dictionary_internalize failed");
949 if ((p
= ppath_create()) == NULL
)
950 atf_tc_fail("ppath_create failed");
952 if (ppath_push_key(p
, "John Doe") == NULL
)
953 atf_tc_fail("ppath_push_key failed");
954 if (ppath_push_key(p
, "russian citizen") == NULL
)
955 atf_tc_fail("ppath_push_key failed");
958 rc
= ppath_get_bool(d
, p
, &v
);
959 ATF_CHECK_EQ(rc
, ENOENT
);
960 ATF_CHECK_EQ(v
, false);
962 rc
= ppath_set_bool(d
, p
, false);
963 ATF_CHECK_EQ(rc
, ENOENT
);
966 rc
= ppath_get_bool(d
, p
, &v
);
967 ATF_CHECK_EQ(rc
, ENOENT
);
968 ATF_CHECK_EQ(v
, true);
971 prop_object_release(d
);
972 assert_no_ppath_extant();
973 assert_no_ppath_component_extant();
976 ATF_TC(create_bool_eexist
);
978 ATF_TC_HEAD(create_bool_eexist
, tc
)
980 atf_tc_set_md_var(tc
, "descr", "check ppath_create_bool() returns "
981 "EEXIST because the \"u.s. citizen\" property in the "
982 "\"John Doe\" record in the \"personnel\" property list "
986 ATF_TC_BODY(create_bool_eexist
, tc
)
993 assert_no_ppath_extant();
994 assert_no_ppath_component_extant();
996 if ((d
= prop_dictionary_internalize(personnel
)) == NULL
)
997 atf_tc_fail("prop_dictionary_internalize failed");
999 if ((p
= ppath_create()) == NULL
)
1000 atf_tc_fail("ppath_create failed");
1002 if (ppath_push_key(p
, "John Doe") == NULL
)
1003 atf_tc_fail("ppath_push_key failed");
1004 if (ppath_push_key(p
, "u.s. citizen") == NULL
)
1005 atf_tc_fail("ppath_push_key failed");
1008 rc
= ppath_get_bool(d
, p
, &v
);
1009 ATF_CHECK_EQ(rc
, 0);
1010 ATF_CHECK_EQ(v
, true);
1012 rc
= ppath_create_bool(d
, p
, false);
1013 ATF_CHECK_EQ(rc
, EEXIST
);
1016 rc
= ppath_get_bool(d
, p
, &v
);
1017 ATF_CHECK_EQ(rc
, 0);
1018 ATF_CHECK_EQ(v
, true);
1021 prop_object_release(d
);
1022 assert_no_ppath_extant();
1023 assert_no_ppath_component_extant();
1026 ATF_TC(create_bool_success
);
1028 ATF_TC_HEAD(create_bool_success
, tc
)
1030 atf_tc_set_md_var(tc
, "descr", "check ppath_create_bool() creates "
1031 "the \"russian citizen\" property in the \"John Doe\" record in "
1032 "the \"personnel\" property list and sets it to false");
1035 ATF_TC_BODY(create_bool_success
, tc
)
1039 prop_dictionary_t d
;
1042 assert_no_ppath_extant();
1043 assert_no_ppath_component_extant();
1045 if ((d
= prop_dictionary_internalize(personnel
)) == NULL
)
1046 atf_tc_fail("prop_dictionary_internalize failed");
1048 if ((p
= ppath_create()) == NULL
)
1049 atf_tc_fail("ppath_create failed");
1051 if (ppath_push_key(p
, "John Doe") == NULL
)
1052 atf_tc_fail("ppath_push_key failed");
1053 if (ppath_push_key(p
, "russian citizen") == NULL
)
1054 atf_tc_fail("ppath_push_key failed");
1057 rc
= ppath_get_bool(d
, p
, &v
);
1058 ATF_CHECK_EQ(rc
, ENOENT
);
1059 ATF_CHECK_EQ(v
, false);
1061 rc
= ppath_create_bool(d
, p
, false);
1062 ATF_CHECK_EQ(rc
, 0);
1065 rc
= ppath_get_bool(d
, p
, &v
);
1066 ATF_CHECK_EQ(rc
, 0);
1067 ATF_CHECK_EQ(v
, false);
1070 prop_object_release(d
);
1071 assert_no_ppath_extant();
1072 assert_no_ppath_component_extant();
1075 ATF_TC(set_bool_success
);
1077 ATF_TC_HEAD(set_bool_success
, tc
)
1079 atf_tc_set_md_var(tc
, "descr", "check ppath_set_bool() sets "
1080 "the \"u.s. citizen\" property in the \"John Doe\" record in the "
1081 "\"personnel\" property list to false and verifies the new value");
1084 ATF_TC_BODY(set_bool_success
, tc
)
1088 prop_dictionary_t d
;
1091 assert_no_ppath_extant();
1092 assert_no_ppath_component_extant();
1094 if ((d
= prop_dictionary_internalize(personnel
)) == NULL
)
1095 atf_tc_fail("prop_dictionary_internalize failed");
1097 if ((p
= ppath_create()) == NULL
)
1098 atf_tc_fail("ppath_create failed");
1100 if (ppath_push_key(p
, "John Doe") == NULL
)
1101 atf_tc_fail("ppath_push_key failed");
1102 if (ppath_push_key(p
, "u.s. citizen") == NULL
)
1103 atf_tc_fail("ppath_push_key failed");
1106 rc
= ppath_get_bool(d
, p
, &v
);
1107 ATF_CHECK_EQ(rc
, 0);
1108 ATF_CHECK_EQ(v
, true);
1110 rc
= ppath_set_bool(d
, p
, v
);
1111 ATF_CHECK_EQ(rc
, 0);
1114 rc
= ppath_get_bool(d
, p
, &v
);
1115 ATF_CHECK_EQ(rc
, 0);
1116 ATF_CHECK_EQ(v
, true);
1119 prop_object_release(d
);
1120 assert_no_ppath_extant();
1121 assert_no_ppath_component_extant();
1124 ATF_TC(get_bool_success
);
1126 ATF_TC_HEAD(get_bool_success
, tc
)
1128 atf_tc_set_md_var(tc
, "descr", "check ppath_get_bool() fetches "
1129 "the \"u.s. citizen\" property from the \"John Doe\" record in the "
1130 "\"personnel\" property list, and compares it with the expected "
1134 ATF_TC_BODY(get_bool_success
, tc
)
1138 prop_dictionary_t d
;
1141 assert_no_ppath_extant();
1142 assert_no_ppath_component_extant();
1144 if ((d
= prop_dictionary_internalize(personnel
)) == NULL
)
1145 atf_tc_fail("prop_dictionary_internalize failed");
1147 if ((p
= ppath_create()) == NULL
)
1148 atf_tc_fail("ppath_create failed");
1150 if (ppath_push_key(p
, "John Doe") == NULL
)
1151 atf_tc_fail("ppath_push_key failed");
1152 if (ppath_push_key(p
, "u.s. citizen") == NULL
)
1153 atf_tc_fail("ppath_push_key failed");
1155 rc
= ppath_get_bool(d
, p
, &v
);
1156 ATF_CHECK_EQ(rc
, 0);
1157 ATF_CHECK_EQ(v
, true);
1160 prop_object_release(d
);
1161 assert_no_ppath_extant();
1162 assert_no_ppath_component_extant();
1165 ATF_TC(delete_bool_success
);
1167 ATF_TC_HEAD(delete_bool_success
, tc
)
1169 atf_tc_set_md_var(tc
, "descr", "check ppath_delete_bool() succeeds "
1170 "for the path (\"John Doe\", \"u.s. citizen\") in the "
1171 "\"personnel\" property list");
1174 ATF_TC_BODY(delete_bool_success
, tc
)
1177 prop_dictionary_t d
;
1180 assert_no_ppath_extant();
1181 assert_no_ppath_component_extant();
1183 if ((d
= prop_dictionary_internalize(personnel
)) == NULL
)
1184 atf_tc_fail("prop_dictionary_internalize failed");
1186 if ((p
= ppath_create()) == NULL
)
1187 atf_tc_fail("ppath_create failed");
1189 if (ppath_push_key(p
, "John Doe") == NULL
)
1190 atf_tc_fail("ppath_push_key failed");
1191 if (ppath_push_key(p
, "u.s. citizen") == NULL
)
1192 atf_tc_fail("ppath_push_key failed");
1194 rc
= ppath_delete_bool(d
, p
);
1195 ATF_CHECK_EQ(rc
, 0);
1197 rc
= ppath_get_bool(d
, p
, NULL
);
1198 ATF_CHECK_EQ(rc
, ENOENT
);
1201 prop_object_release(d
);
1202 assert_no_ppath_extant();
1203 assert_no_ppath_component_extant();
1206 ATF_TC(delete_bool_eftype
);
1208 ATF_TC_HEAD(delete_bool_eftype
, tc
)
1210 atf_tc_set_md_var(tc
, "descr", "check ppath_delete_bool() returns "
1211 "EFTYPE for the path (\"John Doe\", \"job title\") in the "
1212 "\"personnel\" property list and does not delete the path");
1215 ATF_TC_BODY(delete_bool_eftype
, tc
)
1218 prop_dictionary_t d
;
1221 assert_no_ppath_extant();
1222 assert_no_ppath_component_extant();
1224 if ((d
= prop_dictionary_internalize(personnel
)) == NULL
)
1225 atf_tc_fail("prop_dictionary_internalize failed");
1227 if ((p
= ppath_create()) == NULL
)
1228 atf_tc_fail("ppath_create failed");
1230 if (ppath_push_key(p
, "John Doe") == NULL
)
1231 atf_tc_fail("ppath_push_key failed");
1232 if (ppath_push_key(p
, "job title") == NULL
)
1233 atf_tc_fail("ppath_push_key failed");
1235 rc
= ppath_delete_bool(d
, p
);
1236 ATF_CHECK_EQ(rc
, EFTYPE
);
1238 rc
= ppath_get_object(d
, p
, NULL
);
1239 ATF_CHECK_EQ(rc
, 0);
1242 prop_object_release(d
);
1243 assert_no_ppath_extant();
1244 assert_no_ppath_component_extant();
1247 ATF_TC(delete_bool_enoent
);
1249 ATF_TC_HEAD(delete_bool_enoent
, tc
)
1251 atf_tc_set_md_var(tc
, "descr", "check ppath_delete_bool() returns "
1252 "ENOENT for the path (\"John Doe\", \"citizen\") in the "
1253 "\"personnel\" property list");
1256 ATF_TC_BODY(delete_bool_enoent
, tc
)
1259 prop_dictionary_t d
;
1262 assert_no_ppath_extant();
1263 assert_no_ppath_component_extant();
1265 if ((d
= prop_dictionary_internalize(personnel
)) == NULL
)
1266 atf_tc_fail("prop_dictionary_internalize failed");
1268 if ((p
= ppath_create()) == NULL
)
1269 atf_tc_fail("ppath_create failed");
1271 if (ppath_push_key(p
, "John Doe") == NULL
)
1272 atf_tc_fail("ppath_push_key failed");
1273 if (ppath_push_key(p
, "citizen") == NULL
)
1274 atf_tc_fail("ppath_push_key failed");
1276 rc
= ppath_delete_bool(d
, p
);
1277 ATF_CHECK_EQ(rc
, ENOENT
);
1280 prop_object_release(d
);
1281 assert_no_ppath_extant();
1282 assert_no_ppath_component_extant();
1285 ATF_TC(get_bool_enoent
);
1287 ATF_TC_HEAD(get_bool_enoent
, tc
)
1289 atf_tc_set_md_var(tc
, "descr", "check ppath_get_bool() returns "
1290 "ENOENT for the path (\"John Doe\", \"citizen\") in the "
1291 "\"personnel\" property list, and the bool * argument is "
1295 ATF_TC_BODY(get_bool_enoent
, tc
)
1299 prop_dictionary_t d
;
1302 assert_no_ppath_extant();
1303 assert_no_ppath_component_extant();
1305 if ((d
= prop_dictionary_internalize(personnel
)) == NULL
)
1306 atf_tc_fail("prop_dictionary_internalize failed");
1308 if ((p
= ppath_create()) == NULL
)
1309 atf_tc_fail("ppath_create failed");
1311 if (ppath_push_key(p
, "John Doe") == NULL
)
1312 atf_tc_fail("ppath_push_key failed");
1313 if (ppath_push_key(p
, "citizen") == NULL
)
1314 atf_tc_fail("ppath_push_key failed");
1317 rc
= ppath_get_bool(d
, p
, &v
);
1318 ATF_CHECK_EQ(rc
, ENOENT
);
1319 ATF_CHECK_EQ(v
, true);
1322 rc
= ppath_get_bool(d
, p
, &v
);
1323 ATF_CHECK_EQ(rc
, ENOENT
);
1324 ATF_CHECK_EQ(v
, false);
1327 prop_object_release(d
);
1328 assert_no_ppath_extant();
1329 assert_no_ppath_component_extant();
1332 ATF_TC(get_bool_eftype
);
1334 ATF_TC_HEAD(get_bool_eftype
, tc
)
1336 atf_tc_set_md_var(tc
, "descr", "check ppath_get_bool() returns "
1337 "EFTYPE for the path (\"John Doe\", \"job title\") in the "
1338 "\"personnel\" property list, and the bool * argument is "
1342 ATF_TC_BODY(get_bool_eftype
, tc
)
1346 prop_dictionary_t d
;
1349 assert_no_ppath_extant();
1350 assert_no_ppath_component_extant();
1352 if ((d
= prop_dictionary_internalize(personnel
)) == NULL
)
1353 atf_tc_fail("prop_dictionary_internalize failed");
1355 if ((p
= ppath_create()) == NULL
)
1356 atf_tc_fail("ppath_create failed");
1358 if (ppath_push_key(p
, "John Doe") == NULL
)
1359 atf_tc_fail("ppath_push_key failed");
1360 if (ppath_push_key(p
, "job title") == NULL
)
1361 atf_tc_fail("ppath_push_key failed");
1364 rc
= ppath_get_bool(d
, p
, &v
);
1365 ATF_CHECK_EQ(rc
, EFTYPE
);
1366 ATF_CHECK_EQ(v
, true);
1369 rc
= ppath_get_bool(d
, p
, &v
);
1370 ATF_CHECK_EQ(rc
, EFTYPE
);
1371 ATF_CHECK_EQ(v
, false);
1374 prop_object_release(d
);
1375 assert_no_ppath_extant();
1376 assert_no_ppath_component_extant();
1379 ATF_TC(get_string_eftype
);
1381 ATF_TC_HEAD(get_string_eftype
, tc
)
1383 atf_tc_set_md_var(tc
, "descr", "check ppath_get_string() returns "
1384 "EFTYPE for the path (\"John Doe\", \"u.s. citizen\") in the "
1385 "\"personnel\" property list, and the const char ** argument is "
1389 ATF_TC_BODY(get_string_eftype
, tc
)
1393 prop_dictionary_t d
;
1396 assert_no_ppath_extant();
1397 assert_no_ppath_component_extant();
1399 if ((d
= prop_dictionary_internalize(personnel
)) == NULL
)
1400 atf_tc_fail("prop_dictionary_internalize failed");
1402 if ((p
= ppath_create()) == NULL
)
1403 atf_tc_fail("ppath_create failed");
1405 if (ppath_push_key(p
, "John Doe") == NULL
)
1406 atf_tc_fail("ppath_push_key failed");
1407 if (ppath_push_key(p
, "u.s. citizen") == NULL
)
1408 atf_tc_fail("ppath_push_key failed");
1411 rc
= ppath_get_string(d
, p
, &v
);
1412 ATF_CHECK_EQ(rc
, EFTYPE
);
1413 ATF_CHECK_EQ(v
, NULL
);
1416 rc
= ppath_get_string(d
, p
, &v
);
1417 ATF_CHECK_EQ(rc
, EFTYPE
);
1418 ATF_CHECK_STREQ(v
, "xyz");
1421 prop_object_release(d
);
1422 assert_no_ppath_extant();
1423 assert_no_ppath_component_extant();
1426 ATF_TC(get_string_enoent
);
1428 ATF_TC_HEAD(get_string_enoent
, tc
)
1430 atf_tc_set_md_var(tc
, "descr", "check ppath_get_string() returns "
1431 "ENOENT for the path (\"John Doe\", \"title\") in the "
1432 "\"personnel\" property list, and the const char ** argument is "
1436 ATF_TC_BODY(get_string_enoent
, tc
)
1440 prop_dictionary_t d
;
1443 assert_no_ppath_extant();
1444 assert_no_ppath_component_extant();
1446 if ((d
= prop_dictionary_internalize(personnel
)) == NULL
)
1447 atf_tc_fail("prop_dictionary_internalize failed");
1449 if ((p
= ppath_create()) == NULL
)
1450 atf_tc_fail("ppath_create failed");
1452 if (ppath_push_key(p
, "John Doe") == NULL
)
1453 atf_tc_fail("ppath_push_key failed");
1454 if (ppath_push_key(p
, "title") == NULL
)
1455 atf_tc_fail("ppath_push_key failed");
1458 rc
= ppath_get_string(d
, p
, &v
);
1459 ATF_CHECK_EQ(rc
, ENOENT
);
1460 ATF_CHECK_EQ(v
, NULL
);
1463 rc
= ppath_get_string(d
, p
, &v
);
1464 ATF_CHECK_EQ(rc
, ENOENT
);
1465 ATF_CHECK_STREQ(v
, "xyz");
1468 prop_object_release(d
);
1469 assert_no_ppath_extant();
1470 assert_no_ppath_component_extant();
1473 ATF_TC(get_string_success
);
1475 ATF_TC_HEAD(get_string_success
, tc
)
1477 atf_tc_set_md_var(tc
, "descr", "check ppath_get_string() fetches "
1478 "the \"job title\" property from the \"John Doe\" record in the "
1479 "\"personnel\" property list and compares it with the expected "
1480 "value, \"computer programmer\"");
1483 ATF_TC_BODY(get_string_success
, tc
)
1486 const char *v
= NULL
;;
1487 prop_dictionary_t d
;
1490 assert_no_ppath_extant();
1491 assert_no_ppath_component_extant();
1493 if ((d
= prop_dictionary_internalize(personnel
)) == NULL
)
1494 atf_tc_fail("prop_dictionary_internalize failed");
1496 if ((p
= ppath_create()) == NULL
)
1497 atf_tc_fail("ppath_create failed");
1499 if (ppath_push_key(p
, "John Doe") == NULL
)
1500 atf_tc_fail("ppath_push_key failed");
1501 if (ppath_push_key(p
, "job title") == NULL
)
1502 atf_tc_fail("ppath_push_key failed");
1504 rc
= ppath_get_string(d
, p
, &v
);
1505 ATF_CHECK_EQ(rc
, 0);
1506 ATF_CHECK_STREQ(v
, "computer programmer");
1509 prop_object_release(d
);
1510 assert_no_ppath_extant();
1511 assert_no_ppath_component_extant();
1517 ATF_TP_ADD_TC(tp
, push_until_full
);
1518 ATF_TP_ADD_TC(tp
, pop_until_empty
);
1519 ATF_TP_ADD_TC(tp
, length
);
1520 ATF_TP_ADD_TC(tp
, component_at
);
1521 ATF_TP_ADD_TC(tp
, get_idx_key
);
1522 ATF_TP_ADD_TC(tp
, ppath_copy
);
1523 ATF_TP_ADD_TC(tp
, replace
);
1525 ATF_TP_ADD_TC(tp
, delete_bool_eftype
);
1526 ATF_TP_ADD_TC(tp
, delete_bool_enoent
);
1527 ATF_TP_ADD_TC(tp
, delete_bool_success
);
1529 ATF_TP_ADD_TC(tp
, get_bool_eftype
);
1530 ATF_TP_ADD_TC(tp
, get_bool_enoent
);
1531 ATF_TP_ADD_TC(tp
, get_bool_success
);
1533 ATF_TP_ADD_TC(tp
, copydel_bool_success
);
1534 ATF_TP_ADD_TC(tp
, copydel_object_twice_success
);
1535 ATF_TP_ADD_TC(tp
, copyset_object_twice_success
);
1536 ATF_TP_ADD_TC(tp
, copyset_bool_success
);
1537 ATF_TP_ADD_TC(tp
, create_bool_eexist
);
1538 ATF_TP_ADD_TC(tp
, create_bool_success
);
1539 ATF_TP_ADD_TC(tp
, set_bool_enoent
);
1540 ATF_TP_ADD_TC(tp
, set_bool_eftype
);
1541 ATF_TP_ADD_TC(tp
, set_bool_success
);
1543 ATF_TP_ADD_TC(tp
, get_string_eftype
);
1544 ATF_TP_ADD_TC(tp
, get_string_enoent
);
1545 ATF_TP_ADD_TC(tp
, get_string_success
);
1547 return atf_no_error();