Reverting merge from trunk
[official-gcc.git] / libstdc++-v3 / testsuite / 27_io / basic_ostream / sentry / pod / 1.cc
blobd22f15496143e4bb7ceab0d16070746a972b21f3
1 // 1999-10-14 bkoz
3 // Copyright (C) 1999-2013 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.
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 COPYING3. If not see
18 // <http://www.gnu.org/licenses/>.
21 // 27.6.1.1.2 class basic_istream::sentry
23 #include <ostream>
24 #include <sstream>
25 #include <typeinfo>
26 #include <ext/pod_char_traits.h>
27 #include <testsuite_hooks.h>
28 #include <testsuite_character.h>
30 void test01()
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_ostream<pod_ushort> ostream_type;
38 bool test __attribute__((unused)) = true;
41 const string_type str01;
42 stringbuf_type* strbuf01 = 0;
43 stringbuf_type strbuf02(str01);
44 ostream_type ostr01(strbuf01);
45 ostream_type ostr02(&strbuf02);
47 // test negatives
48 try
50 ostream_type::sentry sentry01(ostr01);
52 catch (std::bad_cast& obj)
54 // Not ok, throws bad_cast because locale has no ctype facet,
55 // but none is needed for ostream::sentry.
56 VERIFY( false );
58 catch (...)
60 VERIFY( false );
63 // imbued.
64 const std::locale loc(std::locale::classic(), new std::ctype<pod_ushort>);
65 ostr01.imbue(loc);
66 try
68 ostream_type::sentry sentry01(ostr01);
69 VERIFY( bool(sentry01) == false );
71 catch (...)
73 VERIFY( false );
76 // test positive
77 try
79 ostream_type::sentry sentry03(ostr02);
81 catch (std::bad_cast& obj)
83 // Not ok, throws bad_cast because locale has no ctype facet,
84 // but none is needed for ostream::sentry.
85 VERIFY( false );
87 catch (...)
89 VERIFY( false );
92 // imbued.
93 ostr02.clear();
94 ostr02.imbue(loc);
95 try
97 ostream_type::sentry sentry03(ostr02);
98 VERIFY( bool(sentry03) == true );
100 catch (...)
102 VERIFY( false );
106 #if !__GXX_WEAK__
107 // Explicitly instantiate for systems with no COMDAT or weak support.
108 template
109 const std::basic_string<__gnu_test::pod_ushort>::size_type
110 std::basic_string<__gnu_test::pod_ushort>::_Rep::_S_max_size;
112 template
113 const __gnu_test::pod_ushort
114 std::basic_string<__gnu_test::pod_ushort>::_Rep::_S_terminal;
115 #endif
117 int main()
119 test01();
120 return 0;