| 1 | // Copyright (C) 2015-2025 Free Software Foundation, Inc. |
| 2 | // |
| 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) |
| 7 | // any later version. |
| 8 | |
| 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. |
| 13 | |
| 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/>. |
| 17 | |
| 18 | // { dg-do run { target c++14 } } |
| 19 | |
| 20 | #include <experimental/buffer> |
| 21 | #include <testsuite_hooks.h> |
| 22 | |
| 23 | using std::experimental::net::const_buffer; |
| 24 | using std::experimental::net::mutable_buffer; |
| 25 | |
| 26 | void |
| 27 | test01() |
| 28 | { |
| 29 | using B = const_buffer; |
| 30 | const B b; |
| 31 | |
| 32 | static_assert( std::is_nothrow_default_constructible<B>::value, |
| 33 | "const_mutable is nothrow default constructible" ); |
| 34 | static_assert( std::is_copy_assignable<B>::value, |
| 35 | "const_mutable is copy assignable" ); |
| 36 | static_assert( std::is_nothrow_constructible<B, const void*, size_t>::value, |
| 37 | "const_mutable is nothrow constructible from pointer and length" ); |
| 38 | static_assert( std::is_nothrow_constructible<B, mutable_buffer>::value, |
| 39 | "const_mutable is nothrow constructible from mutable_buffer" ); |
| 40 | static_assert( std::is_same<decltype(b.data()), const void*>::value, |
| 41 | "data() return const void*" ); |
| 42 | static_assert( noexcept(b.data()), |
| 43 | "data() is nothrow" ); |
| 44 | static_assert( std::is_same<decltype(b.size()), size_t>::value, |
| 45 | "size() return size_t" ); |
| 46 | static_assert( noexcept(b.size()), |
| 47 | "size() is nothrow" ); |
| 48 | } |
| 49 | |
| 50 | void |
| 51 | test02() |
| 52 | { |
| 53 | bool test __attribute__((unused)) = false; |
| 54 | char c[4]; |
| 55 | |
| 56 | const_buffer b; |
| 57 | VERIFY( b.data() == nullptr ); |
| 58 | VERIFY( b.size() == 0 ); |
| 59 | |
| 60 | b = const_buffer(c, sizeof(c)); |
| 61 | VERIFY( b.data() == c ); |
| 62 | VERIFY( b.size() == sizeof(c) ); |
| 63 | |
| 64 | b = const_buffer{}; |
| 65 | VERIFY( b.data() == nullptr ); |
| 66 | VERIFY( b.size() == 0 ); |
| 67 | } |
| 68 | |
| 69 | int |
| 70 | main() |
| 71 | { |
| 72 | test01(); |
| 73 | test02(); |
| 74 | } |