]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/testsuite/27_io/ios_base/storage/2.cc
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 27_io / ios_base / storage / 2.cc
CommitLineData
713c16f8
BK
1// 2000-12-19 bkoz
2
8d9254fc 3// Copyright (C) 2000-2020 Free Software Foundation, Inc.
713c16f8
BK
4//
5// This file is part of the GNU ISO C++ Library. This library is free
6// software; you can redistribute it and/or modify it under the
7// terms of the GNU General Public License as published by the
748086b7 8// Free Software Foundation; either version 3, or (at your option)
713c16f8
BK
9// any later version.
10
11// This library is distributed in the hope that it will be useful,
12// but WITHOUT ANY WARRANTY; without even the implied warranty of
13// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14// GNU General Public License for more details.
15
16// You should have received a copy of the GNU General Public License along
748086b7
JJ
17// with this library; see the file COPYING3. If not see
18// <http://www.gnu.org/licenses/>.
713c16f8
BK
19
20// 27.4.2.5 ios_base storage functions
21
58e93a26
BK
22// This fails on some versions of Darwin 8 because malloc doesn't return
23// NULL even if an allocation fails (filed as Radar 3884894).
24// { dg-do run { xfail *-*-darwin8.[0-4].* } }
58c3ef5c 25
9a3b094f
JH
26// Skip test at -m64 on Darwin because RLIMITS are not being honored.
27// Radar 6467883: 10.4/10.5 setrlimits are not honored by memory allocators
28// Radar 6467884: 10.X systems are not robust when paging space is exceeded
4f4b0ab8 29// { dg-skip-if "" { *-*-darwin* && lp64 } }
10613537 30
713c16f8
BK
31#include <sstream>
32#include <iostream>
6725add5 33#include <limits>
fe413112 34#include <testsuite_hooks.h>
713c16f8 35
663653eb
BK
36// libstdc++/3129
37void test02()
38{
fd0bf20c 39 bool test = true;
d02475fd 40 int max = std::numeric_limits<int>::max() - 1;
663653eb
BK
41 std::stringbuf strbuf;
42 std::ios ios(&strbuf);
43
a9aa7083
JQ
44 ios.exceptions(std::ios::badbit);
45
663653eb
BK
46 long l = 0;
47 void* v = 0;
48
49 // pword
a9aa7083
JQ
50 ios.pword(1) = v;
51 VERIFY( ios.pword(1) == v );
cdd17d6e 52
cdd17d6e 53 try
663653eb
BK
54 {
55 v = ios.pword(max);
56 }
5f302518 57 catch(std::ios_base::failure&)
663653eb
BK
58 {
59 // Ok.
60 VERIFY( ios.bad() );
61 }
62 catch(...)
63 {
fd0bf20c 64 VERIFY( false );
663653eb
BK
65 }
66 VERIFY( v == 0 );
67
a9aa7083 68 VERIFY( ios.pword(1) == v );
cdd17d6e 69
a9aa7083
JQ
70 // max is different code path from max-1
71 v = &test;
fd0bf20c 72 try
a9aa7083
JQ
73 {
74 v = ios.pword(std::numeric_limits<int>::max());
75 }
5f302518 76 catch(std::ios_base::failure&)
a9aa7083
JQ
77 {
78 // Ok.
79 VERIFY( ios.bad() );
80 }
81 catch(...)
82 {
fd0bf20c 83 VERIFY( false );
a9aa7083
JQ
84 }
85 VERIFY( v == &test );
86
663653eb 87 // iword
a9aa7083
JQ
88 ios.iword(1) = 1;
89 VERIFY( ios.iword(1) == 1 );
cdd17d6e
JW
90
91 try
663653eb
BK
92 {
93 l = ios.iword(max);
94 }
5f302518 95 catch(std::ios_base::failure&)
663653eb
BK
96 {
97 // Ok.
98 VERIFY( ios.bad() );
99 }
100 catch(...)
101 {
fd0bf20c 102 VERIFY( false );
663653eb
BK
103 }
104 VERIFY( l == 0 );
a9aa7083
JQ
105
106 VERIFY( ios.iword(1) == 1 );
107
108 // max is different code path from max-1
109 l = 1;
cdd17d6e 110 try
a9aa7083
JQ
111 {
112 l = ios.iword(std::numeric_limits<int>::max());
113 }
5f302518 114 catch(std::ios_base::failure&)
a9aa7083
JQ
115 {
116 // Ok.
117 VERIFY( ios.bad() );
118 }
119 catch(...)
120 {
fd0bf20c 121 VERIFY( false );
a9aa7083
JQ
122 }
123 VERIFY( l == 1 );
663653eb 124}
713c16f8
BK
125
126int main(void)
127{
aecf642c 128 __gnu_test::set_memory_limits();
663653eb 129 test02();
713c16f8
BK
130 return 0;
131}