]> 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/*
d09495fa 2 * "$Id: testppd.c 5826 2006-08-15 19:04:11Z 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 */
d09495fa 198 char lang[255]; /* LANG environment variable */
a74454a7 199
200
d09495fa 201 if (argc > 2)
202 {
203 snprintf(lang, sizeof(lang), "LANG=%s", argv[2]);
204 putenv(lang);
205 }
206
a74454a7 207 ppdLocalize(ppd);
208
209 for (i = ppd->num_groups, group = ppd->groups;
210 i > 0;
211 i --, group ++)
212 {
213 printf("%s (%s):\n", group->name, group->text);
d09495fa 214
a74454a7 215 for (j = group->num_options, option = group->options;
216 j > 0;
217 j --, option ++)
218 {
219 printf(" %s (%s):\n", option->keyword, option->text);
220
221 for (k = 0; k < option->num_choices; k ++)
222 printf(" - %s (%s)\n", option->choices[k].choice,
223 option->choices[k].text);
224 }
225 }
d09495fa 226
227 puts("Attributes:");
228
229 for (attr = (ppd_attr_t *)cupsArrayFirst(ppd->sorted_attrs);
230 attr;
231 attr = (ppd_attr_t *)cupsArrayNext(ppd->sorted_attrs))
232 printf(" *%s %s/%s: \"%s\"\n", attr->name, attr->spec,
233 attr->text, attr->value ? attr->value : "");
a74454a7 234 }
e1d6a774 235 }
236
fa73b229 237 return (status);
238}
239
240
241/*
d09495fa 242 * End of "$Id: testppd.c 5826 2006-08-15 19:04:11Z mike $".
fa73b229 243 */