]> git.ipfire.org Git - thirdparty/cups.git/blame - cups/testcups.c
Merge changes from CUPS 1.4svn-r8290.
[thirdparty/cups.git] / cups / testcups.c
CommitLineData
09a101d6 1/*
2 * "$Id$"
3 *
4 * CUPS API test program for the Common UNIX Printing System (CUPS).
5 *
1f0275e3 6 * Copyright 2007-2008 by Apple Inc.
09a101d6 7 * Copyright 2007 by Easy Software Products.
8 *
9 * These coded instructions, statements, and computer programs are the
bc44d920 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/".
09a101d6 14 *
15 * This file is subject to the Apple OS-Developed Software exception.
16 *
17 * Contents:
18 *
a4924f6c
MS
19 * main() - Main entry.
20 * dests_equal() - Determine whether two destinations are equal.
09a101d6 21 */
22
23/*
24 * Include necessary headers...
25 */
26
27#include <stdio.h>
28#include <stdlib.h>
29#include "cups.h"
30
31
a4924f6c
MS
32/*
33 * Local functions...
34 */
35
36static int dests_equal(cups_dest_t *a, cups_dest_t *b);
37static void show_diffs(cups_dest_t *a, cups_dest_t *b);
38
39
09a101d6 40/*
41 * 'main()' - Main entry.
42 */
43
44int /* O - Exit status */
45main(int argc, /* I - Number of command-line arguments */
46 char *argv[]) /* I - Command-line arguments */
47{
48 int status = 0, /* Exit status */
a4924f6c 49 i, /* Looping var */
09a101d6 50 num_dests; /* Number of destinations */
51 cups_dest_t *dests, /* Destinations */
a4924f6c
MS
52 *dest, /* Current destination */
53 *named_dest; /* Current named destination */
09a101d6 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
a4924f6c
MS
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);
09a101d6 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 {
09a101d6 158 puts("FAIL");
91c84a35 159 return (1);
09a101d6 160 }
161 else
162 puts("PASS");
163
164 /*
a4924f6c 165 * cupsGetNamedDest(NULL, printer, instance)
09a101d6 166 */
167
a4924f6c
MS
168 printf("cupsGetNamedDest(NULL, \"%s\", \"%s\"): ", dest->name,
169 dest->instance ? dest->instance : "(null)");
09a101d6 170 fflush(stdout);
171
a4924f6c
MS
172 if ((named_dest = cupsGetNamedDest(NULL, dest->name,
173 dest->instance)) == NULL ||
174 !dests_equal(dest, named_dest))
09a101d6 175 {
a4924f6c
MS
176 if (named_dest)
177 {
178 puts("FAIL (different values)");
179 show_diffs(dest, named_dest);
180 }
181 else
182 puts("FAIL (no destination)");
183
184
09a101d6 185 status = 1;
09a101d6 186 }
187 else
188 puts("PASS");
189
a4924f6c
MS
190 if (named_dest)
191 cupsFreeDests(1, named_dest);
192
09a101d6 193 /*
194 * cupsPrintFile()
195 */
196
197 fputs("cupsPrintFile: ", stdout);
198 fflush(stdout);
199
426c6a59 200 if (cupsPrintFile(dest->name, "../data/testprint", "Test Page",
09a101d6 201 dest->num_options, dest->options) <= 0)
202 {
426c6a59 203 printf("FAIL (%s)\n", cupsLastErrorString());
1f0275e3 204 return (1);
09a101d6 205 }
206 else
207 puts("PASS");
208
209 /*
210 * cupsGetPPD(printer)
211 */
212
213 fputs("cupsGetPPD(): ", stdout);
214 fflush(stdout);
215
216 if ((ppdfile = cupsGetPPD(dest->name)) == NULL)
217 {
09a101d6 218 puts("FAIL");
219 }
220 else
221 {
222 puts("PASS");
223
224 /*
225 * ppdOpenFile()
226 */
227
228 fputs("ppdOpenFile(): ", stdout);
229 fflush(stdout);
230
231 if ((ppd = ppdOpenFile(ppdfile)) == NULL)
232 {
233 puts("FAIL");
234 return (1);
235 }
236 else
237 puts("PASS");
238
239 ppdClose(ppd);
240 unlink(ppdfile);
241 }
242
243 /*
244 * cupsGetJobs()
245 */
246
247 fputs("cupsGetJobs: ", stdout);
248 fflush(stdout);
249
250 num_jobs = cupsGetJobs(&jobs, NULL, 0, -1);
251
252 if (num_jobs == 0)
253 {
254 puts("FAIL");
255 return (1);
256 }
257 else
258 puts("PASS");
259
260 cupsFreeJobs(num_jobs, jobs);
261 cupsFreeDests(num_dests, dests);
262
263 return (status);
264}
265
266
a4924f6c
MS
267/*
268 * 'dests_equal()' - Determine whether two destinations are equal.
269 */
270
271static int /* O - 1 if equal, 0 if not equal */
272dests_equal(cups_dest_t *a, /* I - First destination */
273 cups_dest_t *b) /* I - Second destination */
274{
275 int i; /* Looping var */
276 cups_option_t *aoption; /* Current option */
277 const char *bval; /* Option value */
278
279
280 if (a == b)
281 return (1);
282
1f0275e3 283 if (!a || !b)
a4924f6c
MS
284 return (0);
285
286 if (strcasecmp(a->name, b->name) ||
287 (a->instance && !b->instance) ||
288 (!a->instance && b->instance) ||
289 (a->instance && strcasecmp(a->instance, b->instance)) ||
290 a->num_options != b->num_options)
291 return (0);
292
293 for (i = a->num_options, aoption = a->options; i > 0; i --, aoption ++)
294 if ((bval = cupsGetOption(aoption->name, b->num_options,
295 b->options)) == NULL ||
296 strcmp(aoption->value, bval))
297 return (0);
298
299 return (1);
300}
301
302
303/*
304 * 'show_diffs()' - Show differences between two destinations.
305 */
306
307static void
308show_diffs(cups_dest_t *a, /* I - First destination */
309 cups_dest_t *b) /* I - Second destination */
310{
311 int i; /* Looping var */
312 cups_option_t *aoption; /* Current option */
313 const char *bval; /* Option value */
314
315
316 if (!a || !b)
317 return;
318
319 puts(" Item cupsGetDest cupsGetNamedDest");
320 puts(" -------------------- -------------------- --------------------");
321
322 if (strcasecmp(a->name, b->name))
323 printf(" name %-20.20s %-20.20s\n", a->name, b->name);
324
325 if ((a->instance && !b->instance) ||
326 (!a->instance && b->instance) ||
327 (a->instance && strcasecmp(a->instance, b->instance)))
328 printf(" instance %-20.20s %-20.20s\n",
329 a->instance ? a->instance : "(null)",
330 b->instance ? b->instance : "(null)");
331
332 if (a->num_options != b->num_options)
333 printf(" num_options %-20d %-20d\n", a->num_options,
334 b->num_options);
335
336 for (i = a->num_options, aoption = a->options; i > 0; i --, aoption ++)
337 if ((bval = cupsGetOption(aoption->name, b->num_options,
338 b->options)) == NULL ||
339 strcmp(aoption->value, bval))
340 printf(" %-20.20s %-20.20s %-20.20s\n", aoption->name,
341 aoption->value, bval ? bval : "(null)");
342}
343
344
09a101d6 345/*
1f0275e3 346 * End of "$Id$".
09a101d6 347 */