Remove old autovect-branch by moving to "dead" directory.
[official-gcc.git] / old-autovect-branch / libstdc++-v3 / testsuite / 27_io / basic_istream / sentry / pod / 1.cc
blob15b7e8b8f35cecc49b47158b1dcde86b89524dc9
1 // 1999-10-14 bkoz
3 // Copyright (C) 1999, 2001, 2003, 2005 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 2, or (at your option)
9 // any later version.
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.
16 // You should have received a copy of the GNU General Public License along
17 // with this library; see the file COPYING. If not, write to the Free
18 // Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
19 // USA.
21 // As a special exception, you may use this file as part of a free software
22 // library without restriction. Specifically, if other files instantiate
23 // templates or use macros or inline functions from this file, or you compile
24 // this file and link it with other files to produce an executable, this
25 // file does not by itself cause the resulting executable to be covered by
26 // the GNU General Public License. This exception does not however
27 // invalidate any other reasons why the executable file might be covered by
28 // the GNU General Public License.
30 // 27.6.1.1.2 class basic_istream::sentry
32 #include <istream>
33 #include <sstream>
34 #include <ext/pod_char_traits.h>
35 #include <testsuite_hooks.h>
36 #include <testsuite_character.h>
38 void test01()
40 using namespace std;
41 using __gnu_test::pod_ushort;
42 typedef basic_string<pod_ushort> string_type;
43 typedef basic_stringbuf<pod_ushort> stringbuf_type;
44 typedef basic_istream<pod_ushort> istream_type;
46 bool test __attribute__((unused)) = true;
49 const string_type str01;
50 stringbuf_type strbuf01;
51 stringbuf_type strbuf02(str01);
52 istream_type istr01(&strbuf01);
53 istream_type istr02(&strbuf02);
55 // test negatives
56 try
58 istream_type::sentry sentry01(istr01);
60 catch (std::bad_cast& obj)
62 // Ok, throws bad_cast because locale has no ctype facet.
64 catch (...)
66 VERIFY( false );
69 try
71 istream_type::sentry sentry02(istr01, true);
73 catch (std::bad_cast& obj)
75 // Ok, throws bad_cast because locale has no ctype facet.
77 catch (...)
79 VERIFY( false );
82 // imbued.
83 const std::locale loc(std::locale::classic(), new std::ctype<pod_ushort>);
84 istr01.imbue(loc);
85 try
87 istream_type::sentry sentry01(istr01);
88 VERIFY( bool(sentry01) == false );
90 catch (...)
92 VERIFY( false );
95 try
97 istream_type::sentry sentry02(istr01, true);
98 VERIFY( bool(sentry02) == false );
100 catch (...)
102 VERIFY( false );
105 // test positive
108 istream_type::sentry sentry03(istr02);
110 catch (std::bad_cast& obj)
112 // Ok, throws bad_cast because locale has no ctype facet.
114 catch (...)
116 VERIFY( false );
121 istream_type::sentry sentry04(istr02, true);
123 catch (std::bad_cast& obj)
125 // Ok, throws bad_cast because locale has no ctype facet.
127 catch (...)
129 VERIFY( false );
132 // imbued.
133 istr02.imbue(loc);
136 istr02.clear();
137 istream_type::sentry sentry03(istr02);
138 // ... as eofbit set.
139 VERIFY( bool(sentry03) == false );
141 catch (...)
143 VERIFY( false );
148 istr02.clear();
149 istream_type::sentry sentry04(istr02, true);
150 VERIFY( bool(sentry04) == true );
152 catch (...)
154 VERIFY( false );
158 #if !__GXX_WEAK__
159 // Explicitly instantiate for systems with no COMDAT or weak support.
160 template
161 std::basic_string<__gnu_test::pod_ushort>::size_type
162 std::basic_string<__gnu_test::pod_ushort>::_Rep::_S_max_size;
164 template
165 __gnu_test::pod_ushort
166 std::basic_string<__gnu_test::pod_ushort>::_Rep::_S_terminal;
167 #endif
169 int main()
171 test01();
172 return 0;