]>
Commit | Line | Data |
---|---|---|
1 | /* | |
2 | * "$Id: testppd.c 5826 2006-08-15 19:04:11Z mike $" | |
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 | ||
48 | /* | |
49 | * Test data... | |
50 | */ | |
51 | ||
52 | static 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" | |
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 | ||
72 | static 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" | |
95 | "} stopped cleartomark\n"; | |
96 | ||
97 | ||
98 | /* | |
99 | * 'main()' - Main entry. | |
100 | */ | |
101 | ||
102 | int /* O - Exit status */ | |
103 | main(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) */ | |
108 | int conflicts; /* Number of conflicts */ | |
109 | char *s; /* String */ | |
110 | ||
111 | ||
112 | status = 0; | |
113 | ||
114 | if (argc == 1) | |
115 | { | |
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 | ||
143 | fputs("ppdEmitString (defaults): ", stdout); | |
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); | |
154 | } | |
155 | ||
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 | ||
174 | if (s) | |
175 | free(s); | |
176 | ||
177 | ppdClose(ppd); | |
178 | } | |
179 | else | |
180 | { | |
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 */ | |
195 | ppd_attr_t *attr; /* Current attribute */ | |
196 | ppd_group_t *group; /* Option group */ | |
197 | ppd_option_t *option; /* Option */ | |
198 | char lang[255]; /* LANG environment variable */ | |
199 | ||
200 | ||
201 | if (argc > 2) | |
202 | { | |
203 | snprintf(lang, sizeof(lang), "LANG=%s", argv[2]); | |
204 | putenv(lang); | |
205 | } | |
206 | ||
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); | |
214 | ||
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 | } | |
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 : ""); | |
234 | } | |
235 | } | |
236 | ||
237 | return (status); | |
238 | } | |
239 | ||
240 | ||
241 | /* | |
242 | * End of "$Id: testppd.c 5826 2006-08-15 19:04:11Z mike $". | |
243 | */ |