/*
- * "$Id: testppd.c 7897 2008-09-02 19:33:19Z mike $"
+ * PPD test program for CUPS.
*
- * PPD test program for the Common UNIX Printing System (CUPS).
+ * Copyright 2007-2015 by Apple Inc.
+ * Copyright 1997-2006 by Easy Software Products.
*
- * Copyright 2007-2009 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
+ * 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/".
- *
- * This file is subject to the Apple OS-Developed Software exception.
- *
- * Contents:
- *
- * main() - Main entry.
+ * This file is subject to the Apple OS-Developed Software exception.
*/
/*
* Include necessary headers...
*/
-#include <stdio.h>
-#include <stdlib.h>
-#include <cups/string.h>
+#undef _CUPS_NO_DEPRECATED
+#include "cups-private.h"
+#include "ppd-private.h"
#include <sys/stat.h>
-#include <errno.h>
-#include "cups.h"
-#include "pwgmedia.h"
#ifdef WIN32
# include <io.h>
#else
# include <unistd.h>
# include <fcntl.h>
#endif /* WIN32 */
+#include <math.h>
/*
"%%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"
+ "} stopped cleartomark\n"
+ "[{\n"
"%%BeginFeature: *IntOption None\n"
"%%EndFeature\n"
"} stopped cleartomark\n"
"%%EndFeature\n"
"} stopped cleartomark\n"
"[{\n"
+ "%%BeginFeature: *MediaType Plain\n"
+ "MediaType=Plain\n"
+ "%%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"
"%%EndFeature\n"
"} stopped cleartomark\n";
+static const char *default2_code =
+ "[{\n"
+ "%%BeginFeature: *InstalledDuplexer False\n"
+ "%%EndFeature\n"
+ "} stopped cleartomark\n"
+ "[{\n"
+ "%%BeginFeature: *InputSlot Tray\n"
+ "InputSlot=Tray\n"
+ "%%EndFeature\n"
+ "} stopped cleartomark\n"
+ "[{\n"
+ "%%BeginFeature: *Quality Normal\n"
+ "Quality=Normal\n"
+ "%%EndFeature\n"
+ "} stopped cleartomark\n"
+ "[{\n"
+ "%%BeginFeature: *IntOption None\n"
+ "%%EndFeature\n"
+ "} stopped cleartomark\n"
+ "[{\n"
+ "%%BeginFeature: *StringOption None\n"
+ "%%EndFeature\n"
+ "} stopped cleartomark\n";
+
/*
* 'main()' - Main entry.
maxsize, /* Maximum size */
*size; /* Current size */
ppd_attr_t *attr; /* Current attribute */
- _cups_pwg_media_t *pwgmedia; /* PWG media size */
+ _ppd_cache_t *pc; /* PPD cache */
status = 0;
}
putenv("LOCALEDIR=locale");
+ putenv("SOFTWARE=CUPS");
/*
* Do tests with test.ppd...
fputs("ppdOpenFile(test.ppd): ", stdout);
- if ((ppd = ppdOpenFile("test.ppd")) != NULL)
+ if ((ppd = _ppdOpenFile("test.ppd", _PPD_LOCALIZATION_ALL)) != NULL)
puts("PASS");
else
{
num_options = cupsGetConflicts(ppd, "InputSlot", "Envelope", &options);
if (num_options != 2 ||
(val = cupsGetOption("PageRegion", num_options, options)) == NULL ||
- strcasecmp(val, "Letter") ||
+ _cups_strcasecmp(val, "Letter") ||
(val = cupsGetOption("PageSize", num_options, options)) == NULL ||
- strcasecmp(val, "Letter"))
+ _cups_strcasecmp(val, "Letter"))
{
printf("FAIL (%d options:", num_options);
for (i = 0; i < num_options; i ++)
num_options = 0;
options = NULL;
if (cupsResolveConflicts(ppd, NULL, NULL, &num_options, &options) &&
- num_options == 1 && !strcasecmp(options[0].name, "InputSlot") &&
- !strcasecmp(options[0].value, "Tray"))
+ num_options == 1 && !_cups_strcasecmp(options[0].name, "InputSlot") &&
+ !_cups_strcasecmp(options[0].value, "Tray"))
puts("PASS (Resolved by changing InputSlot)");
else if (num_options > 0)
{
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 ++;
else
puts("PASS");
- fputs("_cupsPWGMediaBySize(842, 1191): ", stdout);
- if ((pwgmedia = _cupsPWGMediaBySize(842, 1191)) == NULL)
+ fputs("cupsMarkOptions(media=oe_letter-fullbleed_8.5x11in): ", stdout);
+ num_options = cupsAddOption("media", "oe_letter-fullbleed_8.5x11in", 0,
+ &options);
+ cupsMarkOptions(ppd, num_options, options);
+ cupsFreeOptions(num_options, options);
+
+ size = ppdPageSize(ppd, NULL);
+ if (!size || strcmp(size->name, "Letter.Fullbleed"))
{
- puts("FAIL (not found)");
+ printf("FAIL (%s)\n", size ? size->name : "unknown");
+ status ++;
+ }
+ else
+ puts("PASS");
+
+ fputs("cupsMarkOptions(media=A4): ", stdout);
+ num_options = cupsAddOption("media", "A4", 0, &options);
+ cupsMarkOptions(ppd, num_options, options);
+ cupsFreeOptions(num_options, options);
+
+ size = ppdPageSize(ppd, NULL);
+ if (!size || strcmp(size->name, "A4"))
+ {
+ printf("FAIL (%s)\n", size ? size->name : "unknown");
status ++;
}
- else if (strcmp(pwgmedia->pwg, "iso_a3_297x420mm"))
+ else
+ puts("PASS");
+
+ /*
+ * Custom sizes...
+ */
+
+ fputs("cupsMarkOptions(media=Custom.8x10in): ", stdout);
+ num_options = cupsAddOption("media", "Custom.8x10in", 0, &options);
+ cupsMarkOptions(ppd, num_options, options);
+ cupsFreeOptions(num_options, options);
+
+ size = ppdPageSize(ppd, NULL);
+ if (!size || strcmp(size->name, "Custom") ||
+ fabs(size->width - 576.0) > 0.001 ||
+ fabs(size->length - 720.0) > 0.001)
{
- printf("FAIL (%s)\n", pwgmedia->pwg);
+ printf("FAIL (%s - %gx%g)\n", size ? size->name : "unknown",
+ size ? size->width : 0.0, size ? size->length : 0.0);
status ++;
}
else
printf("FAIL (%d conflicts)\n", conflicts);
}
+ fputs("ppdEmitString (defaults): ", stdout);
+ if ((s = ppdEmitString(ppd, PPD_ORDER_ANY, 0.0)) != NULL &&
+ !strcmp(s, default2_code))
+ puts("PASS");
+ else
+ {
+ status ++;
+ printf("FAIL (%d bytes instead of %d)\n", s ? (int)strlen(s) : 0,
+ (int)strlen(default2_code));
+
+ if (s)
+ puts(s);
+ }
+
+ if (s)
+ free(s);
+
fputs("ppdConflicts(): ", stdout);
ppdMarkOption(ppd, "PageSize", "Env10");
ppdMarkOption(ppd, "InputSlot", "Envelope");
ppdMarkOption(ppd, "Quality", "Photo");
- if ((conflicts = ppdConflicts(ppd)) == 2)
- puts("PASS (2)");
+ if ((conflicts = ppdConflicts(ppd)) == 1)
+ puts("PASS (1)");
else
{
printf("FAIL (%d)\n", conflicts);
num_options = 0;
options = NULL;
if (cupsResolveConflicts(ppd, NULL, NULL, &num_options, &options) &&
- num_options == 1 && !strcasecmp(options->name, "Quality") &&
- !strcasecmp(options->value, "Normal"))
+ num_options == 1 && !_cups_strcasecmp(options->name, "Quality") &&
+ !_cups_strcasecmp(options->value, "Normal"))
puts("PASS");
else if (num_options > 0)
{
fputs("cupsResolveConflicts(loop test): ", stdout);
ppdMarkOption(ppd, "PageSize", "A4");
+ ppdMarkOption(ppd, "InputSlot", "Tray");
ppdMarkOption(ppd, "Quality", "Photo");
num_options = 0;
options = NULL;
}
else
puts("FAIL (No conflicts!)");
-
+
fputs("ppdInstallableConflict(): ", stdout);
if (ppdInstallableConflict(ppd, "Duplex", "DuplexNoTumble") &&
!ppdInstallableConflict(ppd, "Duplex", "None"))
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,
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,
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,
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,
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], ':'))
{
- filename = cupsGetPPD(argv[1] + 2);
- if (!filename)
+ /*
+ * 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 */
+
+ if (argv[1][2])
+ printer = argv[1] + 2;
+ else if (argv[2])
+ printer = argv[2];
+ else
+ {
+ puts("Usage: ./testppd -d printer");
+ return (1);
+ }
+
+ filename = cupsGetPPD(printer);
+
+ if (!filename)
+ {
+ printf("%s: %s\n", printer, cupsLastErrorString());
+ return (1);
+ }
+ }
else
filename = argv[1];
if ((realsize = readlink(filename, realfile, sizeof(realfile) - 1)) < 0)
- strcpy(realfile, "Unknown");
+ strlcpy(realfile, "Unknown", sizeof(realfile));
else
realfile[realsize] = '\0';
}
ppdLocalize(ppd);
+ ppdMarkDefaults(ppd);
if (argc > 3)
{
printf(" %s (%s):\n", option->keyword, option->text);
for (k = 0; k < option->num_choices; k ++)
- printf(" - %s (%s)\n", option->choices[k].choice,
- option->choices[k].text);
+ printf(" - %s%s (%s)\n",
+ option->choices[k].marked ? "*" : "",
+ option->choices[k].choice, option->choices[k].text);
if ((coption = ppdFindCustomOption(ppd, option->keyword)) != NULL)
{
}
}
- puts("Constraints:");
+ puts("\nSizes:");
+ for (i = ppd->num_sizes, size = ppd->sizes; i > 0; i --, size ++)
+ printf(" %s = %gx%g, [%g %g %g %g]\n", size->name, size->width,
+ size->length, size->left, size->bottom, size->right, size->top);
+
+ puts("\nConstraints:");
for (i = ppd->num_consts, c = ppd->consts; i > 0; i --, c ++)
printf(" *UIConstraints: *%s %s *%s %s\n", c->option1, c->choice1,
c->option2, c->choice2);
+ if (ppd->num_consts == 0)
+ puts(" NO CONSTRAINTS");
+
+ puts("\nFilters:");
+
+ for (i = 0; i < ppd->num_filters; i ++)
+ printf(" %s\n", ppd->filters[i]);
+
+ if (ppd->num_filters == 0)
+ puts(" NO FILTERS");
- puts("Attributes:");
+ puts("\nAttributes:");
for (attr = (ppd_attr_t *)cupsArrayFirst(ppd->sorted_attrs);
attr;
attr = (ppd_attr_t *)cupsArrayNext(ppd->sorted_attrs))
printf(" *%s %s/%s: \"%s\"\n", attr->name, attr->spec,
attr->text, attr->value ? attr->value : "");
+
+ puts("\nPPD Cache:");
+ if ((pc = _ppdCacheCreateWithPPD(ppd)) == NULL)
+ printf(" Unable to create: %s\n", cupsLastErrorString());
+ else
+ {
+ _ppdCacheWriteFile(pc, "t.cache", NULL);
+ puts(" Wrote t.cache.");
+ }
}
if (!strncmp(argv[1], "-d", 2))
return (status);
}
-
-
-/*
- * End of "$Id: testppd.c 7897 2008-09-02 19:33:19Z mike $".
- */