]>
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 | * | |
bc44d920 | 6 | * Copyright 2007 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 = | |
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" | |
56 | "%%BeginFeature: *IntOption None\n" | |
57 | "%%EndFeature\n" | |
58 | "} stopped cleartomark\n" | |
59 | "[{\n" | |
60 | "%%BeginFeature: *StringOption None\n" | |
61 | "%%EndFeature\n" | |
62 | "} stopped cleartomark\n"; | |
63 | ||
64 | static const char *custom_code = | |
8ca02f3c | 65 | "[{\n" |
66 | "%%BeginFeature: *InputSlot Tray\n" | |
67 | "InputSlot=Tray\n" | |
68 | "%%EndFeature\n" | |
69 | "} stopped cleartomark\n" | |
70 | "[{\n" | |
71 | "%%BeginFeature: *IntOption None\n" | |
72 | "%%EndFeature\n" | |
73 | "} stopped cleartomark\n" | |
74 | "[{\n" | |
75 | "%%BeginFeature: *StringOption None\n" | |
76 | "%%EndFeature\n" | |
0a682745 MS |
77 | "} stopped cleartomark\n" |
78 | "[{\n" | |
79 | "%%BeginFeature: *CustomPageSize True\n" | |
80 | "400\n" | |
81 | "500\n" | |
82 | "0\n" | |
83 | "0\n" | |
84 | "0\n" | |
85 | "PageSize=Custom\n" | |
86 | "%%EndFeature\n" | |
e1d6a774 | 87 | "} stopped cleartomark\n"; |
88 | ||
89 | ||
fa73b229 | 90 | /* |
91 | * 'main()' - Main entry. | |
92 | */ | |
93 | ||
94 | int /* O - Exit status */ | |
95 | main(int argc, /* I - Number of command-line arguments */ | |
96 | char *argv[]) /* I - Command-line arguments */ | |
97 | { | |
98 | ppd_file_t *ppd; /* PPD file loaded from disk */ | |
99 | int status; /* Status of tests (0 = success, 1 = fail) */ | |
e1d6a774 | 100 | int conflicts; /* Number of conflicts */ |
101 | char *s; /* String */ | |
bc44d920 | 102 | char buffer[8192]; /* String buffer */ |
5a738aea | 103 | const char *text; /* Localized text */ |
fa73b229 | 104 | |
105 | ||
106 | status = 0; | |
107 | ||
a74454a7 | 108 | if (argc == 1) |
fa73b229 | 109 | { |
c9fc04c6 MS |
110 | /* |
111 | * Setup directories for locale stuff... | |
112 | */ | |
113 | ||
114 | if (access("locale", 0)) | |
115 | { | |
116 | mkdir("locale", 0777); | |
117 | mkdir("locale/fr", 0777); | |
118 | symlink("../../../locale/cups_fr.po", "locale/fr/cups_fr.po"); | |
119 | mkdir("locale/zh_TW", 0777); | |
120 | symlink("../../../locale/cups_zh_TW.po", "locale/zh_TW/cups_zh_TW.po"); | |
121 | } | |
122 | ||
123 | putenv("LOCALEDIR=locale"); | |
124 | ||
125 | /* | |
126 | * Do tests with test.ppd... | |
127 | */ | |
128 | ||
a74454a7 | 129 | fputs("ppdOpenFile: ", stdout); |
130 | ||
131 | if ((ppd = ppdOpenFile("test.ppd")) != NULL) | |
132 | puts("PASS"); | |
133 | else | |
134 | { | |
135 | ppd_status_t err; /* Last error in file */ | |
136 | int line; /* Line number in file */ | |
137 | ||
138 | ||
139 | status ++; | |
140 | err = ppdLastError(&line); | |
141 | ||
142 | printf("FAIL (%s on line %d)\n", ppdErrorString(err), line); | |
143 | } | |
144 | ||
145 | fputs("ppdMarkDefaults: ", stdout); | |
146 | ppdMarkDefaults(ppd); | |
147 | ||
148 | if ((conflicts = ppdConflicts(ppd)) == 0) | |
149 | puts("PASS"); | |
150 | else | |
151 | { | |
152 | status ++; | |
153 | printf("FAIL (%d conflicts)\n", conflicts); | |
154 | } | |
155 | ||
8ca02f3c | 156 | fputs("ppdEmitString (defaults): ", stdout); |
a74454a7 | 157 | if ((s = ppdEmitString(ppd, PPD_ORDER_ANY, 0.0)) != NULL && |
158 | !strcmp(s, default_code)) | |
159 | puts("PASS"); | |
160 | else | |
161 | { | |
bc44d920 | 162 | status ++; |
a74454a7 | 163 | printf("FAIL (%d bytes instead of %d)\n", s ? (int)strlen(s) : 0, |
164 | (int)strlen(default_code)); | |
165 | ||
166 | if (s) | |
167 | puts(s); | |
ed486911 | 168 | } |
169 | ||
8ca02f3c | 170 | if (s) |
171 | free(s); | |
172 | ||
173 | fputs("ppdEmitString (custom size): ", stdout); | |
174 | ppdMarkOption(ppd, "PageSize", "Custom.400x500"); | |
175 | ||
176 | if ((s = ppdEmitString(ppd, PPD_ORDER_ANY, 0.0)) != NULL && | |
177 | !strcmp(s, custom_code)) | |
178 | puts("PASS"); | |
179 | else | |
180 | { | |
bc44d920 | 181 | status ++; |
8ca02f3c | 182 | printf("FAIL (%d bytes instead of %d)\n", s ? (int)strlen(s) : 0, |
183 | (int)strlen(custom_code)); | |
184 | ||
185 | if (s) | |
186 | puts(s); | |
187 | } | |
188 | ||
a74454a7 | 189 | if (s) |
190 | free(s); | |
e1d6a774 | 191 | |
bc44d920 | 192 | /* |
193 | * Test localization... | |
194 | */ | |
195 | ||
196 | fputs("ppdLocalizeIPPReason(text): ", stdout); | |
197 | if (ppdLocalizeIPPReason(ppd, "foo", NULL, buffer, sizeof(buffer)) && | |
198 | !strcmp(buffer, "Foo Reason")) | |
199 | puts("PASS"); | |
200 | else | |
201 | { | |
202 | status ++; | |
203 | printf("FAIL (\"%s\" instead of \"Foo Reason\")\n", buffer); | |
204 | } | |
205 | ||
206 | fputs("ppdLocalizeIPPReason(http): ", stdout); | |
207 | if (ppdLocalizeIPPReason(ppd, "foo", "http", buffer, sizeof(buffer)) && | |
208 | !strcmp(buffer, "http://foo/bar.html")) | |
209 | puts("PASS"); | |
210 | else | |
211 | { | |
212 | status ++; | |
213 | printf("FAIL (\"%s\" instead of \"http://foo/bar.html\")\n", buffer); | |
214 | } | |
215 | ||
216 | fputs("ppdLocalizeIPPReason(help): ", stdout); | |
217 | if (ppdLocalizeIPPReason(ppd, "foo", "help", buffer, sizeof(buffer)) && | |
218 | !strcmp(buffer, "help:anchor='foo'%20bookID=Vendor%20Help")) | |
219 | puts("PASS"); | |
220 | else | |
221 | { | |
222 | status ++; | |
223 | printf("FAIL (\"%s\" instead of \"help:anchor='foo'%%20bookID=Vendor%%20Help\")\n", buffer); | |
224 | } | |
225 | ||
226 | fputs("ppdLocalizeIPPReason(file): ", stdout); | |
227 | if (ppdLocalizeIPPReason(ppd, "foo", "file", buffer, sizeof(buffer)) && | |
228 | !strcmp(buffer, "/help/foo/bar.html")) | |
229 | puts("PASS"); | |
230 | else | |
231 | { | |
232 | status ++; | |
233 | printf("FAIL (\"%s\" instead of \"/help/foo/bar.html\")\n", buffer); | |
234 | } | |
235 | ||
236 | putenv("LANG=fr"); | |
237 | ||
238 | fputs("ppdLocalizeIPPReason(fr text): ", stdout); | |
239 | if (ppdLocalizeIPPReason(ppd, "foo", NULL, buffer, sizeof(buffer)) && | |
240 | !strcmp(buffer, "La Long Foo Reason")) | |
241 | puts("PASS"); | |
242 | else | |
243 | { | |
244 | status ++; | |
245 | printf("FAIL (\"%s\" instead of \"La Long Foo Reason\")\n", buffer); | |
246 | } | |
247 | ||
db1f069b MS |
248 | putenv("LANG=zh_TW"); |
249 | ||
250 | fputs("ppdLocalizeIPPReason(zh_TW text): ", stdout); | |
251 | if (ppdLocalizeIPPReason(ppd, "foo", NULL, buffer, sizeof(buffer)) && | |
252 | !strcmp(buffer, "Number 1 Foo Reason")) | |
253 | puts("PASS"); | |
254 | else | |
255 | { | |
256 | status ++; | |
257 | printf("FAIL (\"%s\" instead of \"Number 1 Foo Reason\")\n", buffer); | |
258 | } | |
5a738aea MS |
259 | |
260 | /* | |
261 | * cupsMarkerName localization... | |
262 | */ | |
263 | ||
264 | putenv("LANG=en"); | |
265 | ||
266 | fputs("ppdLocalizeMarkerName(bogus): ", stdout); | |
267 | ||
268 | if ((text = ppdLocalizeMarkerName(ppd, "bogus")) != NULL) | |
269 | { | |
270 | status ++; | |
271 | printf("FAIL (\"%s\" instead of NULL)\n", text); | |
272 | } | |
273 | else | |
274 | puts("PASS"); | |
275 | ||
276 | fputs("ppdLocalizeMarkerName(cyan): ", stdout); | |
277 | ||
278 | if ((text = ppdLocalizeMarkerName(ppd, "cyan")) != NULL && | |
279 | !strcmp(text, "Cyan Toner")) | |
280 | puts("PASS"); | |
281 | else | |
282 | { | |
283 | status ++; | |
284 | printf("FAIL (\"%s\" instead of \"Cyan Toner\")\n", | |
285 | text ? text : "(null)"); | |
286 | } | |
287 | ||
288 | putenv("LANG=fr"); | |
289 | ||
290 | fputs("ppdLocalizeMarkerName(fr cyan): ", stdout); | |
291 | if ((text = ppdLocalizeMarkerName(ppd, "cyan")) != NULL && | |
292 | !strcmp(text, "La Toner Cyan")) | |
293 | puts("PASS"); | |
294 | else | |
295 | { | |
296 | status ++; | |
297 | printf("FAIL (\"%s\" instead of \"La Toner Cyan\")\n", | |
298 | text ? text : "(null)"); | |
299 | } | |
300 | ||
301 | putenv("LANG=zh_TW"); | |
302 | ||
303 | fputs("ppdLocalizeMarkerName(zh_TW cyan): ", stdout); | |
304 | if ((text = ppdLocalizeMarkerName(ppd, "cyan")) != NULL && | |
305 | !strcmp(text, "Number 1 Cyan Toner")) | |
306 | puts("PASS"); | |
307 | else | |
308 | { | |
309 | status ++; | |
310 | printf("FAIL (\"%s\" instead of \"Number 1 Cyan Toner\")\n", | |
311 | text ? text : "(null)"); | |
312 | } | |
e1d6a774 | 313 | } |
e1d6a774 | 314 | else |
315 | { | |
dd1abb6b MS |
316 | const char *filename; /* PPD filename */ |
317 | ||
318 | ||
319 | if (!strncmp(argv[1], "-d", 2)) | |
320 | filename = cupsGetPPD(argv[1] + 2); | |
321 | else | |
322 | filename = argv[1]; | |
323 | ||
324 | if ((ppd = ppdOpenFile(filename)) == NULL) | |
a74454a7 | 325 | { |
326 | ppd_status_t err; /* Last error in file */ | |
327 | int line; /* Line number in file */ | |
328 | ||
329 | ||
330 | status ++; | |
331 | err = ppdLastError(&line); | |
332 | ||
333 | printf("%s: %s on line %d\n", argv[1], ppdErrorString(err), line); | |
334 | } | |
335 | else | |
336 | { | |
337 | int i, j, k; /* Looping vars */ | |
d09495fa | 338 | ppd_attr_t *attr; /* Current attribute */ |
a74454a7 | 339 | ppd_group_t *group; /* Option group */ |
340 | ppd_option_t *option; /* Option */ | |
b86bc4cf | 341 | ppd_coption_t *coption; /* Custom option */ |
342 | ppd_cparam_t *cparam; /* Custom parameter */ | |
d09495fa | 343 | char lang[255]; /* LANG environment variable */ |
a74454a7 | 344 | |
345 | ||
d09495fa | 346 | if (argc > 2) |
347 | { | |
348 | snprintf(lang, sizeof(lang), "LANG=%s", argv[2]); | |
349 | putenv(lang); | |
350 | } | |
351 | ||
a74454a7 | 352 | ppdLocalize(ppd); |
353 | ||
354 | for (i = ppd->num_groups, group = ppd->groups; | |
355 | i > 0; | |
356 | i --, group ++) | |
357 | { | |
358 | printf("%s (%s):\n", group->name, group->text); | |
d09495fa | 359 | |
a74454a7 | 360 | for (j = group->num_options, option = group->options; |
361 | j > 0; | |
362 | j --, option ++) | |
363 | { | |
364 | printf(" %s (%s):\n", option->keyword, option->text); | |
365 | ||
366 | for (k = 0; k < option->num_choices; k ++) | |
367 | printf(" - %s (%s)\n", option->choices[k].choice, | |
368 | option->choices[k].text); | |
b86bc4cf | 369 | |
370 | if ((coption = ppdFindCustomOption(ppd, option->keyword)) != NULL) | |
371 | { | |
372 | for (cparam = (ppd_cparam_t *)cupsArrayFirst(coption->params); | |
373 | cparam; | |
374 | cparam = (ppd_cparam_t *)cupsArrayNext(coption->params)) | |
375 | { | |
376 | switch (cparam->type) | |
377 | { | |
378 | case PPD_CUSTOM_CURVE : | |
379 | printf(" %s(%s): PPD_CUSTOM_CURVE (%g to %g)\n", | |
380 | cparam->name, cparam->text, | |
381 | cparam->minimum.custom_curve, | |
382 | cparam->maximum.custom_curve); | |
383 | break; | |
384 | ||
385 | case PPD_CUSTOM_INT : | |
386 | printf(" %s(%s): PPD_CUSTOM_INT (%d to %d)\n", | |
387 | cparam->name, cparam->text, | |
388 | cparam->minimum.custom_int, | |
389 | cparam->maximum.custom_int); | |
390 | break; | |
391 | ||
392 | case PPD_CUSTOM_INVCURVE : | |
393 | printf(" %s(%s): PPD_CUSTOM_INVCURVE (%g to %g)\n", | |
394 | cparam->name, cparam->text, | |
395 | cparam->minimum.custom_invcurve, | |
396 | cparam->maximum.custom_invcurve); | |
397 | break; | |
398 | ||
399 | case PPD_CUSTOM_PASSCODE : | |
400 | printf(" %s(%s): PPD_CUSTOM_PASSCODE (%d to %d)\n", | |
401 | cparam->name, cparam->text, | |
402 | cparam->minimum.custom_passcode, | |
403 | cparam->maximum.custom_passcode); | |
404 | break; | |
405 | ||
406 | case PPD_CUSTOM_PASSWORD : | |
407 | printf(" %s(%s): PPD_CUSTOM_PASSWORD (%d to %d)\n", | |
408 | cparam->name, cparam->text, | |
409 | cparam->minimum.custom_password, | |
410 | cparam->maximum.custom_password); | |
411 | break; | |
412 | ||
413 | case PPD_CUSTOM_POINTS : | |
414 | printf(" %s(%s): PPD_CUSTOM_POINTS (%g to %g)\n", | |
415 | cparam->name, cparam->text, | |
416 | cparam->minimum.custom_points, | |
417 | cparam->maximum.custom_points); | |
418 | break; | |
419 | ||
420 | case PPD_CUSTOM_REAL : | |
421 | printf(" %s(%s): PPD_CUSTOM_REAL (%g to %g)\n", | |
422 | cparam->name, cparam->text, | |
423 | cparam->minimum.custom_real, | |
424 | cparam->maximum.custom_real); | |
425 | break; | |
426 | ||
427 | case PPD_CUSTOM_STRING : | |
428 | printf(" %s(%s): PPD_CUSTOM_STRING (%d to %d)\n", | |
429 | cparam->name, cparam->text, | |
430 | cparam->minimum.custom_string, | |
431 | cparam->maximum.custom_string); | |
432 | break; | |
433 | } | |
434 | } | |
435 | } | |
a74454a7 | 436 | } |
437 | } | |
d09495fa | 438 | |
439 | puts("Attributes:"); | |
440 | ||
441 | for (attr = (ppd_attr_t *)cupsArrayFirst(ppd->sorted_attrs); | |
442 | attr; | |
443 | attr = (ppd_attr_t *)cupsArrayNext(ppd->sorted_attrs)) | |
444 | printf(" *%s %s/%s: \"%s\"\n", attr->name, attr->spec, | |
445 | attr->text, attr->value ? attr->value : ""); | |
a74454a7 | 446 | } |
dd1abb6b MS |
447 | |
448 | if (!strncmp(argv[1], "-d", 2)) | |
449 | unlink(filename); | |
e1d6a774 | 450 | } |
451 | ||
2e4ff8af MS |
452 | #ifdef __APPLE__ |
453 | if (getenv("MallocStackLogging") && getenv("MallocStackLoggingNoCompact")) | |
454 | { | |
455 | char command[1024]; /* malloc_history command */ | |
456 | ||
457 | snprintf(command, sizeof(command), "malloc_history %d -all_by_size", | |
458 | getpid()); | |
459 | fflush(stdout); | |
460 | system(command); | |
461 | } | |
462 | #endif /* __APPLE__ */ | |
463 | ||
464 | ppdClose(ppd); | |
465 | ||
fa73b229 | 466 | return (status); |
467 | } | |
468 | ||
469 | ||
470 | /* | |
75bd9771 | 471 | * End of "$Id: testppd.c 7633 2008-06-10 23:07:29Z mike $". |
fa73b229 | 472 | */ |