]> git.ipfire.org Git - thirdparty/cups.git/blob - cups/testcups.c
Import CUPS 1.4svn-r7226.
[thirdparty/cups.git] / cups / testcups.c
1 /*
2 * "$Id$"
3 *
4 * CUPS API test program for the Common UNIX Printing System (CUPS).
5 *
6 * Copyright 2007 by Apple Inc.
7 * Copyright 2007 by Easy Software Products.
8 *
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/".
14 *
15 * This file is subject to the Apple OS-Developed Software exception.
16 *
17 * Contents:
18 *
19 * main() - Main entry.
20 * dests_equal() - Determine whether two destinations are equal.
21 */
22
23 /*
24 * Include necessary headers...
25 */
26
27 #include <stdio.h>
28 #include <stdlib.h>
29 #include "cups.h"
30
31
32 /*
33 * Local functions...
34 */
35
36 static int dests_equal(cups_dest_t *a, cups_dest_t *b);
37 static void show_diffs(cups_dest_t *a, cups_dest_t *b);
38
39
40 /*
41 * 'main()' - Main entry.
42 */
43
44 int /* O - Exit status */
45 main(int argc, /* I - Number of command-line arguments */
46 char *argv[]) /* I - Command-line arguments */
47 {
48 int status = 0, /* Exit status */
49 i, /* Looping var */
50 num_dests; /* Number of destinations */
51 cups_dest_t *dests, /* Destinations */
52 *dest, /* Current destination */
53 *named_dest; /* Current named destination */
54 const char *ppdfile; /* PPD file */
55 ppd_file_t *ppd; /* PPD file data */
56 int num_jobs; /* Number of jobs for queue */
57 cups_job_t *jobs; /* Jobs for queue */
58
59
60 /*
61 * cupsGetDests()
62 */
63
64 fputs("cupsGetDests: ", stdout);
65 fflush(stdout);
66
67 num_dests = cupsGetDests(&dests);
68
69 if (num_dests == 0)
70 {
71 puts("FAIL");
72 return (1);
73 }
74 else
75 {
76 printf("PASS (%d dests)\n", num_dests);
77
78 for (i = num_dests, dest = dests; i > 0; i --, dest ++)
79 {
80 printf(" %s", dest->name);
81
82 if (dest->instance)
83 printf(" /%s", dest->instance);
84
85 if (dest->is_default)
86 puts(" ***DEFAULT***");
87 else
88 putchar('\n');
89 }
90 }
91
92 /*
93 * cupsGetDest(NULL)
94 */
95
96 fputs("cupsGetDest(NULL): ", stdout);
97 fflush(stdout);
98
99 if ((dest = cupsGetDest(NULL, NULL, num_dests, dests)) == NULL)
100 {
101 for (i = num_dests, dest = dests; i > 0; i --, dest ++)
102 if (dest->is_default)
103 break;
104
105 if (i)
106 {
107 status = 1;
108 puts("FAIL");
109 }
110 else
111 puts("PASS (no default)");
112
113 dest = NULL;
114 }
115 else
116 printf("PASS (%s)\n", dest->name);
117
118 /*
119 * cupsGetNamedDest(NULL, NULL, NULL)
120 */
121
122 fputs("cupsGetNamedDest(NULL, NULL, NULL): ", stdout);
123 fflush(stdout);
124
125 if ((named_dest = cupsGetNamedDest(NULL, NULL, NULL)) == NULL ||
126 !dests_equal(dest, named_dest))
127 {
128 if (!dest)
129 puts("PASS (no default)");
130 else if (named_dest)
131 {
132 puts("FAIL (different values)");
133 show_diffs(dest, named_dest);
134 status = 1;
135 }
136 else
137 {
138 puts("FAIL (no default)");
139 status = 1;
140 }
141 }
142 else
143 printf("PASS (%s)\n", named_dest->name);
144
145 if (named_dest)
146 cupsFreeDests(1, named_dest);
147
148 /*
149 * cupsGetDest(printer)
150 */
151
152 printf("cupsGetDest(\"%s\"): ", dests[num_dests / 2].name);
153 fflush(stdout);
154
155 if ((dest = cupsGetDest(dests[num_dests / 2].name, NULL, num_dests,
156 dests)) == NULL)
157 {
158 status = 1;
159 puts("FAIL");
160 return (1);
161 }
162 else
163 puts("PASS");
164
165 /*
166 * cupsGetNamedDest(NULL, printer, instance)
167 */
168
169 printf("cupsGetNamedDest(NULL, \"%s\", \"%s\"): ", dest->name,
170 dest->instance ? dest->instance : "(null)");
171 fflush(stdout);
172
173 if ((named_dest = cupsGetNamedDest(NULL, dest->name,
174 dest->instance)) == NULL ||
175 !dests_equal(dest, named_dest))
176 {
177 if (named_dest)
178 {
179 puts("FAIL (different values)");
180 show_diffs(dest, named_dest);
181 }
182 else
183 puts("FAIL (no destination)");
184
185
186 status = 1;
187 }
188 else
189 puts("PASS");
190
191 if (named_dest)
192 cupsFreeDests(1, named_dest);
193
194 /*
195 * cupsPrintFile()
196 */
197
198 fputs("cupsPrintFile: ", stdout);
199 fflush(stdout);
200
201 if (cupsPrintFile(dest->name, "../data/testprint.ps", "Test Page",
202 dest->num_options, dest->options) <= 0)
203 {
204 status = 1;
205 puts("FAIL");
206 }
207 else
208 puts("PASS");
209
210 /*
211 * cupsGetPPD(printer)
212 */
213
214 fputs("cupsGetPPD(): ", stdout);
215 fflush(stdout);
216
217 if ((ppdfile = cupsGetPPD(dest->name)) == NULL)
218 {
219 status = 1;
220 puts("FAIL");
221 }
222 else
223 {
224 puts("PASS");
225
226 /*
227 * ppdOpenFile()
228 */
229
230 fputs("ppdOpenFile(): ", stdout);
231 fflush(stdout);
232
233 if ((ppd = ppdOpenFile(ppdfile)) == NULL)
234 {
235 puts("FAIL");
236 return (1);
237 }
238 else
239 puts("PASS");
240
241 ppdClose(ppd);
242 unlink(ppdfile);
243 }
244
245 /*
246 * cupsGetJobs()
247 */
248
249 fputs("cupsGetJobs: ", stdout);
250 fflush(stdout);
251
252 num_jobs = cupsGetJobs(&jobs, NULL, 0, -1);
253
254 if (num_jobs == 0)
255 {
256 puts("FAIL");
257 return (1);
258 }
259 else
260 puts("PASS");
261
262 cupsFreeJobs(num_jobs, jobs);
263 cupsFreeDests(num_dests, dests);
264
265 return (status);
266 }
267
268
269 /*
270 * 'dests_equal()' - Determine whether two destinations are equal.
271 */
272
273 static int /* O - 1 if equal, 0 if not equal */
274 dests_equal(cups_dest_t *a, /* I - First destination */
275 cups_dest_t *b) /* I - Second destination */
276 {
277 int i; /* Looping var */
278 cups_option_t *aoption; /* Current option */
279 const char *bval; /* Option value */
280
281
282 if (a == b)
283 return (1);
284
285 if ((!a && b) || (a && !b))
286 return (0);
287
288 if (strcasecmp(a->name, b->name) ||
289 (a->instance && !b->instance) ||
290 (!a->instance && b->instance) ||
291 (a->instance && strcasecmp(a->instance, b->instance)) ||
292 a->num_options != b->num_options)
293 return (0);
294
295 for (i = a->num_options, aoption = a->options; i > 0; i --, aoption ++)
296 if ((bval = cupsGetOption(aoption->name, b->num_options,
297 b->options)) == NULL ||
298 strcmp(aoption->value, bval))
299 return (0);
300
301 return (1);
302 }
303
304
305 /*
306 * 'show_diffs()' - Show differences between two destinations.
307 */
308
309 static void
310 show_diffs(cups_dest_t *a, /* I - First destination */
311 cups_dest_t *b) /* I - Second destination */
312 {
313 int i; /* Looping var */
314 cups_option_t *aoption; /* Current option */
315 const char *bval; /* Option value */
316
317
318 if (!a || !b)
319 return;
320
321 puts(" Item cupsGetDest cupsGetNamedDest");
322 puts(" -------------------- -------------------- --------------------");
323
324 if (strcasecmp(a->name, b->name))
325 printf(" name %-20.20s %-20.20s\n", a->name, b->name);
326
327 if ((a->instance && !b->instance) ||
328 (!a->instance && b->instance) ||
329 (a->instance && strcasecmp(a->instance, b->instance)))
330 printf(" instance %-20.20s %-20.20s\n",
331 a->instance ? a->instance : "(null)",
332 b->instance ? b->instance : "(null)");
333
334 if (a->num_options != b->num_options)
335 printf(" num_options %-20d %-20d\n", a->num_options,
336 b->num_options);
337
338 for (i = a->num_options, aoption = a->options; i > 0; i --, aoption ++)
339 if ((bval = cupsGetOption(aoption->name, b->num_options,
340 b->options)) == NULL ||
341 strcmp(aoption->value, bval))
342 printf(" %-20.20s %-20.20s %-20.20s\n", aoption->name,
343 aoption->value, bval ? bval : "(null)");
344 }
345
346
347 /*
348 * End of "$Id: testfile.c 6192 2007-01-10 19:26:48Z mike $".
349 */