]>
git.ipfire.org Git - thirdparty/cups.git/blob - cups/testcups.c
4 * CUPS API test program for CUPS.
6 * Copyright 2007-2011 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...
27 #include "string-private.h"
37 static int dests_equal(cups_dest_t
*a
, cups_dest_t
*b
);
38 static void show_diffs(cups_dest_t
*a
, cups_dest_t
*b
);
42 * 'main()' - Main entry.
45 int /* O - Exit status */
46 main(int argc
, /* I - Number of command-line arguments */
47 char *argv
[]) /* I - Command-line arguments */
49 int status
= 0, /* Exit status */
51 num_dests
; /* Number of destinations */
52 cups_dest_t
*dests
, /* Destinations */
53 *dest
, /* Current destination */
54 *named_dest
; /* Current named destination */
55 const char *ppdfile
; /* PPD file */
56 ppd_file_t
*ppd
; /* PPD file data */
57 int num_jobs
; /* Number of jobs for queue */
58 cups_job_t
*jobs
; /* Jobs for queue */
64 * ./testcups printer file interval
67 int interval
, /* Interval between writes */
69 cups_file_t
*fp
; /* Print file */
70 char buffer
[16384]; /* Read/write buffer */
71 ssize_t bytes
; /* Bytes read/written */
76 puts("Usage: ./testcups");
77 puts(" ./testcups printer file interval");
81 if ((fp
= cupsFileOpen(argv
[2], "r")) == NULL
)
83 printf("Unable to open \"%s\": %s\n", argv
[2], strerror(errno
));
87 if ((job_id
= cupsCreateJob(CUPS_HTTP_DEFAULT
, argv
[1], "testcups", 0,
90 printf("Unable to create print job on %s: %s\n", argv
[1],
91 cupsLastErrorString());
95 interval
= atoi(argv
[3]);
97 if (cupsStartDocument(CUPS_HTTP_DEFAULT
, argv
[1], job_id
, argv
[2],
98 CUPS_FORMAT_AUTO
, 1) != HTTP_CONTINUE
)
100 puts("Unable to start document!");
104 while ((bytes
= cupsFileRead(fp
, buffer
, sizeof(buffer
))) > 0)
106 printf("Writing %d bytes...\n", (int)bytes
);
108 if (cupsWriteRequestData(CUPS_HTTP_DEFAULT
, buffer
,
109 bytes
) != HTTP_CONTINUE
)
111 puts("Unable to write bytes!");
120 if (cupsFinishDocument(CUPS_HTTP_DEFAULT
, argv
[1]) != HTTP_OK
)
122 puts("Unable to finish document!");
133 fputs("cupsGetDests: ", stdout
);
136 num_dests
= cupsGetDests(&dests
);
145 printf("PASS (%d dests)\n", num_dests
);
147 for (i
= num_dests
, dest
= dests
; i
> 0; i
--, dest
++)
149 printf(" %s", dest
->name
);
152 printf(" /%s", dest
->instance
);
154 if (dest
->is_default
)
155 puts(" ***DEFAULT***");
165 fputs("cupsGetDest(NULL): ", stdout
);
168 if ((dest
= cupsGetDest(NULL
, NULL
, num_dests
, dests
)) == NULL
)
170 for (i
= num_dests
, dest
= dests
; i
> 0; i
--, dest
++)
171 if (dest
->is_default
)
180 puts("PASS (no default)");
185 printf("PASS (%s)\n", dest
->name
);
188 * cupsGetNamedDest(NULL, NULL, NULL)
191 fputs("cupsGetNamedDest(NULL, NULL, NULL): ", stdout
);
194 if ((named_dest
= cupsGetNamedDest(NULL
, NULL
, NULL
)) == NULL
||
195 !dests_equal(dest
, named_dest
))
198 puts("PASS (no default)");
201 puts("FAIL (different values)");
202 show_diffs(dest
, named_dest
);
207 puts("FAIL (no default)");
212 printf("PASS (%s)\n", named_dest
->name
);
215 cupsFreeDests(1, named_dest
);
218 * cupsGetDest(printer)
221 printf("cupsGetDest(\"%s\"): ", dests
[num_dests
/ 2].name
);
224 if ((dest
= cupsGetDest(dests
[num_dests
/ 2].name
, NULL
, num_dests
,
234 * cupsGetNamedDest(NULL, printer, instance)
237 printf("cupsGetNamedDest(NULL, \"%s\", \"%s\"): ", dest
->name
,
238 dest
->instance
? dest
->instance
: "(null)");
241 if ((named_dest
= cupsGetNamedDest(NULL
, dest
->name
,
242 dest
->instance
)) == NULL
||
243 !dests_equal(dest
, named_dest
))
247 puts("FAIL (different values)");
248 show_diffs(dest
, named_dest
);
251 puts("FAIL (no destination)");
260 cupsFreeDests(1, named_dest
);
266 fputs("cupsPrintFile: ", stdout
);
269 if (cupsPrintFile(dest
->name
, "../data/testprint", "Test Page",
270 dest
->num_options
, dest
->options
) <= 0)
272 printf("FAIL (%s)\n", cupsLastErrorString());
279 * cupsGetPPD(printer)
282 fputs("cupsGetPPD(): ", stdout
);
285 if ((ppdfile
= cupsGetPPD(dest
->name
)) == NULL
)
297 fputs("ppdOpenFile(): ", stdout
);
300 if ((ppd
= ppdOpenFile(ppdfile
)) == NULL
)
316 fputs("cupsGetJobs: ", stdout
);
319 num_jobs
= cupsGetJobs(&jobs
, NULL
, 0, -1);
329 cupsFreeJobs(num_jobs
, jobs
);
330 cupsFreeDests(num_dests
, dests
);
337 * 'dests_equal()' - Determine whether two destinations are equal.
340 static int /* O - 1 if equal, 0 if not equal */
341 dests_equal(cups_dest_t
*a
, /* I - First destination */
342 cups_dest_t
*b
) /* I - Second destination */
344 int i
; /* Looping var */
345 cups_option_t
*aoption
; /* Current option */
346 const char *bval
; /* Option value */
355 if (_cups_strcasecmp(a
->name
, b
->name
) ||
356 (a
->instance
&& !b
->instance
) ||
357 (!a
->instance
&& b
->instance
) ||
358 (a
->instance
&& _cups_strcasecmp(a
->instance
, b
->instance
)) ||
359 a
->num_options
!= b
->num_options
)
362 for (i
= a
->num_options
, aoption
= a
->options
; i
> 0; i
--, aoption
++)
363 if ((bval
= cupsGetOption(aoption
->name
, b
->num_options
,
364 b
->options
)) == NULL
||
365 strcmp(aoption
->value
, bval
))
373 * 'show_diffs()' - Show differences between two destinations.
377 show_diffs(cups_dest_t
*a
, /* I - First destination */
378 cups_dest_t
*b
) /* I - Second destination */
380 int i
; /* Looping var */
381 cups_option_t
*aoption
; /* Current option */
382 const char *bval
; /* Option value */
388 puts(" Item cupsGetDest cupsGetNamedDest");
389 puts(" -------------------- -------------------- --------------------");
391 if (_cups_strcasecmp(a
->name
, b
->name
))
392 printf(" name %-20.20s %-20.20s\n", a
->name
, b
->name
);
394 if ((a
->instance
&& !b
->instance
) ||
395 (!a
->instance
&& b
->instance
) ||
396 (a
->instance
&& _cups_strcasecmp(a
->instance
, b
->instance
)))
397 printf(" instance %-20.20s %-20.20s\n",
398 a
->instance
? a
->instance
: "(null)",
399 b
->instance
? b
->instance
: "(null)");
401 if (a
->num_options
!= b
->num_options
)
402 printf(" num_options %-20d %-20d\n", a
->num_options
,
405 for (i
= a
->num_options
, aoption
= a
->options
; i
> 0; i
--, aoption
++)
406 if ((bval
= cupsGetOption(aoption
->name
, b
->num_options
,
407 b
->options
)) == NULL
||
408 strcmp(aoption
->value
, bval
))
409 printf(" %-20.20s %-20.20s %-20.20s\n", aoption
->name
,
410 aoption
->value
, bval
? bval
: "(null)");