]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/testsuite/experimental/net/buffer/arithmetic.cc
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / experimental / net / buffer / arithmetic.cc
CommitLineData
a5544970 1// Copyright (C) 2015-2019 Free Software Foundation, Inc.
e5989e71
JW
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
7e8b87e9 18// { dg-do run { target c++14 } }
e5989e71
JW
19
20#include <experimental/buffer>
21#include <testsuite_hooks.h>
22
23using std::experimental::net::mutable_buffer;
24using std::experimental::net::const_buffer;
25
26void
27test01()
28{
29 bool test __attribute__((unused)) = false;
30 char c[4];
31
32 mutable_buffer mb;
33 mb = mb + 0;
34 VERIFY( mb.data() == nullptr );
35 VERIFY( mb.size() == 0 );
36
37 mb = 0 + mb;
38 VERIFY( mb.data() == nullptr );
39 VERIFY( mb.size() == 0 );
40
41 mb = mutable_buffer(c, sizeof(c));
42 mb = mb + 1;
43 VERIFY( mb.data() == c+1 );
44 VERIFY( mb.size() == 3 );
45
46 mb = mb + 2;
47 VERIFY( mb.data() == c+3 );
48 VERIFY( mb.size() == 1 );
49
50 mb = mb + 2;
51 VERIFY( mb.data() == c+4 );
52 VERIFY( mb.size() == 0 );
53
54 mb = mutable_buffer(c, sizeof(c));
55 mb = 3 + mb;
56 VERIFY( mb.data() == c+3 );
57 VERIFY( mb.size() == 1 );
58
59 mb = 2 + mb;
60 VERIFY( mb.data() == c+4 );
61 VERIFY( mb.size() == 0 );
62}
63
64void
65test02()
66{
67 bool test __attribute__((unused)) = false;
68 char c[4];
69
70 const_buffer cb;
71 cb = cb + 0;
72 VERIFY( cb.data() == nullptr );
73 VERIFY( cb.size() == 0 );
74
75 cb = 0 + cb;
76 VERIFY( cb.data() == nullptr );
77 VERIFY( cb.size() == 0 );
78
79 cb = const_buffer(c, sizeof(c));
80 cb = cb + 1;
81 VERIFY( cb.data() == c+1 );
82 VERIFY( cb.size() == 3 );
83
84 cb = cb + 2;
85 VERIFY( cb.data() == c+3 );
86 VERIFY( cb.size() == 1 );
87
88 cb = cb + 2;
89 VERIFY( cb.data() == c+4 );
90 VERIFY( cb.size() == 0 );
91
92 cb = const_buffer(c, sizeof(c));
93 cb = 3 + cb;
94 VERIFY( cb.data() == c+3 );
95 VERIFY( cb.size() == 1 );
96
97 cb = 2 + cb;
98 VERIFY( cb.data() == c+4 );
99 VERIFY( cb.size() == 0 );
100}
101
102int
103main()
104{
105 test01();
106 test02();
107}