]> git.ipfire.org Git - thirdparty/cups.git/blob - systemv/cupstestppd.c
8e4f4226734bc7c001749c288231e545d6868dfb
[thirdparty/cups.git] / systemv / cupstestppd.c
1 /*
2 * "$Id: cupstestppd.c,v 1.1 2002/12/13 21:18:08 mike Exp $"
3 *
4 * PPD test program for the Common UNIX Printing System (CUPS).
5 *
6 * Copyright 1997-2002 by Easy Software Products, all rights reserved.
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 ++)
86 if (strcmp(argv[i], "-v") == 0)
87 verbose ++;
88 else if (argv[i][0] == '-' && argv[i][1])
89 {
90 ppd = NULL;
91 break;
92 }
93 else
94 {
95 /*
96 * Open the PPD file...
97 */
98
99 if (argv[i][0] == '-')
100 {
101 /*
102 * Read from stdin...
103 */
104
105 puts("FILE: (stdin)\n");
106
107 ppd = ppdOpen(stdin);
108 }
109 else
110 {
111 /*
112 * Read from a file...
113 */
114
115 printf("FILE: %s\n\n", argv[i]);
116
117 ppd = ppdOpenFile(argv[i]);
118 }
119
120 if (ppd == NULL)
121 {
122 if (errno)
123 {
124 status = ERROR_FILE_OPEN;
125 printf(" Unable to open PPD file - %s\n\n", strerror(errno));
126 }
127 else
128 {
129 status = ERROR_PPD_FORMAT;
130 puts(" Unable to open PPD file using CUPS functions!\n");
131 }
132
133 continue;
134 }
135
136 /*
137 * Show the header and then perform basic conformance tests (limited
138 * only by what the CUPS PPD functions actually load...)
139 */
140
141 puts(" CONFORMANCE TESTS:");
142
143 errors = 0;
144
145 for (j = 0, group = ppd->groups; j < ppd->num_groups; j ++, group ++)
146 for (k = 0, option = group->options; k < group->num_options; k ++, option ++)
147 if (option->defchoice[0])
148 {
149 printf(" PASS Default%s\n", option->keyword);
150 }
151 else
152 {
153 errors ++;
154 printf(" **FAIL** REQUIRED Default%s\n", option->keyword);
155 }
156
157 if (ppd->num_fonts)
158 puts(" PASS Fonts");
159 else
160 {
161 errors ++;
162 puts(" **FAIL** REQUIRED Fonts");
163 }
164
165 if (ppd->lang_encoding != NULL)
166 puts(" PASS LanguageEncoding");
167 else
168 {
169 errors ++;
170 puts(" **FAIL** REQUIRED LanguageEncoding");
171 }
172
173 if (ppd->lang_version != NULL)
174 puts(" PASS LanguageVersion");
175 else
176 {
177 errors ++;
178 puts(" **FAIL** REQUIRED LanguageVersion");
179 }
180
181 if (ppd->manufacturer != NULL)
182 puts(" PASS Manufacturer");
183 else
184 {
185 errors ++;
186 puts(" **FAIL** REQUIRED Manufacturer");
187 }
188
189 if (ppd->modelname != NULL)
190 puts(" PASS ModelName");
191 else
192 {
193 errors ++;
194 puts(" **FAIL** REQUIRED ModelName");
195 }
196
197 if (ppd->nickname != NULL)
198 puts(" PASS NickName");
199 else
200 {
201 errors ++;
202 puts(" **FAIL** REQUIRED NickName");
203 }
204
205 if (ppdFindOption(ppd, "PageSize") != NULL)
206 puts(" PASS PageSize");
207 else
208 {
209 errors ++;
210 puts(" **FAIL** REQUIRED PageSize");
211 }
212
213 if (ppdFindOption(ppd, "PageRegion") != NULL)
214 puts(" PASS PageRegion");
215 else
216 {
217 errors ++;
218 puts(" **FAIL** REQUIRED PageRegion");
219 }
220
221 if (ppd->product != NULL)
222 puts(" PASS Product");
223 else
224 {
225 errors ++;
226 puts(" **FAIL** REQUIRED Product");
227 }
228
229 if (ppd->shortnickname != NULL)
230 puts(" PASS ShortNickName");
231 else
232 {
233 errors ++;
234 puts(" **FAIL** REQUIRED ShortNickName");
235 }
236
237 if (errors)
238 {
239 puts("\n **** CONFORMANCE TESTING FAILED ****");
240 status = ERROR_CONFORMANCE;
241 }
242
243 puts("");
244
245 /*
246 * Then list the options, if "-v" was provided...
247 */
248
249 if (verbose)
250 {
251 puts("");
252 puts(" OPTIONS:");
253 printf(" language_level = %d\n", ppd->language_level);
254 printf(" color_device = %s\n", ppd->color_device ? "TRUE" : "FALSE");
255 printf(" variable_sizes = %s\n", ppd->variable_sizes ? "TRUE" : "FALSE");
256 printf(" landscape = %d\n", ppd->landscape);
257
258 switch (ppd->colorspace)
259 {
260 case PPD_CS_CMYK :
261 puts(" colorspace = PPD_CS_CMYK");
262 break;
263 case PPD_CS_CMY :
264 puts(" colorspace = PPD_CS_CMY");
265 break;
266 case PPD_CS_GRAY :
267 puts(" colorspace = PPD_CS_GRAY");
268 break;
269 case PPD_CS_RGB :
270 puts(" colorspace = PPD_CS_RGB");
271 break;
272 default :
273 puts(" colorspace = <unknown>");
274 break;
275 }
276
277 printf(" num_emulations = %d\n", ppd->num_emulations);
278 for (j = 0; j < ppd->num_emulations; j ++)
279 printf(" emulations[%d] = %s\n", j, ppd->emulations[j].name);
280
281 printf(" lang_encoding = %s\n", ppd->lang_encoding);
282 printf(" lang_version = %s\n", ppd->lang_version);
283 printf(" modelname = %s\n", ppd->modelname);
284 printf(" ttrasterizer = %s\n",
285 ppd->ttrasterizer == NULL ? "None" : ppd->ttrasterizer);
286 printf(" manufacturer = %s\n", ppd->manufacturer);
287 printf(" product = %s\n", ppd->product);
288 printf(" nickname = %s\n", ppd->nickname);
289 printf(" shortnickname = %s\n", ppd->shortnickname);
290 printf(" patches = %d bytes\n",
291 ppd->patches == NULL ? 0 : (int)strlen(ppd->patches));
292
293 printf(" num_groups = %d\n", ppd->num_groups);
294 for (j = 0, group = ppd->groups; j < ppd->num_groups; j ++, group ++)
295 {
296 printf(" group[%d] = %s\n", j, group->text);
297
298 for (k = 0, option = group->options; k < group->num_options; k ++, option ++)
299 {
300 printf(" options[%d] = %s (%s) %s %s %.0f (%d choices)\n", k,
301 option->keyword, option->text, uis[option->ui],
302 sections[option->section], option->order,
303 option->num_choices);
304
305 if (strcmp(option->keyword, "PageSize") == 0 ||
306 strcmp(option->keyword, "PageRegion") == 0)
307 {
308 for (m = option->num_choices, choice = option->choices;
309 m > 0;
310 m --, choice ++)
311 {
312 size = ppdPageSize(ppd, choice->choice);
313
314 if (size == NULL)
315 printf(" %s (%s) = ERROR", choice->choice, choice->text);
316 else
317 printf(" %s (%s) = %.2fx%.2fin (%.1f,%.1f,%.1f,%.1f)", choice->choice,
318 choice->text, size->width / 72.0, size->length / 72.0,
319 size->left / 72.0, size->bottom / 72.0,
320 size->right / 72.0, size->top / 72.0);
321
322 if (strcmp(option->defchoice, choice->choice) == 0)
323 puts(" *");
324 else
325 putchar('\n');
326 }
327 }
328 else
329 {
330 for (m = option->num_choices, choice = option->choices;
331 m > 0;
332 m --, choice ++)
333 {
334 printf(" %s (%s)", choice->choice, choice->text);
335
336 if (strcmp(option->defchoice, choice->choice) == 0)
337 puts(" *");
338 else
339 putchar('\n');
340 }
341 }
342 }
343 }
344
345 printf(" num_profiles = %d\n", ppd->num_profiles);
346 for (j = 0; j < ppd->num_profiles; j ++)
347 printf(" profiles[%d] = %s/%s %.3f %.3f [ %.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f %.3f ]\n",
348 j, ppd->profiles[j].resolution, ppd->profiles[j].media_type,
349 ppd->profiles[j].gamma, ppd->profiles[j].density,
350 ppd->profiles[j].matrix[0][0], ppd->profiles[j].matrix[0][1],
351 ppd->profiles[j].matrix[0][2], ppd->profiles[j].matrix[1][0],
352 ppd->profiles[j].matrix[1][1], ppd->profiles[j].matrix[1][2],
353 ppd->profiles[j].matrix[2][0], ppd->profiles[j].matrix[2][1],
354 ppd->profiles[j].matrix[2][2]);
355
356 printf(" num_fonts = %d\n", ppd->num_fonts);
357 for (j = 0; j < ppd->num_fonts; j ++)
358 printf(" fonts[%d] = %s\n", j, ppd->fonts[j]);
359 }
360
361 ppdClose(ppd);
362 }
363
364 if (!ppd)
365 {
366 puts("Usage: cupstestppd [-v] filename1.ppd [... filenameN.ppd]");
367 puts(" program | cupstestppd [-v] -");
368
369 return (ERROR_USAGE);
370 }
371 else
372 return (status);
373 }
374
375
376 /*
377 * End of "$Id: cupstestppd.c,v 1.1 2002/12/13 21:18:08 mike Exp $".
378 */