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 ();
100 char *formatted
= support_format_addrinfo (ai
, ret
);
102 /* Verify that the result appears exactly once. */
103 const char *expected
= "address: STREAM/TCP 192.0.0.1 80\n"
104 "address: DGRAM/UDP 192.0.0.1 80\n"
105 "address: RAW/IP 192.0.0.1 80\n";
107 const char *contains
= strstr (formatted
, expected
);
108 const char *contains2
= NULL
;
110 if (contains
!= NULL
)
111 contains2
= strstr (contains
+ strlen (expected
), expected
);
113 if (contains
== NULL
|| contains2
!= NULL
)
115 printf ("continue failed:\n%s\n", formatted
);
116 support_record_failure ();
123 __builtin_unreachable ();
128 do_one_test_set (int action
)
132 snprintf (buf
, sizeof (buf
), "files [SUCCESS=%s] files",
133 action_str (action
));
134 __nss_configure_lookup ("hosts", buf
);
136 do_one_test (action
, AF_UNSPEC
, false);
137 do_one_test (action
, AF_INET
, false);
138 do_one_test (action
, AF_INET
, true);
144 do_one_test_set (ACTION_CONTINUE
);
145 do_one_test_set (ACTION_MERGE
);
149 #include <support/test-driver.c>