]> git.ipfire.org Git - thirdparty/cups.git/blame - cups/testppd.c
Merge changes from CUPS 1.4svn-r8227.
[thirdparty/cups.git] / cups / testppd.c
CommitLineData
fa73b229 1/*
b19ccc9e 2 * "$Id: testppd.c 7897 2008-09-02 19:33:19Z mike $"
fa73b229 3 *
4 * PPD test program for the Common UNIX Printing System (CUPS).
5 *
c168a833 6 * Copyright 2007-2009 by Apple Inc.
fa73b229 7 * Copyright 1997-2006 by Easy Software Products.
8 *
9 * These coded instructions, statements, and computer programs are the
bc44d920 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/".
fa73b229 14 *
15 * This file is subject to the Apple OS-Developed Software exception.
16 *
17 * Contents:
18 *
19 * main() - Main entry.
20 */
21
22/*
23 * Include necessary headers...
24 */
25
26#include <stdio.h>
27#include <stdlib.h>
28#include <cups/string.h>
c9fc04c6 29#include <sys/stat.h>
fa73b229 30#include <errno.h>
dd1abb6b 31#include "cups.h"
c168a833 32#include "pwgmedia.h"
fa73b229 33#ifdef WIN32
34# include <io.h>
35#else
36# include <unistd.h>
37# include <fcntl.h>
38#endif /* WIN32 */
39
40
e1d6a774 41/*
42 * Test data...
43 */
44
45static const char *default_code =
66ab9486
MS
46 "[{\n"
47 "%%BeginFeature: *InstalledDuplexer False\n"
48 "%%EndFeature\n"
49 "} stopped cleartomark\n"
e1d6a774 50 "[{\n"
51 "%%BeginFeature: *PageRegion Letter\n"
52 "PageRegion=Letter\n"
53 "%%EndFeature\n"
54 "} stopped cleartomark\n"
55 "[{\n"
56 "%%BeginFeature: *InputSlot Tray\n"
57 "InputSlot=Tray\n"
58 "%%EndFeature\n"
8ca02f3c 59 "} stopped cleartomark\n"
60 "[{\n"
61 "%%BeginFeature: *IntOption None\n"
62 "%%EndFeature\n"
63 "} stopped cleartomark\n"
64 "[{\n"
65 "%%BeginFeature: *StringOption None\n"
66 "%%EndFeature\n"
67 "} stopped cleartomark\n";
68
69static const char *custom_code =
66ab9486
MS
70 "[{\n"
71 "%%BeginFeature: *InstalledDuplexer False\n"
72 "%%EndFeature\n"
73 "} stopped cleartomark\n"
8ca02f3c 74 "[{\n"
75 "%%BeginFeature: *InputSlot Tray\n"
76 "InputSlot=Tray\n"
77 "%%EndFeature\n"
78 "} stopped cleartomark\n"
79 "[{\n"
80 "%%BeginFeature: *IntOption None\n"
81 "%%EndFeature\n"
82 "} stopped cleartomark\n"
83 "[{\n"
ee571f26
MS
84 "%%BeginFeature: *CustomStringOption True\n"
85 "(value\\0502\\051)\n"
86 "(value 1)\n"
87 "StringOption=Custom\n"
8ca02f3c 88 "%%EndFeature\n"
0a682745
MS
89 "} stopped cleartomark\n"
90 "[{\n"
91 "%%BeginFeature: *CustomPageSize True\n"
92 "400\n"
93 "500\n"
94 "0\n"
95 "0\n"
96 "0\n"
97 "PageSize=Custom\n"
98 "%%EndFeature\n"
e1d6a774 99 "} stopped cleartomark\n";
100
101
fa73b229 102/*
103 * 'main()' - Main entry.
104 */
105
106int /* O - Exit status */
107main(int argc, /* I - Number of command-line arguments */
108 char *argv[]) /* I - Command-line arguments */
109{
66ab9486 110 int i; /* Looping var */
fa73b229 111 ppd_file_t *ppd; /* PPD file loaded from disk */
112 int status; /* Status of tests (0 = success, 1 = fail) */
e1d6a774 113 int conflicts; /* Number of conflicts */
114 char *s; /* String */
bc44d920 115 char buffer[8192]; /* String buffer */
5a738aea 116 const char *text; /* Localized text */
66ab9486
MS
117 int num_options; /* Number of options */
118 cups_option_t *options; /* Options */
005dd1eb 119 ppd_size_t minsize, /* Minimum size */
c168a833
MS
120 maxsize, /* Maximum size */
121 *size; /* Current size */
6e8b116d 122 ppd_attr_t *attr; /* Current attribute */
c168a833 123 _cups_pwg_media_t *pwgmedia; /* PWG media size */
fa73b229 124
125
126 status = 0;
127
a74454a7 128 if (argc == 1)
fa73b229 129 {
c9fc04c6
MS
130 /*
131 * Setup directories for locale stuff...
132 */
133
134 if (access("locale", 0))
135 {
136 mkdir("locale", 0777);
137 mkdir("locale/fr", 0777);
138 symlink("../../../locale/cups_fr.po", "locale/fr/cups_fr.po");
139 mkdir("locale/zh_TW", 0777);
140 symlink("../../../locale/cups_zh_TW.po", "locale/zh_TW/cups_zh_TW.po");
141 }
142
143 putenv("LOCALEDIR=locale");
144
145 /*
146 * Do tests with test.ppd...
147 */
148
66ab9486 149 fputs("ppdOpenFile(test.ppd): ", stdout);
a74454a7 150
151 if ((ppd = ppdOpenFile("test.ppd")) != NULL)
152 puts("PASS");
153 else
154 {
155 ppd_status_t err; /* Last error in file */
156 int line; /* Line number in file */
157
158
159 status ++;
160 err = ppdLastError(&line);
161
162 printf("FAIL (%s on line %d)\n", ppdErrorString(err), line);
163 }
164
6e8b116d
MS
165 fputs("ppdFindAttr(wildcard): ", stdout);
166 if ((attr = ppdFindAttr(ppd, "cupsTest", NULL)) == NULL)
167 {
168 status ++;
169 puts("FAIL (not found)");
170 }
171 else if (strcmp(attr->name, "cupsTest") || strcmp(attr->spec, "Foo"))
172 {
173 status ++;
174 printf("FAIL (got \"%s %s\")\n", attr->name, attr->spec);
175 }
176 else
177 puts("PASS");
178
179 fputs("ppdFindNextAttr(wildcard): ", stdout);
180 if ((attr = ppdFindNextAttr(ppd, "cupsTest", NULL)) == NULL)
181 {
182 status ++;
183 puts("FAIL (not found)");
184 }
185 else if (strcmp(attr->name, "cupsTest") || strcmp(attr->spec, "Bar"))
186 {
187 status ++;
188 printf("FAIL (got \"%s %s\")\n", attr->name, attr->spec);
189 }
190 else
191 puts("PASS");
192
193 fputs("ppdFindAttr(Foo): ", stdout);
194 if ((attr = ppdFindAttr(ppd, "cupsTest", "Foo")) == NULL)
195 {
196 status ++;
197 puts("FAIL (not found)");
198 }
199 else if (strcmp(attr->name, "cupsTest") || strcmp(attr->spec, "Foo"))
200 {
201 status ++;
202 printf("FAIL (got \"%s %s\")\n", attr->name, attr->spec);
203 }
204 else
205 puts("PASS");
206
207 fputs("ppdFindNextAttr(Foo): ", stdout);
208 if ((attr = ppdFindNextAttr(ppd, "cupsTest", "Foo")) != NULL)
209 {
210 status ++;
211 printf("FAIL (got \"%s %s\")\n", attr->name, attr->spec);
212 }
213 else
214 puts("PASS");
215
a74454a7 216 fputs("ppdMarkDefaults: ", stdout);
217 ppdMarkDefaults(ppd);
218
219 if ((conflicts = ppdConflicts(ppd)) == 0)
220 puts("PASS");
221 else
222 {
223 status ++;
224 printf("FAIL (%d conflicts)\n", conflicts);
225 }
226
8ca02f3c 227 fputs("ppdEmitString (defaults): ", stdout);
a74454a7 228 if ((s = ppdEmitString(ppd, PPD_ORDER_ANY, 0.0)) != NULL &&
229 !strcmp(s, default_code))
230 puts("PASS");
231 else
232 {
bc44d920 233 status ++;
a74454a7 234 printf("FAIL (%d bytes instead of %d)\n", s ? (int)strlen(s) : 0,
235 (int)strlen(default_code));
236
237 if (s)
238 puts(s);
ed486911 239 }
240
8ca02f3c 241 if (s)
242 free(s);
243
ee571f26 244 fputs("ppdEmitString (custom size and string): ", stdout);
8ca02f3c 245 ppdMarkOption(ppd, "PageSize", "Custom.400x500");
ee571f26 246 ppdMarkOption(ppd, "StringOption", "{String1=\"value 1\" String2=value(2)}");
8ca02f3c 247
248 if ((s = ppdEmitString(ppd, PPD_ORDER_ANY, 0.0)) != NULL &&
249 !strcmp(s, custom_code))
250 puts("PASS");
251 else
252 {
bc44d920 253 status ++;
8ca02f3c 254 printf("FAIL (%d bytes instead of %d)\n", s ? (int)strlen(s) : 0,
255 (int)strlen(custom_code));
256
257 if (s)
258 puts(s);
259 }
260
a74454a7 261 if (s)
262 free(s);
e1d6a774 263
66ab9486
MS
264 /*
265 * Test constraints...
266 */
267
268 fputs("ppdConflicts(): ", stdout);
269 ppdMarkOption(ppd, "PageSize", "Letter");
270 ppdMarkOption(ppd, "InputSlot", "Envelope");
271
272 if ((conflicts = ppdConflicts(ppd)) == 2)
273 puts("PASS (2)");
274 else
275 {
276 printf("FAIL (%d)\n", conflicts);
277 status ++;
278 }
279
06d4e77b 280 fputs("cupsResolveConflicts(InputSlot=Envelope): ", stdout);
66ab9486
MS
281 num_options = 0;
282 options = NULL;
c168a833 283 if (!cupsResolveConflicts(ppd, "InputSlot", "Envelope", &num_options,
06d4e77b
MS
284 &options))
285 {
c168a833
MS
286 puts("FAIL (Unable to resolve)");
287 status ++;
288 }
289 else if (num_options != 2 ||
290 !cupsGetOption("PageSize", num_options, options))
291 {
292 printf("FAIL (%d options:", num_options);
293 for (i = 0; i < num_options; i ++)
294 printf(" %s=%s", options[i].name, options[i].value);
295 puts(")");
06d4e77b
MS
296 status ++;
297 }
298 else
c168a833
MS
299 puts("PASS (Resolved by changing PageSize)");
300
06d4e77b
MS
301 cupsFreeOptions(num_options, options);
302
303 fputs("cupsResolveConflicts(No option/choice): ", stdout);
304 num_options = 0;
305 options = NULL;
306 if (cupsResolveConflicts(ppd, NULL, NULL, &num_options, &options) &&
307 num_options == 1 && !strcasecmp(options[0].name, "InputSlot") &&
c168a833
MS
308 !strcasecmp(options[0].value, "Tray"))
309 puts("PASS (Resolved by changing InputSlot)");
66ab9486
MS
310 else if (num_options > 0)
311 {
312 printf("FAIL (%d options:", num_options);
313 for (i = 0; i < num_options; i ++)
314 printf(" %s=%s", options[i].name, options[i].value);
315 puts(")");
316 status ++;
317 }
318 else
319 {
06d4e77b 320 puts("FAIL (Unable to resolve)");
66ab9486
MS
321 status ++;
322 }
323 cupsFreeOptions(num_options, options);
324
325 fputs("ppdInstallableConflict(): ", stdout);
326 if (ppdInstallableConflict(ppd, "Duplex", "DuplexNoTumble") &&
327 !ppdInstallableConflict(ppd, "Duplex", "None"))
328 puts("PASS");
329 else if (!ppdInstallableConflict(ppd, "Duplex", "DuplexNoTumble"))
330 {
331 puts("FAIL (Duplex=DuplexNoTumble did not conflict)");
332 status ++;
333 }
334 else
335 {
336 puts("FAIL (Duplex=None conflicted)");
337 status ++;
338 }
339
005dd1eb
MS
340 /*
341 * ppdPageSizeLimits
342 */
343
344 fputs("ppdPageSizeLimits: ", stdout);
345 if (ppdPageSizeLimits(ppd, &minsize, &maxsize))
346 {
347 if (minsize.width != 36 || minsize.length != 36 ||
348 maxsize.width != 1080 || maxsize.length != 86400)
349 {
350 printf("FAIL (got min=%.0fx%.0f, max=%.0fx%.0f, "
351 "expected min=36x36, max=1080x86400)\n", minsize.width,
352 minsize.length, maxsize.width, maxsize.length);
353 status ++;
354 }
355 else
356 puts("PASS");
357 }
358 else
359 {
360 puts("FAIL (returned 0)");
361 status ++;
362 }
363
c168a833
MS
364 /*
365 * cupsMarkOptions with PWG and IPP size names.
366 */
367
368 fputs("cupsMarkOptions(media=iso-a4): ", stdout);
369 num_options = cupsAddOption("media", "iso-a4", 0, &options);
370 cupsMarkOptions(ppd, num_options, options);
371 cupsFreeOptions(num_options, options);
372
373 size = ppdPageSize(ppd, NULL);
374 if (!size || strcmp(size->name, "A4"))
375 {
376 printf("FAIL (%s)\n", size ? size->name : "unknown");
377 status ++;
378 }
379 else
380 puts("PASS");
381
382 fputs("cupsMarkOptions(media=na_letter_8.5x11in): ", stdout);
383 num_options = cupsAddOption("media", "na_letter_8.5x11in", 0, &options);
384 cupsMarkOptions(ppd, num_options, options);
385 cupsFreeOptions(num_options, options);
386
387 size = ppdPageSize(ppd, NULL);
388 if (!size || strcmp(size->name, "Letter"))
389 {
390 printf("FAIL (%s)\n", size ? size->name : "unknown");
391 status ++;
392 }
393 else
394 puts("PASS");
395
396 fputs("_cupsPWGMediaBySize(842, 1191): ", stdout);
397 if ((pwgmedia = _cupsPWGMediaBySize(842, 1191)) == NULL)
398 {
399 puts("FAIL (not found)");
400 status ++;
401 }
402 else if (strcmp(pwgmedia->pwg, "iso_a3_297x420mm"))
403 {
404 printf("FAIL (%s)\n", pwgmedia->pwg);
405 status ++;
406 }
407 else
408 puts("PASS");
409
bc44d920 410 /*
411 * Test localization...
412 */
413
414 fputs("ppdLocalizeIPPReason(text): ", stdout);
415 if (ppdLocalizeIPPReason(ppd, "foo", NULL, buffer, sizeof(buffer)) &&
416 !strcmp(buffer, "Foo Reason"))
417 puts("PASS");
418 else
419 {
420 status ++;
421 printf("FAIL (\"%s\" instead of \"Foo Reason\")\n", buffer);
422 }
423
424 fputs("ppdLocalizeIPPReason(http): ", stdout);
425 if (ppdLocalizeIPPReason(ppd, "foo", "http", buffer, sizeof(buffer)) &&
426 !strcmp(buffer, "http://foo/bar.html"))
427 puts("PASS");
428 else
429 {
430 status ++;
431 printf("FAIL (\"%s\" instead of \"http://foo/bar.html\")\n", buffer);
432 }
433
434 fputs("ppdLocalizeIPPReason(help): ", stdout);
435 if (ppdLocalizeIPPReason(ppd, "foo", "help", buffer, sizeof(buffer)) &&
436 !strcmp(buffer, "help:anchor='foo'%20bookID=Vendor%20Help"))
437 puts("PASS");
438 else
439 {
440 status ++;
441 printf("FAIL (\"%s\" instead of \"help:anchor='foo'%%20bookID=Vendor%%20Help\")\n", buffer);
442 }
443
444 fputs("ppdLocalizeIPPReason(file): ", stdout);
445 if (ppdLocalizeIPPReason(ppd, "foo", "file", buffer, sizeof(buffer)) &&
446 !strcmp(buffer, "/help/foo/bar.html"))
447 puts("PASS");
448 else
449 {
450 status ++;
451 printf("FAIL (\"%s\" instead of \"/help/foo/bar.html\")\n", buffer);
452 }
453
454 putenv("LANG=fr");
c5571a1d
MS
455 putenv("LC_ALL=fr");
456 putenv("LC_CTYPE=fr");
457 putenv("LC_MESSAGES=fr");
bc44d920 458
459 fputs("ppdLocalizeIPPReason(fr text): ", stdout);
460 if (ppdLocalizeIPPReason(ppd, "foo", NULL, buffer, sizeof(buffer)) &&
461 !strcmp(buffer, "La Long Foo Reason"))
462 puts("PASS");
463 else
464 {
465 status ++;
466 printf("FAIL (\"%s\" instead of \"La Long Foo Reason\")\n", buffer);
467 }
468
db1f069b 469 putenv("LANG=zh_TW");
c5571a1d
MS
470 putenv("LC_ALL=zh_TW");
471 putenv("LC_CTYPE=zh_TW");
472 putenv("LC_MESSAGES=zh_TW");
db1f069b
MS
473
474 fputs("ppdLocalizeIPPReason(zh_TW text): ", stdout);
475 if (ppdLocalizeIPPReason(ppd, "foo", NULL, buffer, sizeof(buffer)) &&
476 !strcmp(buffer, "Number 1 Foo Reason"))
477 puts("PASS");
478 else
479 {
480 status ++;
481 printf("FAIL (\"%s\" instead of \"Number 1 Foo Reason\")\n", buffer);
482 }
5a738aea
MS
483
484 /*
485 * cupsMarkerName localization...
486 */
487
488 putenv("LANG=en");
c5571a1d
MS
489 putenv("LC_ALL=en");
490 putenv("LC_CTYPE=en");
491 putenv("LC_MESSAGES=en");
5a738aea
MS
492
493 fputs("ppdLocalizeMarkerName(bogus): ", stdout);
494
495 if ((text = ppdLocalizeMarkerName(ppd, "bogus")) != NULL)
496 {
497 status ++;
498 printf("FAIL (\"%s\" instead of NULL)\n", text);
499 }
500 else
501 puts("PASS");
502
503 fputs("ppdLocalizeMarkerName(cyan): ", stdout);
504
505 if ((text = ppdLocalizeMarkerName(ppd, "cyan")) != NULL &&
506 !strcmp(text, "Cyan Toner"))
507 puts("PASS");
508 else
509 {
510 status ++;
511 printf("FAIL (\"%s\" instead of \"Cyan Toner\")\n",
512 text ? text : "(null)");
513 }
514
515 putenv("LANG=fr");
c5571a1d
MS
516 putenv("LC_ALL=fr");
517 putenv("LC_CTYPE=fr");
518 putenv("LC_MESSAGES=fr");
5a738aea
MS
519
520 fputs("ppdLocalizeMarkerName(fr cyan): ", stdout);
521 if ((text = ppdLocalizeMarkerName(ppd, "cyan")) != NULL &&
522 !strcmp(text, "La Toner Cyan"))
523 puts("PASS");
524 else
525 {
526 status ++;
527 printf("FAIL (\"%s\" instead of \"La Toner Cyan\")\n",
528 text ? text : "(null)");
529 }
530
531 putenv("LANG=zh_TW");
c5571a1d
MS
532 putenv("LC_ALL=zh_TW");
533 putenv("LC_CTYPE=zh_TW");
534 putenv("LC_MESSAGES=zh_TW");
5a738aea
MS
535
536 fputs("ppdLocalizeMarkerName(zh_TW cyan): ", stdout);
537 if ((text = ppdLocalizeMarkerName(ppd, "cyan")) != NULL &&
538 !strcmp(text, "Number 1 Cyan Toner"))
539 puts("PASS");
540 else
541 {
542 status ++;
543 printf("FAIL (\"%s\" instead of \"Number 1 Cyan Toner\")\n",
544 text ? text : "(null)");
545 }
66ab9486
MS
546
547 ppdClose(ppd);
548
549 /*
550 * Test new constraints...
551 */
552
553 fputs("ppdOpenFile(test2.ppd): ", stdout);
554
555 if ((ppd = ppdOpenFile("test2.ppd")) != NULL)
556 puts("PASS");
557 else
558 {
559 ppd_status_t err; /* Last error in file */
560 int line; /* Line number in file */
561
562
563 status ++;
564 err = ppdLastError(&line);
565
566 printf("FAIL (%s on line %d)\n", ppdErrorString(err), line);
567 }
568
569 fputs("ppdMarkDefaults: ", stdout);
570 ppdMarkDefaults(ppd);
571
572 if ((conflicts = ppdConflicts(ppd)) == 0)
573 puts("PASS");
574 else
575 {
576 status ++;
577 printf("FAIL (%d conflicts)\n", conflicts);
578 }
579
580 fputs("ppdConflicts(): ", stdout);
581 ppdMarkOption(ppd, "PageSize", "Env10");
582 ppdMarkOption(ppd, "InputSlot", "Envelope");
583 ppdMarkOption(ppd, "Quality", "Photo");
584
585 if ((conflicts = ppdConflicts(ppd)) == 2)
586 puts("PASS (2)");
587 else
588 {
589 printf("FAIL (%d)\n", conflicts);
590 status ++;
591 }
592
06d4e77b 593 fputs("cupsResolveConflicts(Quality=Photo): ", stdout);
66ab9486
MS
594 num_options = 0;
595 options = NULL;
596 if (cupsResolveConflicts(ppd, "Quality", "Photo", &num_options,
06d4e77b
MS
597 &options))
598 {
599 printf("FAIL (%d options:", num_options);
600 for (i = 0; i < num_options; i ++)
601 printf(" %s=%s", options[i].name, options[i].value);
602 puts(")");
603 status ++;
604 }
605 else
606 puts("PASS (Unable to resolve)");
607 cupsFreeOptions(num_options, options);
608
609 fputs("cupsResolveConflicts(No option/choice): ", stdout);
610 num_options = 0;
611 options = NULL;
612 if (cupsResolveConflicts(ppd, NULL, NULL, &num_options, &options) &&
66ab9486
MS
613 num_options == 1 && !strcasecmp(options->name, "Quality") &&
614 !strcasecmp(options->value, "Normal"))
615 puts("PASS");
616 else if (num_options > 0)
617 {
618 printf("FAIL (%d options:", num_options);
619 for (i = 0; i < num_options; i ++)
620 printf(" %s=%s", options[i].name, options[i].value);
621 puts(")");
622 status ++;
623 }
624 else
625 {
626 puts("FAIL (Unable to resolve!)");
627 status ++;
628 }
629 cupsFreeOptions(num_options, options);
630
631 fputs("cupsResolveConflicts(loop test): ", stdout);
632 ppdMarkOption(ppd, "PageSize", "A4");
633 ppdMarkOption(ppd, "Quality", "Photo");
634 num_options = 0;
635 options = NULL;
06d4e77b 636 if (!cupsResolveConflicts(ppd, NULL, NULL, &num_options, &options))
66ab9486
MS
637 puts("PASS");
638 else if (num_options > 0)
639 {
640 printf("FAIL (%d options:", num_options);
641 for (i = 0; i < num_options; i ++)
642 printf(" %s=%s", options[i].name, options[i].value);
643 puts(")");
644 }
645 else
646 puts("FAIL (No conflicts!)");
647
648 fputs("ppdInstallableConflict(): ", stdout);
649 if (ppdInstallableConflict(ppd, "Duplex", "DuplexNoTumble") &&
650 !ppdInstallableConflict(ppd, "Duplex", "None"))
651 puts("PASS");
652 else if (!ppdInstallableConflict(ppd, "Duplex", "DuplexNoTumble"))
653 {
654 puts("FAIL (Duplex=DuplexNoTumble did not conflict)");
655 status ++;
656 }
657 else
658 {
659 puts("FAIL (Duplex=None conflicted)");
660 status ++;
661 }
005dd1eb
MS
662
663 /*
664 * ppdPageSizeLimits
665 */
666
667 ppdMarkDefaults(ppd);
668
669 fputs("ppdPageSizeLimits(default): ", stdout);
670 if (ppdPageSizeLimits(ppd, &minsize, &maxsize))
671 {
672 if (minsize.width != 36 || minsize.length != 36 ||
673 maxsize.width != 1080 || maxsize.length != 86400)
674 {
675 printf("FAIL (got min=%.0fx%.0f, max=%.0fx%.0f, "
676 "expected min=36x36, max=1080x86400)\n", minsize.width,
677 minsize.length, maxsize.width, maxsize.length);
678 status ++;
679 }
680 else
681 puts("PASS");
682 }
683 else
684 {
685 puts("FAIL (returned 0)");
686 status ++;
687 }
688
689 ppdMarkOption(ppd, "InputSlot", "Manual");
690
691 fputs("ppdPageSizeLimits(InputSlot=Manual): ", stdout);
692 if (ppdPageSizeLimits(ppd, &minsize, &maxsize))
693 {
694 if (minsize.width != 100 || minsize.length != 100 ||
695 maxsize.width != 1000 || maxsize.length != 1000)
696 {
697 printf("FAIL (got min=%.0fx%.0f, max=%.0fx%.0f, "
698 "expected min=100x100, max=1000x1000)\n", minsize.width,
699 minsize.length, maxsize.width, maxsize.length);
700 status ++;
701 }
702 else
703 puts("PASS");
704 }
705 else
706 {
707 puts("FAIL (returned 0)");
708 status ++;
709 }
710
711 ppdMarkOption(ppd, "Quality", "Photo");
712
713 fputs("ppdPageSizeLimits(Quality=Photo): ", stdout);
714 if (ppdPageSizeLimits(ppd, &minsize, &maxsize))
715 {
716 if (minsize.width != 200 || minsize.length != 200 ||
717 maxsize.width != 1000 || maxsize.length != 1000)
718 {
719 printf("FAIL (got min=%.0fx%.0f, max=%.0fx%.0f, "
720 "expected min=200x200, max=1000x1000)\n", minsize.width,
721 minsize.length, maxsize.width, maxsize.length);
722 status ++;
723 }
724 else
725 puts("PASS");
726 }
727 else
728 {
729 puts("FAIL (returned 0)");
730 status ++;
731 }
732
733 ppdMarkOption(ppd, "InputSlot", "Tray");
734
735 fputs("ppdPageSizeLimits(Quality=Photo): ", stdout);
736 if (ppdPageSizeLimits(ppd, &minsize, &maxsize))
737 {
738 if (minsize.width != 300 || minsize.length != 300 ||
739 maxsize.width != 1080 || maxsize.length != 86400)
740 {
741 printf("FAIL (got min=%.0fx%.0f, max=%.0fx%.0f, "
742 "expected min=300x300, max=1080x86400)\n", minsize.width,
743 minsize.length, maxsize.width, maxsize.length);
744 status ++;
745 }
746 else
747 puts("PASS");
748 }
749 else
750 {
751 puts("FAIL (returned 0)");
752 status ++;
753 }
e1d6a774 754 }
e1d6a774 755 else
756 {
dd1abb6b
MS
757 const char *filename; /* PPD filename */
758
759
760 if (!strncmp(argv[1], "-d", 2))
749b1e90 761 {
dd1abb6b 762 filename = cupsGetPPD(argv[1] + 2);
749b1e90
MS
763 if (!filename)
764 {
765 printf("%s: %s\n", argv[1], cupsLastErrorString());
766 return (1);
767 }
768 }
dd1abb6b
MS
769 else
770 filename = argv[1];
771
772 if ((ppd = ppdOpenFile(filename)) == NULL)
a74454a7 773 {
774 ppd_status_t err; /* Last error in file */
775 int line; /* Line number in file */
776
777
778 status ++;
779 err = ppdLastError(&line);
780
781 printf("%s: %s on line %d\n", argv[1], ppdErrorString(err), line);
782 }
783 else
784 {
66ab9486 785 int j, k; /* Looping vars */
a74454a7 786 ppd_group_t *group; /* Option group */
787 ppd_option_t *option; /* Option */
b86bc4cf 788 ppd_coption_t *coption; /* Custom option */
789 ppd_cparam_t *cparam; /* Custom parameter */
66ab9486 790 ppd_const_t *c; /* UIConstraints */
c5571a1d
MS
791 char lang[255], /* LANG environment variable */
792 lc_all[255], /* LC_ALL environment variable */
793 lc_ctype[255], /* LC_CTYPE environment variable */
794 lc_messages[255];/* LC_MESSAGES environment variable */
a74454a7 795
796
d09495fa 797 if (argc > 2)
798 {
799 snprintf(lang, sizeof(lang), "LANG=%s", argv[2]);
800 putenv(lang);
c5571a1d
MS
801 snprintf(lc_all, sizeof(lc_all), "LC_ALL=%s", argv[2]);
802 putenv(lc_all);
803 snprintf(lc_ctype, sizeof(lc_ctype), "LC_CTYPE=%s", argv[2]);
804 putenv(lc_ctype);
805 snprintf(lc_messages, sizeof(lc_messages), "LC_MESSAGES=%s", argv[2]);
806 putenv(lc_messages);
d09495fa 807 }
808
a74454a7 809 ppdLocalize(ppd);
810
e4572d57
MS
811 if (argc > 3)
812 {
813 text = ppdLocalizeIPPReason(ppd, argv[3], NULL, buffer, sizeof(buffer));
814 printf("ppdLocalizeIPPReason(%s)=%s\n", argv[3],
815 text ? text : "(null)");
816 return (text == NULL);
817 }
818
a74454a7 819 for (i = ppd->num_groups, group = ppd->groups;
820 i > 0;
821 i --, group ++)
822 {
823 printf("%s (%s):\n", group->name, group->text);
d09495fa 824
a74454a7 825 for (j = group->num_options, option = group->options;
826 j > 0;
827 j --, option ++)
828 {
829 printf(" %s (%s):\n", option->keyword, option->text);
830
831 for (k = 0; k < option->num_choices; k ++)
832 printf(" - %s (%s)\n", option->choices[k].choice,
833 option->choices[k].text);
b86bc4cf 834
835 if ((coption = ppdFindCustomOption(ppd, option->keyword)) != NULL)
836 {
837 for (cparam = (ppd_cparam_t *)cupsArrayFirst(coption->params);
838 cparam;
839 cparam = (ppd_cparam_t *)cupsArrayNext(coption->params))
840 {
841 switch (cparam->type)
842 {
843 case PPD_CUSTOM_CURVE :
844 printf(" %s(%s): PPD_CUSTOM_CURVE (%g to %g)\n",
845 cparam->name, cparam->text,
846 cparam->minimum.custom_curve,
847 cparam->maximum.custom_curve);
848 break;
849
850 case PPD_CUSTOM_INT :
851 printf(" %s(%s): PPD_CUSTOM_INT (%d to %d)\n",
852 cparam->name, cparam->text,
853 cparam->minimum.custom_int,
854 cparam->maximum.custom_int);
855 break;
856
857 case PPD_CUSTOM_INVCURVE :
858 printf(" %s(%s): PPD_CUSTOM_INVCURVE (%g to %g)\n",
859 cparam->name, cparam->text,
860 cparam->minimum.custom_invcurve,
861 cparam->maximum.custom_invcurve);
862 break;
863
864 case PPD_CUSTOM_PASSCODE :
865 printf(" %s(%s): PPD_CUSTOM_PASSCODE (%d to %d)\n",
866 cparam->name, cparam->text,
867 cparam->minimum.custom_passcode,
868 cparam->maximum.custom_passcode);
869 break;
870
871 case PPD_CUSTOM_PASSWORD :
872 printf(" %s(%s): PPD_CUSTOM_PASSWORD (%d to %d)\n",
873 cparam->name, cparam->text,
874 cparam->minimum.custom_password,
875 cparam->maximum.custom_password);
876 break;
877
878 case PPD_CUSTOM_POINTS :
879 printf(" %s(%s): PPD_CUSTOM_POINTS (%g to %g)\n",
880 cparam->name, cparam->text,
881 cparam->minimum.custom_points,
882 cparam->maximum.custom_points);
883 break;
884
885 case PPD_CUSTOM_REAL :
886 printf(" %s(%s): PPD_CUSTOM_REAL (%g to %g)\n",
887 cparam->name, cparam->text,
888 cparam->minimum.custom_real,
889 cparam->maximum.custom_real);
890 break;
891
892 case PPD_CUSTOM_STRING :
893 printf(" %s(%s): PPD_CUSTOM_STRING (%d to %d)\n",
894 cparam->name, cparam->text,
895 cparam->minimum.custom_string,
896 cparam->maximum.custom_string);
897 break;
898 }
899 }
900 }
a74454a7 901 }
902 }
d09495fa 903
66ab9486
MS
904 puts("Constraints:");
905
906 for (i = ppd->num_consts, c = ppd->consts; i > 0; i --, c ++)
907 printf(" *UIConstraints: *%s %s *%s %s\n", c->option1, c->choice1,
908 c->option2, c->choice2);
909
d09495fa 910 puts("Attributes:");
911
912 for (attr = (ppd_attr_t *)cupsArrayFirst(ppd->sorted_attrs);
913 attr;
914 attr = (ppd_attr_t *)cupsArrayNext(ppd->sorted_attrs))
915 printf(" *%s %s/%s: \"%s\"\n", attr->name, attr->spec,
916 attr->text, attr->value ? attr->value : "");
a74454a7 917 }
dd1abb6b
MS
918
919 if (!strncmp(argv[1], "-d", 2))
920 unlink(filename);
e1d6a774 921 }
922
2e4ff8af
MS
923#ifdef __APPLE__
924 if (getenv("MallocStackLogging") && getenv("MallocStackLoggingNoCompact"))
925 {
926 char command[1024]; /* malloc_history command */
927
928 snprintf(command, sizeof(command), "malloc_history %d -all_by_size",
929 getpid());
930 fflush(stdout);
931 system(command);
932 }
933#endif /* __APPLE__ */
934
935 ppdClose(ppd);
936
fa73b229 937 return (status);
938}
939
940
941/*
b19ccc9e 942 * End of "$Id: testppd.c 7897 2008-09-02 19:33:19Z mike $".
fa73b229 943 */