]>
git.ipfire.org Git - thirdparty/cups.git/blob - cups/testppd.c
2 * "$Id: testppd.c 6936 2007-09-10 18:15:36Z 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 if ((ppd
= ppdOpenFile(argv
[1])) == NULL
)
318 ppd_status_t err
; /* Last error in file */
319 int line
; /* Line number in file */
323 err
= ppdLastError(&line
);
325 printf("%s: %s on line %d\n", argv
[1], ppdErrorString(err
), line
);
329 int i
, j
, k
; /* Looping vars */
330 ppd_attr_t
*attr
; /* Current attribute */
331 ppd_group_t
*group
; /* Option group */
332 ppd_option_t
*option
; /* Option */
333 ppd_coption_t
*coption
; /* Custom option */
334 ppd_cparam_t
*cparam
; /* Custom parameter */
335 char lang
[255]; /* LANG environment variable */
340 snprintf(lang
, sizeof(lang
), "LANG=%s", argv
[2]);
346 for (i
= ppd
->num_groups
, group
= ppd
->groups
;
350 printf("%s (%s):\n", group
->name
, group
->text
);
352 for (j
= group
->num_options
, option
= group
->options
;
356 printf(" %s (%s):\n", option
->keyword
, option
->text
);
358 for (k
= 0; k
< option
->num_choices
; k
++)
359 printf(" - %s (%s)\n", option
->choices
[k
].choice
,
360 option
->choices
[k
].text
);
362 if ((coption
= ppdFindCustomOption(ppd
, option
->keyword
)) != NULL
)
364 for (cparam
= (ppd_cparam_t
*)cupsArrayFirst(coption
->params
);
366 cparam
= (ppd_cparam_t
*)cupsArrayNext(coption
->params
))
368 switch (cparam
->type
)
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
);
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
);
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
);
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
);
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
);
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
);
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
);
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
);
433 for (attr
= (ppd_attr_t
*)cupsArrayFirst(ppd
->sorted_attrs
);
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
: "");
442 if (getenv("MallocStackLogging") && getenv("MallocStackLoggingNoCompact"))
444 char command
[1024]; /* malloc_history command */
446 snprintf(command
, sizeof(command
), "malloc_history %d -all_by_size",
451 #endif /* __APPLE__ */
460 * End of "$Id: testppd.c 6936 2007-09-10 18:15:36Z mike $".