]>
Commit | Line | Data |
---|---|---|
4b0b2cf9 | 1 | /* |
f1c012ac | 2 | * "$Id: cupstestppd.c,v 1.4 2003/01/29 01:40:16 mike Exp $" |
4b0b2cf9 | 3 | * |
4 | * PPD test program for the Common UNIX Printing System (CUPS). | |
5 | * | |
997fbfa7 | 6 | * Copyright 1997-2003 by Easy Software Products, all rights reserved. |
4b0b2cf9 | 7 | * |
8 | * These coded instructions, statements, and computer programs are the | |
9 | * property of Easy Software Products and are protected by Federal | |
10 | * copyright law. Distribution and use rights are outlined in the file | |
11 | * "LICENSE.txt" which should have been included with this file. If this | |
12 | * file is missing or damaged please contact Easy Software Products | |
13 | * at: | |
14 | * | |
15 | * Attn: CUPS Licensing Information | |
16 | * Easy Software Products | |
17 | * 44141 Airport View Drive, Suite 204 | |
18 | * Hollywood, Maryland 20636-3111 USA | |
19 | * | |
20 | * Voice: (301) 373-9603 | |
21 | * EMail: cups-info@cups.org | |
22 | * WWW: http://www.cups.org | |
23 | * | |
24 | * PostScript is a trademark of Adobe Systems, Inc. | |
25 | * | |
26 | * This file is subject to the Apple OS-Developed Software exception. | |
27 | * | |
28 | * Contents: | |
29 | * | |
30 | * main() - Main entry for test program. | |
31 | */ | |
32 | ||
33 | /* | |
34 | * Include necessary headers... | |
35 | */ | |
36 | ||
37 | #include <cups/cups.h> | |
38 | #include <cups/string.h> | |
39 | #include <errno.h> | |
40 | ||
41 | ||
42 | /* | |
43 | * Error codes... | |
44 | */ | |
45 | ||
46 | #define ERROR_NONE 0 | |
47 | #define ERROR_USAGE 1 | |
48 | #define ERROR_FILE_OPEN 2 | |
49 | #define ERROR_PPD_FORMAT 3 | |
50 | #define ERROR_CONFORMANCE 4 | |
51 | ||
52 | ||
53 | /* | |
54 | * 'main()' - Main entry for test program. | |
55 | */ | |
56 | ||
57 | int /* O - Exit status */ | |
58 | main(int argc, /* I - Number of command-line arguments */ | |
59 | char *argv[]) /* I - Command-line arguments */ | |
60 | { | |
61 | int i, j, k, m; /* Looping vars */ | |
62 | int verbose; /* Want verbose output? */ | |
63 | int status; /* Exit status */ | |
64 | int errors; /* Number of conformance errors */ | |
65 | ppd_file_t *ppd; /* PPD file record */ | |
66 | ppd_size_t *size; /* Size record */ | |
67 | ppd_group_t *group; /* UI group */ | |
68 | ppd_option_t *option; /* Standard UI option */ | |
69 | ppd_choice_t *choice; /* Standard UI option choice */ | |
70 | static char *uis[] = { "BOOLEAN", "PICKONE", "PICKMANY" }; | |
71 | static char *sections[] = { "ANY", "DOCUMENT", "EXIT", | |
72 | "JCL", "PAGE", "PROLOG" }; | |
73 | ||
74 | ||
75 | setbuf(stdout, NULL); | |
76 | ||
77 | /* | |
78 | * Display PPD files for each file listed on the command-line... | |
79 | */ | |
80 | ||
81 | verbose = 0; | |
82 | ppd = NULL; | |
83 | status = ERROR_NONE; | |
84 | ||
85 | for (i = 1; i < argc; i ++) | |
77f83108 | 86 | if (strcmp(argv[i], "-q") == 0) |
87 | { | |
88 | if (verbose > 0) | |
89 | { | |
90 | fputs("cupstestppd: The -q option is incompatible with the -v option.\n", | |
91 | stderr); | |
92 | return (1); | |
93 | } | |
94 | ||
95 | verbose --; | |
96 | } | |
97 | else if (strcmp(argv[i], "-v") == 0) | |
98 | { | |
99 | if (verbose < 0) | |
100 | { | |
101 | fputs("cupstestppd: The -v option is incompatible with the -q option.\n", | |
102 | stderr); | |
103 | return (1); | |
104 | } | |
105 | ||
4b0b2cf9 | 106 | verbose ++; |
77f83108 | 107 | } |
4b0b2cf9 | 108 | else if (argv[i][0] == '-' && argv[i][1]) |
109 | { | |
110 | ppd = NULL; | |
111 | break; | |
112 | } | |
113 | else | |
114 | { | |
115 | /* | |
116 | * Open the PPD file... | |
117 | */ | |
118 | ||
119 | if (argv[i][0] == '-') | |
120 | { | |
121 | /* | |
122 | * Read from stdin... | |
123 | */ | |
124 | ||
77f83108 | 125 | if (verbose >= 0) |
126 | puts("FILE: (stdin)\n"); | |
4b0b2cf9 | 127 | |
128 | ppd = ppdOpen(stdin); | |
129 | } | |
130 | else | |
131 | { | |
132 | /* | |
133 | * Read from a file... | |
134 | */ | |
135 | ||
77f83108 | 136 | if (verbose >= 0) |
137 | printf("FILE: %s\n\n", argv[i]); | |
4b0b2cf9 | 138 | |
139 | ppd = ppdOpenFile(argv[i]); | |
140 | } | |
141 | ||
142 | if (ppd == NULL) | |
143 | { | |
144 | if (errno) | |
145 | { | |
146 | status = ERROR_FILE_OPEN; | |
77f83108 | 147 | |
148 | if (verbose >= 0) | |
149 | printf(" Unable to open PPD file - %s\n\n", strerror(errno)); | |
4b0b2cf9 | 150 | } |
151 | else | |
152 | { | |
153 | status = ERROR_PPD_FORMAT; | |
77f83108 | 154 | |
155 | if (verbose >= 0) | |
156 | puts(" Unable to open PPD file using CUPS functions!\n"); | |
4b0b2cf9 | 157 | } |
158 | ||
159 | continue; | |
160 | } | |
161 | ||
162 | /* | |
163 | * Show the header and then perform basic conformance tests (limited | |
164 | * only by what the CUPS PPD functions actually load...) | |
165 | */ | |
166 | ||
77f83108 | 167 | if (verbose >= 0) |
168 | puts(" CONFORMANCE TESTS:"); | |
4b0b2cf9 | 169 | |
170 | errors = 0; | |
171 | ||
172 | for (j = 0, group = ppd->groups; j < ppd->num_groups; j ++, group ++) | |
173 | for (k = 0, option = group->options; k < group->num_options; k ++, option ++) | |
174 | if (option->defchoice[0]) | |
175 | { | |
77f83108 | 176 | if (verbose >= 0) |
177 | printf(" PASS Default%s\n", option->keyword); | |
4b0b2cf9 | 178 | } |
179 | else | |
180 | { | |
181 | errors ++; | |
77f83108 | 182 | |
183 | if (verbose >= 0) | |
184 | printf(" **FAIL** REQUIRED Default%s\n", option->keyword); | |
4b0b2cf9 | 185 | } |
186 | ||
187 | if (ppd->num_fonts) | |
77f83108 | 188 | { |
189 | if (verbose >= 0) | |
190 | puts(" PASS Fonts"); | |
191 | } | |
4b0b2cf9 | 192 | else |
193 | { | |
194 | errors ++; | |
77f83108 | 195 | |
196 | if (verbose >= 0) | |
197 | puts(" **FAIL** REQUIRED Fonts"); | |
4b0b2cf9 | 198 | } |
199 | ||
200 | if (ppd->lang_encoding != NULL) | |
77f83108 | 201 | { |
202 | if (verbose >= 0) | |
203 | puts(" PASS LanguageEncoding"); | |
204 | } | |
4b0b2cf9 | 205 | else |
206 | { | |
207 | errors ++; | |
77f83108 | 208 | |
209 | if (verbose >= 0) | |
210 | puts(" **FAIL** REQUIRED LanguageEncoding"); | |
4b0b2cf9 | 211 | } |
212 | ||
213 | if (ppd->lang_version != NULL) | |
77f83108 | 214 | { |
215 | if (verbose >= 0) | |
216 | puts(" PASS LanguageVersion"); | |
217 | } | |
4b0b2cf9 | 218 | else |
219 | { | |
220 | errors ++; | |
77f83108 | 221 | |
222 | if (verbose >= 0) | |
223 | puts(" **FAIL** REQUIRED LanguageVersion"); | |
4b0b2cf9 | 224 | } |
225 | ||
226 | if (ppd->manufacturer != NULL) | |
77f83108 | 227 | { |
228 | if (verbose >= 0) | |
229 | puts(" PASS Manufacturer"); | |
230 | } | |
4b0b2cf9 | 231 | else |
232 | { | |
233 | errors ++; | |
77f83108 | 234 | |
235 | if (verbose >= 0) | |
236 | puts(" **FAIL** REQUIRED Manufacturer"); | |
4b0b2cf9 | 237 | } |
238 | ||
239 | if (ppd->modelname != NULL) | |
77f83108 | 240 | { |
241 | if (verbose >= 0) | |
242 | puts(" PASS ModelName"); | |
243 | } | |
4b0b2cf9 | 244 | else |
245 | { | |
246 | errors ++; | |
77f83108 | 247 | |
248 | if (verbose >= 0) | |
249 | puts(" **FAIL** REQUIRED ModelName"); | |
4b0b2cf9 | 250 | } |
251 | ||
252 | if (ppd->nickname != NULL) | |
77f83108 | 253 | { |
254 | if (verbose >= 0) | |
255 | puts(" PASS NickName"); | |
256 | } | |
4b0b2cf9 | 257 | else |
258 | { | |
259 | errors ++; | |
77f83108 | 260 | |
261 | if (verbose >= 0) | |
262 | puts(" **FAIL** REQUIRED NickName"); | |
4b0b2cf9 | 263 | } |
264 | ||
265 | if (ppdFindOption(ppd, "PageSize") != NULL) | |
77f83108 | 266 | { |
267 | if (verbose >= 0) | |
268 | puts(" PASS PageSize"); | |
269 | } | |
4b0b2cf9 | 270 | else |
271 | { | |
272 | errors ++; | |
77f83108 | 273 | |
274 | if (verbose >= 0) | |
275 | puts(" **FAIL** REQUIRED PageSize"); | |
4b0b2cf9 | 276 | } |
277 | ||
278 | if (ppdFindOption(ppd, "PageRegion") != NULL) | |
77f83108 | 279 | { |
280 | if (verbose >= 0) | |
281 | puts(" PASS PageRegion"); | |
282 | } | |
4b0b2cf9 | 283 | else |
284 | { | |
285 | errors ++; | |
77f83108 | 286 | |
287 | if (verbose >= 0) | |
288 | puts(" **FAIL** REQUIRED PageRegion"); | |
4b0b2cf9 | 289 | } |
290 | ||
291 | if (ppd->product != NULL) | |
77f83108 | 292 | { |
293 | if (verbose >= 0) | |
294 | puts(" PASS Product"); | |
295 | } | |
4b0b2cf9 | 296 | else |
297 | { | |
298 | errors ++; | |
77f83108 | 299 | |
300 | if (verbose >= 0) | |
301 | puts(" **FAIL** REQUIRED Product"); | |
4b0b2cf9 | 302 | } |
303 | ||
304 | if (ppd->shortnickname != NULL) | |
77f83108 | 305 | { |
306 | if (verbose >= 0) | |
307 | puts(" PASS ShortNickName"); | |
308 | } | |
4b0b2cf9 | 309 | else |
310 | { | |
311 | errors ++; | |
77f83108 | 312 | |
313 | if (verbose >= 0) | |
314 | puts(" **FAIL** REQUIRED ShortNickName"); | |
4b0b2cf9 | 315 | } |
316 | ||
317 | if (errors) | |
318 | { | |
77f83108 | 319 | if (verbose >= 0) |
320 | puts("\n **** CONFORMANCE TESTING FAILED ****"); | |
321 | ||
4b0b2cf9 | 322 | status = ERROR_CONFORMANCE; |
323 | } | |
324 | ||
77f83108 | 325 | if (verbose >= 0) |
326 | puts(""); | |
4b0b2cf9 | 327 | |
328 | /* | |
329 | * Then list the options, if "-v" was provided... | |
330 | */ | |
331 | ||
77f83108 | 332 | if (verbose > 0) |
4b0b2cf9 | 333 | { |
334 | puts(""); | |
335 | puts(" OPTIONS:"); | |
336 | printf(" language_level = %d\n", ppd->language_level); | |
337 | printf(" color_device = %s\n", ppd->color_device ? "TRUE" : "FALSE"); | |
338 | printf(" variable_sizes = %s\n", ppd->variable_sizes ? "TRUE" : "FALSE"); | |
339 | printf(" landscape = %d\n", ppd->landscape); | |
340 | ||
341 | switch (ppd->colorspace) | |
342 | { | |
343 | case PPD_CS_CMYK : | |
344 | puts(" colorspace = PPD_CS_CMYK"); | |
345 | break; | |
346 | case PPD_CS_CMY : | |
347 | puts(" colorspace = PPD_CS_CMY"); | |
348 | break; | |
349 | case PPD_CS_GRAY : | |
350 | puts(" colorspace = PPD_CS_GRAY"); | |
351 | break; | |
352 | case PPD_CS_RGB : | |
353 | puts(" colorspace = PPD_CS_RGB"); | |
354 | break; | |
355 | default : | |
356 | puts(" colorspace = <unknown>"); | |
357 | break; | |
358 | } | |
359 | ||
360 | printf(" num_emulations = %d\n", ppd->num_emulations); | |
361 | for (j = 0; j < ppd->num_emulations; j ++) | |
362 | printf(" emulations[%d] = %s\n", j, ppd->emulations[j].name); | |
363 | ||
364 | printf(" lang_encoding = %s\n", ppd->lang_encoding); | |
365 | printf(" lang_version = %s\n", ppd->lang_version); | |
366 | printf(" modelname = %s\n", ppd->modelname); | |
367 | printf(" ttrasterizer = %s\n", | |
368 | ppd->ttrasterizer == NULL ? "None" : ppd->ttrasterizer); | |
369 | printf(" manufacturer = %s\n", ppd->manufacturer); | |
370 | printf(" product = %s\n", ppd->product); | |
371 | printf(" nickname = %s\n", ppd->nickname); | |
372 | printf(" shortnickname = %s\n", ppd->shortnickname); | |
373 | printf(" patches = %d bytes\n", | |
374 | ppd->patches == NULL ? 0 : (int)strlen(ppd->patches)); | |
375 | ||
376 | printf(" num_groups = %d\n", ppd->num_groups); | |
377 | for (j = 0, group = ppd->groups; j < ppd->num_groups; j ++, group ++) | |
378 | { | |
379 | printf(" group[%d] = %s\n", j, group->text); | |
380 | ||
381 | for (k = 0, option = group->options; k < group->num_options; k ++, option ++) | |
382 | { | |
383 | printf(" options[%d] = %s (%s) %s %s %.0f (%d choices)\n", k, | |
384 | option->keyword, option->text, uis[option->ui], | |
385 | sections[option->section], option->order, | |
386 | option->num_choices); | |
387 | ||
388 | if (strcmp(option->keyword, "PageSize") == 0 || | |
389 | strcmp(option->keyword, "PageRegion") == 0) | |
390 | { | |
391 | for (m = option->num_choices, choice = option->choices; | |
392 | m > 0; | |
393 | m --, choice ++) | |
394 | { | |
395 | size = ppdPageSize(ppd, choice->choice); | |
396 | ||
397 | if (size == NULL) | |
398 | printf(" %s (%s) = ERROR", choice->choice, choice->text); | |
399 | else | |
400 | printf(" %s (%s) = %.2fx%.2fin (%.1f,%.1f,%.1f,%.1f)", choice->choice, | |
401 | choice->text, size->width / 72.0, size->length / 72.0, | |
402 | size->left / 72.0, size->bottom / 72.0, | |
403 | size->right / 72.0, size->top / 72.0); | |
404 | ||
405 | if (strcmp(option->defchoice, choice->choice) == 0) | |
406 | puts(" *"); | |
407 | else | |
408 | putchar('\n'); | |
409 | } | |
410 | } | |
411 | else | |
412 | { | |
413 | for (m = option->num_choices, choice = option->choices; | |
414 | m > 0; | |
415 | m --, choice ++) | |
416 | { | |
417 | printf(" %s (%s)", choice->choice, choice->text); | |
418 | ||
419 | if (strcmp(option->defchoice, choice->choice) == 0) | |
420 | puts(" *"); | |
421 | else | |
422 | putchar('\n'); | |
423 | } | |
424 | } | |
425 | } | |
426 | } | |
427 | ||
428 | printf(" num_profiles = %d\n", ppd->num_profiles); | |
429 | for (j = 0; j < ppd->num_profiles; j ++) | |
430 | printf(" profiles[%d] = %s/%s %.3f %.3f [ %.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f ]\n", | |
431 | j, ppd->profiles[j].resolution, ppd->profiles[j].media_type, | |
432 | ppd->profiles[j].gamma, ppd->profiles[j].density, | |
433 | ppd->profiles[j].matrix[0][0], ppd->profiles[j].matrix[0][1], | |
434 | ppd->profiles[j].matrix[0][2], ppd->profiles[j].matrix[1][0], | |
435 | ppd->profiles[j].matrix[1][1], ppd->profiles[j].matrix[1][2], | |
436 | ppd->profiles[j].matrix[2][0], ppd->profiles[j].matrix[2][1], | |
437 | ppd->profiles[j].matrix[2][2]); | |
438 | ||
439 | printf(" num_fonts = %d\n", ppd->num_fonts); | |
440 | for (j = 0; j < ppd->num_fonts; j ++) | |
441 | printf(" fonts[%d] = %s\n", j, ppd->fonts[j]); | |
442 | } | |
443 | ||
444 | ppdClose(ppd); | |
445 | } | |
446 | ||
f1c012ac | 447 | if (!ppd && verbose >= 0) |
4b0b2cf9 | 448 | { |
77f83108 | 449 | puts("Usage: cupstestppd [-q] [-v] filename1.ppd [... filenameN.ppd]"); |
450 | puts(" program | cupstestppd [-q] [-v] -"); | |
4b0b2cf9 | 451 | |
452 | return (ERROR_USAGE); | |
453 | } | |
454 | else | |
455 | return (status); | |
456 | } | |
457 | ||
458 | ||
459 | /* | |
f1c012ac | 460 | * End of "$Id: cupstestppd.c,v 1.4 2003/01/29 01:40:16 mike Exp $". |
4b0b2cf9 | 461 | */ |