]>
git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/experimental/net/internet/resolver/ops/lookup.cc
1 // Copyright (C) 2015-2024 Free Software Foundation, Inc.
3 // This file is part of the GNU ISO C++ Library. This library is free
4 // software; you can redistribute it and/or modify it under the
5 // terms of the GNU General Public License as published by the
6 // Free Software Foundation; either version 3, or (at your option)
9 // This library is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License along
15 // with this library; see the file COPYING3. If not see
16 // <http://www.gnu.org/licenses/>.
18 // { dg-do run { target c++14 } }
19 // { dg-require-effective-target net_ts_ip }
20 // { dg-add-options net_ts }
21 // { dg-xfail-run-if "io_context requires a working pipe" { *-*-rtems* } }
23 #include <experimental/internet>
24 #include <testsuite_hooks.h>
26 using namespace std::experimental::net
;
33 ip::tcp::resolver
resolv(ctx
);
34 auto hostname
= "localhost", service
= "http";
35 auto addrs
= resolv
.resolve(hostname
, service
, ec
);
36 if (ec
== ip::resolver_errc::service_not_found
)
38 // Solaris doesn't have http in /etc/services, try some others.
39 for (auto serv
: {"ftp", "telnet", "smtp"})
41 addrs
= resolv
.resolve(hostname
, serv
, ec
);
50 VERIFY( addrs
.size() > 0 );
51 VERIFY( addrs
.begin() != addrs
.end() );
52 VERIFY( ! addrs
.empty() );
54 auto addrs2
= resolv
.resolve(hostname
, service
);
55 VERIFY( addrs
== addrs2
);
63 ip::tcp::resolver
resolv(ctx
);
64 auto flags
= ip::resolver_base::numeric_host
;
66 flags
|= ip::tcp::resolver::numeric_service
;
68 auto addrs
= resolv
.resolve("127.0.0.1", "42", flags
, ec
);
70 VERIFY( addrs
.size() > 0 );
71 VERIFY( addrs
.begin() != addrs
.end() );
73 auto addrs2
= resolv
.resolve("127.0.0.1", "42", flags
);
74 VERIFY( addrs
== addrs2
);
76 addrs
= resolv
.resolve("localhost", "42", flags
, ec
);
78 VERIFY( addrs
.empty() );
79 addrs
= resolv
.resolve("127.0.0.1", "nameserver", flags
, ec
);
81 VERIFY( addrs
.empty() );
86 resolv
.resolve("localhost", "42", flags
);
87 } catch (const std::system_error
& e
) {
89 VERIFY( e
.code() == ec
);
100 ip::tcp::resolver
resolv(ctx
);
101 auto addrs
= resolv
.resolve("test.invalid.", "http", ec
);
103 VERIFY( addrs
.size() == 0 );
104 VERIFY( addrs
.begin() == addrs
.end() );
105 VERIFY( addrs
.empty() );
109 resolv
.resolve("test.invalid.", "http");
110 } catch (const std::system_error
& e
) {
112 VERIFY( e
.code() == ec
);