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