]> git.ipfire.org Git - thirdparty/cups.git/blobdiff - cups/testppd.c
License change: Apache License, Version 2.0.
[thirdparty/cups.git] / cups / testppd.c
index ef88425dcae082fcde1813925f32d94b7a6503e7..5ebc549a3cea7695560edbc0cbd07e0021ee3418 100644 (file)
@@ -1,29 +1,19 @@
 /*
- * "$Id: testppd.c 7897 2008-09-02 19:33:19Z mike $"
+ * PPD test program for CUPS.
  *
- *   PPD test program for CUPS.
+ * Copyright 2007-2017 by Apple Inc.
+ * Copyright 1997-2006 by Easy Software Products.
  *
- *   Copyright 2007-2012 by Apple Inc.
- *   Copyright 1997-2006 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.
+ * Licensed under Apache License v2.0.  See the file "LICENSE" for more information.
  */
 
 /*
  * Include necessary headers...
  */
 
+#undef _CUPS_NO_DEPRECATED
 #include "cups-private.h"
+#include "ppd-private.h"
 #include <sys/stat.h>
 #ifdef WIN32
 #  include <io.h>
@@ -31,6 +21,7 @@
 #  include <unistd.h>
 #  include <fcntl.h>
 #endif /* WIN32 */
+#include <math.h>
 
 
 /*
@@ -53,6 +44,11 @@ static const char    *default_code =
                        "%%EndFeature\n"
                        "} stopped cleartomark\n"
                        "[{\n"
+                       "%%BeginFeature: *OutputBin Tray1\n"
+                       "OutputBin=Tray1\n"
+                       "%%EndFeature\n"
+                       "} stopped cleartomark\n"
+                       "[{\n"
                        "%%BeginFeature: *MediaType Plain\n"
                        "MediaType=Plain\n"
                        "%%EndFeature\n"
@@ -82,6 +78,11 @@ static const char    *custom_code =
                        "%%EndFeature\n"
                        "} stopped cleartomark\n"
                        "[{\n"
+                       "%%BeginFeature: *OutputBin Tray1\n"
+                       "OutputBin=Tray1\n"
+                       "%%EndFeature\n"
+                       "} stopped cleartomark\n"
+                       "[{\n"
                        "%%BeginFeature: *IntOption None\n"
                        "%%EndFeature\n"
                        "} stopped cleartomark\n"
@@ -393,10 +394,10 @@ main(int  argc,                           /* I - Number of command-line arguments */
     fputs("ppdPageSizeLimits: ", stdout);
     if (ppdPageSizeLimits(ppd, &minsize, &maxsize))
     {
-      if (minsize.width != 36 || minsize.length != 36 ||
-          maxsize.width != 1080 || maxsize.length != 86400)
+      if (fabs(minsize.width - 36.0) > 0.001 || fabs(minsize.length - 36.0) > 0.001 ||
+          fabs(maxsize.width - 1080.0) > 0.001 || fabs(maxsize.length - 86400.0) > 0.001)
       {
-        printf("FAIL (got min=%.0fx%.0f, max=%.0fx%.0f, "
+        printf("FAIL (got min=%.3fx%.3f, max=%.3fx%.3f, "
               "expected min=36x36, max=1080x86400)\n", minsize.width,
               minsize.length, maxsize.width, maxsize.length);
         status ++;
@@ -482,7 +483,8 @@ main(int  argc,                             /* I - Number of command-line arguments */
 
     size = ppdPageSize(ppd, NULL);
     if (!size || strcmp(size->name, "Custom") ||
-        size->width != 576 || size->length != 720)
+        fabs(size->width - 576.0) > 0.001 ||
+        fabs(size->length - 720.0) > 0.001)
     {
       printf("FAIL (%s - %gx%g)\n", size ? size->name : "unknown",
              size ? size->width : 0.0, size ? size->length : 0.0);
@@ -771,8 +773,8 @@ main(int  argc,                             /* I - Number of command-line arguments */
     fputs("ppdPageSizeLimits(default): ", stdout);
     if (ppdPageSizeLimits(ppd, &minsize, &maxsize))
     {
-      if (minsize.width != 36 || minsize.length != 36 ||
-          maxsize.width != 1080 || maxsize.length != 86400)
+      if (fabs(minsize.width - 36.0) > 0.001 || fabs(minsize.length - 36.0) > 0.001 ||
+          fabs(maxsize.width - 1080.0) > 0.001 || fabs(maxsize.length - 86400.0) > 0.001)
       {
         printf("FAIL (got min=%.0fx%.0f, max=%.0fx%.0f, "
               "expected min=36x36, max=1080x86400)\n", minsize.width,
@@ -793,8 +795,8 @@ main(int  argc,                             /* I - Number of command-line arguments */
     fputs("ppdPageSizeLimits(InputSlot=Manual): ", stdout);
     if (ppdPageSizeLimits(ppd, &minsize, &maxsize))
     {
-      if (minsize.width != 100 || minsize.length != 100 ||
-          maxsize.width != 1000 || maxsize.length != 1000)
+      if (fabs(minsize.width - 100.0) > 0.001 || fabs(minsize.length - 100.0) > 0.001 ||
+          fabs(maxsize.width - 1000.0) > 0.001 || fabs(maxsize.length - 1000.0) > 0.001)
       {
         printf("FAIL (got min=%.0fx%.0f, max=%.0fx%.0f, "
               "expected min=100x100, max=1000x1000)\n", minsize.width,
@@ -815,8 +817,8 @@ main(int  argc,                             /* I - Number of command-line arguments */
     fputs("ppdPageSizeLimits(Quality=Photo): ", stdout);
     if (ppdPageSizeLimits(ppd, &minsize, &maxsize))
     {
-      if (minsize.width != 200 || minsize.length != 200 ||
-          maxsize.width != 1000 || maxsize.length != 1000)
+      if (fabs(minsize.width - 200.0) > 0.001 || fabs(minsize.length - 200.0) > 0.001 ||
+          fabs(maxsize.width - 1000.0) > 0.001 || fabs(maxsize.length - 1000.0) > 0.001)
       {
         printf("FAIL (got min=%.0fx%.0f, max=%.0fx%.0f, "
               "expected min=200x200, max=1000x1000)\n", minsize.width,
@@ -837,8 +839,8 @@ main(int  argc,                             /* I - Number of command-line arguments */
     fputs("ppdPageSizeLimits(Quality=Photo): ", stdout);
     if (ppdPageSizeLimits(ppd, &minsize, &maxsize))
     {
-      if (minsize.width != 300 || minsize.length != 300 ||
-          maxsize.width != 1080 || maxsize.length != 86400)
+      if (fabs(minsize.width - 300.0) > 0.001 || fabs(minsize.length - 300.0) > 0.001 ||
+          fabs(maxsize.width - 1080.0) > 0.001 || fabs(maxsize.length - 86400.0) > 0.001)
       {
         printf("FAIL (got min=%.0fx%.0f, max=%.0fx%.0f, "
               "expected min=300x300, max=1080x86400)\n", minsize.width,
@@ -854,13 +856,66 @@ main(int  argc,                           /* I - Number of command-line arguments */
       status ++;
     }
   }
+  else if (!strncmp(argv[1], "ipp://", 6) || !strncmp(argv[1], "ipps://", 7))
+  {
+   /*
+    * ipp://... or ipps://...
+    */
+
+    http_t     *http;                  /* Connection to printer */
+    ipp_t      *request,               /* Get-Printer-Attributes request */
+               *response;              /* Get-Printer-Attributes response */
+    char       scheme[32],             /* URI scheme */
+               userpass[256],          /* Username:password */
+               host[256],              /* Hostname */
+               resource[256];          /* Resource path */
+    int                port;                   /* Port number */
+
+    if (httpSeparateURI(HTTP_URI_CODING_ALL, argv[1], scheme, sizeof(scheme), userpass, sizeof(userpass), host, sizeof(host), &port, resource, sizeof(resource)) < HTTP_URI_STATUS_OK)
+    {
+      printf("Bad URI \"%s\".\n", argv[1]);
+      return (1);
+    }
+
+    http = httpConnect2(host, port, NULL, AF_UNSPEC, !strcmp(scheme, "ipps") ? HTTP_ENCRYPTION_ALWAYS : HTTP_ENCRYPTION_IF_REQUESTED, 1, 30000, NULL);
+    if (!http)
+    {
+      printf("Unable to connect to \"%s:%d\": %s\n", host, port, cupsLastErrorString());
+      return (1);
+    }
+
+    request = ippNewRequest(IPP_OP_GET_PRINTER_ATTRIBUTES);
+    ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "printer-uri", NULL, argv[1]);
+    response = cupsDoRequest(http, request, resource);
+
+    if (_ppdCreateFromIPP(buffer, sizeof(buffer), response))
+      printf("Created PPD: %s\n", buffer);
+    else
+      puts("Unable to create PPD.");
+
+    ippDelete(response);
+    httpClose(http);
+    return (0);
+  }
   else
   {
     const char *filename;              /* PPD filename */
     struct stat        fileinfo;               /* File information */
 
 
-    if (!strncmp(argv[1], "-d", 2))
+    if (strchr(argv[1], ':'))
+    {
+     /*
+      * Server PPD...
+      */
+
+      if ((filename = cupsGetServerPPD(CUPS_HTTP_DEFAULT, argv[1])) == NULL)
+      {
+        printf("%s: %s\n", argv[1], cupsLastErrorString());
+        return (1);
+      }
+    }
+    else if (!strncmp(argv[1], "-d", 2))
     {
       const char *printer;             /* Printer name */
 
@@ -1105,8 +1160,3 @@ main(int  argc,                           /* I - Number of command-line arguments */
 
   return (status);
 }
-
-
-/*
- * End of "$Id: testppd.c 7897 2008-09-02 19:33:19Z mike $".
- */