/*
- * "$Id: testppd.c 7897 2008-09-02 19:33:19Z mike $"
+ * "$Id: testppd.c 11060 2013-06-25 15:02:18Z msweet $"
*
- * PPD test program for the Common UNIX Printing System (CUPS).
+ * PPD test program for CUPS.
*
- * Copyright 2007-2008 by Apple Inc.
+ * Copyright 2007-2013 by Apple Inc.
* Copyright 1997-2006 by Easy Software Products.
*
* These coded instructions, statements, and computer programs are the
* Include necessary headers...
*/
-#include <stdio.h>
-#include <stdlib.h>
-#include <cups/string.h>
+#undef _CUPS_NO_DEPRECATED
+#include "cups-private.h"
#include <sys/stat.h>
-#include <errno.h>
-#include "cups.h"
#ifdef WIN32
# include <io.h>
#else
"%%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: *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.
int conflicts; /* Number of conflicts */
char *s; /* String */
char buffer[8192]; /* String buffer */
- const char *text; /* Localized text */
+ const char *text, /* Localized text */
+ *val; /* Option value */
int num_options; /* Number of options */
cups_option_t *options; /* Options */
ppd_size_t minsize, /* Minimum size */
- maxsize; /* Maximum size */
+ maxsize, /* Maximum size */
+ *size; /* Current size */
+ ppd_attr_t *attr; /* Current attribute */
+ _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
{
printf("FAIL (%s on line %d)\n", ppdErrorString(err), line);
}
+ fputs("ppdFindAttr(wildcard): ", stdout);
+ if ((attr = ppdFindAttr(ppd, "cupsTest", NULL)) == NULL)
+ {
+ status ++;
+ puts("FAIL (not found)");
+ }
+ else if (strcmp(attr->name, "cupsTest") || strcmp(attr->spec, "Foo"))
+ {
+ status ++;
+ printf("FAIL (got \"%s %s\")\n", attr->name, attr->spec);
+ }
+ else
+ puts("PASS");
+
+ fputs("ppdFindNextAttr(wildcard): ", stdout);
+ if ((attr = ppdFindNextAttr(ppd, "cupsTest", NULL)) == NULL)
+ {
+ status ++;
+ puts("FAIL (not found)");
+ }
+ else if (strcmp(attr->name, "cupsTest") || strcmp(attr->spec, "Bar"))
+ {
+ status ++;
+ printf("FAIL (got \"%s %s\")\n", attr->name, attr->spec);
+ }
+ else
+ puts("PASS");
+
+ fputs("ppdFindAttr(Foo): ", stdout);
+ if ((attr = ppdFindAttr(ppd, "cupsTest", "Foo")) == NULL)
+ {
+ status ++;
+ puts("FAIL (not found)");
+ }
+ else if (strcmp(attr->name, "cupsTest") || strcmp(attr->spec, "Foo"))
+ {
+ status ++;
+ printf("FAIL (got \"%s %s\")\n", attr->name, attr->spec);
+ }
+ else
+ puts("PASS");
+
+ fputs("ppdFindNextAttr(Foo): ", stdout);
+ if ((attr = ppdFindNextAttr(ppd, "cupsTest", "Foo")) != NULL)
+ {
+ status ++;
+ printf("FAIL (got \"%s %s\")\n", attr->name, attr->spec);
+ }
+ else
+ puts("PASS");
+
fputs("ppdMarkDefaults: ", stdout);
ppdMarkDefaults(ppd);
* Test constraints...
*/
- fputs("ppdConflicts(): ", stdout);
+ fputs("cupsGetConflicts(InputSlot=Envelope): ", stdout);
ppdMarkOption(ppd, "PageSize", "Letter");
+
+ num_options = cupsGetConflicts(ppd, "InputSlot", "Envelope", &options);
+ if (num_options != 2 ||
+ (val = cupsGetOption("PageRegion", num_options, options)) == NULL ||
+ _cups_strcasecmp(val, "Letter") ||
+ (val = cupsGetOption("PageSize", num_options, options)) == NULL ||
+ _cups_strcasecmp(val, "Letter"))
+ {
+ printf("FAIL (%d options:", num_options);
+ for (i = 0; i < num_options; i ++)
+ printf(" %s=%s", options[i].name, options[i].value);
+ puts(")");
+ status ++;
+ }
+ else
+ puts("PASS");
+
+ fputs("ppdConflicts(): ", stdout);
ppdMarkOption(ppd, "InputSlot", "Envelope");
if ((conflicts = ppdConflicts(ppd)) == 2)
fputs("cupsResolveConflicts(InputSlot=Envelope): ", stdout);
num_options = 0;
options = NULL;
- if (cupsResolveConflicts(ppd, "InputSlot", "Envelope", &num_options,
+ if (!cupsResolveConflicts(ppd, "InputSlot", "Envelope", &num_options,
&options))
{
- puts("FAIL (Resolved but shouldn't be able to!)");
+ puts("FAIL (Unable to resolve)");
+ status ++;
+ }
+ else if (num_options != 2 ||
+ !cupsGetOption("PageSize", num_options, options))
+ {
+ printf("FAIL (%d options:", num_options);
+ for (i = 0; i < num_options; i ++)
+ printf(" %s=%s", options[i].name, options[i].value);
+ puts(")");
status ++;
}
else
- puts("PASS (Unable to resolve)");
+ puts("PASS (Resolved by changing PageSize)");
+
cupsFreeOptions(num_options, options);
fputs("cupsResolveConflicts(No option/choice): ", stdout);
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, "Manual"))
- puts("PASS (Resolved)");
+ 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)
{
printf("FAIL (%d options:", num_options);
status ++;
}
+ /*
+ * cupsMarkOptions with PWG and IPP size names.
+ */
+
+ fputs("cupsMarkOptions(media=iso-a4): ", stdout);
+ num_options = cupsAddOption("media", "iso-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
+ puts("PASS");
+
+ fputs("cupsMarkOptions(media=na_letter_8.5x11in): ", stdout);
+ num_options = cupsAddOption("media", "na_letter_8.5x11in", 0, &options);
+ cupsMarkOptions(ppd, num_options, options);
+ cupsFreeOptions(num_options, options);
+
+ size = ppdPageSize(ppd, NULL);
+ if (!size || strcmp(size->name, "Letter"))
+ {
+ printf("FAIL (%s)\n", size ? size->name : "unknown");
+ status ++;
+ }
+ else
+ puts("PASS");
+
+ 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"))
+ {
+ 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
+ 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") ||
+ size->width != 576 || size->length != 720)
+ {
+ printf("FAIL (%s - %gx%g)\n", size ? size->name : "unknown",
+ size ? size->width : 0.0, size ? size->length : 0.0);
+ status ++;
+ }
+ else
+ puts("PASS");
+
/*
* Test localization...
*/
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"))
else
{
const char *filename; /* PPD filename */
+ struct stat fileinfo; /* File information */
if (!strncmp(argv[1], "-d", 2))
{
- filename = cupsGetPPD(argv[1] + 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", argv[1], cupsLastErrorString());
+ printf("%s: %s\n", printer, cupsLastErrorString());
return (1);
}
}
else
filename = argv[1];
+ if (lstat(filename, &fileinfo))
+ {
+ printf("%s: %s\n", filename, strerror(errno));
+ return (1);
+ }
+
+ if (S_ISLNK(fileinfo.st_mode))
+ {
+ char realfile[1024]; /* Real file path */
+ ssize_t realsize; /* Size of real file path */
+
+
+ if ((realsize = readlink(filename, realfile, sizeof(realfile) - 1)) < 0)
+ strlcpy(realfile, "Unknown", sizeof(realfile));
+ else
+ realfile[realsize] = '\0';
+
+ if (stat(realfile, &fileinfo))
+ printf("%s: symlink to \"%s\", %s\n", filename, realfile,
+ strerror(errno));
+ else
+ printf("%s: symlink to \"%s\", %ld bytes\n", filename, realfile,
+ (long)fileinfo.st_size);
+ }
+ else
+ printf("%s: regular file, %ld bytes\n", filename, (long)fileinfo.st_size);
+
if ((ppd = ppdOpenFile(filename)) == NULL)
{
ppd_status_t err; /* Last error in file */
else
{
int j, k; /* Looping vars */
- ppd_attr_t *attr; /* Current attribute */
ppd_group_t *group; /* Option group */
ppd_option_t *option; /* Option */
ppd_coption_t *coption; /* Custom option */
}
ppdLocalize(ppd);
+ ppdMarkDefaults(ppd);
+
+ if (argc > 3)
+ {
+ text = ppdLocalizeIPPReason(ppd, argv[3], NULL, buffer, sizeof(buffer));
+ printf("ppdLocalizeIPPReason(%s)=%s\n", argv[3],
+ text ? text : "(null)");
+ return (text == NULL);
+ }
for (i = ppd->num_groups, group = ppd->groups;
i > 0;
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]);
- puts("Attributes:");
+ if (ppd->num_filters == 0)
+ puts(" NO FILTERS");
+
+ 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))
/*
- * End of "$Id: testppd.c 7897 2008-09-02 19:33:19Z mike $".
+ * End of "$Id: testppd.c 11060 2013-06-25 15:02:18Z msweet $".
*/