Merged revisions 143552,143554,143557,143560,143562,143564-143567,143570-143573,14357...
[official-gcc.git] / libstdc++-v3 / testsuite / 27_io / ios_base / storage / 2.cc
blobbe4cf8d1161a24dd78aea21f29f30279b82b91a3
1 // 2000-12-19 bkoz
3 // Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007
4 // Free Software Foundation
5 //
6 // This file is part of the GNU ISO C++ Library. This library is free
7 // software; you can redistribute it and/or modify it under the
8 // terms of the GNU General Public License as published by the
9 // Free Software Foundation; either version 2, or (at your option)
10 // any later version.
12 // This library is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
17 // You should have received a copy of the GNU General Public License along
18 // with this library; see the file COPYING. If not, write to the Free
19 // Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
20 // USA.
22 // 27.4.2.5 ios_base storage functions
24 // XXX This test will not work for some versions of irix6 because of
25 // XXX bug(s) in libc malloc for very large allocations. However
26 // XXX -lmalloc seems to work.
27 // See http://gcc.gnu.org/ml/gcc/2002-05/msg01012.html
28 // { dg-options "-lmalloc" { target mips*-*-irix6* } }
30 // This fails on some versions of Darwin 8 because malloc doesn't return
31 // NULL even if an allocation fails (filed as Radar 3884894).
32 // { dg-do run { xfail *-*-darwin8.[0-4].* } }
34 // Skip test at -m64 on Darwin because RLIMITS are not being honored.
35 // Radar 6467883: 10.4/10.5 setrlimits are not honored by memory allocators
36 // Radar 6467884: 10.X systems are not robust when paging space is exceeded
37 // { dg-skip-if "" { *-*-darwin* && lp64 } { "*" } { "" } }
39 #include <sstream>
40 #include <iostream>
41 #include <limits>
42 #include <testsuite_hooks.h>
44 // libstdc++/3129
45 void test02()
47 bool test __attribute__((unused)) = true;
48 int max = std::numeric_limits<int>::max() - 1;
49 std::stringbuf strbuf;
50 std::ios ios(&strbuf);
52 ios.exceptions(std::ios::badbit);
54 long l = 0;
55 void* v = 0;
57 // pword
58 ios.pword(1) = v;
59 VERIFY( ios.pword(1) == v );
61 try
63 v = ios.pword(max);
65 catch(std::ios_base::failure& obj)
67 // Ok.
68 VERIFY( ios.bad() );
70 catch(...)
72 test = false;
73 VERIFY( test );
75 VERIFY( v == 0 );
77 VERIFY( ios.pword(1) == v );
79 // max is different code path from max-1
80 v = &test;
81 try
83 v = ios.pword(std::numeric_limits<int>::max());
85 catch(std::ios_base::failure& obj)
87 // Ok.
88 VERIFY( ios.bad() );
90 catch(...)
92 test = false;
93 VERIFY( test );
95 VERIFY( v == &test );
97 // iword
98 ios.iword(1) = 1;
99 VERIFY( ios.iword(1) == 1 );
101 try
103 l = ios.iword(max);
105 catch(std::ios_base::failure& obj)
107 // Ok.
108 VERIFY( ios.bad() );
110 catch(...)
112 test = false;
113 VERIFY( test );
115 VERIFY( l == 0 );
117 VERIFY( ios.iword(1) == 1 );
119 // max is different code path from max-1
120 l = 1;
121 try
123 l = ios.iword(std::numeric_limits<int>::max());
125 catch(std::ios_base::failure& obj)
127 // Ok.
128 VERIFY( ios.bad() );
130 catch(...)
132 test = false;
133 VERIFY( test );
135 VERIFY( l == 1 );
139 int main(void)
141 __gnu_test::set_memory_limits();
142 test02();
143 return 0;