]> git.ipfire.org Git - thirdparty/cups.git/blobdiff - test/ipptool.c
Fix build errors on Fedora.
[thirdparty/cups.git] / test / ipptool.c
index 6d56f1c54f95b9d5ac17042fa5687085e788cc6b..00124c1f0d48b953921f046e3ba62c779c5ecbdb 100644 (file)
@@ -1,43 +1,18 @@
 /*
  * "$Id$"
  *
- *   ipptool command for CUPS.
+ * ipptool command for CUPS.
  *
- *   Copyright 2007-2010 by Apple Inc.
- *   Copyright 1997-2007 by Easy Software Products.
+ * Copyright 2007-2014 by Apple Inc.
+ * Copyright 1997-2007 by Easy Software Products.
  *
- *   These coded instructions, statements, and computer programs are the
- *   property of Apple Inc. and are protected by Federal copyright
- *   law.  Distribution and use rights are outlined in the file "LICENSE.txt"
- *   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/".
+ * These coded instructions, statements, and computer programs are the
+ * property of Apple Inc. and are protected by Federal copyright
+ * law.  Distribution and use rights are outlined in the file "LICENSE.txt"
+ * 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/".
  *
- * Contents:
- *
- *   main()              - Parse options and do tests.
- *   compare_vars()      - Compare two variables.
- *   do_tests()          - Do tests as specified in the test file.
- *   expand_variables()  - Expand variables in a string.
- *   expect_matches()    - Return true if the tag matches the specification.
- *   get_collection()    - Get a collection value from the current test file.
- *   get_filename()      - Get a filename based on the current test file.
- *   get_token()         - Get a token from a file.
- *   get_variable()      - Get the value of a variable.
- *   iso_date()          - Return an ISO 8601 date/time string for the given IPP
- *                         dateTime value.
- *   print_attr()        - Print an attribute on the screen.
- *   print_col()         - Print a collection attribute on the screen.
- *   print_csv()         - Print a line of CSV text.
- *   print_fatal_error() - Print a fatal error message.
- *   print_line()        - Print a line of formatted text.
- *   print_test_error()  - Print a test error message.
- *   print_xml_header()  - Print a standard XML plist header.
- *   print_xml_string()  - Print an XML string with escaping.
- *   print_xml_trailer() - Print the XML trailer with success/fail value.
- *   set_variable()      - Set a variable value.
- *   usage()             - Show program usage.
- *   validate_attr()     - Determine whether an attribute is valid.
- *   with_value()        - Test a WITH-VALUE predicate.
+ * This file is subject to the Apple OS-Developed Software exception.
  */
 
 /*
 #include <cups/cups-private.h>
 #include <cups/file-private.h>
 #include <regex.h>
-
+#include <sys/stat.h>
+#ifdef WIN32
+#  define R_OK 0
+#else
+#  include <signal.h>
+#endif /* WIN32 */
 #ifndef O_BINARY
 #  define O_BINARY 0
 #endif /* !O_BINARY */
@@ -73,6 +53,16 @@ typedef enum _cups_output_e          /**** Output mode ****/
   _CUPS_OUTPUT_CSV                     /* Comma-separated values output */
 } _cups_output_t;
 
+typedef enum _cups_with_e              /**** WITH flags ****/
+{
+  _CUPS_WITH_LITERAL = 0,              /* Match string is a literal value */
+  _CUPS_WITH_ALL = 1,                  /* Must match all values */
+  _CUPS_WITH_REGEX = 2,                        /* Match string is a regular expression */
+  _CUPS_WITH_HOSTNAME = 4,             /* Match string is a URI hostname */
+  _CUPS_WITH_RESOURCE = 8,             /* Match string is a URI resource */
+  _CUPS_WITH_SCHEME = 16               /* Match string is a URI scheme */
+} _cups_with_t;
+
 typedef struct _cups_expect_s          /**** Expected attribute info ****/
 {
   int          optional,               /* Optional attribute? */
@@ -81,9 +71,15 @@ typedef struct _cups_expect_s                /**** Expected attribute info ****/
                *of_type,               /* Type name */
                *same_count_as,         /* Parallel attribute name */
                *if_defined,            /* Only required if variable defined */
-               *if_undefined,          /* Only required if variable is not defined */
-               *with_value;            /* Attribute must include this value */
-  int          with_regex,             /* WITH-VALUE is a regular expression */
+               *if_not_defined,        /* Only required if variable is not defined */
+               *with_value,            /* Attribute must include this value */
+               *define_match,          /* Variable to define on match */
+               *define_no_match,       /* Variable to define on no-match */
+               *define_value;          /* Variable to define with value */
+  int          repeat_limit,           /* Maximum number of times to repeat */
+               repeat_match,           /* Repeat test on match */
+               repeat_no_match,        /* Repeat test on no match */
+               with_flags,             /* WITH flags  */
                count;                  /* Expected count if > 0 */
   ipp_tag_t    in_group;               /* IN-GROUP value */
 } _cups_expect_t;
@@ -92,7 +88,13 @@ typedef struct _cups_status_s                /**** Status info ****/
 {
   ipp_status_t status;                 /* Expected status code */
   char         *if_defined,            /* Only if variable is defined */
-               *if_undefined;          /* Only if variable is not defined */
+               *if_not_defined,        /* Only if variable is not defined */
+               *define_match,          /* Variable to define on match */
+               *define_no_match,       /* Variable to define on no-match */
+               *define_value;          /* Variable to define with value */
+  int          repeat_limit,           /* Maximum number of times to repeat */
+               repeat_match,           /* Repeat the test when it does not match */
+               repeat_no_match;        /* Repeat the test when it matches */
 } _cups_status_t;
 
 typedef struct _cups_var_s             /**** Variable ****/
@@ -103,14 +105,16 @@ typedef struct _cups_var_s                /**** Variable ****/
 
 typedef struct _cups_vars_s            /**** Set of variables ****/
 {
-  const char   *uri,                   /* URI for printer */
-               *filename;              /* Filename */
-  char         scheme[64],             /* Scheme from URI */
+  char         *uri,                   /* URI for printer */
+               *filename,              /* Filename */
+               scheme[64],             /* Scheme from URI */
                userpass[256],          /* Username/password from URI */
                hostname[256],          /* Hostname from URI */
                resource[1024];         /* Resource path from URI */
   int          port;                   /* Port number from URI */
   http_encryption_t encryption;                /* Encryption for connection? */
+  double       timeout;                /* Timeout for connection */
+  int          family;                 /* Address family */
   cups_array_t *vars;                  /* Array of variables */
 } _cups_vars_t;
 
@@ -119,74 +123,67 @@ typedef struct _cups_vars_s               /**** Set of variables ****/
  * Globals...
  */
 
-_cups_transfer_t Transfer = _CUPS_TRANSFER_AUTO;
+static _cups_transfer_t Transfer = _CUPS_TRANSFER_AUTO;
                                        /* How to transfer requests */
-_cups_output_t Output = _CUPS_OUTPUT_LIST;
+static _cups_output_t  Output = _CUPS_OUTPUT_LIST;
                                        /* Output mode */
-int            Verbosity = 0,          /* Show all attributes? */
+static int     Cancel = 0,             /* Cancel test? */
+               IgnoreErrors = 0,       /* Ignore errors? */
+               StopAfterIncludeError = 0,
+                                       /* Stop after include errors? */
+               Verbosity = 0,          /* Show all attributes? */
                Version = 11,           /* Default IPP version */
-               XMLHeader = 0;          /* 1 if header is written */
-const char * const URIStatusStrings[] =        /* URI status strings */
-{
-  "URI too large",
-  "Bad arguments to function",
-  "Bad resource in URI",
-  "Bad port number in URI",
-  "Bad hostname/address in URI",
-  "Bad username in URI",
-  "Bad scheme in URI",
-  "Bad/empty URI",
-  "OK",
-  "Missing scheme in URI",
-  "Unknown scheme in URI",
-  "Missing resource in URI"
-};
+               XMLHeader = 0,          /* 1 if header is written */
+               TestCount = 0,          /* Number of tests run */
+               PassCount = 0,          /* Number of passing tests */
+               FailCount = 0,          /* Number of failing tests */
+               SkipCount = 0;          /* Number of skipped tests */
+static char    *Password = NULL;       /* Password from URI */
 
 
 /*
  * Local functions...
  */
 
+static void    add_stringf(cups_array_t *a, const char *s, ...)
+               __attribute__ ((__format__ (__printf__, 2, 3)));
 static int     compare_vars(_cups_var_t *a, _cups_var_t *b);
 static int     do_tests(_cups_vars_t *vars, const char *testfile);
 static void    expand_variables(_cups_vars_t *vars, char *dst, const char *src,
-                                size_t dstsize)
-#ifdef __GNUC__
-__attribute((nonnull(1,2,3)))
-#endif /* __GNUC__ */
-;
+                                size_t dstsize) __attribute__((nonnull(1,2,3)));
 static int      expect_matches(_cups_expect_t *expect, ipp_tag_t value_tag);
 static ipp_t   *get_collection(_cups_vars_t *vars, FILE *fp, int *linenum);
 static char    *get_filename(const char *testfile, char *dst, const char *src,
                              size_t dstsize);
+static char    *get_string(ipp_attribute_t *attr, int element, int flags,
+                           char *buffer, size_t bufsize);
 static char    *get_token(FILE *fp, char *buf, int buflen,
                           int *linenum);
 static char    *get_variable(_cups_vars_t *vars, const char *name);
 static char    *iso_date(ipp_uchar_t *date);
-static void    print_attr(ipp_attribute_t *attr);
+static const char *password_cb(const char *prompt);
+static void    print_attr(ipp_attribute_t *attr, ipp_tag_t *group);
 static void    print_col(ipp_t *col);
 static void    print_csv(ipp_attribute_t *attr, int num_displayed,
                          char **displayed, size_t *widths);
 static void    print_fatal_error(const char *s, ...)
-#ifdef __GNUC__
-__attribute__ ((__format__ (__printf__, 1, 2)))
-#endif /* __GNUC__ */
-;
+               __attribute__ ((__format__ (__printf__, 1, 2)));
 static void    print_line(ipp_attribute_t *attr, int num_displayed,
                           char **displayed, size_t *widths);
-static void    print_test_error(const char *s, ...)
-#ifdef __GNUC__
-__attribute__ ((__format__ (__printf__, 1, 2)))
-#endif /* __GNUC__ */
-;
 static void    print_xml_header(void);
 static void    print_xml_string(const char *element, const char *s);
 static void    print_xml_trailer(int success, const char *message);
 static void    set_variable(_cups_vars_t *vars, const char *name,
                             const char *value);
-static void    usage(void);
-static int     validate_attr(ipp_attribute_t *attr, int print);
-static int      with_value(char *value, int regex, ipp_attribute_t *attr);
+#ifndef WIN32
+static void    sigterm_handler(int sig);
+#endif /* WIN32 */
+static int     timeout_cb(http_t *http, void *user_data);
+static void    usage(void) __attribute__((noreturn));
+static int     validate_attr(cups_array_t *errors, ipp_attribute_t *attr);
+static int      with_value(cups_array_t *errors, char *value, int flags,
+                          ipp_attribute_t *attr, char *matchbuf,
+                          size_t matchlen);
 
 
 /*
@@ -203,9 +200,11 @@ main(int  argc,                            /* I - Number of command-line args */
                        name[1024],     /* Name/value buffer */
                        *value,         /* Pointer to value */
                        filename[1024], /* Real filename */
-                       testname[1024]; /* Real test filename */
-  const char           *testfile;      /* Test file to use */
-  int                  interval,       /* Test interval */
+                       testname[1024], /* Real test filename */
+                       uri[1024];      /* Copy of printer URI */
+  const char           *ext,           /* Extension on filename */
+                       *testfile;      /* Test file to use */
+  int                  interval,       /* Test interval in microseconds */
                        repeat;         /* Repeat count */
   _cups_vars_t         vars;           /* Variables */
   http_uri_status_t    uri_status;     /* URI separation status */
@@ -213,6 +212,14 @@ main(int  argc,                            /* I - Number of command-line args */
                                        /* Global data */
 
 
+#ifndef WIN32
+ /*
+  * Catch SIGINT and SIGTERM...
+  */
+
+  signal(SIGINT, sigterm_handler);
+  signal(SIGTERM, sigterm_handler);
+#endif /* !WIN32 */
 
  /*
   * Initialize the locale and variables...
@@ -221,7 +228,8 @@ main(int  argc,                             /* I - Number of command-line args */
   _cupsSetLocale(argv);
 
   memset(&vars, 0, sizeof(vars));
-  vars.vars = cupsArrayNew((cups_array_func_t)compare_vars, NULL);
+  vars.family = AF_UNSPEC;
+  vars.vars   = cupsArrayNew((cups_array_func_t)compare_vars, NULL);
 
  /*
   * We need at least:
@@ -236,12 +244,35 @@ main(int  argc,                           /* I - Number of command-line args */
 
   for (i = 1; i < argc; i ++)
   {
-    if (argv[i][0] == '-')
+    if (!strcmp(argv[i], "--help"))
+    {
+      usage();
+    }
+    else if (!strcmp(argv[i], "--stop-after-include-error"))
+    {
+      StopAfterIncludeError = 1;
+    }
+    else if (!strcmp(argv[i], "--version"))
+    {
+      puts(CUPS_SVERSION);
+      return (0);
+    }
+    else if (argv[i][0] == '-')
     {
       for (opt = argv[i] + 1; *opt; opt ++)
       {
         switch (*opt)
         {
+         case '4' : /* Connect using IPv4 only */
+             vars.family = AF_INET;
+             break;
+
+#ifdef AF_INET6
+         case '6' : /* Connect using IPv6 only */
+             vars.family = AF_INET6;
+             break;
+#endif /* AF_INET6 */
+
           case 'C' : /* Enable HTTP chunking */
               Transfer = _CUPS_TRANSFER_CHUNKED;
               break;
@@ -250,12 +281,15 @@ main(int  argc,                           /* I - Number of command-line args */
 #ifdef HAVE_SSL
              vars.encryption = HTTP_ENCRYPT_REQUIRED;
 #else
-             _cupsLangPrintf(stderr,
-                             _("%s: Sorry, no encryption support compiled in\n"),
+             _cupsLangPrintf(stderr, _("%s: Sorry, no encryption support."),
                              argv[0]);
 #endif /* HAVE_SSL */
              break;
 
+          case 'I' : /* Ignore errors */
+             IgnoreErrors = 1;
+             break;
+
           case 'L' : /* Disable HTTP chunking */
               Transfer = _CUPS_TRANSFER_LENGTH;
               break;
@@ -264,19 +298,33 @@ main(int  argc,                           /* I - Number of command-line args */
 #ifdef HAVE_SSL
              vars.encryption = HTTP_ENCRYPT_ALWAYS;
 #else
-             _cupsLangPrintf(stderr,
-                             _("%s: Sorry, no encryption support compiled in\n"),
+             _cupsLangPrintf(stderr, _("%s: Sorry, no encryption support."),
                              argv[0]);
 #endif /* HAVE_SSL */
              break;
 
+         case 'T' : /* Set timeout */
+             i ++;
+
+             if (i >= argc)
+             {
+               _cupsLangPrintf(stderr,
+                               _("%s: Missing timeout for \"-T\"."),
+                               "ipptool");
+               usage();
+              }
+
+             vars.timeout = _cupsStrScand(argv[i], NULL, localeconv());
+             break;
+
          case 'V' : /* Set IPP version */
              i ++;
 
              if (i >= argc)
              {
-               _cupsLangPuts(stderr,
-                             _("ipptool: Missing version for \"-V\".\n"));
+               _cupsLangPrintf(stderr,
+                               _("%s: Missing version for \"-V\"."),
+                               "ipptool");
                usage();
               }
 
@@ -293,8 +341,8 @@ main(int  argc,                             /* I - Number of command-line args */
              else
              {
                _cupsLangPrintf(stderr,
-                               _("ipptool: Bad version %s for \"-V\".\n"),
-                               argv[i]);
+                               _("%s: Bad version %s for \"-V\"."),
+                               "ipptool", argv[i]);
                usage();
              }
              break;
@@ -305,7 +353,7 @@ main(int  argc,                             /* I - Number of command-line args */
               if (interval || repeat)
              {
                _cupsLangPuts(stderr, _("ipptool: \"-i\" and \"-n\" are "
-                                       "incompatible with -X\".\n"));
+                                       "incompatible with -X\"."));
                usage();
              }
              break;
@@ -320,7 +368,7 @@ main(int  argc,                             /* I - Number of command-line args */
              if (i >= argc)
              {
                _cupsLangPuts(stderr,
-                             _("ipptool: Missing name=value for \"-d\".\n"));
+                             _("ipptool: Missing name=value for \"-d\"."));
                usage();
               }
 
@@ -339,21 +387,95 @@ main(int  argc,                           /* I - Number of command-line args */
              if (i >= argc)
              {
                _cupsLangPuts(stderr,
-                             _("ipptool: Missing filename for \"-f\".\n"));
+                             _("ipptool: Missing filename for \"-f\"."));
                usage();
               }
 
-              if (access(argv[i], 0) && argv[i][0] != '/')
+              if (vars.filename)
+              {
+               free(vars.filename);
+               vars.filename = NULL;
+             }
+
+              if (access(argv[i], 0))
+              {
+               /*
+                * Try filename.gz...
+                */
+
+               snprintf(filename, sizeof(filename), "%s.gz", argv[i]);
+                if (access(filename, 0) && filename[0] != '/'
+#ifdef WIN32
+                    && (!isalpha(filename[0] & 255) || filename[1] != ':')
+#endif /* WIN32 */
+                    )
+               {
+                 snprintf(filename, sizeof(filename), "%s/ipptool/%s",
+                          cg->cups_datadir, argv[i]);
+                 if (access(filename, 0))
+                 {
+                   snprintf(filename, sizeof(filename), "%s/ipptool/%s.gz",
+                            cg->cups_datadir, argv[i]);
+                   if (access(filename, 0))
+                     vars.filename = strdup(argv[i]);
+                   else
+                     vars.filename = strdup(filename);
+                 }
+                 else
+                   vars.filename = strdup(filename);
+               }
+               else
+                 vars.filename = strdup(filename);
+             }
+              else
+               vars.filename = strdup(argv[i]);
+
+              if ((ext = strrchr(vars.filename, '.')) != NULL)
               {
-                snprintf(filename, sizeof(filename), "%s/ipptool/%s",
-                         cg->cups_datadir, argv[i]);
-                if (access(argv[i], 0))
-                 vars.filename = argv[i];
+               /*
+                * Guess the MIME media type based on the extension...
+                */
+
+                if (!_cups_strcasecmp(ext, ".gif"))
+                  set_variable(&vars, "filetype", "image/gif");
+                else if (!_cups_strcasecmp(ext, ".htm") ||
+                         !_cups_strcasecmp(ext, ".htm.gz") ||
+                         !_cups_strcasecmp(ext, ".html") ||
+                         !_cups_strcasecmp(ext, ".html.gz"))
+                  set_variable(&vars, "filetype", "text/html");
+                else if (!_cups_strcasecmp(ext, ".jpg"))
+                  set_variable(&vars, "filetype", "image/jpeg");
+                else if (!_cups_strcasecmp(ext, ".pcl") ||
+                         !_cups_strcasecmp(ext, ".pcl.gz"))
+                  set_variable(&vars, "filetype", "application/vnd.hp-PCL");
+                else if (!_cups_strcasecmp(ext, ".pdf"))
+                  set_variable(&vars, "filetype", "application/pdf");
+                else if (!_cups_strcasecmp(ext, ".png"))
+                  set_variable(&vars, "filetype", "image/png");
+                else if (!_cups_strcasecmp(ext, ".ps") ||
+                         !_cups_strcasecmp(ext, ".ps.gz"))
+                  set_variable(&vars, "filetype", "application/postscript");
+                else if (!_cups_strcasecmp(ext, ".pwg") ||
+                         !_cups_strcasecmp(ext, ".pwg.gz") ||
+                         !_cups_strcasecmp(ext, ".ras") ||
+                         !_cups_strcasecmp(ext, ".ras.gz"))
+                  set_variable(&vars, "filetype", "image/pwg-raster");
+                else if (!_cups_strcasecmp(ext, ".txt") ||
+                         !_cups_strcasecmp(ext, ".txt.gz"))
+                  set_variable(&vars, "filetype", "text/plain");
+                else if (!_cups_strcasecmp(ext, ".xps"))
+                  set_variable(&vars, "filetype", "application/openxps");
                 else
-                  vars.filename = filename;
+                 set_variable(&vars, "filetype", "application/octet-stream");
               }
               else
-               vars.filename = argv[i];
+              {
+               /*
+                * Use the "auto-type" MIME media type...
+                */
+
+               set_variable(&vars, "filetype", "application/octet-stream");
+              }
              break;
 
           case 'i' : /* Test every N seconds */
@@ -362,16 +484,25 @@ main(int  argc,                           /* I - Number of command-line args */
              if (i >= argc)
              {
                _cupsLangPuts(stderr,
-                             _("ipptool: Missing seconds for \"-i\".\n"));
+                             _("ipptool: Missing seconds for \"-i\"."));
                usage();
               }
              else
-               interval = atoi(argv[i]);
+             {
+               interval = (int)(_cupsStrScand(argv[i], NULL, localeconv()) *
+                                1000000.0);
+               if (interval <= 0)
+               {
+                 _cupsLangPuts(stderr,
+                               _("ipptool: Invalid seconds for \"-i\"."));
+                 usage();
+               }
+              }
 
               if (Output == _CUPS_OUTPUT_PLIST && interval)
              {
-               _cupsLangPuts(stderr, _("ipptool: \"-i\" is incompatible with "
-                                       "\"-X\".\n"));
+               _cupsLangPuts(stderr, _("ipptool: \"-i\" and \"-n\" are "
+                                       "incompatible with -X\"."));
                usage();
              }
              break;
@@ -386,7 +517,7 @@ main(int  argc,                             /* I - Number of command-line args */
              if (i >= argc)
              {
                _cupsLangPuts(stderr,
-                             _("ipptool: Missing count for \"-n\".\n"));
+                             _("ipptool: Missing count for \"-n\"."));
                usage();
               }
              else
@@ -394,8 +525,8 @@ main(int  argc,                             /* I - Number of command-line args */
 
               if (Output == _CUPS_OUTPUT_PLIST && repeat)
              {
-               _cupsLangPuts(stderr, _("ipptool: \"-n\" is incompatible with "
-                                       "\"-X\".\n"));
+               _cupsLangPuts(stderr, _("ipptool: \"-i\" and \"-n\" are "
+                                       "incompatible with -X\"."));
                usage();
              }
              break;
@@ -413,16 +544,18 @@ main(int  argc,                           /* I - Number of command-line args */
              break;
 
          default :
-             _cupsLangPrintf(stderr, _("ipptool: Unknown option \"-%c\".\n"),
+             _cupsLangPrintf(stderr, _("ipptool: Unknown option \"-%c\"."),
                              *opt);
              usage();
-             break;
        }
       }
     }
-    else if (!strncmp(argv[i], "ipp://", 6) ||
-             !strncmp(argv[i], "http://", 7) ||
-             !strncmp(argv[i], "https://", 8))
+    else if (!strncmp(argv[i], "ipp://", 6) || !strncmp(argv[i], "http://", 7)
+#ifdef HAVE_SSL
+            || !strncmp(argv[i], "ipps://", 7)
+            || !strncmp(argv[i], "https://", 8)
+#endif /* HAVE_SSL */
+            )
     {
      /*
       * Set URI...
@@ -430,10 +563,15 @@ main(int  argc,                           /* I - Number of command-line args */
 
       if (vars.uri)
       {
-        _cupsLangPuts(stderr, _("ipptool: May only specify a single URI.\n"));
+        _cupsLangPuts(stderr, _("ipptool: May only specify a single URI."));
         usage();
       }
 
+#ifdef HAVE_SSL
+      if (!strncmp(argv[i], "ipps://", 7) || !strncmp(argv[i], "https://", 8))
+        vars.encryption = HTTP_ENCRYPT_ALWAYS;
+#endif /* HAVE_SSL */
+
       vars.uri   = argv[i];
       uri_status = httpSeparateURI(HTTP_URI_CODING_ALL, vars.uri,
                                    vars.scheme, sizeof(vars.scheme),
@@ -444,18 +582,23 @@ main(int  argc,                           /* I - Number of command-line args */
 
       if (uri_status != HTTP_URI_OK)
       {
-        _cupsLangPrintf(stderr, _("ipptool: Bad URI - %s.\n"),
-                       URIStatusStrings[uri_status - HTTP_URI_OVERFLOW]);
+        _cupsLangPrintf(stderr, _("ipptool: Bad URI - %s."), httpURIStatusString(uri_status));
         return (1);
       }
 
-      if (strcmp(vars.scheme, "http") && strcmp(vars.scheme, "https") &&
-          strcmp(vars.scheme, "ipp"))
+      if (vars.userpass[0])
       {
-        _cupsLangPuts(stderr, _("ipptool: Only http, https, and ipp URIs are "
-                               "supported."));
-       return (1);
+        if ((Password = strchr(vars.userpass, ':')) != NULL)
+         *Password++ = '\0';
+
+        cupsSetUser(vars.userpass);
+       cupsSetPasswordCB(password_cb);
+       set_variable(&vars, "uriuser", vars.userpass);
       }
+
+      httpAssembleURI(HTTP_URI_CODING_ALL, uri, sizeof(uri), vars.scheme, NULL,
+                      vars.hostname, vars.port, vars.resource);
+      vars.uri = uri;
     }
     else
     {
@@ -469,7 +612,11 @@ main(int  argc,                            /* I - Number of command-line args */
        usage();
       }
 
-      if (access(argv[i], 0) && argv[i][0] != '/')
+      if (access(argv[i], 0) && argv[i][0] != '/'
+#ifdef WIN32
+          && (!isalpha(argv[i][0] & 255) || argv[i][1] != ':')
+#endif /* WIN32 */
+          )
       {
         snprintf(testname, sizeof(testname), "%s/ipptool/%s", cg->cups_datadir,
                  argv[i]);
@@ -495,23 +642,33 @@ main(int  argc,                           /* I - Number of command-line args */
 
   if (Output == _CUPS_OUTPUT_PLIST)
     print_xml_trailer(!status, NULL);
-  else if (interval && repeat > 0)
+  else if (interval > 0 && repeat > 0)
   {
     while (repeat > 1)
     {
-      sleep(interval);
+      usleep((useconds_t)interval);
       do_tests(&vars, testfile);
       repeat --;
     }
   }
-  else if (interval)
+  else if (interval > 0)
   {
     for (;;)
     {
-      sleep(interval);
+      usleep((useconds_t)interval);
       do_tests(&vars, testfile);
     }
   }
+  else if (Output == _CUPS_OUTPUT_TEST && TestCount > 1)
+  {
+   /*
+    * Show a summary report if there were multiple tests...
+    */
+
+    printf("\nSummary: %d tests, %d passed, %d failed, %d skipped\n"
+           "Score: %d%%\n", TestCount, PassCount, FailCount, SkipCount,
+           100 * (PassCount + SkipCount) / TestCount);
+  }
 
  /*
   * Exit...
@@ -521,6 +678,42 @@ main(int  argc,                            /* I - Number of command-line args */
 }
 
 
+/*
+ * 'add_stringf()' - Add a formatted string to an array.
+ */
+
+static void
+add_stringf(cups_array_t *a,           /* I - Array */
+            const char   *s,           /* I - Printf-style format string */
+            ...)                       /* I - Additional args as needed */
+{
+  char         buffer[10240];          /* Format buffer */
+  va_list      ap;                     /* Argument pointer */
+
+
+ /*
+  * Don't bother is the array is NULL...
+  */
+
+  if (!a)
+    return;
+
+ /*
+  * Format the message...
+  */
+
+  va_start(ap, s);
+  vsnprintf(buffer, sizeof(buffer), s, ap);
+  va_end(ap);
+
+ /*
+  * Add it to the array...
+  */
+
+  cupsArrayAdd(a, buffer);
+}
+
+
 /*
  * 'compare_vars()' - Compare two variables.
  */
@@ -529,7 +722,7 @@ static int                          /* O - Result of comparison */
 compare_vars(_cups_var_t *a,           /* I - First variable */
              _cups_var_t *b)           /* I - Second variable */
 {
-  return (strcasecmp(a->name, b->name));
+  return (_cups_strcasecmp(a->name, b->name));
 }
 
 
@@ -544,15 +737,29 @@ do_tests(_cups_vars_t *vars,              /* I - Variables */
   int          i,                      /* Looping var */
                linenum,                /* Current line number */
                pass,                   /* Did we pass the test? */
-               request_id;             /* Current request ID */
+               prev_pass = 1,          /* Did we pass the previous test? */
+               request_id,             /* Current request ID */
+               show_header = 1,        /* Show the test header? */
+               ignore_errors,          /* Ignore test failures? */
+               skip_previous = 0,      /* Skip on previous test failure? */
+               repeat_count,           /* Repeat count */
+               repeat_interval,        /* Repeat interval */
+               repeat_prev,            /* Previous repeat interval */
+               repeat_test;            /* Repeat a test? */
   http_t       *http = NULL;           /* HTTP connection to server */
   FILE         *fp = NULL;             /* Test file */
   char         resource[512],          /* Resource for request */
                token[1024],            /* Token from file */
                *tokenptr,              /* Pointer into token */
-               temp[1024];             /* Temporary string */
-  ipp_t                *request = NULL;        /* IPP request */
-  ipp_t                *response = NULL;       /* IPP response */
+               temp[1024],             /* Temporary string */
+               buffer[8192],           /* Copy buffer */
+               compression[16];        /* COMPRESSION value */
+  ipp_t                *request = NULL,        /* IPP request */
+               *response = NULL;       /* IPP response */
+  size_t       length;                 /* Length of IPP request */
+  http_status_t        status;                 /* HTTP status */
+  cups_file_t  *reqfile;               /* File to send */
+  ssize_t      bytes;                  /* Bytes read/written */
   char         attr[128];              /* Attribute name */
   ipp_op_t     op;                     /* Operation */
   ipp_tag_t    group;                  /* Current group */
@@ -560,10 +767,13 @@ do_tests(_cups_vars_t *vars,              /* I - Variables */
   ipp_attribute_t *attrptr,            /* Attribute pointer */
                *found,                 /* Found attribute */
                *lastcol = NULL;        /* Last collection attribute */
-  char         name[1024];             /* Name of test */
+  char         name[1024],             /* Name of test */
+               file_id[1024],          /* File identifier */
+               test_id[1024];          /* Test identifier */
   char         filename[1024];         /* Filename */
   _cups_transfer_t transfer;           /* To chunk or not to chunk */
-  int          version;                /* IPP version number to use */
+  int          version,                /* IPP version number to use */
+               skip_test;              /* Skip this test? */
   int          num_statuses = 0;       /* Number of valid status codes */
   _cups_status_t statuses[100],                /* Valid status codes */
                *last_status;           /* Last STATUS (for predicates) */
@@ -574,6 +784,9 @@ do_tests(_cups_vars_t *vars,                /* I - Variables */
   int          num_displayed = 0;      /* Number of displayed attributes */
   char         *displayed[200];        /* Displayed attributes */
   size_t       widths[200];            /* Width of columns */
+  cups_array_t *a,                     /* Duplicate attribute array */
+               *errors = NULL;         /* Errors array */
+  const char   *error;                 /* Current error */
 
 
  /*
@@ -584,37 +797,47 @@ do_tests(_cups_vars_t *vars,              /* I - Variables */
   {
     print_fatal_error("Unable to open test file %s - %s", testfile,
                       strerror(errno));
-    goto test_error;
+    pass = 0;
+    goto test_exit;
   }
 
  /*
   * Connect to the server...
   */
 
-  if ((http = httpConnectEncrypt(vars->hostname, vars->port,
-                                 vars->encryption)) == NULL)
+  if ((http = httpConnect2(vars->hostname, vars->port, NULL, vars->family,
+                           vars->encryption, 1, 30000, NULL)) == NULL)
   {
     print_fatal_error("Unable to connect to %s on port %d - %s", vars->hostname,
-                      vars->port, strerror(errno));
-    goto test_error;
+                      vars->port, cupsLastErrorString());
+    pass = 0;
+    goto test_exit;
   }
 
+#ifdef HAVE_LIBZ
+  httpSetDefaultField(http, HTTP_FIELD_ACCEPT_ENCODING,
+                      "deflate, gzip, identity");
+#else
+  httpSetDefaultField(http, HTTP_FIELD_ACCEPT_ENCODING, "identity");
+#endif /* HAVE_LIBZ */
+
+  if (vars->timeout > 0.0)
+    httpSetTimeout(http, vars->timeout, timeout_cb, NULL);
+
  /*
   * Loop on tests...
   */
 
-  if (Output == _CUPS_OUTPUT_PLIST)
-    print_xml_header();
-  else if (Output == _CUPS_OUTPUT_TEST)
-    printf("\"%s\":\n", testfile);
-
   CUPS_SRAND(time(NULL));
 
+  errors     = cupsArrayNew3(NULL, NULL, NULL, 0, (cups_acopy_func_t)strdup,
+                             (cups_afree_func_t)free);
+  file_id[0] = '\0';
   pass       = 1;
   linenum    = 1;
   request_id = (CUPS_RAND() % 1000) * 137 + 1;
 
-  while (get_token(fp, token, sizeof(token), &linenum) != NULL)
+  while (!Cancel && get_token(fp, token, sizeof(token), &linenum) != NULL)
   {
    /*
     * Expect an open brace...
@@ -636,7 +859,71 @@ do_tests(_cups_vars_t *vars,               /* I - Variables */
       {
         print_fatal_error("Missing DEFINE name and/or value on line %d.",
                          linenum);
-        goto test_error;
+       pass = 0;
+       goto test_exit;
+      }
+
+      continue;
+    }
+    else if (!strcmp(token, "DEFINE-DEFAULT"))
+    {
+     /*
+      * DEFINE-DEFAULT name value
+      */
+
+      if (get_token(fp, attr, sizeof(attr), &linenum) &&
+          get_token(fp, temp, sizeof(temp), &linenum))
+      {
+        expand_variables(vars, token, temp, sizeof(token));
+       if (!get_variable(vars, attr))
+         set_variable(vars, attr, token);
+      }
+      else
+      {
+        print_fatal_error("Missing DEFINE-DEFAULT name and/or value on line "
+                         "%d.", linenum);
+       pass = 0;
+       goto test_exit;
+      }
+
+      continue;
+    }
+    else if (!strcmp(token, "FILE-ID"))
+    {
+     /*
+      * FILE-ID "string"
+      */
+
+      if (get_token(fp, temp, sizeof(temp), &linenum))
+      {
+        expand_variables(vars, file_id, temp, sizeof(file_id));
+      }
+      else
+      {
+        print_fatal_error("Missing FILE-ID value on line %d.", linenum);
+       pass = 0;
+       goto test_exit;
+      }
+
+      continue;
+    }
+    else if (!strcmp(token, "IGNORE-ERRORS"))
+    {
+     /*
+      * IGNORE-ERRORS yes
+      * IGNORE-ERRORS no
+      */
+
+      if (get_token(fp, temp, sizeof(temp), &linenum) &&
+          (!_cups_strcasecmp(temp, "yes") || !_cups_strcasecmp(temp, "no")))
+      {
+        IgnoreErrors = !_cups_strcasecmp(temp, "yes");
+      }
+      else
+      {
+        print_fatal_error("Missing IGNORE-ERRORS value on line %d.", linenum);
+       pass = 0;
+       goto test_exit;
       }
 
       continue;
@@ -656,12 +943,149 @@ do_tests(_cups_vars_t *vars,             /* I - Variables */
 
         if (!do_tests(vars, get_filename(testfile, filename, temp,
                                         sizeof(filename))))
-         goto test_error;
+       {
+         pass = 0;
+
+         if (StopAfterIncludeError)
+           goto test_exit;
+       }
       }
       else
       {
         print_fatal_error("Missing INCLUDE filename on line %d.", linenum);
-        goto test_error;
+       pass = 0;
+       goto test_exit;
+      }
+
+      show_header = 1;
+      continue;
+    }
+    else if (!strcmp(token, "INCLUDE-IF-DEFINED"))
+    {
+     /*
+      * INCLUDE-IF-DEFINED name "filename"
+      * INCLUDE-IF-DEFINED name <filename>
+      */
+
+      if (get_token(fp, attr, sizeof(attr), &linenum) &&
+          get_token(fp, temp, sizeof(temp), &linenum))
+      {
+       /*
+        * Map the filename to and then run the tests...
+       */
+
+        if (get_variable(vars, attr) &&
+           !do_tests(vars, get_filename(testfile, filename, temp,
+                                        sizeof(filename))))
+       {
+         pass = 0;
+
+         if (StopAfterIncludeError)
+           goto test_exit;
+       }
+      }
+      else
+      {
+        print_fatal_error("Missing INCLUDE-IF-DEFINED name or filename on line "
+                         "%d.", linenum);
+       pass = 0;
+       goto test_exit;
+      }
+
+      show_header = 1;
+      continue;
+    }
+    else if (!strcmp(token, "INCLUDE-IF-NOT-DEFINED"))
+    {
+     /*
+      * INCLUDE-IF-NOT-DEFINED name "filename"
+      * INCLUDE-IF-NOT-DEFINED name <filename>
+      */
+
+      if (get_token(fp, attr, sizeof(attr), &linenum) &&
+          get_token(fp, temp, sizeof(temp), &linenum))
+      {
+       /*
+        * Map the filename to and then run the tests...
+       */
+
+        if (!get_variable(vars, attr) &&
+           !do_tests(vars, get_filename(testfile, filename, temp,
+                                        sizeof(filename))))
+       {
+         pass = 0;
+
+         if (StopAfterIncludeError)
+           goto test_exit;
+       }
+      }
+      else
+      {
+        print_fatal_error("Missing INCLUDE-IF-NOT-DEFINED name or filename on "
+                         "line %d.", linenum);
+       pass = 0;
+       goto test_exit;
+      }
+
+      show_header = 1;
+      continue;
+    }
+    else if (!strcmp(token, "SKIP-IF-DEFINED"))
+    {
+     /*
+      * SKIP-IF-DEFINED variable
+      */
+
+      if (get_token(fp, temp, sizeof(temp), &linenum))
+      {
+        if (get_variable(vars, temp))
+         goto test_exit;
+      }
+      else
+      {
+        print_fatal_error("Missing SKIP-IF-DEFINED variable on line %d.",
+                         linenum);
+       pass = 0;
+       goto test_exit;
+      }
+    }
+    else if (!strcmp(token, "SKIP-IF-NOT-DEFINED"))
+    {
+     /*
+      * SKIP-IF-NOT-DEFINED variable
+      */
+
+      if (get_token(fp, temp, sizeof(temp), &linenum))
+      {
+        if (!get_variable(vars, temp))
+         goto test_exit;
+      }
+      else
+      {
+        print_fatal_error("Missing SKIP-IF-NOT-DEFINED variable on line %d.",
+                         linenum);
+       pass = 0;
+       goto test_exit;
+      }
+    }
+    else if (!strcmp(token, "STOP-AFTER-INCLUDE-ERROR"))
+    {
+     /*
+      * STOP-AFTER-INCLUDE-ERROR yes
+      * STOP-AFTER-INCLUDE-ERROR no
+      */
+
+      if (get_token(fp, temp, sizeof(temp), &linenum) &&
+          (!_cups_strcasecmp(temp, "yes") || !_cups_strcasecmp(temp, "no")))
+      {
+        StopAfterIncludeError = !_cups_strcasecmp(temp, "yes");
+      }
+      else
+      {
+        print_fatal_error("Missing STOP-AFTER-INCLUDE-ERROR value on line %d.",
+                          linenum);
+       pass = 0;
+       goto test_exit;
       }
 
       continue;
@@ -686,13 +1110,15 @@ do_tests(_cups_vars_t *vars,             /* I - Variables */
        {
          print_fatal_error("Bad TRANSFER value \"%s\" on line %d.", temp,
                            linenum);
-         goto test_error;
+         pass = 0;
+         goto test_exit;
        }
       }
       else
       {
         print_fatal_error("Missing TRANSFER value on line %d.", linenum);
-        goto test_error;
+       pass = 0;
+       goto test_exit;
       }
 
       continue;
@@ -714,13 +1140,15 @@ do_tests(_cups_vars_t *vars,             /* I - Variables */
        else
        {
          print_fatal_error("Bad VERSION \"%s\" on line %d.", temp, linenum);
-         goto test_error;
+         pass = 0;
+         goto test_exit;
        }
       }
       else
       {
         print_fatal_error("Missing VERSION number on line %d.", linenum);
-        goto test_error;
+       pass = 0;
+       goto test_exit;
       }
 
       continue;
@@ -728,24 +1156,40 @@ do_tests(_cups_vars_t *vars,             /* I - Variables */
     else if (strcmp(token, "{"))
     {
       print_fatal_error("Unexpected token %s seen on line %d.", token, linenum);
-      goto test_error;
+      pass = 0;
+      goto test_exit;
     }
 
    /*
     * Initialize things...
     */
 
+    if (show_header)
+    {
+      if (Output == _CUPS_OUTPUT_PLIST)
+       print_xml_header();
+      else if (Output == _CUPS_OUTPUT_TEST)
+       printf("\"%s\":\n", testfile);
+
+      show_header = 0;
+    }
+
     strlcpy(resource, vars->resource, sizeof(resource));
 
     request_id ++;
-    request       = ippNew();
-    op            = (ipp_op_t)0;
-    group         = IPP_TAG_ZERO;
-    last_expect   = NULL;
-    last_status   = NULL;
-    filename[0]   = '\0';
-    version       = Version;
-    transfer      = Transfer;
+    request        = ippNew();
+    op             = (ipp_op_t)0;
+    group          = IPP_TAG_ZERO;
+    ignore_errors  = IgnoreErrors;
+    last_expect    = NULL;
+    last_status    = NULL;
+    filename[0]    = '\0';
+    skip_previous  = 0;
+    skip_test      = 0;
+    test_id[0]     = '\0';
+    version        = Version;
+    transfer       = Transfer;
+    compression[0] = '\0';
 
     strlcpy(name, testfile, sizeof(name));
     if (strrchr(name, '.') != NULL)
@@ -757,17 +1201,35 @@ do_tests(_cups_vars_t *vars,             /* I - Variables */
 
     while (get_token(fp, token, sizeof(token), &linenum) != NULL)
     {
-      if (strcasecmp(token, "COUNT") &&
-          strcasecmp(token, "IF-DEFINED") &&
-          strcasecmp(token, "IF-UNDEFINED") &&
-          strcasecmp(token, "IN-GROUP") &&
-          strcasecmp(token, "OF-TYPE") &&
-          strcasecmp(token, "SAME-COUNT-AS") &&
-          strcasecmp(token, "WITH-VALUE"))
+      if (_cups_strcasecmp(token, "COUNT") &&
+          _cups_strcasecmp(token, "DEFINE-MATCH") &&
+          _cups_strcasecmp(token, "DEFINE-NO-MATCH") &&
+          _cups_strcasecmp(token, "DEFINE-VALUE") &&
+          _cups_strcasecmp(token, "IF-DEFINED") &&
+          _cups_strcasecmp(token, "IF-NOT-DEFINED") &&
+          _cups_strcasecmp(token, "IN-GROUP") &&
+          _cups_strcasecmp(token, "OF-TYPE") &&
+          _cups_strcasecmp(token, "REPEAT-LIMIT") &&
+          _cups_strcasecmp(token, "REPEAT-MATCH") &&
+          _cups_strcasecmp(token, "REPEAT-NO-MATCH") &&
+          _cups_strcasecmp(token, "SAME-COUNT-AS") &&
+          _cups_strcasecmp(token, "WITH-ALL-VALUES") &&
+          _cups_strcasecmp(token, "WITH-ALL-HOSTNAMES") &&
+          _cups_strcasecmp(token, "WITH-ALL-RESOURCES") &&
+          _cups_strcasecmp(token, "WITH-ALL-SCHEMES") &&
+          _cups_strcasecmp(token, "WITH-HOSTNAME") &&
+          _cups_strcasecmp(token, "WITH-RESOURCE") &&
+          _cups_strcasecmp(token, "WITH-SCHEME") &&
+          _cups_strcasecmp(token, "WITH-VALUE"))
         last_expect = NULL;
 
-      if (strcasecmp(token, "IF-DEFINED") &&
-          strcasecmp(token, "IF-UNDEFINED"))
+      if (_cups_strcasecmp(token, "DEFINE-MATCH") &&
+          _cups_strcasecmp(token, "DEFINE-NO-MATCH") &&
+         _cups_strcasecmp(token, "IF-DEFINED") &&
+          _cups_strcasecmp(token, "IF-NOT-DEFINED") &&
+          _cups_strcasecmp(token, "REPEAT-LIMIT") &&
+          _cups_strcasecmp(token, "REPEAT-MATCH") &&
+          _cups_strcasecmp(token, "REPEAT-NO-MATCH"))
         last_status = NULL;
 
       if (!strcmp(token, "}"))
@@ -783,40 +1245,47 @@ do_tests(_cups_vars_t *vars,             /* I - Variables */
 
        if (col)
        {
-         ipp_attribute_t *tempcol;     /* Pointer to new buffer */
+          ippSetCollection(request, &lastcol, ippGetCount(lastcol), col);
+        }
+       else
+       {
+         pass = 0;
+         goto test_exit;
+       }
+      }
+      else if (!strcmp(token, "COMPRESSION"))
+      {
+       /*
+       * COMPRESSION none
+       * COMPRESSION deflate
+       * COMPRESSION gzip
+       */
 
+       if (get_token(fp, temp, sizeof(temp), &linenum))
+       {
+         expand_variables(vars, compression, temp, sizeof(compression));
+#ifdef HAVE_LIBZ
+         if (strcmp(compression, "none") && strcmp(compression, "deflate") &&
+             strcmp(compression, "gzip"))
+#else
+         if (strcmp(compression, "none"))
+#endif /* HAVE_LIBZ */
+          {
+           print_fatal_error("Unsupported COMPRESSION value '%s' on line %d.",
+                             compression, linenum);
+           pass = 0;
+           goto test_exit;
+          }
 
-        /*
-         * Reallocate memory...
-         */
-
-         if ((tempcol = realloc(lastcol, sizeof(ipp_attribute_t) +
-                                         (lastcol->num_values + 1) *
-                                         sizeof(ipp_value_t))) == NULL)
-         {
-           print_fatal_error("Unable to allocate memory on line %d.", linenum);
-           goto test_error;
-         }
-
-         if (tempcol != lastcol)
-         {
-          /*
-           * Reset pointers in the list...
-           */
-
-           if (request->prev)
-             request->prev->next = tempcol;
-           else
-             request->attrs = tempcol;
-
-           lastcol = request->current = request->last = tempcol;
-         }
-
-         lastcol->values[lastcol->num_values].collection = col;
-         lastcol->num_values ++;
+          if (!strcmp(compression, "none"))
+            compression[0] = '\0';
        }
        else
-         goto test_error;
+       {
+         print_fatal_error("Missing COMPRESSION value on line %d.", linenum);
+         pass = 0;
+         goto test_exit;
+       }
       }
       else if (!strcmp(token, "DEFINE"))
       {
@@ -834,10 +1303,32 @@ do_tests(_cups_vars_t *vars,             /* I - Variables */
        {
          print_fatal_error("Missing DEFINE name and/or value on line %d.",
                            linenum);
-         goto test_error;
+         pass = 0;
+         goto test_exit;
+       }
+      }
+      else if (!strcmp(token, "IGNORE-ERRORS"))
+      {
+       /*
+       * IGNORE-ERRORS yes
+       * IGNORE-ERRORS no
+       */
+
+       if (get_token(fp, temp, sizeof(temp), &linenum) &&
+           (!_cups_strcasecmp(temp, "yes") || !_cups_strcasecmp(temp, "no")))
+       {
+         ignore_errors = !_cups_strcasecmp(temp, "yes");
+       }
+       else
+       {
+         print_fatal_error("Missing IGNORE-ERRORS value on line %d.", linenum);
+         pass = 0;
+         goto test_exit;
        }
+
+       continue;
       }
-      else if (!strcasecmp(token, "NAME"))
+      else if (!_cups_strcasecmp(token, "NAME"))
       {
        /*
         * Name of test...
@@ -856,21 +1347,123 @@ do_tests(_cups_vars_t *vars,            /* I - Variables */
        {
          if (isdigit(temp[0] & 255))
            request_id = atoi(temp);
-         else if (!strcasecmp(temp, "random"))
+         else if (!_cups_strcasecmp(temp, "random"))
            request_id = (CUPS_RAND() % 1000) * 137 + 1;
          else
          {
            print_fatal_error("Bad REQUEST-ID value \"%s\" on line %d.", temp,
                              linenum);
-           goto test_error;
+           pass = 0;
+           goto test_exit;
          }
        }
        else
        {
          print_fatal_error("Missing REQUEST-ID value on line %d.", linenum);
-         goto test_error;
+         pass = 0;
+         goto test_exit;
+       }
+      }
+      else if (!strcmp(token, "SKIP-IF-DEFINED"))
+      {
+       /*
+       * SKIP-IF-DEFINED variable
+       */
+
+       if (get_token(fp, temp, sizeof(temp), &linenum))
+       {
+         if (get_variable(vars, temp))
+           skip_test = 1;
+       }
+       else
+       {
+         print_fatal_error("Missing SKIP-IF-DEFINED value on line %d.",
+                           linenum);
+         pass = 0;
+         goto test_exit;
+       }
+      }
+      else if (!strcmp(token, "SKIP-IF-MISSING"))
+      {
+       /*
+       * SKIP-IF-MISSING filename
+       */
+
+       if (get_token(fp, temp, sizeof(temp), &linenum))
+       {
+         expand_variables(vars, token, temp, sizeof(token));
+         get_filename(testfile, filename, token, sizeof(filename));
+
+         if (access(filename, R_OK))
+           skip_test = 1;
+       }
+       else
+       {
+         print_fatal_error("Missing SKIP-IF-MISSING filename on line %d.",
+                           linenum);
+         pass = 0;
+         goto test_exit;
        }
       }
+      else if (!strcmp(token, "SKIP-IF-NOT-DEFINED"))
+      {
+       /*
+       * SKIP-IF-NOT-DEFINED variable
+       */
+
+       if (get_token(fp, temp, sizeof(temp), &linenum))
+       {
+         if (!get_variable(vars, temp))
+           skip_test = 1;
+       }
+       else
+       {
+         print_fatal_error("Missing SKIP-IF-NOT-DEFINED value on line %d.",
+                           linenum);
+         pass = 0;
+         goto test_exit;
+       }
+      }
+      else if (!strcmp(token, "SKIP-PREVIOUS-ERROR"))
+      {
+       /*
+       * SKIP-PREVIOUS-ERROR yes
+       * SKIP-PREVIOUS-ERROR no
+       */
+
+       if (get_token(fp, temp, sizeof(temp), &linenum) &&
+           (!_cups_strcasecmp(temp, "yes") || !_cups_strcasecmp(temp, "no")))
+       {
+         skip_previous = !_cups_strcasecmp(temp, "yes");
+       }
+       else
+       {
+         print_fatal_error("Missing SKIP-PREVIOUS-ERROR value on line %d.", linenum);
+         pass = 0;
+         goto test_exit;
+       }
+
+       continue;
+      }
+      else if (!strcmp(token, "TEST-ID"))
+      {
+       /*
+       * TEST-ID "string"
+       */
+
+       if (get_token(fp, temp, sizeof(temp), &linenum))
+       {
+         expand_variables(vars, test_id, temp, sizeof(test_id));
+       }
+       else
+       {
+         print_fatal_error("Missing TEST-ID value on line %d.", linenum);
+         pass = 0;
+         goto test_exit;
+       }
+
+       continue;
+      }
       else if (!strcmp(token, "TRANSFER"))
       {
        /*
@@ -891,16 +1484,18 @@ do_tests(_cups_vars_t *vars,             /* I - Variables */
          {
            print_fatal_error("Bad TRANSFER value \"%s\" on line %d.", temp,
                              linenum);
-           goto test_error;
+           pass = 0;
+           goto test_exit;
          }
        }
        else
        {
          print_fatal_error("Missing TRANSFER value on line %d.", linenum);
-         goto test_error;
+         pass = 0;
+         goto test_exit;
        }
       }
-      else if (!strcasecmp(token, "VERSION"))
+      else if (!_cups_strcasecmp(token, "VERSION"))
       {
        if (get_token(fp, temp, sizeof(temp), &linenum))
        {
@@ -919,16 +1514,18 @@ do_tests(_cups_vars_t *vars,             /* I - Variables */
          else
          {
            print_fatal_error("Bad VERSION \"%s\" on line %d.", temp, linenum);
-           goto test_error;
+           pass = 0;
+           goto test_exit;
          }
        }
        else
        {
          print_fatal_error("Missing VERSION number on line %d.", linenum);
-         goto test_error;
+         pass = 0;
+         goto test_exit;
        }
       }
-      else if (!strcasecmp(token, "RESOURCE"))
+      else if (!_cups_strcasecmp(token, "RESOURCE"))
       {
        /*
         * Resource name...
@@ -937,29 +1534,35 @@ do_tests(_cups_vars_t *vars,             /* I - Variables */
        if (!get_token(fp, resource, sizeof(resource), &linenum))
        {
          print_fatal_error("Missing RESOURCE path on line %d.", linenum);
-         goto test_error;
+         pass = 0;
+         goto test_exit;
        }
       }
-      else if (!strcasecmp(token, "OPERATION"))
+      else if (!_cups_strcasecmp(token, "OPERATION"))
       {
        /*
         * Operation...
        */
 
-       if (!get_token(fp, token, sizeof(token), &linenum))
+       if (!get_token(fp, temp, sizeof(temp), &linenum))
        {
          print_fatal_error("Missing OPERATION code on line %d.", linenum);
-         goto test_error;
+         pass = 0;
+         goto test_exit;
        }
 
-       if ((op = ippOpValue(token)) < 0 && (op = strtol(token, NULL, 0)) == 0)
+       expand_variables(vars, token, temp, sizeof(token));
+
+       if ((op = ippOpValue(token)) == (ipp_op_t)-1 &&
+           (op = (ipp_op_t)strtol(token, NULL, 0)) == 0)
        {
          print_fatal_error("Bad OPERATION code \"%s\" on line %d.", token,
                            linenum);
-         goto test_error;
+         pass = 0;
+         goto test_exit;
        }
       }
-      else if (!strcasecmp(token, "GROUP"))
+      else if (!_cups_strcasecmp(token, "GROUP"))
       {
        /*
         * Attribute group...
@@ -968,13 +1571,15 @@ do_tests(_cups_vars_t *vars,             /* I - Variables */
        if (!get_token(fp, token, sizeof(token), &linenum))
        {
          print_fatal_error("Missing GROUP tag on line %d.", linenum);
-         goto test_error;
+         pass = 0;
+         goto test_exit;
        }
 
        if ((value = ippTagValue(token)) < 0)
        {
          print_fatal_error("Bad GROUP tag \"%s\" on line %d.", token, linenum);
-         goto test_error;
+         pass = 0;
+         goto test_exit;
        }
 
        if (value == group)
@@ -982,30 +1587,39 @@ do_tests(_cups_vars_t *vars,             /* I - Variables */
 
         group = value;
       }
-      else if (!strcasecmp(token, "DELAY"))
+      else if (!_cups_strcasecmp(token, "DELAY"))
       {
        /*
         * Delay before operation...
        */
 
-        int delay;
+        double delay;
 
-       if (!get_token(fp, token, sizeof(token), &linenum))
+       if (!get_token(fp, temp, sizeof(temp), &linenum))
        {
          print_fatal_error("Missing DELAY value on line %d.", linenum);
-         goto test_error;
+         pass = 0;
+         goto test_exit;
        }
 
-       if ((delay = atoi(token)) <= 0)
+       expand_variables(vars, token, temp, sizeof(token));
+
+       if ((delay = _cupsStrScand(token, NULL, localeconv())) <= 0.0)
        {
          print_fatal_error("Bad DELAY value \"%s\" on line %d.", token,
                            linenum);
-         goto test_error;
+         pass = 0;
+         goto test_exit;
        }
        else
-         sleep(delay);
+       {
+         if (Output == _CUPS_OUTPUT_TEST)
+           printf("    [%g second delay]\n", delay);
+
+         usleep((useconds_t)(1000000.0 * delay));
+       }
       }
-      else if (!strcasecmp(token, "ATTR"))
+      else if (!_cups_strcasecmp(token, "ATTR"))
       {
        /*
         * Attribute...
@@ -1014,68 +1628,110 @@ do_tests(_cups_vars_t *vars,           /* I - Variables */
        if (!get_token(fp, token, sizeof(token), &linenum))
        {
          print_fatal_error("Missing ATTR value tag on line %d.", linenum);
-         goto test_error;
+         pass = 0;
+         goto test_exit;
        }
 
        if ((value = ippTagValue(token)) == IPP_TAG_ZERO)
        {
          print_fatal_error("Bad ATTR value tag \"%s\" on line %d.", token,
                            linenum);
-         goto test_error;
+         pass = 0;
+         goto test_exit;
        }
 
        if (!get_token(fp, attr, sizeof(attr), &linenum))
        {
          print_fatal_error("Missing ATTR name on line %d.", linenum);
-         goto test_error;
+         pass = 0;
+         goto test_exit;
        }
 
        if (!get_token(fp, temp, sizeof(temp), &linenum))
        {
          print_fatal_error("Missing ATTR value on line %d.", linenum);
-         goto test_error;
+         pass = 0;
+         goto test_exit;
        }
 
         expand_variables(vars, token, temp, sizeof(token));
+        attrptr = NULL;
 
         switch (value)
        {
          case IPP_TAG_BOOLEAN :
-             if (!strcasecmp(token, "true"))
-               ippAddBoolean(request, group, attr, 1);
+             if (!_cups_strcasecmp(token, "true"))
+               attrptr = ippAddBoolean(request, group, attr, 1);
               else
-               ippAddBoolean(request, group, attr, atoi(token));
+               attrptr = ippAddBoolean(request, group, attr, (char)atoi(token));
              break;
 
          case IPP_TAG_INTEGER :
          case IPP_TAG_ENUM :
-             ippAddInteger(request, group, value, attr, atoi(token));
+             if (!strchr(token, ','))
+               attrptr = ippAddInteger(request, group, value, attr, (int)strtol(token, &tokenptr, 0));
+             else
+             {
+               int     values[100],    /* Values */
+                       num_values = 1; /* Number of values */
+
+               values[0] = (int)strtol(token, &tokenptr, 10);
+               while (tokenptr && *tokenptr &&
+                      num_values < (int)(sizeof(values) / sizeof(values[0])))
+               {
+                 if (*tokenptr == ',')
+                   tokenptr ++;
+                 else if (!isdigit(*tokenptr & 255) && *tokenptr != '-')
+                   break;
+
+                 values[num_values] = (int)strtol(tokenptr, &tokenptr, 0);
+                 num_values ++;
+               }
+
+               attrptr = ippAddIntegers(request, group, value, attr, num_values, values);
+             }
+
+             if (!tokenptr || *tokenptr)
+             {
+               print_fatal_error("Bad %s value \"%s\" on line %d.",
+                                 ippTagString(value), token, linenum);
+               pass = 0;
+               goto test_exit;
+             }
              break;
 
          case IPP_TAG_RESOLUTION :
              {
                int     xres,           /* X resolution */
                        yres;           /* Y resolution */
-               char    units[6];       /* Units */
-
-                if (sscanf(token, "%dx%d%5s", &xres, &yres, units) != 3 ||
-                   (strcasecmp(units, "dpi") && strcasecmp(units, "dpc") &&
-                    strcasecmp(units, "other")))
-               {
-                 print_fatal_error("Bad resolution value \"%s\" on line %d.",
+               char    *ptr;           /* Pointer into value */
+
+               xres = yres = (int)strtol(token, (char **)&ptr, 10);
+               if (ptr > token && xres > 0)
+               {
+                 if (*ptr == 'x')
+                   yres = (int)strtol(ptr + 1, (char **)&ptr, 10);
+               }
+
+               if (ptr <= token || xres <= 0 || yres <= 0 || !ptr ||
+                   (_cups_strcasecmp(ptr, "dpi") &&
+                    _cups_strcasecmp(ptr, "dpc") &&
+                    _cups_strcasecmp(ptr, "dpcm") &&
+                    _cups_strcasecmp(ptr, "other")))
+               {
+                 print_fatal_error("Bad resolution value \"%s\" on line %d.",
                                    token, linenum);
-                 goto test_error;
-               }
-
-               if (!strcasecmp(units, "dpi"))
-                 ippAddResolution(request, group, attr, xres, yres,
-                                  IPP_RES_PER_INCH);
-               else if (!strcasecmp(units, "dpc"))
-                 ippAddResolution(request, group, attr, xres, yres,
-                                  IPP_RES_PER_CM);
-               else
-                 ippAddResolution(request, group, attr, xres, yres,
-                                  (ipp_res_t)0);
+                 pass = 0;
+                 goto test_exit;
+               }
+
+               if (!_cups_strcasecmp(ptr, "dpi"))
+                 attrptr = ippAddResolution(request, group, attr, IPP_RES_PER_INCH, xres, yres);
+               else if (!_cups_strcasecmp(ptr, "dpc") ||
+                        !_cups_strcasecmp(ptr, "dpcm"))
+                 attrptr = ippAddResolution(request, group, attr, IPP_RES_PER_CM, xres, yres);
+               else
+                 attrptr = ippAddResolution(request, group, attr, (ipp_res_t)0, xres, yres);
              }
              break;
 
@@ -1096,11 +1752,12 @@ do_tests(_cups_vars_t *vars,            /* I - Variables */
                {
                  print_fatal_error("Bad rangeOfInteger value \"%s\" on line "
                                    "%d.", token, linenum);
-                 goto test_error;
+                 pass = 0;
+                 goto test_exit;
                }
 
-               ippAddRanges(request, group, attr, num_vals / 2, lowers,
-                            uppers);
+               attrptr = ippAddRanges(request, group, attr, num_vals / 2, lowers,
+                                      uppers);
              }
              break;
 
@@ -1112,24 +1769,33 @@ do_tests(_cups_vars_t *vars,            /* I - Variables */
 
                 if (col)
                 {
-                 lastcol = ippAddCollection(request, group, attr, col);
+                 attrptr = lastcol = ippAddCollection(request, group, attr, col);
                  ippDelete(col);
                }
                else
-                 goto test_error;
+               {
+                 pass = 0;
+                 goto test_exit;
+               }
               }
              else
              {
                print_fatal_error("Bad ATTR collection value on line %d.",
                                  linenum);
-               goto test_error;
+               pass = 0;
+               goto test_exit;
              }
              break;
 
+          case IPP_TAG_STRING :
+              attrptr = ippAddOctetString(request, group, attr, token, (int)strlen(token));
+             break;
+
          default :
              print_fatal_error("Unsupported ATTR value tag %s on line %d.",
                                ippTagString(value), linenum);
-             goto test_error;
+             pass = 0;
+             goto test_exit;
 
          case IPP_TAG_TEXTLANG :
          case IPP_TAG_NAMELANG :
@@ -1142,7 +1808,7 @@ do_tests(_cups_vars_t *vars,              /* I - Variables */
          case IPP_TAG_LANGUAGE :
          case IPP_TAG_MIMETYPE :
              if (!strchr(token, ','))
-               ippAddString(request, group, value, attr, NULL, token);
+               attrptr = ippAddString(request, group, value, attr, NULL, token);
              else
              {
               /*
@@ -1159,18 +1825,31 @@ do_tests(_cups_vars_t *vars,            /* I - Variables */
 
                 for (ptr = strchr(token, ','); ptr; ptr = strchr(ptr, ','))
                {
-                 *ptr++ = '\0';
-                 values[num_values] = ptr;
-                 num_values ++;
+                 if (ptr > token && ptr[-1] == '\\')
+                   _cups_strcpy(ptr - 1, ptr);
+                 else
+                 {
+                   *ptr++ = '\0';
+                   values[num_values] = ptr;
+                   num_values ++;
+                 }
                }
 
-               ippAddStrings(request, group, value, attr, num_values,
-                             NULL, (const char **)values);
+               attrptr = ippAddStrings(request, group, value, attr, num_values,
+                                       NULL, (const char **)values);
              }
              break;
        }
+
+       if (!attrptr)
+       {
+         print_fatal_error("Unable to add attribute on line %d: %s", linenum,
+                           cupsLastErrorString());
+         pass = 0;
+         goto test_exit;
+       }
       }
-      else if (!strcasecmp(token, "FILE"))
+      else if (!_cups_strcasecmp(token, "FILE"))
       {
        /*
         * File...
@@ -1179,13 +1858,23 @@ do_tests(_cups_vars_t *vars,            /* I - Variables */
        if (!get_token(fp, temp, sizeof(temp), &linenum))
        {
          print_fatal_error("Missing FILE filename on line %d.", linenum);
-         goto test_error;
+         pass = 0;
+         goto test_exit;
        }
 
         expand_variables(vars, token, temp, sizeof(token));
        get_filename(testfile, filename, token, sizeof(filename));
+
+        if (access(filename, R_OK))
+        {
+         print_fatal_error("Filename \"%s\" on line %d cannot be read.",
+                           temp, linenum);
+         print_fatal_error("Filename mapped to \"%s\".", filename);
+         pass = 0;
+         goto test_exit;
+        }
       }
-      else if (!strcasecmp(token, "STATUS"))
+      else if (!_cups_strcasecmp(token, "STATUS"))
       {
        /*
         * Status...
@@ -1194,29 +1883,39 @@ do_tests(_cups_vars_t *vars,            /* I - Variables */
         if (num_statuses >= (int)(sizeof(statuses) / sizeof(statuses[0])))
        {
          print_fatal_error("Too many STATUS's on line %d.", linenum);
-         goto test_error;
+         pass = 0;
+         goto test_exit;
        }
 
        if (!get_token(fp, token, sizeof(token), &linenum))
        {
          print_fatal_error("Missing STATUS code on line %d.", linenum);
-         goto test_error;
+         pass = 0;
+         goto test_exit;
        }
 
-       if ((statuses[num_statuses].status = ippErrorValue(token)) < 0)
+       if ((statuses[num_statuses].status = ippErrorValue(token))
+               == (ipp_status_t)-1 &&
+           (statuses[num_statuses].status = (ipp_status_t)strtol(token, NULL, 0)) == 0)
        {
          print_fatal_error("Bad STATUS code \"%s\" on line %d.", token,
                            linenum);
-         goto test_error;
+         pass = 0;
+         goto test_exit;
        }
 
         last_status = statuses + num_statuses;
        num_statuses ++;
 
-       last_status->if_defined   = NULL;
-       last_status->if_undefined = NULL;
+        last_status->define_match    = NULL;
+        last_status->define_no_match = NULL;
+       last_status->if_defined      = NULL;
+       last_status->if_not_defined  = NULL;
+       last_status->repeat_limit    = 1000;
+       last_status->repeat_match    = 0;
+       last_status->repeat_no_match = 0;
       }
-      else if (!strcasecmp(token, "EXPECT"))
+      else if (!_cups_strcasecmp(token, "EXPECT"))
       {
        /*
         * Expected attributes...
@@ -1225,19 +1924,22 @@ do_tests(_cups_vars_t *vars,            /* I - Variables */
         if (num_expects >= (int)(sizeof(expects) / sizeof(expects[0])))
         {
          print_fatal_error("Too many EXPECT's on line %d.", linenum);
-         goto test_error;
+         pass = 0;
+         goto test_exit;
         }
 
        if (!get_token(fp, token, sizeof(token), &linenum))
        {
          print_fatal_error("Missing EXPECT name on line %d.", linenum);
-         goto test_error;
+         pass = 0;
+         goto test_exit;
        }
 
         last_expect = expects + num_expects;
        num_expects ++;
 
        memset(last_expect, 0, sizeof(_cups_expect_t));
+       last_expect->repeat_limit = 1000;
 
         if (token[0] == '!')
         {
@@ -1252,18 +1954,20 @@ do_tests(_cups_vars_t *vars,            /* I - Variables */
         else
          last_expect->name = strdup(token);
       }
-      else if (!strcasecmp(token, "COUNT"))
+      else if (!_cups_strcasecmp(token, "COUNT"))
       {
        if (!get_token(fp, token, sizeof(token), &linenum))
        {
          print_fatal_error("Missing COUNT number on line %d.", linenum);
-         goto test_error;
+         pass = 0;
+         goto test_exit;
        }
 
         if ((i = atoi(token)) <= 0)
        {
          print_fatal_error("Bad COUNT \"%s\" on line %d.", token, linenum);
-         goto test_error;
+         pass = 0;
+         goto test_exit;
        }
 
        if (last_expect)
@@ -1272,16 +1976,82 @@ do_tests(_cups_vars_t *vars,            /* I - Variables */
        {
          print_fatal_error("COUNT without a preceding EXPECT on line %d.",
                            linenum);
-         goto test_error;
+         pass = 0;
+         goto test_exit;
+       }
+      }
+      else if (!_cups_strcasecmp(token, "DEFINE-MATCH"))
+      {
+       if (!get_token(fp, token, sizeof(token), &linenum))
+       {
+         print_fatal_error("Missing DEFINE-MATCH variable on line %d.",
+                           linenum);
+         pass = 0;
+         goto test_exit;
+       }
+
+       if (last_expect)
+         last_expect->define_match = strdup(token);
+       else if (last_status)
+         last_status->define_match = strdup(token);
+       else
+       {
+         print_fatal_error("DEFINE-MATCH without a preceding EXPECT or STATUS "
+                           "on line %d.", linenum);
+         pass = 0;
+         goto test_exit;
+       }
+      }
+      else if (!_cups_strcasecmp(token, "DEFINE-NO-MATCH"))
+      {
+       if (!get_token(fp, token, sizeof(token), &linenum))
+       {
+         print_fatal_error("Missing DEFINE-NO-MATCH variable on line %d.",
+                           linenum);
+         pass = 0;
+         goto test_exit;
+       }
+
+       if (last_expect)
+         last_expect->define_no_match = strdup(token);
+       else if (last_status)
+         last_status->define_no_match = strdup(token);
+       else
+       {
+         print_fatal_error("DEFINE-NO-MATCH without a preceding EXPECT or "
+                           "STATUS on line %d.", linenum);
+         pass = 0;
+         goto test_exit;
+       }
+      }
+      else if (!_cups_strcasecmp(token, "DEFINE-VALUE"))
+      {
+       if (!get_token(fp, token, sizeof(token), &linenum))
+       {
+         print_fatal_error("Missing DEFINE-VALUE variable on line %d.",
+                           linenum);
+         pass = 0;
+         goto test_exit;
+       }
+
+       if (last_expect)
+         last_expect->define_value = strdup(token);
+       else
+       {
+         print_fatal_error("DEFINE-VALUE without a preceding EXPECT on "
+                           "line %d.", linenum);
+         pass = 0;
+         goto test_exit;
        }
       }
-      else if (!strcasecmp(token, "OF-TYPE"))
+      else if (!_cups_strcasecmp(token, "OF-TYPE"))
       {
        if (!get_token(fp, token, sizeof(token), &linenum))
        {
          print_fatal_error("Missing OF-TYPE value tag(s) on line %d.",
                            linenum);
-         goto test_error;
+         pass = 0;
+         goto test_exit;
        }
 
        if (last_expect)
@@ -1290,10 +2060,11 @@ do_tests(_cups_vars_t *vars,            /* I - Variables */
        {
          print_fatal_error("OF-TYPE without a preceding EXPECT on line %d.",
                            linenum);
-         goto test_error;
+         pass = 0;
+         goto test_exit;
        }
       }
-      else if (!strcasecmp(token, "IN-GROUP"))
+      else if (!_cups_strcasecmp(token, "IN-GROUP"))
       {
         ipp_tag_t      in_group;       /* IN-GROUP value */
 
@@ -1301,7 +2072,8 @@ do_tests(_cups_vars_t *vars,              /* I - Variables */
        if (!get_token(fp, token, sizeof(token), &linenum))
        {
          print_fatal_error("Missing IN-GROUP group tag on line %d.", linenum);
-         goto test_error;
+         pass = 0;
+         goto test_exit;
        }
 
         if ((in_group = ippTagValue(token)) == (ipp_tag_t)-1)
@@ -1313,15 +2085,72 @@ do_tests(_cups_vars_t *vars,            /* I - Variables */
        {
          print_fatal_error("IN-GROUP without a preceding EXPECT on line %d.",
                            linenum);
-         goto test_error;
+         pass = 0;
+         goto test_exit;
+       }
+      }
+      else if (!_cups_strcasecmp(token, "REPEAT-LIMIT"))
+      {
+       if (!get_token(fp, token, sizeof(token), &linenum))
+       {
+         print_fatal_error("Missing REPEAT-LIMIT value on line %d.", linenum);
+         pass = 0;
+         goto test_exit;
+       }
+       else if (atoi(token) <= 0)
+       {
+         print_fatal_error("Bad REPEAT-LIMIT value on line %d.", linenum);
+         pass = 0;
+         goto test_exit;
+       }
+
+        if (last_status)
+          last_status->repeat_limit = atoi(token);
+       else if (last_expect)
+         last_expect->repeat_limit = atoi(token);
+       else
+       {
+         print_fatal_error("REPEAT-LIMIT without a preceding EXPECT or STATUS "
+                           "on line %d.", linenum);
+         pass = 0;
+         goto test_exit;
+       }
+      }
+      else if (!_cups_strcasecmp(token, "REPEAT-MATCH"))
+      {
+        if (last_status)
+          last_status->repeat_match = 1;
+       else if (last_expect)
+         last_expect->repeat_match = 1;
+       else
+       {
+         print_fatal_error("REPEAT-MATCH without a preceding EXPECT or STATUS "
+                           "on line %d.", linenum);
+         pass = 0;
+         goto test_exit;
+       }
+      }
+      else if (!_cups_strcasecmp(token, "REPEAT-NO-MATCH"))
+      {
+       if (last_status)
+         last_status->repeat_no_match = 1;
+       else if (last_expect)
+         last_expect->repeat_no_match = 1;
+       else
+       {
+         print_fatal_error("REPEAT-NO-MATCH without a preceding EXPECT or "
+                           "STATUS on ine %d.", linenum);
+         pass = 0;
+         goto test_exit;
        }
       }
-      else if (!strcasecmp(token, "SAME-COUNT-AS"))
+      else if (!_cups_strcasecmp(token, "SAME-COUNT-AS"))
       {
        if (!get_token(fp, token, sizeof(token), &linenum))
        {
          print_fatal_error("Missing SAME-COUNT-AS name on line %d.", linenum);
-         goto test_error;
+         pass = 0;
+         goto test_exit;
        }
 
        if (last_expect)
@@ -1330,15 +2159,17 @@ do_tests(_cups_vars_t *vars,            /* I - Variables */
        {
          print_fatal_error("SAME-COUNT-AS without a preceding EXPECT on line "
                            "%d.", linenum);
-         goto test_error;
+         pass = 0;
+         goto test_exit;
        }
       }
-      else if (!strcasecmp(token, "IF-DEFINED"))
+      else if (!_cups_strcasecmp(token, "IF-DEFINED"))
       {
        if (!get_token(fp, token, sizeof(token), &linenum))
        {
          print_fatal_error("Missing IF-DEFINED name on line %d.", linenum);
-         goto test_error;
+         pass = 0;
+         goto test_exit;
        }
 
        if (last_expect)
@@ -1349,50 +2180,84 @@ do_tests(_cups_vars_t *vars,            /* I - Variables */
        {
          print_fatal_error("IF-DEFINED without a preceding EXPECT or STATUS "
                            "on line %d.", linenum);
-         goto test_error;
+         pass = 0;
+         goto test_exit;
        }
       }
-      else if (!strcasecmp(token, "IF-UNDEFINED"))
+      else if (!_cups_strcasecmp(token, "IF-NOT-DEFINED"))
       {
        if (!get_token(fp, token, sizeof(token), &linenum))
        {
-         print_fatal_error("Missing IF-UNDEFINED name on line %d.", linenum);
-         goto test_error;
+         print_fatal_error("Missing IF-NOT-DEFINED name on line %d.", linenum);
+         pass = 0;
+         goto test_exit;
        }
 
        if (last_expect)
-         last_expect->if_undefined = strdup(token);
+         last_expect->if_not_defined = strdup(token);
        else if (last_status)
-         last_status->if_undefined = strdup(token);
+         last_status->if_not_defined = strdup(token);
        else
        {
-         print_fatal_error("IF-UNDEFINED without a preceding EXPECT or STATUS "
+         print_fatal_error("IF-NOT-DEFINED without a preceding EXPECT or STATUS "
                            "on line %d.", linenum);
-         goto test_error;
+         pass = 0;
+         goto test_exit;
        }
       }
-      else if (!strcasecmp(token, "WITH-VALUE"))
+      else if (!_cups_strcasecmp(token, "WITH-ALL-VALUES") ||
+               !_cups_strcasecmp(token, "WITH-ALL-HOSTNAMES") ||
+               !_cups_strcasecmp(token, "WITH-ALL-RESOURCES") ||
+               !_cups_strcasecmp(token, "WITH-ALL-SCHEMES") ||
+               !_cups_strcasecmp(token, "WITH-HOSTNAME") ||
+               !_cups_strcasecmp(token, "WITH-RESOURCE") ||
+               !_cups_strcasecmp(token, "WITH-SCHEME") ||
+               !_cups_strcasecmp(token, "WITH-VALUE"))
       {
-       if (!get_token(fp, token, sizeof(token), &linenum))
+       if (last_expect)
        {
-         print_fatal_error("Missing WITH-VALUE value on line %d.", linenum);
-         goto test_error;
+         if (!_cups_strcasecmp(token, "WITH-ALL-HOSTNAMES") ||
+             !_cups_strcasecmp(token, "WITH-HOSTNAME"))
+           last_expect->with_flags = _CUPS_WITH_HOSTNAME;
+         else if (!_cups_strcasecmp(token, "WITH-ALL-RESOURCES") ||
+             !_cups_strcasecmp(token, "WITH-RESOURCE"))
+           last_expect->with_flags = _CUPS_WITH_RESOURCE;
+         else if (!_cups_strcasecmp(token, "WITH-ALL-SCHEMES") ||
+             !_cups_strcasecmp(token, "WITH-SCHEME"))
+           last_expect->with_flags = _CUPS_WITH_SCHEME;
+
+         if (!_cups_strncasecmp(token, "WITH-ALL-", 9))
+           last_expect->with_flags |= _CUPS_WITH_ALL;
+        }
+
+       if (!get_token(fp, temp, sizeof(temp), &linenum))
+       {
+         print_fatal_error("Missing %s value on line %d.", token, linenum);
+         pass = 0;
+         goto test_exit;
        }
 
         if (last_expect)
        {
-         tokenptr = token + strlen(token) - 1;
-         if (token[0] == '/' && tokenptr > token && *tokenptr == '/')
-         {
-          /*
+        /*
+         * Expand any variables in the value and then save it.
+         */
+
+         expand_variables(vars, token, temp, sizeof(token));
+
+         tokenptr = token + strlen(token) - 1;
+
+         if (token[0] == '/' && tokenptr > token && *tokenptr == '/')
+         {
+          /*
            * WITH-VALUE is a POSIX extended regular expression.
            */
 
-           last_expect->with_value = calloc(1, tokenptr - token);
-           last_expect->with_regex = 1;
+           last_expect->with_value = calloc(1, (size_t)(tokenptr - token));
+           last_expect->with_flags |= _CUPS_WITH_REGEX;
 
            if (last_expect->with_value)
-             memcpy(last_expect->with_value, token + 1, tokenptr - token - 1);
+             memcpy(last_expect->with_value, token + 1, (size_t)(tokenptr - token - 1));
          }
          else
          {
@@ -1400,17 +2265,33 @@ do_tests(_cups_vars_t *vars,            /* I - Variables */
            * WITH-VALUE is a literal value...
            */
 
+           char *ptr;                  /* Pointer into value */
+
+            for (ptr = token; *ptr; ptr ++)
+            {
+             if (*ptr == '\\' && ptr[1])
+             {
+              /*
+               * Remove \ from \foo...
+               */
+
+               _cups_strcpy(ptr, ptr + 1);
+             }
+           }
+
            last_expect->with_value = strdup(token);
+           last_expect->with_flags |= _CUPS_WITH_LITERAL;
          }
        }
        else
        {
-         print_fatal_error("WITH-VALUE without a preceding EXPECT on line %d.",
+         print_fatal_error("%s without a preceding EXPECT on line %d.", token,
                            linenum);
-         goto test_error;
+         pass = 0;
+         goto test_exit;
        }
       }
-      else if (!strcasecmp(token, "DISPLAY"))
+      else if (!_cups_strcasecmp(token, "DISPLAY"))
       {
        /*
         * Display attributes...
@@ -1419,13 +2300,15 @@ do_tests(_cups_vars_t *vars,            /* I - Variables */
         if (num_displayed >= (int)(sizeof(displayed) / sizeof(displayed[0])))
        {
          print_fatal_error("Too many DISPLAY's on line %d", linenum);
-         goto test_error;
+         pass = 0;
+         goto test_exit;
        }
 
        if (!get_token(fp, token, sizeof(token), &linenum))
        {
          print_fatal_error("Missing DISPLAY name on line %d.", linenum);
-         goto test_error;
+         pass = 0;
+         goto test_exit;
        }
 
        displayed[num_displayed] = strdup(token);
@@ -1435,7 +2318,8 @@ do_tests(_cups_vars_t *vars,              /* I - Variables */
       {
        print_fatal_error("Unexpected token %s seen on line %d.", token,
                          linenum);
-       goto test_error;
+       pass = 0;
+       goto test_exit;
       }
     }
 
@@ -1443,372 +2327,300 @@ do_tests(_cups_vars_t *vars,          /* I - Variables */
     * Submit the IPP request...
     */
 
-    request->request.op.version[0]   = version / 10;
-    request->request.op.version[1]   = version % 10;
-    request->request.op.operation_id = op;
-    request->request.op.request_id   = request_id;
+    TestCount ++;
+
+    ippSetVersion(request, version / 10, version % 10);
+    ippSetOperation(request, op);
+    ippSetRequestId(request, request_id);
 
     if (Output == _CUPS_OUTPUT_PLIST)
     {
       puts("<dict>");
       puts("<key>Name</key>");
       print_xml_string("string", name);
+      if (file_id[0])
+      {
+       puts("<key>FileId</key>");
+       print_xml_string("string", file_id);
+      }
+      if (test_id[0])
+      {
+        puts("<key>TestId</key>");
+        print_xml_string("string", test_id);
+      }
+      puts("<key>Version</key>");
+      printf("<string>%d.%d</string>\n", version / 10, version % 10);
       puts("<key>Operation</key>");
       print_xml_string("string", ippOpString(op));
+      puts("<key>RequestId</key>");
+      printf("<integer>%d</integer>\n", request_id);
       puts("<key>RequestAttributes</key>");
-      puts("<dict>");
-      for (attrptr = request->attrs; attrptr; attrptr = attrptr->next)
-       print_attr(attrptr);
-      puts("</dict>");
+      puts("<array>");
+      if (request->attrs)
+      {
+       puts("<dict>");
+       for (attrptr = request->attrs,
+                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)
     {
       if (Verbosity)
       {
-        printf("    %s:\n", ippOpString(op));
+       printf("    %s:\n", ippOpString(op));
 
-        for (attrptr = request->attrs; attrptr; attrptr = attrptr->next)
-          print_attr(attrptr);
+       for (attrptr = request->attrs; attrptr; attrptr = attrptr->next)
+         print_attr(attrptr, NULL);
       }
 
-      printf("    %-69.69s [", name);
+      printf("    %-68.68s [", name);
       fflush(stdout);
     }
 
-    if (transfer == _CUPS_TRANSFER_CHUNKED ||
-        (transfer == _CUPS_TRANSFER_AUTO && filename[0]))
+    if ((skip_previous && !prev_pass) || skip_test)
     {
-     /*
-      * Send request using chunking...
-      */
+      SkipCount ++;
 
-      http_status_t status = cupsSendRequest(http, request, resource, 0);
+      ippDelete(request);
+      request = NULL;
 
-      if (status == HTTP_CONTINUE && filename[0])
+      if (Output == _CUPS_OUTPUT_PLIST)
       {
-        int    fd;                     /* File to send */
-        char   buffer[8192];           /* Copy buffer */
-        ssize_t        bytes;                  /* Bytes read/written */
-
-        if ((fd = open(filename, O_RDONLY | O_BINARY)) >= 0)
-        {
-          while ((bytes = read(fd, buffer, sizeof(buffer))) > 0)
-            if ((status = cupsWriteRequestData(http, buffer,
-                                               bytes)) != HTTP_CONTINUE)
-              break;
-        }
-        else
-       {
-         snprintf(buffer, sizeof(buffer), "%s: %s", filename, strerror(errno));
-         _cupsSetError(IPP_INTERNAL_ERROR, buffer, 0);
-
-          status = HTTP_ERROR;
-       }
+       puts("<key>Successful</key>");
+       puts("<true />");
+       puts("<key>StatusCode</key>");
+       print_xml_string("string", "skip");
+       puts("<key>ResponseAttributes</key>");
+       puts("<dict />");
       }
+      else if (Output == _CUPS_OUTPUT_TEST)
+       puts("SKIP]");
 
-      ippDelete(request);
-
-      if (status == HTTP_CONTINUE)
-       response = cupsGetResponse(http, resource);
-      else
-       response = NULL;
+      goto skip_error;
     }
-    else if (filename[0])
-      response = cupsDoFileRequest(http, request, resource, filename);
-    else
-      response = cupsDoRequest(http, request, resource);
 
-    request = NULL;
+    repeat_count    = 0;
+    repeat_interval = 1;
+    repeat_prev     = 1;
 
-    if (!response)
-      pass = 0;
-    else
+    do
     {
-      if (http->version != HTTP_1_1)
-        pass = 0;
+      repeat_count ++;
 
-      if (response->request.status.version[0] != (version / 10) ||
-         response->request.status.version[1] != (version % 10) ||
-         response->request.status.request_id != request_id)
-        pass = 0;
+      status = HTTP_OK;
 
-      if ((attrptr = ippFindAttribute(response, "job-id",
-                                      IPP_TAG_INTEGER)) != NULL)
+      if (transfer == _CUPS_TRANSFER_CHUNKED ||
+         (transfer == _CUPS_TRANSFER_AUTO && filename[0]))
       {
-        snprintf(temp, sizeof(temp), "%d", attrptr->values[0].integer);
-       set_variable(vars, "job-id", temp);
-      }
-
-      if ((attrptr = ippFindAttribute(response, "job-uri",
-                                      IPP_TAG_URI)) != NULL)
-       set_variable(vars, "job-uri", attrptr->values[0].string.text);
+       /*
+       * Send request using chunking - a 0 length means "chunk".
+       */
 
-      if ((attrptr = ippFindAttribute(response, "notify-subscription-id",
-                                      IPP_TAG_INTEGER)) != NULL)
-      {
-        snprintf(temp, sizeof(temp), "%d", attrptr->values[0].integer);
-       set_variable(vars, "notify-subscription-id", temp);
+       length = 0;
       }
-
-      attrptr = response->attrs;
-      if (!attrptr || !attrptr->name ||
-         attrptr->value_tag != IPP_TAG_CHARSET ||
-         attrptr->group_tag != IPP_TAG_OPERATION ||
-         attrptr->num_values != 1 ||
-          strcmp(attrptr->name, "attributes-charset"))
-        pass = 0;
-
-      if (attrptr)
+      else
       {
-        attrptr = attrptr->next;
-       if (!attrptr || !attrptr->name ||
-           attrptr->value_tag != IPP_TAG_LANGUAGE ||
-           attrptr->group_tag != IPP_TAG_OPERATION ||
-           attrptr->num_values != 1 ||
-           strcmp(attrptr->name, "attributes-natural-language"))
-         pass = 0;
-      }
-
-      if ((attrptr = ippFindAttribute(response, "status-message",
-                                      IPP_TAG_ZERO)) != NULL &&
-          (attrptr->value_tag != IPP_TAG_TEXT ||
-          attrptr->group_tag != IPP_TAG_OPERATION ||
-          attrptr->num_values != 1 ||
-          (attrptr->value_tag == IPP_TAG_TEXT &&
-           strlen(attrptr->values[0].string.text) > 255)))
-       pass = 0;
+       /*
+       * Send request using content length...
+       */
 
-      if ((attrptr = ippFindAttribute(response, "detailed-status-message",
-                                      IPP_TAG_ZERO)) != NULL &&
-          (attrptr->value_tag != IPP_TAG_TEXT ||
-          attrptr->group_tag != IPP_TAG_OPERATION ||
-          attrptr->num_values != 1 ||
-          (attrptr->value_tag == IPP_TAG_TEXT &&
-           strlen(attrptr->values[0].string.text) > 1023)))
-       pass = 0;
+       length = ippLength(request);
 
-      for (attrptr = response->attrs, group = attrptr->group_tag;
-           attrptr;
-          attrptr = attrptr->next)
-      {
-        if (attrptr->group_tag < group && attrptr->group_tag != IPP_TAG_ZERO)
+       if (filename[0] && (reqfile = cupsFileOpen(filename, "r")) != NULL)
        {
-         pass = 0;
-         break;
-       }
+        /*
+         * Read the file to get the uncompressed file size...
+         */
 
-        if (!validate_attr(attrptr, 0))
-       {
-         pass = 0;
-         break;
+         while ((bytes = cupsFileRead(reqfile, buffer, sizeof(buffer))) > 0)
+           length += (size_t)bytes;
+
+         cupsFileClose(reqfile);
        }
       }
 
-      for (i = 0; i < num_statuses; i ++)
-      {
-        if (statuses[i].if_defined &&
-           !get_variable(vars, statuses[i].if_defined))
-         continue;
-
-        if (statuses[i].if_undefined &&
-           get_variable(vars, statuses[i].if_undefined))
-         continue;
+     /*
+      * Send the request...
+      */
 
-        if (response->request.status.status_code == statuses[i].status)
-         break;
-      }
+      response    = NULL;
+      repeat_test = 0;
+      prev_pass   = 1;
 
-      if (i == num_statuses && num_statuses > 0)
-       pass = 0;
-      else
+      if (status != HTTP_ERROR)
       {
-        for (i = num_expects, expect = expects; i > 0; i --, expect ++)
-        {
-          if (expect->if_defined && !get_variable(vars, expect->if_defined))
-            continue;
-
-          if (expect->if_undefined && get_variable(vars, expect->if_undefined))
-            continue;
+       while (!response && !Cancel && prev_pass)
+       {
+         status = cupsSendRequest(http, request, resource, length);
 
-          found = ippFindAttribute(response, expect->name, IPP_TAG_ZERO);
+#ifdef HAVE_LIBZ
+         if (compression[0])
+           httpSetField(http, HTTP_FIELD_CONTENT_ENCODING, compression);
+#endif /* HAVE_LIBZ */
 
-          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))
-          {
-           pass = 0;
-           break;
-          }
+         if (!Cancel && status == HTTP_CONTINUE &&
+             request->state == IPP_DATA && filename[0])
+         {
+           if ((reqfile = cupsFileOpen(filename, "r")) != NULL)
+           {
+             while (!Cancel &&
+                    (bytes = cupsFileRead(reqfile, buffer, sizeof(buffer))) > 0)
+               if ((status = cupsWriteRequestData(http, buffer, (size_t)bytes)) != HTTP_CONTINUE)
+                 break;
 
-          if (found &&
-             !with_value(expect->with_value, expect->with_regex, found))
-          {
-            pass = 0;
-            break;
-          }
+             cupsFileClose(reqfile);
+           }
+           else
+           {
+             snprintf(buffer, sizeof(buffer), "%s: %s", filename,
+                      strerror(errno));
+             _cupsSetError(IPP_INTERNAL_ERROR, buffer, 0);
 
-          if (found && expect->count > 0 && found->num_values != expect->count)
-         {
-            pass = 0;
-            break;
+             status = HTTP_ERROR;
+           }
          }
 
-          if (found && expect->same_count_as)
-          {
-            attrptr = ippFindAttribute(response, expect->same_count_as,
-                                       IPP_TAG_ZERO);
+        /*
+         * Get the server's response...
+         */
 
-            if (!attrptr || attrptr->num_values != found->num_values)
-            {
-              pass = 0;
-              break;
-            }
-          }
-        }
-      }
-    }
+         if (!Cancel && status != HTTP_ERROR)
+         {
+           response = cupsGetResponse(http, resource);
+           status   = httpGetStatus(http);
+         }
 
-    if (Output == _CUPS_OUTPUT_PLIST)
-    {
-      puts("<key>Successful</key>");
-      puts(pass ? "<true />" : "<false />");
-      puts("<key>StatusCode</key>");
-      print_xml_string("string", ippErrorString(cupsLastError()));
-      puts("<key>ResponseAttributes</key>");
-      puts("<dict>");
-      for (attrptr = response ? response->attrs : NULL;
-          attrptr;
-          attrptr = attrptr->next)
-       print_attr(attrptr);
-      puts("</dict>");
-    }
-    else if (Output == _CUPS_OUTPUT_TEST)
-    {
-      puts(pass ? "PASS]" : "FAIL]");
+         if (!Cancel && status == HTTP_ERROR && http->error != EINVAL &&
+#ifdef WIN32
+             http->error != WSAETIMEDOUT)
+#else
+             http->error != ETIMEDOUT)
+#endif /* WIN32 */
+         {
+           if (httpReconnect(http))
+             prev_pass = 0;
+         }
+         else if (status == HTTP_ERROR)
+         {
+           prev_pass = 0;
+           break;
+         }
+         else if (status != HTTP_OK)
+         {
+           httpFlush(http);
 
-      if (Verbosity && response)
-      {
-       printf("        RECEIVED: %lu bytes in response\n",
-              (unsigned long)ippLength(response));
-       printf("        status-code = %x (%s)\n", cupsLastError(),
-              ippErrorString(cupsLastError()));
+           if (status == HTTP_STATUS_UNAUTHORIZED)
+             continue;
 
-       for (attrptr = response->attrs;
-            attrptr != NULL;
-            attrptr = attrptr->next)
-       {
-         print_attr(attrptr);
+           break;
+         }
        }
       }
-    }
-    else if (!pass)
-      fprintf(stderr, "%s\n", cupsLastErrorString());
 
-    if (pass && Output != _CUPS_OUTPUT_PLIST && Output != _CUPS_OUTPUT_QUIET &&
-        !Verbosity && num_displayed > 0)
-    {
-      if (Output >= _CUPS_OUTPUT_LIST)
+      if (!Cancel && status == HTTP_ERROR && http->error != EINVAL &&
+#ifdef WIN32
+         http->error != WSAETIMEDOUT)
+#else
+         http->error != ETIMEDOUT)
+#endif /* WIN32 */
       {
-       size_t  width;                  /* Length of value */
-
-
-        for (i = 0; i < num_displayed; i ++)
-        {
-          widths[i] = strlen(displayed[i]);
+       if (httpReconnect(http))
+         prev_pass = 0;
+      }
+      else if (status == HTTP_ERROR)
+      {
+        if (!Cancel)
+          httpReconnect(http);
 
-          for (attrptr = ippFindAttribute(response, displayed[i], IPP_TAG_ZERO);
-               attrptr;
-               attrptr = ippFindNextAttribute(response, displayed[i],
-                                              IPP_TAG_ZERO))
-          {
-            width = _ippAttrString(attrptr, NULL, 0);
-            if (width > widths[i])
-              widths[i] = width;
-          }
-        }
+       prev_pass = 0;
+      }
+      else if (status != HTTP_OK)
+      {
+        httpFlush(http);
+        prev_pass = 0;
+      }
 
-        if (Output == _CUPS_OUTPUT_CSV)
-         print_csv(NULL, num_displayed, displayed, widths);
-       else
-         print_line(NULL, num_displayed, displayed, widths);
+     /*
+      * Check results of request...
+      */
 
-        attrptr = response->attrs;
+      cupsArrayClear(errors);
 
-        while (attrptr)
-        {
-         while (attrptr && attrptr->group_tag <= IPP_TAG_OPERATION)
-           attrptr = attrptr->next;
+      if (http->version != HTTP_1_1)
+       add_stringf(errors, "Bad HTTP version (%d.%d)", http->version / 100,
+                   http->version % 100);
 
-          if (attrptr)
-          {
-            if (Output == _CUPS_OUTPUT_CSV)
-             print_csv(attrptr, num_displayed, displayed, widths);
-           else
-             print_line(attrptr, num_displayed, displayed, widths);
+      if (!response)
+      {
+       /*
+        * No response, log error...
+        */
 
-            while (attrptr && attrptr->group_tag > IPP_TAG_OPERATION)
-              attrptr = attrptr->next;
-          }
-        }
+       add_stringf(errors, "IPP request failed with status %s (%s)",
+                   ippErrorString(cupsLastError()),
+                   cupsLastErrorString());
       }
       else
       {
-       for (attrptr = response->attrs;
-            attrptr != NULL;
-            attrptr = attrptr->next)
+       /*
+        * Collect common attribute values...
+        */
+
+       if ((attrptr = ippFindAttribute(response, "job-id",
+                                       IPP_TAG_INTEGER)) != NULL)
        {
-         if (attrptr->name)
-         {
-           for (i = 0; i < num_displayed; i ++)
-           {
-             if (!strcmp(displayed[i], attrptr->name))
-             {
-               print_attr(attrptr);
-               break;
-             }
-           }
-         }
+         snprintf(temp, sizeof(temp), "%d", attrptr->values[0].integer);
+         set_variable(vars, "job-id", temp);
        }
-      }
-    }
-    else if (!pass)
-    {
-      if (Output == _CUPS_OUTPUT_PLIST)
-      {
-       puts("<key>Errors</key>");
-       puts("<array>");
-      }
 
-      if (http->version != HTTP_1_1)
-       print_test_error("Bad HTTP version (%d.%d)", http->version / 100,
-                        http->version % 100);
+       if ((attrptr = ippFindAttribute(response, "job-uri",
+                                       IPP_TAG_URI)) != NULL)
+         set_variable(vars, "job-uri", attrptr->values[0].string.text);
 
-      if (!response)
-       print_test_error("IPP request failed with status %s (%s)",
-                        ippErrorString(cupsLastError()),
-                        cupsLastErrorString());
-      else
-      {
-       if (response->request.status.version[0] != (version / 10) ||
-           response->request.status.version[1] != (version % 10))
-          print_test_error("Bad version %d.%d in response - expected %d.%d "
-                          "(RFC 2911 section 3.1.8).",
-                          response->request.status.version[0],
-                          response->request.status.version[1],
-                          version / 10, version % 10);
+       if ((attrptr = ippFindAttribute(response, "notify-subscription-id",
+                                       IPP_TAG_INTEGER)) != NULL)
+       {
+         snprintf(temp, sizeof(temp), "%d", attrptr->values[0].integer);
+         set_variable(vars, "notify-subscription-id", temp);
+       }
+
+       /*
+        * Check response, validating groups and attributes and logging errors
+        * as needed...
+        */
+
+       if (response->state != IPP_DATA)
+         add_stringf(errors,
+                     "Missing end-of-attributes-tag in response "
+                     "(RFC 2910 section 3.5.1)");
+
+       if (version &&
+           (response->request.status.version[0] != (version / 10) ||
+            response->request.status.version[1] != (version % 10)))
+          add_stringf(errors,
+                      "Bad version %d.%d in response - expected %d.%d "
+                     "(RFC 2911 section 3.1.8).",
+                     response->request.status.version[0],
+                     response->request.status.version[1],
+                     version / 10, version % 10);
 
        if (response->request.status.request_id != request_id)
-         print_test_error("Bad request ID %d in response - expected %d "
-                          "(RFC 2911 section 3.1.1)",
-                          response->request.status.request_id, request_id);
+         add_stringf(errors,
+                     "Bad request ID %d in response - expected %d "
+                     "(RFC 2911 section 3.1.1)",
+                     response->request.status.request_id, request_id);
 
        attrptr = response->attrs;
        if (!attrptr)
-         print_test_error("Missing first attribute \"attributes-charset "
-                          "(charset)\" in group operation-attributes-tag "
-                          "(RFC 2911 section 3.1.4).");
+         add_stringf(errors,
+                     "Missing first attribute \"attributes-charset "
+                     "(charset)\" in group operation-attributes-tag "
+                     "(RFC 2911 section 3.1.4).");
        else
        {
          if (!attrptr->name ||
@@ -1816,112 +2628,222 @@ do_tests(_cups_vars_t *vars,          /* I - Variables */
              attrptr->group_tag != IPP_TAG_OPERATION ||
              attrptr->num_values != 1 ||
              strcmp(attrptr->name, "attributes-charset"))
-           print_test_error("Bad first attribute \"%s (%s%s)\" in group %s, "
-                            "expected \"attributes-charset (charset)\" in "
-                            "group operation-attributes-tag (RFC 2911 section "
-                            "3.1.4).",
-                            attrptr->name ? attrptr->name : "(null)",
-                            attrptr->num_values > 1 ? "1setOf " : "",
-                            ippTagString(attrptr->value_tag),
-                            ippTagString(attrptr->group_tag));
+           add_stringf(errors,
+                       "Bad first attribute \"%s (%s%s)\" in group %s, "
+                       "expected \"attributes-charset (charset)\" in "
+                       "group operation-attributes-tag (RFC 2911 section "
+                       "3.1.4).",
+                       attrptr->name ? attrptr->name : "(null)",
+                       attrptr->num_values > 1 ? "1setOf " : "",
+                       ippTagString(attrptr->value_tag),
+                       ippTagString(attrptr->group_tag));
 
          attrptr = attrptr->next;
          if (!attrptr)
-           print_test_error("Missing second attribute \"attributes-natural-"
-                            "language (naturalLanguage)\" in group "
-                            "operation-attributes-tag (RFC 2911 section "
-                            "3.1.4).");
+           add_stringf(errors,
+                       "Missing second attribute \"attributes-natural-"
+                       "language (naturalLanguage)\" in group "
+                       "operation-attributes-tag (RFC 2911 section "
+                       "3.1.4).");
          else if (!attrptr->name ||
                   attrptr->value_tag != IPP_TAG_LANGUAGE ||
                   attrptr->group_tag != IPP_TAG_OPERATION ||
                   attrptr->num_values != 1 ||
                   strcmp(attrptr->name, "attributes-natural-language"))
-           print_test_error("Bad first attribute \"%s (%s%s)\" in group %s, "
-                            "expected \"attributes-natural-language "
-                            "(naturalLanguage)\" in group "
-                            "operation-attributes-tag (RFC 2911 section "
-                            "3.1.4).",
-                            attrptr->name ? attrptr->name : "(null)",
-                            attrptr->num_values > 1 ? "1setOf " : "",
-                            ippTagString(attrptr->value_tag),
-                            ippTagString(attrptr->group_tag));
+           add_stringf(errors,
+                       "Bad first attribute \"%s (%s%s)\" in group %s, "
+                       "expected \"attributes-natural-language "
+                       "(naturalLanguage)\" in group "
+                       "operation-attributes-tag (RFC 2911 section "
+                       "3.1.4).",
+                       attrptr->name ? attrptr->name : "(null)",
+                       attrptr->num_values > 1 ? "1setOf " : "",
+                       ippTagString(attrptr->value_tag),
+                       ippTagString(attrptr->group_tag));
         }
 
        if ((attrptr = ippFindAttribute(response, "status-message",
                                         IPP_TAG_ZERO)) != NULL)
        {
          if (attrptr->value_tag != IPP_TAG_TEXT)
-           print_test_error("status-message (text(255)) has wrong value tag "
-                            "%s (RFC 2911 section 3.1.6.2).",
-                            ippTagString(attrptr->value_tag));
+           add_stringf(errors,
+                       "status-message (text(255)) has wrong value tag "
+                       "%s (RFC 2911 section 3.1.6.2).",
+                       ippTagString(attrptr->value_tag));
          if (attrptr->group_tag != IPP_TAG_OPERATION)
-           print_test_error("status-message (text(255)) has wrong group tag "
-                            "%s (RFC 2911 section 3.1.6.2).",
-                            ippTagString(attrptr->group_tag));
+           add_stringf(errors,
+                       "status-message (text(255)) has wrong group tag "
+                       "%s (RFC 2911 section 3.1.6.2).",
+                       ippTagString(attrptr->group_tag));
          if (attrptr->num_values != 1)
-           print_test_error("status-message (text(255)) has %d values "
-                            "(RFC 2911 section 3.1.6.2).",
-                            attrptr->num_values);
+           add_stringf(errors,
+                       "status-message (text(255)) has %d values "
+                       "(RFC 2911 section 3.1.6.2).",
+                       attrptr->num_values);
          if (attrptr->value_tag == IPP_TAG_TEXT &&
              strlen(attrptr->values[0].string.text) > 255)
-           print_test_error("status-message (text(255)) has bad length %d"
-                            " (RFC 2911 section 3.1.6.2).",
-                            (int)strlen(attrptr->values[0].string.text));
+           add_stringf(errors,
+                       "status-message (text(255)) has bad length %d"
+                       " (RFC 2911 section 3.1.6.2).",
+                       (int)strlen(attrptr->values[0].string.text));
         }
 
        if ((attrptr = ippFindAttribute(response, "detailed-status-message",
                                         IPP_TAG_ZERO)) != NULL)
        {
          if (attrptr->value_tag != IPP_TAG_TEXT)
-           print_test_error("detailed-status-message (text(MAX)) has wrong "
-                            "value tag %s (RFC 2911 section 3.1.6.3).",
-                            ippTagString(attrptr->value_tag));
+           add_stringf(errors,
+                       "detailed-status-message (text(MAX)) has wrong "
+                       "value tag %s (RFC 2911 section 3.1.6.3).",
+                       ippTagString(attrptr->value_tag));
          if (attrptr->group_tag != IPP_TAG_OPERATION)
-           print_test_error("detailed-status-message (text(MAX)) has wrong "
-                            "group tag %s (RFC 2911 section 3.1.6.3).",
-                            ippTagString(attrptr->group_tag));
+           add_stringf(errors,
+                       "detailed-status-message (text(MAX)) has wrong "
+                       "group tag %s (RFC 2911 section 3.1.6.3).",
+                       ippTagString(attrptr->group_tag));
          if (attrptr->num_values != 1)
-           print_test_error("detailed-status-message (text(MAX)) has %d values"
-                            " (RFC 2911 section 3.1.6.3).",
-                            attrptr->num_values);
+           add_stringf(errors,
+                       "detailed-status-message (text(MAX)) has %d values"
+                       " (RFC 2911 section 3.1.6.3).",
+                       attrptr->num_values);
          if (attrptr->value_tag == IPP_TAG_TEXT &&
              strlen(attrptr->values[0].string.text) > 1023)
-           print_test_error("detailed-status-message (text(MAX)) has bad "
-                            "length %d (RFC 2911 section 3.1.6.3).",
-                            (int)strlen(attrptr->values[0].string.text));
+           add_stringf(errors,
+                       "detailed-status-message (text(MAX)) has bad "
+                       "length %d (RFC 2911 section 3.1.6.3).",
+                       (int)strlen(attrptr->values[0].string.text));
         }
 
-       for (attrptr = response->attrs, group = attrptr->group_tag;
+       a = cupsArrayNew((cups_array_func_t)strcmp, NULL);
+
+       for (attrptr = response->attrs,
+                group = attrptr ? attrptr->group_tag : IPP_TAG_ZERO;
             attrptr;
             attrptr = attrptr->next)
        {
-         if (attrptr->group_tag < group && attrptr->group_tag != IPP_TAG_ZERO)
-           print_test_error("Attribute groups out of order (%s < %s)",
-                            ippTagString(attrptr->group_tag),
-                            ippTagString(group));
+         if (attrptr->group_tag != group)
+         {
+           int out_of_order = 0;       /* Are attribute groups out-of-order? */
+           cupsArrayClear(a);
+
+            switch (attrptr->group_tag)
+            {
+              case IPP_TAG_ZERO :
+                  break;
+
+              case IPP_TAG_OPERATION :
+                  out_of_order = 1;
+                  break;
+
+              case IPP_TAG_UNSUPPORTED_GROUP :
+                  if (group != IPP_TAG_OPERATION)
+                   out_of_order = 1;
+                  break;
+
+              case IPP_TAG_JOB :
+              case IPP_TAG_PRINTER :
+                  if (group != IPP_TAG_OPERATION &&
+                      group != IPP_TAG_UNSUPPORTED_GROUP)
+                   out_of_order = 1;
+                  break;
+
+              case IPP_TAG_SUBSCRIPTION :
+                  if (group > attrptr->group_tag &&
+                      group != IPP_TAG_DOCUMENT)
+                   out_of_order = 1;
+                  break;
+
+              default :
+                  if (group > attrptr->group_tag)
+                   out_of_order = 1;
+                  break;
+            }
+
+            if (out_of_order)
+             add_stringf(errors, "Attribute groups out of order (%s < %s)",
+                         ippTagString(attrptr->group_tag),
+                         ippTagString(group));
+
+           if (attrptr->group_tag != IPP_TAG_ZERO)
+             group = attrptr->group_tag;
+         }
+
+         validate_attr(errors, attrptr);
 
-         validate_attr(attrptr, 1);
+          if (attrptr->name)
+          {
+            if (cupsArrayFind(a, attrptr->name))
+              add_stringf(errors, "Duplicate \"%s\" attribute in %s group",
+                         attrptr->name, ippTagString(group));
+
+            cupsArrayAdd(a, attrptr->name);
+          }
        }
 
+        cupsArrayDelete(a);
+
+       /*
+        * Now check the test-defined expected status-code and attribute
+        * values...
+        */
+
        for (i = 0; i < num_statuses; i ++)
        {
          if (statuses[i].if_defined &&
              !get_variable(vars, statuses[i].if_defined))
            continue;
 
-         if (statuses[i].if_undefined &&
-             get_variable(vars, statuses[i].if_undefined))
+         if (statuses[i].if_not_defined &&
+             get_variable(vars, statuses[i].if_not_defined))
            continue;
 
          if (response->request.status.status_code == statuses[i].status)
-           break;
-        }
+         {
+           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)
        {
-         print_test_error("Bad status-code (%s)",
-                          ippErrorString(cupsLastError()));
-         print_test_error("status-message=\"%s\"", cupsLastErrorString());
+         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 ++)
@@ -1929,68 +2851,316 @@ do_tests(_cups_vars_t *vars,           /* I - Variables */
          if (expect->if_defined && !get_variable(vars, expect->if_defined))
            continue;
 
-         if (expect->if_undefined && get_variable(vars, expect->if_undefined))
+         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)
-            print_test_error("NOT EXPECTED: %s", expect->name);
-         else if (!found && !(expect->not_expect || expect->optional))
-           print_test_error("EXPECTED: %s", expect->name);
-         else if (found)
+         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_matches(expect, found->value_tag))
-             print_test_error("EXPECTED: %s OF-TYPE %s (got %s)",
-                              expect->name, expect->of_type,
-                              ippTagString(found->value_tag));
+           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 (expect->in_group && found->group_tag != expect->in_group)
-             print_test_error("EXPECTED: %s IN-GROUP %s (got %s).",
-                              expect->name, ippTagString(expect->in_group),
-                              ippTagString(found->group_tag));
+         if (found)
+           ippAttributeString(found, buffer, sizeof(buffer));
 
-           if (!with_value(expect->with_value, expect->with_regex, found))
+         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_regex)
-               print_test_error("EXPECTED: %s WITH-VALUE /%s/",
-                                expect->name, expect->with_value);
+             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
-               print_test_error("EXPECTED: %s WITH-VALUE \"%s\"",
-                                expect->name, expect->with_value);
+               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->count > 0 && found->num_values != expect->count)
+           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)
            {
-             print_test_error("EXPECTED: %s COUNT %d (got %d)", expect->name,
-                              expect->count, found->num_values);
+             add_stringf(errors, "EXPECTED: %s COUNT %d (got %d)", expect->name,
+                         expect->count, found->num_values);
            }
 
-           if (expect->same_count_as)
+           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)
            {
-             attrptr = ippFindAttribute(response, expect->same_count_as,
-                                        IPP_TAG_ZERO);
-
-             if (!attrptr)
-               print_test_error("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)
-               print_test_error("EXPECTED: %s (%d values) SAME-COUNT-AS %s "
-                                "(%d values)", expect->name, found->num_values,
-                                expect->same_count_as, attrptr->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 */
+
+      for (i = 0; i < num_displayed; i ++)
+      {
+       widths[i] = strlen(displayed[i]);
+
+       for (attrptr = ippFindAttribute(response, displayed[i], IPP_TAG_ZERO);
+            attrptr;
+            attrptr = ippFindNextAttribute(response, displayed[i],
+                                           IPP_TAG_ZERO))
+       {
+         width = ippAttributeString(attrptr, NULL, 0);
+         if (width > widths[i])
+           widths[i] = width;
        }
       }
 
+      if (Output == _CUPS_OUTPUT_CSV)
+       print_csv(NULL, num_displayed, displayed, widths);
+      else
+       print_line(NULL, num_displayed, displayed, widths);
+
+      attrptr = response->attrs;
+
+      while (attrptr)
+      {
+       while (attrptr && attrptr->group_tag <= IPP_TAG_OPERATION)
+         attrptr = attrptr->next;
+
+       if (attrptr)
+       {
+         if (Output == _CUPS_OUTPUT_CSV)
+           print_csv(attrptr, num_displayed, displayed, widths);
+         else
+           print_line(attrptr, num_displayed, displayed, widths);
+
+         while (attrptr && attrptr->group_tag > IPP_TAG_OPERATION)
+           attrptr = attrptr->next;
+       }
+      }
+    }
+    else if (!prev_pass)
+    {
       if (Output == _CUPS_OUTPUT_PLIST)
+      {
+       puts("<key>Errors</key>");
+       puts("<array>");
+
+       for (error = (char *)cupsArrayFirst(errors);
+            error;
+            error = (char *)cupsArrayNext(errors))
+         print_xml_string("string", error);
+
        puts("</array>");
+      }
+      else
+      {
+       for (error = (char *)cupsArrayFirst(errors);
+            error;
+            error = (char *)cupsArrayNext(errors))
+         printf("        %s\n", error);
+      }
+    }
+
+    if (num_displayed > 0 && !Verbosity && response &&
+        Output == _CUPS_OUTPUT_TEST)
+    {
+      for (attrptr = response->attrs;
+          attrptr != NULL;
+          attrptr = attrptr->next)
+      {
+       if (attrptr->name)
+       {
+         for (i = 0; i < num_displayed; i ++)
+         {
+           if (!strcmp(displayed[i], attrptr->name))
+           {
+             print_attr(attrptr, NULL);
+             break;
+           }
+         }
+       }
+      }
     }
 
+    skip_error:
+
     if (Output == _CUPS_OUTPUT_PLIST)
       puts("</dict>");
 
+    fflush(stdout);
+
     ippDelete(response);
     response = NULL;
 
@@ -1998,8 +3168,12 @@ do_tests(_cups_vars_t *vars,             /* I - Variables */
     {
       if (statuses[i].if_defined)
         free(statuses[i].if_defined);
-      if (statuses[i].if_undefined)
-        free(statuses[i].if_undefined);
+      if (statuses[i].if_not_defined)
+        free(statuses[i].if_not_defined);
+      if (statuses[i].define_match)
+        free(statuses[i].define_match);
+      if (statuses[i].define_no_match)
+        free(statuses[i].define_no_match);
     }
     num_statuses = 0;
 
@@ -2012,10 +3186,16 @@ do_tests(_cups_vars_t *vars,            /* I - Variables */
         free(expect->same_count_as);
       if (expect->if_defined)
         free(expect->if_defined);
-      if (expect->if_undefined)
-        free(expect->if_undefined);
+      if (expect->if_not_defined)
+        free(expect->if_not_defined);
       if (expect->with_value)
         free(expect->with_value);
+      if (expect->define_match)
+        free(expect->define_match);
+      if (expect->define_no_match)
+        free(expect->define_no_match);
+      if (expect->define_value)
+        free(expect->define_value);
     }
     num_expects = 0;
 
@@ -2023,20 +3203,13 @@ do_tests(_cups_vars_t *vars,            /* I - Variables */
       free(displayed[i]);
     num_displayed = 0;
 
-    if (!pass)
+    if (!ignore_errors && !prev_pass)
       break;
   }
 
-  fclose(fp);
-  httpClose(http);
-
-  return (pass);
-
- /*
-  * If we get here there was a fatal test error...
-  */
+  test_exit:
 
-  test_error:
+  cupsArrayDelete(errors);
 
   if (fp)
     fclose(fp);
@@ -2049,8 +3222,12 @@ do_tests(_cups_vars_t *vars,             /* I - Variables */
   {
     if (statuses[i].if_defined)
       free(statuses[i].if_defined);
-    if (statuses[i].if_undefined)
-      free(statuses[i].if_undefined);
+    if (statuses[i].if_not_defined)
+      free(statuses[i].if_not_defined);
+      if (statuses[i].define_match)
+        free(statuses[i].define_match);
+      if (statuses[i].define_no_match)
+        free(statuses[i].define_no_match);
   }
 
   for (i = num_expects, expect = expects; i > 0; i --, expect ++)
@@ -2062,16 +3239,22 @@ do_tests(_cups_vars_t *vars,            /* I - Variables */
       free(expect->same_count_as);
     if (expect->if_defined)
       free(expect->if_defined);
-    if (expect->if_undefined)
-      free(expect->if_undefined);
+    if (expect->if_not_defined)
+      free(expect->if_not_defined);
     if (expect->with_value)
       free(expect->with_value);
+    if (expect->define_match)
+      free(expect->define_match);
+    if (expect->define_no_match)
+      free(expect->define_no_match);
+    if (expect->define_value)
+      free(expect->define_value);
   }
 
   for (i = 0; i < num_displayed; i ++)
     free(displayed[i]);
 
-  return (0);
+  return (pass);
 }
 
 
@@ -2165,7 +3348,7 @@ expand_variables(_cups_vars_t *vars,      /* I - Variables */
 
       if (value)
       {
-        strlcpy(dstptr, value, dstend - dstptr + 1);
+        strlcpy(dstptr, value, (size_t)(dstend - dstptr + 1));
        dstptr += strlen(dstptr);
       }
     }
@@ -2270,44 +3453,12 @@ get_collection(_cups_vars_t *vars,      /* I  - Variables */
       ipp_t    *subcol = get_collection(vars, fp, linenum);
                                        /* Collection value */
 
-      if (subcol)
-      {
-       ipp_attribute_t *tempcol;       /* Pointer to new buffer */
-
-
-       /*
-       * Reallocate memory...
-       */
-
-       if ((tempcol = realloc(lastcol, sizeof(ipp_attribute_t) +
-                                       (lastcol->num_values + 1) *
-                                       sizeof(ipp_value_t))) == NULL)
-       {
-         print_fatal_error("Unable to allocate memory on line %d.", *linenum);
-         goto col_error;
-       }
-
-       if (tempcol != lastcol)
-       {
-        /*
-         * Reset pointers in the list...
-         */
-
-         if (col->prev)
-           col->prev->next = tempcol;
-         else
-           col->attrs = tempcol;
-
-         lastcol = col->current = col->last = tempcol;
-       }
-
-       lastcol->values[lastcol->num_values].collection = subcol;
-       lastcol->num_values ++;
-      }
+      if (subcol)
+        ippSetCollection(col, &lastcol, ippGetCount(lastcol), subcol);
       else
        goto col_error;
     }
-    else if (!strcasecmp(token, "MEMBER"))
+    else if (!_cups_strcasecmp(token, "MEMBER"))
     {
      /*
       * Attribute...
@@ -2321,7 +3472,7 @@ get_collection(_cups_vars_t *vars,        /* I  - Variables */
        goto col_error;
       }
 
-      if ((value = ippTagValue(token)) < 0)
+      if ((value = ippTagValue(token)) == IPP_TAG_ZERO)
       {
        print_fatal_error("Bad MEMBER value tag \"%s\" on line %d.", token,
                          *linenum);
@@ -2345,10 +3496,10 @@ get_collection(_cups_vars_t *vars,      /* I  - Variables */
       switch (value)
       {
        case IPP_TAG_BOOLEAN :
-           if (!strcasecmp(token, "true"))
+           if (!_cups_strcasecmp(token, "true"))
              ippAddBoolean(col, IPP_TAG_ZERO, attr, 1);
            else
-             ippAddBoolean(col, IPP_TAG_ZERO, attr, atoi(token));
+             ippAddBoolean(col, IPP_TAG_ZERO, attr, (char)atoi(token));
            break;
 
        case IPP_TAG_INTEGER :
@@ -2363,23 +3514,23 @@ get_collection(_cups_vars_t *vars,      /* I  - Variables */
              char      units[6];       /* Units */
 
              if (sscanf(token, "%dx%d%5s", &xres, &yres, units) != 3 ||
-                 (strcasecmp(units, "dpi") && strcasecmp(units, "dpc") &&
-                  strcasecmp(units, "other")))
+                 (_cups_strcasecmp(units, "dpi") &&
+                  _cups_strcasecmp(units, "dpc") &&
+                  _cups_strcasecmp(units, "dpcm") &&
+                  _cups_strcasecmp(units, "other")))
              {
                print_fatal_error("Bad resolution value \"%s\" on line %d.",
                                  token, *linenum);
                goto col_error;
              }
 
-             if (!strcasecmp(units, "dpi"))
-               ippAddResolution(col, IPP_TAG_ZERO, attr, xres, yres,
-                                IPP_RES_PER_INCH);
-             else if (!strcasecmp(units, "dpc"))
-               ippAddResolution(col, IPP_TAG_ZERO, attr, xres, yres,
-                                IPP_RES_PER_CM);
+             if (!_cups_strcasecmp(units, "dpi"))
+               ippAddResolution(col, IPP_TAG_ZERO, attr, IPP_RES_PER_INCH, xres, yres);
+             else if (!_cups_strcasecmp(units, "dpc") ||
+                      !_cups_strcasecmp(units, "dpcm"))
+               ippAddResolution(col, IPP_TAG_ZERO, attr, IPP_RES_PER_CM, xres, yres);
              else
-               ippAddResolution(col, IPP_TAG_ZERO, attr, xres, yres,
-                                (ipp_res_t)0);
+               ippAddResolution(col, IPP_TAG_ZERO, attr, (ipp_res_t)0, xres, yres);
            }
            break;
 
@@ -2428,6 +3579,9 @@ get_collection(_cups_vars_t *vars,        /* I  - Variables */
              goto col_error;
            }
            break;
+       case IPP_TAG_STRING :
+           ippAddOctetString(col, IPP_TAG_ZERO, attr, token, (int)strlen(token));
+           break;
 
        default :
            if (!strchr(token, ','))
@@ -2501,7 +3655,11 @@ get_filename(const char *testfile,       /* I - Current test file */
     if (*dstptr == '>')
       *dstptr = '\0';
   }
-  else if (*src == '/' || !strchr(testfile, '/'))
+  else if (*src == '/' || !strchr(testfile, '/')
+#ifdef WIN32
+           || (isalpha(*src & 255) && src[1] == ':')
+#endif /* WIN32 */
+           )
   {
    /*
     * Use the path as-is...
@@ -2521,13 +3679,60 @@ get_filename(const char *testfile,      /* I - Current test file */
     else
       dstptr = dst; /* Should never happen */
 
-    strlcpy(dstptr, src, dstsize - (dstptr - dst));
+    strlcpy(dstptr, src, dstsize - (size_t)(dstptr - dst));
   }
 
   return (dst);
 }
 
 
+/*
+ * 'get_string()' - Get a pointer to a string value or the portion of interest.
+ */
+
+static char *                          /* O - Pointer to string */
+get_string(ipp_attribute_t *attr,      /* I - IPP attribute */
+           int             element,    /* I - Element to fetch */
+           int             flags,      /* I - Value ("with") flags */
+           char            *buffer,    /* I - Temporary buffer */
+          size_t          bufsize)     /* I - Size of temporary buffer */
+{
+  char *ptr,                           /* Value */
+       scheme[256],                    /* URI scheme */
+       userpass[256],                  /* Username/password */
+       hostname[256],                  /* Hostname */
+       resource[1024];                 /* Resource */
+  int  port;                           /* Port number */
+
+
+  ptr = attr->values[element].string.text;
+
+  if (flags & _CUPS_WITH_HOSTNAME)
+  {
+    if (httpSeparateURI(HTTP_URI_CODING_ALL, ptr, scheme, sizeof(scheme), userpass, sizeof(userpass), buffer, (int)bufsize, &port, resource, sizeof(resource)) < HTTP_URI_STATUS_OK)
+      buffer[0] = '\0';
+
+    return (buffer);
+  }
+  else if (flags & _CUPS_WITH_RESOURCE)
+  {
+    if (httpSeparateURI(HTTP_URI_CODING_ALL, ptr, scheme, sizeof(scheme), userpass, sizeof(userpass), hostname, sizeof(hostname), &port, buffer, (int)bufsize) < HTTP_URI_STATUS_OK)
+      buffer[0] = '\0';
+
+    return (buffer);
+  }
+  else if (flags & _CUPS_WITH_SCHEME)
+  {
+    if (httpSeparateURI(HTTP_URI_CODING_ALL, ptr, buffer, (int)bufsize, userpass, sizeof(userpass), hostname, sizeof(hostname), &port, resource, sizeof(resource)) < HTTP_URI_STATUS_OK)
+      buffer[0] = '\0';
+
+    return (buffer);
+  }
+  else
+    return (ptr);
+}
+
+
 /*
  * 'get_token()' - Get a token from a file.
  */
@@ -2581,15 +3786,15 @@ get_token(FILE *fp,                     /* I  - File to read from */
          */
 
          if (bufptr < bufend)
-           *bufptr++ = ch;
+           *bufptr++ = (char)ch;
 
          if ((ch = getc(fp)) != EOF && bufptr < bufend)
-           *bufptr++ = ch;
+           *bufptr++ = (char)ch;
        }
        else if (ch == quote)
           break;
        else if (bufptr < bufend)
-          *bufptr++ = ch;
+          *bufptr++ = (char)ch;
       }
 
       *bufptr = '\0';
@@ -2623,7 +3828,7 @@ get_token(FILE *fp,                       /* I  - File to read from */
        if (isspace(ch) || ch == '#')
           break;
        else if (bufptr < bufend)
-          *bufptr++ = ch;
+          *bufptr++ = (char)ch;
 
       if (ch == '#')
         ungetc(ch, fp);
@@ -2665,29 +3870,42 @@ get_variable(_cups_vars_t *vars,        /* I - Variables */
 static char *                          /* O - ISO 8601 date/time string */
 iso_date(ipp_uchar_t *date)            /* I - IPP (RFC 1903) date/time value */
 {
-  unsigned     year = (date[0] << 8) + date[1];
-                                       /* Year */
+  time_t       utctime;                /* UTC time since 1970 */
+  struct tm    *utcdate;               /* UTC date/time */
   static char  buffer[255];            /* String buffer */
 
 
-  if (date[9] == 0 && date[10] == 0)
-    snprintf(buffer, sizeof(buffer), "%04u-%02u-%02uT%02u:%02u:%02uZ",
-            year, date[2], date[3], date[4], date[5], date[6]);
-  else
-    snprintf(buffer, sizeof(buffer), "%04u-%02u-%02uT%02u:%02u:%02u%c%02u%02u",
-            year, date[2], date[3], date[4], date[5], date[6],
-            date[8], date[9], date[10]);
+  utctime = ippDateToTime(date);
+  utcdate = gmtime(&utctime);
+
+  snprintf(buffer, sizeof(buffer), "%04d-%02d-%02dT%02d:%02d:%02dZ",
+          utcdate->tm_year + 1900, utcdate->tm_mon + 1, utcdate->tm_mday,
+          utcdate->tm_hour, utcdate->tm_min, utcdate->tm_sec);
 
   return (buffer);
 }
 
 
+/*
+ * 'password_cb()' - Password callback for authenticated tests.
+ */
+
+static const char *                    /* O - Password */
+password_cb(const char *prompt)                /* I - Prompt (unused) */
+{
+  (void)prompt;
+
+  return (Password);
+}
+
+
 /*
  * 'print_attr()' - Print an attribute on the screen.
  */
 
 static void
-print_attr(ipp_attribute_t *attr)      /* I - Attribute to print */
+print_attr(ipp_attribute_t *attr,      /* I  - Attribute to print */
+           ipp_tag_t       *group)     /* IO - Current group */
 {
   int                  i;              /* Looping var */
   ipp_attribute_t      *colattr;       /* Collection attribute */
@@ -2695,155 +3913,202 @@ print_attr(ipp_attribute_t *attr)     /* I - Attribute to print */
 
   if (Output == _CUPS_OUTPUT_PLIST)
   {
-    if (!attr->name)
+    if (!attr->name || (group && *group != attr->group_tag))
     {
-      printf("<key>%s</key>\n<true />\n", ippTagString(attr->group_tag));
-      return;
+      if (attr->group_tag != IPP_TAG_ZERO)
+      {
+       puts("</dict>");
+       puts("<dict>");
+      }
+
+      if (group)
+        *group = attr->group_tag;
     }
 
+    if (!attr->name)
+      return;
+
     print_xml_string("key", attr->name);
     if (attr->num_values > 1)
       puts("<array>");
-  }
-  else if (Output == _CUPS_OUTPUT_TEST)
-  {
-    if (!attr->name)
+
+    switch (attr->value_tag)
     {
-      puts("        -- separator --");
-      return;
-    }
+      case IPP_TAG_INTEGER :
+      case IPP_TAG_ENUM :
+         for (i = 0; i < attr->num_values; i ++)
+           if (Output == _CUPS_OUTPUT_PLIST)
+             printf("<integer>%d</integer>\n", attr->values[i].integer);
+           else
+             printf("%d ", attr->values[i].integer);
+         break;
 
-    printf("        %s (%s%s) = ", attr->name,
-          attr->num_values > 1 ? "1setOf " : "",
-          ippTagString(attr->value_tag));
-  }
+      case IPP_TAG_BOOLEAN :
+         for (i = 0; i < attr->num_values; i ++)
+           if (Output == _CUPS_OUTPUT_PLIST)
+             puts(attr->values[i].boolean ? "<true />" : "<false />");
+           else if (attr->values[i].boolean)
+             fputs("true ", stdout);
+           else
+             fputs("false ", stdout);
+         break;
 
-  switch (attr->value_tag)
-  {
-    case IPP_TAG_INTEGER :
-    case IPP_TAG_ENUM :
-       for (i = 0; i < attr->num_values; i ++)
-         if (Output == _CUPS_OUTPUT_PLIST)
-           printf("<integer>%d</integer>\n", attr->values[i].integer);
-         else
-           printf("%d ", attr->values[i].integer);
-       break;
+      case IPP_TAG_RANGE :
+         for (i = 0; i < attr->num_values; i ++)
+           if (Output == _CUPS_OUTPUT_PLIST)
+             printf("<dict><key>lower</key><integer>%d</integer>"
+                    "<key>upper</key><integer>%d</integer></dict>\n",
+                    attr->values[i].range.lower, attr->values[i].range.upper);
+           else
+             printf("%d-%d ", attr->values[i].range.lower,
+                    attr->values[i].range.upper);
+         break;
 
-    case IPP_TAG_BOOLEAN :
-       for (i = 0; i < attr->num_values; i ++)
-         if (Output == _CUPS_OUTPUT_PLIST)
-           puts(attr->values[i].boolean ? "<true />" : "<false />");
-         else if (attr->values[i].boolean)
-           fputs("true ", stdout);
-         else
-           fputs("false ", stdout);
-       break;
+      case IPP_TAG_RESOLUTION :
+         for (i = 0; i < attr->num_values; i ++)
+           if (Output == _CUPS_OUTPUT_PLIST)
+             printf("<dict><key>xres</key><integer>%d</integer>"
+                    "<key>yres</key><integer>%d</integer>"
+                    "<key>units</key><string>%s</string></dict>\n",
+                    attr->values[i].resolution.xres,
+                    attr->values[i].resolution.yres,
+                    attr->values[i].resolution.units == IPP_RES_PER_INCH ?
+                        "dpi" : "dpcm");
+           else
+             printf("%dx%d%s ", attr->values[i].resolution.xres,
+                    attr->values[i].resolution.yres,
+                    attr->values[i].resolution.units == IPP_RES_PER_INCH ?
+                        "dpi" : "dpcm");
+         break;
 
-    case IPP_TAG_RANGE :
-       for (i = 0; i < attr->num_values; i ++)
-         if (Output == _CUPS_OUTPUT_PLIST)
-           printf("<dict><key>lower</key><integer>%d</integer>"
-                  "<key>upper</key><integer>%d</integer></dict>\n",
-                  attr->values[i].range.lower, attr->values[i].range.upper);
-         else
-           printf("%d-%d ", attr->values[i].range.lower,
-                  attr->values[i].range.upper);
-       break;
+      case IPP_TAG_DATE :
+         for (i = 0; i < attr->num_values; i ++)
+           if (Output == _CUPS_OUTPUT_PLIST)
+             printf("<date>%s</date>\n", iso_date(attr->values[i].date));
+           else
+             printf("%s ", iso_date(attr->values[i].date));
+         break;
 
-    case IPP_TAG_RESOLUTION :
-       for (i = 0; i < attr->num_values; i ++)
-         if (Output == _CUPS_OUTPUT_PLIST)
-           printf("<dict><key>xres</key><integer>%d</integer>"
-                  "<key>yres</key><integer>%d</integer>"
-                  "<key>units</key><string>%s</string></dict>\n",
-                  attr->values[i].resolution.xres,
-                  attr->values[i].resolution.yres,
-                  attr->values[i].resolution.units == IPP_RES_PER_INCH ?
-                      "dpi" : "dpc");
-         else
-           printf("%dx%d%s ", attr->values[i].resolution.xres,
-                  attr->values[i].resolution.yres,
-                  attr->values[i].resolution.units == IPP_RES_PER_INCH ?
-                      "dpi" : "dpc");
-       break;
+      case IPP_TAG_STRING :
+          for (i = 0; i < attr->num_values; i ++)
+          {
+            if (Output == _CUPS_OUTPUT_PLIST)
+            {
+             char      buffer[IPP_MAX_LENGTH * 5 / 4 + 1];
+                                       /* Output buffer */
 
-    case IPP_TAG_DATE :
-       for (i = 0; i < attr->num_values; i ++)
-         if (Output == _CUPS_OUTPUT_PLIST)
-            printf("<date>%s</date>\n", iso_date(attr->values[i].date));
-          else
-           printf("%s ", iso_date(attr->values[i].date));
-        break;
+              printf("<data>%s</data>\n",
+                     httpEncode64_2(buffer, sizeof(buffer),
+                                    attr->values[i].unknown.data,
+                                    attr->values[i].unknown.length));
+            }
+            else
+            {
+              char     *ptr,           /* Pointer into data */
+                       *end;           /* End of data */
+
+              putchar('\"');
+              for (ptr = attr->values[i].unknown.data,
+                       end = ptr + attr->values[i].unknown.length;
+                   ptr < end;
+                   ptr ++)
+              {
+                if (*ptr == '\\' || *ptr == '\"')
+                  printf("\\%c", *ptr);
+                else if (!isprint(*ptr & 255))
+                  printf("\\%03o", *ptr & 255);
+                else
+                  putchar(*ptr);
+              }
+              putchar('\"');
+            }
+          }
+          break;
 
-    case IPP_TAG_STRING :
-    case IPP_TAG_TEXT :
-    case IPP_TAG_NAME :
-    case IPP_TAG_KEYWORD :
-    case IPP_TAG_CHARSET :
-    case IPP_TAG_URI :
-    case IPP_TAG_MIMETYPE :
-    case IPP_TAG_LANGUAGE :
-       for (i = 0; i < attr->num_values; i ++)
-         if (Output == _CUPS_OUTPUT_PLIST)
-           print_xml_string("string", attr->values[i].string.text);
-         else
-           printf("\"%s\" ", attr->values[i].string.text);
-       break;
+      case IPP_TAG_TEXT :
+      case IPP_TAG_NAME :
+      case IPP_TAG_KEYWORD :
+      case IPP_TAG_CHARSET :
+      case IPP_TAG_URI :
+      case IPP_TAG_MIMETYPE :
+      case IPP_TAG_LANGUAGE :
+         for (i = 0; i < attr->num_values; i ++)
+           if (Output == _CUPS_OUTPUT_PLIST)
+             print_xml_string("string", attr->values[i].string.text);
+           else
+             printf("\"%s\" ", attr->values[i].string.text);
+         break;
 
-    case IPP_TAG_TEXTLANG :
-    case IPP_TAG_NAMELANG :
-       for (i = 0; i < attr->num_values; i ++)
-         if (Output == _CUPS_OUTPUT_PLIST)
+      case IPP_TAG_TEXTLANG :
+      case IPP_TAG_NAMELANG :
+         for (i = 0; i < attr->num_values; i ++)
+           if (Output == _CUPS_OUTPUT_PLIST)
+           {
+             fputs("<dict><key>language</key><string>", stdout);
+             print_xml_string(NULL, attr->values[i].string.language);
+             fputs("</string><key>string</key><string>", stdout);
+             print_xml_string(NULL, attr->values[i].string.text);
+             puts("</string></dict>");
+           }
+           else
+             printf("\"%s\"[%s] ", attr->values[i].string.text,
+                    attr->values[i].string.language);
+         break;
+
+      case IPP_TAG_BEGIN_COLLECTION :
+         for (i = 0; i < attr->num_values; i ++)
          {
-           fputs("<dict><key>language</key><string>", stdout);
-           print_xml_string(NULL, attr->values[i].string.charset);
-           fputs("</string><key>string</key><string>", stdout);
-           print_xml_string(NULL, attr->values[i].string.text);
-           puts("</string></dict>");
+           if (Output == _CUPS_OUTPUT_PLIST)
+           {
+             puts("<dict>");
+             for (colattr = attr->values[i].collection->attrs;
+                  colattr;
+                  colattr = colattr->next)
+               print_attr(colattr, NULL);
+             puts("</dict>");
+           }
+           else
+           {
+             if (i)
+               putchar(' ');
+
+             print_col(attr->values[i].collection);
+           }
          }
-         else
-           printf("\"%s\",%s ", attr->values[i].string.text,
-                  attr->values[i].string.charset);
-       break;
+         break;
 
-    case IPP_TAG_BEGIN_COLLECTION :
-       for (i = 0; i < attr->num_values; i ++)
-       {
+      default :
          if (Output == _CUPS_OUTPUT_PLIST)
-         {
-           puts("<dict>");
-           for (colattr = attr->values[i].collection->attrs;
-                colattr;
-                colattr = colattr->next)
-             print_attr(colattr);
-           puts("</dict>");
-         }
+           printf("<string>&lt;&lt;%s&gt;&gt;</string>\n",
+                  ippTagString(attr->value_tag));
          else
-         {
-           if (i)
-             putchar(' ');
-
-           print_col(attr->values[i].collection);
-          }
-       }
-       break;
-
-    default :
-       if (Output == _CUPS_OUTPUT_PLIST)
-         printf("<string>&lt;&lt;%s&gt;&gt;</string>\n",
-                ippTagString(attr->value_tag));
-       else
-         fputs(ippTagString(attr->value_tag), stdout);
-       break;
-  }
+           fputs(ippTagString(attr->value_tag), stdout);
+         break;
+    }
 
-  if (Output == _CUPS_OUTPUT_PLIST)
-  {
     if (attr->num_values > 1)
       puts("</array>");
   }
   else
-    putchar('\n');
+  {
+    char       buffer[8192];           /* Value buffer */
+
+    if (Output == _CUPS_OUTPUT_TEST)
+    {
+      if (!attr->name)
+      {
+        puts("        -- separator --");
+        return;
+      }
+
+      printf("        %s (%s%s) = ", attr->name,
+            attr->num_values > 1 ? "1setOf " : "",
+            ippTagString(attr->value_tag));
+    }
+
+    ippAttributeString(attr, buffer, sizeof(buffer));
+    puts(buffer);
+  }
 }
 
 
@@ -2895,7 +4160,7 @@ print_col(ipp_t *col)                     /* I - Collection attribute to print */
            printf("%dx%d%s ", attr->values[i].resolution.xres,
                   attr->values[i].resolution.yres,
                   attr->values[i].resolution.units == IPP_RES_PER_INCH ?
-                      "dpi" : "dpc");
+                      "dpi" : "dpcm");
          break;
 
       case IPP_TAG_STRING :
@@ -2913,8 +4178,8 @@ print_col(ipp_t *col)                     /* I - Collection attribute to print */
       case IPP_TAG_TEXTLANG :
       case IPP_TAG_NAMELANG :
          for (i = 0; i < attr->num_values; i ++)
-           printf("\"%s\",%s ", attr->values[i].string.text,
-                  attr->values[i].string.charset);
+           printf("\"%s\"[%s] ", attr->values[i].string.text,
+                  attr->values[i].string.language);
          break;
 
       case IPP_TAG_BEGIN_COLLECTION :
@@ -2984,7 +4249,7 @@ print_csv(
           break;
         else if (!strcmp(current->name, displayed[i]))
         {
-          _ippAttrString(current, buffer, maxlength);
+          ippAttributeString(current, buffer, maxlength);
           break;
         }
       }
@@ -3052,7 +4317,7 @@ print_fatal_error(const char *s,  /* I - Printf-style format string */
     print_xml_trailer(0, buffer);
   }
   else
-    _cupsLangPrintf(stderr, "ipptool: %s\n", buffer);
+    _cupsLangPrintf(stderr, "ipptool: %s", buffer);
 }
 
 
@@ -3105,7 +4370,7 @@ print_line(
           break;
         else if (!strcmp(current->name, displayed[i]))
         {
-          _ippAttrString(current, buffer, maxlength);
+          ippAttributeString(current, buffer, maxlength);
           break;
         }
       }
@@ -3141,37 +4406,6 @@ print_line(
 }
 
 
-/*
- * 'print_test_error()' - Print a test error message.
- */
-
-static void
-print_test_error(const char *s,                /* I - Printf-style format string */
-                 ...)                  /* I - Additional arguments as needed */
-{
-  char         buffer[10240];          /* Format buffer */
-  va_list      ap;                     /* Pointer to arguments */
-
-
- /*
-  * Format the error message...
-  */
-
-  va_start(ap, s);
-  vsnprintf(buffer, sizeof(buffer), s, ap);
-  va_end(ap);
-
- /*
-  * Then output it...
-  */
-
-  if (Output == _CUPS_OUTPUT_PLIST)
-    print_xml_string("string", buffer);
-  else
-    printf("        %s\n", buffer);
-}
-
-
 /*
  * 'print_xml_header()' - Print a standard XML plist header.
  */
@@ -3186,6 +4420,8 @@ print_xml_header(void)
          "\"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">");
     puts("<plist version=\"1.0\">");
     puts("<dict>");
+    puts("<key>ipptoolVersion</key>");
+    puts("<string>" CUPS_SVERSION "</string>");
     puts("<key>Transfer</key>");
     printf("<string>%s</string>\n",
            Transfer == _CUPS_TRANSFER_AUTO ? "auto" :
@@ -3202,21 +4438,84 @@ print_xml_header(void)
  * 'print_xml_string()' - Print an XML string with escaping.
  */
 
-static void
-print_xml_string(const char *element,  /* I - Element name or NULL */
-                const char *s)         /* I - String to print */
-{
-  if (element)
-    printf("<%s>", element);
+static void
+print_xml_string(const char *element,  /* I - Element name or NULL */
+                const char *s)         /* I - String to print */
+{
+  if (element)
+    printf("<%s>", element);
+
+  while (*s)
+  {
+    if (*s == '&')
+      fputs("&amp;", stdout);
+    else if (*s == '<')
+      fputs("&lt;", stdout);
+    else if (*s == '>')
+      fputs("&gt;", stdout);
+    else if ((*s & 0xe0) == 0xc0)
+    {
+     /*
+      * Validate UTF-8 two-byte sequence...
+      */
+
+      if ((s[1] & 0xc0) != 0x80)
+      {
+        putchar('?');
+        s ++;
+      }
+      else
+      {
+        putchar(*s++);
+        putchar(*s);
+      }
+    }
+    else if ((*s & 0xf0) == 0xe0)
+    {
+     /*
+      * Validate UTF-8 three-byte sequence...
+      */
+
+      if ((s[1] & 0xc0) != 0x80 || (s[2] & 0xc0) != 0x80)
+      {
+        putchar('?');
+        s += 2;
+      }
+      else
+      {
+        putchar(*s++);
+        putchar(*s++);
+        putchar(*s);
+      }
+    }
+    else if ((*s & 0xf8) == 0xf0)
+    {
+     /*
+      * Validate UTF-8 four-byte sequence...
+      */
+
+      if ((s[1] & 0xc0) != 0x80 || (s[2] & 0xc0) != 0x80 ||
+          (s[3] & 0xc0) != 0x80)
+      {
+        putchar('?');
+        s += 3;
+      }
+      else
+      {
+        putchar(*s++);
+        putchar(*s++);
+        putchar(*s++);
+        putchar(*s);
+      }
+    }
+    else if ((*s & 0x80) || (*s < ' ' && !isspace(*s & 255)))
+    {
+     /*
+      * Invalid control character...
+      */
 
-  while (*s)
-  {
-    if (*s == '&')
-      fputs("&amp;", stdout);
-    else if (*s == '<')
-      fputs("&lt;", stdout);
-    else if (*s == '>')
-      fputs("&gt;", stdout);
+      putchar('?');
+    }
     else
       putchar(*s);
 
@@ -3267,6 +4566,15 @@ set_variable(_cups_vars_t *vars, /* I - Variables */
                *var;                   /* New variable */
 
 
+  if (!_cups_strcasecmp(name, "filename"))
+  {
+    if (vars->filename)
+      free(vars->filename);
+
+    vars->filename = strdup(value);
+    return;
+  }
+
   key.name = (char *)name;
   if ((var = cupsArrayFind(vars->vars, &key)) != NULL)
   {
@@ -3288,6 +4596,61 @@ set_variable(_cups_vars_t *vars, /* I - Variables */
 }
 
 
+#ifndef WIN32
+/*
+ * 'sigterm_handler()' - Handle SIGINT and SIGTERM.
+ */
+
+static void
+sigterm_handler(int sig)               /* I - Signal number (unused) */
+{
+  (void)sig;
+
+  Cancel = 1;
+
+  signal(SIGINT, SIG_DFL);
+  signal(SIGTERM, SIG_DFL);
+}
+#endif /* !WIN32 */
+
+
+/*
+ * 'timeout_cb()' - Handle HTTP timeouts.
+ */
+
+static int                             /* O - 1 to continue, 0 to cancel */
+timeout_cb(http_t *http,               /* I - Connection to server */
+           void   *user_data)          /* I - User data (unused) */
+{
+  int          buffered = 0;           /* Bytes buffered but not yet sent */
+
+
+  (void)user_data;
+
+  /*
+  * If the socket still have data waiting to be sent to the printer (as can
+  * happen if the printer runs out of paper), continue to wait until the output
+  * buffer is empty...
+  */
+
+#ifdef SO_NWRITE                       /* OS X and some versions of Linux */
+  socklen_t len = sizeof(buffered);    /* Size of return value */
+
+  if (getsockopt(httpGetFd(http), SOL_SOCKET, SO_NWRITE, &buffered, &len))
+    buffered = 0;
+
+#elif defined(SIOCOUTQ)                        /* Others except Windows */
+  if (ioctl(httpGetFd(http), SIOCOUTQ, &buffered))
+    buffered = 0;
+
+#else                                  /* Windows (not possible) */
+  (void)http;
+#endif /* SO_NWRITE */
+
+  return (buffered > 0);
+}
+
+
 /*
  * 'usage()' - Show program usage.
  */
@@ -3295,27 +4658,37 @@ set_variable(_cups_vars_t *vars,        /* I - Variables */
 static void
 usage(void)
 {
-  _cupsLangPuts(stderr,
-                _("Usage: ipptool [options] URI filename [ ... "
-                 "filenameN ]\n"
-                 "\n"
-                 "Options:\n"
-                 "\n"
-                 "-C             Send requests using chunking (default)\n"
-                 "-E             Test with TLS encryption.\n"
-                 "-L             Send requests using content-length\n"
-                 "-S             Test with SSL encryption.\n"
-                 "-V version     Set default IPP version.\n"
-                 "-X             Produce XML plist instead of plain text.\n"
-                 "-d name=value  Define variable.\n"
-                 "-f filename    Set default request filename.\n"
-                 "-i seconds     Repeat the last file with the given time "
-                 "interval.\n"
-                 "-n count       Repeat the last file the given number of "
-                 "times.\n"
-                 "-q             Be quiet - no output except errors.\n"
-                 "-t             Produce a test report.\n"
-                 "-v             Show all attributes sent and received.\n"));
+  _cupsLangPuts(stderr, _("Usage: ipptool [options] URI filename [ ... "
+                         "filenameN ]"));
+  _cupsLangPuts(stderr, _("Options:"));
+  _cupsLangPuts(stderr, _("  -4                      Connect using IPv4."));
+  _cupsLangPuts(stderr, _("  -6                      Connect using IPv6."));
+  _cupsLangPuts(stderr, _("  -C                      Send requests using "
+                          "chunking (default)."));
+  _cupsLangPuts(stdout, _("  -E                      Test with HTTP Upgrade to "
+                          "TLS."));
+  _cupsLangPuts(stderr, _("  -I                      Ignore errors."));
+  _cupsLangPuts(stderr, _("  -L                      Send requests using "
+                          "content-length."));
+  _cupsLangPuts(stderr, _("  -S                      Test with SSL "
+                         "encryption."));
+  _cupsLangPuts(stderr, _("  -T seconds              Set the receive/send "
+                          "timeout in seconds."));
+  _cupsLangPuts(stderr, _("  -V version              Set default IPP "
+                          "version."));
+  _cupsLangPuts(stderr, _("  -X                      Produce XML plist instead "
+                          "of plain text."));
+  _cupsLangPuts(stderr, _("  -d name=value           Set named variable to "
+                          "value."));
+  _cupsLangPuts(stderr, _("  -f filename             Set default request "
+                          "filename."));
+  _cupsLangPuts(stderr, _("  -i seconds              Repeat the last file with "
+                          "the given time interval."));
+  _cupsLangPuts(stderr, _("  -n count                Repeat the last file the "
+                          "given number of times."));
+  _cupsLangPuts(stderr, _("  -q                      Run silently."));
+  _cupsLangPuts(stderr, _("  -t                      Produce a test report."));
+  _cupsLangPuts(stderr, _("  -v                      Be verbose."));
 
   exit(1);
 }
@@ -3326,8 +4699,8 @@ usage(void)
  */
 
 static int                             /* O - 1 if valid, 0 otherwise */
-validate_attr(ipp_attribute_t *attr,   /* I - Attribute to validate */
-              int             print)   /* I - 1 = report issues to stdout */
+validate_attr(cups_array_t    *errors, /* I - Errors array */
+              ipp_attribute_t *attr)   /* I - Attribute to validate */
 {
   int          i;                      /* Looping var */
   char         scheme[64],             /* Scheme from URI */
@@ -3362,18 +4735,18 @@ validate_attr(ipp_attribute_t *attr,    /* I - Attribute to validate */
   {
     valid = 0;
 
-    if (print)
-      print_test_error("\"%s\": Bad attribute name - invalid character (RFC "
-                      "2911 section 4.1.3).", attr->name);
+    add_stringf(errors,
+               "\"%s\": Bad attribute name - invalid character "
+               "(RFC 2911 section 4.1.3).", attr->name);
   }
 
   if ((ptr - attr->name) > 255)
   {
     valid = 0;
 
-    if (print)
-      print_test_error("\"%s\": Bad attribute name - bad length (RFC 2911 "
-                      "section 4.1.3).", attr->name);
+    add_stringf(errors,
+               "\"%s\": Bad attribute name - bad length "
+               "(RFC 2911 section 4.1.3).", attr->name);
   }
 
   switch (attr->value_tag)
@@ -3389,11 +4762,10 @@ validate_attr(ipp_attribute_t *attr,    /* I - Attribute to validate */
          {
            valid = 0;
 
-           if (print)
-             print_test_error("\"%s\": Bad boolen value %d (RFC 2911 section "
-                              "4.1.10).", attr->name, attr->values[i].boolean);
-            else
-             break;
+           add_stringf(errors,
+                       "\"%s\": Bad boolen value %d "
+                       "(RFC 2911 section 4.1.11).", attr->name,
+                       attr->values[i].boolean);
          }
        }
         break;
@@ -3405,12 +4777,10 @@ validate_attr(ipp_attribute_t *attr,    /* I - Attribute to validate */
          {
            valid = 0;
 
-           if (print)
-             print_test_error("\"%s\": Bad enum value %d - out of range "
-                              "(RFC 2911 section 4.1.4).", attr->name,
-                              attr->values[i].integer);
-            else
-             break;
+           add_stringf(errors,
+                       "\"%s\": Bad enum value %d - out of range "
+                       "(RFC 2911 section 4.1.4).", attr->name,
+                       attr->values[i].integer);
          }
        }
         break;
@@ -3418,16 +4788,14 @@ validate_attr(ipp_attribute_t *attr,    /* I - Attribute to validate */
     case IPP_TAG_STRING :
         for (i = 0; i < attr->num_values; i ++)
        {
-         if (attr->values[i].unknown.length > 1023)
+         if (attr->values[i].unknown.length > IPP_MAX_OCTETSTRING)
          {
            valid = 0;
 
-           if (print)
-             print_test_error("\"%s\": Bad octetString value - bad length %d "
-                              "(RFC 2911 section 4.1.10).", attr->name,
-                              attr->values[i].unknown.length);
-            else
-             break;
+           add_stringf(errors,
+                       "\"%s\": Bad octetString value - bad length %d "
+                       "(RFC 2911 section 4.1.10).", attr->name,
+                       attr->values[i].unknown.length);
          }
        }
         break;
@@ -3441,99 +4809,81 @@ validate_attr(ipp_attribute_t *attr,    /* I - Attribute to validate */
          {
            valid = 0;
 
-           if (print)
-             print_test_error("\"%s\": Bad dateTime month %u (RFC 2911 "
-                              "section 4.1.13).", attr->name, date[2]);
-            else
-             break;
+           add_stringf(errors,
+                       "\"%s\": Bad dateTime month %u "
+                       "(RFC 2911 section 4.1.14).", attr->name, date[2]);
          }
 
           if (date[3] < 1 || date[3] > 31)
          {
            valid = 0;
 
-           if (print)
-             print_test_error("\"%s\": Bad dateTime day %u (RFC 2911 "
-                              "section 4.1.13).", attr->name, date[3]);
-            else
-             break;
+           add_stringf(errors,
+                       "\"%s\": Bad dateTime day %u "
+                       "(RFC 2911 section 4.1.14).", attr->name, date[3]);
          }
 
           if (date[4] > 23)
          {
            valid = 0;
 
-           if (print)
-             print_test_error("\"%s\": Bad dateTime hours %u (RFC 2911 "
-                              "section 4.1.13).", attr->name, date[4]);
-            else
-             break;
+           add_stringf(errors,
+                       "\"%s\": Bad dateTime hours %u "
+                       "(RFC 2911 section 4.1.14).", attr->name, date[4]);
          }
 
           if (date[5] > 59)
          {
            valid = 0;
 
-           if (print)
-             print_test_error("\"%s\": Bad dateTime minutes %u (RFC 2911 "
-                              "section 4.1.13).", attr->name, date[5]);
-            else
-             break;
+           add_stringf(errors,
+                       "\"%s\": Bad dateTime minutes %u "
+                       "(RFC 2911 section 4.1.14).", attr->name, date[5]);
          }
 
           if (date[6] > 60)
          {
            valid = 0;
 
-           if (print)
-             print_test_error("\"%s\": Bad dateTime seconds %u (RFC 2911 "
-                              "section 4.1.13).", attr->name, date[6]);
-            else
-             break;
+           add_stringf(errors,
+                       "\"%s\": Bad dateTime seconds %u "
+                       "(RFC 2911 section 4.1.14).", attr->name, date[6]);
          }
 
           if (date[7] > 9)
          {
            valid = 0;
 
-           if (print)
-             print_test_error("\"%s\": Bad dateTime deciseconds %u (RFC 2911 "
-                              "section 4.1.13).", attr->name, date[7]);
-            else
-             break;
+           add_stringf(errors,
+                       "\"%s\": Bad dateTime deciseconds %u "
+                       "(RFC 2911 section 4.1.14).", attr->name, date[7]);
          }
 
           if (date[8] != '-' && date[8] != '+')
          {
            valid = 0;
 
-           if (print)
-             print_test_error("\"%s\": Bad dateTime UTC sign '%c' (RFC 2911 "
-                              "section 4.1.13).", attr->name, date[8]);
-            else
-             break;
+           add_stringf(errors,
+                       "\"%s\": Bad dateTime UTC sign '%c' "
+                       "(RFC 2911 section 4.1.14).", attr->name, date[8]);
          }
 
           if (date[9] > 11)
          {
            valid = 0;
 
-           if (print)
-             print_test_error("\"%s\": Bad dateTime UTC hours %u (RFC 2911 "
-                              "section 4.1.13).", attr->name, date[9]);
-            else
-             break;
+           add_stringf(errors,
+                       "\"%s\": Bad dateTime UTC hours %u "
+                       "(RFC 2911 section 4.1.14).", attr->name, date[9]);
          }
 
           if (date[10] > 59)
          {
            valid = 0;
 
-           if (print)
-             print_test_error("\"%s\": Bad dateTime UTC minutes %u (RFC 2911 "
-                              "section 4.1.13).", attr->name, date[10]);
-            else
-             break;
+           add_stringf(errors,
+                       "\"%s\": Bad dateTime UTC minutes %u "
+                       "(RFC 2911 section 4.1.14).", attr->name, date[10]);
          }
        }
         break;
@@ -3545,36 +4895,32 @@ validate_attr(ipp_attribute_t *attr,    /* I - Attribute to validate */
          {
            valid = 0;
 
-           if (print)
-             print_test_error("\"%s\": Bad resolution value %dx%d%s - cross "
-                              "feed resolution must be positive (RFC 2911 "
-                              "section 4.1.13).", attr->name,
-                              attr->values[i].resolution.xres,
-                              attr->values[i].resolution.yres,
-                              attr->values[i].resolution.units ==
-                                  IPP_RES_PER_INCH ? "dpi" :
-                                  attr->values[i].resolution.units ==
-                                      IPP_RES_PER_CM ? "dpc" : "unknown");
-            else
-             break;
+           add_stringf(errors,
+                       "\"%s\": Bad resolution value %dx%d%s - cross "
+                       "feed resolution must be positive "
+                       "(RFC 2911 section 4.1.15).", attr->name,
+                       attr->values[i].resolution.xres,
+                       attr->values[i].resolution.yres,
+                       attr->values[i].resolution.units ==
+                           IPP_RES_PER_INCH ? "dpi" :
+                           attr->values[i].resolution.units ==
+                               IPP_RES_PER_CM ? "dpcm" : "unknown");
          }
 
          if (attr->values[i].resolution.yres <= 0)
          {
            valid = 0;
 
-           if (print)
-             print_test_error("\"%s\": Bad resolution value %dx%d%s - feed "
-                              "resolution must be positive (RFC 2911 section "
-                              "4.1.13).", attr->name,
-                              attr->values[i].resolution.xres,
-                              attr->values[i].resolution.yres,
-                              attr->values[i].resolution.units ==
-                                  IPP_RES_PER_INCH ? "dpi" :
-                                  attr->values[i].resolution.units ==
-                                      IPP_RES_PER_CM ? "dpc" : "unknown");
-            else
-             break;
+           add_stringf(errors,
+                       "\"%s\": Bad resolution value %dx%d%s - feed "
+                       "resolution must be positive "
+                       "(RFC 2911 section 4.1.15).", attr->name,
+                       attr->values[i].resolution.xres,
+                       attr->values[i].resolution.yres,
+                       attr->values[i].resolution.units ==
+                           IPP_RES_PER_INCH ? "dpi" :
+                           attr->values[i].resolution.units ==
+                               IPP_RES_PER_CM ? "dpcm" : "unknown");
          }
 
          if (attr->values[i].resolution.units != IPP_RES_PER_INCH &&
@@ -3582,17 +4928,15 @@ validate_attr(ipp_attribute_t *attr,    /* I - Attribute to validate */
          {
            valid = 0;
 
-           if (print)
-             print_test_error("\"%s\": Bad resolution value %dx%d%s - bad "
-                              "units value (RFC 2911 section 4.1.13).",
-                              attr->name, attr->values[i].resolution.xres,
-                              attr->values[i].resolution.yres,
-                              attr->values[i].resolution.units ==
-                                  IPP_RES_PER_INCH ? "dpi" :
-                                  attr->values[i].resolution.units ==
-                                      IPP_RES_PER_CM ? "dpc" : "unknown");
-            else
-             break;
+           add_stringf(errors,
+                       "\"%s\": Bad resolution value %dx%d%s - bad "
+                       "units value (RFC 2911 section 4.1.15).",
+                       attr->name, attr->values[i].resolution.xres,
+                       attr->values[i].resolution.yres,
+                       attr->values[i].resolution.units ==
+                           IPP_RES_PER_INCH ? "dpi" :
+                           attr->values[i].resolution.units ==
+                               IPP_RES_PER_CM ? "dpcm" : "unknown");
          }
        }
         break;
@@ -3604,13 +4948,11 @@ validate_attr(ipp_attribute_t *attr,    /* I - Attribute to validate */
          {
            valid = 0;
 
-           if (print)
-             print_test_error("\"%s\": Bad rangeOfInteger value %d-%d - lower "
-                              "greater than upper (RFC 2911 section 4.1.13).",
-                              attr->name, attr->values[i].range.lower,
-                              attr->values[i].range.upper);
-            else
-             break;
+           add_stringf(errors,
+                       "\"%s\": Bad rangeOfInteger value %d-%d - lower "
+                       "greater than upper (RFC 2911 section 4.1.13).",
+                       attr->name, attr->values[i].range.lower,
+                       attr->values[i].range.upper);
          }
        }
         break;
@@ -3622,20 +4964,20 @@ validate_attr(ipp_attribute_t *attr,    /* I - Attribute to validate */
               colattr;
               colattr = colattr->next)
          {
-           if (!validate_attr(colattr, 0))
+           if (!validate_attr(NULL, colattr))
            {
              valid = 0;
              break;
            }
          }
 
-         if (colattr && print)
+         if (colattr && errors)
          {
-            print_test_error("\"%s\": Bad collection value.", attr->name);
+            add_stringf(errors, "\"%s\": Bad collection value.", attr->name);
 
            while (colattr)
            {
-             validate_attr(colattr, print);
+             validate_attr(errors, colattr);
              colattr = colattr->next;
            }
          }
@@ -3683,25 +5025,21 @@ validate_attr(ipp_attribute_t *attr,    /* I - Attribute to validate */
          {
            valid = 0;
 
-           if (print)
-             print_test_error("\"%s\": Bad text value \"%s\" - bad UTF-8 "
-                              "sequence (RFC 2911 section 4.1.1).", attr->name,
-                              attr->values[i].string.text);
-            else
-             break;
+           add_stringf(errors,
+                       "\"%s\": Bad text value \"%s\" - bad UTF-8 "
+                       "sequence (RFC 2911 section 4.1.1).", attr->name,
+                       attr->values[i].string.text);
          }
 
-         if ((ptr - attr->values[i].string.text) > 1023)
+         if ((ptr - attr->values[i].string.text) > (IPP_MAX_TEXT - 1))
          {
            valid = 0;
 
-           if (print)
-             print_test_error("\"%s\": Bad text value \"%s\" - bad length %d "
-                              "(RFC 2911 section 4.1.1).", attr->name,
-                              attr->values[i].string.text,
-                              (int)strlen(attr->values[i].string.text));
-            else
-             break;
+           add_stringf(errors,
+                       "\"%s\": Bad text value \"%s\" - bad length %d "
+                       "(RFC 2911 section 4.1.1).", attr->name,
+                       attr->values[i].string.text,
+                       (int)strlen(attr->values[i].string.text));
          }
        }
         break;
@@ -3747,25 +5085,21 @@ validate_attr(ipp_attribute_t *attr,    /* I - Attribute to validate */
          {
            valid = 0;
 
-           if (print)
-             print_test_error("\"%s\": Bad name value \"%s\" - bad UTF-8 "
-                              "sequence (RFC 2911 section 4.1.2).", attr->name,
-                              attr->values[i].string.text);
-            else
-             break;
+           add_stringf(errors,
+                       "\"%s\": Bad name value \"%s\" - bad UTF-8 "
+                       "sequence (RFC 2911 section 4.1.2).", attr->name,
+                       attr->values[i].string.text);
          }
 
-         if ((ptr - attr->values[i].string.text) > 1023)
+         if ((ptr - attr->values[i].string.text) > (IPP_MAX_NAME - 1))
          {
            valid = 0;
 
-           if (print)
-             print_test_error("\"%s\": Bad name value \"%s\" - bad length %d "
-                              "(RFC 2911 section 4.1.2).", attr->name,
-                              attr->values[i].string.text,
-                              (int)strlen(attr->values[i].string.text));
-            else
-             break;
+           add_stringf(errors,
+                       "\"%s\": Bad name value \"%s\" - bad length %d "
+                       "(RFC 2911 section 4.1.2).", attr->name,
+                       attr->values[i].string.text,
+                       (int)strlen(attr->values[i].string.text));
          }
        }
         break;
@@ -3782,25 +5116,21 @@ validate_attr(ipp_attribute_t *attr,    /* I - Attribute to validate */
          {
            valid = 0;
 
-           if (print)
-             print_test_error("\"%s\": Bad keyword value \"%s\" - invalid "
-                              "character (RFC 2911 section 4.1.3).",
-                              attr->name, attr->values[i].string.text);
-            else
-             break;
+           add_stringf(errors,
+                       "\"%s\": Bad keyword value \"%s\" - invalid "
+                       "character (RFC 2911 section 4.1.3).",
+                       attr->name, attr->values[i].string.text);
          }
 
-         if ((ptr - attr->values[i].string.text) > 255)
+         if ((ptr - attr->values[i].string.text) > (IPP_MAX_KEYWORD - 1))
          {
            valid = 0;
 
-           if (print)
-             print_test_error("\"%s\": Bad keyword value \"%s\" - bad "
-                              "length %d (RFC 2911 section 4.1.3).",
-                              attr->name, attr->values[i].string.text,
-                              (int)strlen(attr->values[i].string.text));
-            else
-             break;
+           add_stringf(errors,
+                       "\"%s\": Bad keyword value \"%s\" - bad "
+                       "length %d (RFC 2911 section 4.1.3).",
+                       attr->name, attr->values[i].string.text,
+                       (int)strlen(attr->values[i].string.text));
          }
        }
         break;
@@ -3819,27 +5149,22 @@ validate_attr(ipp_attribute_t *attr,    /* I - Attribute to validate */
          {
            valid = 0;
 
-           if (print)
-             print_test_error("\"%s\": Bad URI value \"%s\" - %s "
-                              "(RFC 2911 section 4.1.5).", attr->name,
-                              attr->values[i].string.text,
-                              URIStatusStrings[uri_status -
-                                               HTTP_URI_OVERFLOW]);
-            else
-             break;
+           add_stringf(errors,
+                       "\"%s\": Bad URI value \"%s\" - %s "
+                       "(RFC 2911 section 4.1.5).", attr->name,
+                       attr->values[i].string.text,
+                       httpURIStatusString(uri_status));
          }
 
-         if (strlen(attr->values[i].string.text) > 1023)
+         if (strlen(attr->values[i].string.text) > (IPP_MAX_URI - 1))
          {
            valid = 0;
 
-           if (print)
-             print_test_error("\"%s\": Bad URI value \"%s\" - bad length %d "
-                              "(RFC 2911 section 4.1.5).", attr->name,
-                              attr->values[i].string.text,
-                              (int)strlen(attr->values[i].string.text));
-            else
-             break;
+           add_stringf(errors,
+                       "\"%s\": Bad URI value \"%s\" - bad length %d "
+                       "(RFC 2911 section 4.1.5).", attr->name,
+                       attr->values[i].string.text,
+                       (int)strlen(attr->values[i].string.text));
          }
        }
         break;
@@ -3860,25 +5185,21 @@ validate_attr(ipp_attribute_t *attr,    /* I - Attribute to validate */
          {
            valid = 0;
 
-            if (print)
-             print_test_error("\"%s\": Bad uriScheme value \"%s\" - bad "
-                              "characters (RFC 2911 section 4.1.6).",
-                              attr->name, attr->values[i].string.text);
-            else
-             break;
+           add_stringf(errors,
+                       "\"%s\": Bad uriScheme value \"%s\" - bad "
+                       "characters (RFC 2911 section 4.1.6).",
+                       attr->name, attr->values[i].string.text);
          }
 
-         if ((ptr - attr->values[i].string.text) > 63)
+         if ((ptr - attr->values[i].string.text) > (IPP_MAX_URISCHEME - 1))
          {
            valid = 0;
 
-            if (print)
-             print_test_error("\"%s\": Bad uriScheme value \"%s\" - bad "
-                              "length %d (RFC 2911 section 4.1.6).",
-                              attr->name, attr->values[i].string.text,
-                              (int)strlen(attr->values[i].string.text));
-            else
-             break;
+           add_stringf(errors,
+                       "\"%s\": Bad uriScheme value \"%s\" - bad "
+                       "length %d (RFC 2911 section 4.1.6).",
+                       attr->name, attr->values[i].string.text,
+                       (int)strlen(attr->values[i].string.text));
          }
        }
         break;
@@ -3895,25 +5216,21 @@ validate_attr(ipp_attribute_t *attr,    /* I - Attribute to validate */
          {
            valid = 0;
 
-            if (print)
-             print_test_error("\"%s\": Bad charset value \"%s\" - bad "
-                              "characters (RFC 2911 section 4.1.7).",
-                              attr->name, attr->values[i].string.text);
-            else
-             break;
+           add_stringf(errors,
+                       "\"%s\": Bad charset value \"%s\" - bad "
+                       "characters (RFC 2911 section 4.1.7).",
+                       attr->name, attr->values[i].string.text);
          }
 
-         if ((ptr - attr->values[i].string.text) > 40)
+         if ((ptr - attr->values[i].string.text) > (IPP_MAX_CHARSET - 1))
          {
            valid = 0;
 
-            if (print)
-             print_test_error("\"%s\": Bad charset value \"%s\" - bad "
-                              "length %d (RFC 2911 section 4.1.7).",
-                              attr->name, attr->values[i].string.text,
-                              (int)strlen(attr->values[i].string.text));
-            else
-             break;
+           add_stringf(errors,
+                       "\"%s\": Bad charset value \"%s\" - bad "
+                       "length %d (RFC 2911 section 4.1.7).",
+                       attr->name, attr->values[i].string.text,
+                       (int)strlen(attr->values[i].string.text));
          }
        }
         break;
@@ -3946,6 +5263,7 @@ validate_attr(ipp_attribute_t *attr,      /* I - Attribute to validate */
           regerror(i, &re, temp, sizeof(temp));
          print_fatal_error("Unable to compile naturalLanguage regular "
                            "expression: %s.", temp);
+         break;
         }
 
         for (i = 0; i < attr->num_values; i ++)
@@ -3954,25 +5272,21 @@ validate_attr(ipp_attribute_t *attr,    /* I - Attribute to validate */
          {
            valid = 0;
 
-            if (print)
-             print_test_error("\"%s\": Bad naturalLanguage value \"%s\" - bad "
-                              "characters (RFC 2911 section 4.1.8).",
-                              attr->name, attr->values[i].string.text);
-            else
-             break;
+           add_stringf(errors,
+                       "\"%s\": Bad naturalLanguage value \"%s\" - bad "
+                       "characters (RFC 2911 section 4.1.8).",
+                       attr->name, attr->values[i].string.text);
          }
 
-         if (strlen(attr->values[i].string.text) > 63)
+         if (strlen(attr->values[i].string.text) > (IPP_MAX_LANGUAGE - 1))
          {
            valid = 0;
 
-            if (print)
-             print_test_error("\"%s\": Bad naturalLanguage value \"%s\" - bad "
-                              "length %d (RFC 2911 section 4.1.8).",
-                              attr->name, attr->values[i].string.text,
-                              (int)strlen(attr->values[i].string.text));
-            else
-             break;
+           add_stringf(errors,
+                       "\"%s\": Bad naturalLanguage value \"%s\" - bad "
+                       "length %d (RFC 2911 section 4.1.8).",
+                       attr->name, attr->values[i].string.text,
+                       (int)strlen(attr->values[i].string.text));
          }
        }
 
@@ -4002,6 +5316,7 @@ validate_attr(ipp_attribute_t *attr,      /* I - Attribute to validate */
           regerror(i, &re, temp, sizeof(temp));
          print_fatal_error("Unable to compile mimeMediaType regular "
                            "expression: %s.", temp);
+         break;
         }
 
         for (i = 0; i < attr->num_values; i ++)
@@ -4010,27 +5325,25 @@ validate_attr(ipp_attribute_t *attr,    /* I - Attribute to validate */
          {
            valid = 0;
 
-            if (print)
-             print_test_error("\"%s\": Bad mimeMediaType value \"%s\" - bad "
-                              "characters (RFC 2911 section 4.1.9).",
-                              attr->name, attr->values[i].string.text);
-            else
-             break;
+           add_stringf(errors,
+                       "\"%s\": Bad mimeMediaType value \"%s\" - bad "
+                       "characters (RFC 2911 section 4.1.9).",
+                       attr->name, attr->values[i].string.text);
          }
 
-         if (strlen(attr->values[i].string.text) > 255)
+         if (strlen(attr->values[i].string.text) > (IPP_MAX_MIMETYPE - 1))
          {
            valid = 0;
 
-            if (print)
-             print_test_error("\"%s\": Bad mimeMediaType value \"%s\" - bad "
-                              "length %d (RFC 2911 section 4.1.9).",
-                              attr->name, attr->values[i].string.text,
-                              (int)strlen(attr->values[i].string.text));
-            else
-             break;
+           add_stringf(errors,
+                       "\"%s\": Bad mimeMediaType value \"%s\" - bad "
+                       "length %d (RFC 2911 section 4.1.9).",
+                       attr->name, attr->values[i].string.text,
+                       (int)strlen(attr->values[i].string.text));
          }
        }
+
+       regfree(&re);
         break;
 
     default :
@@ -4046,14 +5359,22 @@ validate_attr(ipp_attribute_t *attr,    /* I - Attribute to validate */
  */
 
 static int                             /* O - 1 on match, 0 on non-match */
-with_value(char            *value,     /* I - Value string */
-           int             regex,      /* I - Value is a regular expression */
-           ipp_attribute_t *attr)      /* I - Attribute to compare */
+with_value(cups_array_t    *errors,    /* I - Errors array */
+           char            *value,     /* I - Value string */
+           int             flags,      /* I - Flags for match */
+           ipp_attribute_t *attr,      /* I - Attribute to compare */
+          char            *matchbuf,   /* I - Buffer to hold matching value */
+          size_t          matchlen)    /* I - Length of match buffer */
 {
-  int  i;                              /* Looping var */
-  char *valptr;                        /* Pointer into value */
+  int  i,                              /* Looping var */
+       match;                          /* Match? */
+  char temp[1024],                     /* Temporary value string */
+       *valptr;                        /* Pointer into value */
 
 
+  *matchbuf = '\0';
+  match     = (flags & _CUPS_WITH_ALL) ? 1 : 0;
+
  /*
   * NULL matches everything.
   */
@@ -4073,12 +5394,75 @@ with_value(char            *value,      /* I - Value string */
         {
          char  op,                     /* Comparison operator */
                *nextptr;               /* Next pointer */
-         int   intvalue;               /* Integer value */
+         int   intvalue,               /* Integer value */
+               valmatch = 0;           /* Does the current value match? */
+
+          valptr = value;
+
+         while (isspace(*valptr & 255) || isdigit(*valptr & 255) ||
+                *valptr == '-' || *valptr == ',' || *valptr == '<' ||
+                *valptr == '=' || *valptr == '>')
+         {
+           op = '=';
+           while (*valptr && !isdigit(*valptr & 255) && *valptr != '-')
+           {
+             if (*valptr == '<' || *valptr == '>' || *valptr == '=')
+               op = *valptr;
+             valptr ++;
+           }
+
+            if (!*valptr)
+             break;
+
+           intvalue = (int)strtol(valptr, &nextptr, 0);
+           if (nextptr == valptr)
+             break;
+           valptr = nextptr;
+
+            if ((op == '=' && attr->values[i].integer == intvalue) ||
+                (op == '<' && attr->values[i].integer < intvalue) ||
+                (op == '>' && attr->values[i].integer > intvalue))
+           {
+             if (!matchbuf[0])
+               snprintf(matchbuf, matchlen, "%d", attr->values[i].integer);
+
+             valmatch = 1;
+             break;
+           }
+         }
+
+          if (flags & _CUPS_WITH_ALL)
+          {
+            if (!valmatch)
+            {
+              match = 0;
+              break;
+            }
+          }
+          else if (valmatch)
+          {
+            match = 1;
+            break;
+          }
+        }
+
+        if (!match && errors)
+       {
+         for (i = 0; i < attr->num_values; i ++)
+           add_stringf(errors, "GOT: %s=%d", attr->name,
+                       attr->values[i].integer);
+       }
+       break;
 
+    case IPP_TAG_RANGE :
+        for (i = 0; i < attr->num_values; i ++)
+        {
+         char  op,                     /* Comparison operator */
+               *nextptr;               /* Next pointer */
+         int   intvalue,               /* Integer value */
+               valmatch = 0;           /* Does the current value match? */
 
           valptr = value;
-         if (!strncmp(valptr, "no-value,", 9))
-           valptr += 9;
 
          while (isspace(*valptr & 255) || isdigit(*valptr & 255) ||
                 *valptr == '-' || *valptr == ',' || *valptr == '<' ||
@@ -4095,40 +5479,139 @@ with_value(char            *value,     /* I - Value string */
             if (!*valptr)
              break;
 
-           intvalue = strtol(valptr, &nextptr, 0);
+           intvalue = (int)strtol(valptr, &nextptr, 0);
            if (nextptr == valptr)
              break;
            valptr = nextptr;
 
-           switch (op)
+            if ((op == '=' && (attr->values[i].range.lower == intvalue ||
+                              attr->values[i].range.upper == intvalue)) ||
+               (op == '<' && attr->values[i].range.upper < intvalue) ||
+               (op == '>' && attr->values[i].range.upper > intvalue))
            {
-             case '=' :
-                 if (attr->values[i].integer == intvalue)
-                   return (1);
-                 break;
-             case '<' :
-                 if (attr->values[i].integer < intvalue)
-                   return (1);
-                 break;
-             case '>' :
-                 if (attr->values[i].integer > intvalue)
-                   return (1);
-                 break;
+             if (!matchbuf[0])
+               snprintf(matchbuf, matchlen, "%d-%d",
+                        attr->values[0].range.lower,
+                        attr->values[0].range.upper);
+
+             valmatch = 1;
+             break;
            }
          }
+
+          if (flags & _CUPS_WITH_ALL)
+          {
+            if (!valmatch)
+            {
+              match = 0;
+              break;
+            }
+          }
+          else if (valmatch)
+          {
+            match = 1;
+            break;
+          }
         }
+
+        if (!match && errors)
+       {
+         for (i = 0; i < attr->num_values; i ++)
+           add_stringf(errors, "GOT: %s=%d-%d", attr->name,
+                            attr->values[i].range.lower,
+                            attr->values[i].range.upper);
+       }
        break;
 
     case IPP_TAG_BOOLEAN :
        for (i = 0; i < attr->num_values; i ++)
        {
           if (!strcmp(value, "true") == attr->values[i].boolean)
-           return (1);
+          {
+            if (!matchbuf[0])
+             strlcpy(matchbuf, value, matchlen);
+
+           if (!(flags & _CUPS_WITH_ALL))
+           {
+             match = 1;
+             break;
+           }
+         }
+         else if (flags & _CUPS_WITH_ALL)
+         {
+           match = 0;
+           break;
+         }
+       }
+
+       if (!match && errors)
+       {
+         for (i = 0; i < attr->num_values; i ++)
+           add_stringf(errors, "GOT: %s=%s", attr->name,
+                            attr->values[i].boolean ? "true" : "false");
+       }
+       break;
+
+    case IPP_TAG_RESOLUTION :
+       for (i = 0; i < attr->num_values; i ++)
+       {
+         if (attr->values[i].resolution.xres ==
+                 attr->values[i].resolution.yres)
+           snprintf(temp, sizeof(temp), "%d%s",
+                    attr->values[i].resolution.xres,
+                    attr->values[i].resolution.units == IPP_RES_PER_INCH ?
+                        "dpi" : "dpcm");
+         else
+           snprintf(temp, sizeof(temp), "%dx%d%s",
+                    attr->values[i].resolution.xres,
+                    attr->values[i].resolution.yres,
+                    attr->values[i].resolution.units == IPP_RES_PER_INCH ?
+                        "dpi" : "dpcm");
+
+          if (!strcmp(value, temp))
+          {
+            if (!matchbuf[0])
+             strlcpy(matchbuf, value, matchlen);
+
+           if (!(flags & _CUPS_WITH_ALL))
+           {
+             match = 1;
+             break;
+           }
+         }
+         else if (flags & _CUPS_WITH_ALL)
+         {
+           match = 0;
+           break;
+         }
+       }
+
+       if (!match && errors)
+       {
+         for (i = 0; i < attr->num_values; i ++)
+         {
+           if (attr->values[i].resolution.xres ==
+                   attr->values[i].resolution.yres)
+             snprintf(temp, sizeof(temp), "%d%s",
+                      attr->values[i].resolution.xres,
+                      attr->values[i].resolution.units == IPP_RES_PER_INCH ?
+                          "dpi" : "dpcm");
+           else
+             snprintf(temp, sizeof(temp), "%dx%d%s",
+                      attr->values[i].resolution.xres,
+                      attr->values[i].resolution.yres,
+                      attr->values[i].resolution.units == IPP_RES_PER_INCH ?
+                          "dpi" : "dpcm");
+
+            if (strcmp(value, temp))
+             add_stringf(errors, "GOT: %s=%s", attr->name, temp);
+         }
        }
        break;
 
     case IPP_TAG_NOVALUE :
-        return (!strcmp(value, "no-value") || !strncmp(value, "no-value,", 9));
+    case IPP_TAG_UNKNOWN :
+       return (1);
 
     case IPP_TAG_CHARSET :
     case IPP_TAG_KEYWORD :
@@ -4140,7 +5623,7 @@ with_value(char            *value,        /* I - Value string */
     case IPP_TAG_TEXTLANG :
     case IPP_TAG_URI :
     case IPP_TAG_URISCHEME :
-        if (regex)
+        if (flags & _CUPS_WITH_REGEX)
        {
         /*
          * Value is an extended, case-sensitive POSIX regular expression...
@@ -4150,8 +5633,6 @@ with_value(char            *value,        /* I - Value string */
 
           if ((i = regcomp(&re, value, REG_EXTENDED | REG_NOSUB)) != 0)
          {
-           char temp[256];             /* Temporary string */
-
             regerror(i, &re, temp, sizeof(temp));
 
            print_fatal_error("Unable to compile WITH-VALUE regular expression "
@@ -4165,34 +5646,71 @@ with_value(char            *value,      /* I - Value string */
 
          for (i = 0; i < attr->num_values; i ++)
          {
-           if (regexec(&re, attr->values[i].string.text, 0, NULL, 0))
+           if (!regexec(&re, get_string(attr, i, flags, temp, sizeof(temp)),
+                        0, NULL, 0))
+           {
+             if (!matchbuf[0])
+               strlcpy(matchbuf,
+                       get_string(attr, i, flags, temp, sizeof(temp)),
+                       matchlen);
+
+             if (!(flags & _CUPS_WITH_ALL))
+             {
+               match = 1;
+               break;
+             }
+           }
+           else if (flags & _CUPS_WITH_ALL)
+           {
+             match = 0;
              break;
+           }
          }
 
          regfree(&re);
-
-          return (i == attr->num_values);
        }
        else
        {
         /*
-         * Value is a literal string, see if at least one value matches the
-         * literal string...
+         * Value is a literal string, see if the value(s) match...
          */
 
          for (i = 0; i < attr->num_values; i ++)
          {
-           if (!strcmp(value, attr->values[i].string.text))
-             return (1);
+           if (!strcmp(value, get_string(attr, i, flags, temp, sizeof(temp))))
+           {
+             if (!matchbuf[0])
+               strlcpy(matchbuf,
+                       get_string(attr, i, flags, temp, sizeof(temp)),
+                       matchlen);
+
+             if (!(flags & _CUPS_WITH_ALL))
+             {
+               match = 1;
+               break;
+             }
+           }
+           else if (flags & _CUPS_WITH_ALL)
+           {
+             match = 0;
+             break;
+           }
          }
        }
+
+        if (!match && errors)
+        {
+         for (i = 0; i < attr->num_values; i ++)
+           add_stringf(errors, "GOT: %s=\"%s\"", attr->name,
+                       attr->values[i].string.text);
+        }
        break;
 
     default :
         break;
   }
 
-  return (0);
+  return (match);
 }