]>
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>
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: *InputSlot Tray\n"
68 "} stopped cleartomark\n"
70 "%%BeginFeature: *IntOption None\n"
72 "} stopped cleartomark\n"
74 "%%BeginFeature: *StringOption None\n"
76 "} stopped cleartomark\n"
78 "%%BeginFeature: *CustomPageSize True\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 */
102 const char *text
; /* Localized text */
109 fputs("ppdOpenFile: ", stdout
);
111 if ((ppd
= ppdOpenFile("test.ppd")) != NULL
)
115 ppd_status_t err
; /* Last error in file */
116 int line
; /* Line number in file */
120 err
= ppdLastError(&line
);
122 printf("FAIL (%s on line %d)\n", ppdErrorString(err
), line
);
125 fputs("ppdMarkDefaults: ", stdout
);
126 ppdMarkDefaults(ppd
);
128 if ((conflicts
= ppdConflicts(ppd
)) == 0)
133 printf("FAIL (%d conflicts)\n", conflicts
);
136 fputs("ppdEmitString (defaults): ", stdout
);
137 if ((s
= ppdEmitString(ppd
, PPD_ORDER_ANY
, 0.0)) != NULL
&&
138 !strcmp(s
, default_code
))
143 printf("FAIL (%d bytes instead of %d)\n", s
? (int)strlen(s
) : 0,
144 (int)strlen(default_code
));
153 fputs("ppdEmitString (custom size): ", stdout
);
154 ppdMarkOption(ppd
, "PageSize", "Custom.400x500");
156 if ((s
= ppdEmitString(ppd
, PPD_ORDER_ANY
, 0.0)) != NULL
&&
157 !strcmp(s
, custom_code
))
162 printf("FAIL (%d bytes instead of %d)\n", s
? (int)strlen(s
) : 0,
163 (int)strlen(custom_code
));
173 * Test localization...
176 fputs("ppdLocalizeIPPReason(text): ", stdout
);
177 if (ppdLocalizeIPPReason(ppd
, "foo", NULL
, buffer
, sizeof(buffer
)) &&
178 !strcmp(buffer
, "Foo Reason"))
183 printf("FAIL (\"%s\" instead of \"Foo Reason\")\n", buffer
);
186 fputs("ppdLocalizeIPPReason(http): ", stdout
);
187 if (ppdLocalizeIPPReason(ppd
, "foo", "http", buffer
, sizeof(buffer
)) &&
188 !strcmp(buffer
, "http://foo/bar.html"))
193 printf("FAIL (\"%s\" instead of \"http://foo/bar.html\")\n", buffer
);
196 fputs("ppdLocalizeIPPReason(help): ", stdout
);
197 if (ppdLocalizeIPPReason(ppd
, "foo", "help", buffer
, sizeof(buffer
)) &&
198 !strcmp(buffer
, "help:anchor='foo'%20bookID=Vendor%20Help"))
203 printf("FAIL (\"%s\" instead of \"help:anchor='foo'%%20bookID=Vendor%%20Help\")\n", buffer
);
206 fputs("ppdLocalizeIPPReason(file): ", stdout
);
207 if (ppdLocalizeIPPReason(ppd
, "foo", "file", buffer
, sizeof(buffer
)) &&
208 !strcmp(buffer
, "/help/foo/bar.html"))
213 printf("FAIL (\"%s\" instead of \"/help/foo/bar.html\")\n", buffer
);
218 fputs("ppdLocalizeIPPReason(fr text): ", stdout
);
219 if (ppdLocalizeIPPReason(ppd
, "foo", NULL
, buffer
, sizeof(buffer
)) &&
220 !strcmp(buffer
, "La Long Foo Reason"))
225 printf("FAIL (\"%s\" instead of \"La Long Foo Reason\")\n", buffer
);
228 putenv("LANG=zh_TW");
230 fputs("ppdLocalizeIPPReason(zh_TW text): ", stdout
);
231 if (ppdLocalizeIPPReason(ppd
, "foo", NULL
, buffer
, sizeof(buffer
)) &&
232 !strcmp(buffer
, "Number 1 Foo Reason"))
237 printf("FAIL (\"%s\" instead of \"Number 1 Foo Reason\")\n", buffer
);
241 * cupsMarkerName localization...
246 fputs("ppdLocalizeMarkerName(bogus): ", stdout
);
248 if ((text
= ppdLocalizeMarkerName(ppd
, "bogus")) != NULL
)
251 printf("FAIL (\"%s\" instead of NULL)\n", text
);
256 fputs("ppdLocalizeMarkerName(cyan): ", stdout
);
258 if ((text
= ppdLocalizeMarkerName(ppd
, "cyan")) != NULL
&&
259 !strcmp(text
, "Cyan Toner"))
264 printf("FAIL (\"%s\" instead of \"Cyan Toner\")\n",
265 text
? text
: "(null)");
270 fputs("ppdLocalizeMarkerName(fr cyan): ", stdout
);
271 if ((text
= ppdLocalizeMarkerName(ppd
, "cyan")) != NULL
&&
272 !strcmp(text
, "La Toner Cyan"))
277 printf("FAIL (\"%s\" instead of \"La Toner Cyan\")\n",
278 text
? text
: "(null)");
281 putenv("LANG=zh_TW");
283 fputs("ppdLocalizeMarkerName(zh_TW cyan): ", stdout
);
284 if ((text
= ppdLocalizeMarkerName(ppd
, "cyan")) != NULL
&&
285 !strcmp(text
, "Number 1 Cyan Toner"))
290 printf("FAIL (\"%s\" instead of \"Number 1 Cyan Toner\")\n",
291 text
? text
: "(null)");
296 if ((ppd
= ppdOpenFile(argv
[1])) == NULL
)
298 ppd_status_t err
; /* Last error in file */
299 int line
; /* Line number in file */
303 err
= ppdLastError(&line
);
305 printf("%s: %s on line %d\n", argv
[1], ppdErrorString(err
), line
);
309 int i
, j
, k
; /* Looping vars */
310 ppd_attr_t
*attr
; /* Current attribute */
311 ppd_group_t
*group
; /* Option group */
312 ppd_option_t
*option
; /* Option */
313 ppd_coption_t
*coption
; /* Custom option */
314 ppd_cparam_t
*cparam
; /* Custom parameter */
315 char lang
[255]; /* LANG environment variable */
320 snprintf(lang
, sizeof(lang
), "LANG=%s", argv
[2]);
326 for (i
= ppd
->num_groups
, group
= ppd
->groups
;
330 printf("%s (%s):\n", group
->name
, group
->text
);
332 for (j
= group
->num_options
, option
= group
->options
;
336 printf(" %s (%s):\n", option
->keyword
, option
->text
);
338 for (k
= 0; k
< option
->num_choices
; k
++)
339 printf(" - %s (%s)\n", option
->choices
[k
].choice
,
340 option
->choices
[k
].text
);
342 if ((coption
= ppdFindCustomOption(ppd
, option
->keyword
)) != NULL
)
344 for (cparam
= (ppd_cparam_t
*)cupsArrayFirst(coption
->params
);
346 cparam
= (ppd_cparam_t
*)cupsArrayNext(coption
->params
))
348 switch (cparam
->type
)
350 case PPD_CUSTOM_CURVE
:
351 printf(" %s(%s): PPD_CUSTOM_CURVE (%g to %g)\n",
352 cparam
->name
, cparam
->text
,
353 cparam
->minimum
.custom_curve
,
354 cparam
->maximum
.custom_curve
);
357 case PPD_CUSTOM_INT
:
358 printf(" %s(%s): PPD_CUSTOM_INT (%d to %d)\n",
359 cparam
->name
, cparam
->text
,
360 cparam
->minimum
.custom_int
,
361 cparam
->maximum
.custom_int
);
364 case PPD_CUSTOM_INVCURVE
:
365 printf(" %s(%s): PPD_CUSTOM_INVCURVE (%g to %g)\n",
366 cparam
->name
, cparam
->text
,
367 cparam
->minimum
.custom_invcurve
,
368 cparam
->maximum
.custom_invcurve
);
371 case PPD_CUSTOM_PASSCODE
:
372 printf(" %s(%s): PPD_CUSTOM_PASSCODE (%d to %d)\n",
373 cparam
->name
, cparam
->text
,
374 cparam
->minimum
.custom_passcode
,
375 cparam
->maximum
.custom_passcode
);
378 case PPD_CUSTOM_PASSWORD
:
379 printf(" %s(%s): PPD_CUSTOM_PASSWORD (%d to %d)\n",
380 cparam
->name
, cparam
->text
,
381 cparam
->minimum
.custom_password
,
382 cparam
->maximum
.custom_password
);
385 case PPD_CUSTOM_POINTS
:
386 printf(" %s(%s): PPD_CUSTOM_POINTS (%g to %g)\n",
387 cparam
->name
, cparam
->text
,
388 cparam
->minimum
.custom_points
,
389 cparam
->maximum
.custom_points
);
392 case PPD_CUSTOM_REAL
:
393 printf(" %s(%s): PPD_CUSTOM_REAL (%g to %g)\n",
394 cparam
->name
, cparam
->text
,
395 cparam
->minimum
.custom_real
,
396 cparam
->maximum
.custom_real
);
399 case PPD_CUSTOM_STRING
:
400 printf(" %s(%s): PPD_CUSTOM_STRING (%d to %d)\n",
401 cparam
->name
, cparam
->text
,
402 cparam
->minimum
.custom_string
,
403 cparam
->maximum
.custom_string
);
413 for (attr
= (ppd_attr_t
*)cupsArrayFirst(ppd
->sorted_attrs
);
415 attr
= (ppd_attr_t
*)cupsArrayNext(ppd
->sorted_attrs
))
416 printf(" *%s %s/%s: \"%s\"\n", attr
->name
, attr
->spec
,
417 attr
->text
, attr
->value
? attr
->value
: "");
422 if (getenv("MallocStackLogging") && getenv("MallocStackLoggingNoCompact"))
424 char command
[1024]; /* malloc_history command */
426 snprintf(command
, sizeof(command
), "malloc_history %d -all_by_size",
431 #endif /* __APPLE__ */
440 * End of "$Id: testppd.c 6936 2007-09-10 18:15:36Z mike $".