]> git.ipfire.org Git - thirdparty/cups.git/blame - cups/testppd.c
Merge changes from CUPS 1.4svn-r7626.
[thirdparty/cups.git] / cups / testppd.c
CommitLineData
fa73b229 1/*
2e4ff8af 2 * "$Id: testppd.c 6936 2007-09-10 18:15:36Z 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>
31#include "ppd.h"
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
44static 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
64static 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
94int /* O - Exit status */
95main(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 {
a74454a7 316 if ((ppd = ppdOpenFile(argv[1])) == NULL)
317 {
318 ppd_status_t err; /* Last error in file */
319 int line; /* Line number in file */
320
321
322 status ++;
323 err = ppdLastError(&line);
324
325 printf("%s: %s on line %d\n", argv[1], ppdErrorString(err), line);
326 }
327 else
328 {
329 int i, j, k; /* Looping vars */
d09495fa 330 ppd_attr_t *attr; /* Current attribute */
a74454a7 331 ppd_group_t *group; /* Option group */
332 ppd_option_t *option; /* Option */
b86bc4cf 333 ppd_coption_t *coption; /* Custom option */
334 ppd_cparam_t *cparam; /* Custom parameter */
d09495fa 335 char lang[255]; /* LANG environment variable */
a74454a7 336
337
d09495fa 338 if (argc > 2)
339 {
340 snprintf(lang, sizeof(lang), "LANG=%s", argv[2]);
341 putenv(lang);
342 }
343
a74454a7 344 ppdLocalize(ppd);
345
346 for (i = ppd->num_groups, group = ppd->groups;
347 i > 0;
348 i --, group ++)
349 {
350 printf("%s (%s):\n", group->name, group->text);
d09495fa 351
a74454a7 352 for (j = group->num_options, option = group->options;
353 j > 0;
354 j --, option ++)
355 {
356 printf(" %s (%s):\n", option->keyword, option->text);
357
358 for (k = 0; k < option->num_choices; k ++)
359 printf(" - %s (%s)\n", option->choices[k].choice,
360 option->choices[k].text);
b86bc4cf 361
362 if ((coption = ppdFindCustomOption(ppd, option->keyword)) != NULL)
363 {
364 for (cparam = (ppd_cparam_t *)cupsArrayFirst(coption->params);
365 cparam;
366 cparam = (ppd_cparam_t *)cupsArrayNext(coption->params))
367 {
368 switch (cparam->type)
369 {
370 case PPD_CUSTOM_CURVE :
371 printf(" %s(%s): PPD_CUSTOM_CURVE (%g to %g)\n",
372 cparam->name, cparam->text,
373 cparam->minimum.custom_curve,
374 cparam->maximum.custom_curve);
375 break;
376
377 case PPD_CUSTOM_INT :
378 printf(" %s(%s): PPD_CUSTOM_INT (%d to %d)\n",
379 cparam->name, cparam->text,
380 cparam->minimum.custom_int,
381 cparam->maximum.custom_int);
382 break;
383
384 case PPD_CUSTOM_INVCURVE :
385 printf(" %s(%s): PPD_CUSTOM_INVCURVE (%g to %g)\n",
386 cparam->name, cparam->text,
387 cparam->minimum.custom_invcurve,
388 cparam->maximum.custom_invcurve);
389 break;
390
391 case PPD_CUSTOM_PASSCODE :
392 printf(" %s(%s): PPD_CUSTOM_PASSCODE (%d to %d)\n",
393 cparam->name, cparam->text,
394 cparam->minimum.custom_passcode,
395 cparam->maximum.custom_passcode);
396 break;
397
398 case PPD_CUSTOM_PASSWORD :
399 printf(" %s(%s): PPD_CUSTOM_PASSWORD (%d to %d)\n",
400 cparam->name, cparam->text,
401 cparam->minimum.custom_password,
402 cparam->maximum.custom_password);
403 break;
404
405 case PPD_CUSTOM_POINTS :
406 printf(" %s(%s): PPD_CUSTOM_POINTS (%g to %g)\n",
407 cparam->name, cparam->text,
408 cparam->minimum.custom_points,
409 cparam->maximum.custom_points);
410 break;
411
412 case PPD_CUSTOM_REAL :
413 printf(" %s(%s): PPD_CUSTOM_REAL (%g to %g)\n",
414 cparam->name, cparam->text,
415 cparam->minimum.custom_real,
416 cparam->maximum.custom_real);
417 break;
418
419 case PPD_CUSTOM_STRING :
420 printf(" %s(%s): PPD_CUSTOM_STRING (%d to %d)\n",
421 cparam->name, cparam->text,
422 cparam->minimum.custom_string,
423 cparam->maximum.custom_string);
424 break;
425 }
426 }
427 }
a74454a7 428 }
429 }
d09495fa 430
431 puts("Attributes:");
432
433 for (attr = (ppd_attr_t *)cupsArrayFirst(ppd->sorted_attrs);
434 attr;
435 attr = (ppd_attr_t *)cupsArrayNext(ppd->sorted_attrs))
436 printf(" *%s %s/%s: \"%s\"\n", attr->name, attr->spec,
437 attr->text, attr->value ? attr->value : "");
a74454a7 438 }
e1d6a774 439 }
440
2e4ff8af
MS
441#ifdef __APPLE__
442 if (getenv("MallocStackLogging") && getenv("MallocStackLoggingNoCompact"))
443 {
444 char command[1024]; /* malloc_history command */
445
446 snprintf(command, sizeof(command), "malloc_history %d -all_by_size",
447 getpid());
448 fflush(stdout);
449 system(command);
450 }
451#endif /* __APPLE__ */
452
453 ppdClose(ppd);
454
fa73b229 455 return (status);
456}
457
458
459/*
2e4ff8af 460 * End of "$Id: testppd.c 6936 2007-09-10 18:15:36Z mike $".
fa73b229 461 */