]> git.ipfire.org Git - thirdparty/cups.git/blob - cups/testppd.c
Import CUPS 1.4svn r7023 into easysw/current.
[thirdparty/cups.git] / cups / testppd.c
1 /*
2 * "$Id: testppd.c 6936 2007-09-10 18:15:36Z mike $"
3 *
4 * PPD test program for the Common UNIX Printing System (CUPS).
5 *
6 * Copyright 2007 by Apple Inc.
7 * Copyright 1997-2006 by Easy Software Products.
8 *
9 * These coded instructions, statements, and computer programs are the
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/".
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>
29 #include <errno.h>
30 #include "ppd.h"
31 #ifdef WIN32
32 # include <io.h>
33 #else
34 # include <unistd.h>
35 # include <fcntl.h>
36 #endif /* WIN32 */
37
38
39 /*
40 * Test data...
41 */
42
43 static const char *default_code =
44 "[{\n"
45 "%%BeginFeature: *PageRegion Letter\n"
46 "PageRegion=Letter\n"
47 "%%EndFeature\n"
48 "} stopped cleartomark\n"
49 "[{\n"
50 "%%BeginFeature: *InputSlot Tray\n"
51 "InputSlot=Tray\n"
52 "%%EndFeature\n"
53 "} stopped cleartomark\n"
54 "[{\n"
55 "%%BeginFeature: *IntOption None\n"
56 "%%EndFeature\n"
57 "} stopped cleartomark\n"
58 "[{\n"
59 "%%BeginFeature: *StringOption None\n"
60 "%%EndFeature\n"
61 "} stopped cleartomark\n";
62
63 static const char *custom_code =
64 "[{\n"
65 "%%BeginFeature: *CustomPageSize True\n"
66 "400\n"
67 "500\n"
68 "0\n"
69 "0\n"
70 "0\n"
71 "PageSize=Custom\n"
72 "%%EndFeature\n"
73 "} stopped cleartomark\n"
74 "[{\n"
75 "%%BeginFeature: *InputSlot Tray\n"
76 "InputSlot=Tray\n"
77 "%%EndFeature\n"
78 "} stopped cleartomark\n"
79 "[{\n"
80 "%%BeginFeature: *IntOption None\n"
81 "%%EndFeature\n"
82 "} stopped cleartomark\n"
83 "[{\n"
84 "%%BeginFeature: *StringOption None\n"
85 "%%EndFeature\n"
86 "} stopped cleartomark\n";
87
88
89 /*
90 * 'main()' - Main entry.
91 */
92
93 int /* O - Exit status */
94 main(int argc, /* I - Number of command-line arguments */
95 char *argv[]) /* I - Command-line arguments */
96 {
97 ppd_file_t *ppd; /* PPD file loaded from disk */
98 int status; /* Status of tests (0 = success, 1 = fail) */
99 int conflicts; /* Number of conflicts */
100 char *s; /* String */
101 char buffer[8192]; /* String buffer */
102
103
104 status = 0;
105
106 if (argc == 1)
107 {
108 fputs("ppdOpenFile: ", stdout);
109
110 if ((ppd = ppdOpenFile("test.ppd")) != NULL)
111 puts("PASS");
112 else
113 {
114 ppd_status_t err; /* Last error in file */
115 int line; /* Line number in file */
116
117
118 status ++;
119 err = ppdLastError(&line);
120
121 printf("FAIL (%s on line %d)\n", ppdErrorString(err), line);
122 }
123
124 fputs("ppdMarkDefaults: ", stdout);
125 ppdMarkDefaults(ppd);
126
127 if ((conflicts = ppdConflicts(ppd)) == 0)
128 puts("PASS");
129 else
130 {
131 status ++;
132 printf("FAIL (%d conflicts)\n", conflicts);
133 }
134
135 fputs("ppdEmitString (defaults): ", stdout);
136 if ((s = ppdEmitString(ppd, PPD_ORDER_ANY, 0.0)) != NULL &&
137 !strcmp(s, default_code))
138 puts("PASS");
139 else
140 {
141 status ++;
142 printf("FAIL (%d bytes instead of %d)\n", s ? (int)strlen(s) : 0,
143 (int)strlen(default_code));
144
145 if (s)
146 puts(s);
147 }
148
149 if (s)
150 free(s);
151
152 fputs("ppdEmitString (custom size): ", stdout);
153 ppdMarkOption(ppd, "PageSize", "Custom.400x500");
154
155 if ((s = ppdEmitString(ppd, PPD_ORDER_ANY, 0.0)) != NULL &&
156 !strcmp(s, custom_code))
157 puts("PASS");
158 else
159 {
160 status ++;
161 printf("FAIL (%d bytes instead of %d)\n", s ? (int)strlen(s) : 0,
162 (int)strlen(custom_code));
163
164 if (s)
165 puts(s);
166 }
167
168 if (s)
169 free(s);
170
171 /*
172 * Test localization...
173 */
174
175 fputs("ppdLocalizeIPPReason(text): ", stdout);
176 if (ppdLocalizeIPPReason(ppd, "foo", NULL, buffer, sizeof(buffer)) &&
177 !strcmp(buffer, "Foo Reason"))
178 puts("PASS");
179 else
180 {
181 status ++;
182 printf("FAIL (\"%s\" instead of \"Foo Reason\")\n", buffer);
183 }
184
185 fputs("ppdLocalizeIPPReason(http): ", stdout);
186 if (ppdLocalizeIPPReason(ppd, "foo", "http", buffer, sizeof(buffer)) &&
187 !strcmp(buffer, "http://foo/bar.html"))
188 puts("PASS");
189 else
190 {
191 status ++;
192 printf("FAIL (\"%s\" instead of \"http://foo/bar.html\")\n", buffer);
193 }
194
195 fputs("ppdLocalizeIPPReason(help): ", stdout);
196 if (ppdLocalizeIPPReason(ppd, "foo", "help", buffer, sizeof(buffer)) &&
197 !strcmp(buffer, "help:anchor='foo'%20bookID=Vendor%20Help"))
198 puts("PASS");
199 else
200 {
201 status ++;
202 printf("FAIL (\"%s\" instead of \"help:anchor='foo'%%20bookID=Vendor%%20Help\")\n", buffer);
203 }
204
205 fputs("ppdLocalizeIPPReason(file): ", stdout);
206 if (ppdLocalizeIPPReason(ppd, "foo", "file", buffer, sizeof(buffer)) &&
207 !strcmp(buffer, "/help/foo/bar.html"))
208 puts("PASS");
209 else
210 {
211 status ++;
212 printf("FAIL (\"%s\" instead of \"/help/foo/bar.html\")\n", buffer);
213 }
214
215 putenv("LANG=fr");
216
217 fputs("ppdLocalizeIPPReason(fr text): ", stdout);
218 if (ppdLocalizeIPPReason(ppd, "foo", NULL, buffer, sizeof(buffer)) &&
219 !strcmp(buffer, "La Long Foo Reason"))
220 puts("PASS");
221 else
222 {
223 status ++;
224 printf("FAIL (\"%s\" instead of \"La Long Foo Reason\")\n", buffer);
225 }
226
227 putenv("LANG=zh_TW");
228
229 fputs("ppdLocalizeIPPReason(zh_TW text): ", stdout);
230 if (ppdLocalizeIPPReason(ppd, "foo", NULL, buffer, sizeof(buffer)) &&
231 !strcmp(buffer, "Number 1 Foo Reason"))
232 puts("PASS");
233 else
234 {
235 status ++;
236 printf("FAIL (\"%s\" instead of \"Number 1 Foo Reason\")\n", buffer);
237 }
238 }
239 else
240 {
241 if ((ppd = ppdOpenFile(argv[1])) == NULL)
242 {
243 ppd_status_t err; /* Last error in file */
244 int line; /* Line number in file */
245
246
247 status ++;
248 err = ppdLastError(&line);
249
250 printf("%s: %s on line %d\n", argv[1], ppdErrorString(err), line);
251 }
252 else
253 {
254 int i, j, k; /* Looping vars */
255 ppd_attr_t *attr; /* Current attribute */
256 ppd_group_t *group; /* Option group */
257 ppd_option_t *option; /* Option */
258 ppd_coption_t *coption; /* Custom option */
259 ppd_cparam_t *cparam; /* Custom parameter */
260 char lang[255]; /* LANG environment variable */
261
262
263 if (argc > 2)
264 {
265 snprintf(lang, sizeof(lang), "LANG=%s", argv[2]);
266 putenv(lang);
267 }
268
269 ppdLocalize(ppd);
270
271 for (i = ppd->num_groups, group = ppd->groups;
272 i > 0;
273 i --, group ++)
274 {
275 printf("%s (%s):\n", group->name, group->text);
276
277 for (j = group->num_options, option = group->options;
278 j > 0;
279 j --, option ++)
280 {
281 printf(" %s (%s):\n", option->keyword, option->text);
282
283 for (k = 0; k < option->num_choices; k ++)
284 printf(" - %s (%s)\n", option->choices[k].choice,
285 option->choices[k].text);
286
287 if ((coption = ppdFindCustomOption(ppd, option->keyword)) != NULL)
288 {
289 for (cparam = (ppd_cparam_t *)cupsArrayFirst(coption->params);
290 cparam;
291 cparam = (ppd_cparam_t *)cupsArrayNext(coption->params))
292 {
293 switch (cparam->type)
294 {
295 case PPD_CUSTOM_CURVE :
296 printf(" %s(%s): PPD_CUSTOM_CURVE (%g to %g)\n",
297 cparam->name, cparam->text,
298 cparam->minimum.custom_curve,
299 cparam->maximum.custom_curve);
300 break;
301
302 case PPD_CUSTOM_INT :
303 printf(" %s(%s): PPD_CUSTOM_INT (%d to %d)\n",
304 cparam->name, cparam->text,
305 cparam->minimum.custom_int,
306 cparam->maximum.custom_int);
307 break;
308
309 case PPD_CUSTOM_INVCURVE :
310 printf(" %s(%s): PPD_CUSTOM_INVCURVE (%g to %g)\n",
311 cparam->name, cparam->text,
312 cparam->minimum.custom_invcurve,
313 cparam->maximum.custom_invcurve);
314 break;
315
316 case PPD_CUSTOM_PASSCODE :
317 printf(" %s(%s): PPD_CUSTOM_PASSCODE (%d to %d)\n",
318 cparam->name, cparam->text,
319 cparam->minimum.custom_passcode,
320 cparam->maximum.custom_passcode);
321 break;
322
323 case PPD_CUSTOM_PASSWORD :
324 printf(" %s(%s): PPD_CUSTOM_PASSWORD (%d to %d)\n",
325 cparam->name, cparam->text,
326 cparam->minimum.custom_password,
327 cparam->maximum.custom_password);
328 break;
329
330 case PPD_CUSTOM_POINTS :
331 printf(" %s(%s): PPD_CUSTOM_POINTS (%g to %g)\n",
332 cparam->name, cparam->text,
333 cparam->minimum.custom_points,
334 cparam->maximum.custom_points);
335 break;
336
337 case PPD_CUSTOM_REAL :
338 printf(" %s(%s): PPD_CUSTOM_REAL (%g to %g)\n",
339 cparam->name, cparam->text,
340 cparam->minimum.custom_real,
341 cparam->maximum.custom_real);
342 break;
343
344 case PPD_CUSTOM_STRING :
345 printf(" %s(%s): PPD_CUSTOM_STRING (%d to %d)\n",
346 cparam->name, cparam->text,
347 cparam->minimum.custom_string,
348 cparam->maximum.custom_string);
349 break;
350 }
351 }
352 }
353 }
354 }
355
356 puts("Attributes:");
357
358 for (attr = (ppd_attr_t *)cupsArrayFirst(ppd->sorted_attrs);
359 attr;
360 attr = (ppd_attr_t *)cupsArrayNext(ppd->sorted_attrs))
361 printf(" *%s %s/%s: \"%s\"\n", attr->name, attr->spec,
362 attr->text, attr->value ? attr->value : "");
363 }
364 }
365
366 #ifdef __APPLE__
367 if (getenv("MallocStackLogging") && getenv("MallocStackLoggingNoCompact"))
368 {
369 char command[1024]; /* malloc_history command */
370
371 snprintf(command, sizeof(command), "malloc_history %d -all_by_size",
372 getpid());
373 fflush(stdout);
374 system(command);
375 }
376 #endif /* __APPLE__ */
377
378 ppdClose(ppd);
379
380 return (status);
381 }
382
383
384 /*
385 * End of "$Id: testppd.c 6936 2007-09-10 18:15:36Z mike $".
386 */