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