summaryrefslogtreecommitdiff
path: root/libstdc++-v3/testsuite/experimental/net/buffer/arithmetic.cc
blob: 861afa83e4646e694a88a1d60305a46ff82091bb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
// Copyright (C) 2015-2018 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library.  This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 3, or (at your option)
// any later version.

// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License along
// with this library; see the file COPYING3.  If not see
// <http://www.gnu.org/licenses/>.

// { dg-do run { target c++14 } }

#include <experimental/buffer>
#include <testsuite_hooks.h>

using std::experimental::net::mutable_buffer;
using std::experimental::net::const_buffer;

void
test01()
{
  bool test __attribute__((unused)) = false;
  char c[4];

  mutable_buffer mb;
  mb = mb + 0;
  VERIFY( mb.data() == nullptr );
  VERIFY( mb.size() == 0 );

  mb = 0 + mb;
  VERIFY( mb.data() == nullptr );
  VERIFY( mb.size() == 0 );

  mb = mutable_buffer(c, sizeof(c));
  mb = mb + 1;
  VERIFY( mb.data() == c+1 );
  VERIFY( mb.size() == 3 );

  mb = mb + 2;
  VERIFY( mb.data() == c+3 );
  VERIFY( mb.size() == 1 );

  mb = mb + 2;
  VERIFY( mb.data() == c+4 );
  VERIFY( mb.size() == 0 );

  mb = mutable_buffer(c, sizeof(c));
  mb = 3 + mb;
  VERIFY( mb.data() == c+3 );
  VERIFY( mb.size() == 1 );

  mb = 2 + mb;
  VERIFY( mb.data() == c+4 );
  VERIFY( mb.size() == 0 );
}

void
test02()
{
  bool test __attribute__((unused)) = false;
  char c[4];

  const_buffer cb;
  cb = cb + 0;
  VERIFY( cb.data() == nullptr );
  VERIFY( cb.size() == 0 );

  cb = 0 + cb;
  VERIFY( cb.data() == nullptr );
  VERIFY( cb.size() == 0 );

  cb = const_buffer(c, sizeof(c));
  cb = cb + 1;
  VERIFY( cb.data() == c+1 );
  VERIFY( cb.size() == 3 );

  cb = cb + 2;
  VERIFY( cb.data() == c+3 );
  VERIFY( cb.size() == 1 );

  cb = cb + 2;
  VERIFY( cb.data() == c+4 );
  VERIFY( cb.size() == 0 );

  cb = const_buffer(c, sizeof(c));
  cb = 3 + cb;
  VERIFY( cb.data() == c+3 );
  VERIFY( cb.size() == 1 );

  cb = 2 + cb;
  VERIFY( cb.data() == c+4 );
  VERIFY( cb.size() == 0 );
}

int
main()
{
  test01();
  test02();
}