]> git.ipfire.org Git - thirdparty/cups.git/blobdiff - test/ipptest.c
Load cups into easysw/current.
[thirdparty/cups.git] / test / ipptest.c
index fa73d0fcc5cc53fc16aa5fd34399c72911d30842..98843ff6c3e8f1c565a07e42241373008b6d9cc9 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * "$Id: ipptest.c 5023 2006-01-29 14:39:44Z mike $"
+ * "$Id: ipptest.c 5414 2006-04-17 20:07:24Z mike $"
  *
  *   IPP test command for the Common UNIX Printing System (CUPS).
  *
  *
  * Contents:
  *
- *   main()          - Parse options and do tests.
- *   do_tests()      - Do tests as specified in the test file.
- *   get_tag()       - Get an IPP value or group tag from a name...
- *   get_token()     - Get a token from a file.
- *   print_attr()    - Print an attribute on the screen.
+ *   main()       - Parse options and do tests.
+ *   do_tests()   - Do tests as specified in the test file.
+ *   get_tag()    - Get an IPP value or group tag from a name...
+ *   get_token()  - Get a token from a file.
+ *   print_attr() - Print an attribute on the screen.
+ *   usage()      - Show program usage.
  */
 
 /*
 #include <cups/language.h>
 
 
+/*
+ * Globals...
+ */
+
+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 */
+               };
+
+
+
+
 /*
  * Local functions...
  */
@@ -52,8 +104,10 @@ 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);
 
 
 /*
@@ -66,6 +120,8 @@ main(int  argc,                              /* I - Number of command-line arguments */
 {
   int          i;                      /* Looping var */
   int          status;                 /* Status of tests... */
+  const char   *uri;                   /* URI to use */
+  const char   *testfile;              /* Test file to use */
 
 
  /*
@@ -74,24 +130,54 @@ main(int  argc,                            /* I - Number of command-line arguments */
   *     testipp URL testfile
   */
 
-  if (argc < 3)
+  uri      = NULL;
+  testfile = NULL;
+  status   = 0;
+
+  for (i = 1; i < argc; i ++)
   {
-    fputs("Usage: ipptest URL testfile [ ... testfileN ]\n", stderr);
-    return (1);
-  }
+    if (argv[i][0] == '-')
+    {
+      if (!strcmp(argv[i], "-v"))
+        Verbosity ++;
+      else
+        usage(argv[i]);
+    }
+    else if (!strncmp(argv[i], "ipp://", 6) ||
+             !strncmp(argv[i], "http://", 7) ||
+             !strncmp(argv[i], "https://", 8))
+    {
+     /*
+      * Set URI...
+      */
 
- /*
-  * Run tests...
-  */
+      if (!testfile && uri)
+        usage(NULL);
+
+      uri      = argv[i];
+      testfile = NULL;
+    }
+    else
+    {
+     /*
+      * Run test...
+      */
+
+      testfile = argv[i];
+
+      if (!do_tests(uri, testfile))
+        status ++;
+    }
+  }
 
-  for (i = 2, status = 1; status && i < argc; i ++)
-    status = status && do_tests(argv[1], argv[i]);
+  if (!uri || !testfile)
+    usage(NULL);
 
  /*
   * Exit...
   */
 
-  return (!status);
+  return (status);
 }
 
 
@@ -469,10 +555,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);
@@ -490,7 +579,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
@@ -525,7 +614,12 @@ do_tests(const char *uri,          /* I - URI to connect on */
        printf("        RECEIVED: %lu bytes in response\n",
               (unsigned long)ippLength(response));
 
-        if (num_displayed > 0)
+        if (Verbosity)
+       {
+         for (attrptr = response->attrs; attrptr != NULL; attrptr = attrptr->next)
+           print_attr(attrptr);
+        }
+        else if (num_displayed > 0)
        {
          for (attrptr = response->attrs; attrptr != NULL; attrptr = attrptr->next)
            if (attrptr->name)
@@ -553,8 +647,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(), cupsLastErrorString());
 
         for (i = 0; i < num_expects; i ++)
          if (ippFindAttribute(response, expects[i], IPP_TAG_ZERO) == NULL)
@@ -589,31 +682,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.
  */
@@ -722,7 +814,7 @@ print_attr(ipp_attribute_t *attr)   /* I - Attribute to print */
     return;
   }
 
-  printf("        %s = ", attr->name);
+  printf("        %s (%s) = ", attr->name, get_tag_string(attr->value_tag));
 
   switch (attr->value_tag)
   {
@@ -786,5 +878,24 @@ print_attr(ipp_attribute_t *attr)  /* I - Attribute to print */
 
 
 /*
- * End of "$Id: ipptest.c 5023 2006-01-29 14:39:44Z mike $".
+ * 'usage()' - Show program usage.
+ */
+
+void
+usage(const char *option)              /* I - Option string or NULL */
+{
+  if (option)
+    fprintf(stderr, "ipptest: Unknown option \"%s\"!\n", option);
+
+  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);
+
+  exit(1);
+}
+
+
+/*
+ * End of "$Id: ipptest.c 5414 2006-04-17 20:07:24Z mike $".
  */