]>
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 */
122 * Setup directories for locale stuff...
125 if (access("locale", 0))
127 mkdir("locale", 0777);
128 mkdir("locale/fr", 0777);
129 symlink("../../../locale/cups_fr.po", "locale/fr/cups_fr.po");
130 mkdir("locale/zh_TW", 0777);
131 symlink("../../../locale/cups_zh_TW.po", "locale/zh_TW/cups_zh_TW.po");
134 putenv("LOCALEDIR=locale");
137 * Do tests with test.ppd...
140 fputs("ppdOpenFile(test.ppd): ", stdout
);
142 if ((ppd
= ppdOpenFile("test.ppd")) != NULL
)
146 ppd_status_t err
; /* Last error in file */
147 int line
; /* Line number in file */
151 err
= ppdLastError(&line
);
153 printf("FAIL (%s on line %d)\n", ppdErrorString(err
), line
);
156 fputs("ppdMarkDefaults: ", stdout
);
157 ppdMarkDefaults(ppd
);
159 if ((conflicts
= ppdConflicts(ppd
)) == 0)
164 printf("FAIL (%d conflicts)\n", conflicts
);
167 fputs("ppdEmitString (defaults): ", stdout
);
168 if ((s
= ppdEmitString(ppd
, PPD_ORDER_ANY
, 0.0)) != NULL
&&
169 !strcmp(s
, default_code
))
174 printf("FAIL (%d bytes instead of %d)\n", s
? (int)strlen(s
) : 0,
175 (int)strlen(default_code
));
184 fputs("ppdEmitString (custom size): ", stdout
);
185 ppdMarkOption(ppd
, "PageSize", "Custom.400x500");
187 if ((s
= ppdEmitString(ppd
, PPD_ORDER_ANY
, 0.0)) != NULL
&&
188 !strcmp(s
, custom_code
))
193 printf("FAIL (%d bytes instead of %d)\n", s
? (int)strlen(s
) : 0,
194 (int)strlen(custom_code
));
204 * Test constraints...
207 fputs("ppdConflicts(): ", stdout
);
208 ppdMarkOption(ppd
, "PageSize", "Letter");
209 ppdMarkOption(ppd
, "InputSlot", "Envelope");
211 if ((conflicts
= ppdConflicts(ppd
)) == 2)
215 printf("FAIL (%d)\n", conflicts
);
219 fputs("cupsResolveConflicts(): ", stdout
);
222 if (cupsResolveConflicts(ppd
, "InputSlot", "Envelope", &num_options
,
224 num_options
== 1 && !strcasecmp(options
->name
, "InputSlot") &&
225 !strcasecmp(options
->value
, "Tray"))
227 else if (num_options
> 0)
229 printf("FAIL (%d options:", num_options
);
230 for (i
= 0; i
< num_options
; i
++)
231 printf(" %s=%s", options
[i
].name
, options
[i
].value
);
237 puts("FAIL (Unable to resolve!)");
240 cupsFreeOptions(num_options
, options
);
242 fputs("ppdInstallableConflict(): ", stdout
);
243 if (ppdInstallableConflict(ppd
, "Duplex", "DuplexNoTumble") &&
244 !ppdInstallableConflict(ppd
, "Duplex", "None"))
246 else if (!ppdInstallableConflict(ppd
, "Duplex", "DuplexNoTumble"))
248 puts("FAIL (Duplex=DuplexNoTumble did not conflict)");
253 puts("FAIL (Duplex=None conflicted)");
258 * Test localization...
261 fputs("ppdLocalizeIPPReason(text): ", stdout
);
262 if (ppdLocalizeIPPReason(ppd
, "foo", NULL
, buffer
, sizeof(buffer
)) &&
263 !strcmp(buffer
, "Foo Reason"))
268 printf("FAIL (\"%s\" instead of \"Foo Reason\")\n", buffer
);
271 fputs("ppdLocalizeIPPReason(http): ", stdout
);
272 if (ppdLocalizeIPPReason(ppd
, "foo", "http", buffer
, sizeof(buffer
)) &&
273 !strcmp(buffer
, "http://foo/bar.html"))
278 printf("FAIL (\"%s\" instead of \"http://foo/bar.html\")\n", buffer
);
281 fputs("ppdLocalizeIPPReason(help): ", stdout
);
282 if (ppdLocalizeIPPReason(ppd
, "foo", "help", buffer
, sizeof(buffer
)) &&
283 !strcmp(buffer
, "help:anchor='foo'%20bookID=Vendor%20Help"))
288 printf("FAIL (\"%s\" instead of \"help:anchor='foo'%%20bookID=Vendor%%20Help\")\n", buffer
);
291 fputs("ppdLocalizeIPPReason(file): ", stdout
);
292 if (ppdLocalizeIPPReason(ppd
, "foo", "file", buffer
, sizeof(buffer
)) &&
293 !strcmp(buffer
, "/help/foo/bar.html"))
298 printf("FAIL (\"%s\" instead of \"/help/foo/bar.html\")\n", buffer
);
303 fputs("ppdLocalizeIPPReason(fr text): ", stdout
);
304 if (ppdLocalizeIPPReason(ppd
, "foo", NULL
, buffer
, sizeof(buffer
)) &&
305 !strcmp(buffer
, "La Long Foo Reason"))
310 printf("FAIL (\"%s\" instead of \"La Long Foo Reason\")\n", buffer
);
313 putenv("LANG=zh_TW");
315 fputs("ppdLocalizeIPPReason(zh_TW text): ", stdout
);
316 if (ppdLocalizeIPPReason(ppd
, "foo", NULL
, buffer
, sizeof(buffer
)) &&
317 !strcmp(buffer
, "Number 1 Foo Reason"))
322 printf("FAIL (\"%s\" instead of \"Number 1 Foo Reason\")\n", buffer
);
326 * cupsMarkerName localization...
331 fputs("ppdLocalizeMarkerName(bogus): ", stdout
);
333 if ((text
= ppdLocalizeMarkerName(ppd
, "bogus")) != NULL
)
336 printf("FAIL (\"%s\" instead of NULL)\n", text
);
341 fputs("ppdLocalizeMarkerName(cyan): ", stdout
);
343 if ((text
= ppdLocalizeMarkerName(ppd
, "cyan")) != NULL
&&
344 !strcmp(text
, "Cyan Toner"))
349 printf("FAIL (\"%s\" instead of \"Cyan Toner\")\n",
350 text
? text
: "(null)");
355 fputs("ppdLocalizeMarkerName(fr cyan): ", stdout
);
356 if ((text
= ppdLocalizeMarkerName(ppd
, "cyan")) != NULL
&&
357 !strcmp(text
, "La Toner Cyan"))
362 printf("FAIL (\"%s\" instead of \"La Toner Cyan\")\n",
363 text
? text
: "(null)");
366 putenv("LANG=zh_TW");
368 fputs("ppdLocalizeMarkerName(zh_TW cyan): ", stdout
);
369 if ((text
= ppdLocalizeMarkerName(ppd
, "cyan")) != NULL
&&
370 !strcmp(text
, "Number 1 Cyan Toner"))
375 printf("FAIL (\"%s\" instead of \"Number 1 Cyan Toner\")\n",
376 text
? text
: "(null)");
382 * Test new constraints...
385 fputs("ppdOpenFile(test2.ppd): ", stdout
);
387 if ((ppd
= ppdOpenFile("test2.ppd")) != NULL
)
391 ppd_status_t err
; /* Last error in file */
392 int line
; /* Line number in file */
396 err
= ppdLastError(&line
);
398 printf("FAIL (%s on line %d)\n", ppdErrorString(err
), line
);
401 fputs("ppdMarkDefaults: ", stdout
);
402 ppdMarkDefaults(ppd
);
404 if ((conflicts
= ppdConflicts(ppd
)) == 0)
409 printf("FAIL (%d conflicts)\n", conflicts
);
412 fputs("ppdConflicts(): ", stdout
);
413 ppdMarkOption(ppd
, "PageSize", "Env10");
414 ppdMarkOption(ppd
, "InputSlot", "Envelope");
415 ppdMarkOption(ppd
, "Quality", "Photo");
417 if ((conflicts
= ppdConflicts(ppd
)) == 2)
421 printf("FAIL (%d)\n", conflicts
);
425 fputs("cupsResolveConflicts(): ", stdout
);
428 if (cupsResolveConflicts(ppd
, "Quality", "Photo", &num_options
,
430 num_options
== 1 && !strcasecmp(options
->name
, "Quality") &&
431 !strcasecmp(options
->value
, "Normal"))
433 else if (num_options
> 0)
435 printf("FAIL (%d options:", num_options
);
436 for (i
= 0; i
< num_options
; i
++)
437 printf(" %s=%s", options
[i
].name
, options
[i
].value
);
443 puts("FAIL (Unable to resolve!)");
446 cupsFreeOptions(num_options
, options
);
448 fputs("cupsResolveConflicts(loop test): ", stdout
);
449 ppdMarkOption(ppd
, "PageSize", "A4");
450 ppdMarkOption(ppd
, "Quality", "Photo");
453 if (!cupsResolveConflicts(ppd
, "Quality", "Photo", &num_options
,
456 else if (num_options
> 0)
458 printf("FAIL (%d options:", num_options
);
459 for (i
= 0; i
< num_options
; i
++)
460 printf(" %s=%s", options
[i
].name
, options
[i
].value
);
464 puts("FAIL (No conflicts!)");
466 fputs("ppdInstallableConflict(): ", stdout
);
467 if (ppdInstallableConflict(ppd
, "Duplex", "DuplexNoTumble") &&
468 !ppdInstallableConflict(ppd
, "Duplex", "None"))
470 else if (!ppdInstallableConflict(ppd
, "Duplex", "DuplexNoTumble"))
472 puts("FAIL (Duplex=DuplexNoTumble did not conflict)");
477 puts("FAIL (Duplex=None conflicted)");
483 const char *filename
; /* PPD filename */
486 if (!strncmp(argv
[1], "-d", 2))
487 filename
= cupsGetPPD(argv
[1] + 2);
491 if ((ppd
= ppdOpenFile(filename
)) == NULL
)
493 ppd_status_t err
; /* Last error in file */
494 int line
; /* Line number in file */
498 err
= ppdLastError(&line
);
500 printf("%s: %s on line %d\n", argv
[1], ppdErrorString(err
), line
);
504 int j
, k
; /* Looping vars */
505 ppd_attr_t
*attr
; /* Current attribute */
506 ppd_group_t
*group
; /* Option group */
507 ppd_option_t
*option
; /* Option */
508 ppd_coption_t
*coption
; /* Custom option */
509 ppd_cparam_t
*cparam
; /* Custom parameter */
510 ppd_const_t
*c
; /* UIConstraints */
511 char lang
[255]; /* LANG environment variable */
516 snprintf(lang
, sizeof(lang
), "LANG=%s", argv
[2]);
522 for (i
= ppd
->num_groups
, group
= ppd
->groups
;
526 printf("%s (%s):\n", group
->name
, group
->text
);
528 for (j
= group
->num_options
, option
= group
->options
;
532 printf(" %s (%s):\n", option
->keyword
, option
->text
);
534 for (k
= 0; k
< option
->num_choices
; k
++)
535 printf(" - %s (%s)\n", option
->choices
[k
].choice
,
536 option
->choices
[k
].text
);
538 if ((coption
= ppdFindCustomOption(ppd
, option
->keyword
)) != NULL
)
540 for (cparam
= (ppd_cparam_t
*)cupsArrayFirst(coption
->params
);
542 cparam
= (ppd_cparam_t
*)cupsArrayNext(coption
->params
))
544 switch (cparam
->type
)
546 case PPD_CUSTOM_CURVE
:
547 printf(" %s(%s): PPD_CUSTOM_CURVE (%g to %g)\n",
548 cparam
->name
, cparam
->text
,
549 cparam
->minimum
.custom_curve
,
550 cparam
->maximum
.custom_curve
);
553 case PPD_CUSTOM_INT
:
554 printf(" %s(%s): PPD_CUSTOM_INT (%d to %d)\n",
555 cparam
->name
, cparam
->text
,
556 cparam
->minimum
.custom_int
,
557 cparam
->maximum
.custom_int
);
560 case PPD_CUSTOM_INVCURVE
:
561 printf(" %s(%s): PPD_CUSTOM_INVCURVE (%g to %g)\n",
562 cparam
->name
, cparam
->text
,
563 cparam
->minimum
.custom_invcurve
,
564 cparam
->maximum
.custom_invcurve
);
567 case PPD_CUSTOM_PASSCODE
:
568 printf(" %s(%s): PPD_CUSTOM_PASSCODE (%d to %d)\n",
569 cparam
->name
, cparam
->text
,
570 cparam
->minimum
.custom_passcode
,
571 cparam
->maximum
.custom_passcode
);
574 case PPD_CUSTOM_PASSWORD
:
575 printf(" %s(%s): PPD_CUSTOM_PASSWORD (%d to %d)\n",
576 cparam
->name
, cparam
->text
,
577 cparam
->minimum
.custom_password
,
578 cparam
->maximum
.custom_password
);
581 case PPD_CUSTOM_POINTS
:
582 printf(" %s(%s): PPD_CUSTOM_POINTS (%g to %g)\n",
583 cparam
->name
, cparam
->text
,
584 cparam
->minimum
.custom_points
,
585 cparam
->maximum
.custom_points
);
588 case PPD_CUSTOM_REAL
:
589 printf(" %s(%s): PPD_CUSTOM_REAL (%g to %g)\n",
590 cparam
->name
, cparam
->text
,
591 cparam
->minimum
.custom_real
,
592 cparam
->maximum
.custom_real
);
595 case PPD_CUSTOM_STRING
:
596 printf(" %s(%s): PPD_CUSTOM_STRING (%d to %d)\n",
597 cparam
->name
, cparam
->text
,
598 cparam
->minimum
.custom_string
,
599 cparam
->maximum
.custom_string
);
607 puts("Constraints:");
609 for (i
= ppd
->num_consts
, c
= ppd
->consts
; i
> 0; i
--, c
++)
610 printf(" *UIConstraints: *%s %s *%s %s\n", c
->option1
, c
->choice1
,
611 c
->option2
, c
->choice2
);
615 for (attr
= (ppd_attr_t
*)cupsArrayFirst(ppd
->sorted_attrs
);
617 attr
= (ppd_attr_t
*)cupsArrayNext(ppd
->sorted_attrs
))
618 printf(" *%s %s/%s: \"%s\"\n", attr
->name
, attr
->spec
,
619 attr
->text
, attr
->value
? attr
->value
: "");
622 if (!strncmp(argv
[1], "-d", 2))
627 if (getenv("MallocStackLogging") && getenv("MallocStackLoggingNoCompact"))
629 char command
[1024]; /* malloc_history command */
631 snprintf(command
, sizeof(command
), "malloc_history %d -all_by_size",
636 #endif /* __APPLE__ */
645 * End of "$Id: testppd.c 7633 2008-06-10 23:07:29Z mike $".