]>
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-2009 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...
38 static int dests_equal(cups_dest_t
*a
, cups_dest_t
*b
);
39 static void show_diffs(cups_dest_t
*a
, cups_dest_t
*b
);
43 * 'main()' - Main entry.
46 int /* O - Exit status */
47 main(int argc
, /* I - Number of command-line arguments */
48 char *argv
[]) /* I - Command-line arguments */
50 int status
= 0, /* Exit status */
52 num_dests
; /* Number of destinations */
53 cups_dest_t
*dests
, /* Destinations */
54 *dest
, /* Current destination */
55 *named_dest
; /* Current named destination */
56 const char *ppdfile
; /* PPD file */
57 ppd_file_t
*ppd
; /* PPD file data */
58 int num_jobs
; /* Number of jobs for queue */
59 cups_job_t
*jobs
; /* Jobs for queue */
65 * ./testcups printer file interval
68 int interval
, /* Interval between writes */
70 cups_file_t
*fp
; /* Print file */
71 char buffer
[16384]; /* Read/write buffer */
72 ssize_t bytes
; /* Bytes read/written */
77 puts("Usage: ./testcups");
78 puts(" ./testcups printer file interval");
82 if ((fp
= cupsFileOpen(argv
[2], "r")) == NULL
)
84 printf("Unable to open \"%s\": %s\n", argv
[2], strerror(errno
));
88 if ((job_id
= cupsCreateJob(CUPS_HTTP_DEFAULT
, argv
[1], "testcups", 0,
91 printf("Unable to create print job on %s: %s\n", argv
[1],
92 cupsLastErrorString());
96 interval
= atoi(argv
[3]);
98 if (cupsStartDocument(CUPS_HTTP_DEFAULT
, argv
[1], job_id
, argv
[2],
99 CUPS_FORMAT_AUTO
, 1) != HTTP_CONTINUE
)
101 puts("Unable to start document!");
105 while ((bytes
= cupsFileRead(fp
, buffer
, sizeof(buffer
))) > 0)
107 printf("Writing %d bytes...\n", (int)bytes
);
109 if (cupsWriteRequestData(CUPS_HTTP_DEFAULT
, buffer
,
110 bytes
) != HTTP_CONTINUE
)
112 puts("Unable to write bytes!");
121 if (cupsFinishDocument(CUPS_HTTP_DEFAULT
, argv
[1]) != HTTP_OK
)
123 puts("Unable to finish document!");
134 fputs("cupsGetDests: ", stdout
);
137 num_dests
= cupsGetDests(&dests
);
146 printf("PASS (%d dests)\n", num_dests
);
148 for (i
= num_dests
, dest
= dests
; i
> 0; i
--, dest
++)
150 printf(" %s", dest
->name
);
153 printf(" /%s", dest
->instance
);
155 if (dest
->is_default
)
156 puts(" ***DEFAULT***");
166 fputs("cupsGetDest(NULL): ", stdout
);
169 if ((dest
= cupsGetDest(NULL
, NULL
, num_dests
, dests
)) == NULL
)
171 for (i
= num_dests
, dest
= dests
; i
> 0; i
--, dest
++)
172 if (dest
->is_default
)
181 puts("PASS (no default)");
186 printf("PASS (%s)\n", dest
->name
);
189 * cupsGetNamedDest(NULL, NULL, NULL)
192 fputs("cupsGetNamedDest(NULL, NULL, NULL): ", stdout
);
195 if ((named_dest
= cupsGetNamedDest(NULL
, NULL
, NULL
)) == NULL
||
196 !dests_equal(dest
, named_dest
))
199 puts("PASS (no default)");
202 puts("FAIL (different values)");
203 show_diffs(dest
, named_dest
);
208 puts("FAIL (no default)");
213 printf("PASS (%s)\n", named_dest
->name
);
216 cupsFreeDests(1, named_dest
);
219 * cupsGetDest(printer)
222 printf("cupsGetDest(\"%s\"): ", dests
[num_dests
/ 2].name
);
225 if ((dest
= cupsGetDest(dests
[num_dests
/ 2].name
, NULL
, num_dests
,
235 * cupsGetNamedDest(NULL, printer, instance)
238 printf("cupsGetNamedDest(NULL, \"%s\", \"%s\"): ", dest
->name
,
239 dest
->instance
? dest
->instance
: "(null)");
242 if ((named_dest
= cupsGetNamedDest(NULL
, dest
->name
,
243 dest
->instance
)) == NULL
||
244 !dests_equal(dest
, named_dest
))
248 puts("FAIL (different values)");
249 show_diffs(dest
, named_dest
);
252 puts("FAIL (no destination)");
261 cupsFreeDests(1, named_dest
);
267 fputs("cupsPrintFile: ", stdout
);
270 if (cupsPrintFile(dest
->name
, "../data/testprint", "Test Page",
271 dest
->num_options
, dest
->options
) <= 0)
273 printf("FAIL (%s)\n", cupsLastErrorString());
280 * cupsGetPPD(printer)
283 fputs("cupsGetPPD(): ", stdout
);
286 if ((ppdfile
= cupsGetPPD(dest
->name
)) == NULL
)
298 fputs("ppdOpenFile(): ", stdout
);
301 if ((ppd
= ppdOpenFile(ppdfile
)) == NULL
)
317 fputs("cupsGetJobs: ", stdout
);
320 num_jobs
= cupsGetJobs(&jobs
, NULL
, 0, -1);
330 cupsFreeJobs(num_jobs
, jobs
);
331 cupsFreeDests(num_dests
, dests
);
338 * 'dests_equal()' - Determine whether two destinations are equal.
341 static int /* O - 1 if equal, 0 if not equal */
342 dests_equal(cups_dest_t
*a
, /* I - First destination */
343 cups_dest_t
*b
) /* I - Second destination */
345 int i
; /* Looping var */
346 cups_option_t
*aoption
; /* Current option */
347 const char *bval
; /* Option value */
356 if (strcasecmp(a
->name
, b
->name
) ||
357 (a
->instance
&& !b
->instance
) ||
358 (!a
->instance
&& b
->instance
) ||
359 (a
->instance
&& strcasecmp(a
->instance
, b
->instance
)) ||
360 a
->num_options
!= b
->num_options
)
363 for (i
= a
->num_options
, aoption
= a
->options
; i
> 0; i
--, aoption
++)
364 if ((bval
= cupsGetOption(aoption
->name
, b
->num_options
,
365 b
->options
)) == NULL
||
366 strcmp(aoption
->value
, bval
))
374 * 'show_diffs()' - Show differences between two destinations.
378 show_diffs(cups_dest_t
*a
, /* I - First destination */
379 cups_dest_t
*b
) /* I - Second destination */
381 int i
; /* Looping var */
382 cups_option_t
*aoption
; /* Current option */
383 const char *bval
; /* Option value */
389 puts(" Item cupsGetDest cupsGetNamedDest");
390 puts(" -------------------- -------------------- --------------------");
392 if (strcasecmp(a
->name
, b
->name
))
393 printf(" name %-20.20s %-20.20s\n", a
->name
, b
->name
);
395 if ((a
->instance
&& !b
->instance
) ||
396 (!a
->instance
&& b
->instance
) ||
397 (a
->instance
&& strcasecmp(a
->instance
, b
->instance
)))
398 printf(" instance %-20.20s %-20.20s\n",
399 a
->instance
? a
->instance
: "(null)",
400 b
->instance
? b
->instance
: "(null)");
402 if (a
->num_options
!= b
->num_options
)
403 printf(" num_options %-20d %-20d\n", a
->num_options
,
406 for (i
= a
->num_options
, aoption
= a
->options
; i
> 0; i
--, aoption
++)
407 if ((bval
= cupsGetOption(aoption
->name
, b
->num_options
,
408 b
->options
)) == NULL
||
409 strcmp(aoption
->value
, bval
))
410 printf(" %-20.20s %-20.20s %-20.20s\n", aoption
->name
,
411 aoption
->value
, bval
? bval
: "(null)");