|
1 | | -/* |
2 | | - * CUPS cupsGetDests API test program for CUPS. |
3 | | - * |
4 | | - * Copyright 2017 by Apple Inc. |
5 | | - * |
6 | | - * Licensed under Apache License v2.0. See the file "LICENSE" for more information. |
7 | | - */ |
8 | | - |
9 | | -/* |
10 | | - * Include necessary headers... |
11 | | - */ |
| 1 | +// |
| 2 | +// CUPS cupsGetDests API test program for CUPS. |
| 3 | +// |
| 4 | +// Copyright © 2023 by OpenPrinting. |
| 5 | +// Copyright © 2017 by Apple Inc. |
| 6 | +// |
| 7 | +// Licensed under Apache License v2.0. See the file "LICENSE" for more |
| 8 | +// information. |
| 9 | +// |
12 | 10 |
|
13 | 11 | #include <stdio.h> |
14 | | -#include "cups.h" |
| 12 | +#include <stdlib.h> |
15 | 13 | #include <sys/time.h> |
| 14 | +#include "cups.h" |
| 15 | +#include "test-internal.h" |
16 | 16 |
|
17 | 17 |
|
18 | | -/* |
19 | | - * 'main()' - Loop calling cupsGetDests. |
20 | | - */ |
| 18 | +// |
| 19 | +// 'main()' - Loop calling cupsGetDests. |
| 20 | +// |
21 | 21 |
|
22 | | -int /* O - Exit status */ |
23 | | -main(void) |
| 22 | +int // O - Exit status |
| 23 | +main(int argc, // I - Number of command-line arguments |
| 24 | + char *argv[]) // I - Command-line arguments |
24 | 25 | { |
25 | | - int num_dests; /* Number of destinations */ |
26 | | - cups_dest_t *dests; /* Destinations */ |
27 | | - struct timeval start, end; /* Start and stop time */ |
28 | | - double secs; /* Total seconds to run cupsGetDests */ |
| 26 | + size_t count = 1; // Number of times |
| 27 | + size_t num_dests; // Number of destinations |
| 28 | + cups_dest_t *dests; // Destinations |
| 29 | + struct timeval start, end; // Start and stop time |
| 30 | + double secs; // Total seconds to run cupsGetDests |
| 31 | + |
| 32 | + |
| 33 | + // Parse command-line... |
| 34 | + if (argc > 2 || (argc == 2 && (argv[1][0] < '1' || argv[1][0] > '9'))) |
| 35 | + { |
| 36 | + fputs("Usage: ./testgetdests [COUNT]\n", stderr); |
| 37 | + return (1); |
| 38 | + } |
29 | 39 |
|
| 40 | + if (argc == 2) |
| 41 | + count = strtoul(argv[1], NULL, 10); |
| 42 | + else |
| 43 | + count = 1; |
30 | 44 |
|
31 | | - for (;;) |
| 45 | + // Run tests... |
| 46 | + while (count > 0) |
32 | 47 | { |
| 48 | + testBegin("cupsGetDests"); |
33 | 49 | gettimeofday(&start, NULL); |
34 | 50 | num_dests = cupsGetDests(CUPS_HTTP_DEFAULT, &dests); |
35 | 51 | gettimeofday(&end, NULL); |
36 | 52 | secs = end.tv_sec - start.tv_sec + 0.000001 * (end.tv_usec - start.tv_usec); |
37 | 53 |
|
38 | | - printf("Found %d printers in %.3f seconds...\n", num_dests, secs); |
| 54 | + testEndMessage(secs < 2.0, "%u printers in %.3f seconds", (unsigned)num_dests, secs); |
39 | 55 |
|
40 | 56 | cupsFreeDests(num_dests, dests); |
41 | | - sleep(1); |
| 57 | + |
| 58 | + count --; |
| 59 | + |
| 60 | + if (count > 0) |
| 61 | + sleep(1); |
42 | 62 | } |
43 | 63 |
|
44 | 64 | return (0); |
|
0 commit comments