]>
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: *StringOption None\n"
85 "} stopped cleartomark\n"
87 "%%BeginFeature: *CustomPageSize True\n"
95 "} stopped cleartomark\n";
99 * 'main()' - Main entry.
102 int /* O - Exit status */
103 main(int argc
, /* I - Number of command-line arguments */
104 char *argv
[]) /* I - Command-line arguments */
106 int i
; /* Looping var */
107 ppd_file_t
*ppd
; /* PPD file loaded from disk */
108 int status
; /* Status of tests (0 = success, 1 = fail) */
109 int conflicts
; /* Number of conflicts */
110 char *s
; /* String */
111 char buffer
[8192]; /* String buffer */
112 const char *text
; /* Localized text */
113 int num_options
; /* Number of options */
114 cups_option_t
*options
; /* Options */
115 ppd_size_t minsize
, /* Minimum size */
116 maxsize
; /* Maximum size */
124 * Setup directories for locale stuff...
127 if (access("locale", 0))
129 mkdir("locale", 0777);
130 mkdir("locale/fr", 0777);
131 symlink("../../../locale/cups_fr.po", "locale/fr/cups_fr.po");
132 mkdir("locale/zh_TW", 0777);
133 symlink("../../../locale/cups_zh_TW.po", "locale/zh_TW/cups_zh_TW.po");
136 putenv("LOCALEDIR=locale");
139 * Do tests with test.ppd...
142 fputs("ppdOpenFile(test.ppd): ", stdout
);
144 if ((ppd
= ppdOpenFile("test.ppd")) != NULL
)
148 ppd_status_t err
; /* Last error in file */
149 int line
; /* Line number in file */
153 err
= ppdLastError(&line
);
155 printf("FAIL (%s on line %d)\n", ppdErrorString(err
), line
);
158 fputs("ppdMarkDefaults: ", stdout
);
159 ppdMarkDefaults(ppd
);
161 if ((conflicts
= ppdConflicts(ppd
)) == 0)
166 printf("FAIL (%d conflicts)\n", conflicts
);
169 fputs("ppdEmitString (defaults): ", stdout
);
170 if ((s
= ppdEmitString(ppd
, PPD_ORDER_ANY
, 0.0)) != NULL
&&
171 !strcmp(s
, default_code
))
176 printf("FAIL (%d bytes instead of %d)\n", s
? (int)strlen(s
) : 0,
177 (int)strlen(default_code
));
186 fputs("ppdEmitString (custom size): ", stdout
);
187 ppdMarkOption(ppd
, "PageSize", "Custom.400x500");
189 if ((s
= ppdEmitString(ppd
, PPD_ORDER_ANY
, 0.0)) != NULL
&&
190 !strcmp(s
, custom_code
))
195 printf("FAIL (%d bytes instead of %d)\n", s
? (int)strlen(s
) : 0,
196 (int)strlen(custom_code
));
206 * Test constraints...
209 fputs("ppdConflicts(): ", stdout
);
210 ppdMarkOption(ppd
, "PageSize", "Letter");
211 ppdMarkOption(ppd
, "InputSlot", "Envelope");
213 if ((conflicts
= ppdConflicts(ppd
)) == 2)
217 printf("FAIL (%d)\n", conflicts
);
221 fputs("cupsResolveConflicts(): ", stdout
);
224 if (cupsResolveConflicts(ppd
, "InputSlot", "Envelope", &num_options
,
226 num_options
== 1 && !strcasecmp(options
->name
, "InputSlot") &&
227 !strcasecmp(options
->value
, "Tray"))
229 else if (num_options
> 0)
231 printf("FAIL (%d options:", num_options
);
232 for (i
= 0; i
< num_options
; i
++)
233 printf(" %s=%s", options
[i
].name
, options
[i
].value
);
239 puts("FAIL (Unable to resolve!)");
242 cupsFreeOptions(num_options
, options
);
244 fputs("ppdInstallableConflict(): ", stdout
);
245 if (ppdInstallableConflict(ppd
, "Duplex", "DuplexNoTumble") &&
246 !ppdInstallableConflict(ppd
, "Duplex", "None"))
248 else if (!ppdInstallableConflict(ppd
, "Duplex", "DuplexNoTumble"))
250 puts("FAIL (Duplex=DuplexNoTumble did not conflict)");
255 puts("FAIL (Duplex=None conflicted)");
263 fputs("ppdPageSizeLimits: ", stdout
);
264 if (ppdPageSizeLimits(ppd
, &minsize
, &maxsize
))
266 if (minsize
.width
!= 36 || minsize
.length
!= 36 ||
267 maxsize
.width
!= 1080 || maxsize
.length
!= 86400)
269 printf("FAIL (got min=%.0fx%.0f, max=%.0fx%.0f, "
270 "expected min=36x36, max=1080x86400)\n", minsize
.width
,
271 minsize
.length
, maxsize
.width
, maxsize
.length
);
279 puts("FAIL (returned 0)");
284 * Test localization...
287 fputs("ppdLocalizeIPPReason(text): ", stdout
);
288 if (ppdLocalizeIPPReason(ppd
, "foo", NULL
, buffer
, sizeof(buffer
)) &&
289 !strcmp(buffer
, "Foo Reason"))
294 printf("FAIL (\"%s\" instead of \"Foo Reason\")\n", buffer
);
297 fputs("ppdLocalizeIPPReason(http): ", stdout
);
298 if (ppdLocalizeIPPReason(ppd
, "foo", "http", buffer
, sizeof(buffer
)) &&
299 !strcmp(buffer
, "http://foo/bar.html"))
304 printf("FAIL (\"%s\" instead of \"http://foo/bar.html\")\n", buffer
);
307 fputs("ppdLocalizeIPPReason(help): ", stdout
);
308 if (ppdLocalizeIPPReason(ppd
, "foo", "help", buffer
, sizeof(buffer
)) &&
309 !strcmp(buffer
, "help:anchor='foo'%20bookID=Vendor%20Help"))
314 printf("FAIL (\"%s\" instead of \"help:anchor='foo'%%20bookID=Vendor%%20Help\")\n", buffer
);
317 fputs("ppdLocalizeIPPReason(file): ", stdout
);
318 if (ppdLocalizeIPPReason(ppd
, "foo", "file", buffer
, sizeof(buffer
)) &&
319 !strcmp(buffer
, "/help/foo/bar.html"))
324 printf("FAIL (\"%s\" instead of \"/help/foo/bar.html\")\n", buffer
);
329 fputs("ppdLocalizeIPPReason(fr text): ", stdout
);
330 if (ppdLocalizeIPPReason(ppd
, "foo", NULL
, buffer
, sizeof(buffer
)) &&
331 !strcmp(buffer
, "La Long Foo Reason"))
336 printf("FAIL (\"%s\" instead of \"La Long Foo Reason\")\n", buffer
);
339 putenv("LANG=zh_TW");
341 fputs("ppdLocalizeIPPReason(zh_TW text): ", stdout
);
342 if (ppdLocalizeIPPReason(ppd
, "foo", NULL
, buffer
, sizeof(buffer
)) &&
343 !strcmp(buffer
, "Number 1 Foo Reason"))
348 printf("FAIL (\"%s\" instead of \"Number 1 Foo Reason\")\n", buffer
);
352 * cupsMarkerName localization...
357 fputs("ppdLocalizeMarkerName(bogus): ", stdout
);
359 if ((text
= ppdLocalizeMarkerName(ppd
, "bogus")) != NULL
)
362 printf("FAIL (\"%s\" instead of NULL)\n", text
);
367 fputs("ppdLocalizeMarkerName(cyan): ", stdout
);
369 if ((text
= ppdLocalizeMarkerName(ppd
, "cyan")) != NULL
&&
370 !strcmp(text
, "Cyan Toner"))
375 printf("FAIL (\"%s\" instead of \"Cyan Toner\")\n",
376 text
? text
: "(null)");
381 fputs("ppdLocalizeMarkerName(fr cyan): ", stdout
);
382 if ((text
= ppdLocalizeMarkerName(ppd
, "cyan")) != NULL
&&
383 !strcmp(text
, "La Toner Cyan"))
388 printf("FAIL (\"%s\" instead of \"La Toner Cyan\")\n",
389 text
? text
: "(null)");
392 putenv("LANG=zh_TW");
394 fputs("ppdLocalizeMarkerName(zh_TW cyan): ", stdout
);
395 if ((text
= ppdLocalizeMarkerName(ppd
, "cyan")) != NULL
&&
396 !strcmp(text
, "Number 1 Cyan Toner"))
401 printf("FAIL (\"%s\" instead of \"Number 1 Cyan Toner\")\n",
402 text
? text
: "(null)");
408 * Test new constraints...
411 fputs("ppdOpenFile(test2.ppd): ", stdout
);
413 if ((ppd
= ppdOpenFile("test2.ppd")) != NULL
)
417 ppd_status_t err
; /* Last error in file */
418 int line
; /* Line number in file */
422 err
= ppdLastError(&line
);
424 printf("FAIL (%s on line %d)\n", ppdErrorString(err
), line
);
427 fputs("ppdMarkDefaults: ", stdout
);
428 ppdMarkDefaults(ppd
);
430 if ((conflicts
= ppdConflicts(ppd
)) == 0)
435 printf("FAIL (%d conflicts)\n", conflicts
);
438 fputs("ppdConflicts(): ", stdout
);
439 ppdMarkOption(ppd
, "PageSize", "Env10");
440 ppdMarkOption(ppd
, "InputSlot", "Envelope");
441 ppdMarkOption(ppd
, "Quality", "Photo");
443 if ((conflicts
= ppdConflicts(ppd
)) == 2)
447 printf("FAIL (%d)\n", conflicts
);
451 fputs("cupsResolveConflicts(): ", stdout
);
454 if (cupsResolveConflicts(ppd
, "Quality", "Photo", &num_options
,
456 num_options
== 1 && !strcasecmp(options
->name
, "Quality") &&
457 !strcasecmp(options
->value
, "Normal"))
459 else if (num_options
> 0)
461 printf("FAIL (%d options:", num_options
);
462 for (i
= 0; i
< num_options
; i
++)
463 printf(" %s=%s", options
[i
].name
, options
[i
].value
);
469 puts("FAIL (Unable to resolve!)");
472 cupsFreeOptions(num_options
, options
);
474 fputs("cupsResolveConflicts(loop test): ", stdout
);
475 ppdMarkOption(ppd
, "PageSize", "A4");
476 ppdMarkOption(ppd
, "Quality", "Photo");
479 if (!cupsResolveConflicts(ppd
, "Quality", "Photo", &num_options
,
482 else if (num_options
> 0)
484 printf("FAIL (%d options:", num_options
);
485 for (i
= 0; i
< num_options
; i
++)
486 printf(" %s=%s", options
[i
].name
, options
[i
].value
);
490 puts("FAIL (No conflicts!)");
492 fputs("ppdInstallableConflict(): ", stdout
);
493 if (ppdInstallableConflict(ppd
, "Duplex", "DuplexNoTumble") &&
494 !ppdInstallableConflict(ppd
, "Duplex", "None"))
496 else if (!ppdInstallableConflict(ppd
, "Duplex", "DuplexNoTumble"))
498 puts("FAIL (Duplex=DuplexNoTumble did not conflict)");
503 puts("FAIL (Duplex=None conflicted)");
511 ppdMarkDefaults(ppd
);
513 fputs("ppdPageSizeLimits(default): ", stdout
);
514 if (ppdPageSizeLimits(ppd
, &minsize
, &maxsize
))
516 if (minsize
.width
!= 36 || minsize
.length
!= 36 ||
517 maxsize
.width
!= 1080 || maxsize
.length
!= 86400)
519 printf("FAIL (got min=%.0fx%.0f, max=%.0fx%.0f, "
520 "expected min=36x36, max=1080x86400)\n", minsize
.width
,
521 minsize
.length
, maxsize
.width
, maxsize
.length
);
529 puts("FAIL (returned 0)");
533 ppdMarkOption(ppd
, "InputSlot", "Manual");
535 fputs("ppdPageSizeLimits(InputSlot=Manual): ", stdout
);
536 if (ppdPageSizeLimits(ppd
, &minsize
, &maxsize
))
538 if (minsize
.width
!= 100 || minsize
.length
!= 100 ||
539 maxsize
.width
!= 1000 || maxsize
.length
!= 1000)
541 printf("FAIL (got min=%.0fx%.0f, max=%.0fx%.0f, "
542 "expected min=100x100, max=1000x1000)\n", minsize
.width
,
543 minsize
.length
, maxsize
.width
, maxsize
.length
);
551 puts("FAIL (returned 0)");
555 ppdMarkOption(ppd
, "Quality", "Photo");
557 fputs("ppdPageSizeLimits(Quality=Photo): ", stdout
);
558 if (ppdPageSizeLimits(ppd
, &minsize
, &maxsize
))
560 if (minsize
.width
!= 200 || minsize
.length
!= 200 ||
561 maxsize
.width
!= 1000 || maxsize
.length
!= 1000)
563 printf("FAIL (got min=%.0fx%.0f, max=%.0fx%.0f, "
564 "expected min=200x200, max=1000x1000)\n", minsize
.width
,
565 minsize
.length
, maxsize
.width
, maxsize
.length
);
573 puts("FAIL (returned 0)");
577 ppdMarkOption(ppd
, "InputSlot", "Tray");
579 fputs("ppdPageSizeLimits(Quality=Photo): ", stdout
);
580 if (ppdPageSizeLimits(ppd
, &minsize
, &maxsize
))
582 if (minsize
.width
!= 300 || minsize
.length
!= 300 ||
583 maxsize
.width
!= 1080 || maxsize
.length
!= 86400)
585 printf("FAIL (got min=%.0fx%.0f, max=%.0fx%.0f, "
586 "expected min=300x300, max=1080x86400)\n", minsize
.width
,
587 minsize
.length
, maxsize
.width
, maxsize
.length
);
595 puts("FAIL (returned 0)");
601 const char *filename
; /* PPD filename */
604 if (!strncmp(argv
[1], "-d", 2))
605 filename
= cupsGetPPD(argv
[1] + 2);
609 if ((ppd
= ppdOpenFile(filename
)) == NULL
)
611 ppd_status_t err
; /* Last error in file */
612 int line
; /* Line number in file */
616 err
= ppdLastError(&line
);
618 printf("%s: %s on line %d\n", argv
[1], ppdErrorString(err
), line
);
622 int j
, k
; /* Looping vars */
623 ppd_attr_t
*attr
; /* Current attribute */
624 ppd_group_t
*group
; /* Option group */
625 ppd_option_t
*option
; /* Option */
626 ppd_coption_t
*coption
; /* Custom option */
627 ppd_cparam_t
*cparam
; /* Custom parameter */
628 ppd_const_t
*c
; /* UIConstraints */
629 char lang
[255]; /* LANG environment variable */
634 snprintf(lang
, sizeof(lang
), "LANG=%s", argv
[2]);
640 for (i
= ppd
->num_groups
, group
= ppd
->groups
;
644 printf("%s (%s):\n", group
->name
, group
->text
);
646 for (j
= group
->num_options
, option
= group
->options
;
650 printf(" %s (%s):\n", option
->keyword
, option
->text
);
652 for (k
= 0; k
< option
->num_choices
; k
++)
653 printf(" - %s (%s)\n", option
->choices
[k
].choice
,
654 option
->choices
[k
].text
);
656 if ((coption
= ppdFindCustomOption(ppd
, option
->keyword
)) != NULL
)
658 for (cparam
= (ppd_cparam_t
*)cupsArrayFirst(coption
->params
);
660 cparam
= (ppd_cparam_t
*)cupsArrayNext(coption
->params
))
662 switch (cparam
->type
)
664 case PPD_CUSTOM_CURVE
:
665 printf(" %s(%s): PPD_CUSTOM_CURVE (%g to %g)\n",
666 cparam
->name
, cparam
->text
,
667 cparam
->minimum
.custom_curve
,
668 cparam
->maximum
.custom_curve
);
671 case PPD_CUSTOM_INT
:
672 printf(" %s(%s): PPD_CUSTOM_INT (%d to %d)\n",
673 cparam
->name
, cparam
->text
,
674 cparam
->minimum
.custom_int
,
675 cparam
->maximum
.custom_int
);
678 case PPD_CUSTOM_INVCURVE
:
679 printf(" %s(%s): PPD_CUSTOM_INVCURVE (%g to %g)\n",
680 cparam
->name
, cparam
->text
,
681 cparam
->minimum
.custom_invcurve
,
682 cparam
->maximum
.custom_invcurve
);
685 case PPD_CUSTOM_PASSCODE
:
686 printf(" %s(%s): PPD_CUSTOM_PASSCODE (%d to %d)\n",
687 cparam
->name
, cparam
->text
,
688 cparam
->minimum
.custom_passcode
,
689 cparam
->maximum
.custom_passcode
);
692 case PPD_CUSTOM_PASSWORD
:
693 printf(" %s(%s): PPD_CUSTOM_PASSWORD (%d to %d)\n",
694 cparam
->name
, cparam
->text
,
695 cparam
->minimum
.custom_password
,
696 cparam
->maximum
.custom_password
);
699 case PPD_CUSTOM_POINTS
:
700 printf(" %s(%s): PPD_CUSTOM_POINTS (%g to %g)\n",
701 cparam
->name
, cparam
->text
,
702 cparam
->minimum
.custom_points
,
703 cparam
->maximum
.custom_points
);
706 case PPD_CUSTOM_REAL
:
707 printf(" %s(%s): PPD_CUSTOM_REAL (%g to %g)\n",
708 cparam
->name
, cparam
->text
,
709 cparam
->minimum
.custom_real
,
710 cparam
->maximum
.custom_real
);
713 case PPD_CUSTOM_STRING
:
714 printf(" %s(%s): PPD_CUSTOM_STRING (%d to %d)\n",
715 cparam
->name
, cparam
->text
,
716 cparam
->minimum
.custom_string
,
717 cparam
->maximum
.custom_string
);
725 puts("Constraints:");
727 for (i
= ppd
->num_consts
, c
= ppd
->consts
; i
> 0; i
--, c
++)
728 printf(" *UIConstraints: *%s %s *%s %s\n", c
->option1
, c
->choice1
,
729 c
->option2
, c
->choice2
);
733 for (attr
= (ppd_attr_t
*)cupsArrayFirst(ppd
->sorted_attrs
);
735 attr
= (ppd_attr_t
*)cupsArrayNext(ppd
->sorted_attrs
))
736 printf(" *%s %s/%s: \"%s\"\n", attr
->name
, attr
->spec
,
737 attr
->text
, attr
->value
? attr
->value
: "");
740 if (!strncmp(argv
[1], "-d", 2))
745 if (getenv("MallocStackLogging") && getenv("MallocStackLoggingNoCompact"))
747 char command
[1024]; /* malloc_history command */
749 snprintf(command
, sizeof(command
), "malloc_history %d -all_by_size",
754 #endif /* __APPLE__ */
763 * End of "$Id: testppd.c 7633 2008-06-10 23:07:29Z mike $".