1*11be35a1SLionel Sambuc /* $Id: t_ppath.c,v 1.1 2011/08/25 19:09:46 dyoung Exp $ */
2*11be35a1SLionel Sambuc
3*11be35a1SLionel Sambuc /* Copyright (c) 2010 David Young. All rights reserved. */
4*11be35a1SLionel Sambuc
5*11be35a1SLionel Sambuc #include <sys/cdefs.h>
6*11be35a1SLionel Sambuc __RCSID("$Id: t_ppath.c,v 1.1 2011/08/25 19:09:46 dyoung Exp $");
7*11be35a1SLionel Sambuc
8*11be35a1SLionel Sambuc #include <assert.h>
9*11be35a1SLionel Sambuc #include <atf-c.h>
10*11be35a1SLionel Sambuc #include <errno.h>
11*11be35a1SLionel Sambuc #include <stdlib.h>
12*11be35a1SLionel Sambuc #include <string.h>
13*11be35a1SLionel Sambuc
14*11be35a1SLionel Sambuc #include <ppath/ppath.h>
15*11be35a1SLionel Sambuc #include "personnel.h"
16*11be35a1SLionel Sambuc
17*11be35a1SLionel Sambuc void test_ppath_extant_inc(void);
18*11be35a1SLionel Sambuc void test_ppath_extant_dec(void);
19*11be35a1SLionel Sambuc void test_ppath_component_extant_inc(void);
20*11be35a1SLionel Sambuc void test_ppath_component_extant_dec(void);
21*11be35a1SLionel Sambuc
22*11be35a1SLionel Sambuc __strong_alias(ppath_extant_inc, test_ppath_extant_inc);
23*11be35a1SLionel Sambuc __strong_alias(ppath_extant_dec, test_ppath_extant_dec);
24*11be35a1SLionel Sambuc __strong_alias(ppath_component_extant_inc, test_ppath_component_extant_inc);
25*11be35a1SLionel Sambuc __strong_alias(ppath_component_extant_dec, test_ppath_component_extant_dec);
26*11be35a1SLionel Sambuc
27*11be35a1SLionel Sambuc static uint64_t nppath = 0, nppath_component = 0;
28*11be35a1SLionel Sambuc
29*11be35a1SLionel Sambuc static bool
dictionary_equals(prop_dictionary_t ld,prop_dictionary_t rd)30*11be35a1SLionel Sambuc dictionary_equals(prop_dictionary_t ld, prop_dictionary_t rd)
31*11be35a1SLionel Sambuc {
32*11be35a1SLionel Sambuc bool eq;
33*11be35a1SLionel Sambuc char *lt, *rt;
34*11be35a1SLionel Sambuc
35*11be35a1SLionel Sambuc lt = prop_dictionary_externalize(ld);
36*11be35a1SLionel Sambuc rt = prop_dictionary_externalize(rd);
37*11be35a1SLionel Sambuc
38*11be35a1SLionel Sambuc assert(lt != NULL && rt != NULL);
39*11be35a1SLionel Sambuc
40*11be35a1SLionel Sambuc eq = (strcmp(lt, rt) == 0);
41*11be35a1SLionel Sambuc
42*11be35a1SLionel Sambuc free(lt);
43*11be35a1SLionel Sambuc free(rt);
44*11be35a1SLionel Sambuc
45*11be35a1SLionel Sambuc return eq;
46*11be35a1SLionel Sambuc }
47*11be35a1SLionel Sambuc
48*11be35a1SLionel Sambuc static void
assert_no_ppath_extant(void)49*11be35a1SLionel Sambuc assert_no_ppath_extant(void)
50*11be35a1SLionel Sambuc {
51*11be35a1SLionel Sambuc ATF_CHECK_EQ(nppath, 0);
52*11be35a1SLionel Sambuc }
53*11be35a1SLionel Sambuc
54*11be35a1SLionel Sambuc static void
assert_no_ppath_component_extant(void)55*11be35a1SLionel Sambuc assert_no_ppath_component_extant(void)
56*11be35a1SLionel Sambuc {
57*11be35a1SLionel Sambuc ATF_CHECK_EQ(nppath_component, 0);
58*11be35a1SLionel Sambuc }
59*11be35a1SLionel Sambuc
60*11be35a1SLionel Sambuc void
test_ppath_extant_inc(void)61*11be35a1SLionel Sambuc test_ppath_extant_inc(void)
62*11be35a1SLionel Sambuc {
63*11be35a1SLionel Sambuc if (++nppath == 0)
64*11be35a1SLionel Sambuc atf_tc_fail("count of extant paths overflowed");
65*11be35a1SLionel Sambuc }
66*11be35a1SLionel Sambuc
67*11be35a1SLionel Sambuc void
test_ppath_extant_dec(void)68*11be35a1SLionel Sambuc test_ppath_extant_dec(void)
69*11be35a1SLionel Sambuc {
70*11be35a1SLionel Sambuc if (nppath-- == 0)
71*11be35a1SLionel Sambuc atf_tc_fail("count of extant path underflowed");
72*11be35a1SLionel Sambuc }
73*11be35a1SLionel Sambuc
74*11be35a1SLionel Sambuc void
test_ppath_component_extant_inc(void)75*11be35a1SLionel Sambuc test_ppath_component_extant_inc(void)
76*11be35a1SLionel Sambuc {
77*11be35a1SLionel Sambuc if (++nppath_component == 0)
78*11be35a1SLionel Sambuc atf_tc_fail("count of extant path components overflowed");
79*11be35a1SLionel Sambuc }
80*11be35a1SLionel Sambuc
81*11be35a1SLionel Sambuc void
test_ppath_component_extant_dec(void)82*11be35a1SLionel Sambuc test_ppath_component_extant_dec(void)
83*11be35a1SLionel Sambuc {
84*11be35a1SLionel Sambuc if (nppath_component-- == 0)
85*11be35a1SLionel Sambuc atf_tc_fail("count of extant path components underflowed");
86*11be35a1SLionel Sambuc }
87*11be35a1SLionel Sambuc
88*11be35a1SLionel Sambuc ATF_TC(push_until_full);
89*11be35a1SLionel Sambuc
ATF_TC_HEAD(push_until_full,tc)90*11be35a1SLionel Sambuc ATF_TC_HEAD(push_until_full, tc)
91*11be35a1SLionel Sambuc {
92*11be35a1SLionel Sambuc atf_tc_set_md_var(tc, "descr", "check ppath_push() returns error "
93*11be35a1SLionel Sambuc "after ppath_t reaches maximum length");
94*11be35a1SLionel Sambuc }
95*11be35a1SLionel Sambuc
ATF_TC_BODY(push_until_full,tc)96*11be35a1SLionel Sambuc ATF_TC_BODY(push_until_full, tc)
97*11be35a1SLionel Sambuc {
98*11be35a1SLionel Sambuc ppath_t *p, *rp;
99*11be35a1SLionel Sambuc ppath_component_t *pc;
100*11be35a1SLionel Sambuc int i;
101*11be35a1SLionel Sambuc
102*11be35a1SLionel Sambuc assert_no_ppath_extant();
103*11be35a1SLionel Sambuc assert_no_ppath_component_extant();
104*11be35a1SLionel Sambuc
105*11be35a1SLionel Sambuc if ((p = ppath_create()) == NULL)
106*11be35a1SLionel Sambuc atf_tc_fail("ppath_create failed");
107*11be35a1SLionel Sambuc
108*11be35a1SLionel Sambuc if ((pc = ppath_idx(0)) == NULL)
109*11be35a1SLionel Sambuc atf_tc_fail("ppath_idx failed");
110*11be35a1SLionel Sambuc
111*11be35a1SLionel Sambuc for (i = 0; i < PPATH_MAX_COMPONENTS; i++) {
112*11be35a1SLionel Sambuc rp = ppath_push(p, pc);
113*11be35a1SLionel Sambuc ATF_CHECK_EQ(rp, p);
114*11be35a1SLionel Sambuc }
115*11be35a1SLionel Sambuc
116*11be35a1SLionel Sambuc rp = ppath_push(p, pc);
117*11be35a1SLionel Sambuc ATF_CHECK_EQ(rp, NULL);
118*11be35a1SLionel Sambuc
119*11be35a1SLionel Sambuc rp = ppath_push(p, pc);
120*11be35a1SLionel Sambuc ATF_CHECK_EQ(rp, NULL);
121*11be35a1SLionel Sambuc
122*11be35a1SLionel Sambuc ppath_component_release(pc);
123*11be35a1SLionel Sambuc ppath_release(p);
124*11be35a1SLionel Sambuc
125*11be35a1SLionel Sambuc assert_no_ppath_extant();
126*11be35a1SLionel Sambuc assert_no_ppath_component_extant();
127*11be35a1SLionel Sambuc }
128*11be35a1SLionel Sambuc
129*11be35a1SLionel Sambuc ATF_TC(pop_until_empty);
ATF_TC_HEAD(pop_until_empty,tc)130*11be35a1SLionel Sambuc ATF_TC_HEAD(pop_until_empty, tc)
131*11be35a1SLionel Sambuc {
132*11be35a1SLionel Sambuc atf_tc_set_md_var(tc, "descr", "check ppath_pop() returns error "
133*11be35a1SLionel Sambuc "after ppath_t is empty");
134*11be35a1SLionel Sambuc }
135*11be35a1SLionel Sambuc
ATF_TC_BODY(pop_until_empty,tc)136*11be35a1SLionel Sambuc ATF_TC_BODY(pop_until_empty, tc)
137*11be35a1SLionel Sambuc {
138*11be35a1SLionel Sambuc ppath_t *p, *rp;
139*11be35a1SLionel Sambuc ppath_component_t *pc, *rpc;
140*11be35a1SLionel Sambuc int i;
141*11be35a1SLionel Sambuc
142*11be35a1SLionel Sambuc assert_no_ppath_extant();
143*11be35a1SLionel Sambuc assert_no_ppath_component_extant();
144*11be35a1SLionel Sambuc
145*11be35a1SLionel Sambuc if ((p = ppath_create()) == NULL)
146*11be35a1SLionel Sambuc atf_tc_fail("ppath_create failed");
147*11be35a1SLionel Sambuc
148*11be35a1SLionel Sambuc if ((pc = ppath_idx(0)) == NULL)
149*11be35a1SLionel Sambuc atf_tc_fail("ppath_idx failed");
150*11be35a1SLionel Sambuc
151*11be35a1SLionel Sambuc for (i = 0; i < PPATH_MAX_COMPONENTS; i++) {
152*11be35a1SLionel Sambuc rp = ppath_push(p, pc);
153*11be35a1SLionel Sambuc ATF_CHECK_EQ(rp, p);
154*11be35a1SLionel Sambuc }
155*11be35a1SLionel Sambuc
156*11be35a1SLionel Sambuc for (i = 0; i < PPATH_MAX_COMPONENTS; i++) {
157*11be35a1SLionel Sambuc rp = ppath_pop(p, &rpc);
158*11be35a1SLionel Sambuc ATF_CHECK_EQ(rp, p);
159*11be35a1SLionel Sambuc ATF_CHECK_EQ(rpc, pc);
160*11be35a1SLionel Sambuc ppath_component_release(rpc);
161*11be35a1SLionel Sambuc }
162*11be35a1SLionel Sambuc
163*11be35a1SLionel Sambuc rp = ppath_pop(p, &rpc);
164*11be35a1SLionel Sambuc ATF_CHECK_EQ(rp, NULL);
165*11be35a1SLionel Sambuc rp = ppath_pop(p, &rpc);
166*11be35a1SLionel Sambuc ATF_CHECK_EQ(rp, NULL);
167*11be35a1SLionel Sambuc
168*11be35a1SLionel Sambuc ppath_component_release(pc);
169*11be35a1SLionel Sambuc ppath_release(p);
170*11be35a1SLionel Sambuc
171*11be35a1SLionel Sambuc assert_no_ppath_extant();
172*11be35a1SLionel Sambuc assert_no_ppath_component_extant();
173*11be35a1SLionel Sambuc }
174*11be35a1SLionel Sambuc
175*11be35a1SLionel Sambuc ATF_TC(length);
176*11be35a1SLionel Sambuc
ATF_TC_HEAD(length,tc)177*11be35a1SLionel Sambuc ATF_TC_HEAD(length, tc)
178*11be35a1SLionel Sambuc {
179*11be35a1SLionel Sambuc atf_tc_set_md_var(tc, "descr", "check that ppath_push() "
180*11be35a1SLionel Sambuc "and ppath_pop() affect ppath_length() correctly");
181*11be35a1SLionel Sambuc }
182*11be35a1SLionel Sambuc
ATF_TC_BODY(length,tc)183*11be35a1SLionel Sambuc ATF_TC_BODY(length, tc)
184*11be35a1SLionel Sambuc {
185*11be35a1SLionel Sambuc ppath_t *p, *rp;
186*11be35a1SLionel Sambuc ppath_component_t *pc;
187*11be35a1SLionel Sambuc unsigned int i, len;
188*11be35a1SLionel Sambuc
189*11be35a1SLionel Sambuc assert_no_ppath_extant();
190*11be35a1SLionel Sambuc assert_no_ppath_component_extant();
191*11be35a1SLionel Sambuc
192*11be35a1SLionel Sambuc if ((p = ppath_create()) == NULL)
193*11be35a1SLionel Sambuc atf_tc_fail("ppath_create failed");
194*11be35a1SLionel Sambuc
195*11be35a1SLionel Sambuc if ((pc = ppath_idx(0)) == NULL)
196*11be35a1SLionel Sambuc atf_tc_fail("ppath_idx failed");
197*11be35a1SLionel Sambuc
198*11be35a1SLionel Sambuc for (i = 0; i < PPATH_MAX_COMPONENTS; i++) {
199*11be35a1SLionel Sambuc len = ppath_length(p);
200*11be35a1SLionel Sambuc ATF_CHECK_EQ(len, i);
201*11be35a1SLionel Sambuc rp = ppath_push(p, pc);
202*11be35a1SLionel Sambuc ATF_CHECK_EQ(rp, p);
203*11be35a1SLionel Sambuc }
204*11be35a1SLionel Sambuc
205*11be35a1SLionel Sambuc for (i = 0; i < PPATH_MAX_COMPONENTS; i++) {
206*11be35a1SLionel Sambuc len = ppath_length(p);
207*11be35a1SLionel Sambuc ATF_CHECK_EQ(len, PPATH_MAX_COMPONENTS - i);
208*11be35a1SLionel Sambuc rp = ppath_pop(p, NULL);
209*11be35a1SLionel Sambuc ATF_CHECK_EQ(rp, p);
210*11be35a1SLionel Sambuc }
211*11be35a1SLionel Sambuc ppath_component_release(pc);
212*11be35a1SLionel Sambuc ppath_release(p);
213*11be35a1SLionel Sambuc
214*11be35a1SLionel Sambuc assert_no_ppath_extant();
215*11be35a1SLionel Sambuc assert_no_ppath_component_extant();
216*11be35a1SLionel Sambuc }
217*11be35a1SLionel Sambuc
218*11be35a1SLionel Sambuc ATF_TC(component_at);
219*11be35a1SLionel Sambuc
ATF_TC_HEAD(component_at,tc)220*11be35a1SLionel Sambuc ATF_TC_HEAD(component_at, tc)
221*11be35a1SLionel Sambuc {
222*11be35a1SLionel Sambuc atf_tc_set_md_var(tc, "descr", "check that ppath_component_at() "
223*11be35a1SLionel Sambuc "returns the expected component");
224*11be35a1SLionel Sambuc }
225*11be35a1SLionel Sambuc
ATF_TC_BODY(component_at,tc)226*11be35a1SLionel Sambuc ATF_TC_BODY(component_at, tc)
227*11be35a1SLionel Sambuc {
228*11be35a1SLionel Sambuc ppath_t *p, *rp;
229*11be35a1SLionel Sambuc ppath_component_t *pc;
230*11be35a1SLionel Sambuc unsigned int i;
231*11be35a1SLionel Sambuc
232*11be35a1SLionel Sambuc assert_no_ppath_extant();
233*11be35a1SLionel Sambuc assert_no_ppath_component_extant();
234*11be35a1SLionel Sambuc
235*11be35a1SLionel Sambuc if ((p = ppath_create()) == NULL)
236*11be35a1SLionel Sambuc atf_tc_fail("ppath_create failed");
237*11be35a1SLionel Sambuc
238*11be35a1SLionel Sambuc for (i = 0; i < PPATH_MAX_COMPONENTS; i++) {
239*11be35a1SLionel Sambuc if ((pc = ppath_idx(i)) == NULL)
240*11be35a1SLionel Sambuc atf_tc_fail("ppath_idx failed");
241*11be35a1SLionel Sambuc rp = ppath_push(p, pc);
242*11be35a1SLionel Sambuc ppath_component_release(pc);
243*11be35a1SLionel Sambuc ATF_CHECK_EQ(rp, p);
244*11be35a1SLionel Sambuc }
245*11be35a1SLionel Sambuc
246*11be35a1SLionel Sambuc for (i = 0; i < PPATH_MAX_COMPONENTS; i++) {
247*11be35a1SLionel Sambuc pc = ppath_component_at(p, i);
248*11be35a1SLionel Sambuc ATF_CHECK_EQ(ppath_component_idx(pc), (int)i);
249*11be35a1SLionel Sambuc ppath_component_release(pc);
250*11be35a1SLionel Sambuc }
251*11be35a1SLionel Sambuc ppath_release(p);
252*11be35a1SLionel Sambuc
253*11be35a1SLionel Sambuc assert_no_ppath_extant();
254*11be35a1SLionel Sambuc assert_no_ppath_component_extant();
255*11be35a1SLionel Sambuc }
256*11be35a1SLionel Sambuc
257*11be35a1SLionel Sambuc ATF_TC(get_idx_key);
258*11be35a1SLionel Sambuc
ATF_TC_HEAD(get_idx_key,tc)259*11be35a1SLionel Sambuc ATF_TC_HEAD(get_idx_key, tc)
260*11be35a1SLionel Sambuc {
261*11be35a1SLionel Sambuc atf_tc_set_md_var(tc, "descr", "check that ppath_component_idx() "
262*11be35a1SLionel Sambuc "and ppath_component_key() return -1 and NULL, respectively, if "
263*11be35a1SLionel Sambuc "the component is a key or an index, respectively.");
264*11be35a1SLionel Sambuc }
265*11be35a1SLionel Sambuc
ATF_TC_BODY(get_idx_key,tc)266*11be35a1SLionel Sambuc ATF_TC_BODY(get_idx_key, tc)
267*11be35a1SLionel Sambuc {
268*11be35a1SLionel Sambuc ppath_component_t *idx, *key;
269*11be35a1SLionel Sambuc
270*11be35a1SLionel Sambuc assert_no_ppath_extant();
271*11be35a1SLionel Sambuc assert_no_ppath_component_extant();
272*11be35a1SLionel Sambuc
273*11be35a1SLionel Sambuc if ((idx = ppath_idx(0)) == NULL)
274*11be35a1SLionel Sambuc atf_tc_fail("ppath_idx failed");
275*11be35a1SLionel Sambuc if ((key = ppath_key("key")) == NULL)
276*11be35a1SLionel Sambuc atf_tc_fail("ppath_idx failed");
277*11be35a1SLionel Sambuc
278*11be35a1SLionel Sambuc ATF_CHECK_EQ(ppath_component_key(idx), NULL);
279*11be35a1SLionel Sambuc ATF_CHECK_EQ(ppath_component_idx(key), -1);
280*11be35a1SLionel Sambuc
281*11be35a1SLionel Sambuc ppath_component_release(idx);
282*11be35a1SLionel Sambuc ppath_component_release(key);
283*11be35a1SLionel Sambuc
284*11be35a1SLionel Sambuc assert_no_ppath_extant();
285*11be35a1SLionel Sambuc assert_no_ppath_component_extant();
286*11be35a1SLionel Sambuc }
287*11be35a1SLionel Sambuc
288*11be35a1SLionel Sambuc ATF_TC(ppath_copy);
289*11be35a1SLionel Sambuc
ATF_TC_HEAD(ppath_copy,tc)290*11be35a1SLionel Sambuc ATF_TC_HEAD(ppath_copy, tc)
291*11be35a1SLionel Sambuc {
292*11be35a1SLionel Sambuc atf_tc_set_md_var(tc, "descr", "check that ppath_copy() "
293*11be35a1SLionel Sambuc "creates an exact replica of a path, and that no "
294*11be35a1SLionel Sambuc "resources are leaked.");
295*11be35a1SLionel Sambuc }
296*11be35a1SLionel Sambuc
ATF_TC_BODY(ppath_copy,tc)297*11be35a1SLionel Sambuc ATF_TC_BODY(ppath_copy, tc)
298*11be35a1SLionel Sambuc {
299*11be35a1SLionel Sambuc ppath_component_t *pc, *cpc;
300*11be35a1SLionel Sambuc ppath_t *p, *cp, *rp;
301*11be35a1SLionel Sambuc unsigned int i;
302*11be35a1SLionel Sambuc
303*11be35a1SLionel Sambuc assert_no_ppath_extant();
304*11be35a1SLionel Sambuc assert_no_ppath_component_extant();
305*11be35a1SLionel Sambuc
306*11be35a1SLionel Sambuc if ((p = ppath_create()) == NULL)
307*11be35a1SLionel Sambuc atf_tc_fail("ppath_create failed");
308*11be35a1SLionel Sambuc
309*11be35a1SLionel Sambuc for (i = 0; i < PPATH_MAX_COMPONENTS; i++) {
310*11be35a1SLionel Sambuc if ((pc = ppath_idx(i)) == NULL)
311*11be35a1SLionel Sambuc atf_tc_fail("ppath_idx failed");
312*11be35a1SLionel Sambuc rp = ppath_push(p, pc);
313*11be35a1SLionel Sambuc ppath_component_release(pc);
314*11be35a1SLionel Sambuc ATF_CHECK_EQ(rp, p);
315*11be35a1SLionel Sambuc }
316*11be35a1SLionel Sambuc
317*11be35a1SLionel Sambuc if ((cp = ppath_copy(p)) == NULL)
318*11be35a1SLionel Sambuc atf_tc_fail("ppath_copy failed");
319*11be35a1SLionel Sambuc
320*11be35a1SLionel Sambuc for (i = 0; i < PPATH_MAX_COMPONENTS; i++) {
321*11be35a1SLionel Sambuc pc = ppath_component_at(p, i);
322*11be35a1SLionel Sambuc cpc = ppath_component_at(cp, i);
323*11be35a1SLionel Sambuc ATF_CHECK_EQ(pc, cpc);
324*11be35a1SLionel Sambuc ppath_component_release(pc);
325*11be35a1SLionel Sambuc ppath_component_release(cpc);
326*11be35a1SLionel Sambuc }
327*11be35a1SLionel Sambuc
328*11be35a1SLionel Sambuc ppath_release(cp);
329*11be35a1SLionel Sambuc ppath_release(p);
330*11be35a1SLionel Sambuc
331*11be35a1SLionel Sambuc assert_no_ppath_extant();
332*11be35a1SLionel Sambuc assert_no_ppath_component_extant();
333*11be35a1SLionel Sambuc }
334*11be35a1SLionel Sambuc
335*11be35a1SLionel Sambuc ATF_TC(replace);
336*11be35a1SLionel Sambuc
ATF_TC_HEAD(replace,tc)337*11be35a1SLionel Sambuc ATF_TC_HEAD(replace, tc)
338*11be35a1SLionel Sambuc {
339*11be35a1SLionel Sambuc atf_tc_set_md_var(tc, "descr", "check that ppath_replace_idx() "
340*11be35a1SLionel Sambuc "and ppath_replace_key() produce the paths we expect without "
341*11be35a1SLionel Sambuc "leaking resources.");
342*11be35a1SLionel Sambuc }
343*11be35a1SLionel Sambuc
ATF_TC_BODY(replace,tc)344*11be35a1SLionel Sambuc ATF_TC_BODY(replace, tc)
345*11be35a1SLionel Sambuc {
346*11be35a1SLionel Sambuc ppath_component_t *pc;
347*11be35a1SLionel Sambuc ppath_t *p, *cp, *rp;
348*11be35a1SLionel Sambuc unsigned int i;
349*11be35a1SLionel Sambuc
350*11be35a1SLionel Sambuc assert_no_ppath_extant();
351*11be35a1SLionel Sambuc assert_no_ppath_component_extant();
352*11be35a1SLionel Sambuc
353*11be35a1SLionel Sambuc if ((p = ppath_create()) == NULL)
354*11be35a1SLionel Sambuc atf_tc_fail("ppath_create failed");
355*11be35a1SLionel Sambuc
356*11be35a1SLionel Sambuc /* index replacement fails on an empty path */
357*11be35a1SLionel Sambuc rp = ppath_replace_idx(p, 0);
358*11be35a1SLionel Sambuc ATF_CHECK_EQ(rp, NULL);
359*11be35a1SLionel Sambuc
360*11be35a1SLionel Sambuc /* key replacement fails on an empty path */
361*11be35a1SLionel Sambuc rp = ppath_replace_key(p, "key");
362*11be35a1SLionel Sambuc ATF_CHECK_EQ(rp, NULL);
363*11be35a1SLionel Sambuc
364*11be35a1SLionel Sambuc for (i = 0; i < PPATH_MAX_COMPONENTS; i++) {
365*11be35a1SLionel Sambuc if ((pc = ppath_idx(i)) == NULL)
366*11be35a1SLionel Sambuc atf_tc_fail("ppath_idx failed");
367*11be35a1SLionel Sambuc rp = ppath_push(p, pc);
368*11be35a1SLionel Sambuc ppath_component_release(pc);
369*11be35a1SLionel Sambuc ATF_CHECK_EQ(rp, p);
370*11be35a1SLionel Sambuc }
371*11be35a1SLionel Sambuc
372*11be35a1SLionel Sambuc if ((cp = ppath_copy(p)) == NULL)
373*11be35a1SLionel Sambuc atf_tc_fail("ppath_copy failed");
374*11be35a1SLionel Sambuc
375*11be35a1SLionel Sambuc rp = ppath_pop(cp, NULL);
376*11be35a1SLionel Sambuc ATF_CHECK_EQ(rp, cp);
377*11be35a1SLionel Sambuc rp = ppath_push_key(cp, "key");
378*11be35a1SLionel Sambuc ATF_CHECK_EQ(rp, cp);
379*11be35a1SLionel Sambuc
380*11be35a1SLionel Sambuc ppath_replace_idx(p, 0);
381*11be35a1SLionel Sambuc
382*11be35a1SLionel Sambuc if ((pc = ppath_component_at(p, PPATH_MAX_COMPONENTS - 1)) == NULL)
383*11be35a1SLionel Sambuc atf_tc_fail("ppath_idx failed");
384*11be35a1SLionel Sambuc ATF_CHECK_EQ(ppath_component_idx(pc), 0);
385*11be35a1SLionel Sambuc ppath_component_release(pc);
386*11be35a1SLionel Sambuc
387*11be35a1SLionel Sambuc for (i = 0; i < PPATH_MAX_COMPONENTS - 1; i++) {
388*11be35a1SLionel Sambuc if ((pc = ppath_component_at(p, i)) == NULL)
389*11be35a1SLionel Sambuc atf_tc_fail("ppath_idx failed");
390*11be35a1SLionel Sambuc ATF_CHECK_EQ(ppath_component_idx(pc), (int)i);
391*11be35a1SLionel Sambuc ppath_component_release(pc);
392*11be35a1SLionel Sambuc }
393*11be35a1SLionel Sambuc
394*11be35a1SLionel Sambuc for (i = 0; i < PPATH_MAX_COMPONENTS - 1; i++) {
395*11be35a1SLionel Sambuc if ((pc = ppath_component_at(cp, i)) == NULL)
396*11be35a1SLionel Sambuc atf_tc_fail("ppath_idx failed");
397*11be35a1SLionel Sambuc ATF_CHECK_EQ(ppath_component_idx(pc), (int)i);
398*11be35a1SLionel Sambuc ppath_component_release(pc);
399*11be35a1SLionel Sambuc }
400*11be35a1SLionel Sambuc
401*11be35a1SLionel Sambuc if ((pc = ppath_component_at(cp, PPATH_MAX_COMPONENTS - 1)) == NULL)
402*11be35a1SLionel Sambuc atf_tc_fail("ppath_idx failed");
403*11be35a1SLionel Sambuc if (ppath_component_key(pc) == NULL ||
404*11be35a1SLionel Sambuc strcmp(ppath_component_key(pc), "key") != 0)
405*11be35a1SLionel Sambuc atf_tc_fail("last path component expected to be \"key\"");
406*11be35a1SLionel Sambuc ppath_component_release(pc);
407*11be35a1SLionel Sambuc ppath_release(p);
408*11be35a1SLionel Sambuc ppath_release(cp);
409*11be35a1SLionel Sambuc
410*11be35a1SLionel Sambuc assert_no_ppath_extant();
411*11be35a1SLionel Sambuc assert_no_ppath_component_extant();
412*11be35a1SLionel Sambuc }
413*11be35a1SLionel Sambuc
414*11be35a1SLionel Sambuc ATF_TC(copyset_object_twice_success);
415*11be35a1SLionel Sambuc
ATF_TC_HEAD(copyset_object_twice_success,tc)416*11be35a1SLionel Sambuc ATF_TC_HEAD(copyset_object_twice_success, tc)
417*11be35a1SLionel Sambuc {
418*11be35a1SLionel Sambuc atf_tc_set_md_var(tc, "descr",
419*11be35a1SLionel Sambuc "check that after back-to-back ppath_copyset_object() calls, "
420*11be35a1SLionel Sambuc "changing the \"u.s. citizen\" property and the first property "
421*11be35a1SLionel Sambuc "in \"children\" in the \"John Doe\" record in the "
422*11be35a1SLionel Sambuc "\"personnel\" property list, the properties are changed "
423*11be35a1SLionel Sambuc "in the new dictionary and unchanged in the old dictionary");
424*11be35a1SLionel Sambuc }
425*11be35a1SLionel Sambuc
ATF_TC_BODY(copyset_object_twice_success,tc)426*11be35a1SLionel Sambuc ATF_TC_BODY(copyset_object_twice_success, tc)
427*11be35a1SLionel Sambuc {
428*11be35a1SLionel Sambuc const char *s;
429*11be35a1SLionel Sambuc char *oext, *next;
430*11be35a1SLionel Sambuc int rc;
431*11be35a1SLionel Sambuc bool v = false;
432*11be35a1SLionel Sambuc prop_dictionary_t d, od;
433*11be35a1SLionel Sambuc prop_object_t nd = NULL, ond;
434*11be35a1SLionel Sambuc prop_object_t r, or;
435*11be35a1SLionel Sambuc ppath_t *p, *p2, *p3;
436*11be35a1SLionel Sambuc
437*11be35a1SLionel Sambuc assert_no_ppath_extant();
438*11be35a1SLionel Sambuc assert_no_ppath_component_extant();
439*11be35a1SLionel Sambuc
440*11be35a1SLionel Sambuc if ((d = prop_dictionary_internalize(personnel)) == NULL)
441*11be35a1SLionel Sambuc atf_tc_fail("prop_dictionary_internalize failed");
442*11be35a1SLionel Sambuc od = prop_dictionary_copy(d);
443*11be35a1SLionel Sambuc
444*11be35a1SLionel Sambuc if (!dictionary_equals(od, d)) {
445*11be35a1SLionel Sambuc oext = prop_dictionary_externalize(od);
446*11be35a1SLionel Sambuc next = prop_dictionary_externalize(d);
447*11be35a1SLionel Sambuc atf_tc_fail("dictionaries are unequal from the outset, argh! "
448*11be35a1SLionel Sambuc "original\n%s\nnew\n%s", oext, next);
449*11be35a1SLionel Sambuc free(oext);
450*11be35a1SLionel Sambuc free(next);
451*11be35a1SLionel Sambuc }
452*11be35a1SLionel Sambuc
453*11be35a1SLionel Sambuc if ((p = ppath_create()) == NULL || (p2 = ppath_create()) == NULL ||
454*11be35a1SLionel Sambuc (p3 = ppath_create()) == NULL)
455*11be35a1SLionel Sambuc atf_tc_fail("ppath_create failed");
456*11be35a1SLionel Sambuc
457*11be35a1SLionel Sambuc if (ppath_push_key(p, "John Doe") == NULL)
458*11be35a1SLionel Sambuc atf_tc_fail("ppath_push_key failed");
459*11be35a1SLionel Sambuc if (ppath_push_key(p, "u.s. citizen") == NULL)
460*11be35a1SLionel Sambuc atf_tc_fail("ppath_push_key failed");
461*11be35a1SLionel Sambuc
462*11be35a1SLionel Sambuc if (ppath_push_key(p2, "John Doe") == NULL)
463*11be35a1SLionel Sambuc atf_tc_fail("ppath_push_key failed");
464*11be35a1SLionel Sambuc if (ppath_push_key(p2, "children") == NULL)
465*11be35a1SLionel Sambuc atf_tc_fail("ppath_push_key failed");
466*11be35a1SLionel Sambuc if (ppath_push_idx(p2, 0) == NULL)
467*11be35a1SLionel Sambuc atf_tc_fail("ppath_push_idx failed");
468*11be35a1SLionel Sambuc
469*11be35a1SLionel Sambuc if (ppath_push_key(p3, "John Doe") == NULL)
470*11be35a1SLionel Sambuc atf_tc_fail("ppath_push_key failed");
471*11be35a1SLionel Sambuc
472*11be35a1SLionel Sambuc v = false;
473*11be35a1SLionel Sambuc rc = ppath_get_bool(d, p, &v);
474*11be35a1SLionel Sambuc ATF_CHECK_EQ(rc, 0);
475*11be35a1SLionel Sambuc ATF_CHECK_EQ(v, true);
476*11be35a1SLionel Sambuc
477*11be35a1SLionel Sambuc s = "";
478*11be35a1SLionel Sambuc rc = ppath_get_string(d, p2, &s);
479*11be35a1SLionel Sambuc ATF_CHECK_EQ(rc, 0);
480*11be35a1SLionel Sambuc ATF_CHECK_STREQ(s, "Jane Doe");
481*11be35a1SLionel Sambuc
482*11be35a1SLionel Sambuc rc = ppath_copyset_bool(d, &nd, p, false);
483*11be35a1SLionel Sambuc ATF_CHECK_EQ(rc, 0);
484*11be35a1SLionel Sambuc
485*11be35a1SLionel Sambuc rc = ppath_get_object(nd, p3, &r);
486*11be35a1SLionel Sambuc ATF_CHECK_EQ(rc, 0);
487*11be35a1SLionel Sambuc
488*11be35a1SLionel Sambuc ond = nd;
489*11be35a1SLionel Sambuc
490*11be35a1SLionel Sambuc rc = ppath_copyset_string(d, &nd, p2, "Martha Doe");
491*11be35a1SLionel Sambuc ATF_CHECK_EQ(rc, 0);
492*11be35a1SLionel Sambuc
493*11be35a1SLionel Sambuc ATF_CHECK_EQ(nd, ond);
494*11be35a1SLionel Sambuc
495*11be35a1SLionel Sambuc rc = ppath_get_object(nd, p3, &or);
496*11be35a1SLionel Sambuc ATF_CHECK_EQ(rc, 0);
497*11be35a1SLionel Sambuc
498*11be35a1SLionel Sambuc ATF_CHECK_EQ(r, or);
499*11be35a1SLionel Sambuc
500*11be35a1SLionel Sambuc v = true;
501*11be35a1SLionel Sambuc rc = ppath_get_bool(nd, p, &v);
502*11be35a1SLionel Sambuc ATF_CHECK_EQ(rc, 0);
503*11be35a1SLionel Sambuc ATF_CHECK_EQ(v, false);
504*11be35a1SLionel Sambuc
505*11be35a1SLionel Sambuc s = "";
506*11be35a1SLionel Sambuc rc = ppath_get_string(nd, p2, &s);
507*11be35a1SLionel Sambuc ATF_CHECK_EQ(rc, 0);
508*11be35a1SLionel Sambuc ATF_CHECK_STREQ(s, "Martha Doe");
509*11be35a1SLionel Sambuc
510*11be35a1SLionel Sambuc if (!dictionary_equals(od, d)) {
511*11be35a1SLionel Sambuc oext = prop_dictionary_externalize(od);
512*11be35a1SLionel Sambuc next = prop_dictionary_externalize(d);
513*11be35a1SLionel Sambuc atf_tc_fail("copydel modified original dictionary, "
514*11be35a1SLionel Sambuc "original\n%s\nnew\n%s", oext, next);
515*11be35a1SLionel Sambuc free(oext);
516*11be35a1SLionel Sambuc free(next);
517*11be35a1SLionel Sambuc }
518*11be35a1SLionel Sambuc
519*11be35a1SLionel Sambuc if (dictionary_equals(od, nd)) {
520*11be35a1SLionel Sambuc oext = prop_dictionary_externalize(od);
521*11be35a1SLionel Sambuc next = prop_dictionary_externalize(nd);
522*11be35a1SLionel Sambuc atf_tc_fail("copydel made no change to the new "
523*11be35a1SLionel Sambuc "dictionary, original\n%s\nnew\n%s", oext, next);
524*11be35a1SLionel Sambuc free(oext);
525*11be35a1SLionel Sambuc free(next);
526*11be35a1SLionel Sambuc }
527*11be35a1SLionel Sambuc
528*11be35a1SLionel Sambuc rc = ppath_set_bool(od, p, false);
529*11be35a1SLionel Sambuc ATF_CHECK_EQ(rc, 0);
530*11be35a1SLionel Sambuc
531*11be35a1SLionel Sambuc rc = ppath_set_string(od, p2, "Martha Doe");
532*11be35a1SLionel Sambuc ATF_CHECK_EQ(rc, 0);
533*11be35a1SLionel Sambuc
534*11be35a1SLionel Sambuc if (!dictionary_equals(od, nd)) {
535*11be35a1SLionel Sambuc oext = prop_dictionary_externalize(od);
536*11be35a1SLionel Sambuc next = prop_dictionary_externalize(nd);
537*11be35a1SLionel Sambuc atf_tc_fail("copydel made an out-of-bounds change to the new "
538*11be35a1SLionel Sambuc "dictionary, original\n%s\nnew\n%s", oext, next);
539*11be35a1SLionel Sambuc free(oext);
540*11be35a1SLionel Sambuc free(next);
541*11be35a1SLionel Sambuc }
542*11be35a1SLionel Sambuc
543*11be35a1SLionel Sambuc ppath_release(p);
544*11be35a1SLionel Sambuc ppath_release(p2);
545*11be35a1SLionel Sambuc ppath_release(p3);
546*11be35a1SLionel Sambuc prop_object_release(d);
547*11be35a1SLionel Sambuc prop_object_release(od);
548*11be35a1SLionel Sambuc prop_object_release(nd);
549*11be35a1SLionel Sambuc assert_no_ppath_extant();
550*11be35a1SLionel Sambuc assert_no_ppath_component_extant();
551*11be35a1SLionel Sambuc }
552*11be35a1SLionel Sambuc
553*11be35a1SLionel Sambuc ATF_TC(copydel_object_twice_success);
554*11be35a1SLionel Sambuc
ATF_TC_HEAD(copydel_object_twice_success,tc)555*11be35a1SLionel Sambuc ATF_TC_HEAD(copydel_object_twice_success, tc)
556*11be35a1SLionel Sambuc {
557*11be35a1SLionel Sambuc atf_tc_set_md_var(tc, "descr",
558*11be35a1SLionel Sambuc "check that after back-to-back ppath_copydel_object() calls, "
559*11be35a1SLionel Sambuc "removing the \"u.s. citizen\" property and the first property "
560*11be35a1SLionel Sambuc "in \"children\" from the \"John Doe\" record in the "
561*11be35a1SLionel Sambuc "\"personnel\" property list, the properties are missing "
562*11be35a1SLionel Sambuc "from the new dictionary and unchanged in the old dictionary");
563*11be35a1SLionel Sambuc }
564*11be35a1SLionel Sambuc
ATF_TC_BODY(copydel_object_twice_success,tc)565*11be35a1SLionel Sambuc ATF_TC_BODY(copydel_object_twice_success, tc)
566*11be35a1SLionel Sambuc {
567*11be35a1SLionel Sambuc const char *s;
568*11be35a1SLionel Sambuc char *oext, *next;
569*11be35a1SLionel Sambuc int rc;
570*11be35a1SLionel Sambuc bool v = false;
571*11be35a1SLionel Sambuc prop_dictionary_t d, od;
572*11be35a1SLionel Sambuc prop_object_t nd = NULL, ond;
573*11be35a1SLionel Sambuc prop_object_t r, or;
574*11be35a1SLionel Sambuc ppath_t *p, *p2, *p3;
575*11be35a1SLionel Sambuc
576*11be35a1SLionel Sambuc assert_no_ppath_extant();
577*11be35a1SLionel Sambuc assert_no_ppath_component_extant();
578*11be35a1SLionel Sambuc
579*11be35a1SLionel Sambuc if ((d = prop_dictionary_internalize(personnel)) == NULL)
580*11be35a1SLionel Sambuc atf_tc_fail("prop_dictionary_internalize failed");
581*11be35a1SLionel Sambuc od = prop_dictionary_copy(d);
582*11be35a1SLionel Sambuc
583*11be35a1SLionel Sambuc if (!dictionary_equals(od, d)) {
584*11be35a1SLionel Sambuc oext = prop_dictionary_externalize(od);
585*11be35a1SLionel Sambuc next = prop_dictionary_externalize(d);
586*11be35a1SLionel Sambuc atf_tc_fail("dictionaries are unequal from the outset, argh! "
587*11be35a1SLionel Sambuc "original\n%s\nnew\n%s", oext, next);
588*11be35a1SLionel Sambuc free(oext);
589*11be35a1SLionel Sambuc free(next);
590*11be35a1SLionel Sambuc }
591*11be35a1SLionel Sambuc
592*11be35a1SLionel Sambuc if ((p = ppath_create()) == NULL || (p2 = ppath_create()) == NULL ||
593*11be35a1SLionel Sambuc (p3 = ppath_create()) == NULL)
594*11be35a1SLionel Sambuc atf_tc_fail("ppath_create failed");
595*11be35a1SLionel Sambuc
596*11be35a1SLionel Sambuc if (ppath_push_key(p, "John Doe") == NULL)
597*11be35a1SLionel Sambuc atf_tc_fail("ppath_push_key failed");
598*11be35a1SLionel Sambuc if (ppath_push_key(p, "u.s. citizen") == NULL)
599*11be35a1SLionel Sambuc atf_tc_fail("ppath_push_key failed");
600*11be35a1SLionel Sambuc
601*11be35a1SLionel Sambuc if (ppath_push_key(p2, "John Doe") == NULL)
602*11be35a1SLionel Sambuc atf_tc_fail("ppath_push_key failed");
603*11be35a1SLionel Sambuc if (ppath_push_key(p2, "children") == NULL)
604*11be35a1SLionel Sambuc atf_tc_fail("ppath_push_key failed");
605*11be35a1SLionel Sambuc if (ppath_push_idx(p2, 0) == NULL)
606*11be35a1SLionel Sambuc atf_tc_fail("ppath_push_idx failed");
607*11be35a1SLionel Sambuc
608*11be35a1SLionel Sambuc if (ppath_push_key(p3, "John Doe") == NULL)
609*11be35a1SLionel Sambuc atf_tc_fail("ppath_push_key failed");
610*11be35a1SLionel Sambuc
611*11be35a1SLionel Sambuc v = false;
612*11be35a1SLionel Sambuc rc = ppath_get_bool(d, p, &v);
613*11be35a1SLionel Sambuc ATF_CHECK_EQ(rc, 0);
614*11be35a1SLionel Sambuc ATF_CHECK_EQ(v, true);
615*11be35a1SLionel Sambuc
616*11be35a1SLionel Sambuc s = "";
617*11be35a1SLionel Sambuc rc = ppath_get_string(d, p2, &s);
618*11be35a1SLionel Sambuc ATF_CHECK_EQ(rc, 0);
619*11be35a1SLionel Sambuc ATF_CHECK_STREQ(s, "Jane Doe");
620*11be35a1SLionel Sambuc
621*11be35a1SLionel Sambuc rc = ppath_copydel_bool(d, &nd, p);
622*11be35a1SLionel Sambuc ATF_CHECK_EQ(rc, 0);
623*11be35a1SLionel Sambuc
624*11be35a1SLionel Sambuc ond = nd;
625*11be35a1SLionel Sambuc
626*11be35a1SLionel Sambuc rc = ppath_get_object(nd, p3, &r);
627*11be35a1SLionel Sambuc ATF_CHECK_EQ(rc, 0);
628*11be35a1SLionel Sambuc
629*11be35a1SLionel Sambuc rc = ppath_copydel_string(d, &nd, p2);
630*11be35a1SLionel Sambuc ATF_CHECK_EQ(rc, 0);
631*11be35a1SLionel Sambuc
632*11be35a1SLionel Sambuc ATF_CHECK_EQ(nd, ond);
633*11be35a1SLionel Sambuc
634*11be35a1SLionel Sambuc rc = ppath_get_object(nd, p3, &or);
635*11be35a1SLionel Sambuc ATF_CHECK_EQ(rc, 0);
636*11be35a1SLionel Sambuc
637*11be35a1SLionel Sambuc ATF_CHECK_EQ(r, or);
638*11be35a1SLionel Sambuc
639*11be35a1SLionel Sambuc v = true;
640*11be35a1SLionel Sambuc rc = ppath_get_bool(nd, p, &v);
641*11be35a1SLionel Sambuc ATF_CHECK_EQ(rc, ENOENT);
642*11be35a1SLionel Sambuc ATF_CHECK_EQ(v, true);
643*11be35a1SLionel Sambuc
644*11be35a1SLionel Sambuc if (!dictionary_equals(od, d)) {
645*11be35a1SLionel Sambuc oext = prop_dictionary_externalize(od);
646*11be35a1SLionel Sambuc next = prop_dictionary_externalize(d);
647*11be35a1SLionel Sambuc atf_tc_fail("copydel modified original dictionary, "
648*11be35a1SLionel Sambuc "original\n%s\nnew\n%s", oext, next);
649*11be35a1SLionel Sambuc free(oext);
650*11be35a1SLionel Sambuc free(next);
651*11be35a1SLionel Sambuc }
652*11be35a1SLionel Sambuc
653*11be35a1SLionel Sambuc if (dictionary_equals(od, nd)) {
654*11be35a1SLionel Sambuc oext = prop_dictionary_externalize(od);
655*11be35a1SLionel Sambuc next = prop_dictionary_externalize(nd);
656*11be35a1SLionel Sambuc atf_tc_fail("copydel made no change to the new "
657*11be35a1SLionel Sambuc "dictionary, original\n%s\nnew\n%s", oext, next);
658*11be35a1SLionel Sambuc free(oext);
659*11be35a1SLionel Sambuc free(next);
660*11be35a1SLionel Sambuc }
661*11be35a1SLionel Sambuc
662*11be35a1SLionel Sambuc rc = ppath_delete_bool(od, p);
663*11be35a1SLionel Sambuc ATF_CHECK_EQ(rc, 0);
664*11be35a1SLionel Sambuc
665*11be35a1SLionel Sambuc rc = ppath_delete_string(od, p2);
666*11be35a1SLionel Sambuc ATF_CHECK_EQ(rc, 0);
667*11be35a1SLionel Sambuc
668*11be35a1SLionel Sambuc if (!dictionary_equals(od, nd)) {
669*11be35a1SLionel Sambuc oext = prop_dictionary_externalize(od);
670*11be35a1SLionel Sambuc next = prop_dictionary_externalize(nd);
671*11be35a1SLionel Sambuc atf_tc_fail("copydel made an out-of-bounds change to the new "
672*11be35a1SLionel Sambuc "dictionary, original\n%s\nnew\n%s", oext, next);
673*11be35a1SLionel Sambuc free(oext);
674*11be35a1SLionel Sambuc free(next);
675*11be35a1SLionel Sambuc }
676*11be35a1SLionel Sambuc
677*11be35a1SLionel Sambuc ppath_release(p);
678*11be35a1SLionel Sambuc ppath_release(p2);
679*11be35a1SLionel Sambuc ppath_release(p3);
680*11be35a1SLionel Sambuc prop_object_release(d);
681*11be35a1SLionel Sambuc prop_object_release(od);
682*11be35a1SLionel Sambuc prop_object_release(nd);
683*11be35a1SLionel Sambuc assert_no_ppath_extant();
684*11be35a1SLionel Sambuc assert_no_ppath_component_extant();
685*11be35a1SLionel Sambuc }
686*11be35a1SLionel Sambuc
687*11be35a1SLionel Sambuc ATF_TC(copydel_bool_success);
688*11be35a1SLionel Sambuc
ATF_TC_HEAD(copydel_bool_success,tc)689*11be35a1SLionel Sambuc ATF_TC_HEAD(copydel_bool_success, tc)
690*11be35a1SLionel Sambuc {
691*11be35a1SLionel Sambuc atf_tc_set_md_var(tc, "descr", "check ppath_copydel_bool() deletes "
692*11be35a1SLionel Sambuc "the \"u.s. citizen\" property in the \"John Doe\" record in the "
693*11be35a1SLionel Sambuc "\"personnel\" property list and verifies the value is missing "
694*11be35a1SLionel Sambuc "from the new dictionary and unchanged in the old dictionary");
695*11be35a1SLionel Sambuc }
696*11be35a1SLionel Sambuc
ATF_TC_BODY(copydel_bool_success,tc)697*11be35a1SLionel Sambuc ATF_TC_BODY(copydel_bool_success, tc)
698*11be35a1SLionel Sambuc {
699*11be35a1SLionel Sambuc char *oext, *next;
700*11be35a1SLionel Sambuc int rc;
701*11be35a1SLionel Sambuc bool v = false;
702*11be35a1SLionel Sambuc prop_dictionary_t d, od;
703*11be35a1SLionel Sambuc prop_object_t nd = NULL;
704*11be35a1SLionel Sambuc ppath_t *p;
705*11be35a1SLionel Sambuc
706*11be35a1SLionel Sambuc assert_no_ppath_extant();
707*11be35a1SLionel Sambuc assert_no_ppath_component_extant();
708*11be35a1SLionel Sambuc
709*11be35a1SLionel Sambuc if ((d = prop_dictionary_internalize(personnel)) == NULL)
710*11be35a1SLionel Sambuc atf_tc_fail("prop_dictionary_internalize failed");
711*11be35a1SLionel Sambuc od = prop_dictionary_copy(d);
712*11be35a1SLionel Sambuc
713*11be35a1SLionel Sambuc if (!dictionary_equals(od, d)) {
714*11be35a1SLionel Sambuc oext = prop_dictionary_externalize(od);
715*11be35a1SLionel Sambuc next = prop_dictionary_externalize(d);
716*11be35a1SLionel Sambuc atf_tc_fail("dictionaries are unequal from the outset, argh! "
717*11be35a1SLionel Sambuc "original\n%s\nnew\n%s", oext, next);
718*11be35a1SLionel Sambuc free(oext);
719*11be35a1SLionel Sambuc free(next);
720*11be35a1SLionel Sambuc }
721*11be35a1SLionel Sambuc
722*11be35a1SLionel Sambuc if ((p = ppath_create()) == NULL)
723*11be35a1SLionel Sambuc atf_tc_fail("ppath_create failed");
724*11be35a1SLionel Sambuc
725*11be35a1SLionel Sambuc if (ppath_push_key(p, "John Doe") == NULL)
726*11be35a1SLionel Sambuc atf_tc_fail("ppath_push_key failed");
727*11be35a1SLionel Sambuc if (ppath_push_key(p, "u.s. citizen") == NULL)
728*11be35a1SLionel Sambuc atf_tc_fail("ppath_push_key failed");
729*11be35a1SLionel Sambuc
730*11be35a1SLionel Sambuc v = false;
731*11be35a1SLionel Sambuc rc = ppath_get_bool(d, p, &v);
732*11be35a1SLionel Sambuc ATF_CHECK_EQ(rc, 0);
733*11be35a1SLionel Sambuc ATF_CHECK_EQ(v, true);
734*11be35a1SLionel Sambuc
735*11be35a1SLionel Sambuc rc = ppath_copydel_bool(d, &nd, p);
736*11be35a1SLionel Sambuc ATF_CHECK_EQ(rc, 0);
737*11be35a1SLionel Sambuc
738*11be35a1SLionel Sambuc v = true;
739*11be35a1SLionel Sambuc rc = ppath_get_bool(nd, p, &v);
740*11be35a1SLionel Sambuc ATF_CHECK_EQ(rc, ENOENT);
741*11be35a1SLionel Sambuc ATF_CHECK_EQ(v, true);
742*11be35a1SLionel Sambuc
743*11be35a1SLionel Sambuc if (!dictionary_equals(od, d)) {
744*11be35a1SLionel Sambuc oext = prop_dictionary_externalize(od);
745*11be35a1SLionel Sambuc next = prop_dictionary_externalize(d);
746*11be35a1SLionel Sambuc atf_tc_fail("copydel modified original dictionary, "
747*11be35a1SLionel Sambuc "original\n%s\nnew\n%s", oext, next);
748*11be35a1SLionel Sambuc free(oext);
749*11be35a1SLionel Sambuc free(next);
750*11be35a1SLionel Sambuc }
751*11be35a1SLionel Sambuc
752*11be35a1SLionel Sambuc if (dictionary_equals(od, nd)) {
753*11be35a1SLionel Sambuc oext = prop_dictionary_externalize(od);
754*11be35a1SLionel Sambuc next = prop_dictionary_externalize(nd);
755*11be35a1SLionel Sambuc atf_tc_fail("copydel made no change to the new "
756*11be35a1SLionel Sambuc "dictionary, original\n%s\nnew\n%s", oext, next);
757*11be35a1SLionel Sambuc free(oext);
758*11be35a1SLionel Sambuc free(next);
759*11be35a1SLionel Sambuc }
760*11be35a1SLionel Sambuc
761*11be35a1SLionel Sambuc rc = ppath_delete_bool(od, p);
762*11be35a1SLionel Sambuc ATF_CHECK_EQ(rc, 0);
763*11be35a1SLionel Sambuc
764*11be35a1SLionel Sambuc if (!dictionary_equals(od, nd)) {
765*11be35a1SLionel Sambuc oext = prop_dictionary_externalize(od);
766*11be35a1SLionel Sambuc next = prop_dictionary_externalize(nd);
767*11be35a1SLionel Sambuc atf_tc_fail("copydel made an out-of-bounds change to the new "
768*11be35a1SLionel Sambuc "dictionary, original\n%s\nnew\n%s", oext, next);
769*11be35a1SLionel Sambuc free(oext);
770*11be35a1SLionel Sambuc free(next);
771*11be35a1SLionel Sambuc }
772*11be35a1SLionel Sambuc
773*11be35a1SLionel Sambuc ppath_release(p);
774*11be35a1SLionel Sambuc prop_object_release(d);
775*11be35a1SLionel Sambuc prop_object_release(od);
776*11be35a1SLionel Sambuc prop_object_release(nd);
777*11be35a1SLionel Sambuc assert_no_ppath_extant();
778*11be35a1SLionel Sambuc assert_no_ppath_component_extant();
779*11be35a1SLionel Sambuc }
780*11be35a1SLionel Sambuc
781*11be35a1SLionel Sambuc ATF_TC(copyset_bool_success);
782*11be35a1SLionel Sambuc
ATF_TC_HEAD(copyset_bool_success,tc)783*11be35a1SLionel Sambuc ATF_TC_HEAD(copyset_bool_success, tc)
784*11be35a1SLionel Sambuc {
785*11be35a1SLionel Sambuc atf_tc_set_md_var(tc, "descr", "check ppath_copyset_bool() sets "
786*11be35a1SLionel Sambuc "the \"u.s. citizen\" property in the \"John Doe\" record in the "
787*11be35a1SLionel Sambuc "\"personnel\" property list to false and verifies the new value "
788*11be35a1SLionel Sambuc "in the new dictionary and that the old dictionary is unchanged");
789*11be35a1SLionel Sambuc }
790*11be35a1SLionel Sambuc
ATF_TC_BODY(copyset_bool_success,tc)791*11be35a1SLionel Sambuc ATF_TC_BODY(copyset_bool_success, tc)
792*11be35a1SLionel Sambuc {
793*11be35a1SLionel Sambuc char *oext, *next;
794*11be35a1SLionel Sambuc int rc;
795*11be35a1SLionel Sambuc bool v = false;
796*11be35a1SLionel Sambuc prop_dictionary_t d, od;
797*11be35a1SLionel Sambuc prop_object_t nd = NULL;
798*11be35a1SLionel Sambuc ppath_t *p;
799*11be35a1SLionel Sambuc
800*11be35a1SLionel Sambuc assert_no_ppath_extant();
801*11be35a1SLionel Sambuc assert_no_ppath_component_extant();
802*11be35a1SLionel Sambuc
803*11be35a1SLionel Sambuc if ((d = prop_dictionary_internalize(personnel)) == NULL)
804*11be35a1SLionel Sambuc atf_tc_fail("prop_dictionary_internalize failed");
805*11be35a1SLionel Sambuc od = prop_dictionary_copy(d);
806*11be35a1SLionel Sambuc
807*11be35a1SLionel Sambuc if (!dictionary_equals(od, d)) {
808*11be35a1SLionel Sambuc oext = prop_dictionary_externalize(od);
809*11be35a1SLionel Sambuc next = prop_dictionary_externalize(d);
810*11be35a1SLionel Sambuc atf_tc_fail("dictionaries are unequal from the outset, argh! "
811*11be35a1SLionel Sambuc "original\n%s\nnew\n%s", oext, next);
812*11be35a1SLionel Sambuc free(oext);
813*11be35a1SLionel Sambuc free(next);
814*11be35a1SLionel Sambuc }
815*11be35a1SLionel Sambuc
816*11be35a1SLionel Sambuc if ((p = ppath_create()) == NULL)
817*11be35a1SLionel Sambuc atf_tc_fail("ppath_create failed");
818*11be35a1SLionel Sambuc
819*11be35a1SLionel Sambuc if (ppath_push_key(p, "John Doe") == NULL)
820*11be35a1SLionel Sambuc atf_tc_fail("ppath_push_key failed");
821*11be35a1SLionel Sambuc if (ppath_push_key(p, "u.s. citizen") == NULL)
822*11be35a1SLionel Sambuc atf_tc_fail("ppath_push_key failed");
823*11be35a1SLionel Sambuc
824*11be35a1SLionel Sambuc v = false;
825*11be35a1SLionel Sambuc rc = ppath_get_bool(d, p, &v);
826*11be35a1SLionel Sambuc ATF_CHECK_EQ(rc, 0);
827*11be35a1SLionel Sambuc ATF_CHECK_EQ(v, true);
828*11be35a1SLionel Sambuc
829*11be35a1SLionel Sambuc rc = ppath_copyset_bool(d, &nd, p, false);
830*11be35a1SLionel Sambuc ATF_CHECK_EQ(rc, 0);
831*11be35a1SLionel Sambuc
832*11be35a1SLionel Sambuc v = true;
833*11be35a1SLionel Sambuc rc = ppath_get_bool(nd, p, &v);
834*11be35a1SLionel Sambuc ATF_CHECK_EQ(rc, 0);
835*11be35a1SLionel Sambuc ATF_CHECK_EQ(v, false);
836*11be35a1SLionel Sambuc
837*11be35a1SLionel Sambuc if (!dictionary_equals(od, d)) {
838*11be35a1SLionel Sambuc oext = prop_dictionary_externalize(od);
839*11be35a1SLionel Sambuc next = prop_dictionary_externalize(d);
840*11be35a1SLionel Sambuc atf_tc_fail("copyset modified original dictionary, "
841*11be35a1SLionel Sambuc "original\n%s\nnew\n%s", oext, next);
842*11be35a1SLionel Sambuc free(oext);
843*11be35a1SLionel Sambuc free(next);
844*11be35a1SLionel Sambuc }
845*11be35a1SLionel Sambuc
846*11be35a1SLionel Sambuc if (dictionary_equals(od, nd)) {
847*11be35a1SLionel Sambuc oext = prop_dictionary_externalize(od);
848*11be35a1SLionel Sambuc next = prop_dictionary_externalize(nd);
849*11be35a1SLionel Sambuc atf_tc_fail("copyset made no change to the new "
850*11be35a1SLionel Sambuc "dictionary, original\n%s\nnew\n%s", oext, next);
851*11be35a1SLionel Sambuc free(oext);
852*11be35a1SLionel Sambuc free(next);
853*11be35a1SLionel Sambuc }
854*11be35a1SLionel Sambuc
855*11be35a1SLionel Sambuc rc = ppath_set_bool(nd, p, true);
856*11be35a1SLionel Sambuc ATF_CHECK_EQ(rc, 0);
857*11be35a1SLionel Sambuc
858*11be35a1SLionel Sambuc if (!dictionary_equals(od, nd)) {
859*11be35a1SLionel Sambuc oext = prop_dictionary_externalize(od);
860*11be35a1SLionel Sambuc next = prop_dictionary_externalize(nd);
861*11be35a1SLionel Sambuc atf_tc_fail("copyset made an out-of-bounds change to the new "
862*11be35a1SLionel Sambuc "dictionary, original\n%s\nnew\n%s", oext, next);
863*11be35a1SLionel Sambuc free(oext);
864*11be35a1SLionel Sambuc free(next);
865*11be35a1SLionel Sambuc }
866*11be35a1SLionel Sambuc
867*11be35a1SLionel Sambuc ppath_release(p);
868*11be35a1SLionel Sambuc prop_object_release(d);
869*11be35a1SLionel Sambuc prop_object_release(od);
870*11be35a1SLionel Sambuc prop_object_release(nd);
871*11be35a1SLionel Sambuc assert_no_ppath_extant();
872*11be35a1SLionel Sambuc assert_no_ppath_component_extant();
873*11be35a1SLionel Sambuc }
874*11be35a1SLionel Sambuc
875*11be35a1SLionel Sambuc ATF_TC(set_bool_eftype);
876*11be35a1SLionel Sambuc
ATF_TC_HEAD(set_bool_eftype,tc)877*11be35a1SLionel Sambuc ATF_TC_HEAD(set_bool_eftype, tc)
878*11be35a1SLionel Sambuc {
879*11be35a1SLionel Sambuc atf_tc_set_md_var(tc, "descr", "check ppath_set_bool() does not "
880*11be35a1SLionel Sambuc "overwrite with a bool "
881*11be35a1SLionel Sambuc "the \"job title\" property in the \"John Doe\" record in "
882*11be35a1SLionel Sambuc "the "
883*11be35a1SLionel Sambuc "\"personnel\" property list");
884*11be35a1SLionel Sambuc }
885*11be35a1SLionel Sambuc
ATF_TC_BODY(set_bool_eftype,tc)886*11be35a1SLionel Sambuc ATF_TC_BODY(set_bool_eftype, tc)
887*11be35a1SLionel Sambuc {
888*11be35a1SLionel Sambuc int rc;
889*11be35a1SLionel Sambuc bool v = false;
890*11be35a1SLionel Sambuc prop_dictionary_t d;
891*11be35a1SLionel Sambuc ppath_t *p;
892*11be35a1SLionel Sambuc
893*11be35a1SLionel Sambuc assert_no_ppath_extant();
894*11be35a1SLionel Sambuc assert_no_ppath_component_extant();
895*11be35a1SLionel Sambuc
896*11be35a1SLionel Sambuc if ((d = prop_dictionary_internalize(personnel)) == NULL)
897*11be35a1SLionel Sambuc atf_tc_fail("prop_dictionary_internalize failed");
898*11be35a1SLionel Sambuc
899*11be35a1SLionel Sambuc if ((p = ppath_create()) == NULL)
900*11be35a1SLionel Sambuc atf_tc_fail("ppath_create failed");
901*11be35a1SLionel Sambuc
902*11be35a1SLionel Sambuc if (ppath_push_key(p, "John Doe") == NULL)
903*11be35a1SLionel Sambuc atf_tc_fail("ppath_push_key failed");
904*11be35a1SLionel Sambuc if (ppath_push_key(p, "job title") == NULL)
905*11be35a1SLionel Sambuc atf_tc_fail("ppath_push_key failed");
906*11be35a1SLionel Sambuc
907*11be35a1SLionel Sambuc v = false;
908*11be35a1SLionel Sambuc rc = ppath_get_bool(d, p, &v);
909*11be35a1SLionel Sambuc ATF_CHECK_EQ(rc, EFTYPE);
910*11be35a1SLionel Sambuc ATF_CHECK_EQ(v, false);
911*11be35a1SLionel Sambuc
912*11be35a1SLionel Sambuc rc = ppath_set_bool(d, p, false);
913*11be35a1SLionel Sambuc ATF_CHECK_EQ(rc, EFTYPE);
914*11be35a1SLionel Sambuc
915*11be35a1SLionel Sambuc v = true;
916*11be35a1SLionel Sambuc rc = ppath_get_bool(d, p, &v);
917*11be35a1SLionel Sambuc ATF_CHECK_EQ(rc, EFTYPE);
918*11be35a1SLionel Sambuc ATF_CHECK_EQ(v, true);
919*11be35a1SLionel Sambuc
920*11be35a1SLionel Sambuc ppath_release(p);
921*11be35a1SLionel Sambuc prop_object_release(d);
922*11be35a1SLionel Sambuc assert_no_ppath_extant();
923*11be35a1SLionel Sambuc assert_no_ppath_component_extant();
924*11be35a1SLionel Sambuc }
925*11be35a1SLionel Sambuc
926*11be35a1SLionel Sambuc ATF_TC(set_bool_enoent);
927*11be35a1SLionel Sambuc
ATF_TC_HEAD(set_bool_enoent,tc)928*11be35a1SLionel Sambuc ATF_TC_HEAD(set_bool_enoent, tc)
929*11be35a1SLionel Sambuc {
930*11be35a1SLionel Sambuc atf_tc_set_md_var(tc, "descr", "check ppath_set_bool() does not create "
931*11be35a1SLionel Sambuc "the \"russian citizen\" property in the \"John Doe\" record in "
932*11be35a1SLionel Sambuc "the "
933*11be35a1SLionel Sambuc "\"personnel\" property list");
934*11be35a1SLionel Sambuc }
935*11be35a1SLionel Sambuc
ATF_TC_BODY(set_bool_enoent,tc)936*11be35a1SLionel Sambuc ATF_TC_BODY(set_bool_enoent, tc)
937*11be35a1SLionel Sambuc {
938*11be35a1SLionel Sambuc int rc;
939*11be35a1SLionel Sambuc bool v = false;
940*11be35a1SLionel Sambuc prop_dictionary_t d;
941*11be35a1SLionel Sambuc ppath_t *p;
942*11be35a1SLionel Sambuc
943*11be35a1SLionel Sambuc assert_no_ppath_extant();
944*11be35a1SLionel Sambuc assert_no_ppath_component_extant();
945*11be35a1SLionel Sambuc
946*11be35a1SLionel Sambuc if ((d = prop_dictionary_internalize(personnel)) == NULL)
947*11be35a1SLionel Sambuc atf_tc_fail("prop_dictionary_internalize failed");
948*11be35a1SLionel Sambuc
949*11be35a1SLionel Sambuc if ((p = ppath_create()) == NULL)
950*11be35a1SLionel Sambuc atf_tc_fail("ppath_create failed");
951*11be35a1SLionel Sambuc
952*11be35a1SLionel Sambuc if (ppath_push_key(p, "John Doe") == NULL)
953*11be35a1SLionel Sambuc atf_tc_fail("ppath_push_key failed");
954*11be35a1SLionel Sambuc if (ppath_push_key(p, "russian citizen") == NULL)
955*11be35a1SLionel Sambuc atf_tc_fail("ppath_push_key failed");
956*11be35a1SLionel Sambuc
957*11be35a1SLionel Sambuc v = false;
958*11be35a1SLionel Sambuc rc = ppath_get_bool(d, p, &v);
959*11be35a1SLionel Sambuc ATF_CHECK_EQ(rc, ENOENT);
960*11be35a1SLionel Sambuc ATF_CHECK_EQ(v, false);
961*11be35a1SLionel Sambuc
962*11be35a1SLionel Sambuc rc = ppath_set_bool(d, p, false);
963*11be35a1SLionel Sambuc ATF_CHECK_EQ(rc, ENOENT);
964*11be35a1SLionel Sambuc
965*11be35a1SLionel Sambuc v = true;
966*11be35a1SLionel Sambuc rc = ppath_get_bool(d, p, &v);
967*11be35a1SLionel Sambuc ATF_CHECK_EQ(rc, ENOENT);
968*11be35a1SLionel Sambuc ATF_CHECK_EQ(v, true);
969*11be35a1SLionel Sambuc
970*11be35a1SLionel Sambuc ppath_release(p);
971*11be35a1SLionel Sambuc prop_object_release(d);
972*11be35a1SLionel Sambuc assert_no_ppath_extant();
973*11be35a1SLionel Sambuc assert_no_ppath_component_extant();
974*11be35a1SLionel Sambuc }
975*11be35a1SLionel Sambuc
976*11be35a1SLionel Sambuc ATF_TC(create_bool_eexist);
977*11be35a1SLionel Sambuc
ATF_TC_HEAD(create_bool_eexist,tc)978*11be35a1SLionel Sambuc ATF_TC_HEAD(create_bool_eexist, tc)
979*11be35a1SLionel Sambuc {
980*11be35a1SLionel Sambuc atf_tc_set_md_var(tc, "descr", "check ppath_create_bool() returns "
981*11be35a1SLionel Sambuc "EEXIST because the \"u.s. citizen\" property in the "
982*11be35a1SLionel Sambuc "\"John Doe\" record in the \"personnel\" property list "
983*11be35a1SLionel Sambuc "already exists");
984*11be35a1SLionel Sambuc }
985*11be35a1SLionel Sambuc
ATF_TC_BODY(create_bool_eexist,tc)986*11be35a1SLionel Sambuc ATF_TC_BODY(create_bool_eexist, tc)
987*11be35a1SLionel Sambuc {
988*11be35a1SLionel Sambuc int rc;
989*11be35a1SLionel Sambuc bool v = false;
990*11be35a1SLionel Sambuc prop_dictionary_t d;
991*11be35a1SLionel Sambuc ppath_t *p;
992*11be35a1SLionel Sambuc
993*11be35a1SLionel Sambuc assert_no_ppath_extant();
994*11be35a1SLionel Sambuc assert_no_ppath_component_extant();
995*11be35a1SLionel Sambuc
996*11be35a1SLionel Sambuc if ((d = prop_dictionary_internalize(personnel)) == NULL)
997*11be35a1SLionel Sambuc atf_tc_fail("prop_dictionary_internalize failed");
998*11be35a1SLionel Sambuc
999*11be35a1SLionel Sambuc if ((p = ppath_create()) == NULL)
1000*11be35a1SLionel Sambuc atf_tc_fail("ppath_create failed");
1001*11be35a1SLionel Sambuc
1002*11be35a1SLionel Sambuc if (ppath_push_key(p, "John Doe") == NULL)
1003*11be35a1SLionel Sambuc atf_tc_fail("ppath_push_key failed");
1004*11be35a1SLionel Sambuc if (ppath_push_key(p, "u.s. citizen") == NULL)
1005*11be35a1SLionel Sambuc atf_tc_fail("ppath_push_key failed");
1006*11be35a1SLionel Sambuc
1007*11be35a1SLionel Sambuc v = false;
1008*11be35a1SLionel Sambuc rc = ppath_get_bool(d, p, &v);
1009*11be35a1SLionel Sambuc ATF_CHECK_EQ(rc, 0);
1010*11be35a1SLionel Sambuc ATF_CHECK_EQ(v, true);
1011*11be35a1SLionel Sambuc
1012*11be35a1SLionel Sambuc rc = ppath_create_bool(d, p, false);
1013*11be35a1SLionel Sambuc ATF_CHECK_EQ(rc, EEXIST);
1014*11be35a1SLionel Sambuc
1015*11be35a1SLionel Sambuc v = false;
1016*11be35a1SLionel Sambuc rc = ppath_get_bool(d, p, &v);
1017*11be35a1SLionel Sambuc ATF_CHECK_EQ(rc, 0);
1018*11be35a1SLionel Sambuc ATF_CHECK_EQ(v, true);
1019*11be35a1SLionel Sambuc
1020*11be35a1SLionel Sambuc ppath_release(p);
1021*11be35a1SLionel Sambuc prop_object_release(d);
1022*11be35a1SLionel Sambuc assert_no_ppath_extant();
1023*11be35a1SLionel Sambuc assert_no_ppath_component_extant();
1024*11be35a1SLionel Sambuc }
1025*11be35a1SLionel Sambuc
1026*11be35a1SLionel Sambuc ATF_TC(create_bool_success);
1027*11be35a1SLionel Sambuc
ATF_TC_HEAD(create_bool_success,tc)1028*11be35a1SLionel Sambuc ATF_TC_HEAD(create_bool_success, tc)
1029*11be35a1SLionel Sambuc {
1030*11be35a1SLionel Sambuc atf_tc_set_md_var(tc, "descr", "check ppath_create_bool() creates "
1031*11be35a1SLionel Sambuc "the \"russian citizen\" property in the \"John Doe\" record in "
1032*11be35a1SLionel Sambuc "the \"personnel\" property list and sets it to false");
1033*11be35a1SLionel Sambuc }
1034*11be35a1SLionel Sambuc
ATF_TC_BODY(create_bool_success,tc)1035*11be35a1SLionel Sambuc ATF_TC_BODY(create_bool_success, tc)
1036*11be35a1SLionel Sambuc {
1037*11be35a1SLionel Sambuc int rc;
1038*11be35a1SLionel Sambuc bool v = false;
1039*11be35a1SLionel Sambuc prop_dictionary_t d;
1040*11be35a1SLionel Sambuc ppath_t *p;
1041*11be35a1SLionel Sambuc
1042*11be35a1SLionel Sambuc assert_no_ppath_extant();
1043*11be35a1SLionel Sambuc assert_no_ppath_component_extant();
1044*11be35a1SLionel Sambuc
1045*11be35a1SLionel Sambuc if ((d = prop_dictionary_internalize(personnel)) == NULL)
1046*11be35a1SLionel Sambuc atf_tc_fail("prop_dictionary_internalize failed");
1047*11be35a1SLionel Sambuc
1048*11be35a1SLionel Sambuc if ((p = ppath_create()) == NULL)
1049*11be35a1SLionel Sambuc atf_tc_fail("ppath_create failed");
1050*11be35a1SLionel Sambuc
1051*11be35a1SLionel Sambuc if (ppath_push_key(p, "John Doe") == NULL)
1052*11be35a1SLionel Sambuc atf_tc_fail("ppath_push_key failed");
1053*11be35a1SLionel Sambuc if (ppath_push_key(p, "russian citizen") == NULL)
1054*11be35a1SLionel Sambuc atf_tc_fail("ppath_push_key failed");
1055*11be35a1SLionel Sambuc
1056*11be35a1SLionel Sambuc v = false;
1057*11be35a1SLionel Sambuc rc = ppath_get_bool(d, p, &v);
1058*11be35a1SLionel Sambuc ATF_CHECK_EQ(rc, ENOENT);
1059*11be35a1SLionel Sambuc ATF_CHECK_EQ(v, false);
1060*11be35a1SLionel Sambuc
1061*11be35a1SLionel Sambuc rc = ppath_create_bool(d, p, false);
1062*11be35a1SLionel Sambuc ATF_CHECK_EQ(rc, 0);
1063*11be35a1SLionel Sambuc
1064*11be35a1SLionel Sambuc v = true;
1065*11be35a1SLionel Sambuc rc = ppath_get_bool(d, p, &v);
1066*11be35a1SLionel Sambuc ATF_CHECK_EQ(rc, 0);
1067*11be35a1SLionel Sambuc ATF_CHECK_EQ(v, false);
1068*11be35a1SLionel Sambuc
1069*11be35a1SLionel Sambuc ppath_release(p);
1070*11be35a1SLionel Sambuc prop_object_release(d);
1071*11be35a1SLionel Sambuc assert_no_ppath_extant();
1072*11be35a1SLionel Sambuc assert_no_ppath_component_extant();
1073*11be35a1SLionel Sambuc }
1074*11be35a1SLionel Sambuc
1075*11be35a1SLionel Sambuc ATF_TC(set_bool_success);
1076*11be35a1SLionel Sambuc
ATF_TC_HEAD(set_bool_success,tc)1077*11be35a1SLionel Sambuc ATF_TC_HEAD(set_bool_success, tc)
1078*11be35a1SLionel Sambuc {
1079*11be35a1SLionel Sambuc atf_tc_set_md_var(tc, "descr", "check ppath_set_bool() sets "
1080*11be35a1SLionel Sambuc "the \"u.s. citizen\" property in the \"John Doe\" record in the "
1081*11be35a1SLionel Sambuc "\"personnel\" property list to false and verifies the new value");
1082*11be35a1SLionel Sambuc }
1083*11be35a1SLionel Sambuc
ATF_TC_BODY(set_bool_success,tc)1084*11be35a1SLionel Sambuc ATF_TC_BODY(set_bool_success, tc)
1085*11be35a1SLionel Sambuc {
1086*11be35a1SLionel Sambuc int rc;
1087*11be35a1SLionel Sambuc bool v = false;
1088*11be35a1SLionel Sambuc prop_dictionary_t d;
1089*11be35a1SLionel Sambuc ppath_t *p;
1090*11be35a1SLionel Sambuc
1091*11be35a1SLionel Sambuc assert_no_ppath_extant();
1092*11be35a1SLionel Sambuc assert_no_ppath_component_extant();
1093*11be35a1SLionel Sambuc
1094*11be35a1SLionel Sambuc if ((d = prop_dictionary_internalize(personnel)) == NULL)
1095*11be35a1SLionel Sambuc atf_tc_fail("prop_dictionary_internalize failed");
1096*11be35a1SLionel Sambuc
1097*11be35a1SLionel Sambuc if ((p = ppath_create()) == NULL)
1098*11be35a1SLionel Sambuc atf_tc_fail("ppath_create failed");
1099*11be35a1SLionel Sambuc
1100*11be35a1SLionel Sambuc if (ppath_push_key(p, "John Doe") == NULL)
1101*11be35a1SLionel Sambuc atf_tc_fail("ppath_push_key failed");
1102*11be35a1SLionel Sambuc if (ppath_push_key(p, "u.s. citizen") == NULL)
1103*11be35a1SLionel Sambuc atf_tc_fail("ppath_push_key failed");
1104*11be35a1SLionel Sambuc
1105*11be35a1SLionel Sambuc v = false;
1106*11be35a1SLionel Sambuc rc = ppath_get_bool(d, p, &v);
1107*11be35a1SLionel Sambuc ATF_CHECK_EQ(rc, 0);
1108*11be35a1SLionel Sambuc ATF_CHECK_EQ(v, true);
1109*11be35a1SLionel Sambuc
1110*11be35a1SLionel Sambuc rc = ppath_set_bool(d, p, v);
1111*11be35a1SLionel Sambuc ATF_CHECK_EQ(rc, 0);
1112*11be35a1SLionel Sambuc
1113*11be35a1SLionel Sambuc v = true;
1114*11be35a1SLionel Sambuc rc = ppath_get_bool(d, p, &v);
1115*11be35a1SLionel Sambuc ATF_CHECK_EQ(rc, 0);
1116*11be35a1SLionel Sambuc ATF_CHECK_EQ(v, true);
1117*11be35a1SLionel Sambuc
1118*11be35a1SLionel Sambuc ppath_release(p);
1119*11be35a1SLionel Sambuc prop_object_release(d);
1120*11be35a1SLionel Sambuc assert_no_ppath_extant();
1121*11be35a1SLionel Sambuc assert_no_ppath_component_extant();
1122*11be35a1SLionel Sambuc }
1123*11be35a1SLionel Sambuc
1124*11be35a1SLionel Sambuc ATF_TC(get_bool_success);
1125*11be35a1SLionel Sambuc
ATF_TC_HEAD(get_bool_success,tc)1126*11be35a1SLionel Sambuc ATF_TC_HEAD(get_bool_success, tc)
1127*11be35a1SLionel Sambuc {
1128*11be35a1SLionel Sambuc atf_tc_set_md_var(tc, "descr", "check ppath_get_bool() fetches "
1129*11be35a1SLionel Sambuc "the \"u.s. citizen\" property from the \"John Doe\" record in the "
1130*11be35a1SLionel Sambuc "\"personnel\" property list, and compares it with the expected "
1131*11be35a1SLionel Sambuc "value, true");
1132*11be35a1SLionel Sambuc }
1133*11be35a1SLionel Sambuc
ATF_TC_BODY(get_bool_success,tc)1134*11be35a1SLionel Sambuc ATF_TC_BODY(get_bool_success, tc)
1135*11be35a1SLionel Sambuc {
1136*11be35a1SLionel Sambuc int rc;
1137*11be35a1SLionel Sambuc bool v = false;
1138*11be35a1SLionel Sambuc prop_dictionary_t d;
1139*11be35a1SLionel Sambuc ppath_t *p;
1140*11be35a1SLionel Sambuc
1141*11be35a1SLionel Sambuc assert_no_ppath_extant();
1142*11be35a1SLionel Sambuc assert_no_ppath_component_extant();
1143*11be35a1SLionel Sambuc
1144*11be35a1SLionel Sambuc if ((d = prop_dictionary_internalize(personnel)) == NULL)
1145*11be35a1SLionel Sambuc atf_tc_fail("prop_dictionary_internalize failed");
1146*11be35a1SLionel Sambuc
1147*11be35a1SLionel Sambuc if ((p = ppath_create()) == NULL)
1148*11be35a1SLionel Sambuc atf_tc_fail("ppath_create failed");
1149*11be35a1SLionel Sambuc
1150*11be35a1SLionel Sambuc if (ppath_push_key(p, "John Doe") == NULL)
1151*11be35a1SLionel Sambuc atf_tc_fail("ppath_push_key failed");
1152*11be35a1SLionel Sambuc if (ppath_push_key(p, "u.s. citizen") == NULL)
1153*11be35a1SLionel Sambuc atf_tc_fail("ppath_push_key failed");
1154*11be35a1SLionel Sambuc
1155*11be35a1SLionel Sambuc rc = ppath_get_bool(d, p, &v);
1156*11be35a1SLionel Sambuc ATF_CHECK_EQ(rc, 0);
1157*11be35a1SLionel Sambuc ATF_CHECK_EQ(v, true);
1158*11be35a1SLionel Sambuc
1159*11be35a1SLionel Sambuc ppath_release(p);
1160*11be35a1SLionel Sambuc prop_object_release(d);
1161*11be35a1SLionel Sambuc assert_no_ppath_extant();
1162*11be35a1SLionel Sambuc assert_no_ppath_component_extant();
1163*11be35a1SLionel Sambuc }
1164*11be35a1SLionel Sambuc
1165*11be35a1SLionel Sambuc ATF_TC(delete_bool_success);
1166*11be35a1SLionel Sambuc
ATF_TC_HEAD(delete_bool_success,tc)1167*11be35a1SLionel Sambuc ATF_TC_HEAD(delete_bool_success, tc)
1168*11be35a1SLionel Sambuc {
1169*11be35a1SLionel Sambuc atf_tc_set_md_var(tc, "descr", "check ppath_delete_bool() succeeds "
1170*11be35a1SLionel Sambuc "for the path (\"John Doe\", \"u.s. citizen\") in the "
1171*11be35a1SLionel Sambuc "\"personnel\" property list");
1172*11be35a1SLionel Sambuc }
1173*11be35a1SLionel Sambuc
ATF_TC_BODY(delete_bool_success,tc)1174*11be35a1SLionel Sambuc ATF_TC_BODY(delete_bool_success, tc)
1175*11be35a1SLionel Sambuc {
1176*11be35a1SLionel Sambuc int rc;
1177*11be35a1SLionel Sambuc prop_dictionary_t d;
1178*11be35a1SLionel Sambuc ppath_t *p;
1179*11be35a1SLionel Sambuc
1180*11be35a1SLionel Sambuc assert_no_ppath_extant();
1181*11be35a1SLionel Sambuc assert_no_ppath_component_extant();
1182*11be35a1SLionel Sambuc
1183*11be35a1SLionel Sambuc if ((d = prop_dictionary_internalize(personnel)) == NULL)
1184*11be35a1SLionel Sambuc atf_tc_fail("prop_dictionary_internalize failed");
1185*11be35a1SLionel Sambuc
1186*11be35a1SLionel Sambuc if ((p = ppath_create()) == NULL)
1187*11be35a1SLionel Sambuc atf_tc_fail("ppath_create failed");
1188*11be35a1SLionel Sambuc
1189*11be35a1SLionel Sambuc if (ppath_push_key(p, "John Doe") == NULL)
1190*11be35a1SLionel Sambuc atf_tc_fail("ppath_push_key failed");
1191*11be35a1SLionel Sambuc if (ppath_push_key(p, "u.s. citizen") == NULL)
1192*11be35a1SLionel Sambuc atf_tc_fail("ppath_push_key failed");
1193*11be35a1SLionel Sambuc
1194*11be35a1SLionel Sambuc rc = ppath_delete_bool(d, p);
1195*11be35a1SLionel Sambuc ATF_CHECK_EQ(rc, 0);
1196*11be35a1SLionel Sambuc
1197*11be35a1SLionel Sambuc rc = ppath_get_bool(d, p, NULL);
1198*11be35a1SLionel Sambuc ATF_CHECK_EQ(rc, ENOENT);
1199*11be35a1SLionel Sambuc
1200*11be35a1SLionel Sambuc ppath_release(p);
1201*11be35a1SLionel Sambuc prop_object_release(d);
1202*11be35a1SLionel Sambuc assert_no_ppath_extant();
1203*11be35a1SLionel Sambuc assert_no_ppath_component_extant();
1204*11be35a1SLionel Sambuc }
1205*11be35a1SLionel Sambuc
1206*11be35a1SLionel Sambuc ATF_TC(delete_bool_eftype);
1207*11be35a1SLionel Sambuc
ATF_TC_HEAD(delete_bool_eftype,tc)1208*11be35a1SLionel Sambuc ATF_TC_HEAD(delete_bool_eftype, tc)
1209*11be35a1SLionel Sambuc {
1210*11be35a1SLionel Sambuc atf_tc_set_md_var(tc, "descr", "check ppath_delete_bool() returns "
1211*11be35a1SLionel Sambuc "EFTYPE for the path (\"John Doe\", \"job title\") in the "
1212*11be35a1SLionel Sambuc "\"personnel\" property list and does not delete the path");
1213*11be35a1SLionel Sambuc }
1214*11be35a1SLionel Sambuc
ATF_TC_BODY(delete_bool_eftype,tc)1215*11be35a1SLionel Sambuc ATF_TC_BODY(delete_bool_eftype, tc)
1216*11be35a1SLionel Sambuc {
1217*11be35a1SLionel Sambuc int rc;
1218*11be35a1SLionel Sambuc prop_dictionary_t d;
1219*11be35a1SLionel Sambuc ppath_t *p;
1220*11be35a1SLionel Sambuc
1221*11be35a1SLionel Sambuc assert_no_ppath_extant();
1222*11be35a1SLionel Sambuc assert_no_ppath_component_extant();
1223*11be35a1SLionel Sambuc
1224*11be35a1SLionel Sambuc if ((d = prop_dictionary_internalize(personnel)) == NULL)
1225*11be35a1SLionel Sambuc atf_tc_fail("prop_dictionary_internalize failed");
1226*11be35a1SLionel Sambuc
1227*11be35a1SLionel Sambuc if ((p = ppath_create()) == NULL)
1228*11be35a1SLionel Sambuc atf_tc_fail("ppath_create failed");
1229*11be35a1SLionel Sambuc
1230*11be35a1SLionel Sambuc if (ppath_push_key(p, "John Doe") == NULL)
1231*11be35a1SLionel Sambuc atf_tc_fail("ppath_push_key failed");
1232*11be35a1SLionel Sambuc if (ppath_push_key(p, "job title") == NULL)
1233*11be35a1SLionel Sambuc atf_tc_fail("ppath_push_key failed");
1234*11be35a1SLionel Sambuc
1235*11be35a1SLionel Sambuc rc = ppath_delete_bool(d, p);
1236*11be35a1SLionel Sambuc ATF_CHECK_EQ(rc, EFTYPE);
1237*11be35a1SLionel Sambuc
1238*11be35a1SLionel Sambuc rc = ppath_get_object(d, p, NULL);
1239*11be35a1SLionel Sambuc ATF_CHECK_EQ(rc, 0);
1240*11be35a1SLionel Sambuc
1241*11be35a1SLionel Sambuc ppath_release(p);
1242*11be35a1SLionel Sambuc prop_object_release(d);
1243*11be35a1SLionel Sambuc assert_no_ppath_extant();
1244*11be35a1SLionel Sambuc assert_no_ppath_component_extant();
1245*11be35a1SLionel Sambuc }
1246*11be35a1SLionel Sambuc
1247*11be35a1SLionel Sambuc ATF_TC(delete_bool_enoent);
1248*11be35a1SLionel Sambuc
ATF_TC_HEAD(delete_bool_enoent,tc)1249*11be35a1SLionel Sambuc ATF_TC_HEAD(delete_bool_enoent, tc)
1250*11be35a1SLionel Sambuc {
1251*11be35a1SLionel Sambuc atf_tc_set_md_var(tc, "descr", "check ppath_delete_bool() returns "
1252*11be35a1SLionel Sambuc "ENOENT for the path (\"John Doe\", \"citizen\") in the "
1253*11be35a1SLionel Sambuc "\"personnel\" property list");
1254*11be35a1SLionel Sambuc }
1255*11be35a1SLionel Sambuc
ATF_TC_BODY(delete_bool_enoent,tc)1256*11be35a1SLionel Sambuc ATF_TC_BODY(delete_bool_enoent, tc)
1257*11be35a1SLionel Sambuc {
1258*11be35a1SLionel Sambuc int rc;
1259*11be35a1SLionel Sambuc prop_dictionary_t d;
1260*11be35a1SLionel Sambuc ppath_t *p;
1261*11be35a1SLionel Sambuc
1262*11be35a1SLionel Sambuc assert_no_ppath_extant();
1263*11be35a1SLionel Sambuc assert_no_ppath_component_extant();
1264*11be35a1SLionel Sambuc
1265*11be35a1SLionel Sambuc if ((d = prop_dictionary_internalize(personnel)) == NULL)
1266*11be35a1SLionel Sambuc atf_tc_fail("prop_dictionary_internalize failed");
1267*11be35a1SLionel Sambuc
1268*11be35a1SLionel Sambuc if ((p = ppath_create()) == NULL)
1269*11be35a1SLionel Sambuc atf_tc_fail("ppath_create failed");
1270*11be35a1SLionel Sambuc
1271*11be35a1SLionel Sambuc if (ppath_push_key(p, "John Doe") == NULL)
1272*11be35a1SLionel Sambuc atf_tc_fail("ppath_push_key failed");
1273*11be35a1SLionel Sambuc if (ppath_push_key(p, "citizen") == NULL)
1274*11be35a1SLionel Sambuc atf_tc_fail("ppath_push_key failed");
1275*11be35a1SLionel Sambuc
1276*11be35a1SLionel Sambuc rc = ppath_delete_bool(d, p);
1277*11be35a1SLionel Sambuc ATF_CHECK_EQ(rc, ENOENT);
1278*11be35a1SLionel Sambuc
1279*11be35a1SLionel Sambuc ppath_release(p);
1280*11be35a1SLionel Sambuc prop_object_release(d);
1281*11be35a1SLionel Sambuc assert_no_ppath_extant();
1282*11be35a1SLionel Sambuc assert_no_ppath_component_extant();
1283*11be35a1SLionel Sambuc }
1284*11be35a1SLionel Sambuc
1285*11be35a1SLionel Sambuc ATF_TC(get_bool_enoent);
1286*11be35a1SLionel Sambuc
ATF_TC_HEAD(get_bool_enoent,tc)1287*11be35a1SLionel Sambuc ATF_TC_HEAD(get_bool_enoent, tc)
1288*11be35a1SLionel Sambuc {
1289*11be35a1SLionel Sambuc atf_tc_set_md_var(tc, "descr", "check ppath_get_bool() returns "
1290*11be35a1SLionel Sambuc "ENOENT for the path (\"John Doe\", \"citizen\") in the "
1291*11be35a1SLionel Sambuc "\"personnel\" property list, and the bool * argument is "
1292*11be35a1SLionel Sambuc "unchanged");
1293*11be35a1SLionel Sambuc }
1294*11be35a1SLionel Sambuc
ATF_TC_BODY(get_bool_enoent,tc)1295*11be35a1SLionel Sambuc ATF_TC_BODY(get_bool_enoent, tc)
1296*11be35a1SLionel Sambuc {
1297*11be35a1SLionel Sambuc int rc;
1298*11be35a1SLionel Sambuc bool v;
1299*11be35a1SLionel Sambuc prop_dictionary_t d;
1300*11be35a1SLionel Sambuc ppath_t *p;
1301*11be35a1SLionel Sambuc
1302*11be35a1SLionel Sambuc assert_no_ppath_extant();
1303*11be35a1SLionel Sambuc assert_no_ppath_component_extant();
1304*11be35a1SLionel Sambuc
1305*11be35a1SLionel Sambuc if ((d = prop_dictionary_internalize(personnel)) == NULL)
1306*11be35a1SLionel Sambuc atf_tc_fail("prop_dictionary_internalize failed");
1307*11be35a1SLionel Sambuc
1308*11be35a1SLionel Sambuc if ((p = ppath_create()) == NULL)
1309*11be35a1SLionel Sambuc atf_tc_fail("ppath_create failed");
1310*11be35a1SLionel Sambuc
1311*11be35a1SLionel Sambuc if (ppath_push_key(p, "John Doe") == NULL)
1312*11be35a1SLionel Sambuc atf_tc_fail("ppath_push_key failed");
1313*11be35a1SLionel Sambuc if (ppath_push_key(p, "citizen") == NULL)
1314*11be35a1SLionel Sambuc atf_tc_fail("ppath_push_key failed");
1315*11be35a1SLionel Sambuc
1316*11be35a1SLionel Sambuc v = true;
1317*11be35a1SLionel Sambuc rc = ppath_get_bool(d, p, &v);
1318*11be35a1SLionel Sambuc ATF_CHECK_EQ(rc, ENOENT);
1319*11be35a1SLionel Sambuc ATF_CHECK_EQ(v, true);
1320*11be35a1SLionel Sambuc
1321*11be35a1SLionel Sambuc v = false;
1322*11be35a1SLionel Sambuc rc = ppath_get_bool(d, p, &v);
1323*11be35a1SLionel Sambuc ATF_CHECK_EQ(rc, ENOENT);
1324*11be35a1SLionel Sambuc ATF_CHECK_EQ(v, false);
1325*11be35a1SLionel Sambuc
1326*11be35a1SLionel Sambuc ppath_release(p);
1327*11be35a1SLionel Sambuc prop_object_release(d);
1328*11be35a1SLionel Sambuc assert_no_ppath_extant();
1329*11be35a1SLionel Sambuc assert_no_ppath_component_extant();
1330*11be35a1SLionel Sambuc }
1331*11be35a1SLionel Sambuc
1332*11be35a1SLionel Sambuc ATF_TC(get_bool_eftype);
1333*11be35a1SLionel Sambuc
ATF_TC_HEAD(get_bool_eftype,tc)1334*11be35a1SLionel Sambuc ATF_TC_HEAD(get_bool_eftype, tc)
1335*11be35a1SLionel Sambuc {
1336*11be35a1SLionel Sambuc atf_tc_set_md_var(tc, "descr", "check ppath_get_bool() returns "
1337*11be35a1SLionel Sambuc "EFTYPE for the path (\"John Doe\", \"job title\") in the "
1338*11be35a1SLionel Sambuc "\"personnel\" property list, and the bool * argument is "
1339*11be35a1SLionel Sambuc "unchanged");
1340*11be35a1SLionel Sambuc }
1341*11be35a1SLionel Sambuc
ATF_TC_BODY(get_bool_eftype,tc)1342*11be35a1SLionel Sambuc ATF_TC_BODY(get_bool_eftype, tc)
1343*11be35a1SLionel Sambuc {
1344*11be35a1SLionel Sambuc int rc;
1345*11be35a1SLionel Sambuc bool v;
1346*11be35a1SLionel Sambuc prop_dictionary_t d;
1347*11be35a1SLionel Sambuc ppath_t *p;
1348*11be35a1SLionel Sambuc
1349*11be35a1SLionel Sambuc assert_no_ppath_extant();
1350*11be35a1SLionel Sambuc assert_no_ppath_component_extant();
1351*11be35a1SLionel Sambuc
1352*11be35a1SLionel Sambuc if ((d = prop_dictionary_internalize(personnel)) == NULL)
1353*11be35a1SLionel Sambuc atf_tc_fail("prop_dictionary_internalize failed");
1354*11be35a1SLionel Sambuc
1355*11be35a1SLionel Sambuc if ((p = ppath_create()) == NULL)
1356*11be35a1SLionel Sambuc atf_tc_fail("ppath_create failed");
1357*11be35a1SLionel Sambuc
1358*11be35a1SLionel Sambuc if (ppath_push_key(p, "John Doe") == NULL)
1359*11be35a1SLionel Sambuc atf_tc_fail("ppath_push_key failed");
1360*11be35a1SLionel Sambuc if (ppath_push_key(p, "job title") == NULL)
1361*11be35a1SLionel Sambuc atf_tc_fail("ppath_push_key failed");
1362*11be35a1SLionel Sambuc
1363*11be35a1SLionel Sambuc v = true;
1364*11be35a1SLionel Sambuc rc = ppath_get_bool(d, p, &v);
1365*11be35a1SLionel Sambuc ATF_CHECK_EQ(rc, EFTYPE);
1366*11be35a1SLionel Sambuc ATF_CHECK_EQ(v, true);
1367*11be35a1SLionel Sambuc
1368*11be35a1SLionel Sambuc v = false;
1369*11be35a1SLionel Sambuc rc = ppath_get_bool(d, p, &v);
1370*11be35a1SLionel Sambuc ATF_CHECK_EQ(rc, EFTYPE);
1371*11be35a1SLionel Sambuc ATF_CHECK_EQ(v, false);
1372*11be35a1SLionel Sambuc
1373*11be35a1SLionel Sambuc ppath_release(p);
1374*11be35a1SLionel Sambuc prop_object_release(d);
1375*11be35a1SLionel Sambuc assert_no_ppath_extant();
1376*11be35a1SLionel Sambuc assert_no_ppath_component_extant();
1377*11be35a1SLionel Sambuc }
1378*11be35a1SLionel Sambuc
1379*11be35a1SLionel Sambuc ATF_TC(get_string_eftype);
1380*11be35a1SLionel Sambuc
ATF_TC_HEAD(get_string_eftype,tc)1381*11be35a1SLionel Sambuc ATF_TC_HEAD(get_string_eftype, tc)
1382*11be35a1SLionel Sambuc {
1383*11be35a1SLionel Sambuc atf_tc_set_md_var(tc, "descr", "check ppath_get_string() returns "
1384*11be35a1SLionel Sambuc "EFTYPE for the path (\"John Doe\", \"u.s. citizen\") in the "
1385*11be35a1SLionel Sambuc "\"personnel\" property list, and the const char ** argument is "
1386*11be35a1SLionel Sambuc "unchanged");
1387*11be35a1SLionel Sambuc }
1388*11be35a1SLionel Sambuc
ATF_TC_BODY(get_string_eftype,tc)1389*11be35a1SLionel Sambuc ATF_TC_BODY(get_string_eftype, tc)
1390*11be35a1SLionel Sambuc {
1391*11be35a1SLionel Sambuc int rc;
1392*11be35a1SLionel Sambuc const char *v;
1393*11be35a1SLionel Sambuc prop_dictionary_t d;
1394*11be35a1SLionel Sambuc ppath_t *p;
1395*11be35a1SLionel Sambuc
1396*11be35a1SLionel Sambuc assert_no_ppath_extant();
1397*11be35a1SLionel Sambuc assert_no_ppath_component_extant();
1398*11be35a1SLionel Sambuc
1399*11be35a1SLionel Sambuc if ((d = prop_dictionary_internalize(personnel)) == NULL)
1400*11be35a1SLionel Sambuc atf_tc_fail("prop_dictionary_internalize failed");
1401*11be35a1SLionel Sambuc
1402*11be35a1SLionel Sambuc if ((p = ppath_create()) == NULL)
1403*11be35a1SLionel Sambuc atf_tc_fail("ppath_create failed");
1404*11be35a1SLionel Sambuc
1405*11be35a1SLionel Sambuc if (ppath_push_key(p, "John Doe") == NULL)
1406*11be35a1SLionel Sambuc atf_tc_fail("ppath_push_key failed");
1407*11be35a1SLionel Sambuc if (ppath_push_key(p, "u.s. citizen") == NULL)
1408*11be35a1SLionel Sambuc atf_tc_fail("ppath_push_key failed");
1409*11be35a1SLionel Sambuc
1410*11be35a1SLionel Sambuc v = NULL;
1411*11be35a1SLionel Sambuc rc = ppath_get_string(d, p, &v);
1412*11be35a1SLionel Sambuc ATF_CHECK_EQ(rc, EFTYPE);
1413*11be35a1SLionel Sambuc ATF_CHECK_EQ(v, NULL);
1414*11be35a1SLionel Sambuc
1415*11be35a1SLionel Sambuc v = "xyz";
1416*11be35a1SLionel Sambuc rc = ppath_get_string(d, p, &v);
1417*11be35a1SLionel Sambuc ATF_CHECK_EQ(rc, EFTYPE);
1418*11be35a1SLionel Sambuc ATF_CHECK_STREQ(v, "xyz");
1419*11be35a1SLionel Sambuc
1420*11be35a1SLionel Sambuc ppath_release(p);
1421*11be35a1SLionel Sambuc prop_object_release(d);
1422*11be35a1SLionel Sambuc assert_no_ppath_extant();
1423*11be35a1SLionel Sambuc assert_no_ppath_component_extant();
1424*11be35a1SLionel Sambuc }
1425*11be35a1SLionel Sambuc
1426*11be35a1SLionel Sambuc ATF_TC(get_string_enoent);
1427*11be35a1SLionel Sambuc
ATF_TC_HEAD(get_string_enoent,tc)1428*11be35a1SLionel Sambuc ATF_TC_HEAD(get_string_enoent, tc)
1429*11be35a1SLionel Sambuc {
1430*11be35a1SLionel Sambuc atf_tc_set_md_var(tc, "descr", "check ppath_get_string() returns "
1431*11be35a1SLionel Sambuc "ENOENT for the path (\"John Doe\", \"title\") in the "
1432*11be35a1SLionel Sambuc "\"personnel\" property list, and the const char ** argument is "
1433*11be35a1SLionel Sambuc "unchanged");
1434*11be35a1SLionel Sambuc }
1435*11be35a1SLionel Sambuc
ATF_TC_BODY(get_string_enoent,tc)1436*11be35a1SLionel Sambuc ATF_TC_BODY(get_string_enoent, tc)
1437*11be35a1SLionel Sambuc {
1438*11be35a1SLionel Sambuc int rc;
1439*11be35a1SLionel Sambuc const char *v;
1440*11be35a1SLionel Sambuc prop_dictionary_t d;
1441*11be35a1SLionel Sambuc ppath_t *p;
1442*11be35a1SLionel Sambuc
1443*11be35a1SLionel Sambuc assert_no_ppath_extant();
1444*11be35a1SLionel Sambuc assert_no_ppath_component_extant();
1445*11be35a1SLionel Sambuc
1446*11be35a1SLionel Sambuc if ((d = prop_dictionary_internalize(personnel)) == NULL)
1447*11be35a1SLionel Sambuc atf_tc_fail("prop_dictionary_internalize failed");
1448*11be35a1SLionel Sambuc
1449*11be35a1SLionel Sambuc if ((p = ppath_create()) == NULL)
1450*11be35a1SLionel Sambuc atf_tc_fail("ppath_create failed");
1451*11be35a1SLionel Sambuc
1452*11be35a1SLionel Sambuc if (ppath_push_key(p, "John Doe") == NULL)
1453*11be35a1SLionel Sambuc atf_tc_fail("ppath_push_key failed");
1454*11be35a1SLionel Sambuc if (ppath_push_key(p, "title") == NULL)
1455*11be35a1SLionel Sambuc atf_tc_fail("ppath_push_key failed");
1456*11be35a1SLionel Sambuc
1457*11be35a1SLionel Sambuc v = NULL;
1458*11be35a1SLionel Sambuc rc = ppath_get_string(d, p, &v);
1459*11be35a1SLionel Sambuc ATF_CHECK_EQ(rc, ENOENT);
1460*11be35a1SLionel Sambuc ATF_CHECK_EQ(v, NULL);
1461*11be35a1SLionel Sambuc
1462*11be35a1SLionel Sambuc v = "xyz";
1463*11be35a1SLionel Sambuc rc = ppath_get_string(d, p, &v);
1464*11be35a1SLionel Sambuc ATF_CHECK_EQ(rc, ENOENT);
1465*11be35a1SLionel Sambuc ATF_CHECK_STREQ(v, "xyz");
1466*11be35a1SLionel Sambuc
1467*11be35a1SLionel Sambuc ppath_release(p);
1468*11be35a1SLionel Sambuc prop_object_release(d);
1469*11be35a1SLionel Sambuc assert_no_ppath_extant();
1470*11be35a1SLionel Sambuc assert_no_ppath_component_extant();
1471*11be35a1SLionel Sambuc }
1472*11be35a1SLionel Sambuc
1473*11be35a1SLionel Sambuc ATF_TC(get_string_success);
1474*11be35a1SLionel Sambuc
ATF_TC_HEAD(get_string_success,tc)1475*11be35a1SLionel Sambuc ATF_TC_HEAD(get_string_success, tc)
1476*11be35a1SLionel Sambuc {
1477*11be35a1SLionel Sambuc atf_tc_set_md_var(tc, "descr", "check ppath_get_string() fetches "
1478*11be35a1SLionel Sambuc "the \"job title\" property from the \"John Doe\" record in the "
1479*11be35a1SLionel Sambuc "\"personnel\" property list and compares it with the expected "
1480*11be35a1SLionel Sambuc "value, \"computer programmer\"");
1481*11be35a1SLionel Sambuc }
1482*11be35a1SLionel Sambuc
ATF_TC_BODY(get_string_success,tc)1483*11be35a1SLionel Sambuc ATF_TC_BODY(get_string_success, tc)
1484*11be35a1SLionel Sambuc {
1485*11be35a1SLionel Sambuc int rc;
1486*11be35a1SLionel Sambuc const char *v = NULL;;
1487*11be35a1SLionel Sambuc prop_dictionary_t d;
1488*11be35a1SLionel Sambuc ppath_t *p;
1489*11be35a1SLionel Sambuc
1490*11be35a1SLionel Sambuc assert_no_ppath_extant();
1491*11be35a1SLionel Sambuc assert_no_ppath_component_extant();
1492*11be35a1SLionel Sambuc
1493*11be35a1SLionel Sambuc if ((d = prop_dictionary_internalize(personnel)) == NULL)
1494*11be35a1SLionel Sambuc atf_tc_fail("prop_dictionary_internalize failed");
1495*11be35a1SLionel Sambuc
1496*11be35a1SLionel Sambuc if ((p = ppath_create()) == NULL)
1497*11be35a1SLionel Sambuc atf_tc_fail("ppath_create failed");
1498*11be35a1SLionel Sambuc
1499*11be35a1SLionel Sambuc if (ppath_push_key(p, "John Doe") == NULL)
1500*11be35a1SLionel Sambuc atf_tc_fail("ppath_push_key failed");
1501*11be35a1SLionel Sambuc if (ppath_push_key(p, "job title") == NULL)
1502*11be35a1SLionel Sambuc atf_tc_fail("ppath_push_key failed");
1503*11be35a1SLionel Sambuc
1504*11be35a1SLionel Sambuc rc = ppath_get_string(d, p, &v);
1505*11be35a1SLionel Sambuc ATF_CHECK_EQ(rc, 0);
1506*11be35a1SLionel Sambuc ATF_CHECK_STREQ(v, "computer programmer");
1507*11be35a1SLionel Sambuc
1508*11be35a1SLionel Sambuc ppath_release(p);
1509*11be35a1SLionel Sambuc prop_object_release(d);
1510*11be35a1SLionel Sambuc assert_no_ppath_extant();
1511*11be35a1SLionel Sambuc assert_no_ppath_component_extant();
1512*11be35a1SLionel Sambuc }
1513*11be35a1SLionel Sambuc
ATF_TP_ADD_TCS(tp)1514*11be35a1SLionel Sambuc ATF_TP_ADD_TCS(tp)
1515*11be35a1SLionel Sambuc {
1516*11be35a1SLionel Sambuc
1517*11be35a1SLionel Sambuc ATF_TP_ADD_TC(tp, push_until_full);
1518*11be35a1SLionel Sambuc ATF_TP_ADD_TC(tp, pop_until_empty);
1519*11be35a1SLionel Sambuc ATF_TP_ADD_TC(tp, length);
1520*11be35a1SLionel Sambuc ATF_TP_ADD_TC(tp, component_at);
1521*11be35a1SLionel Sambuc ATF_TP_ADD_TC(tp, get_idx_key);
1522*11be35a1SLionel Sambuc ATF_TP_ADD_TC(tp, ppath_copy);
1523*11be35a1SLionel Sambuc ATF_TP_ADD_TC(tp, replace);
1524*11be35a1SLionel Sambuc
1525*11be35a1SLionel Sambuc ATF_TP_ADD_TC(tp, delete_bool_eftype);
1526*11be35a1SLionel Sambuc ATF_TP_ADD_TC(tp, delete_bool_enoent);
1527*11be35a1SLionel Sambuc ATF_TP_ADD_TC(tp, delete_bool_success);
1528*11be35a1SLionel Sambuc
1529*11be35a1SLionel Sambuc ATF_TP_ADD_TC(tp, get_bool_eftype);
1530*11be35a1SLionel Sambuc ATF_TP_ADD_TC(tp, get_bool_enoent);
1531*11be35a1SLionel Sambuc ATF_TP_ADD_TC(tp, get_bool_success);
1532*11be35a1SLionel Sambuc
1533*11be35a1SLionel Sambuc ATF_TP_ADD_TC(tp, copydel_bool_success);
1534*11be35a1SLionel Sambuc ATF_TP_ADD_TC(tp, copydel_object_twice_success);
1535*11be35a1SLionel Sambuc ATF_TP_ADD_TC(tp, copyset_object_twice_success);
1536*11be35a1SLionel Sambuc ATF_TP_ADD_TC(tp, copyset_bool_success);
1537*11be35a1SLionel Sambuc ATF_TP_ADD_TC(tp, create_bool_eexist);
1538*11be35a1SLionel Sambuc ATF_TP_ADD_TC(tp, create_bool_success);
1539*11be35a1SLionel Sambuc ATF_TP_ADD_TC(tp, set_bool_enoent);
1540*11be35a1SLionel Sambuc ATF_TP_ADD_TC(tp, set_bool_eftype);
1541*11be35a1SLionel Sambuc ATF_TP_ADD_TC(tp, set_bool_success);
1542*11be35a1SLionel Sambuc
1543*11be35a1SLionel Sambuc ATF_TP_ADD_TC(tp, get_string_eftype);
1544*11be35a1SLionel Sambuc ATF_TP_ADD_TC(tp, get_string_enoent);
1545*11be35a1SLionel Sambuc ATF_TP_ADD_TC(tp, get_string_success);
1546*11be35a1SLionel Sambuc
1547*11be35a1SLionel Sambuc return atf_no_error();
1548*11be35a1SLionel Sambuc }
1549