]>
git.ipfire.org Git - thirdparty/cups.git/blob - cups/testppd.c
2 * "$Id: testppd.c 7633 2008-06-10 23:07:29Z mike $"
4 * PPD test program for the Common UNIX Printing System (CUPS).
6 * Copyright 2007-2008 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 * main() - Main entry.
23 * Include necessary headers...
28 #include <cups/string.h>
44 static const char *default_code
=
46 "%%BeginFeature: *InstalledDuplexer False\n"
48 "} stopped cleartomark\n"
50 "%%BeginFeature: *PageRegion Letter\n"
53 "} stopped cleartomark\n"
55 "%%BeginFeature: *InputSlot Tray\n"
58 "} stopped cleartomark\n"
60 "%%BeginFeature: *IntOption None\n"
62 "} stopped cleartomark\n"
64 "%%BeginFeature: *StringOption None\n"
66 "} stopped cleartomark\n";
68 static const char *custom_code
=
70 "%%BeginFeature: *InstalledDuplexer False\n"
72 "} stopped cleartomark\n"
74 "%%BeginFeature: *InputSlot Tray\n"
77 "} stopped cleartomark\n"
79 "%%BeginFeature: *IntOption None\n"
81 "} stopped cleartomark\n"
83 "%%BeginFeature: *CustomStringOption True\n"
84 "(value\\0502\\051)\n"
86 "StringOption=Custom\n"
88 "} stopped cleartomark\n"
90 "%%BeginFeature: *CustomPageSize True\n"
98 "} stopped cleartomark\n";
102 * 'main()' - Main entry.
105 int /* O - Exit status */
106 main(int argc
, /* I - Number of command-line arguments */
107 char *argv
[]) /* I - Command-line arguments */
109 int i
; /* Looping var */
110 ppd_file_t
*ppd
; /* PPD file loaded from disk */
111 int status
; /* Status of tests (0 = success, 1 = fail) */
112 int conflicts
; /* Number of conflicts */
113 char *s
; /* String */
114 char buffer
[8192]; /* String buffer */
115 const char *text
; /* Localized text */
116 int num_options
; /* Number of options */
117 cups_option_t
*options
; /* Options */
118 ppd_size_t minsize
, /* Minimum size */
119 maxsize
; /* Maximum size */
127 * Setup directories for locale stuff...
130 if (access("locale", 0))
132 mkdir("locale", 0777);
133 mkdir("locale/fr", 0777);
134 symlink("../../../locale/cups_fr.po", "locale/fr/cups_fr.po");
135 mkdir("locale/zh_TW", 0777);
136 symlink("../../../locale/cups_zh_TW.po", "locale/zh_TW/cups_zh_TW.po");
139 putenv("LOCALEDIR=locale");
142 * Do tests with test.ppd...
145 fputs("ppdOpenFile(test.ppd): ", stdout
);
147 if ((ppd
= ppdOpenFile("test.ppd")) != NULL
)
151 ppd_status_t err
; /* Last error in file */
152 int line
; /* Line number in file */
156 err
= ppdLastError(&line
);
158 printf("FAIL (%s on line %d)\n", ppdErrorString(err
), line
);
161 fputs("ppdMarkDefaults: ", stdout
);
162 ppdMarkDefaults(ppd
);
164 if ((conflicts
= ppdConflicts(ppd
)) == 0)
169 printf("FAIL (%d conflicts)\n", conflicts
);
172 fputs("ppdEmitString (defaults): ", stdout
);
173 if ((s
= ppdEmitString(ppd
, PPD_ORDER_ANY
, 0.0)) != NULL
&&
174 !strcmp(s
, default_code
))
179 printf("FAIL (%d bytes instead of %d)\n", s
? (int)strlen(s
) : 0,
180 (int)strlen(default_code
));
189 fputs("ppdEmitString (custom size and string): ", stdout
);
190 ppdMarkOption(ppd
, "PageSize", "Custom.400x500");
191 ppdMarkOption(ppd
, "StringOption", "{String1=\"value 1\" String2=value(2)}");
193 if ((s
= ppdEmitString(ppd
, PPD_ORDER_ANY
, 0.0)) != NULL
&&
194 !strcmp(s
, custom_code
))
199 printf("FAIL (%d bytes instead of %d)\n", s
? (int)strlen(s
) : 0,
200 (int)strlen(custom_code
));
210 * Test constraints...
213 fputs("ppdConflicts(): ", stdout
);
214 ppdMarkOption(ppd
, "PageSize", "Letter");
215 ppdMarkOption(ppd
, "InputSlot", "Envelope");
217 if ((conflicts
= ppdConflicts(ppd
)) == 2)
221 printf("FAIL (%d)\n", conflicts
);
225 fputs("cupsResolveConflicts(InputSlot=Envelope): ", stdout
);
228 if (cupsResolveConflicts(ppd
, "InputSlot", "Envelope", &num_options
,
231 puts("FAIL (Resolved but shouldn't be able to!)");
235 puts("PASS (Unable to resolve)");
236 cupsFreeOptions(num_options
, options
);
238 fputs("cupsResolveConflicts(No option/choice): ", stdout
);
241 if (cupsResolveConflicts(ppd
, NULL
, NULL
, &num_options
, &options
) &&
242 num_options
== 1 && !strcasecmp(options
[0].name
, "InputSlot") &&
243 !strcasecmp(options
[0].value
, "Manual"))
244 puts("PASS (Resolved)");
245 else if (num_options
> 0)
247 printf("FAIL (%d options:", num_options
);
248 for (i
= 0; i
< num_options
; i
++)
249 printf(" %s=%s", options
[i
].name
, options
[i
].value
);
255 puts("FAIL (Unable to resolve)");
258 cupsFreeOptions(num_options
, options
);
260 fputs("ppdInstallableConflict(): ", stdout
);
261 if (ppdInstallableConflict(ppd
, "Duplex", "DuplexNoTumble") &&
262 !ppdInstallableConflict(ppd
, "Duplex", "None"))
264 else if (!ppdInstallableConflict(ppd
, "Duplex", "DuplexNoTumble"))
266 puts("FAIL (Duplex=DuplexNoTumble did not conflict)");
271 puts("FAIL (Duplex=None conflicted)");
279 fputs("ppdPageSizeLimits: ", stdout
);
280 if (ppdPageSizeLimits(ppd
, &minsize
, &maxsize
))
282 if (minsize
.width
!= 36 || minsize
.length
!= 36 ||
283 maxsize
.width
!= 1080 || maxsize
.length
!= 86400)
285 printf("FAIL (got min=%.0fx%.0f, max=%.0fx%.0f, "
286 "expected min=36x36, max=1080x86400)\n", minsize
.width
,
287 minsize
.length
, maxsize
.width
, maxsize
.length
);
295 puts("FAIL (returned 0)");
300 * Test localization...
303 fputs("ppdLocalizeIPPReason(text): ", stdout
);
304 if (ppdLocalizeIPPReason(ppd
, "foo", NULL
, buffer
, sizeof(buffer
)) &&
305 !strcmp(buffer
, "Foo Reason"))
310 printf("FAIL (\"%s\" instead of \"Foo Reason\")\n", buffer
);
313 fputs("ppdLocalizeIPPReason(http): ", stdout
);
314 if (ppdLocalizeIPPReason(ppd
, "foo", "http", buffer
, sizeof(buffer
)) &&
315 !strcmp(buffer
, "http://foo/bar.html"))
320 printf("FAIL (\"%s\" instead of \"http://foo/bar.html\")\n", buffer
);
323 fputs("ppdLocalizeIPPReason(help): ", stdout
);
324 if (ppdLocalizeIPPReason(ppd
, "foo", "help", buffer
, sizeof(buffer
)) &&
325 !strcmp(buffer
, "help:anchor='foo'%20bookID=Vendor%20Help"))
330 printf("FAIL (\"%s\" instead of \"help:anchor='foo'%%20bookID=Vendor%%20Help\")\n", buffer
);
333 fputs("ppdLocalizeIPPReason(file): ", stdout
);
334 if (ppdLocalizeIPPReason(ppd
, "foo", "file", buffer
, sizeof(buffer
)) &&
335 !strcmp(buffer
, "/help/foo/bar.html"))
340 printf("FAIL (\"%s\" instead of \"/help/foo/bar.html\")\n", buffer
);
345 putenv("LC_CTYPE=fr");
346 putenv("LC_MESSAGES=fr");
348 fputs("ppdLocalizeIPPReason(fr text): ", stdout
);
349 if (ppdLocalizeIPPReason(ppd
, "foo", NULL
, buffer
, sizeof(buffer
)) &&
350 !strcmp(buffer
, "La Long Foo Reason"))
355 printf("FAIL (\"%s\" instead of \"La Long Foo Reason\")\n", buffer
);
358 putenv("LANG=zh_TW");
359 putenv("LC_ALL=zh_TW");
360 putenv("LC_CTYPE=zh_TW");
361 putenv("LC_MESSAGES=zh_TW");
363 fputs("ppdLocalizeIPPReason(zh_TW text): ", stdout
);
364 if (ppdLocalizeIPPReason(ppd
, "foo", NULL
, buffer
, sizeof(buffer
)) &&
365 !strcmp(buffer
, "Number 1 Foo Reason"))
370 printf("FAIL (\"%s\" instead of \"Number 1 Foo Reason\")\n", buffer
);
374 * cupsMarkerName localization...
379 putenv("LC_CTYPE=en");
380 putenv("LC_MESSAGES=en");
382 fputs("ppdLocalizeMarkerName(bogus): ", stdout
);
384 if ((text
= ppdLocalizeMarkerName(ppd
, "bogus")) != NULL
)
387 printf("FAIL (\"%s\" instead of NULL)\n", text
);
392 fputs("ppdLocalizeMarkerName(cyan): ", stdout
);
394 if ((text
= ppdLocalizeMarkerName(ppd
, "cyan")) != NULL
&&
395 !strcmp(text
, "Cyan Toner"))
400 printf("FAIL (\"%s\" instead of \"Cyan Toner\")\n",
401 text
? text
: "(null)");
406 putenv("LC_CTYPE=fr");
407 putenv("LC_MESSAGES=fr");
409 fputs("ppdLocalizeMarkerName(fr cyan): ", stdout
);
410 if ((text
= ppdLocalizeMarkerName(ppd
, "cyan")) != NULL
&&
411 !strcmp(text
, "La Toner Cyan"))
416 printf("FAIL (\"%s\" instead of \"La Toner Cyan\")\n",
417 text
? text
: "(null)");
420 putenv("LANG=zh_TW");
421 putenv("LC_ALL=zh_TW");
422 putenv("LC_CTYPE=zh_TW");
423 putenv("LC_MESSAGES=zh_TW");
425 fputs("ppdLocalizeMarkerName(zh_TW cyan): ", stdout
);
426 if ((text
= ppdLocalizeMarkerName(ppd
, "cyan")) != NULL
&&
427 !strcmp(text
, "Number 1 Cyan Toner"))
432 printf("FAIL (\"%s\" instead of \"Number 1 Cyan Toner\")\n",
433 text
? text
: "(null)");
439 * Test new constraints...
442 fputs("ppdOpenFile(test2.ppd): ", stdout
);
444 if ((ppd
= ppdOpenFile("test2.ppd")) != NULL
)
448 ppd_status_t err
; /* Last error in file */
449 int line
; /* Line number in file */
453 err
= ppdLastError(&line
);
455 printf("FAIL (%s on line %d)\n", ppdErrorString(err
), line
);
458 fputs("ppdMarkDefaults: ", stdout
);
459 ppdMarkDefaults(ppd
);
461 if ((conflicts
= ppdConflicts(ppd
)) == 0)
466 printf("FAIL (%d conflicts)\n", conflicts
);
469 fputs("ppdConflicts(): ", stdout
);
470 ppdMarkOption(ppd
, "PageSize", "Env10");
471 ppdMarkOption(ppd
, "InputSlot", "Envelope");
472 ppdMarkOption(ppd
, "Quality", "Photo");
474 if ((conflicts
= ppdConflicts(ppd
)) == 2)
478 printf("FAIL (%d)\n", conflicts
);
482 fputs("cupsResolveConflicts(Quality=Photo): ", stdout
);
485 if (cupsResolveConflicts(ppd
, "Quality", "Photo", &num_options
,
488 printf("FAIL (%d options:", num_options
);
489 for (i
= 0; i
< num_options
; i
++)
490 printf(" %s=%s", options
[i
].name
, options
[i
].value
);
495 puts("PASS (Unable to resolve)");
496 cupsFreeOptions(num_options
, options
);
498 fputs("cupsResolveConflicts(No option/choice): ", stdout
);
501 if (cupsResolveConflicts(ppd
, NULL
, NULL
, &num_options
, &options
) &&
502 num_options
== 1 && !strcasecmp(options
->name
, "Quality") &&
503 !strcasecmp(options
->value
, "Normal"))
505 else if (num_options
> 0)
507 printf("FAIL (%d options:", num_options
);
508 for (i
= 0; i
< num_options
; i
++)
509 printf(" %s=%s", options
[i
].name
, options
[i
].value
);
515 puts("FAIL (Unable to resolve!)");
518 cupsFreeOptions(num_options
, options
);
520 fputs("cupsResolveConflicts(loop test): ", stdout
);
521 ppdMarkOption(ppd
, "PageSize", "A4");
522 ppdMarkOption(ppd
, "Quality", "Photo");
525 if (!cupsResolveConflicts(ppd
, NULL
, NULL
, &num_options
, &options
))
527 else if (num_options
> 0)
529 printf("FAIL (%d options:", num_options
);
530 for (i
= 0; i
< num_options
; i
++)
531 printf(" %s=%s", options
[i
].name
, options
[i
].value
);
535 puts("FAIL (No conflicts!)");
537 fputs("ppdInstallableConflict(): ", stdout
);
538 if (ppdInstallableConflict(ppd
, "Duplex", "DuplexNoTumble") &&
539 !ppdInstallableConflict(ppd
, "Duplex", "None"))
541 else if (!ppdInstallableConflict(ppd
, "Duplex", "DuplexNoTumble"))
543 puts("FAIL (Duplex=DuplexNoTumble did not conflict)");
548 puts("FAIL (Duplex=None conflicted)");
556 ppdMarkDefaults(ppd
);
558 fputs("ppdPageSizeLimits(default): ", stdout
);
559 if (ppdPageSizeLimits(ppd
, &minsize
, &maxsize
))
561 if (minsize
.width
!= 36 || minsize
.length
!= 36 ||
562 maxsize
.width
!= 1080 || maxsize
.length
!= 86400)
564 printf("FAIL (got min=%.0fx%.0f, max=%.0fx%.0f, "
565 "expected min=36x36, max=1080x86400)\n", minsize
.width
,
566 minsize
.length
, maxsize
.width
, maxsize
.length
);
574 puts("FAIL (returned 0)");
578 ppdMarkOption(ppd
, "InputSlot", "Manual");
580 fputs("ppdPageSizeLimits(InputSlot=Manual): ", stdout
);
581 if (ppdPageSizeLimits(ppd
, &minsize
, &maxsize
))
583 if (minsize
.width
!= 100 || minsize
.length
!= 100 ||
584 maxsize
.width
!= 1000 || maxsize
.length
!= 1000)
586 printf("FAIL (got min=%.0fx%.0f, max=%.0fx%.0f, "
587 "expected min=100x100, max=1000x1000)\n", minsize
.width
,
588 minsize
.length
, maxsize
.width
, maxsize
.length
);
596 puts("FAIL (returned 0)");
600 ppdMarkOption(ppd
, "Quality", "Photo");
602 fputs("ppdPageSizeLimits(Quality=Photo): ", stdout
);
603 if (ppdPageSizeLimits(ppd
, &minsize
, &maxsize
))
605 if (minsize
.width
!= 200 || minsize
.length
!= 200 ||
606 maxsize
.width
!= 1000 || maxsize
.length
!= 1000)
608 printf("FAIL (got min=%.0fx%.0f, max=%.0fx%.0f, "
609 "expected min=200x200, max=1000x1000)\n", minsize
.width
,
610 minsize
.length
, maxsize
.width
, maxsize
.length
);
618 puts("FAIL (returned 0)");
622 ppdMarkOption(ppd
, "InputSlot", "Tray");
624 fputs("ppdPageSizeLimits(Quality=Photo): ", stdout
);
625 if (ppdPageSizeLimits(ppd
, &minsize
, &maxsize
))
627 if (minsize
.width
!= 300 || minsize
.length
!= 300 ||
628 maxsize
.width
!= 1080 || maxsize
.length
!= 86400)
630 printf("FAIL (got min=%.0fx%.0f, max=%.0fx%.0f, "
631 "expected min=300x300, max=1080x86400)\n", minsize
.width
,
632 minsize
.length
, maxsize
.width
, maxsize
.length
);
640 puts("FAIL (returned 0)");
646 const char *filename
; /* PPD filename */
649 if (!strncmp(argv
[1], "-d", 2))
651 filename
= cupsGetPPD(argv
[1] + 2);
654 printf("%s: %s\n", argv
[1], cupsLastErrorString());
661 if ((ppd
= ppdOpenFile(filename
)) == NULL
)
663 ppd_status_t err
; /* Last error in file */
664 int line
; /* Line number in file */
668 err
= ppdLastError(&line
);
670 printf("%s: %s on line %d\n", argv
[1], ppdErrorString(err
), line
);
674 int j
, k
; /* Looping vars */
675 ppd_attr_t
*attr
; /* Current attribute */
676 ppd_group_t
*group
; /* Option group */
677 ppd_option_t
*option
; /* Option */
678 ppd_coption_t
*coption
; /* Custom option */
679 ppd_cparam_t
*cparam
; /* Custom parameter */
680 ppd_const_t
*c
; /* UIConstraints */
681 char lang
[255], /* LANG environment variable */
682 lc_all
[255], /* LC_ALL environment variable */
683 lc_ctype
[255], /* LC_CTYPE environment variable */
684 lc_messages
[255];/* LC_MESSAGES environment variable */
689 snprintf(lang
, sizeof(lang
), "LANG=%s", argv
[2]);
691 snprintf(lc_all
, sizeof(lc_all
), "LC_ALL=%s", argv
[2]);
693 snprintf(lc_ctype
, sizeof(lc_ctype
), "LC_CTYPE=%s", argv
[2]);
695 snprintf(lc_messages
, sizeof(lc_messages
), "LC_MESSAGES=%s", argv
[2]);
701 for (i
= ppd
->num_groups
, group
= ppd
->groups
;
705 printf("%s (%s):\n", group
->name
, group
->text
);
707 for (j
= group
->num_options
, option
= group
->options
;
711 printf(" %s (%s):\n", option
->keyword
, option
->text
);
713 for (k
= 0; k
< option
->num_choices
; k
++)
714 printf(" - %s (%s)\n", option
->choices
[k
].choice
,
715 option
->choices
[k
].text
);
717 if ((coption
= ppdFindCustomOption(ppd
, option
->keyword
)) != NULL
)
719 for (cparam
= (ppd_cparam_t
*)cupsArrayFirst(coption
->params
);
721 cparam
= (ppd_cparam_t
*)cupsArrayNext(coption
->params
))
723 switch (cparam
->type
)
725 case PPD_CUSTOM_CURVE
:
726 printf(" %s(%s): PPD_CUSTOM_CURVE (%g to %g)\n",
727 cparam
->name
, cparam
->text
,
728 cparam
->minimum
.custom_curve
,
729 cparam
->maximum
.custom_curve
);
732 case PPD_CUSTOM_INT
:
733 printf(" %s(%s): PPD_CUSTOM_INT (%d to %d)\n",
734 cparam
->name
, cparam
->text
,
735 cparam
->minimum
.custom_int
,
736 cparam
->maximum
.custom_int
);
739 case PPD_CUSTOM_INVCURVE
:
740 printf(" %s(%s): PPD_CUSTOM_INVCURVE (%g to %g)\n",
741 cparam
->name
, cparam
->text
,
742 cparam
->minimum
.custom_invcurve
,
743 cparam
->maximum
.custom_invcurve
);
746 case PPD_CUSTOM_PASSCODE
:
747 printf(" %s(%s): PPD_CUSTOM_PASSCODE (%d to %d)\n",
748 cparam
->name
, cparam
->text
,
749 cparam
->minimum
.custom_passcode
,
750 cparam
->maximum
.custom_passcode
);
753 case PPD_CUSTOM_PASSWORD
:
754 printf(" %s(%s): PPD_CUSTOM_PASSWORD (%d to %d)\n",
755 cparam
->name
, cparam
->text
,
756 cparam
->minimum
.custom_password
,
757 cparam
->maximum
.custom_password
);
760 case PPD_CUSTOM_POINTS
:
761 printf(" %s(%s): PPD_CUSTOM_POINTS (%g to %g)\n",
762 cparam
->name
, cparam
->text
,
763 cparam
->minimum
.custom_points
,
764 cparam
->maximum
.custom_points
);
767 case PPD_CUSTOM_REAL
:
768 printf(" %s(%s): PPD_CUSTOM_REAL (%g to %g)\n",
769 cparam
->name
, cparam
->text
,
770 cparam
->minimum
.custom_real
,
771 cparam
->maximum
.custom_real
);
774 case PPD_CUSTOM_STRING
:
775 printf(" %s(%s): PPD_CUSTOM_STRING (%d to %d)\n",
776 cparam
->name
, cparam
->text
,
777 cparam
->minimum
.custom_string
,
778 cparam
->maximum
.custom_string
);
786 puts("Constraints:");
788 for (i
= ppd
->num_consts
, c
= ppd
->consts
; i
> 0; i
--, c
++)
789 printf(" *UIConstraints: *%s %s *%s %s\n", c
->option1
, c
->choice1
,
790 c
->option2
, c
->choice2
);
794 for (attr
= (ppd_attr_t
*)cupsArrayFirst(ppd
->sorted_attrs
);
796 attr
= (ppd_attr_t
*)cupsArrayNext(ppd
->sorted_attrs
))
797 printf(" *%s %s/%s: \"%s\"\n", attr
->name
, attr
->spec
,
798 attr
->text
, attr
->value
? attr
->value
: "");
801 if (!strncmp(argv
[1], "-d", 2))
806 if (getenv("MallocStackLogging") && getenv("MallocStackLoggingNoCompact"))
808 char command
[1024]; /* malloc_history command */
810 snprintf(command
, sizeof(command
), "malloc_history %d -all_by_size",
815 #endif /* __APPLE__ */
824 * End of "$Id: testppd.c 7633 2008-06-10 23:07:29Z mike $".