]> git.ipfire.org Git - thirdparty/cups.git/blobdiff - cups/testipp.c
License change: Apache License, Version 2.0.
[thirdparty/cups.git] / cups / testipp.c
index 70c83bf4b5e36079b712b16a93a803dbda6d4e72..39585f1d83898023fb2f584e1970c9c9336ca7d9 100644 (file)
@@ -1,26 +1,10 @@
 /*
- * "$Id: testipp.c 6649 2007-07-11 21:46:42Z mike $"
+ * IPP test program for CUPS.
  *
- *   IPP test program for CUPS.
+ * Copyright 2007-2017 by Apple Inc.
+ * Copyright 1997-2005 by Easy Software Products.
  *
- *   Copyright 2007-2011 by Apple Inc.
- *   Copyright 1997-2005 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/".
- *
- *   This file is subject to the Apple OS-Developed Software exception.
- *
- * Contents:
- *
- *   main()             - Main entry.
- *   hex_dump()         - Produce a hex dump of a buffer.
- *   print_attributes() - Print the attributes in a request...
- *   read_cb()          - Read data from a buffer.
- *   write_cb()         - Write data into a buffer.
+ * Licensed under Apache License v2.0.  See the file "LICENSE" for more information.
  */
 
 /*
@@ -55,7 +39,7 @@ typedef struct _ippdata_t
  * Local globals...
  */
 
-ipp_uchar_t    collection[] =          /* Collection buffer */
+static ipp_uchar_t collection[] =      /* Collection buffer */
                {
                  0x01, 0x01,           /* IPP version */
                  0x00, 0x02,           /* Print-Job operation */
@@ -205,7 +189,7 @@ ipp_uchar_t collection[] =          /* Collection buffer */
                  IPP_TAG_END           /* end tag */
                };
 
-ipp_uchar_t    mixed[] =               /* Mixed value buffer */
+static ipp_uchar_t mixed[] =           /* Mixed value buffer */
                {
                  0x01, 0x01,           /* IPP version */
                  0x00, 0x02,           /* Print-Job operation */
@@ -236,7 +220,7 @@ ipp_uchar_t mixed[] =               /* Mixed value buffer */
  * Local functions...
  */
 
-void   hex_dump(const char *title, ipp_uchar_t *buffer, int bytes);
+void   hex_dump(const char *title, ipp_uchar_t *buffer, size_t bytes);
 void   print_attributes(ipp_t *ipp, int indent);
 ssize_t        read_cb(_ippdata_t *data, ipp_uchar_t *buffer, size_t bytes);
 ssize_t        write_cb(_ippdata_t *data, ipp_uchar_t *buffer, size_t bytes);
@@ -259,10 +243,13 @@ main(int  argc,                   /* I - Number of command-line arguments */
                *media_size,    /* media-size attribute */
                *attr;          /* Other attribute */
   ipp_state_t  state;          /* State */
-  int          length;         /* Length of data */
+  size_t       length;         /* Length of data */
   cups_file_t  *fp;            /* File pointer */
-  int          i;              /* Looping var */
+  size_t       i;              /* Looping var */
   int          status;         /* Status of tests (0 = success, 1 = fail) */
+#ifdef DEBUG
+  const char   *name;          /* Option name */
+#endif /* DEBUG */
 
 
   status = 0;
@@ -278,7 +265,7 @@ main(int  argc,                     /* I - Number of command-line arguments */
     request = ippNew();
     request->request.op.version[0]   = 0x01;
     request->request.op.version[1]   = 0x01;
-    request->request.op.operation_id = IPP_PRINT_JOB;
+    request->request.op.operation_id = IPP_OP_PRINT_JOB;
     request->request.op.request_id   = 1;
 
     ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_CHARSET,
@@ -319,7 +306,7 @@ main(int  argc,                     /* I - Number of command-line arguments */
     if (length != sizeof(collection))
     {
       printf("FAIL - wrong ippLength(), %d instead of %d bytes!\n",
-             length, (int)sizeof(collection));
+             (int)length, (int)sizeof(collection));
       status = 1;
     }
     else
@@ -336,11 +323,11 @@ main(int  argc,                   /* I - Number of command-line arguments */
     data.wbuffer = buffer;
 
     while ((state = ippWriteIO(&data, (ipp_iocb_t)write_cb, 1, NULL,
-                               request)) != IPP_DATA)
-      if (state == IPP_ERROR)
+                               request)) != IPP_STATE_DATA)
+      if (state == IPP_STATE_ERROR)
        break;
 
-    if (state != IPP_DATA)
+    if (state != IPP_STATE_DATA)
     {
       printf("FAIL - %d bytes written.\n", (int)data.wused);
       status = 1;
@@ -359,7 +346,7 @@ main(int  argc,                     /* I - Number of command-line arguments */
         if (data.wbuffer[i] != collection[i])
          break;
 
-      printf("FAIL - output does not match baseline at 0x%04x!\n", i);
+      printf("FAIL - output does not match baseline at 0x%04x!\n", (unsigned)i);
       hex_dump("Bytes Written", data.wbuffer, data.wused);
       hex_dump("Baseline", collection, sizeof(collection));
       status = 1;
@@ -379,13 +366,13 @@ main(int  argc,                   /* I - Number of command-line arguments */
     data.rpos = 0;
 
     while ((state = ippReadIO(&data, (ipp_iocb_t)read_cb, 1, NULL,
-                              request)) != IPP_DATA)
-      if (state == IPP_ERROR)
+                              request)) != IPP_STATE_DATA)
+      if (state == IPP_STATE_ERROR)
        break;
 
     length = ippLength(request);
 
-    if (state != IPP_DATA)
+    if (state != IPP_STATE_DATA)
     {
       printf("FAIL - %d bytes read.\n", (int)data.rpos);
       status = 1;
@@ -400,7 +387,7 @@ main(int  argc,                     /* I - Number of command-line arguments */
     else if (length != sizeof(collection))
     {
       printf("FAIL - wrong ippLength(), %d instead of %d bytes!\n",
-             length, (int)sizeof(collection));
+             (int)length, (int)sizeof(collection));
       print_attributes(request, 8);
       status = 1;
     }
@@ -547,6 +534,53 @@ main(int  argc,                    /* I - Number of command-line arguments */
       }
     }
 
+   /*
+    * Test hierarchical find...
+    */
+
+    fputs("ippFindAttribute(media-col/media-size/x-dimension): ", stdout);
+    if ((attr = ippFindAttribute(request, "media-col/media-size/x-dimension", IPP_TAG_INTEGER)) != NULL)
+    {
+      if (ippGetInteger(attr, 0) != 21590)
+      {
+        printf("FAIL (wrong value for x-dimension - %d)\n", ippGetInteger(attr, 0));
+        status = 1;
+      }
+      else
+        puts("PASS");
+    }
+    else
+    {
+      puts("FAIL (not found)");
+      status = 1;
+    }
+
+    fputs("ippFindNextAttribute(media-col/media-size/x-dimension): ", stdout);
+    if ((attr = ippFindNextAttribute(request, "media-col/media-size/x-dimension", IPP_TAG_INTEGER)) != NULL)
+    {
+      if (ippGetInteger(attr, 0) != 21000)
+      {
+        printf("FAIL (wrong value for x-dimension - %d)\n", ippGetInteger(attr, 0));
+        status = 1;
+      }
+      else
+        puts("PASS");
+    }
+    else
+    {
+      puts("FAIL (not found)");
+      status = 1;
+    }
+
+    fputs("ippFindNextAttribute(media-col/media-size/x-dimension) again: ", stdout);
+    if ((attr = ippFindNextAttribute(request, "media-col/media-size/x-dimension", IPP_TAG_INTEGER)) != NULL)
+    {
+      printf("FAIL (got %d, expected nothing)\n", ippGetInteger(attr, 0));
+      status = 1;
+    }
+    else
+      puts("PASS");
+
     ippDelete(request);
 
    /*
@@ -563,13 +597,13 @@ main(int  argc,                   /* I - Number of command-line arguments */
     data.wbuffer = mixed;
 
     while ((state = ippReadIO(&data, (ipp_iocb_t)read_cb, 1, NULL,
-                              request)) != IPP_DATA)
-      if (state == IPP_ERROR)
+                              request)) != IPP_STATE_DATA)
+      if (state == IPP_STATE_ERROR)
        break;
 
     length = ippLength(request);
 
-    if (state != IPP_DATA)
+    if (state != IPP_STATE_DATA)
     {
       printf("FAIL - %d bytes read.\n", (int)data.rpos);
       status = 1;
@@ -584,7 +618,7 @@ main(int  argc,                     /* I - Number of command-line arguments */
     else if (length != (sizeof(mixed) + 4))
     {
       printf("FAIL - wrong ippLength(), %d instead of %d bytes!\n",
-             length, (int)sizeof(mixed) + 4);
+             (int)length, (int)sizeof(mixed) + 4);
       print_attributes(request, 8);
       status = 1;
     }
@@ -625,11 +659,26 @@ main(int  argc,                   /* I - Number of command-line arguments */
 
     ippDelete(request);
 
+#ifdef DEBUG
+   /*
+    * Test that private option array is sorted...
+    */
+
+    fputs("_ippCheckOptions: ", stdout);
+    if ((name = _ippCheckOptions()) == NULL)
+      puts("PASS");
+    else
+    {
+      printf("FAIL (\"%s\" out of order)\n", name);
+      status = 1;
+    }
+#endif /* DEBUG */
+
    /*
     * Test _ippFindOption() private API...
     */
 
-    fputs("_ippFindOption(printer-type): ", stdout);
+    fputs("_ippFindOption(\"printer-type\"): ", stdout);
     if (_ippFindOption("printer-type"))
       puts("PASS");
     else
@@ -655,7 +704,7 @@ main(int  argc,                     /* I - Number of command-line arguments */
     * Read IPP files...
     */
 
-    for (i = 1; i < argc; i ++)
+    for (i = 1; i < (size_t)argc; i ++)
     {
       if ((fp = cupsFileOpen(argv[i], "r")) == NULL)
       {
@@ -666,9 +715,9 @@ main(int  argc,                     /* I - Number of command-line arguments */
 
       request = ippNew();
       while ((state = ippReadIO(fp, (ipp_iocb_t)cupsFileRead, 1, NULL,
-                                request)) == IPP_ATTRIBUTE);
+                                request)) == IPP_STATE_ATTRIBUTE);
 
-      if (state != IPP_DATA)
+      if (state != IPP_STATE_DATA)
       {
        printf("Error reading IPP message from \"%s\"!\n", argv[i]);
        status = 1;
@@ -695,10 +744,10 @@ main(int  argc,                   /* I - Number of command-line arguments */
 void
 hex_dump(const char  *title,           /* I - Title */
          ipp_uchar_t *buffer,          /* I - Buffer to dump */
-         int         bytes)            /* I - Number of bytes */
+         size_t      bytes)            /* I - Number of bytes */
 {
-  int  i, j;                           /* Looping vars */
-  int  ch;                             /* Current ASCII char */
+  size_t       i, j;                   /* Looping vars */
+  int          ch;                     /* Current ASCII char */
 
 
  /*
@@ -713,7 +762,7 @@ hex_dump(const char  *title,                /* I - Title */
     * Show the offset...
     */
 
-    printf("    %04x ", i);
+    printf("    %04x ", (unsigned)i);
 
    /*
     * Then up to 16 bytes in hex...
@@ -755,88 +804,9 @@ void
 print_attributes(ipp_t *ipp,           /* I - IPP request */
                  int   indent)         /* I - Indentation */
 {
-  int                  i;              /* Looping var */
   ipp_tag_t            group;          /* Current group */
   ipp_attribute_t      *attr;          /* Current attribute */
-  _ipp_value_t         *val;           /* Current value */
-  static const char * const tags[] =   /* Value/group tag strings */
-                       {
-                         "reserved-00",
-                         "operation-attributes-tag",
-                         "job-attributes-tag",
-                         "end-of-attributes-tag",
-                         "printer-attributes-tag",
-                         "unsupported-attributes-tag",
-                         "subscription-attributes-tag",
-                         "event-attributes-tag",
-                         "reserved-08",
-                         "reserved-09",
-                         "reserved-0A",
-                         "reserved-0B",
-                         "reserved-0C",
-                         "reserved-0D",
-                         "reserved-0E",
-                         "reserved-0F",
-                         "unsupported",
-                         "default",
-                         "unknown",
-                         "no-value",
-                         "reserved-14",
-                         "not-settable",
-                         "delete-attr",
-                         "admin-define",
-                         "reserved-18",
-                         "reserved-19",
-                         "reserved-1A",
-                         "reserved-1B",
-                         "reserved-1C",
-                         "reserved-1D",
-                         "reserved-1E",
-                         "reserved-1F",
-                         "reserved-20",
-                         "integer",
-                         "boolean",
-                         "enum",
-                         "reserved-24",
-                         "reserved-25",
-                         "reserved-26",
-                         "reserved-27",
-                         "reserved-28",
-                         "reserved-29",
-                         "reserved-2a",
-                         "reserved-2b",
-                         "reserved-2c",
-                         "reserved-2d",
-                         "reserved-2e",
-                         "reserved-2f",
-                         "octetString",
-                         "dateTime",
-                         "resolution",
-                         "rangeOfInteger",
-                         "begCollection",
-                         "textWithLanguage",
-                         "nameWithLanguage",
-                         "endCollection",
-                         "reserved-38",
-                         "reserved-39",
-                         "reserved-3a",
-                         "reserved-3b",
-                         "reserved-3c",
-                         "reserved-3d",
-                         "reserved-3e",
-                         "reserved-3f",
-                         "reserved-40",
-                         "textWithoutLanguage",
-                         "nameWithoutLanguage",
-                         "reserved-43",
-                         "keyword",
-                         "uri",
-                         "uriScheme",
-                         "charset",
-                         "naturalLanguage",
-                         "mimeMediaType",
-                         "memberName"
-                       };
+  char                  buffer[2048];   /* Value string */
 
 
   for (group = IPP_TAG_ZERO, attr = ipp->attrs; attr; attr = attr->next)
@@ -852,90 +822,12 @@ print_attributes(ipp_t *ipp,              /* I - IPP request */
     {
       group = attr->group_tag;
 
-      printf("\n%*s%s:\n\n", indent - 4, "", tags[group]);
+      printf("\n%*s%s:\n\n", indent - 4, "", ippTagString(group));
     }
 
-    printf("%*s%s (", indent, "", attr->name ? attr->name : "(null)");
-    if (attr->num_values > 1)
-      printf("1setOf ");
-    printf("%s):", tags[attr->value_tag]);
+    ippAttributeString(attr, buffer, sizeof(buffer));
 
-    switch (attr->value_tag)
-    {
-      case IPP_TAG_ENUM :
-      case IPP_TAG_INTEGER :
-          for (i = 0, val = attr->values; i < attr->num_values; i ++, val ++)
-           printf(" %d", val->integer);
-          putchar('\n');
-          break;
-
-      case IPP_TAG_BOOLEAN :
-          for (i = 0, val = attr->values; i < attr->num_values; i ++, val ++)
-           printf(" %s", val->boolean ? "true" : "false");
-          putchar('\n');
-          break;
-
-      case IPP_TAG_RANGE :
-          for (i = 0, val = attr->values; i < attr->num_values; i ++, val ++)
-           printf(" %d-%d", val->range.lower, val->range.upper);
-          putchar('\n');
-          break;
-
-      case IPP_TAG_DATE :
-          {
-           time_t      vtime;          /* Date/Time value */
-           struct tm   *vdate;         /* Date info */
-           char        vstring[256];   /* Formatted time */
-
-           for (i = 0, val = attr->values; i < attr->num_values; i ++, val ++)
-           {
-             vtime = ippDateToTime(val->date);
-             vdate = localtime(&vtime);
-             strftime(vstring, sizeof(vstring), "%c", vdate);
-             printf(" (%s)", vstring);
-           }
-          }
-          putchar('\n');
-          break;
-
-      case IPP_TAG_RESOLUTION :
-          for (i = 0, val = attr->values; i < attr->num_values; i ++, val ++)
-           printf(" %dx%d%s", val->resolution.xres, val->resolution.yres,
-                  val->resolution.units == IPP_RES_PER_INCH ? "dpi" : "dpc");
-          putchar('\n');
-          break;
-
-      case IPP_TAG_STRING :
-      case IPP_TAG_TEXTLANG :
-      case IPP_TAG_NAMELANG :
-      case IPP_TAG_TEXT :
-      case IPP_TAG_NAME :
-      case IPP_TAG_KEYWORD :
-      case IPP_TAG_URI :
-      case IPP_TAG_URISCHEME :
-      case IPP_TAG_CHARSET :
-      case IPP_TAG_LANGUAGE :
-      case IPP_TAG_MIMETYPE :
-          for (i = 0, val = attr->values; i < attr->num_values; i ++, val ++)
-           printf(" \"%s\"", val->string.text);
-          putchar('\n');
-          break;
-
-      case IPP_TAG_BEGIN_COLLECTION :
-          putchar('\n');
-
-          for (i = 0, val = attr->values; i < attr->num_values; i ++, val ++)
-         {
-           if (i)
-             putchar('\n');
-           print_attributes(val->collection, indent + 4);
-         }
-          break;
-
-      default :
-          printf("UNKNOWN (%d values)\n", attr->num_values);
-          break;
-    }
+    printf("%*s%s (%s%s): %s\n", indent, "", attr->name ? attr->name : "(null)", attr->num_values > 1 ? "1setOf " : "", ippTagString(attr->value_tag), buffer);
   }
 }
 
@@ -966,7 +858,7 @@ read_cb(_ippdata_t   *data,         /* I - Data */
   * Return the number of bytes read...
   */
 
-  return (count);
+  return ((ssize_t)count);
 }
 
 
@@ -996,10 +888,5 @@ write_cb(_ippdata_t   *data,               /* I - Data */
   * Return the number of bytes written...
   */
 
-  return (count);
+  return ((ssize_t)count);
 }
-
-
-/*
- * End of "$Id: testipp.c 6649 2007-07-11 21:46:42Z mike $".
- */