Skip to content

Commit 8f44495

Browse files
committed
Implement countdown for testgetdests (Issue #33)
1 parent 0532190 commit 8f44495

2 files changed

Lines changed: 46 additions & 24 deletions

File tree

cups/Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,8 @@ test: $(UNITTARGETS)
180180
# fi
181181
echo Running file API tests...
182182
./testfile 2>>test.log
183+
echo Running cupsGetDests API tests...
184+
./testgetdests 2>>test.log
183185
echo Running HTTP API tests...
184186
./testhttp 2>>test.log
185187
echo Running IPP API tests...

cups/testgetdests.c

Lines changed: 44 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,64 @@
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+
//
1210

1311
#include <stdio.h>
14-
#include "cups.h"
12+
#include <stdlib.h>
1513
#include <sys/time.h>
14+
#include "cups.h"
15+
#include "test-internal.h"
1616

1717

18-
/*
19-
* 'main()' - Loop calling cupsGetDests.
20-
*/
18+
//
19+
// 'main()' - Loop calling cupsGetDests.
20+
//
2121

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
2425
{
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+
}
2939

40+
if (argc == 2)
41+
count = strtoul(argv[1], NULL, 10);
42+
else
43+
count = 1;
3044

31-
for (;;)
45+
// Run tests...
46+
while (count > 0)
3247
{
48+
testBegin("cupsGetDests");
3349
gettimeofday(&start, NULL);
3450
num_dests = cupsGetDests(CUPS_HTTP_DEFAULT, &dests);
3551
gettimeofday(&end, NULL);
3652
secs = end.tv_sec - start.tv_sec + 0.000001 * (end.tv_usec - start.tv_usec);
3753

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);
3955

4056
cupsFreeDests(num_dests, dests);
41-
sleep(1);
57+
58+
count --;
59+
60+
if (count > 0)
61+
sleep(1);
4262
}
4363

4464
return (0);

0 commit comments

Comments
 (0)