]> 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
3fcfcab5 1// 2000-12-19 bkoz
2
d353bf18 3// Copyright (C) 2000-2015 Free Software Foundation, Inc.
3fcfcab5 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
6bc9506f 8// Free Software Foundation; either version 3, or (at your option)
3fcfcab5 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
6bc9506f 17// with this library; see the file COPYING3. If not see
18// <http://www.gnu.org/licenses/>.
3fcfcab5 19
20// 27.4.2.5 ios_base storage functions
21
59a4f683 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].* } }
7f5767ec 25
725c6dd9 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
29// { dg-skip-if "" { *-*-darwin* && lp64 } { "*" } { "" } }
30
63f54259 31// The library still throws the original definition of std::ios::failure
32// { dg-options "-D_GLIBCXX_USE_CXX11_ABI=0" }
33
3fcfcab5 34#include <sstream>
35#include <iostream>
ee620c0d 36#include <limits>
0194306c 37#include <testsuite_hooks.h>
3fcfcab5 38
93218b6c 39// libstdc++/3129
40void test02()
41{
f8ef786c 42 bool test __attribute__((unused)) = true;
a0654d3e 43 int max = std::numeric_limits<int>::max() - 1;
93218b6c 44 std::stringbuf strbuf;
45 std::ios ios(&strbuf);
46
d1a218b7 47 ios.exceptions(std::ios::badbit);
48
93218b6c 49 long l = 0;
50 void* v = 0;
51
52 // pword
d1a218b7 53 ios.pword(1) = v;
54 VERIFY( ios.pword(1) == v );
55
93218b6c 56 try
57 {
58 v = ios.pword(max);
59 }
60 catch(std::ios_base::failure& obj)
61 {
62 // Ok.
63 VERIFY( ios.bad() );
64 }
65 catch(...)
66 {
f633413e 67 test = false;
68 VERIFY( test );
93218b6c 69 }
70 VERIFY( v == 0 );
71
d1a218b7 72 VERIFY( ios.pword(1) == v );
73
74 // max is different code path from max-1
75 v = &test;
76 try
77 {
78 v = ios.pword(std::numeric_limits<int>::max());
79 }
80 catch(std::ios_base::failure& obj)
81 {
82 // Ok.
83 VERIFY( ios.bad() );
84 }
85 catch(...)
86 {
f633413e 87 test = false;
88 VERIFY( test );
d1a218b7 89 }
90 VERIFY( v == &test );
91
93218b6c 92 // iword
d1a218b7 93 ios.iword(1) = 1;
94 VERIFY( ios.iword(1) == 1 );
95
93218b6c 96 try
97 {
98 l = ios.iword(max);
99 }
100 catch(std::ios_base::failure& obj)
101 {
102 // Ok.
103 VERIFY( ios.bad() );
104 }
105 catch(...)
106 {
f633413e 107 test = false;
108 VERIFY( test );
93218b6c 109 }
110 VERIFY( l == 0 );
d1a218b7 111
112 VERIFY( ios.iword(1) == 1 );
113
114 // max is different code path from max-1
115 l = 1;
116 try
117 {
118 l = ios.iword(std::numeric_limits<int>::max());
119 }
120 catch(std::ios_base::failure& obj)
121 {
122 // Ok.
123 VERIFY( ios.bad() );
124 }
125 catch(...)
126 {
f633413e 127 test = false;
128 VERIFY( test );
d1a218b7 129 }
130 VERIFY( l == 1 );
131
93218b6c 132}
3fcfcab5 133
134int main(void)
135{
56dcf3cc 136 __gnu_test::set_memory_limits();
93218b6c 137 test02();
3fcfcab5 138 return 0;
139}