2 * "$Id: testppd.c 12603 2015-05-06 01:42:51Z msweet $"
4 * PPD test program for CUPS.
6 * Copyright 2007-2015 by Apple Inc.
7 * Copyright 1997-2006 by Easy Software Products.
9 * These coded instructions, statements, and computer programs are the
10 * property of Apple Inc. and are protected by Federal copyright
11 * law. Distribution and use rights are outlined in the file "LICENSE.txt"
12 * which should have been included with this file. If this file is
13 * file is missing or damaged, see the license at "http://www.cups.org/".
15 * This file is subject to the Apple OS-Developed Software exception.
19 * Include necessary headers...
22 #undef _CUPS_NO_DEPRECATED
23 #include "cups-private.h"
38 static const char *default_code =
40 "%%BeginFeature: *InstalledDuplexer False\n"
42 "} stopped cleartomark\n"
44 "%%BeginFeature: *PageRegion Letter\n"
47 "} stopped cleartomark\n"
49 "%%BeginFeature: *InputSlot Tray\n"
52 "} stopped cleartomark\n"
54 "%%BeginFeature: *OutputBin Tray1\n"
57 "} stopped cleartomark\n"
59 "%%BeginFeature: *MediaType Plain\n"
62 "} stopped cleartomark\n"
64 "%%BeginFeature: *IntOption None\n"
66 "} stopped cleartomark\n"
68 "%%BeginFeature: *StringOption None\n"
70 "} stopped cleartomark\n";
72 static const char *custom_code =
74 "%%BeginFeature: *InstalledDuplexer False\n"
76 "} stopped cleartomark\n"
78 "%%BeginFeature: *InputSlot Tray\n"
81 "} stopped cleartomark\n"
83 "%%BeginFeature: *MediaType Plain\n"
86 "} stopped cleartomark\n"
88 "%%BeginFeature: *OutputBin Tray1\n"
91 "} stopped cleartomark\n"
93 "%%BeginFeature: *IntOption None\n"
95 "} stopped cleartomark\n"
97 "%%BeginFeature: *CustomStringOption True\n"
98 "(value\\0502\\051)\n"
100 "StringOption=Custom\n"
102 "} stopped cleartomark\n"
104 "%%BeginFeature: *CustomPageSize True\n"
112 "} stopped cleartomark\n";
114 static const char *default2_code =
116 "%%BeginFeature: *InstalledDuplexer False\n"
118 "} stopped cleartomark\n"
120 "%%BeginFeature: *InputSlot Tray\n"
123 "} stopped cleartomark\n"
125 "%%BeginFeature: *Quality Normal\n"
128 "} stopped cleartomark\n"
130 "%%BeginFeature: *IntOption None\n"
132 "} stopped cleartomark\n"
134 "%%BeginFeature: *StringOption None\n"
136 "} stopped cleartomark\n";
140 * 'main()' - Main entry.
143 int /* O - Exit status */
144 main(int argc, /* I - Number of command-line arguments */
145 char *argv[]) /* I - Command-line arguments */
147 int i; /* Looping var */
148 ppd_file_t *ppd; /* PPD file loaded from disk */
149 int status; /* Status of tests (0 = success, 1 = fail) */
150 int conflicts; /* Number of conflicts */
151 char *s; /* String */
152 char buffer[8192]; /* String buffer */
153 const char *text, /* Localized text */
154 *val; /* Option value */
155 int num_options; /* Number of options */
156 cups_option_t *options; /* Options */
157 ppd_size_t minsize, /* Minimum size */
158 maxsize, /* Maximum size */
159 *size; /* Current size */
160 ppd_attr_t *attr; /* Current attribute */
161 _ppd_cache_t *pc; /* PPD cache */
169 * Setup directories for locale stuff...
172 if (access("locale", 0))
174 mkdir("locale", 0777);
175 mkdir("locale/fr", 0777);
176 symlink("../../../locale/cups_fr.po", "locale/fr/cups_fr.po");
177 mkdir("locale/zh_TW", 0777);
178 symlink("../../../locale/cups_zh_TW.po", "locale/zh_TW/cups_zh_TW.po");
181 putenv("LOCALEDIR=locale");
182 putenv("SOFTWARE=CUPS");
185 * Do tests with test.ppd...
188 fputs("ppdOpenFile(test.ppd): ", stdout);
190 if ((ppd = _ppdOpenFile("test.ppd", _PPD_LOCALIZATION_ALL)) != NULL)
194 ppd_status_t err; /* Last error in file */
195 int line; /* Line number in file */
199 err = ppdLastError(&line);
201 printf("FAIL (%s on line %d)\n", ppdErrorString(err), line);
204 fputs("ppdFindAttr(wildcard): ", stdout);
205 if ((attr = ppdFindAttr(ppd, "cupsTest", NULL)) == NULL)
208 puts("FAIL (not found)");
210 else if (strcmp(attr->name, "cupsTest") || strcmp(attr->spec, "Foo"))
213 printf("FAIL (got \"%s %s\")\n", attr->name, attr->spec);
218 fputs("ppdFindNextAttr(wildcard): ", stdout);
219 if ((attr = ppdFindNextAttr(ppd, "cupsTest", NULL)) == NULL)
222 puts("FAIL (not found)");
224 else if (strcmp(attr->name, "cupsTest") || strcmp(attr->spec, "Bar"))
227 printf("FAIL (got \"%s %s\")\n", attr->name, attr->spec);
232 fputs("ppdFindAttr(Foo): ", stdout);
233 if ((attr = ppdFindAttr(ppd, "cupsTest", "Foo")) == NULL)
236 puts("FAIL (not found)");
238 else if (strcmp(attr->name, "cupsTest") || strcmp(attr->spec, "Foo"))
241 printf("FAIL (got \"%s %s\")\n", attr->name, attr->spec);
246 fputs("ppdFindNextAttr(Foo): ", stdout);
247 if ((attr = ppdFindNextAttr(ppd, "cupsTest", "Foo")) != NULL)
250 printf("FAIL (got \"%s %s\")\n", attr->name, attr->spec);
255 fputs("ppdMarkDefaults: ", stdout);
256 ppdMarkDefaults(ppd);
258 if ((conflicts = ppdConflicts(ppd)) == 0)
263 printf("FAIL (%d conflicts)\n", conflicts);
266 fputs("ppdEmitString (defaults): ", stdout);
267 if ((s = ppdEmitString(ppd, PPD_ORDER_ANY, 0.0)) != NULL &&
268 !strcmp(s, default_code))
273 printf("FAIL (%d bytes instead of %d)\n", s ? (int)strlen(s) : 0,
274 (int)strlen(default_code));
283 fputs("ppdEmitString (custom size and string): ", stdout);
284 ppdMarkOption(ppd, "PageSize", "Custom.400x500");
285 ppdMarkOption(ppd, "StringOption", "{String1=\"value 1\" String2=value(2)}");
287 if ((s = ppdEmitString(ppd, PPD_ORDER_ANY, 0.0)) != NULL &&
288 !strcmp(s, custom_code))
293 printf("FAIL (%d bytes instead of %d)\n", s ? (int)strlen(s) : 0,
294 (int)strlen(custom_code));
304 * Test constraints...
307 fputs("cupsGetConflicts(InputSlot=Envelope): ", stdout);
308 ppdMarkOption(ppd, "PageSize", "Letter");
310 num_options = cupsGetConflicts(ppd, "InputSlot", "Envelope", &options);
311 if (num_options != 2 ||
312 (val = cupsGetOption("PageRegion", num_options, options)) == NULL ||
313 _cups_strcasecmp(val, "Letter") ||
314 (val = cupsGetOption("PageSize", num_options, options)) == NULL ||
315 _cups_strcasecmp(val, "Letter"))
317 printf("FAIL (%d options:", num_options);
318 for (i = 0; i < num_options; i ++)
319 printf(" %s=%s", options[i].name, options[i].value);
326 fputs("ppdConflicts(): ", stdout);
327 ppdMarkOption(ppd, "InputSlot", "Envelope");
329 if ((conflicts = ppdConflicts(ppd)) == 2)
333 printf("FAIL (%d)\n", conflicts);
337 fputs("cupsResolveConflicts(InputSlot=Envelope): ", stdout);
340 if (!cupsResolveConflicts(ppd, "InputSlot", "Envelope", &num_options,
343 puts("FAIL (Unable to resolve)");
346 else if (num_options != 2 ||
347 !cupsGetOption("PageSize", num_options, options))
349 printf("FAIL (%d options:", num_options);
350 for (i = 0; i < num_options; i ++)
351 printf(" %s=%s", options[i].name, options[i].value);
356 puts("PASS (Resolved by changing PageSize)");
358 cupsFreeOptions(num_options, options);
360 fputs("cupsResolveConflicts(No option/choice): ", stdout);
363 if (cupsResolveConflicts(ppd, NULL, NULL, &num_options, &options) &&
364 num_options == 1 && !_cups_strcasecmp(options[0].name, "InputSlot") &&
365 !_cups_strcasecmp(options[0].value, "Tray"))
366 puts("PASS (Resolved by changing InputSlot)");
367 else if (num_options > 0)
369 printf("FAIL (%d options:", num_options);
370 for (i = 0; i < num_options; i ++)
371 printf(" %s=%s", options[i].name, options[i].value);
377 puts("FAIL (Unable to resolve)");
380 cupsFreeOptions(num_options, options);
382 fputs("ppdInstallableConflict(): ", stdout);
383 if (ppdInstallableConflict(ppd, "Duplex", "DuplexNoTumble") &&
384 !ppdInstallableConflict(ppd, "Duplex", "None"))
386 else if (!ppdInstallableConflict(ppd, "Duplex", "DuplexNoTumble"))
388 puts("FAIL (Duplex=DuplexNoTumble did not conflict)");
393 puts("FAIL (Duplex=None conflicted)");
401 fputs("ppdPageSizeLimits: ", stdout);
402 if (ppdPageSizeLimits(ppd, &minsize, &maxsize))
404 if (fabs(minsize.width - 36.0) > 0.001 || fabs(minsize.length - 36.0) > 0.001 ||
405 fabs(maxsize.width - 1080.0) > 0.001 || fabs(maxsize.length - 86400.0) > 0.001)
407 printf("FAIL (got min=%.3fx%.3f, max=%.3fx%.3f, "
408 "expected min=36x36, max=1080x86400)\n", minsize.width,
409 minsize.length, maxsize.width, maxsize.length);
417 puts("FAIL (returned 0)");
422 * cupsMarkOptions with PWG and IPP size names.
425 fputs("cupsMarkOptions(media=iso-a4): ", stdout);
426 num_options = cupsAddOption("media", "iso-a4", 0, &options);
427 cupsMarkOptions(ppd, num_options, options);
428 cupsFreeOptions(num_options, options);
430 size = ppdPageSize(ppd, NULL);
431 if (!size || strcmp(size->name, "A4"))
433 printf("FAIL (%s)\n", size ? size->name : "unknown");
439 fputs("cupsMarkOptions(media=na_letter_8.5x11in): ", stdout);
440 num_options = cupsAddOption("media", "na_letter_8.5x11in", 0, &options);
441 cupsMarkOptions(ppd, num_options, options);
442 cupsFreeOptions(num_options, options);
444 size = ppdPageSize(ppd, NULL);
445 if (!size || strcmp(size->name, "Letter"))
447 printf("FAIL (%s)\n", size ? size->name : "unknown");
453 fputs("cupsMarkOptions(media=oe_letter-fullbleed_8.5x11in): ", stdout);
454 num_options = cupsAddOption("media", "oe_letter-fullbleed_8.5x11in", 0,
456 cupsMarkOptions(ppd, num_options, options);
457 cupsFreeOptions(num_options, options);
459 size = ppdPageSize(ppd, NULL);
460 if (!size || strcmp(size->name, "Letter.Fullbleed"))
462 printf("FAIL (%s)\n", size ? size->name : "unknown");
468 fputs("cupsMarkOptions(media=A4): ", stdout);
469 num_options = cupsAddOption("media", "A4", 0, &options);
470 cupsMarkOptions(ppd, num_options, options);
471 cupsFreeOptions(num_options, options);
473 size = ppdPageSize(ppd, NULL);
474 if (!size || strcmp(size->name, "A4"))
476 printf("FAIL (%s)\n", size ? size->name : "unknown");
486 fputs("cupsMarkOptions(media=Custom.8x10in): ", stdout);
487 num_options = cupsAddOption("media", "Custom.8x10in", 0, &options);
488 cupsMarkOptions(ppd, num_options, options);
489 cupsFreeOptions(num_options, options);
491 size = ppdPageSize(ppd, NULL);
492 if (!size || strcmp(size->name, "Custom") ||
493 fabs(size->width - 576.0) > 0.001 ||
494 fabs(size->length - 720.0) > 0.001)
496 printf("FAIL (%s - %gx%g)\n", size ? size->name : "unknown",
497 size ? size->width : 0.0, size ? size->length : 0.0);
504 * Test localization...
507 fputs("ppdLocalizeIPPReason(text): ", stdout);
508 if (ppdLocalizeIPPReason(ppd, "foo", NULL, buffer, sizeof(buffer)) &&
509 !strcmp(buffer, "Foo Reason"))
514 printf("FAIL (\"%s\" instead of \"Foo Reason\")\n", buffer);
517 fputs("ppdLocalizeIPPReason(http): ", stdout);
518 if (ppdLocalizeIPPReason(ppd, "foo", "http", buffer, sizeof(buffer)) &&
519 !strcmp(buffer, "http://foo/bar.html"))
524 printf("FAIL (\"%s\" instead of \"http://foo/bar.html\")\n", buffer);
527 fputs("ppdLocalizeIPPReason(help): ", stdout);
528 if (ppdLocalizeIPPReason(ppd, "foo", "help", buffer, sizeof(buffer)) &&
529 !strcmp(buffer, "help:anchor='foo'%20bookID=Vendor%20Help"))
534 printf("FAIL (\"%s\" instead of \"help:anchor='foo'%%20bookID=Vendor%%20Help\")\n", buffer);
537 fputs("ppdLocalizeIPPReason(file): ", stdout);
538 if (ppdLocalizeIPPReason(ppd, "foo", "file", buffer, sizeof(buffer)) &&
539 !strcmp(buffer, "/help/foo/bar.html"))
544 printf("FAIL (\"%s\" instead of \"/help/foo/bar.html\")\n", buffer);
549 putenv("LC_CTYPE=fr");
550 putenv("LC_MESSAGES=fr");
552 fputs("ppdLocalizeIPPReason(fr text): ", stdout);
553 if (ppdLocalizeIPPReason(ppd, "foo", NULL, buffer, sizeof(buffer)) &&
554 !strcmp(buffer, "La Long Foo Reason"))
559 printf("FAIL (\"%s\" instead of \"La Long Foo Reason\")\n", buffer);
562 putenv("LANG=zh_TW");
563 putenv("LC_ALL=zh_TW");
564 putenv("LC_CTYPE=zh_TW");
565 putenv("LC_MESSAGES=zh_TW");
567 fputs("ppdLocalizeIPPReason(zh_TW text): ", stdout);
568 if (ppdLocalizeIPPReason(ppd, "foo", NULL, buffer, sizeof(buffer)) &&
569 !strcmp(buffer, "Number 1 Foo Reason"))
574 printf("FAIL (\"%s\" instead of \"Number 1 Foo Reason\")\n", buffer);
578 * cupsMarkerName localization...
583 putenv("LC_CTYPE=en");
584 putenv("LC_MESSAGES=en");
586 fputs("ppdLocalizeMarkerName(bogus): ", stdout);
588 if ((text = ppdLocalizeMarkerName(ppd, "bogus")) != NULL)
591 printf("FAIL (\"%s\" instead of NULL)\n", text);
596 fputs("ppdLocalizeMarkerName(cyan): ", stdout);
598 if ((text = ppdLocalizeMarkerName(ppd, "cyan")) != NULL &&
599 !strcmp(text, "Cyan Toner"))
604 printf("FAIL (\"%s\" instead of \"Cyan Toner\")\n",
605 text ? text : "(null)");
610 putenv("LC_CTYPE=fr");
611 putenv("LC_MESSAGES=fr");
613 fputs("ppdLocalizeMarkerName(fr cyan): ", stdout);
614 if ((text = ppdLocalizeMarkerName(ppd, "cyan")) != NULL &&
615 !strcmp(text, "La Toner Cyan"))
620 printf("FAIL (\"%s\" instead of \"La Toner Cyan\")\n",
621 text ? text : "(null)");
624 putenv("LANG=zh_TW");
625 putenv("LC_ALL=zh_TW");
626 putenv("LC_CTYPE=zh_TW");
627 putenv("LC_MESSAGES=zh_TW");
629 fputs("ppdLocalizeMarkerName(zh_TW cyan): ", stdout);
630 if ((text = ppdLocalizeMarkerName(ppd, "cyan")) != NULL &&
631 !strcmp(text, "Number 1 Cyan Toner"))
636 printf("FAIL (\"%s\" instead of \"Number 1 Cyan Toner\")\n",
637 text ? text : "(null)");
643 * Test new constraints...
646 fputs("ppdOpenFile(test2.ppd): ", stdout);
648 if ((ppd = ppdOpenFile("test2.ppd")) != NULL)
652 ppd_status_t err; /* Last error in file */
653 int line; /* Line number in file */
657 err = ppdLastError(&line);
659 printf("FAIL (%s on line %d)\n", ppdErrorString(err), line);
662 fputs("ppdMarkDefaults: ", stdout);
663 ppdMarkDefaults(ppd);
665 if ((conflicts = ppdConflicts(ppd)) == 0)
670 printf("FAIL (%d conflicts)\n", conflicts);
673 fputs("ppdEmitString (defaults): ", stdout);
674 if ((s = ppdEmitString(ppd, PPD_ORDER_ANY, 0.0)) != NULL &&
675 !strcmp(s, default2_code))
680 printf("FAIL (%d bytes instead of %d)\n", s ? (int)strlen(s) : 0,
681 (int)strlen(default2_code));
690 fputs("ppdConflicts(): ", stdout);
691 ppdMarkOption(ppd, "PageSize", "Env10");
692 ppdMarkOption(ppd, "InputSlot", "Envelope");
693 ppdMarkOption(ppd, "Quality", "Photo");
695 if ((conflicts = ppdConflicts(ppd)) == 1)
699 printf("FAIL (%d)\n", conflicts);
703 fputs("cupsResolveConflicts(Quality=Photo): ", stdout);
706 if (cupsResolveConflicts(ppd, "Quality", "Photo", &num_options,
709 printf("FAIL (%d options:", num_options);
710 for (i = 0; i < num_options; i ++)
711 printf(" %s=%s", options[i].name, options[i].value);
716 puts("PASS (Unable to resolve)");
717 cupsFreeOptions(num_options, options);
719 fputs("cupsResolveConflicts(No option/choice): ", stdout);
722 if (cupsResolveConflicts(ppd, NULL, NULL, &num_options, &options) &&
723 num_options == 1 && !_cups_strcasecmp(options->name, "Quality") &&
724 !_cups_strcasecmp(options->value, "Normal"))
726 else if (num_options > 0)
728 printf("FAIL (%d options:", num_options);
729 for (i = 0; i < num_options; i ++)
730 printf(" %s=%s", options[i].name, options[i].value);
736 puts("FAIL (Unable to resolve!)");
739 cupsFreeOptions(num_options, options);
741 fputs("cupsResolveConflicts(loop test): ", stdout);
742 ppdMarkOption(ppd, "PageSize", "A4");
743 ppdMarkOption(ppd, "InputSlot", "Tray");
744 ppdMarkOption(ppd, "Quality", "Photo");
747 if (!cupsResolveConflicts(ppd, NULL, NULL, &num_options, &options))
749 else if (num_options > 0)
751 printf("FAIL (%d options:", num_options);
752 for (i = 0; i < num_options; i ++)
753 printf(" %s=%s", options[i].name, options[i].value);
757 puts("FAIL (No conflicts!)");
759 fputs("ppdInstallableConflict(): ", stdout);
760 if (ppdInstallableConflict(ppd, "Duplex", "DuplexNoTumble") &&
761 !ppdInstallableConflict(ppd, "Duplex", "None"))
763 else if (!ppdInstallableConflict(ppd, "Duplex", "DuplexNoTumble"))
765 puts("FAIL (Duplex=DuplexNoTumble did not conflict)");
770 puts("FAIL (Duplex=None conflicted)");
778 ppdMarkDefaults(ppd);
780 fputs("ppdPageSizeLimits(default): ", stdout);
781 if (ppdPageSizeLimits(ppd, &minsize, &maxsize))
783 if (fabs(minsize.width - 36.0) > 0.001 || fabs(minsize.length - 36.0) > 0.001 ||
784 fabs(maxsize.width - 1080.0) > 0.001 || fabs(maxsize.length - 86400.0) > 0.001)
786 printf("FAIL (got min=%.0fx%.0f, max=%.0fx%.0f, "
787 "expected min=36x36, max=1080x86400)\n", minsize.width,
788 minsize.length, maxsize.width, maxsize.length);
796 puts("FAIL (returned 0)");
800 ppdMarkOption(ppd, "InputSlot", "Manual");
802 fputs("ppdPageSizeLimits(InputSlot=Manual): ", stdout);
803 if (ppdPageSizeLimits(ppd, &minsize, &maxsize))
805 if (fabs(minsize.width - 100.0) > 0.001 || fabs(minsize.length - 100.0) > 0.001 ||
806 fabs(maxsize.width - 1000.0) > 0.001 || fabs(maxsize.length - 1000.0) > 0.001)
808 printf("FAIL (got min=%.0fx%.0f, max=%.0fx%.0f, "
809 "expected min=100x100, max=1000x1000)\n", minsize.width,
810 minsize.length, maxsize.width, maxsize.length);
818 puts("FAIL (returned 0)");
822 ppdMarkOption(ppd, "Quality", "Photo");
824 fputs("ppdPageSizeLimits(Quality=Photo): ", stdout);
825 if (ppdPageSizeLimits(ppd, &minsize, &maxsize))
827 if (fabs(minsize.width - 200.0) > 0.001 || fabs(minsize.length - 200.0) > 0.001 ||
828 fabs(maxsize.width - 1000.0) > 0.001 || fabs(maxsize.length - 1000.0) > 0.001)
830 printf("FAIL (got min=%.0fx%.0f, max=%.0fx%.0f, "
831 "expected min=200x200, max=1000x1000)\n", minsize.width,
832 minsize.length, maxsize.width, maxsize.length);
840 puts("FAIL (returned 0)");
844 ppdMarkOption(ppd, "InputSlot", "Tray");
846 fputs("ppdPageSizeLimits(Quality=Photo): ", stdout);
847 if (ppdPageSizeLimits(ppd, &minsize, &maxsize))
849 if (fabs(minsize.width - 300.0) > 0.001 || fabs(minsize.length - 300.0) > 0.001 ||
850 fabs(maxsize.width - 1080.0) > 0.001 || fabs(maxsize.length - 86400.0) > 0.001)
852 printf("FAIL (got min=%.0fx%.0f, max=%.0fx%.0f, "
853 "expected min=300x300, max=1080x86400)\n", minsize.width,
854 minsize.length, maxsize.width, maxsize.length);
862 puts("FAIL (returned 0)");
866 else if (!strncmp(argv[1], "ipp://", 6) || !strncmp(argv[1], "ipps://", 7))
869 * ipp://... or ipps://...
872 http_t *http; /* Connection to printer */
873 ipp_t *request, /* Get-Printer-Attributes request */
874 *response; /* Get-Printer-Attributes response */
875 char scheme[32], /* URI scheme */
876 userpass[256], /* Username:password */
877 host[256], /* Hostname */
878 resource[256]; /* Resource path */
879 int port; /* Port number */
881 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)
883 printf("Bad URI \"%s\".\n", argv[1]);
887 http = httpConnect2(host, port, NULL, AF_UNSPEC, !strcmp(scheme, "ipps") ? HTTP_ENCRYPTION_ALWAYS : HTTP_ENCRYPTION_IF_REQUESTED, 1, 30000, NULL);
890 printf("Unable to connect to \"%s:%d\": %s\n", host, port, cupsLastErrorString());
894 request = ippNewRequest(IPP_OP_GET_PRINTER_ATTRIBUTES);
895 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "printer-uri", NULL, argv[1]);
896 response = cupsDoRequest(http, request, resource);
898 if (_ppdCreateFromIPP(buffer, sizeof(buffer), response))
899 printf("Created PPD: %s\n", buffer);
901 puts("Unable to create PPD.");
909 const char *filename; /* PPD filename */
910 struct stat fileinfo; /* File information */
913 if (strchr(argv[1], ':'))
919 if ((filename = cupsGetServerPPD(CUPS_HTTP_DEFAULT, argv[1])) == NULL)
921 printf("%s: %s\n", argv[1], cupsLastErrorString());
925 else if (!strncmp(argv[1], "-d", 2))
927 const char *printer; /* Printer name */
930 printer = argv[1] + 2;
935 puts("Usage: ./testppd -d printer");
939 filename = cupsGetPPD(printer);
943 printf("%s: %s\n", printer, cupsLastErrorString());
950 if (lstat(filename, &fileinfo))
952 printf("%s: %s\n", filename, strerror(errno));
956 if (S_ISLNK(fileinfo.st_mode))
958 char realfile[1024]; /* Real file path */
959 ssize_t realsize; /* Size of real file path */
962 if ((realsize = readlink(filename, realfile, sizeof(realfile) - 1)) < 0)
963 strlcpy(realfile, "Unknown", sizeof(realfile));
965 realfile[realsize] = '\0';
967 if (stat(realfile, &fileinfo))
968 printf("%s: symlink to \"%s\", %s\n", filename, realfile,
971 printf("%s: symlink to \"%s\", %ld bytes\n", filename, realfile,
972 (long)fileinfo.st_size);
975 printf("%s: regular file, %ld bytes\n", filename, (long)fileinfo.st_size);
977 if ((ppd = ppdOpenFile(filename)) == NULL)
979 ppd_status_t err; /* Last error in file */
980 int line; /* Line number in file */
984 err = ppdLastError(&line);
986 printf("%s: %s on line %d\n", argv[1], ppdErrorString(err), line);
990 int j, k; /* Looping vars */
991 ppd_group_t *group; /* Option group */
992 ppd_option_t *option; /* Option */
993 ppd_coption_t *coption; /* Custom option */
994 ppd_cparam_t *cparam; /* Custom parameter */
995 ppd_const_t *c; /* UIConstraints */
996 char lang[255], /* LANG environment variable */
997 lc_all[255], /* LC_ALL environment variable */
998 lc_ctype[255], /* LC_CTYPE environment variable */
999 lc_messages[255];/* LC_MESSAGES environment variable */
1004 snprintf(lang, sizeof(lang), "LANG=%s", argv[2]);
1006 snprintf(lc_all, sizeof(lc_all), "LC_ALL=%s", argv[2]);
1008 snprintf(lc_ctype, sizeof(lc_ctype), "LC_CTYPE=%s", argv[2]);
1010 snprintf(lc_messages, sizeof(lc_messages), "LC_MESSAGES=%s", argv[2]);
1011 putenv(lc_messages);
1015 ppdMarkDefaults(ppd);
1019 text = ppdLocalizeIPPReason(ppd, argv[3], NULL, buffer, sizeof(buffer));
1020 printf("ppdLocalizeIPPReason(%s)=%s\n", argv[3],
1021 text ? text : "(null)");
1022 return (text == NULL);
1025 for (i = ppd->num_groups, group = ppd->groups;
1029 printf("%s (%s):\n", group->name, group->text);
1031 for (j = group->num_options, option = group->options;
1035 printf(" %s (%s):\n", option->keyword, option->text);
1037 for (k = 0; k < option->num_choices; k ++)
1038 printf(" - %s%s (%s)\n",
1039 option->choices[k].marked ? "*" : "",
1040 option->choices[k].choice, option->choices[k].text);
1042 if ((coption = ppdFindCustomOption(ppd, option->keyword)) != NULL)
1044 for (cparam = (ppd_cparam_t *)cupsArrayFirst(coption->params);
1046 cparam = (ppd_cparam_t *)cupsArrayNext(coption->params))
1048 switch (cparam->type)
1050 case PPD_CUSTOM_CURVE :
1051 printf(" %s(%s): PPD_CUSTOM_CURVE (%g to %g)\n",
1052 cparam->name, cparam->text,
1053 cparam->minimum.custom_curve,
1054 cparam->maximum.custom_curve);
1057 case PPD_CUSTOM_INT :
1058 printf(" %s(%s): PPD_CUSTOM_INT (%d to %d)\n",
1059 cparam->name, cparam->text,
1060 cparam->minimum.custom_int,
1061 cparam->maximum.custom_int);
1064 case PPD_CUSTOM_INVCURVE :
1065 printf(" %s(%s): PPD_CUSTOM_INVCURVE (%g to %g)\n",
1066 cparam->name, cparam->text,
1067 cparam->minimum.custom_invcurve,
1068 cparam->maximum.custom_invcurve);
1071 case PPD_CUSTOM_PASSCODE :
1072 printf(" %s(%s): PPD_CUSTOM_PASSCODE (%d to %d)\n",
1073 cparam->name, cparam->text,
1074 cparam->minimum.custom_passcode,
1075 cparam->maximum.custom_passcode);
1078 case PPD_CUSTOM_PASSWORD :
1079 printf(" %s(%s): PPD_CUSTOM_PASSWORD (%d to %d)\n",
1080 cparam->name, cparam->text,
1081 cparam->minimum.custom_password,
1082 cparam->maximum.custom_password);
1085 case PPD_CUSTOM_POINTS :
1086 printf(" %s(%s): PPD_CUSTOM_POINTS (%g to %g)\n",
1087 cparam->name, cparam->text,
1088 cparam->minimum.custom_points,
1089 cparam->maximum.custom_points);
1092 case PPD_CUSTOM_REAL :
1093 printf(" %s(%s): PPD_CUSTOM_REAL (%g to %g)\n",
1094 cparam->name, cparam->text,
1095 cparam->minimum.custom_real,
1096 cparam->maximum.custom_real);
1099 case PPD_CUSTOM_STRING :
1100 printf(" %s(%s): PPD_CUSTOM_STRING (%d to %d)\n",
1101 cparam->name, cparam->text,
1102 cparam->minimum.custom_string,
1103 cparam->maximum.custom_string);
1112 for (i = ppd->num_sizes, size = ppd->sizes; i > 0; i --, size ++)
1113 printf(" %s = %gx%g, [%g %g %g %g]\n", size->name, size->width,
1114 size->length, size->left, size->bottom, size->right, size->top);
1116 puts("\nConstraints:");
1118 for (i = ppd->num_consts, c = ppd->consts; i > 0; i --, c ++)
1119 printf(" *UIConstraints: *%s %s *%s %s\n", c->option1, c->choice1,
1120 c->option2, c->choice2);
1121 if (ppd->num_consts == 0)
1122 puts(" NO CONSTRAINTS");
1126 for (i = 0; i < ppd->num_filters; i ++)
1127 printf(" %s\n", ppd->filters[i]);
1129 if (ppd->num_filters == 0)
1130 puts(" NO FILTERS");
1132 puts("\nAttributes:");
1134 for (attr = (ppd_attr_t *)cupsArrayFirst(ppd->sorted_attrs);
1136 attr = (ppd_attr_t *)cupsArrayNext(ppd->sorted_attrs))
1137 printf(" *%s %s/%s: \"%s\"\n", attr->name, attr->spec,
1138 attr->text, attr->value ? attr->value : "");
1140 puts("\nPPD Cache:");
1141 if ((pc = _ppdCacheCreateWithPPD(ppd)) == NULL)
1142 printf(" Unable to create: %s\n", cupsLastErrorString());
1145 _ppdCacheWriteFile(pc, "t.cache", NULL);
1146 puts(" Wrote t.cache.");
1150 if (!strncmp(argv[1], "-d", 2))
1155 if (getenv("MallocStackLogging") && getenv("MallocStackLoggingNoCompact"))
1157 char command[1024]; /* malloc_history command */
1159 snprintf(command, sizeof(command), "malloc_history %d -all_by_size",
1164 #endif /* __APPLE__ */
1173 * End of "$Id: testppd.c 12603 2015-05-06 01:42:51Z msweet $".