| 1 | // { dg-do run { target c++14 } } |
| 2 | // { dg-require-effective-target net_ts_ip } |
| 3 | // { dg-add-options net_ts } |
| 4 | |
| 5 | #include <experimental/internet> |
| 6 | #include <cstring> |
| 7 | #include <testsuite_hooks.h> |
| 8 | |
| 9 | using namespace std::experimental::net; |
| 10 | |
| 11 | void |
| 12 | test_extensible() |
| 13 | { |
| 14 | #if __cplusplus >= 202002L |
| 15 | static_assert(ip::tcp::endpoint().capacity() == sizeof(sockaddr_in6), |
| 16 | "ip::tcp::endpoint::capacity() can store a sockaddr_in6"); |
| 17 | #else |
| 18 | VERIFY( ip::tcp::endpoint().capacity() == sizeof(sockaddr_in6) ); |
| 19 | #endif |
| 20 | |
| 21 | ip::tcp::endpoint t1(ip::tcp::v4(), 22); |
| 22 | VERIFY(t1.size() == sizeof(sockaddr_in)); |
| 23 | t1.resize(sizeof(sockaddr_in)); |
| 24 | try { |
| 25 | t1.resize(2 * sizeof(sockaddr_in)); |
| 26 | VERIFY(false); |
| 27 | } catch (const std::length_error&) { |
| 28 | } |
| 29 | |
| 30 | ip::tcp::endpoint t2(ip::tcp::v6(), 80); |
| 31 | VERIFY(t2.size() == sizeof(sockaddr_in6)); |
| 32 | t2.resize(sizeof(sockaddr_in6)); |
| 33 | try { |
| 34 | t2.resize(2 * sizeof(sockaddr_in6)); |
| 35 | VERIFY(false); |
| 36 | } catch (const std::length_error&) { |
| 37 | } |
| 38 | |
| 39 | ip::tcp::endpoint t3; |
| 40 | std::memcpy(t3.data(), t1.data(), t1.size()); |
| 41 | t3.resize(t1.size()); |
| 42 | VERIFY( t3 == t1 ); |
| 43 | std::memcpy(t3.data(), t2.data(), t2.size()); |
| 44 | t3.resize(t2.size()); |
| 45 | VERIFY( t3 == t2 ); |
| 46 | } |
| 47 | |
| 48 | int main() |
| 49 | { |
| 50 | test_extensible(); |
| 51 | } |