if ((p = ppath_create()) == NULL)
atf_tc_fail("ppath_create failed");
if ((pc = ppath_idx(0)) == NULL)
atf_tc_fail("ppath_idx failed");
for (i = 0; i < PPATH_MAX_COMPONENTS; i++) {
len = ppath_length(p);
ATF_CHECK_EQ(len, i);
rp = ppath_push(p, pc);
ATF_CHECK_EQ(rp, p);
}
for (i = 0; i < PPATH_MAX_COMPONENTS; i++) {
len = ppath_length(p);
ATF_CHECK_EQ(len, PPATH_MAX_COMPONENTS - i);
rp = ppath_pop(p, NULL);
ATF_CHECK_EQ(rp, p);
}
ppath_component_release(pc);
ppath_release(p);
if ((p = ppath_create()) == NULL)
atf_tc_fail("ppath_create failed");
for (i = 0; i < PPATH_MAX_COMPONENTS; i++) {
if ((pc = ppath_idx(i)) == NULL)
atf_tc_fail("ppath_idx failed");
rp = ppath_push(p, pc);
ppath_component_release(pc);
ATF_CHECK_EQ(rp, p);
}
for (i = 0; i < PPATH_MAX_COMPONENTS; i++) {
pc = ppath_component_at(p, i);
ATF_CHECK_EQ(ppath_component_idx(pc), (int)i);
ppath_component_release(pc);
}
ppath_release(p);
ATF_TC_HEAD(get_idx_key, tc)
{
atf_tc_set_md_var(tc, "descr", "check that ppath_component_idx() "
"and ppath_component_key() return -1 and NULL, respectively, if "
"the component is a key or an index, respectively.");
}
ATF_TC_HEAD(ppath_copy, tc)
{
atf_tc_set_md_var(tc, "descr", "check that ppath_copy() "
"creates an exact replica of a path, and that no "
"resources are leaked.");
}
if ((p = ppath_create()) == NULL)
atf_tc_fail("ppath_create failed");
for (i = 0; i < PPATH_MAX_COMPONENTS; i++) {
if ((pc = ppath_idx(i)) == NULL)
atf_tc_fail("ppath_idx failed");
rp = ppath_push(p, pc);
ppath_component_release(pc);
ATF_CHECK_EQ(rp, p);
}
if ((cp = ppath_copy(p)) == NULL)
atf_tc_fail("ppath_copy failed");
for (i = 0; i < PPATH_MAX_COMPONENTS; i++) {
pc = ppath_component_at(p, i);
cpc = ppath_component_at(cp, i);
ATF_CHECK_EQ(pc, cpc);
ppath_component_release(pc);
ppath_component_release(cpc);
}
ATF_TC_HEAD(replace, tc)
{
atf_tc_set_md_var(tc, "descr", "check that ppath_replace_idx() "
"and ppath_replace_key() produce the paths we expect without "
"leaking resources.");
}
if ((p = ppath_create()) == NULL)
atf_tc_fail("ppath_create failed");
/* index replacement fails on an empty path */
rp = ppath_replace_idx(p, 0);
ATF_CHECK_EQ(rp, NULL);
/* key replacement fails on an empty path */
rp = ppath_replace_key(p, "key");
ATF_CHECK_EQ(rp, NULL);
for (i = 0; i < PPATH_MAX_COMPONENTS; i++) {
if ((pc = ppath_idx(i)) == NULL)
atf_tc_fail("ppath_idx failed");
rp = ppath_push(p, pc);
ppath_component_release(pc);
ATF_CHECK_EQ(rp, p);
}
if ((cp = ppath_copy(p)) == NULL)
atf_tc_fail("ppath_copy failed");
rp = ppath_pop(cp, NULL);
ATF_CHECK_EQ(rp, cp);
rp = ppath_push_key(cp, "key");
ATF_CHECK_EQ(rp, cp);
ATF_TC_HEAD(copyset_object_twice_success, tc)
{
atf_tc_set_md_var(tc, "descr",
"check that after back-to-back ppath_copyset_object() calls, "
"changing the \"u.s. citizen\" property and the first property "
"in \"children\" in the \"John Doe\" record in the "
"\"personnel\" property list, the properties are changed "
"in the new dictionary and unchanged in the old dictionary");
}
if ((d = prop_dictionary_internalize(personnel)) == NULL)
atf_tc_fail("prop_dictionary_internalize failed");
od = prop_dictionary_copy(d);
if (!dictionary_equals(od, d)) {
oext = prop_dictionary_externalize(od);
next = prop_dictionary_externalize(d);
atf_tc_fail("dictionaries are unequal from the outset, argh! "
"original\n%s\nnew\n%s", oext, next);
free(oext);
free(next);
}
if (!dictionary_equals(od, d)) {
oext = prop_dictionary_externalize(od);
next = prop_dictionary_externalize(d);
atf_tc_fail("copydel modified original dictionary, "
"original\n%s\nnew\n%s", oext, next);
free(oext);
free(next);
}
if (dictionary_equals(od, nd)) {
oext = prop_dictionary_externalize(od);
next = prop_dictionary_externalize(nd);
atf_tc_fail("copydel made no change to the new "
"dictionary, original\n%s\nnew\n%s", oext, next);
free(oext);
free(next);
}
if (!dictionary_equals(od, nd)) {
oext = prop_dictionary_externalize(od);
next = prop_dictionary_externalize(nd);
atf_tc_fail("copydel made an out-of-bounds change to the new "
"dictionary, original\n%s\nnew\n%s", oext, next);
free(oext);
free(next);
}
ATF_TC_HEAD(copydel_object_twice_success, tc)
{
atf_tc_set_md_var(tc, "descr",
"check that after back-to-back ppath_copydel_object() calls, "
"removing the \"u.s. citizen\" property and the first property "
"in \"children\" from the \"John Doe\" record in the "
"\"personnel\" property list, the properties are missing "
"from the new dictionary and unchanged in the old dictionary");
}
if ((d = prop_dictionary_internalize(personnel)) == NULL)
atf_tc_fail("prop_dictionary_internalize failed");
od = prop_dictionary_copy(d);
if (!dictionary_equals(od, d)) {
oext = prop_dictionary_externalize(od);
next = prop_dictionary_externalize(d);
atf_tc_fail("dictionaries are unequal from the outset, argh! "
"original\n%s\nnew\n%s", oext, next);
free(oext);
free(next);
}
if (!dictionary_equals(od, d)) {
oext = prop_dictionary_externalize(od);
next = prop_dictionary_externalize(d);
atf_tc_fail("copydel modified original dictionary, "
"original\n%s\nnew\n%s", oext, next);
free(oext);
free(next);
}
if (dictionary_equals(od, nd)) {
oext = prop_dictionary_externalize(od);
next = prop_dictionary_externalize(nd);
atf_tc_fail("copydel made no change to the new "
"dictionary, original\n%s\nnew\n%s", oext, next);
free(oext);
free(next);
}
if (!dictionary_equals(od, nd)) {
oext = prop_dictionary_externalize(od);
next = prop_dictionary_externalize(nd);
atf_tc_fail("copydel made an out-of-bounds change to the new "
"dictionary, original\n%s\nnew\n%s", oext, next);
free(oext);
free(next);
}
ATF_TC_HEAD(copydel_bool_success, tc)
{
atf_tc_set_md_var(tc, "descr", "check ppath_copydel_bool() deletes "
"the \"u.s. citizen\" property in the \"John Doe\" record in the "
"\"personnel\" property list and verifies the value is missing "
"from the new dictionary and unchanged in the old dictionary");
}
if ((d = prop_dictionary_internalize(personnel)) == NULL)
atf_tc_fail("prop_dictionary_internalize failed");
od = prop_dictionary_copy(d);
if (!dictionary_equals(od, d)) {
oext = prop_dictionary_externalize(od);
next = prop_dictionary_externalize(d);
atf_tc_fail("dictionaries are unequal from the outset, argh! "
"original\n%s\nnew\n%s", oext, next);
free(oext);
free(next);
}
if ((p = ppath_create()) == NULL)
atf_tc_fail("ppath_create failed");
if (ppath_push_key(p, "John Doe") == NULL)
atf_tc_fail("ppath_push_key failed");
if (ppath_push_key(p, "u.s. citizen") == NULL)
atf_tc_fail("ppath_push_key failed");
if (!dictionary_equals(od, d)) {
oext = prop_dictionary_externalize(od);
next = prop_dictionary_externalize(d);
atf_tc_fail("copydel modified original dictionary, "
"original\n%s\nnew\n%s", oext, next);
free(oext);
free(next);
}
if (dictionary_equals(od, nd)) {
oext = prop_dictionary_externalize(od);
next = prop_dictionary_externalize(nd);
atf_tc_fail("copydel made no change to the new "
"dictionary, original\n%s\nnew\n%s", oext, next);
free(oext);
free(next);
}
if (!dictionary_equals(od, nd)) {
oext = prop_dictionary_externalize(od);
next = prop_dictionary_externalize(nd);
atf_tc_fail("copydel made an out-of-bounds change to the new "
"dictionary, original\n%s\nnew\n%s", oext, next);
free(oext);
free(next);
}
ATF_TC_HEAD(copyset_bool_success, tc)
{
atf_tc_set_md_var(tc, "descr", "check ppath_copyset_bool() sets "
"the \"u.s. citizen\" property in the \"John Doe\" record in the "
"\"personnel\" property list to false and verifies the new value "
"in the new dictionary and that the old dictionary is unchanged");
}
if ((d = prop_dictionary_internalize(personnel)) == NULL)
atf_tc_fail("prop_dictionary_internalize failed");
od = prop_dictionary_copy(d);
if (!dictionary_equals(od, d)) {
oext = prop_dictionary_externalize(od);
next = prop_dictionary_externalize(d);
atf_tc_fail("dictionaries are unequal from the outset, argh! "
"original\n%s\nnew\n%s", oext, next);
free(oext);
free(next);
}
if ((p = ppath_create()) == NULL)
atf_tc_fail("ppath_create failed");
if (ppath_push_key(p, "John Doe") == NULL)
atf_tc_fail("ppath_push_key failed");
if (ppath_push_key(p, "u.s. citizen") == NULL)
atf_tc_fail("ppath_push_key failed");
if (!dictionary_equals(od, d)) {
oext = prop_dictionary_externalize(od);
next = prop_dictionary_externalize(d);
atf_tc_fail("copyset modified original dictionary, "
"original\n%s\nnew\n%s", oext, next);
free(oext);
free(next);
}
if (dictionary_equals(od, nd)) {
oext = prop_dictionary_externalize(od);
next = prop_dictionary_externalize(nd);
atf_tc_fail("copyset made no change to the new "
"dictionary, original\n%s\nnew\n%s", oext, next);
free(oext);
free(next);
}
if (!dictionary_equals(od, nd)) {
oext = prop_dictionary_externalize(od);
next = prop_dictionary_externalize(nd);
atf_tc_fail("copyset made an out-of-bounds change to the new "
"dictionary, original\n%s\nnew\n%s", oext, next);
free(oext);
free(next);
}
ATF_TC_HEAD(set_bool_eftype, tc)
{
atf_tc_set_md_var(tc, "descr", "check ppath_set_bool() does not "
"overwrite with a bool "
"the \"job title\" property in the \"John Doe\" record in "
"the "
"\"personnel\" property list");
}
ATF_TC_BODY(set_bool_eftype, tc)
{
int rc;
bool v = false;
prop_dictionary_t d;
ppath_t *p;
ATF_TC_HEAD(set_bool_enoent, tc)
{
atf_tc_set_md_var(tc, "descr", "check ppath_set_bool() does not create "
"the \"russian citizen\" property in the \"John Doe\" record in "
"the "
"\"personnel\" property list");
}
ATF_TC_BODY(set_bool_enoent, tc)
{
int rc;
bool v = false;
prop_dictionary_t d;
ppath_t *p;
ATF_TC_HEAD(create_bool_eexist, tc)
{
atf_tc_set_md_var(tc, "descr", "check ppath_create_bool() returns "
"EEXIST because the \"u.s. citizen\" property in the "
"\"John Doe\" record in the \"personnel\" property list "
"already exists");
}
ATF_TC_BODY(create_bool_eexist, tc)
{
int rc;
bool v = false;
prop_dictionary_t d;
ppath_t *p;
ATF_TC_HEAD(create_bool_success, tc)
{
atf_tc_set_md_var(tc, "descr", "check ppath_create_bool() creates "
"the \"russian citizen\" property in the \"John Doe\" record in "
"the \"personnel\" property list and sets it to false");
}
ATF_TC_BODY(create_bool_success, tc)
{
int rc;
bool v = false;
prop_dictionary_t d;
ppath_t *p;
ATF_TC_HEAD(set_bool_success, tc)
{
atf_tc_set_md_var(tc, "descr", "check ppath_set_bool() sets "
"the \"u.s. citizen\" property in the \"John Doe\" record in the "
"\"personnel\" property list to false and verifies the new value");
}
ATF_TC_BODY(set_bool_success, tc)
{
int rc;
bool v = false;
prop_dictionary_t d;
ppath_t *p;
ATF_TC_HEAD(get_bool_success, tc)
{
atf_tc_set_md_var(tc, "descr", "check ppath_get_bool() fetches "
"the \"u.s. citizen\" property from the \"John Doe\" record in the "
"\"personnel\" property list, and compares it with the expected "
"value, true");
}
ATF_TC_BODY(get_bool_success, tc)
{
int rc;
bool v = false;
prop_dictionary_t d;
ppath_t *p;
ATF_TC_HEAD(delete_bool_eftype, tc)
{
atf_tc_set_md_var(tc, "descr", "check ppath_delete_bool() returns "
"EFTYPE for the path (\"John Doe\", \"job title\") in the "
"\"personnel\" property list and does not delete the path");
}
ATF_TC_BODY(delete_bool_eftype, tc)
{
int rc;
prop_dictionary_t d;
ppath_t *p;
ATF_TC_HEAD(get_bool_enoent, tc)
{
atf_tc_set_md_var(tc, "descr", "check ppath_get_bool() returns "
"ENOENT for the path (\"John Doe\", \"citizen\") in the "
"\"personnel\" property list, and the bool * argument is "
"unchanged");
}
ATF_TC_HEAD(get_bool_eftype, tc)
{
atf_tc_set_md_var(tc, "descr", "check ppath_get_bool() returns "
"EFTYPE for the path (\"John Doe\", \"job title\") in the "
"\"personnel\" property list, and the bool * argument is "
"unchanged");
}
ATF_TC_HEAD(get_string_eftype, tc)
{
atf_tc_set_md_var(tc, "descr", "check ppath_get_string() returns "
"EFTYPE for the path (\"John Doe\", \"u.s. citizen\") in the "
"\"personnel\" property list, and the const char ** argument is "
"unchanged");
}
ATF_TC_HEAD(get_string_enoent, tc)
{
atf_tc_set_md_var(tc, "descr", "check ppath_get_string() returns "
"ENOENT for the path (\"John Doe\", \"title\") in the "
"\"personnel\" property list, and the const char ** argument is "
"unchanged");
}
ATF_TC_HEAD(get_string_success, tc)
{
atf_tc_set_md_var(tc, "descr", "check ppath_get_string() fetches "
"the \"job title\" property from the \"John Doe\" record in the "
"\"personnel\" property list and compares it with the expected "
"value, \"computer programmer\"");
}