]>
git.ipfire.org Git - thirdparty/cups.git/blob - cups/testppd.c
2 * "$Id: testppd.c 6799 2007-08-15 19:33: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>
43 static const char *default_code
=
45 "%%BeginFeature: *PageRegion Letter\n"
48 "} stopped cleartomark\n"
50 "%%BeginFeature: *InputSlot Tray\n"
53 "} stopped cleartomark\n"
55 "%%BeginFeature: *IntOption None\n"
57 "} stopped cleartomark\n"
59 "%%BeginFeature: *StringOption None\n"
61 "} stopped cleartomark\n";
63 static const char *custom_code
=
65 "%%BeginFeature: *CustomPageSize True\n"
73 "} stopped cleartomark\n"
75 "%%BeginFeature: *InputSlot Tray\n"
78 "} stopped cleartomark\n"
80 "%%BeginFeature: *IntOption None\n"
82 "} stopped cleartomark\n"
84 "%%BeginFeature: *StringOption None\n"
86 "} stopped cleartomark\n";
90 * 'main()' - Main entry.
93 int /* O - Exit status */
94 main(int argc
, /* I - Number of command-line arguments */
95 char *argv
[]) /* I - Command-line arguments */
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 */
108 fputs("ppdOpenFile: ", stdout
);
110 if ((ppd
= ppdOpenFile("test.ppd")) != NULL
)
114 ppd_status_t err
; /* Last error in file */
115 int line
; /* Line number in file */
119 err
= ppdLastError(&line
);
121 printf("FAIL (%s on line %d)\n", ppdErrorString(err
), line
);
124 fputs("ppdMarkDefaults: ", stdout
);
125 ppdMarkDefaults(ppd
);
127 if ((conflicts
= ppdConflicts(ppd
)) == 0)
132 printf("FAIL (%d conflicts)\n", conflicts
);
135 fputs("ppdEmitString (defaults): ", stdout
);
136 if ((s
= ppdEmitString(ppd
, PPD_ORDER_ANY
, 0.0)) != NULL
&&
137 !strcmp(s
, default_code
))
142 printf("FAIL (%d bytes instead of %d)\n", s
? (int)strlen(s
) : 0,
143 (int)strlen(default_code
));
152 fputs("ppdEmitString (custom size): ", stdout
);
153 ppdMarkOption(ppd
, "PageSize", "Custom.400x500");
155 if ((s
= ppdEmitString(ppd
, PPD_ORDER_ANY
, 0.0)) != NULL
&&
156 !strcmp(s
, custom_code
))
161 printf("FAIL (%d bytes instead of %d)\n", s
? (int)strlen(s
) : 0,
162 (int)strlen(custom_code
));
172 * Test localization...
175 fputs("ppdLocalizeIPPReason(text): ", stdout
);
176 if (ppdLocalizeIPPReason(ppd
, "foo", NULL
, buffer
, sizeof(buffer
)) &&
177 !strcmp(buffer
, "Foo Reason"))
182 printf("FAIL (\"%s\" instead of \"Foo Reason\")\n", buffer
);
185 fputs("ppdLocalizeIPPReason(http): ", stdout
);
186 if (ppdLocalizeIPPReason(ppd
, "foo", "http", buffer
, sizeof(buffer
)) &&
187 !strcmp(buffer
, "http://foo/bar.html"))
192 printf("FAIL (\"%s\" instead of \"http://foo/bar.html\")\n", buffer
);
195 fputs("ppdLocalizeIPPReason(help): ", stdout
);
196 if (ppdLocalizeIPPReason(ppd
, "foo", "help", buffer
, sizeof(buffer
)) &&
197 !strcmp(buffer
, "help:anchor='foo'%20bookID=Vendor%20Help"))
202 printf("FAIL (\"%s\" instead of \"help:anchor='foo'%%20bookID=Vendor%%20Help\")\n", buffer
);
205 fputs("ppdLocalizeIPPReason(file): ", stdout
);
206 if (ppdLocalizeIPPReason(ppd
, "foo", "file", buffer
, sizeof(buffer
)) &&
207 !strcmp(buffer
, "/help/foo/bar.html"))
212 printf("FAIL (\"%s\" instead of \"/help/foo/bar.html\")\n", buffer
);
217 fputs("ppdLocalizeIPPReason(fr text): ", stdout
);
218 if (ppdLocalizeIPPReason(ppd
, "foo", NULL
, buffer
, sizeof(buffer
)) &&
219 !strcmp(buffer
, "La Long Foo Reason"))
224 printf("FAIL (\"%s\" instead of \"La Long Foo Reason\")\n", buffer
);
227 putenv("LANG=zh_TW");
229 fputs("ppdLocalizeIPPReason(zh_TW text): ", stdout
);
230 if (ppdLocalizeIPPReason(ppd
, "foo", NULL
, buffer
, sizeof(buffer
)) &&
231 !strcmp(buffer
, "Number 1 Foo Reason"))
236 printf("FAIL (\"%s\" instead of \"Number 1 Foo Reason\")\n", buffer
);
243 if ((ppd
= ppdOpenFile(argv
[1])) == NULL
)
245 ppd_status_t err
; /* Last error in file */
246 int line
; /* Line number in file */
250 err
= ppdLastError(&line
);
252 printf("%s: %s on line %d\n", argv
[1], ppdErrorString(err
), line
);
256 int i
, j
, k
; /* Looping vars */
257 ppd_attr_t
*attr
; /* Current attribute */
258 ppd_group_t
*group
; /* Option group */
259 ppd_option_t
*option
; /* Option */
260 ppd_coption_t
*coption
; /* Custom option */
261 ppd_cparam_t
*cparam
; /* Custom parameter */
262 char lang
[255]; /* LANG environment variable */
267 snprintf(lang
, sizeof(lang
), "LANG=%s", argv
[2]);
273 for (i
= ppd
->num_groups
, group
= ppd
->groups
;
277 printf("%s (%s):\n", group
->name
, group
->text
);
279 for (j
= group
->num_options
, option
= group
->options
;
283 printf(" %s (%s):\n", option
->keyword
, option
->text
);
285 for (k
= 0; k
< option
->num_choices
; k
++)
286 printf(" - %s (%s)\n", option
->choices
[k
].choice
,
287 option
->choices
[k
].text
);
289 if ((coption
= ppdFindCustomOption(ppd
, option
->keyword
)) != NULL
)
291 for (cparam
= (ppd_cparam_t
*)cupsArrayFirst(coption
->params
);
293 cparam
= (ppd_cparam_t
*)cupsArrayNext(coption
->params
))
295 switch (cparam
->type
)
297 case PPD_CUSTOM_CURVE
:
298 printf(" %s(%s): PPD_CUSTOM_CURVE (%g to %g)\n",
299 cparam
->name
, cparam
->text
,
300 cparam
->minimum
.custom_curve
,
301 cparam
->maximum
.custom_curve
);
304 case PPD_CUSTOM_INT
:
305 printf(" %s(%s): PPD_CUSTOM_INT (%d to %d)\n",
306 cparam
->name
, cparam
->text
,
307 cparam
->minimum
.custom_int
,
308 cparam
->maximum
.custom_int
);
311 case PPD_CUSTOM_INVCURVE
:
312 printf(" %s(%s): PPD_CUSTOM_INVCURVE (%g to %g)\n",
313 cparam
->name
, cparam
->text
,
314 cparam
->minimum
.custom_invcurve
,
315 cparam
->maximum
.custom_invcurve
);
318 case PPD_CUSTOM_PASSCODE
:
319 printf(" %s(%s): PPD_CUSTOM_PASSCODE (%d to %d)\n",
320 cparam
->name
, cparam
->text
,
321 cparam
->minimum
.custom_passcode
,
322 cparam
->maximum
.custom_passcode
);
325 case PPD_CUSTOM_PASSWORD
:
326 printf(" %s(%s): PPD_CUSTOM_PASSWORD (%d to %d)\n",
327 cparam
->name
, cparam
->text
,
328 cparam
->minimum
.custom_password
,
329 cparam
->maximum
.custom_password
);
332 case PPD_CUSTOM_POINTS
:
333 printf(" %s(%s): PPD_CUSTOM_POINTS (%g to %g)\n",
334 cparam
->name
, cparam
->text
,
335 cparam
->minimum
.custom_points
,
336 cparam
->maximum
.custom_points
);
339 case PPD_CUSTOM_REAL
:
340 printf(" %s(%s): PPD_CUSTOM_REAL (%g to %g)\n",
341 cparam
->name
, cparam
->text
,
342 cparam
->minimum
.custom_real
,
343 cparam
->maximum
.custom_real
);
346 case PPD_CUSTOM_STRING
:
347 printf(" %s(%s): PPD_CUSTOM_STRING (%d to %d)\n",
348 cparam
->name
, cparam
->text
,
349 cparam
->minimum
.custom_string
,
350 cparam
->maximum
.custom_string
);
360 for (attr
= (ppd_attr_t
*)cupsArrayFirst(ppd
->sorted_attrs
);
362 attr
= (ppd_attr_t
*)cupsArrayNext(ppd
->sorted_attrs
))
363 printf(" *%s %s/%s: \"%s\"\n", attr
->name
, attr
->spec
,
364 attr
->text
, attr
->value
? attr
->value
: "");
375 * End of "$Id: testppd.c 6799 2007-08-15 19:33:36Z mike $".