]> git.ipfire.org Git - thirdparty/cups.git/blame - cups/testppd.c
Load cups into easysw/current.
[thirdparty/cups.git] / cups / testppd.c
CommitLineData
fa73b229 1/*
f7deaa1a 2 * "$Id: testppd.c 6159 2006-12-19 20:08:42Z mike $"
fa73b229 3 *
4 * PPD test program for the Common UNIX Printing System (CUPS).
5 *
6 * Copyright 1997-2006 by Easy Software Products.
7 *
8 * These coded instructions, statements, and computer programs are the
9 * property of Easy Software Products and are protected by Federal
10 * copyright law. Distribution and use rights are outlined in the file
11 * "LICENSE.txt" which should have been included with this file. If this
12 * file is missing or damaged please contact Easy Software Products
13 * at:
14 *
15 * Attn: CUPS Licensing Information
16 * Easy Software Products
17 * 44141 Airport View Drive, Suite 204
18 * Hollywood, Maryland 20636 USA
19 *
20 * Voice: (301) 373-9600
21 * EMail: cups-info@cups.org
22 * WWW: http://www.cups.org
23 *
24 * This file is subject to the Apple OS-Developed Software exception.
25 *
26 * Contents:
27 *
28 * main() - Main entry.
29 */
30
31/*
32 * Include necessary headers...
33 */
34
35#include <stdio.h>
36#include <stdlib.h>
37#include <cups/string.h>
38#include <errno.h>
39#include "ppd.h"
40#ifdef WIN32
41# include <io.h>
42#else
43# include <unistd.h>
44# include <fcntl.h>
45#endif /* WIN32 */
46
47
e1d6a774 48/*
49 * Test data...
50 */
51
52static const char *default_code =
53 "[{\n"
54 "%%BeginFeature: *PageRegion Letter\n"
55 "PageRegion=Letter\n"
56 "%%EndFeature\n"
57 "} stopped cleartomark\n"
58 "[{\n"
59 "%%BeginFeature: *InputSlot Tray\n"
60 "InputSlot=Tray\n"
61 "%%EndFeature\n"
8ca02f3c 62 "} stopped cleartomark\n"
63 "[{\n"
64 "%%BeginFeature: *IntOption None\n"
65 "%%EndFeature\n"
66 "} stopped cleartomark\n"
67 "[{\n"
68 "%%BeginFeature: *StringOption None\n"
69 "%%EndFeature\n"
70 "} stopped cleartomark\n";
71
72static const char *custom_code =
73 "[{\n"
74 "%%BeginFeature: *CustomPageSize True\n"
75 "400\n"
76 "500\n"
77 "0\n"
78 "0\n"
79 "0\n"
80 "PageSize=Custom\n"
81 "%%EndFeature\n"
82 "} stopped cleartomark\n"
83 "[{\n"
84 "%%BeginFeature: *InputSlot Tray\n"
85 "InputSlot=Tray\n"
86 "%%EndFeature\n"
87 "} stopped cleartomark\n"
88 "[{\n"
89 "%%BeginFeature: *IntOption None\n"
90 "%%EndFeature\n"
91 "} stopped cleartomark\n"
92 "[{\n"
93 "%%BeginFeature: *StringOption None\n"
94 "%%EndFeature\n"
e1d6a774 95 "} stopped cleartomark\n";
96
97
fa73b229 98/*
99 * 'main()' - Main entry.
100 */
101
102int /* O - Exit status */
103main(int argc, /* I - Number of command-line arguments */
104 char *argv[]) /* I - Command-line arguments */
105{
106 ppd_file_t *ppd; /* PPD file loaded from disk */
107 int status; /* Status of tests (0 = success, 1 = fail) */
e1d6a774 108 int conflicts; /* Number of conflicts */
109 char *s; /* String */
fa73b229 110
111
112 status = 0;
113
a74454a7 114 if (argc == 1)
fa73b229 115 {
a74454a7 116 fputs("ppdOpenFile: ", stdout);
117
118 if ((ppd = ppdOpenFile("test.ppd")) != NULL)
119 puts("PASS");
120 else
121 {
122 ppd_status_t err; /* Last error in file */
123 int line; /* Line number in file */
124
125
126 status ++;
127 err = ppdLastError(&line);
128
129 printf("FAIL (%s on line %d)\n", ppdErrorString(err), line);
130 }
131
132 fputs("ppdMarkDefaults: ", stdout);
133 ppdMarkDefaults(ppd);
134
135 if ((conflicts = ppdConflicts(ppd)) == 0)
136 puts("PASS");
137 else
138 {
139 status ++;
140 printf("FAIL (%d conflicts)\n", conflicts);
141 }
142
8ca02f3c 143 fputs("ppdEmitString (defaults): ", stdout);
a74454a7 144 if ((s = ppdEmitString(ppd, PPD_ORDER_ANY, 0.0)) != NULL &&
145 !strcmp(s, default_code))
146 puts("PASS");
147 else
148 {
149 printf("FAIL (%d bytes instead of %d)\n", s ? (int)strlen(s) : 0,
150 (int)strlen(default_code));
151
152 if (s)
153 puts(s);
ed486911 154 }
155
8ca02f3c 156 if (s)
157 free(s);
158
159 fputs("ppdEmitString (custom size): ", stdout);
160 ppdMarkOption(ppd, "PageSize", "Custom.400x500");
161
162 if ((s = ppdEmitString(ppd, PPD_ORDER_ANY, 0.0)) != NULL &&
163 !strcmp(s, custom_code))
164 puts("PASS");
165 else
166 {
167 printf("FAIL (%d bytes instead of %d)\n", s ? (int)strlen(s) : 0,
168 (int)strlen(custom_code));
169
170 if (s)
171 puts(s);
172 }
173
a74454a7 174 if (s)
175 free(s);
e1d6a774 176
a74454a7 177 ppdClose(ppd);
e1d6a774 178 }
e1d6a774 179 else
180 {
a74454a7 181 if ((ppd = ppdOpenFile(argv[1])) == NULL)
182 {
183 ppd_status_t err; /* Last error in file */
184 int line; /* Line number in file */
185
186
187 status ++;
188 err = ppdLastError(&line);
189
190 printf("%s: %s on line %d\n", argv[1], ppdErrorString(err), line);
191 }
192 else
193 {
194 int i, j, k; /* Looping vars */
d09495fa 195 ppd_attr_t *attr; /* Current attribute */
a74454a7 196 ppd_group_t *group; /* Option group */
197 ppd_option_t *option; /* Option */
b86bc4cf 198 ppd_coption_t *coption; /* Custom option */
199 ppd_cparam_t *cparam; /* Custom parameter */
d09495fa 200 char lang[255]; /* LANG environment variable */
a74454a7 201
202
d09495fa 203 if (argc > 2)
204 {
205 snprintf(lang, sizeof(lang), "LANG=%s", argv[2]);
206 putenv(lang);
207 }
208
a74454a7 209 ppdLocalize(ppd);
210
211 for (i = ppd->num_groups, group = ppd->groups;
212 i > 0;
213 i --, group ++)
214 {
215 printf("%s (%s):\n", group->name, group->text);
d09495fa 216
a74454a7 217 for (j = group->num_options, option = group->options;
218 j > 0;
219 j --, option ++)
220 {
221 printf(" %s (%s):\n", option->keyword, option->text);
222
223 for (k = 0; k < option->num_choices; k ++)
224 printf(" - %s (%s)\n", option->choices[k].choice,
225 option->choices[k].text);
b86bc4cf 226
227 if ((coption = ppdFindCustomOption(ppd, option->keyword)) != NULL)
228 {
229 for (cparam = (ppd_cparam_t *)cupsArrayFirst(coption->params);
230 cparam;
231 cparam = (ppd_cparam_t *)cupsArrayNext(coption->params))
232 {
233 switch (cparam->type)
234 {
235 case PPD_CUSTOM_CURVE :
236 printf(" %s(%s): PPD_CUSTOM_CURVE (%g to %g)\n",
237 cparam->name, cparam->text,
238 cparam->minimum.custom_curve,
239 cparam->maximum.custom_curve);
240 break;
241
242 case PPD_CUSTOM_INT :
243 printf(" %s(%s): PPD_CUSTOM_INT (%d to %d)\n",
244 cparam->name, cparam->text,
245 cparam->minimum.custom_int,
246 cparam->maximum.custom_int);
247 break;
248
249 case PPD_CUSTOM_INVCURVE :
250 printf(" %s(%s): PPD_CUSTOM_INVCURVE (%g to %g)\n",
251 cparam->name, cparam->text,
252 cparam->minimum.custom_invcurve,
253 cparam->maximum.custom_invcurve);
254 break;
255
256 case PPD_CUSTOM_PASSCODE :
257 printf(" %s(%s): PPD_CUSTOM_PASSCODE (%d to %d)\n",
258 cparam->name, cparam->text,
259 cparam->minimum.custom_passcode,
260 cparam->maximum.custom_passcode);
261 break;
262
263 case PPD_CUSTOM_PASSWORD :
264 printf(" %s(%s): PPD_CUSTOM_PASSWORD (%d to %d)\n",
265 cparam->name, cparam->text,
266 cparam->minimum.custom_password,
267 cparam->maximum.custom_password);
268 break;
269
270 case PPD_CUSTOM_POINTS :
271 printf(" %s(%s): PPD_CUSTOM_POINTS (%g to %g)\n",
272 cparam->name, cparam->text,
273 cparam->minimum.custom_points,
274 cparam->maximum.custom_points);
275 break;
276
277 case PPD_CUSTOM_REAL :
278 printf(" %s(%s): PPD_CUSTOM_REAL (%g to %g)\n",
279 cparam->name, cparam->text,
280 cparam->minimum.custom_real,
281 cparam->maximum.custom_real);
282 break;
283
284 case PPD_CUSTOM_STRING :
285 printf(" %s(%s): PPD_CUSTOM_STRING (%d to %d)\n",
286 cparam->name, cparam->text,
287 cparam->minimum.custom_string,
288 cparam->maximum.custom_string);
289 break;
290 }
291 }
292 }
a74454a7 293 }
294 }
d09495fa 295
296 puts("Attributes:");
297
298 for (attr = (ppd_attr_t *)cupsArrayFirst(ppd->sorted_attrs);
299 attr;
300 attr = (ppd_attr_t *)cupsArrayNext(ppd->sorted_attrs))
301 printf(" *%s %s/%s: \"%s\"\n", attr->name, attr->spec,
302 attr->text, attr->value ? attr->value : "");
a74454a7 303 }
e1d6a774 304 }
305
fa73b229 306 return (status);
307}
308
309
310/*
f7deaa1a 311 * End of "$Id: testppd.c 6159 2006-12-19 20:08:42Z mike $".
fa73b229 312 */