1 /* Test continue and merge NSS actions for getaddrinfo.
2 Copyright The GNU Toolchain Authors.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <https://www.gnu.org/licenses/>. */
20 #include <gnu/lib-names.h>
26 #include <support/check.h>
27 #include <support/format_nss.h>
28 #include <support/support.h>
29 #include <support/xstdio.h>
30 #include <support/xunistd.h>
39 family_str (int family
)
48 __builtin_unreachable ();
53 action_str (int action
)
62 __builtin_unreachable ();
67 do_one_test (int action
, int family
, bool canon
)
69 struct addrinfo hints
=
77 hints
.ai_flags
= AI_CANONNAME
;
79 printf ("***** Testing \"files [SUCCESS=%s] files\" for family %s, %s\n",
80 action_str (action
), family_str (family
),
81 canon
? "AI_CANONNAME" : "");
83 int ret
= getaddrinfo ("example.org", "80", &hints
, &ai
);
90 char *formatted
= support_format_addrinfo (ai
, ret
);
92 printf ("merge unexpectedly succeeded:\n %s\n", formatted
);
93 support_record_failure ();
101 char *formatted
= support_format_addrinfo (ai
, ret
);
103 /* Verify that the result appears exactly once. */
104 const char *expected
= "address: STREAM/TCP 192.0.0.1 80\n"
105 "address: DGRAM/UDP 192.0.0.1 80\n"
106 "address: RAW/IP 192.0.0.1 80\n";
108 const char *contains
= strstr (formatted
, expected
);
109 const char *contains2
= NULL
;
111 if (contains
!= NULL
)
112 contains2
= strstr (contains
+ strlen (expected
), expected
);
114 if (contains
== NULL
|| contains2
!= NULL
)
116 printf ("continue failed:\n%s\n", formatted
);
117 support_record_failure ();
124 __builtin_unreachable ();
129 do_one_test_set (int action
)
133 snprintf (buf
, sizeof (buf
), "files [SUCCESS=%s] files",
134 action_str (action
));
135 __nss_configure_lookup ("hosts", buf
);
137 do_one_test (action
, AF_UNSPEC
, false);
138 do_one_test (action
, AF_INET
, false);
139 do_one_test (action
, AF_INET
, true);
145 do_one_test_set (ACTION_CONTINUE
);
146 do_one_test_set (ACTION_MERGE
);
150 #include <support/test-driver.c>