]>
git.ipfire.org Git - thirdparty/cups.git/blob - cups/testppd.c
2 * "$Id: testppd.c 7633 2008-06-10 23:07:29Z mike $"
4 * PPD test program for the Common UNIX Printing System (CUPS).
6 * Copyright 2007 by Apple Inc.
7 * Copyright 1997-2006 by Easy Software Products.
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/".
15 * This file is subject to the Apple OS-Developed Software exception.
19 * main() - Main entry.
23 * Include necessary headers...
28 #include <cups/string.h>
44 static const char *default_code
=
46 "%%BeginFeature: *PageRegion Letter\n"
49 "} stopped cleartomark\n"
51 "%%BeginFeature: *InputSlot Tray\n"
54 "} stopped cleartomark\n"
56 "%%BeginFeature: *IntOption None\n"
58 "} stopped cleartomark\n"
60 "%%BeginFeature: *StringOption None\n"
62 "} stopped cleartomark\n";
64 static const char *custom_code
=
66 "%%BeginFeature: *InputSlot Tray\n"
69 "} stopped cleartomark\n"
71 "%%BeginFeature: *IntOption None\n"
73 "} stopped cleartomark\n"
75 "%%BeginFeature: *StringOption None\n"
77 "} stopped cleartomark\n"
79 "%%BeginFeature: *CustomPageSize True\n"
87 "} stopped cleartomark\n";
91 * 'main()' - Main entry.
94 int /* O - Exit status */
95 main(int argc
, /* I - Number of command-line arguments */
96 char *argv
[]) /* I - Command-line arguments */
98 ppd_file_t
*ppd
; /* PPD file loaded from disk */
99 int status
; /* Status of tests (0 = success, 1 = fail) */
100 int conflicts
; /* Number of conflicts */
101 char *s
; /* String */
102 char buffer
[8192]; /* String buffer */
103 const char *text
; /* Localized text */
111 * Setup directories for locale stuff...
114 if (access("locale", 0))
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");
123 putenv("LOCALEDIR=locale");
126 * Do tests with test.ppd...
129 fputs("ppdOpenFile: ", stdout
);
131 if ((ppd
= ppdOpenFile("test.ppd")) != NULL
)
135 ppd_status_t err
; /* Last error in file */
136 int line
; /* Line number in file */
140 err
= ppdLastError(&line
);
142 printf("FAIL (%s on line %d)\n", ppdErrorString(err
), line
);
145 fputs("ppdMarkDefaults: ", stdout
);
146 ppdMarkDefaults(ppd
);
148 if ((conflicts
= ppdConflicts(ppd
)) == 0)
153 printf("FAIL (%d conflicts)\n", conflicts
);
156 fputs("ppdEmitString (defaults): ", stdout
);
157 if ((s
= ppdEmitString(ppd
, PPD_ORDER_ANY
, 0.0)) != NULL
&&
158 !strcmp(s
, default_code
))
163 printf("FAIL (%d bytes instead of %d)\n", s
? (int)strlen(s
) : 0,
164 (int)strlen(default_code
));
173 fputs("ppdEmitString (custom size): ", stdout
);
174 ppdMarkOption(ppd
, "PageSize", "Custom.400x500");
176 if ((s
= ppdEmitString(ppd
, PPD_ORDER_ANY
, 0.0)) != NULL
&&
177 !strcmp(s
, custom_code
))
182 printf("FAIL (%d bytes instead of %d)\n", s
? (int)strlen(s
) : 0,
183 (int)strlen(custom_code
));
193 * Test localization...
196 fputs("ppdLocalizeIPPReason(text): ", stdout
);
197 if (ppdLocalizeIPPReason(ppd
, "foo", NULL
, buffer
, sizeof(buffer
)) &&
198 !strcmp(buffer
, "Foo Reason"))
203 printf("FAIL (\"%s\" instead of \"Foo Reason\")\n", buffer
);
206 fputs("ppdLocalizeIPPReason(http): ", stdout
);
207 if (ppdLocalizeIPPReason(ppd
, "foo", "http", buffer
, sizeof(buffer
)) &&
208 !strcmp(buffer
, "http://foo/bar.html"))
213 printf("FAIL (\"%s\" instead of \"http://foo/bar.html\")\n", buffer
);
216 fputs("ppdLocalizeIPPReason(help): ", stdout
);
217 if (ppdLocalizeIPPReason(ppd
, "foo", "help", buffer
, sizeof(buffer
)) &&
218 !strcmp(buffer
, "help:anchor='foo'%20bookID=Vendor%20Help"))
223 printf("FAIL (\"%s\" instead of \"help:anchor='foo'%%20bookID=Vendor%%20Help\")\n", buffer
);
226 fputs("ppdLocalizeIPPReason(file): ", stdout
);
227 if (ppdLocalizeIPPReason(ppd
, "foo", "file", buffer
, sizeof(buffer
)) &&
228 !strcmp(buffer
, "/help/foo/bar.html"))
233 printf("FAIL (\"%s\" instead of \"/help/foo/bar.html\")\n", buffer
);
238 fputs("ppdLocalizeIPPReason(fr text): ", stdout
);
239 if (ppdLocalizeIPPReason(ppd
, "foo", NULL
, buffer
, sizeof(buffer
)) &&
240 !strcmp(buffer
, "La Long Foo Reason"))
245 printf("FAIL (\"%s\" instead of \"La Long Foo Reason\")\n", buffer
);
248 putenv("LANG=zh_TW");
250 fputs("ppdLocalizeIPPReason(zh_TW text): ", stdout
);
251 if (ppdLocalizeIPPReason(ppd
, "foo", NULL
, buffer
, sizeof(buffer
)) &&
252 !strcmp(buffer
, "Number 1 Foo Reason"))
257 printf("FAIL (\"%s\" instead of \"Number 1 Foo Reason\")\n", buffer
);
261 * cupsMarkerName localization...
266 fputs("ppdLocalizeMarkerName(bogus): ", stdout
);
268 if ((text
= ppdLocalizeMarkerName(ppd
, "bogus")) != NULL
)
271 printf("FAIL (\"%s\" instead of NULL)\n", text
);
276 fputs("ppdLocalizeMarkerName(cyan): ", stdout
);
278 if ((text
= ppdLocalizeMarkerName(ppd
, "cyan")) != NULL
&&
279 !strcmp(text
, "Cyan Toner"))
284 printf("FAIL (\"%s\" instead of \"Cyan Toner\")\n",
285 text
? text
: "(null)");
290 fputs("ppdLocalizeMarkerName(fr cyan): ", stdout
);
291 if ((text
= ppdLocalizeMarkerName(ppd
, "cyan")) != NULL
&&
292 !strcmp(text
, "La Toner Cyan"))
297 printf("FAIL (\"%s\" instead of \"La Toner Cyan\")\n",
298 text
? text
: "(null)");
301 putenv("LANG=zh_TW");
303 fputs("ppdLocalizeMarkerName(zh_TW cyan): ", stdout
);
304 if ((text
= ppdLocalizeMarkerName(ppd
, "cyan")) != NULL
&&
305 !strcmp(text
, "Number 1 Cyan Toner"))
310 printf("FAIL (\"%s\" instead of \"Number 1 Cyan Toner\")\n",
311 text
? text
: "(null)");
316 const char *filename
; /* PPD filename */
319 if (!strncmp(argv
[1], "-d", 2))
320 filename
= cupsGetPPD(argv
[1] + 2);
324 if ((ppd
= ppdOpenFile(filename
)) == NULL
)
326 ppd_status_t err
; /* Last error in file */
327 int line
; /* Line number in file */
331 err
= ppdLastError(&line
);
333 printf("%s: %s on line %d\n", argv
[1], ppdErrorString(err
), line
);
337 int i
, j
, k
; /* Looping vars */
338 ppd_attr_t
*attr
; /* Current attribute */
339 ppd_group_t
*group
; /* Option group */
340 ppd_option_t
*option
; /* Option */
341 ppd_coption_t
*coption
; /* Custom option */
342 ppd_cparam_t
*cparam
; /* Custom parameter */
343 char lang
[255]; /* LANG environment variable */
348 snprintf(lang
, sizeof(lang
), "LANG=%s", argv
[2]);
354 for (i
= ppd
->num_groups
, group
= ppd
->groups
;
358 printf("%s (%s):\n", group
->name
, group
->text
);
360 for (j
= group
->num_options
, option
= group
->options
;
364 printf(" %s (%s):\n", option
->keyword
, option
->text
);
366 for (k
= 0; k
< option
->num_choices
; k
++)
367 printf(" - %s (%s)\n", option
->choices
[k
].choice
,
368 option
->choices
[k
].text
);
370 if ((coption
= ppdFindCustomOption(ppd
, option
->keyword
)) != NULL
)
372 for (cparam
= (ppd_cparam_t
*)cupsArrayFirst(coption
->params
);
374 cparam
= (ppd_cparam_t
*)cupsArrayNext(coption
->params
))
376 switch (cparam
->type
)
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
);
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
);
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
);
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
);
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
);
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
);
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
);
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
);
441 for (attr
= (ppd_attr_t
*)cupsArrayFirst(ppd
->sorted_attrs
);
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
: "");
448 if (!strncmp(argv
[1], "-d", 2))
453 if (getenv("MallocStackLogging") && getenv("MallocStackLoggingNoCompact"))
455 char command
[1024]; /* malloc_history command */
457 snprintf(command
, sizeof(command
), "malloc_history %d -all_by_size",
462 #endif /* __APPLE__ */
471 * End of "$Id: testppd.c 7633 2008-06-10 23:07:29Z mike $".