Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add EXPECT-ALL directive to ipptool #4469

Closed
michaelrsweet opened this issue Aug 18, 2014 · 2 comments
Closed

Add EXPECT-ALL directive to ipptool #4469

michaelrsweet opened this issue Aug 18, 2014 · 2 comments

Comments

@michaelrsweet
Copy link
Collaborator

Version: 2.1-feature
CUPS.org User: mike

The IPP Everywhere test suite could use an EXPECT-ALL directive to iterate over all matches of a given attribute (vs. all value of an attribute).

@michaelrsweet
Copy link
Collaborator Author

CUPS.org User: mike

Fixed in Subversion repository.

@michaelrsweet
Copy link
Collaborator Author

"str4469.patch":

Index: man/ipptool.man

--- man/ipptool.man (revision 12483)
+++ man/ipptool.man (working copy)
@@ -3,7 +3,7 @@
."
." ipptool man page for CUPS.
."
-." Copyright 2010-2014 by Apple Inc.
+." Copyright 2010-2015 by Apple Inc.
."
." These coded instructions, statements, and computer programs are the
." property of Apple Inc. and are protected by Federal copyright
@@ -11,7 +11,7 @@
." which should have been included with this file. If this file is
." file is missing or damaged, see the license at "http://www.cups.org/".
."
-.TH ipptool 1 "CUPS" "29 August 2014" "Apple Inc."
+.TH ipptool 1 "CUPS" "3 February 2015" "Apple Inc."
.SH NAME
ipptool - perform internet printing protocol requests
.SH SYNOPSIS
@@ -242,7 +242,7 @@
PWG Internet Printing Protocol Workgroup (http://www.pwg.org/ipp)
RFC 2911 (http://tools.ietf.org/html/rfc2911),
.SH COPYRIGHT
-Copyright [co] 2007-2014 by Apple Inc.
+Copyright [co] 2007-2015 by Apple Inc.
."
." End of "$Id$".
."

Index: man/ipptoolfile.man

--- man/ipptoolfile.man (revision 12483)
+++ man/ipptoolfile.man (working copy)
@@ -11,7 +11,7 @@
." which should have been included with this file. If this file is
." file is missing or damaged, see the license at "http://www.cups.org/".
."
-.TH ipptoolfile 5 "CUPS" "15 May 2014" "Apple Inc."
+.TH ipptoolfile 5 "CUPS" "3 February 2015" "Apple Inc."
.SH NAME
ipptoolfile - ipptool file format
.SH DESCRIPTION
@@ -168,6 +168,11 @@
\fBEXPECT !\fIattribute-name\fR
Specifies that the response must/may/must not include the named attribute. Additional requirements can be added as predicates - see the "EXPECT PREDICATES" section for more information on predicates. Attribute names can specify member attributes by separating the attribute and member names with the forward slash, for example "media-col/media-size/x-dimension".
.TP 5
+\fBEXPECT-ALL \fIattribute-name \fR[ \fIpredicate(s) \fR]
+.TP 5
+\fBEXPECT-ALL ?\fIattribute-name predicate(s)\fR
+Specifies that the response must/may include the named attribute and that all occurrences of that attribute must match the given predicates.
+.TP 5
\fBFILE filename\fR
Specifies a file to include at the end of the request. This is typically used when sending a test print file.
.TP 5
@@ -610,7 +615,7 @@
PWG Internet Printing Protocol Workgroup (http://www.pwg.org/ipp),
RFC 2911 (http://tools.ietf.org/html/rfc3911)
.SH COPYRIGHT
-Copyright [co] 2007-2014 by Apple Inc.
+Copyright [co] 2007-2015 by Apple Inc.
."
." End of "$Id$".
."

Index: test/ipptool.c

--- test/ipptool.c (revision 12483)
+++ test/ipptool.c (working copy)
@@ -70,7 +70,8 @@
typedef struct cups_expect_s /**** Expected attribute info ***/
{
int optional, /_ Optional attribute? */

  •   not_expect;     /\* Don't expect attribute? */
    
  •   not_expect,     /\* Don't expect attribute? */
    
  •   expect_all;     /\* Expect all attributes to match/not match _/
    

    char *name, /_ Attribute name /
    *of_type, /
    Type name /
    *same_count_as, /
    Parallel attribute name */
    @@ -1993,12 +1994,14 @@
    last_status->repeat_match = 0;
    last_status->repeat_no_match = 0;
    }

  •  else if (!_cups_strcasecmp(token, "EXPECT"))
    
  •  else if (!_cups_strcasecmp(token, "EXPECT") || !_cups_strcasecmp(token, "EXPECT-ALL"))
    

    {
    /*
    * Expected attributes...
    */

  • int expect_all = !_cups_strcasecmp(token, "EXPECT-ALL");

  • if (num_expects >= (int)(sizeof(expects) / sizeof(expects[0])))
    {
    print_fatal_error(outfile, "Too many EXPECT's on line %d.", linenum);
    @@ -2018,6 +2021,7 @@

memset(last_expect, 0, sizeof(_cups_expect_t));
last_expect->repeat_limit = 1000;

  • last_expect->expect_all = expect_all;
 if (token[0] == '!')
 {

@@ -2938,192 +2942,196 @@
get_variable(vars, expect->if_not_defined))
continue;

  • found = ippFindAttribute(response, expect->name, IPP_TAG_ZERO);
    
  •      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(outfile, vars, expect->define_no_match, "1");
    
  •   else if (!expect->define_match && !expect->define_value)
    
  •      do
    
  •      {
    
  •   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 (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->define_no_match)
    
  •   set_variable(outfile, vars, expect->define_no_match, "1");
    
  •     else if (!expect->define_match && !expect->define_value)
      {
    
  •   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 (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->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;
    
  •     if (expect->repeat_no_match &&
    
  •     repeat_count < expect->repeat_limit)
    
  •   repeat_test = 1;
    
  •   continue;
    
  • }
    
  •     break;
    
  •   }
    
  • if (found)
    
  •   ippAttributeString(found, buffer, sizeof(buffer));
    
  •   if (found)
    
  •     ippAttributeString(found, buffer, sizeof(buffer));
    
  • if (found &&
    
  •     !with_value(outfile, NULL, expect->with_value, expect->with_flags, found,
    
  •         buffer, sizeof(buffer)))
    
  • {
    
  •   if (expect->define_no_match)
    
  •     set_variable(outfile, vars, expect->define_no_match, "1");
    
  •   else if (!expect->define_match && !expect->define_value &&
    
  •            !expect->repeat_match && !expect->repeat_no_match)
    
  •   if (found &&
    
  •   !with_value(outfile, NULL, expect->with_value, expect->with_flags, found,
    
  •           buffer, sizeof(buffer)))
    {
    
  •     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);
    
  •     if (expect->define_no_match)
    
  •   set_variable(outfile, 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(outfile, errors, expect->with_value, expect->with_flags, found,
    
  •                buffer, sizeof(buffer));
    
  •   }
    
  •   with_value(outfile, errors, expect->with_value, expect->with_flags, found,
    
  •          buffer, sizeof(buffer));
    
  •     }
    
  •   if (expect->repeat_no_match &&
    
  •   repeat_count < expect->repeat_limit)
    
  •     repeat_test = 1;
    
  •     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(outfile, 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);
    
  •     break;
    }
    
  •   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 (found && expect->count > 0 &&
    
  •   found->num_values != expect->count)
    {
      if (expect->define_no_match)
    set_variable(outfile, 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);
    
  •   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_count < expect->repeat_limit)
    repeat_test = 1;
    
  •     continue;
    
  •     break;
    }
    
  • }
    
  • if (found && expect->define_match)
    

- set_variable(outfile, vars, expect->define_match, "1");

  • if (found && expect->define_value)
    
  • {
    
  •   if (!expect->with_value)
    
  •   if (found && expect->same_count_as)
    {
    
  •     int last = ippGetCount(found) - 1;
    
  •               /\* Last element in attribute */
    
  •     attrptr = ippFindAttribute(response, expect->same_count_as,
    
  •                IPP_TAG_ZERO);
    
  •     switch (ippGetValueTag(found))
    
  •     if (!attrptr || attrptr->num_values != found->num_values)
      {
    
  •       case IPP_TAG_ENUM :
    
  •   case IPP_TAG_INTEGER :
    
  •       snprintf(buffer, sizeof(buffer), "%d", ippGetInteger(found, last));
    
  •       break;
    
  •   if (expect->define_no_match)
    
  •     set_variable(outfile, 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);
    
  •   }
    
  •   case IPP_TAG_BOOLEAN :
    
  •       if (ippGetBoolean(found, last))
    
  •         strlcpy(buffer, "true", sizeof(buffer));
    
  •       else
    
  •         strlcpy(buffer, "false", sizeof(buffer));
    
  •       break;
    
  •   if (expect->repeat_no_match &&
    
  •       repeat_count < expect->repeat_limit)
    
  •     repeat_test = 1;
    
  •   case IPP_TAG_RESOLUTION :
    
  •       {
    
  •         int   xres,   /\* Horizontal resolution */
    
  •           yres;   /\* Vertical resolution */
    
  •         ipp_res_t units;  /\* Resolution units */
    
  •   break;
    
  •     }
    
  •   }
    
  •         xres = ippGetResolution(found, last, &yres, &units);
    
  •   if (found && expect->define_match)
    
  •     set_variable(outfile, vars, expect->define_match, "1");
    
  •         if (xres == yres)
    
  •           snprintf(buffer, sizeof(buffer), "%d%s", xres, units == IPP_RES_PER_INCH ? "dpi" : "dpcm");
    
  •   if (found && expect->define_value)
    
  •   {
    
  •     if (!expect->with_value)
    
  •     {
    
  •   int last = ippGetCount(found) - 1;
    
  •                 /\* Last element in attribute */
    
  •   switch (ippGetValueTag(found))
    
  •   {
    
  •     case IPP_TAG_ENUM :
    
  •     case IPP_TAG_INTEGER :
    
  •         snprintf(buffer, sizeof(buffer), "%d", ippGetInteger(found, last));
    
  •         break;
    
  •     case IPP_TAG_BOOLEAN :
    
  •         if (ippGetBoolean(found, last))
    
  •       strlcpy(buffer, "true", sizeof(buffer));
          else
    
  •           snprintf(buffer, sizeof(buffer), "%dx%d%s", xres, yres, units == IPP_RES_PER_INCH ? "dpi" : "dpcm");
    
  •       }
    
  •       break;
    
  •       strlcpy(buffer, "false", sizeof(buffer));
    
  •         break;
    
  •   case IPP_TAG_CHARSET :
    
  •   case IPP_TAG_KEYWORD :
    
  •   case IPP_TAG_LANGUAGE :
    
  •   case IPP_TAG_MIMETYPE :
    
  •   case IPP_TAG_NAME :
    
  •   case IPP_TAG_NAMELANG :
    
  •   case IPP_TAG_TEXT :
    
  •   case IPP_TAG_TEXTLANG :
    
  •   case IPP_TAG_URI :
    
  •   case IPP_TAG_URISCHEME :
    
  •       strlcpy(buffer, ippGetString(found, last, NULL), sizeof(buffer));
    
  •       break;
    
  •     case IPP_TAG_RESOLUTION :
    
  •         {
    
  •       int xres,   /\* Horizontal resolution */
    
  •             yres; /\* Vertical resolution */
    
  •       ipp_res_t   units;  /* Resolution units */
    
  •   default :
    
  •       ippAttributeString(found, buffer, sizeof(buffer));
    
  •       break;
    
  •       xres = ippGetResolution(found, last, &yres, &units);
    
  •       if (xres == yres)
    
  •         snprintf(buffer, sizeof(buffer), "%d%s", xres, units == IPP_RES_PER_INCH ? "dpi" : "dpcm");
    
  •       else
    
  •         snprintf(buffer, sizeof(buffer), "%dx%d%s", xres, yres, units == IPP_RES_PER_INCH ? "dpi" : "dpcm");
    
  •         }
    
  •         break;
    
  •     case IPP_TAG_CHARSET :
    
  •     case IPP_TAG_KEYWORD :
    
  •     case IPP_TAG_LANGUAGE :
    
  •     case IPP_TAG_MIMETYPE :
    
  •     case IPP_TAG_NAME :
    
  •     case IPP_TAG_NAMELANG :
    
  •     case IPP_TAG_TEXT :
    
  •     case IPP_TAG_TEXTLANG :
    
  •     case IPP_TAG_URI :
    
  •     case IPP_TAG_URISCHEME :
    
  •         strlcpy(buffer, ippGetString(found, last, NULL), sizeof(buffer));
    
  •         break;
    
  •     default :
    
  •         ippAttributeString(found, buffer, sizeof(buffer));
    
  •         break;
    
  •   }
      }
    
  •     set_variable(outfile, vars, expect->define_value, buffer);
    }
    
  •   set_variable(outfile, vars, expect->define_value, buffer);
    

- }

  • if (found && expect->repeat_match &&
    
  •     repeat_count < expect->repeat_limit)
    
  •   repeat_test = 1;
    
  •   if (found && expect->repeat_match &&
    
  •   repeat_count < expect->repeat_limit)
    
  •     repeat_test = 1;
    
  •      }
    
  •      while (expect->expect_all && (found = ippFindNextAttribute(response, expect->name, IPP_TAG_ZERO)) != NULL);
    
    }
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant