Skip to content

Commit 8dc3233

Browse files
committed
Fix handling of EXPECT for finding a single member with a given value (Issue #4)
1 parent 29ce599 commit 8dc3233

2 files changed

Lines changed: 60 additions & 15 deletions

File tree

CHANGES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ libcups v3.0b1 (Month DD, YYYY)
2626
(Issue #24)
2727
- Added public JSON API (Issue #31)
2828
- Updated the CUPS API for consistency.
29+
- Fixed ipptool's handling of EXPECT for member attributes (Issue #4)
2930
- Fixed ipptool's support for octetString values (Issue #23)
3031
- Removed all obsolete/deprecated CUPS 2.x APIs.
3132
- Removed (obsolete) Kerberos support.

tools/ipptool.c

Lines changed: 59 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1844,7 +1844,9 @@ do_test(ipp_file_t *f, /* I - IPP data file */
18441844

18451845
for (i = data->num_expects, expect = data->expects; i > 0; i --, expect ++)
18461846
{
1847-
ipp_attribute_t *group_found; /* Found parent attribute for group tests */
1847+
cups_array_t *exp_errors; // Temporary list of errors
1848+
bool exp_pass; // Did this expect pass?
1849+
ipp_attribute_t *group_found; // Found parent attribute for group tests
18481850

18491851
if (expect->if_defined && !ippFileGetVar(f, expect->if_defined))
18501852
continue;
@@ -1859,6 +1861,9 @@ do_test(ipp_file_t *f, /* I - IPP data file */
18591861
break;
18601862
}
18611863

1864+
exp_pass = false;
1865+
exp_errors = cupsArrayNew(NULL, NULL, NULL, 0, (cups_acopy_cb_t)strdup, (cups_afree_cb_t)free);
1866+
18621867
do
18631868
{
18641869
group_found = found;
@@ -1882,27 +1887,34 @@ do_test(ipp_file_t *f, /* I - IPP data file */
18821887
(expect->with_distinct && !with_distinct_values(NULL, found)))
18831888
{
18841889
if (expect->define_no_match)
1890+
{
18851891
ippFileSetVar(data->parent, expect->define_no_match, "1");
1892+
exp_pass = true;
1893+
}
18861894
else if (!expect->define_match && !expect->define_value)
18871895
{
18881896
if (found && expect->not_expect && !expect->with_value && !expect->with_value_from)
1889-
add_stringf(data->errors, "NOT EXPECTED: %s", expect->name);
1897+
{
1898+
add_stringf(exp_errors, "NOT EXPECTED: %s", expect->name);
1899+
}
18901900
else if (!found && !(expect->not_expect || expect->optional))
1891-
add_stringf(data->errors, "EXPECTED: %s", expect->name);
1901+
{
1902+
add_stringf(exp_errors, "EXPECTED: %s", expect->name);
1903+
}
18921904
else if (found)
18931905
{
18941906
if (!expect_matches(expect, found))
1895-
add_stringf(data->errors, "EXPECTED: %s OF-TYPE %s (got %s)",
1907+
add_stringf(exp_errors, "EXPECTED: %s OF-TYPE %s (got %s)",
18961908
expect->name, expect->of_type,
18971909
ippTagString(ippGetValueTag(found)));
18981910

18991911
if (expect->in_group && ippGetGroupTag(group_found) != expect->in_group)
1900-
add_stringf(data->errors, "EXPECTED: %s IN-GROUP %s (got %s).",
1912+
add_stringf(exp_errors, "EXPECTED: %s IN-GROUP %s (got %s).",
19011913
expect->name, ippTagString(expect->in_group),
19021914
ippTagString(ippGetGroupTag(group_found)));
19031915

19041916
if (expect->with_distinct)
1905-
with_distinct_values(data->errors, found);
1917+
with_distinct_values(exp_errors, found);
19061918
}
19071919
}
19081920

@@ -1917,12 +1929,15 @@ do_test(ipp_file_t *f, /* I - IPP data file */
19171929
if (found && expect->with_value_from && !with_value_from(NULL, ippFindAttribute(response, expect->with_value_from, IPP_TAG_ZERO), found, data->buffer, sizeof(data->buffer)))
19181930
{
19191931
if (expect->define_no_match)
1932+
{
19201933
ippFileSetVar(data->parent, expect->define_no_match, "1");
1934+
exp_pass = true;
1935+
}
19211936
else if (!expect->define_match && !expect->define_value && ((!expect->repeat_match && !expect->repeat_no_match) || repeat_count >= expect->repeat_limit))
19221937
{
1923-
add_stringf(data->errors, "EXPECTED: %s WITH-VALUES-FROM %s", expect->name, expect->with_value_from);
1938+
add_stringf(exp_errors, "EXPECTED: %s WITH-VALUES-FROM %s", expect->name, expect->with_value_from);
19241939

1925-
with_value_from(data->errors, ippFindAttribute(response, expect->with_value_from, IPP_TAG_ZERO), found, data->buffer, sizeof(data->buffer));
1940+
with_value_from(exp_errors, ippFindAttribute(response, expect->with_value_from, IPP_TAG_ZERO), found, data->buffer, sizeof(data->buffer));
19261941
}
19271942

19281943
if (expect->repeat_no_match && repeat_count < expect->repeat_limit)
@@ -1933,31 +1948,41 @@ do_test(ipp_file_t *f, /* I - IPP data file */
19331948
else if (found && !with_value(data, NULL, expect->with_value, expect->with_flags, found, data->buffer, sizeof(data->buffer)))
19341949
{
19351950
if (expect->define_no_match)
1951+
{
19361952
ippFileSetVar(data->parent, expect->define_no_match, "1");
1953+
exp_pass = true;
1954+
}
19371955
else if (!expect->define_match && !expect->define_value &&
19381956
!expect->repeat_match && (!expect->repeat_no_match || repeat_count >= expect->repeat_limit))
19391957
{
19401958
if (expect->with_flags & IPPTOOL_WITH_REGEX)
1941-
add_stringf(data->errors, "EXPECTED: %s %s /%s/", expect->name, with_flags_string(expect->with_flags), expect->with_value);
1959+
add_stringf(exp_errors, "EXPECTED: %s %s /%s/", expect->name, with_flags_string(expect->with_flags), expect->with_value);
19421960
else
1943-
add_stringf(data->errors, "EXPECTED: %s %s \"%s\"", expect->name, with_flags_string(expect->with_flags), expect->with_value);
1961+
add_stringf(exp_errors, "EXPECTED: %s %s \"%s\"", expect->name, with_flags_string(expect->with_flags), expect->with_value);
19441962

1945-
with_value(data, data->errors, expect->with_value, expect->with_flags, found, data->buffer, sizeof(data->buffer));
1963+
with_value(data, exp_errors, expect->with_value, expect->with_flags, found, data->buffer, sizeof(data->buffer));
19461964
}
19471965

19481966
if (expect->repeat_no_match && repeat_count < expect->repeat_limit)
19491967
repeat_test = true;
19501968

19511969
break;
19521970
}
1971+
else if (expect->with_value)
1972+
{
1973+
exp_pass = true;
1974+
}
19531975

19541976
if (found && expect->count > 0 && ippGetCount(found) != expect->count)
19551977
{
19561978
if (expect->define_no_match)
1979+
{
19571980
ippFileSetVar(data->parent, expect->define_no_match, "1");
1981+
exp_pass = true;
1982+
}
19581983
else if (!expect->define_match && !expect->define_value)
19591984
{
1960-
add_stringf(data->errors, "EXPECTED: %s COUNT %u (got %u)", expect->name, (unsigned)expect->count, (unsigned)ippGetCount(found));
1985+
add_stringf(exp_errors, "EXPECTED: %s COUNT %u (got %u)", expect->name, (unsigned)expect->count, (unsigned)ippGetCount(found));
19611986
}
19621987

19631988
if (expect->repeat_no_match && repeat_count < expect->repeat_limit)
@@ -1974,13 +1999,16 @@ do_test(ipp_file_t *f, /* I - IPP data file */
19741999
if (!attrptr || ippGetCount(attrptr) != ippGetCount(found))
19752000
{
19762001
if (expect->define_no_match)
2002+
{
19772003
ippFileSetVar(data->parent, expect->define_no_match, "1");
2004+
exp_pass = true;
2005+
}
19782006
else if (!expect->define_match && !expect->define_value)
19792007
{
19802008
if (!attrptr)
1981-
add_stringf(data->errors, "EXPECTED: %s (%u values) SAME-COUNT-AS %s (not returned)", expect->name, (unsigned)ippGetCount(found), expect->same_count_as);
2009+
add_stringf(exp_errors, "EXPECTED: %s (%u values) SAME-COUNT-AS %s (not returned)", expect->name, (unsigned)ippGetCount(found), expect->same_count_as);
19822010
else if (ippGetCount(attrptr) != ippGetCount(found))
1983-
add_stringf(data->errors, "EXPECTED: %s (%u values) SAME-COUNT-AS %s (%u values)", expect->name, (unsigned)ippGetCount(found), expect->same_count_as, (unsigned)ippGetCount(attrptr));
2011+
add_stringf(exp_errors, "EXPECTED: %s (%u values) SAME-COUNT-AS %s (%u values)", expect->name, (unsigned)ippGetCount(found), expect->same_count_as, (unsigned)ippGetCount(attrptr));
19842012
}
19852013

19862014
if (expect->repeat_no_match && repeat_count < expect->repeat_limit)
@@ -1994,10 +2022,14 @@ do_test(ipp_file_t *f, /* I - IPP data file */
19942022
cupsFilePrintf(cupsFileStdout(), "\n%s\n\n", expect->display_match);
19952023

19962024
if (found && expect->define_match)
2025+
{
19972026
ippFileSetVar(data->parent, expect->define_match, "1");
2027+
exp_pass = true;
2028+
}
19982029

19992030
if (found && expect->define_value)
20002031
{
2032+
exp_pass = true;
20012033
if (!expect->with_value)
20022034
{
20032035
size_t last = ippGetCount(found) - 1;
@@ -2057,7 +2089,19 @@ do_test(ipp_file_t *f, /* I - IPP data file */
20572089
if (found && expect->repeat_match && repeat_count < expect->repeat_limit)
20582090
repeat_test = 1;
20592091
}
2060-
while (expect->expect_all && (found = ippFindNextAttribute(response, expect->name, IPP_TAG_ZERO)) != NULL);
2092+
while ((expect->expect_all || !exp_pass) && (found = ippFindNextAttribute(response, expect->name, IPP_TAG_ZERO)) != NULL);
2093+
2094+
// Handle results of the EXPECT checks...
2095+
if (!exp_pass)
2096+
{
2097+
// Copy errors...
2098+
char *e; // Current error
2099+
2100+
for (e = (char *)cupsArrayGetFirst(exp_errors); e; e = (char *)cupsArrayGetNext(exp_errors))
2101+
cupsArrayAdd(data->errors, e);
2102+
}
2103+
2104+
cupsArrayDelete(exp_errors);
20612105
}
20622106
}
20632107

0 commit comments

Comments
 (0)