]>
git.ipfire.org Git - thirdparty/cups.git/blob - cups/testcups.c
4 * CUPS API test program for the Common UNIX Printing System (CUPS).
6 * Copyright 2007-2008 by Apple Inc.
7 * Copyright 2007 by Easy Software Products.
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/".
15 * This file is subject to the Apple OS-Developed Software exception.
19 * main() - Main entry.
20 * dests_equal() - Determine whether two destinations are equal.
24 * Include necessary headers...
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
);
41 * 'main()' - Main entry.
44 int /* O - Exit status */
45 main(int argc
, /* I - Number of command-line arguments */
46 char *argv
[]) /* I - Command-line arguments */
48 int status
= 0, /* Exit status */
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 */
64 fputs("cupsGetDests: ", stdout
);
67 num_dests
= cupsGetDests(&dests
);
76 printf("PASS (%d dests)\n", num_dests
);
78 for (i
= num_dests
, dest
= dests
; i
> 0; i
--, dest
++)
80 printf(" %s", dest
->name
);
83 printf(" /%s", dest
->instance
);
86 puts(" ***DEFAULT***");
96 fputs("cupsGetDest(NULL): ", stdout
);
99 if ((dest
= cupsGetDest(NULL
, NULL
, num_dests
, dests
)) == NULL
)
101 for (i
= num_dests
, dest
= dests
; i
> 0; i
--, dest
++)
102 if (dest
->is_default
)
111 puts("PASS (no default)");
116 printf("PASS (%s)\n", dest
->name
);
119 * cupsGetNamedDest(NULL, NULL, NULL)
122 fputs("cupsGetNamedDest(NULL, NULL, NULL): ", stdout
);
125 if ((named_dest
= cupsGetNamedDest(NULL
, NULL
, NULL
)) == NULL
||
126 !dests_equal(dest
, named_dest
))
129 puts("PASS (no default)");
132 puts("FAIL (different values)");
133 show_diffs(dest
, named_dest
);
138 puts("FAIL (no default)");
143 printf("PASS (%s)\n", named_dest
->name
);
146 cupsFreeDests(1, named_dest
);
149 * cupsGetDest(printer)
152 printf("cupsGetDest(\"%s\"): ", dests
[num_dests
/ 2].name
);
155 if ((dest
= cupsGetDest(dests
[num_dests
/ 2].name
, NULL
, num_dests
,
165 * cupsGetNamedDest(NULL, printer, instance)
168 printf("cupsGetNamedDest(NULL, \"%s\", \"%s\"): ", dest
->name
,
169 dest
->instance
? dest
->instance
: "(null)");
172 if ((named_dest
= cupsGetNamedDest(NULL
, dest
->name
,
173 dest
->instance
)) == NULL
||
174 !dests_equal(dest
, named_dest
))
178 puts("FAIL (different values)");
179 show_diffs(dest
, named_dest
);
182 puts("FAIL (no destination)");
191 cupsFreeDests(1, named_dest
);
197 fputs("cupsPrintFile: ", stdout
);
200 if (cupsPrintFile(dest
->name
, "../data/testprint.ps", "Test Page",
201 dest
->num_options
, dest
->options
) <= 0)
210 * cupsGetPPD(printer)
213 fputs("cupsGetPPD(): ", stdout
);
216 if ((ppdfile
= cupsGetPPD(dest
->name
)) == NULL
)
228 fputs("ppdOpenFile(): ", stdout
);
231 if ((ppd
= ppdOpenFile(ppdfile
)) == NULL
)
247 fputs("cupsGetJobs: ", stdout
);
250 num_jobs
= cupsGetJobs(&jobs
, NULL
, 0, -1);
260 cupsFreeJobs(num_jobs
, jobs
);
261 cupsFreeDests(num_dests
, dests
);
268 * 'dests_equal()' - Determine whether two destinations are equal.
271 static int /* O - 1 if equal, 0 if not equal */
272 dests_equal(cups_dest_t
*a
, /* I - First destination */
273 cups_dest_t
*b
) /* I - Second destination */
275 int i
; /* Looping var */
276 cups_option_t
*aoption
; /* Current option */
277 const char *bval
; /* Option value */
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
)
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
))
304 * 'show_diffs()' - Show differences between two destinations.
308 show_diffs(cups_dest_t
*a
, /* I - First destination */
309 cups_dest_t
*b
) /* I - Second destination */
311 int i
; /* Looping var */
312 cups_option_t
*aoption
; /* Current option */
313 const char *bval
; /* Option value */
319 puts(" Item cupsGetDest cupsGetNamedDest");
320 puts(" -------------------- -------------------- --------------------");
322 if (strcasecmp(a
->name
, b
->name
))
323 printf(" name %-20.20s %-20.20s\n", a
->name
, b
->name
);
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)");
332 if (a
->num_options
!= b
->num_options
)
333 printf(" num_options %-20d %-20d\n", a
->num_options
,
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)");