]>
git.ipfire.org Git - thirdparty/cups.git/blob - cups/testppd.c
5318c4d240ee5766e282b4b746653f0ef705423c
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 fputs("ppdLocalizeIPPReason(fr text): ", stdout
);
346 if (ppdLocalizeIPPReason(ppd
, "foo", NULL
, buffer
, sizeof(buffer
)) &&
347 !strcmp(buffer
, "La Long Foo Reason"))
352 printf("FAIL (\"%s\" instead of \"La Long Foo Reason\")\n", buffer
);
355 putenv("LANG=zh_TW");
357 fputs("ppdLocalizeIPPReason(zh_TW text): ", stdout
);
358 if (ppdLocalizeIPPReason(ppd
, "foo", NULL
, buffer
, sizeof(buffer
)) &&
359 !strcmp(buffer
, "Number 1 Foo Reason"))
364 printf("FAIL (\"%s\" instead of \"Number 1 Foo Reason\")\n", buffer
);
368 * cupsMarkerName localization...
373 fputs("ppdLocalizeMarkerName(bogus): ", stdout
);
375 if ((text
= ppdLocalizeMarkerName(ppd
, "bogus")) != NULL
)
378 printf("FAIL (\"%s\" instead of NULL)\n", text
);
383 fputs("ppdLocalizeMarkerName(cyan): ", stdout
);
385 if ((text
= ppdLocalizeMarkerName(ppd
, "cyan")) != NULL
&&
386 !strcmp(text
, "Cyan Toner"))
391 printf("FAIL (\"%s\" instead of \"Cyan Toner\")\n",
392 text
? text
: "(null)");
397 fputs("ppdLocalizeMarkerName(fr cyan): ", stdout
);
398 if ((text
= ppdLocalizeMarkerName(ppd
, "cyan")) != NULL
&&
399 !strcmp(text
, "La Toner Cyan"))
404 printf("FAIL (\"%s\" instead of \"La Toner Cyan\")\n",
405 text
? text
: "(null)");
408 putenv("LANG=zh_TW");
410 fputs("ppdLocalizeMarkerName(zh_TW cyan): ", stdout
);
411 if ((text
= ppdLocalizeMarkerName(ppd
, "cyan")) != NULL
&&
412 !strcmp(text
, "Number 1 Cyan Toner"))
417 printf("FAIL (\"%s\" instead of \"Number 1 Cyan Toner\")\n",
418 text
? text
: "(null)");
424 * Test new constraints...
427 fputs("ppdOpenFile(test2.ppd): ", stdout
);
429 if ((ppd
= ppdOpenFile("test2.ppd")) != NULL
)
433 ppd_status_t err
; /* Last error in file */
434 int line
; /* Line number in file */
438 err
= ppdLastError(&line
);
440 printf("FAIL (%s on line %d)\n", ppdErrorString(err
), line
);
443 fputs("ppdMarkDefaults: ", stdout
);
444 ppdMarkDefaults(ppd
);
446 if ((conflicts
= ppdConflicts(ppd
)) == 0)
451 printf("FAIL (%d conflicts)\n", conflicts
);
454 fputs("ppdConflicts(): ", stdout
);
455 ppdMarkOption(ppd
, "PageSize", "Env10");
456 ppdMarkOption(ppd
, "InputSlot", "Envelope");
457 ppdMarkOption(ppd
, "Quality", "Photo");
459 if ((conflicts
= ppdConflicts(ppd
)) == 2)
463 printf("FAIL (%d)\n", conflicts
);
467 fputs("cupsResolveConflicts(Quality=Photo): ", stdout
);
470 if (cupsResolveConflicts(ppd
, "Quality", "Photo", &num_options
,
473 printf("FAIL (%d options:", num_options
);
474 for (i
= 0; i
< num_options
; i
++)
475 printf(" %s=%s", options
[i
].name
, options
[i
].value
);
480 puts("PASS (Unable to resolve)");
481 cupsFreeOptions(num_options
, options
);
483 fputs("cupsResolveConflicts(No option/choice): ", stdout
);
486 if (cupsResolveConflicts(ppd
, NULL
, NULL
, &num_options
, &options
) &&
487 num_options
== 1 && !strcasecmp(options
->name
, "Quality") &&
488 !strcasecmp(options
->value
, "Normal"))
490 else if (num_options
> 0)
492 printf("FAIL (%d options:", num_options
);
493 for (i
= 0; i
< num_options
; i
++)
494 printf(" %s=%s", options
[i
].name
, options
[i
].value
);
500 puts("FAIL (Unable to resolve!)");
503 cupsFreeOptions(num_options
, options
);
505 fputs("cupsResolveConflicts(loop test): ", stdout
);
506 ppdMarkOption(ppd
, "PageSize", "A4");
507 ppdMarkOption(ppd
, "Quality", "Photo");
510 if (!cupsResolveConflicts(ppd
, NULL
, NULL
, &num_options
, &options
))
512 else if (num_options
> 0)
514 printf("FAIL (%d options:", num_options
);
515 for (i
= 0; i
< num_options
; i
++)
516 printf(" %s=%s", options
[i
].name
, options
[i
].value
);
520 puts("FAIL (No conflicts!)");
522 fputs("ppdInstallableConflict(): ", stdout
);
523 if (ppdInstallableConflict(ppd
, "Duplex", "DuplexNoTumble") &&
524 !ppdInstallableConflict(ppd
, "Duplex", "None"))
526 else if (!ppdInstallableConflict(ppd
, "Duplex", "DuplexNoTumble"))
528 puts("FAIL (Duplex=DuplexNoTumble did not conflict)");
533 puts("FAIL (Duplex=None conflicted)");
541 ppdMarkDefaults(ppd
);
543 fputs("ppdPageSizeLimits(default): ", stdout
);
544 if (ppdPageSizeLimits(ppd
, &minsize
, &maxsize
))
546 if (minsize
.width
!= 36 || minsize
.length
!= 36 ||
547 maxsize
.width
!= 1080 || maxsize
.length
!= 86400)
549 printf("FAIL (got min=%.0fx%.0f, max=%.0fx%.0f, "
550 "expected min=36x36, max=1080x86400)\n", minsize
.width
,
551 minsize
.length
, maxsize
.width
, maxsize
.length
);
559 puts("FAIL (returned 0)");
563 ppdMarkOption(ppd
, "InputSlot", "Manual");
565 fputs("ppdPageSizeLimits(InputSlot=Manual): ", stdout
);
566 if (ppdPageSizeLimits(ppd
, &minsize
, &maxsize
))
568 if (minsize
.width
!= 100 || minsize
.length
!= 100 ||
569 maxsize
.width
!= 1000 || maxsize
.length
!= 1000)
571 printf("FAIL (got min=%.0fx%.0f, max=%.0fx%.0f, "
572 "expected min=100x100, max=1000x1000)\n", minsize
.width
,
573 minsize
.length
, maxsize
.width
, maxsize
.length
);
581 puts("FAIL (returned 0)");
585 ppdMarkOption(ppd
, "Quality", "Photo");
587 fputs("ppdPageSizeLimits(Quality=Photo): ", stdout
);
588 if (ppdPageSizeLimits(ppd
, &minsize
, &maxsize
))
590 if (minsize
.width
!= 200 || minsize
.length
!= 200 ||
591 maxsize
.width
!= 1000 || maxsize
.length
!= 1000)
593 printf("FAIL (got min=%.0fx%.0f, max=%.0fx%.0f, "
594 "expected min=200x200, max=1000x1000)\n", minsize
.width
,
595 minsize
.length
, maxsize
.width
, maxsize
.length
);
603 puts("FAIL (returned 0)");
607 ppdMarkOption(ppd
, "InputSlot", "Tray");
609 fputs("ppdPageSizeLimits(Quality=Photo): ", stdout
);
610 if (ppdPageSizeLimits(ppd
, &minsize
, &maxsize
))
612 if (minsize
.width
!= 300 || minsize
.length
!= 300 ||
613 maxsize
.width
!= 1080 || maxsize
.length
!= 86400)
615 printf("FAIL (got min=%.0fx%.0f, max=%.0fx%.0f, "
616 "expected min=300x300, max=1080x86400)\n", minsize
.width
,
617 minsize
.length
, maxsize
.width
, maxsize
.length
);
625 puts("FAIL (returned 0)");
631 const char *filename
; /* PPD filename */
634 if (!strncmp(argv
[1], "-d", 2))
636 filename
= cupsGetPPD(argv
[1] + 2);
639 printf("%s: %s\n", argv
[1], cupsLastErrorString());
646 if ((ppd
= ppdOpenFile(filename
)) == NULL
)
648 ppd_status_t err
; /* Last error in file */
649 int line
; /* Line number in file */
653 err
= ppdLastError(&line
);
655 printf("%s: %s on line %d\n", argv
[1], ppdErrorString(err
), line
);
659 int j
, k
; /* Looping vars */
660 ppd_attr_t
*attr
; /* Current attribute */
661 ppd_group_t
*group
; /* Option group */
662 ppd_option_t
*option
; /* Option */
663 ppd_coption_t
*coption
; /* Custom option */
664 ppd_cparam_t
*cparam
; /* Custom parameter */
665 ppd_const_t
*c
; /* UIConstraints */
666 char lang
[255]; /* LANG environment variable */
671 snprintf(lang
, sizeof(lang
), "LANG=%s", argv
[2]);
677 for (i
= ppd
->num_groups
, group
= ppd
->groups
;
681 printf("%s (%s):\n", group
->name
, group
->text
);
683 for (j
= group
->num_options
, option
= group
->options
;
687 printf(" %s (%s):\n", option
->keyword
, option
->text
);
689 for (k
= 0; k
< option
->num_choices
; k
++)
690 printf(" - %s (%s)\n", option
->choices
[k
].choice
,
691 option
->choices
[k
].text
);
693 if ((coption
= ppdFindCustomOption(ppd
, option
->keyword
)) != NULL
)
695 for (cparam
= (ppd_cparam_t
*)cupsArrayFirst(coption
->params
);
697 cparam
= (ppd_cparam_t
*)cupsArrayNext(coption
->params
))
699 switch (cparam
->type
)
701 case PPD_CUSTOM_CURVE
:
702 printf(" %s(%s): PPD_CUSTOM_CURVE (%g to %g)\n",
703 cparam
->name
, cparam
->text
,
704 cparam
->minimum
.custom_curve
,
705 cparam
->maximum
.custom_curve
);
708 case PPD_CUSTOM_INT
:
709 printf(" %s(%s): PPD_CUSTOM_INT (%d to %d)\n",
710 cparam
->name
, cparam
->text
,
711 cparam
->minimum
.custom_int
,
712 cparam
->maximum
.custom_int
);
715 case PPD_CUSTOM_INVCURVE
:
716 printf(" %s(%s): PPD_CUSTOM_INVCURVE (%g to %g)\n",
717 cparam
->name
, cparam
->text
,
718 cparam
->minimum
.custom_invcurve
,
719 cparam
->maximum
.custom_invcurve
);
722 case PPD_CUSTOM_PASSCODE
:
723 printf(" %s(%s): PPD_CUSTOM_PASSCODE (%d to %d)\n",
724 cparam
->name
, cparam
->text
,
725 cparam
->minimum
.custom_passcode
,
726 cparam
->maximum
.custom_passcode
);
729 case PPD_CUSTOM_PASSWORD
:
730 printf(" %s(%s): PPD_CUSTOM_PASSWORD (%d to %d)\n",
731 cparam
->name
, cparam
->text
,
732 cparam
->minimum
.custom_password
,
733 cparam
->maximum
.custom_password
);
736 case PPD_CUSTOM_POINTS
:
737 printf(" %s(%s): PPD_CUSTOM_POINTS (%g to %g)\n",
738 cparam
->name
, cparam
->text
,
739 cparam
->minimum
.custom_points
,
740 cparam
->maximum
.custom_points
);
743 case PPD_CUSTOM_REAL
:
744 printf(" %s(%s): PPD_CUSTOM_REAL (%g to %g)\n",
745 cparam
->name
, cparam
->text
,
746 cparam
->minimum
.custom_real
,
747 cparam
->maximum
.custom_real
);
750 case PPD_CUSTOM_STRING
:
751 printf(" %s(%s): PPD_CUSTOM_STRING (%d to %d)\n",
752 cparam
->name
, cparam
->text
,
753 cparam
->minimum
.custom_string
,
754 cparam
->maximum
.custom_string
);
762 puts("Constraints:");
764 for (i
= ppd
->num_consts
, c
= ppd
->consts
; i
> 0; i
--, c
++)
765 printf(" *UIConstraints: *%s %s *%s %s\n", c
->option1
, c
->choice1
,
766 c
->option2
, c
->choice2
);
770 for (attr
= (ppd_attr_t
*)cupsArrayFirst(ppd
->sorted_attrs
);
772 attr
= (ppd_attr_t
*)cupsArrayNext(ppd
->sorted_attrs
))
773 printf(" *%s %s/%s: \"%s\"\n", attr
->name
, attr
->spec
,
774 attr
->text
, attr
->value
? attr
->value
: "");
777 if (!strncmp(argv
[1], "-d", 2))
782 if (getenv("MallocStackLogging") && getenv("MallocStackLoggingNoCompact"))
784 char command
[1024]; /* malloc_history command */
786 snprintf(command
, sizeof(command
), "malloc_history %d -all_by_size",
791 #endif /* __APPLE__ */
800 * End of "$Id: testppd.c 7633 2008-06-10 23:07:29Z mike $".