]>
git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/experimental/net/internet/address/v4/creation.cc
1 // Copyright (C) 2015-2019 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-add-options net_ts }
21 #include <experimental/internet>
22 #include <testsuite_hooks.h>
24 namespace net
= std::experimental::net
;
25 using net::ip::address_v4
;
30 bool test
__attribute__((unused
)) = false;
32 auto a0
= make_address_v4( address_v4::bytes_type
{} );
33 VERIFY( a0
.to_uint() == 0 );
34 VERIFY( a0
.to_bytes() == address_v4::bytes_type
{} );
36 address_v4::bytes_type b1
{ 1, 2, 3, 4 };
37 auto a1
= make_address_v4( b1
);
38 VERIFY( a1
.to_uint() == ntohl((1 << 24) | (2 << 16) | (3 << 8) | 4) );
39 VERIFY( a1
.to_bytes() == b1
);
45 bool test
__attribute__((unused
)) = false;
47 auto a0
= net::ip::make_address_v4(0u);
48 VERIFY( a0
.to_uint() == 0 );
49 VERIFY( a0
.to_bytes() == address_v4::bytes_type
{} );
51 address_v4::uint_type u1
= ntohl((5 << 24) | (6 << 16) | (7 << 8) | 8);
52 auto a1
= net::ip::make_address_v4( u1
);
53 VERIFY( a1
.to_uint() == u1
);
54 VERIFY( a1
.to_bytes() == address_v4::bytes_type( 5, 6, 7, 8 ) );
60 bool test
__attribute__((unused
)) = false;
62 auto a1
= net::ip::make_address_v4("127.0.0.1");
63 VERIFY( a1
.is_loopback() );
64 auto a2
= net::ip::make_address_v4(std::string
{"127.0.0.2"});
65 VERIFY( a2
.is_loopback() );
66 auto a3
= net::ip::make_address_v4(std::experimental::string_view
{"127.0.0.3"});
67 VERIFY( a3
.is_loopback() );
70 auto a4
= net::ip::make_address_v4("127...1", ec
);
71 VERIFY( ec
== std::errc::invalid_argument
);
73 net::ip::make_address_v4("127.0.0.1", ec
);
76 a4
= net::ip::make_address_v4(std::string
{"256.0.0.1"}, ec
);
77 VERIFY( ec
== std::errc::invalid_argument
);
79 net::ip::make_address_v4(std::string
{"127.0.0.1"}, ec
);
82 a4
= net::ip::make_address_v4(std::experimental::string_view
{""}, ec
);
83 VERIFY( ec
== std::errc::invalid_argument
);