]> git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/27_io/basic_istream/sentry/pod/1.cc
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 27_io / basic_istream / sentry / pod / 1.cc
1 // 1999-10-14 bkoz
2
3 // Copyright (C) 1999-2016 Free Software Foundation, Inc.
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
8 // Free Software Foundation; either version 3, or (at your option)
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
17 // with this library; see the file COPYING3. If not see
18 // <http://www.gnu.org/licenses/>.
19
20
21 // 27.6.1.1.2 class basic_istream::sentry
22
23 #include <istream>
24 #include <sstream>
25 #include <typeinfo>
26 #include <ext/pod_char_traits.h>
27 #include <testsuite_hooks.h>
28 #include <testsuite_character.h>
29
30 void test01()
31 {
32 using namespace std;
33 using __gnu_test::pod_ushort;
34 typedef basic_string<pod_ushort> string_type;
35 typedef basic_stringbuf<pod_ushort> stringbuf_type;
36 typedef basic_istream<pod_ushort> istream_type;
37
38 bool test __attribute__((unused)) = true;
39
40
41 const string_type str01;
42 stringbuf_type strbuf01;
43 stringbuf_type strbuf02(str01);
44 istream_type istr01(&strbuf01);
45 istream_type istr02(&strbuf02);
46
47 // test negatives
48 try
49 {
50 istream_type::sentry sentry01(istr01);
51 }
52 catch (std::bad_cast& obj)
53 {
54 // Ok, throws bad_cast because locale has no ctype facet.
55 }
56 catch (...)
57 {
58 VERIFY( false );
59 }
60
61 try
62 {
63 istream_type::sentry sentry02(istr01, true);
64 }
65 catch (std::bad_cast& obj)
66 {
67 // Ok, throws bad_cast because locale has no ctype facet.
68 }
69 catch (...)
70 {
71 VERIFY( false );
72 }
73
74 // imbued.
75 const std::locale loc(std::locale::classic(), new std::ctype<pod_ushort>);
76 istr01.imbue(loc);
77 try
78 {
79 istream_type::sentry sentry01(istr01);
80 VERIFY( bool(sentry01) == false );
81 }
82 catch (...)
83 {
84 VERIFY( false );
85 }
86
87 try
88 {
89 istream_type::sentry sentry02(istr01, true);
90 VERIFY( bool(sentry02) == false );
91 }
92 catch (...)
93 {
94 VERIFY( false );
95 }
96
97 // test positive
98 try
99 {
100 istream_type::sentry sentry03(istr02);
101 }
102 catch (std::bad_cast& obj)
103 {
104 // Ok, throws bad_cast because locale has no ctype facet.
105 }
106 catch (...)
107 {
108 VERIFY( false );
109 }
110
111 try
112 {
113 istream_type::sentry sentry04(istr02, true);
114 }
115 catch (std::bad_cast& obj)
116 {
117 // Ok, throws bad_cast because locale has no ctype facet.
118 }
119 catch (...)
120 {
121 VERIFY( false );
122 }
123
124 // imbued.
125 istr02.imbue(loc);
126 try
127 {
128 istr02.clear();
129 istream_type::sentry sentry03(istr02);
130 // ... as eofbit set.
131 VERIFY( bool(sentry03) == false );
132 }
133 catch (...)
134 {
135 VERIFY( false );
136 }
137
138 try
139 {
140 istr02.clear();
141 istream_type::sentry sentry04(istr02, true);
142 VERIFY( bool(sentry04) == true );
143 }
144 catch (...)
145 {
146 VERIFY( false );
147 }
148 }
149
150 #if !__GXX_WEAK__
151 // Explicitly instantiate for systems with no COMDAT or weak support.
152 template
153 const std::basic_string<__gnu_test::pod_ushort>::size_type
154 std::basic_string<__gnu_test::pod_ushort>::_Rep::_S_max_size;
155
156 template
157 const __gnu_test::pod_ushort
158 std::basic_string<__gnu_test::pod_ushort>::_Rep::_S_terminal;
159 #endif
160
161 int main()
162 {
163 test01();
164 return 0;
165 }