]> git.ipfire.org Git - thirdparty/cups.git/blobdiff - test/ipptest.c
Load cups into easysw/current.
[thirdparty/cups.git] / test / ipptest.c
index 199ebe44f618304ae5c014b59b9d618bc35228f2..e0030ae55bd85eab12d23c9f34c6e836b233650d 100644 (file)
@@ -1,25 +1,16 @@
 /*
- * "$Id: ipptest.c 5037 2006-02-01 15:19:59Z mike $"
+ * "$Id: ipptest.c 6649 2007-07-11 21:46:42Z mike $"
  *
  *   IPP test command for the Common UNIX Printing System (CUPS).
  *
- *   Copyright 1997-2006 by Easy Software Products.
+ *   Copyright 2007 by Apple Inc.
+ *   Copyright 1997-2007 by Easy Software Products.
  *
  *   These coded instructions, statements, and computer programs are the
- *   property of Easy Software Products 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 missing or damaged please contact Easy Software Products
- *   at:
- *
- *       Attn: CUPS Licensing Information
- *       Easy Software Products
- *       44141 Airport View Drive, Suite 204
- *       Hollywood, Maryland 20636 USA
- *
- *       Voice: (301) 373-9600
- *       EMail: cups-info@cups.org
- *         WWW: http://www.cups.org
+ *   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:
  *
  * Globals...
  */
 
-int    Verbosity = 0;                  /* Show all attributes? */
+int            Verbosity = 0;          /* Show all attributes? */
+const char     * const TagNames[] =
+               {                       /* Value/group tag names */
+                 "zero",               /* 0x00 */
+                 "operation",          /* 0x01 */
+                 "job",                /* 0x02 */
+                 "end",                /* 0x03 */
+                 "printer",            /* 0x04 */
+                 "unsupported-group",  /* 0x05 */
+                 "subscription",       /* 0x06 */
+                 "event-notification", /* 0x07 */
+                 "", "", "", "", "", "", "", "",
+                 "unsupported-value",  /* 0x10 */
+                 "default",            /* 0x11 */
+                 "unknown",            /* 0x12 */
+                 "novalue",            /* 0x13 */
+                 "",
+                 "notsettable",        /* 0x15 */
+                 "deleteattr",         /* 0x16 */
+                 "anyvalue",           /* 0x17 */
+                 "", "", "", "", "", "", "", "", "",
+                 "integer",            /* 0x21 */
+                 "boolean",            /* 0x22 */
+                 "enum",               /* 0x23 */
+                 "", "", "", "", "", "", "", "", "", "", "", "",
+                 "string",             /* 0x30 */
+                 "date",               /* 0x31 */
+                 "resolution",         /* 0x32 */
+                 "range",              /* 0x33 */
+                 "collection",         /* 0x34 */
+                 "textlang",           /* 0x35 */
+                 "namelang",           /* 0x36 */
+                 "", "", "", "", "", "", "", "", "", "",
+                 "text",               /* 0x41 */
+                 "name",               /* 0x42 */
+                 "",
+                 "keyword",            /* 0x44 */
+                 "uri",                /* 0x45 */
+                 "urischeme",          /* 0x46 */
+                 "charset",            /* 0x47 */
+                 "language",           /* 0x48 */
+                 "mimetype"            /* 0x49 */
+               };
+
+
 
 
 /*
@@ -60,6 +95,7 @@ int           do_tests(const char *, const char *);
 ipp_op_t       ippOpValue(const char *);
 ipp_status_t   ippErrorValue(const char *);
 ipp_tag_t      get_tag(const char *);
+const char     *get_tag_string(ipp_tag_t tag);
 char           *get_token(FILE *, char *, int, int *linenum);
 void           print_attr(ipp_attribute_t *);
 void           usage(const char *option);
@@ -77,6 +113,7 @@ main(int  argc,                              /* I - Number of command-line arguments */
   int          status;                 /* Status of tests... */
   const char   *uri;                   /* URI to use */
   const char   *testfile;              /* Test file to use */
+  int          interval;               /* Test interval */
 
 
  /*
@@ -88,6 +125,7 @@ main(int  argc,                              /* I - Number of command-line arguments */
   uri      = NULL;
   testfile = NULL;
   status   = 0;
+  interval = 0;
 
   for (i = 1; i < argc; i ++)
   {
@@ -95,6 +133,24 @@ main(int  argc,                             /* I - Number of command-line arguments */
     {
       if (!strcmp(argv[i], "-v"))
         Verbosity ++;
+      else if (!strcmp(argv[i], "-d"))
+      {
+        i ++;
+
+       if (i >= argc)
+         usage(NULL);
+       else
+         putenv(argv[i]);
+      }
+      else if (!strcmp(argv[i], "-i"))
+      {
+        i++;
+
+       if (i >= argc)
+         usage(NULL);
+       else
+         interval = atoi(argv[i]);
+      }
       else
         usage(argv[i]);
     }
@@ -128,6 +184,19 @@ main(int  argc,                            /* I - Number of command-line arguments */
   if (!uri || !testfile)
     usage(NULL);
 
+ /*
+  * Loop if the interval is set...
+  */
+
+  if (interval)
+  {
+    for (;;)
+    {
+      sleep(interval);
+      do_tests(uri, testfile);
+    }
+  }
+
  /*
   * Exit...
   */
@@ -385,9 +454,28 @@ do_tests(const char *uri,          /* I - URI to connect on */
              strlcpy(tokenptr, cupsUser(), sizeof(token) - (tokenptr - token));
              tempptr += 5;
            }
+           else if (!strncasecmp(tempptr + 1, "ENV[", 4))
+           {
+             char *end;                /* End of $ENV[name] */
+
+
+             if ((end = strchr(tempptr + 5, ']')) != NULL)
+             {
+               *end++ = '\0';
+               strlcpy(tokenptr,
+                       getenv(tempptr + 5) ? getenv(tempptr + 5) : tempptr + 5,
+                       sizeof(token) - (tokenptr - token));
+               tempptr = end;
+             }
+             else
+             {
+               *tokenptr++ = *tempptr++;
+               *tokenptr   = '\0';
+             }
+           }
             else
            {
-             *tokenptr++ = *tempptr ++;
+             *tokenptr++ = *tempptr++;
              *tokenptr   = '\0';
            }
 
@@ -510,10 +598,13 @@ do_tests(const char *uri,         /* I - URI to connect on */
     request->request.op.operation_id = op;
     request->request.op.request_id   = 1;
 
-#ifdef DEBUG
-    for (attrptr = request->attrs; attrptr; attrptr = attrptr->next)
-      print_attr(attrptr);
-#endif /* DEBUG */
+    if (Verbosity)
+    {
+      printf("%s:\n", ippOpString(op));
+
+      for (attrptr = request->attrs; attrptr; attrptr = attrptr->next)
+       print_attr(attrptr);
+    }
 
     printf("    %-60.60s [", name);
     fflush(stdout);
@@ -521,7 +612,8 @@ do_tests(const char *uri,           /* I - URI to connect on */
     if (filename[0])
       response = cupsDoFileRequest(http, request, resource, filename);
     else
-      response = cupsDoRequest(http, request, resource);
+      response = cupsDoIORequest(http, request, resource, -1,
+                                 Verbosity ? 1 : -1);
 
     if (response == NULL)
     {
@@ -531,7 +623,7 @@ do_tests(const char *uri,           /* I - URI to connect on */
 
       puts("FAIL]");
       printf("        ERROR %04x (%s) @ %s\n", cupsLastError(),
-            ippErrorString(cupsLastError()), ctime(&curtime));
+            cupsLastErrorString(), ctime(&curtime));
       pass = 0;
     }
     else
@@ -599,8 +691,7 @@ do_tests(const char *uri,           /* I - URI to connect on */
          puts("        BAD STATUS");
 
        printf("        status-code = %04x (%s)\n",
-              response->request.status.status_code,
-              ippErrorString(response->request.status.status_code));
+              cupsLastError(), ippErrorString(cupsLastError()));
 
         for (i = 0; i < num_expects; i ++)
          if (ippFindAttribute(response, expects[i], IPP_TAG_ZERO) == NULL)
@@ -635,31 +726,30 @@ ipp_tag_t                         /* O - Value/group tag */
 get_tag(const char *name)              /* I - Name of value/group tag */
 {
   int                  i;              /* Looping var */
-  static const char    * const names[] =
-               {                       /* Value/group tag names */
-                 "zero", "operation", "job", "end", "printer",
-                 "unsupported-group", "subscription", "event-notification",
-                 "", "", "", "", "",
-                 "", "", "", "unsupported-value", "default",
-                 "unknown", "novalue", "", "notsettable",
-                 "deleteattr", "anyvalue", "", "", "", "", "", "",
-                 "", "", "", "integer", "boolean", "enum", "", "",
-                 "", "", "", "", "", "", "", "", "", "", "string",
-                 "date", "resolution", "range", "collection",
-                 "textlang", "namelang", "", "", "", "", "", "", "",
-                 "", "", "", "text", "name", "", "keyword", "uri",
-                 "urischeme", "charset", "language", "mimetype"
-               };
 
 
-  for (i = 0; i < (sizeof(names) / sizeof(names[0])); i ++)
-    if (!strcasecmp(name, names[i]))
+  for (i = 0; i < (sizeof(TagNames) / sizeof(TagNames[0])); i ++)
+    if (!strcasecmp(name, TagNames[i]))
       return ((ipp_tag_t)i);
 
   return (IPP_TAG_ZERO);
 }
 
 
+/*
+ * 'get_tag_string()' - Get the string associated with a tag.
+ */
+
+const char *                           /* O - Tag name string */
+get_tag_string(ipp_tag_t tag)          /* I - IPP tag */
+{
+  if (tag < (ipp_tag_t)(sizeof(TagNames) / sizeof(TagNames[0])))
+    return (TagNames[tag]);
+  else
+    return ("UNKNOWN");
+}
+
+
 /*
  * 'get_token()' - Get a token from a file.
  */
@@ -768,7 +858,9 @@ print_attr(ipp_attribute_t *attr)   /* I - Attribute to print */
     return;
   }
 
-  printf("        %s = ", attr->name);
+  printf("        %s (%s%s) = ", attr->name,
+         attr->num_values > 1 ? "1setOf " : "",
+        get_tag_string(attr->value_tag));
 
   switch (attr->value_tag)
   {
@@ -844,12 +936,13 @@ usage(const char *option)         /* I - Option string or NULL */
   fputs("Usage: ipptest [options] URL testfile [ ... testfileN ]\n", stderr);
   fputs("Options:\n", stderr);
   fputs("\n", stderr);
-  fputs("-v     Show all attributes in response, even on success.\n", stderr);
+  fputs("-i N    Repeat the last test file once every N seconds.\n", stderr);
+  fputs("-v      Show all attributes in response, even on success.\n", stderr);
 
   exit(1);
 }
 
 
 /*
- * End of "$Id: ipptest.c 5037 2006-02-01 15:19:59Z mike $".
+ * End of "$Id: ipptest.c 6649 2007-07-11 21:46:42Z mike $".
  */