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