+ if (response->request.status.status_code == statuses[i].status)
+ {
+ if (statuses[i].repeat_match &&
+ repeat_count < statuses[i].repeat_limit)
+ repeat_test = 1;
+
+ if (statuses[i].define_match)
+ set_variable(vars, statuses[i].define_match, "1");
+
+ break;
+ }
+ else
+ {
+ if (statuses[i].repeat_no_match &&
+ repeat_count < statuses[i].repeat_limit)
+ repeat_test = 1;
+
+ if (statuses[i].define_no_match)
+ {
+ set_variable(vars, statuses[i].define_no_match, "1");
+ break;
+ }
+ }
+ }
+
+ if (i == num_statuses && num_statuses > 0)
+ {
+ for (i = 0; i < num_statuses; i ++)
+ {
+ if (statuses[i].if_defined &&
+ !get_variable(vars, statuses[i].if_defined))
+ continue;
+
+ if (statuses[i].if_not_defined &&
+ get_variable(vars, statuses[i].if_not_defined))
+ continue;
+
+ if (!statuses[i].repeat_match)
+ add_stringf(errors, "EXPECTED: STATUS %s (got %s)",
+ ippErrorString(statuses[i].status),
+ ippErrorString(cupsLastError()));
+ }
+
+ if ((attrptr = ippFindAttribute(response, "status-message",
+ IPP_TAG_TEXT)) != NULL)
+ add_stringf(errors, "status-message=\"%s\"",
+ attrptr->values[0].string.text);
+ }
+
+ for (i = num_expects, expect = expects; i > 0; i --, expect ++)
+ {
+ if (expect->if_defined && !get_variable(vars, expect->if_defined))
+ continue;
+
+ if (expect->if_not_defined &&
+ get_variable(vars, expect->if_not_defined))
+ continue;
+
+ found = ippFindAttribute(response, expect->name, IPP_TAG_ZERO);
+
+ if ((found && expect->not_expect) ||
+ (!found && !(expect->not_expect || expect->optional)) ||
+ (found && !expect_matches(expect, found->value_tag)) ||
+ (found && expect->in_group &&
+ found->group_tag != expect->in_group))
+ {
+ if (expect->define_no_match)
+ set_variable(vars, expect->define_no_match, "1");
+ else if (!expect->define_match && !expect->define_value)
+ {
+ if (found && expect->not_expect)
+ add_stringf(errors, "NOT EXPECTED: %s", expect->name);
+ else if (!found && !(expect->not_expect || expect->optional))
+ add_stringf(errors, "EXPECTED: %s", expect->name);
+ else if (found)
+ {
+ if (!expect_matches(expect, found->value_tag))
+ add_stringf(errors, "EXPECTED: %s OF-TYPE %s (got %s)",
+ expect->name, expect->of_type,
+ ippTagString(found->value_tag));
+
+ if (expect->in_group && found->group_tag != expect->in_group)
+ add_stringf(errors, "EXPECTED: %s IN-GROUP %s (got %s).",
+ expect->name, ippTagString(expect->in_group),
+ ippTagString(found->group_tag));
+ }
+ }
+
+ if (expect->repeat_no_match &&
+ repeat_count < expect->repeat_limit)
+ repeat_test = 1;
+
+ continue;
+ }
+
+ if (found)
+ ippAttributeString(found, buffer, sizeof(buffer));
+
+ if (found &&
+ !with_value(NULL, expect->with_value, expect->with_flags, found,
+ buffer, sizeof(buffer)))
+ {
+ if (expect->define_no_match)
+ set_variable(vars, expect->define_no_match, "1");
+ else if (!expect->define_match && !expect->define_value &&
+ !expect->repeat_match && !expect->repeat_no_match)
+ {
+ if (expect->with_flags & _CUPS_WITH_REGEX)
+ add_stringf(errors, "EXPECTED: %s %s /%s/",
+ expect->name,
+ (expect->with_flags & _CUPS_WITH_ALL) ?
+ "WITH-ALL-VALUES" : "WITH-VALUE",
+ expect->with_value);
+ else
+ add_stringf(errors, "EXPECTED: %s %s \"%s\"",
+ expect->name,
+ (expect->with_flags & _CUPS_WITH_ALL) ?
+ "WITH-ALL-VALUES" : "WITH-VALUE",
+ expect->with_value);
+
+ with_value(errors, expect->with_value, expect->with_flags, found,
+ buffer, sizeof(buffer));
+ }
+
+ if (expect->repeat_no_match &&
+ repeat_count < expect->repeat_limit)
+ repeat_test = 1;
+
+ continue;
+ }
+
+ if (found && expect->count > 0 &&
+ found->num_values != expect->count)
+ {
+ if (expect->define_no_match)
+ set_variable(vars, expect->define_no_match, "1");
+ else if (!expect->define_match && !expect->define_value)
+ {
+ add_stringf(errors, "EXPECTED: %s COUNT %d (got %d)", expect->name,
+ expect->count, found->num_values);
+ }
+
+ if (expect->repeat_no_match &&
+ repeat_count < expect->repeat_limit)
+ repeat_test = 1;
+
+ continue;
+ }
+
+ if (found && expect->same_count_as)
+ {
+ attrptr = ippFindAttribute(response, expect->same_count_as,
+ IPP_TAG_ZERO);
+
+ if (!attrptr || attrptr->num_values != found->num_values)
+ {
+ if (expect->define_no_match)
+ set_variable(vars, expect->define_no_match, "1");
+ else if (!expect->define_match && !expect->define_value)
+ {
+ if (!attrptr)
+ add_stringf(errors,
+ "EXPECTED: %s (%d values) SAME-COUNT-AS %s "
+ "(not returned)", expect->name,
+ found->num_values, expect->same_count_as);
+ else if (attrptr->num_values != found->num_values)
+ add_stringf(errors,
+ "EXPECTED: %s (%d values) SAME-COUNT-AS %s "
+ "(%d values)", expect->name, found->num_values,
+ expect->same_count_as, attrptr->num_values);
+ }
+
+ if (expect->repeat_no_match &&
+ repeat_count < expect->repeat_limit)
+ repeat_test = 1;
+
+ continue;
+ }
+ }
+
+ if (found && expect->define_match)
+ set_variable(vars, expect->define_match, "1");
+
+ if (found && expect->define_value)
+ set_variable(vars, expect->define_value, buffer);
+
+ if (found && expect->repeat_match &&
+ repeat_count < expect->repeat_limit)
+ repeat_test = 1;
+ }
+ }
+
+ /*
+ * If we are going to repeat this test, sleep 1 second so we don't flood
+ * the printer with requests...
+ */
+
+ if (repeat_test)
+ {
+ if (Output == _CUPS_OUTPUT_TEST)
+ {
+ printf("%04d]\n", repeat_count);
+ fflush(stdout);
+ }
+
+ sleep((unsigned)repeat_interval);
+ repeat_interval = _cupsNextDelay(repeat_interval, &repeat_prev);
+
+ if (Output == _CUPS_OUTPUT_TEST)
+ {
+ printf(" %-68.68s [", name);
+ fflush(stdout);
+ }
+ }
+ }
+ while (repeat_test);
+
+ ippDelete(request);
+
+ request = NULL;
+
+ if (cupsArrayCount(errors) > 0)
+ prev_pass = pass = 0;
+
+ if (prev_pass)
+ PassCount ++;
+ else
+ FailCount ++;
+
+ if (Output == _CUPS_OUTPUT_PLIST)
+ {
+ puts("<key>Successful</key>");
+ puts(prev_pass ? "<true />" : "<false />");
+ puts("<key>StatusCode</key>");
+ print_xml_string("string", ippErrorString(cupsLastError()));
+ puts("<key>ResponseAttributes</key>");
+ puts("<array>");
+ puts("<dict>");
+ for (attrptr = response ? response->attrs : NULL,
+ group = attrptr ? attrptr->group_tag : IPP_TAG_ZERO;
+ attrptr;
+ attrptr = attrptr->next)
+ print_attr(attrptr, &group);
+ puts("</dict>");
+ puts("</array>");
+ }
+ else if (Output == _CUPS_OUTPUT_TEST)
+ {
+ puts(prev_pass ? "PASS]" : "FAIL]");
+
+ if (!prev_pass || (Verbosity && response))
+ {
+ printf(" RECEIVED: %lu bytes in response\n",
+ (unsigned long)ippLength(response));
+ printf(" status-code = %s (%s)\n", ippErrorString(cupsLastError()),
+ cupsLastErrorString());
+
+ if (response)
+ {
+ for (attrptr = response->attrs;
+ attrptr != NULL;
+ attrptr = attrptr->next)
+ print_attr(attrptr, NULL);
+ }
+ }
+ }
+ else if (!prev_pass)
+ fprintf(stderr, "%s\n", cupsLastErrorString());
+
+ if (prev_pass && Output >= _CUPS_OUTPUT_LIST && !Verbosity &&
+ num_displayed > 0)
+ {
+ size_t width; /* Length of value */