blob: a924b0bee6889067601d18934fe0c05da4a7116c (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
/* file : tests/conninfo/driver.c
* license : PostgreSQL License; see accompanying COPYRIGHT file
*/
/* Include the upstream package test and rename it's main() function to test()
* (see below for details).
*/
#define main test
#include <uri-regress.c>
#undef main
/* Enable assertions.
*/
#ifdef NDEBUG
# undef NDEBUG
#endif
#include <stdio.h>
#include <assert.h>
#include <string.h> /* strlen() */
/* Usage: argv[0]
*
* Read connection info strings from STDIN and call upstream test main()
* function for each of them. The function prints the parsed connection info to
* stdout on success or error message to stderr on failure.
*/
int
main (int argc, char* argv[])
{
assert (argc == 1);
char s[1024];
while (fgets (s, sizeof(s), stdin) != NULL)
{
/* Print the conninfo string that will be tested.
*/
printf ("trying %s", s);
/* Strip the newline character and make sure it is printed to stdout.
*/
size_t n = strlen (s);
if (n != 0 && s[n - 1] == '\n')
s[n - 1] = '\0';
else
printf ("\n");
/* Make sure the output make sense if stderr is redirected to stdout (and
* vice versa).
*/
fflush (stdout);
/* Run the test.
*
* Note that we need to print the trailing newline character ourselves.
*/
char* args[] = {argv[0], s, NULL};
int r = test (2, args);
fprintf (r == 0 ? stdout : stderr, "\n");
fflush (r == 0 ? stdout : stderr);
}
return 0;
}
|