]>
Commit | Line | Data |
---|---|---|
713c16f8 BK |
1 | // 2000-12-19 bkoz |
2 | ||
818ab71a | 3 | // Copyright (C) 2000-2016 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 | |
29 | // { dg-skip-if "" { *-*-darwin* && lp64 } { "*" } { "" } } | |
30 | ||
34a2b755 JW |
31 | // The library still throws the original definition of std::ios::failure |
32 | // { dg-options "-D_GLIBCXX_USE_CXX11_ABI=0" } | |
33 | ||
713c16f8 BK |
34 | #include <sstream> |
35 | #include <iostream> | |
6725add5 | 36 | #include <limits> |
fe413112 | 37 | #include <testsuite_hooks.h> |
713c16f8 | 38 | |
663653eb BK |
39 | // libstdc++/3129 |
40 | void test02() | |
41 | { | |
fd0bf20c | 42 | bool test = true; |
d02475fd | 43 | int max = std::numeric_limits<int>::max() - 1; |
663653eb BK |
44 | std::stringbuf strbuf; |
45 | std::ios ios(&strbuf); | |
46 | ||
a9aa7083 JQ |
47 | ios.exceptions(std::ios::badbit); |
48 | ||
663653eb BK |
49 | long l = 0; |
50 | void* v = 0; | |
51 | ||
52 | // pword | |
a9aa7083 JQ |
53 | ios.pword(1) = v; |
54 | VERIFY( ios.pword(1) == v ); | |
55 | ||
663653eb BK |
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 | { | |
fd0bf20c | 67 | VERIFY( false ); |
663653eb BK |
68 | } |
69 | VERIFY( v == 0 ); | |
70 | ||
a9aa7083 JQ |
71 | VERIFY( ios.pword(1) == v ); |
72 | ||
73 | // max is different code path from max-1 | |
74 | v = &test; | |
fd0bf20c | 75 | try |
a9aa7083 JQ |
76 | { |
77 | v = ios.pword(std::numeric_limits<int>::max()); | |
78 | } | |
79 | catch(std::ios_base::failure& obj) | |
80 | { | |
81 | // Ok. | |
82 | VERIFY( ios.bad() ); | |
83 | } | |
84 | catch(...) | |
85 | { | |
fd0bf20c | 86 | VERIFY( false ); |
a9aa7083 JQ |
87 | } |
88 | VERIFY( v == &test ); | |
89 | ||
663653eb | 90 | // iword |
a9aa7083 JQ |
91 | ios.iword(1) = 1; |
92 | VERIFY( ios.iword(1) == 1 ); | |
93 | ||
663653eb BK |
94 | try |
95 | { | |
96 | l = ios.iword(max); | |
97 | } | |
98 | catch(std::ios_base::failure& obj) | |
99 | { | |
100 | // Ok. | |
101 | VERIFY( ios.bad() ); | |
102 | } | |
103 | catch(...) | |
104 | { | |
fd0bf20c | 105 | VERIFY( false ); |
663653eb BK |
106 | } |
107 | VERIFY( l == 0 ); | |
a9aa7083 JQ |
108 | |
109 | VERIFY( ios.iword(1) == 1 ); | |
110 | ||
111 | // max is different code path from max-1 | |
112 | l = 1; | |
113 | try | |
114 | { | |
115 | l = ios.iword(std::numeric_limits<int>::max()); | |
116 | } | |
117 | catch(std::ios_base::failure& obj) | |
118 | { | |
119 | // Ok. | |
120 | VERIFY( ios.bad() ); | |
121 | } | |
122 | catch(...) | |
123 | { | |
fd0bf20c | 124 | VERIFY( false ); |
a9aa7083 JQ |
125 | } |
126 | VERIFY( l == 1 ); | |
663653eb | 127 | } |
713c16f8 BK |
128 | |
129 | int main(void) | |
130 | { | |
aecf642c | 131 | __gnu_test::set_memory_limits(); |
663653eb | 132 | test02(); |
713c16f8 BK |
133 | return 0; |
134 | } |