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"
24 #include "ppd-private.h"
39 static const char *default_code
=
41 "%%BeginFeature: *InstalledDuplexer False\n"
43 "} stopped cleartomark\n"
45 "%%BeginFeature: *PageRegion Letter\n"
48 "} stopped cleartomark\n"
50 "%%BeginFeature: *InputSlot Tray\n"
53 "} stopped cleartomark\n"
55 "%%BeginFeature: *OutputBin Tray1\n"
58 "} stopped cleartomark\n"
60 "%%BeginFeature: *MediaType Plain\n"
63 "} stopped cleartomark\n"
65 "%%BeginFeature: *IntOption None\n"
67 "} stopped cleartomark\n"
69 "%%BeginFeature: *StringOption None\n"
71 "} stopped cleartomark\n";
73 static const char *custom_code
=
75 "%%BeginFeature: *InstalledDuplexer False\n"
77 "} stopped cleartomark\n"
79 "%%BeginFeature: *InputSlot Tray\n"
82 "} stopped cleartomark\n"
84 "%%BeginFeature: *MediaType Plain\n"
87 "} stopped cleartomark\n"
89 "%%BeginFeature: *OutputBin Tray1\n"
92 "} stopped cleartomark\n"
94 "%%BeginFeature: *IntOption None\n"
96 "} stopped cleartomark\n"
98 "%%BeginFeature: *CustomStringOption True\n"
99 "(value\\0502\\051)\n"
101 "StringOption=Custom\n"
103 "} stopped cleartomark\n"
105 "%%BeginFeature: *CustomPageSize True\n"
113 "} stopped cleartomark\n";
115 static const char *default2_code
=
117 "%%BeginFeature: *InstalledDuplexer False\n"
119 "} stopped cleartomark\n"
121 "%%BeginFeature: *InputSlot Tray\n"
124 "} stopped cleartomark\n"
126 "%%BeginFeature: *Quality Normal\n"
129 "} stopped cleartomark\n"
131 "%%BeginFeature: *IntOption None\n"
133 "} stopped cleartomark\n"
135 "%%BeginFeature: *StringOption None\n"
137 "} stopped cleartomark\n";
141 * 'main()' - Main entry.
144 int /* O - Exit status */
145 main(int argc
, /* I - Number of command-line arguments */
146 char *argv
[]) /* I - Command-line arguments */
148 int i
; /* Looping var */
149 ppd_file_t
*ppd
; /* PPD file loaded from disk */
150 int status
; /* Status of tests (0 = success, 1 = fail) */
151 int conflicts
; /* Number of conflicts */
152 char *s
; /* String */
153 char buffer
[8192]; /* String buffer */
154 const char *text
, /* Localized text */
155 *val
; /* Option value */
156 int num_options
; /* Number of options */
157 cups_option_t
*options
; /* Options */
158 ppd_size_t minsize
, /* Minimum size */
159 maxsize
, /* Maximum size */
160 *size
; /* Current size */
161 ppd_attr_t
*attr
; /* Current attribute */
162 _ppd_cache_t
*pc
; /* PPD cache */
170 * Setup directories for locale stuff...
173 if (access("locale", 0))
175 mkdir("locale", 0777);
176 mkdir("locale/fr", 0777);
177 symlink("../../../locale/cups_fr.po", "locale/fr/cups_fr.po");
178 mkdir("locale/zh_TW", 0777);
179 symlink("../../../locale/cups_zh_TW.po", "locale/zh_TW/cups_zh_TW.po");
182 putenv("LOCALEDIR=locale");
183 putenv("SOFTWARE=CUPS");
186 * Do tests with test.ppd...
189 fputs("ppdOpenFile(test.ppd): ", stdout
);
191 if ((ppd
= _ppdOpenFile("test.ppd", _PPD_LOCALIZATION_ALL
)) != NULL
)
195 ppd_status_t err
; /* Last error in file */
196 int line
; /* Line number in file */
200 err
= ppdLastError(&line
);
202 printf("FAIL (%s on line %d)\n", ppdErrorString(err
), line
);
205 fputs("ppdFindAttr(wildcard): ", stdout
);
206 if ((attr
= ppdFindAttr(ppd
, "cupsTest", NULL
)) == NULL
)
209 puts("FAIL (not found)");
211 else if (strcmp(attr
->name
, "cupsTest") || strcmp(attr
->spec
, "Foo"))
214 printf("FAIL (got \"%s %s\")\n", attr
->name
, attr
->spec
);
219 fputs("ppdFindNextAttr(wildcard): ", stdout
);
220 if ((attr
= ppdFindNextAttr(ppd
, "cupsTest", NULL
)) == NULL
)
223 puts("FAIL (not found)");
225 else if (strcmp(attr
->name
, "cupsTest") || strcmp(attr
->spec
, "Bar"))
228 printf("FAIL (got \"%s %s\")\n", attr
->name
, attr
->spec
);
233 fputs("ppdFindAttr(Foo): ", stdout
);
234 if ((attr
= ppdFindAttr(ppd
, "cupsTest", "Foo")) == NULL
)
237 puts("FAIL (not found)");
239 else if (strcmp(attr
->name
, "cupsTest") || strcmp(attr
->spec
, "Foo"))
242 printf("FAIL (got \"%s %s\")\n", attr
->name
, attr
->spec
);
247 fputs("ppdFindNextAttr(Foo): ", stdout
);
248 if ((attr
= ppdFindNextAttr(ppd
, "cupsTest", "Foo")) != NULL
)
251 printf("FAIL (got \"%s %s\")\n", attr
->name
, attr
->spec
);
256 fputs("ppdMarkDefaults: ", stdout
);
257 ppdMarkDefaults(ppd
);
259 if ((conflicts
= ppdConflicts(ppd
)) == 0)
264 printf("FAIL (%d conflicts)\n", conflicts
);
267 fputs("ppdEmitString (defaults): ", stdout
);
268 if ((s
= ppdEmitString(ppd
, PPD_ORDER_ANY
, 0.0)) != NULL
&&
269 !strcmp(s
, default_code
))
274 printf("FAIL (%d bytes instead of %d)\n", s
? (int)strlen(s
) : 0,
275 (int)strlen(default_code
));
284 fputs("ppdEmitString (custom size and string): ", stdout
);
285 ppdMarkOption(ppd
, "PageSize", "Custom.400x500");
286 ppdMarkOption(ppd
, "StringOption", "{String1=\"value 1\" String2=value(2)}");
288 if ((s
= ppdEmitString(ppd
, PPD_ORDER_ANY
, 0.0)) != NULL
&&
289 !strcmp(s
, custom_code
))
294 printf("FAIL (%d bytes instead of %d)\n", s
? (int)strlen(s
) : 0,
295 (int)strlen(custom_code
));
305 * Test constraints...
308 fputs("cupsGetConflicts(InputSlot=Envelope): ", stdout
);
309 ppdMarkOption(ppd
, "PageSize", "Letter");
311 num_options
= cupsGetConflicts(ppd
, "InputSlot", "Envelope", &options
);
312 if (num_options
!= 2 ||
313 (val
= cupsGetOption("PageRegion", num_options
, options
)) == NULL
||
314 _cups_strcasecmp(val
, "Letter") ||
315 (val
= cupsGetOption("PageSize", num_options
, options
)) == NULL
||
316 _cups_strcasecmp(val
, "Letter"))
318 printf("FAIL (%d options:", num_options
);
319 for (i
= 0; i
< num_options
; i
++)
320 printf(" %s=%s", options
[i
].name
, options
[i
].value
);
327 fputs("ppdConflicts(): ", stdout
);
328 ppdMarkOption(ppd
, "InputSlot", "Envelope");
330 if ((conflicts
= ppdConflicts(ppd
)) == 2)
334 printf("FAIL (%d)\n", conflicts
);
338 fputs("cupsResolveConflicts(InputSlot=Envelope): ", stdout
);
341 if (!cupsResolveConflicts(ppd
, "InputSlot", "Envelope", &num_options
,
344 puts("FAIL (Unable to resolve)");
347 else if (num_options
!= 2 ||
348 !cupsGetOption("PageSize", num_options
, options
))
350 printf("FAIL (%d options:", num_options
);
351 for (i
= 0; i
< num_options
; i
++)
352 printf(" %s=%s", options
[i
].name
, options
[i
].value
);
357 puts("PASS (Resolved by changing PageSize)");
359 cupsFreeOptions(num_options
, options
);
361 fputs("cupsResolveConflicts(No option/choice): ", stdout
);
364 if (cupsResolveConflicts(ppd
, NULL
, NULL
, &num_options
, &options
) &&
365 num_options
== 1 && !_cups_strcasecmp(options
[0].name
, "InputSlot") &&
366 !_cups_strcasecmp(options
[0].value
, "Tray"))
367 puts("PASS (Resolved by changing InputSlot)");
368 else if (num_options
> 0)
370 printf("FAIL (%d options:", num_options
);
371 for (i
= 0; i
< num_options
; i
++)
372 printf(" %s=%s", options
[i
].name
, options
[i
].value
);
378 puts("FAIL (Unable to resolve)");
381 cupsFreeOptions(num_options
, options
);
383 fputs("ppdInstallableConflict(): ", stdout
);
384 if (ppdInstallableConflict(ppd
, "Duplex", "DuplexNoTumble") &&
385 !ppdInstallableConflict(ppd
, "Duplex", "None"))
387 else if (!ppdInstallableConflict(ppd
, "Duplex", "DuplexNoTumble"))
389 puts("FAIL (Duplex=DuplexNoTumble did not conflict)");
394 puts("FAIL (Duplex=None conflicted)");
402 fputs("ppdPageSizeLimits: ", stdout
);
403 if (ppdPageSizeLimits(ppd
, &minsize
, &maxsize
))
405 if (fabs(minsize
.width
- 36.0) > 0.001 || fabs(minsize
.length
- 36.0) > 0.001 ||
406 fabs(maxsize
.width
- 1080.0) > 0.001 || fabs(maxsize
.length
- 86400.0) > 0.001)
408 printf("FAIL (got min=%.3fx%.3f, max=%.3fx%.3f, "
409 "expected min=36x36, max=1080x86400)\n", minsize
.width
,
410 minsize
.length
, maxsize
.width
, maxsize
.length
);
418 puts("FAIL (returned 0)");
423 * cupsMarkOptions with PWG and IPP size names.
426 fputs("cupsMarkOptions(media=iso-a4): ", stdout
);
427 num_options
= cupsAddOption("media", "iso-a4", 0, &options
);
428 cupsMarkOptions(ppd
, num_options
, options
);
429 cupsFreeOptions(num_options
, options
);
431 size
= ppdPageSize(ppd
, NULL
);
432 if (!size
|| strcmp(size
->name
, "A4"))
434 printf("FAIL (%s)\n", size
? size
->name
: "unknown");
440 fputs("cupsMarkOptions(media=na_letter_8.5x11in): ", stdout
);
441 num_options
= cupsAddOption("media", "na_letter_8.5x11in", 0, &options
);
442 cupsMarkOptions(ppd
, num_options
, options
);
443 cupsFreeOptions(num_options
, options
);
445 size
= ppdPageSize(ppd
, NULL
);
446 if (!size
|| strcmp(size
->name
, "Letter"))
448 printf("FAIL (%s)\n", size
? size
->name
: "unknown");
454 fputs("cupsMarkOptions(media=oe_letter-fullbleed_8.5x11in): ", stdout
);
455 num_options
= cupsAddOption("media", "oe_letter-fullbleed_8.5x11in", 0,
457 cupsMarkOptions(ppd
, num_options
, options
);
458 cupsFreeOptions(num_options
, options
);
460 size
= ppdPageSize(ppd
, NULL
);
461 if (!size
|| strcmp(size
->name
, "Letter.Fullbleed"))
463 printf("FAIL (%s)\n", size
? size
->name
: "unknown");
469 fputs("cupsMarkOptions(media=A4): ", stdout
);
470 num_options
= cupsAddOption("media", "A4", 0, &options
);
471 cupsMarkOptions(ppd
, num_options
, options
);
472 cupsFreeOptions(num_options
, options
);
474 size
= ppdPageSize(ppd
, NULL
);
475 if (!size
|| strcmp(size
->name
, "A4"))
477 printf("FAIL (%s)\n", size
? size
->name
: "unknown");
487 fputs("cupsMarkOptions(media=Custom.8x10in): ", stdout
);
488 num_options
= cupsAddOption("media", "Custom.8x10in", 0, &options
);
489 cupsMarkOptions(ppd
, num_options
, options
);
490 cupsFreeOptions(num_options
, options
);
492 size
= ppdPageSize(ppd
, NULL
);
493 if (!size
|| strcmp(size
->name
, "Custom") ||
494 fabs(size
->width
- 576.0) > 0.001 ||
495 fabs(size
->length
- 720.0) > 0.001)
497 printf("FAIL (%s - %gx%g)\n", size
? size
->name
: "unknown",
498 size
? size
->width
: 0.0, size
? size
->length
: 0.0);
505 * Test localization...
508 fputs("ppdLocalizeIPPReason(text): ", stdout
);
509 if (ppdLocalizeIPPReason(ppd
, "foo", NULL
, buffer
, sizeof(buffer
)) &&
510 !strcmp(buffer
, "Foo Reason"))
515 printf("FAIL (\"%s\" instead of \"Foo Reason\")\n", buffer
);
518 fputs("ppdLocalizeIPPReason(http): ", stdout
);
519 if (ppdLocalizeIPPReason(ppd
, "foo", "http", buffer
, sizeof(buffer
)) &&
520 !strcmp(buffer
, "http://foo/bar.html"))
525 printf("FAIL (\"%s\" instead of \"http://foo/bar.html\")\n", buffer
);
528 fputs("ppdLocalizeIPPReason(help): ", stdout
);
529 if (ppdLocalizeIPPReason(ppd
, "foo", "help", buffer
, sizeof(buffer
)) &&
530 !strcmp(buffer
, "help:anchor='foo'%20bookID=Vendor%20Help"))
535 printf("FAIL (\"%s\" instead of \"help:anchor='foo'%%20bookID=Vendor%%20Help\")\n", buffer
);
538 fputs("ppdLocalizeIPPReason(file): ", stdout
);
539 if (ppdLocalizeIPPReason(ppd
, "foo", "file", buffer
, sizeof(buffer
)) &&
540 !strcmp(buffer
, "/help/foo/bar.html"))
545 printf("FAIL (\"%s\" instead of \"/help/foo/bar.html\")\n", buffer
);
550 putenv("LC_CTYPE=fr");
551 putenv("LC_MESSAGES=fr");
553 fputs("ppdLocalizeIPPReason(fr text): ", stdout
);
554 if (ppdLocalizeIPPReason(ppd
, "foo", NULL
, buffer
, sizeof(buffer
)) &&
555 !strcmp(buffer
, "La Long Foo Reason"))
560 printf("FAIL (\"%s\" instead of \"La Long Foo Reason\")\n", buffer
);
563 putenv("LANG=zh_TW");
564 putenv("LC_ALL=zh_TW");
565 putenv("LC_CTYPE=zh_TW");
566 putenv("LC_MESSAGES=zh_TW");
568 fputs("ppdLocalizeIPPReason(zh_TW text): ", stdout
);
569 if (ppdLocalizeIPPReason(ppd
, "foo", NULL
, buffer
, sizeof(buffer
)) &&
570 !strcmp(buffer
, "Number 1 Foo Reason"))
575 printf("FAIL (\"%s\" instead of \"Number 1 Foo Reason\")\n", buffer
);
579 * cupsMarkerName localization...
584 putenv("LC_CTYPE=en");
585 putenv("LC_MESSAGES=en");
587 fputs("ppdLocalizeMarkerName(bogus): ", stdout
);
589 if ((text
= ppdLocalizeMarkerName(ppd
, "bogus")) != NULL
)
592 printf("FAIL (\"%s\" instead of NULL)\n", text
);
597 fputs("ppdLocalizeMarkerName(cyan): ", stdout
);
599 if ((text
= ppdLocalizeMarkerName(ppd
, "cyan")) != NULL
&&
600 !strcmp(text
, "Cyan Toner"))
605 printf("FAIL (\"%s\" instead of \"Cyan Toner\")\n",
606 text
? text
: "(null)");
611 putenv("LC_CTYPE=fr");
612 putenv("LC_MESSAGES=fr");
614 fputs("ppdLocalizeMarkerName(fr cyan): ", stdout
);
615 if ((text
= ppdLocalizeMarkerName(ppd
, "cyan")) != NULL
&&
616 !strcmp(text
, "La Toner Cyan"))
621 printf("FAIL (\"%s\" instead of \"La Toner Cyan\")\n",
622 text
? text
: "(null)");
625 putenv("LANG=zh_TW");
626 putenv("LC_ALL=zh_TW");
627 putenv("LC_CTYPE=zh_TW");
628 putenv("LC_MESSAGES=zh_TW");
630 fputs("ppdLocalizeMarkerName(zh_TW cyan): ", stdout
);
631 if ((text
= ppdLocalizeMarkerName(ppd
, "cyan")) != NULL
&&
632 !strcmp(text
, "Number 1 Cyan Toner"))
637 printf("FAIL (\"%s\" instead of \"Number 1 Cyan Toner\")\n",
638 text
? text
: "(null)");
644 * Test new constraints...
647 fputs("ppdOpenFile(test2.ppd): ", stdout
);
649 if ((ppd
= ppdOpenFile("test2.ppd")) != NULL
)
653 ppd_status_t err
; /* Last error in file */
654 int line
; /* Line number in file */
658 err
= ppdLastError(&line
);
660 printf("FAIL (%s on line %d)\n", ppdErrorString(err
), line
);
663 fputs("ppdMarkDefaults: ", stdout
);
664 ppdMarkDefaults(ppd
);
666 if ((conflicts
= ppdConflicts(ppd
)) == 0)
671 printf("FAIL (%d conflicts)\n", conflicts
);
674 fputs("ppdEmitString (defaults): ", stdout
);
675 if ((s
= ppdEmitString(ppd
, PPD_ORDER_ANY
, 0.0)) != NULL
&&
676 !strcmp(s
, default2_code
))
681 printf("FAIL (%d bytes instead of %d)\n", s
? (int)strlen(s
) : 0,
682 (int)strlen(default2_code
));
691 fputs("ppdConflicts(): ", stdout
);
692 ppdMarkOption(ppd
, "PageSize", "Env10");
693 ppdMarkOption(ppd
, "InputSlot", "Envelope");
694 ppdMarkOption(ppd
, "Quality", "Photo");
696 if ((conflicts
= ppdConflicts(ppd
)) == 1)
700 printf("FAIL (%d)\n", conflicts
);
704 fputs("cupsResolveConflicts(Quality=Photo): ", stdout
);
707 if (cupsResolveConflicts(ppd
, "Quality", "Photo", &num_options
,
710 printf("FAIL (%d options:", num_options
);
711 for (i
= 0; i
< num_options
; i
++)
712 printf(" %s=%s", options
[i
].name
, options
[i
].value
);
717 puts("PASS (Unable to resolve)");
718 cupsFreeOptions(num_options
, options
);
720 fputs("cupsResolveConflicts(No option/choice): ", stdout
);
723 if (cupsResolveConflicts(ppd
, NULL
, NULL
, &num_options
, &options
) &&
724 num_options
== 1 && !_cups_strcasecmp(options
->name
, "Quality") &&
725 !_cups_strcasecmp(options
->value
, "Normal"))
727 else if (num_options
> 0)
729 printf("FAIL (%d options:", num_options
);
730 for (i
= 0; i
< num_options
; i
++)
731 printf(" %s=%s", options
[i
].name
, options
[i
].value
);
737 puts("FAIL (Unable to resolve!)");
740 cupsFreeOptions(num_options
, options
);
742 fputs("cupsResolveConflicts(loop test): ", stdout
);
743 ppdMarkOption(ppd
, "PageSize", "A4");
744 ppdMarkOption(ppd
, "InputSlot", "Tray");
745 ppdMarkOption(ppd
, "Quality", "Photo");
748 if (!cupsResolveConflicts(ppd
, NULL
, NULL
, &num_options
, &options
))
750 else if (num_options
> 0)
752 printf("FAIL (%d options:", num_options
);
753 for (i
= 0; i
< num_options
; i
++)
754 printf(" %s=%s", options
[i
].name
, options
[i
].value
);
758 puts("FAIL (No conflicts!)");
760 fputs("ppdInstallableConflict(): ", stdout
);
761 if (ppdInstallableConflict(ppd
, "Duplex", "DuplexNoTumble") &&
762 !ppdInstallableConflict(ppd
, "Duplex", "None"))
764 else if (!ppdInstallableConflict(ppd
, "Duplex", "DuplexNoTumble"))
766 puts("FAIL (Duplex=DuplexNoTumble did not conflict)");
771 puts("FAIL (Duplex=None conflicted)");
779 ppdMarkDefaults(ppd
);
781 fputs("ppdPageSizeLimits(default): ", stdout
);
782 if (ppdPageSizeLimits(ppd
, &minsize
, &maxsize
))
784 if (fabs(minsize
.width
- 36.0) > 0.001 || fabs(minsize
.length
- 36.0) > 0.001 ||
785 fabs(maxsize
.width
- 1080.0) > 0.001 || fabs(maxsize
.length
- 86400.0) > 0.001)
787 printf("FAIL (got min=%.0fx%.0f, max=%.0fx%.0f, "
788 "expected min=36x36, max=1080x86400)\n", minsize
.width
,
789 minsize
.length
, maxsize
.width
, maxsize
.length
);
797 puts("FAIL (returned 0)");
801 ppdMarkOption(ppd
, "InputSlot", "Manual");
803 fputs("ppdPageSizeLimits(InputSlot=Manual): ", stdout
);
804 if (ppdPageSizeLimits(ppd
, &minsize
, &maxsize
))
806 if (fabs(minsize
.width
- 100.0) > 0.001 || fabs(minsize
.length
- 100.0) > 0.001 ||
807 fabs(maxsize
.width
- 1000.0) > 0.001 || fabs(maxsize
.length
- 1000.0) > 0.001)
809 printf("FAIL (got min=%.0fx%.0f, max=%.0fx%.0f, "
810 "expected min=100x100, max=1000x1000)\n", minsize
.width
,
811 minsize
.length
, maxsize
.width
, maxsize
.length
);
819 puts("FAIL (returned 0)");
823 ppdMarkOption(ppd
, "Quality", "Photo");
825 fputs("ppdPageSizeLimits(Quality=Photo): ", stdout
);
826 if (ppdPageSizeLimits(ppd
, &minsize
, &maxsize
))
828 if (fabs(minsize
.width
- 200.0) > 0.001 || fabs(minsize
.length
- 200.0) > 0.001 ||
829 fabs(maxsize
.width
- 1000.0) > 0.001 || fabs(maxsize
.length
- 1000.0) > 0.001)
831 printf("FAIL (got min=%.0fx%.0f, max=%.0fx%.0f, "
832 "expected min=200x200, max=1000x1000)\n", minsize
.width
,
833 minsize
.length
, maxsize
.width
, maxsize
.length
);
841 puts("FAIL (returned 0)");
845 ppdMarkOption(ppd
, "InputSlot", "Tray");
847 fputs("ppdPageSizeLimits(Quality=Photo): ", stdout
);
848 if (ppdPageSizeLimits(ppd
, &minsize
, &maxsize
))
850 if (fabs(minsize
.width
- 300.0) > 0.001 || fabs(minsize
.length
- 300.0) > 0.001 ||
851 fabs(maxsize
.width
- 1080.0) > 0.001 || fabs(maxsize
.length
- 86400.0) > 0.001)
853 printf("FAIL (got min=%.0fx%.0f, max=%.0fx%.0f, "
854 "expected min=300x300, max=1080x86400)\n", minsize
.width
,
855 minsize
.length
, maxsize
.width
, maxsize
.length
);
863 puts("FAIL (returned 0)");
867 else if (!strncmp(argv
[1], "ipp://", 6) || !strncmp(argv
[1], "ipps://", 7))
870 * ipp://... or ipps://...
873 http_t
*http
; /* Connection to printer */
874 ipp_t
*request
, /* Get-Printer-Attributes request */
875 *response
; /* Get-Printer-Attributes response */
876 char scheme
[32], /* URI scheme */
877 userpass
[256], /* Username:password */
878 host
[256], /* Hostname */
879 resource
[256]; /* Resource path */
880 int port
; /* Port number */
882 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
)
884 printf("Bad URI \"%s\".\n", argv
[1]);
888 http
= httpConnect2(host
, port
, NULL
, AF_UNSPEC
, !strcmp(scheme
, "ipps") ? HTTP_ENCRYPTION_ALWAYS
: HTTP_ENCRYPTION_IF_REQUESTED
, 1, 30000, NULL
);
891 printf("Unable to connect to \"%s:%d\": %s\n", host
, port
, cupsLastErrorString());
895 request
= ippNewRequest(IPP_OP_GET_PRINTER_ATTRIBUTES
);
896 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_URI
, "printer-uri", NULL
, argv
[1]);
897 response
= cupsDoRequest(http
, request
, resource
);
899 if (_ppdCreateFromIPP(buffer
, sizeof(buffer
), response
))
900 printf("Created PPD: %s\n", buffer
);
902 puts("Unable to create PPD.");
910 const char *filename
; /* PPD filename */
911 struct stat fileinfo
; /* File information */
914 if (strchr(argv
[1], ':'))
920 if ((filename
= cupsGetServerPPD(CUPS_HTTP_DEFAULT
, argv
[1])) == NULL
)
922 printf("%s: %s\n", argv
[1], cupsLastErrorString());
926 else if (!strncmp(argv
[1], "-d", 2))
928 const char *printer
; /* Printer name */
931 printer
= argv
[1] + 2;
936 puts("Usage: ./testppd -d printer");
940 filename
= cupsGetPPD(printer
);
944 printf("%s: %s\n", printer
, cupsLastErrorString());
951 if (lstat(filename
, &fileinfo
))
953 printf("%s: %s\n", filename
, strerror(errno
));
957 if (S_ISLNK(fileinfo
.st_mode
))
959 char realfile
[1024]; /* Real file path */
960 ssize_t realsize
; /* Size of real file path */
963 if ((realsize
= readlink(filename
, realfile
, sizeof(realfile
) - 1)) < 0)
964 strlcpy(realfile
, "Unknown", sizeof(realfile
));
966 realfile
[realsize
] = '\0';
968 if (stat(realfile
, &fileinfo
))
969 printf("%s: symlink to \"%s\", %s\n", filename
, realfile
,
972 printf("%s: symlink to \"%s\", %ld bytes\n", filename
, realfile
,
973 (long)fileinfo
.st_size
);
976 printf("%s: regular file, %ld bytes\n", filename
, (long)fileinfo
.st_size
);
978 if ((ppd
= ppdOpenFile(filename
)) == NULL
)
980 ppd_status_t err
; /* Last error in file */
981 int line
; /* Line number in file */
985 err
= ppdLastError(&line
);
987 printf("%s: %s on line %d\n", argv
[1], ppdErrorString(err
), line
);
991 int j
, k
; /* Looping vars */
992 ppd_group_t
*group
; /* Option group */
993 ppd_option_t
*option
; /* Option */
994 ppd_coption_t
*coption
; /* Custom option */
995 ppd_cparam_t
*cparam
; /* Custom parameter */
996 ppd_const_t
*c
; /* UIConstraints */
997 char lang
[255], /* LANG environment variable */
998 lc_all
[255], /* LC_ALL environment variable */
999 lc_ctype
[255], /* LC_CTYPE environment variable */
1000 lc_messages
[255];/* LC_MESSAGES environment variable */
1005 snprintf(lang
, sizeof(lang
), "LANG=%s", argv
[2]);
1007 snprintf(lc_all
, sizeof(lc_all
), "LC_ALL=%s", argv
[2]);
1009 snprintf(lc_ctype
, sizeof(lc_ctype
), "LC_CTYPE=%s", argv
[2]);
1011 snprintf(lc_messages
, sizeof(lc_messages
), "LC_MESSAGES=%s", argv
[2]);
1012 putenv(lc_messages
);
1016 ppdMarkDefaults(ppd
);
1020 text
= ppdLocalizeIPPReason(ppd
, argv
[3], NULL
, buffer
, sizeof(buffer
));
1021 printf("ppdLocalizeIPPReason(%s)=%s\n", argv
[3],
1022 text
? text
: "(null)");
1023 return (text
== NULL
);
1026 for (i
= ppd
->num_groups
, group
= ppd
->groups
;
1030 printf("%s (%s):\n", group
->name
, group
->text
);
1032 for (j
= group
->num_options
, option
= group
->options
;
1036 printf(" %s (%s):\n", option
->keyword
, option
->text
);
1038 for (k
= 0; k
< option
->num_choices
; k
++)
1039 printf(" - %s%s (%s)\n",
1040 option
->choices
[k
].marked
? "*" : "",
1041 option
->choices
[k
].choice
, option
->choices
[k
].text
);
1043 if ((coption
= ppdFindCustomOption(ppd
, option
->keyword
)) != NULL
)
1045 for (cparam
= (ppd_cparam_t
*)cupsArrayFirst(coption
->params
);
1047 cparam
= (ppd_cparam_t
*)cupsArrayNext(coption
->params
))
1049 switch (cparam
->type
)
1051 case PPD_CUSTOM_CURVE
:
1052 printf(" %s(%s): PPD_CUSTOM_CURVE (%g to %g)\n",
1053 cparam
->name
, cparam
->text
,
1054 cparam
->minimum
.custom_curve
,
1055 cparam
->maximum
.custom_curve
);
1058 case PPD_CUSTOM_INT
:
1059 printf(" %s(%s): PPD_CUSTOM_INT (%d to %d)\n",
1060 cparam
->name
, cparam
->text
,
1061 cparam
->minimum
.custom_int
,
1062 cparam
->maximum
.custom_int
);
1065 case PPD_CUSTOM_INVCURVE
:
1066 printf(" %s(%s): PPD_CUSTOM_INVCURVE (%g to %g)\n",
1067 cparam
->name
, cparam
->text
,
1068 cparam
->minimum
.custom_invcurve
,
1069 cparam
->maximum
.custom_invcurve
);
1072 case PPD_CUSTOM_PASSCODE
:
1073 printf(" %s(%s): PPD_CUSTOM_PASSCODE (%d to %d)\n",
1074 cparam
->name
, cparam
->text
,
1075 cparam
->minimum
.custom_passcode
,
1076 cparam
->maximum
.custom_passcode
);
1079 case PPD_CUSTOM_PASSWORD
:
1080 printf(" %s(%s): PPD_CUSTOM_PASSWORD (%d to %d)\n",
1081 cparam
->name
, cparam
->text
,
1082 cparam
->minimum
.custom_password
,
1083 cparam
->maximum
.custom_password
);
1086 case PPD_CUSTOM_POINTS
:
1087 printf(" %s(%s): PPD_CUSTOM_POINTS (%g to %g)\n",
1088 cparam
->name
, cparam
->text
,
1089 cparam
->minimum
.custom_points
,
1090 cparam
->maximum
.custom_points
);
1093 case PPD_CUSTOM_REAL
:
1094 printf(" %s(%s): PPD_CUSTOM_REAL (%g to %g)\n",
1095 cparam
->name
, cparam
->text
,
1096 cparam
->minimum
.custom_real
,
1097 cparam
->maximum
.custom_real
);
1100 case PPD_CUSTOM_STRING
:
1101 printf(" %s(%s): PPD_CUSTOM_STRING (%d to %d)\n",
1102 cparam
->name
, cparam
->text
,
1103 cparam
->minimum
.custom_string
,
1104 cparam
->maximum
.custom_string
);
1113 for (i
= ppd
->num_sizes
, size
= ppd
->sizes
; i
> 0; i
--, size
++)
1114 printf(" %s = %gx%g, [%g %g %g %g]\n", size
->name
, size
->width
,
1115 size
->length
, size
->left
, size
->bottom
, size
->right
, size
->top
);
1117 puts("\nConstraints:");
1119 for (i
= ppd
->num_consts
, c
= ppd
->consts
; i
> 0; i
--, c
++)
1120 printf(" *UIConstraints: *%s %s *%s %s\n", c
->option1
, c
->choice1
,
1121 c
->option2
, c
->choice2
);
1122 if (ppd
->num_consts
== 0)
1123 puts(" NO CONSTRAINTS");
1127 for (i
= 0; i
< ppd
->num_filters
; i
++)
1128 printf(" %s\n", ppd
->filters
[i
]);
1130 if (ppd
->num_filters
== 0)
1131 puts(" NO FILTERS");
1133 puts("\nAttributes:");
1135 for (attr
= (ppd_attr_t
*)cupsArrayFirst(ppd
->sorted_attrs
);
1137 attr
= (ppd_attr_t
*)cupsArrayNext(ppd
->sorted_attrs
))
1138 printf(" *%s %s/%s: \"%s\"\n", attr
->name
, attr
->spec
,
1139 attr
->text
, attr
->value
? attr
->value
: "");
1141 puts("\nPPD Cache:");
1142 if ((pc
= _ppdCacheCreateWithPPD(ppd
)) == NULL
)
1143 printf(" Unable to create: %s\n", cupsLastErrorString());
1146 _ppdCacheWriteFile(pc
, "t.cache", NULL
);
1147 puts(" Wrote t.cache.");
1151 if (!strncmp(argv
[1], "-d", 2))
1156 if (getenv("MallocStackLogging") && getenv("MallocStackLoggingNoCompact"))
1158 char command
[1024]; /* malloc_history command */
1160 snprintf(command
, sizeof(command
), "malloc_history %d -all_by_size",
1165 #endif /* __APPLE__ */