Merged trunk at revision 161680 into branch.
[official-gcc.git] / libstdc++-v3 / testsuite / 27_io / basic_ostream / sentry / pod / 1.cc
blob00becef2587ccfac4b462f65a41d9d9a8e649a57
1 // 1999-10-14 bkoz
3 // Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007,
4 // 2009, 2010
5 // Free Software Foundation, Inc.
6 //
7 // This file is part of the GNU ISO C++ Library. This library is free
8 // software; you can redistribute it and/or modify it under the
9 // terms of the GNU General Public License as published by the
10 // Free Software Foundation; either version 3, or (at your option)
11 // any later version.
13 // This library is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 // GNU General Public License for more details.
18 // You should have received a copy of the GNU General Public License along
19 // with this library; see the file COPYING3. If not see
20 // <http://www.gnu.org/licenses/>.
23 // 27.6.1.1.2 class basic_istream::sentry
25 #include <ostream>
26 #include <sstream>
27 #include <typeinfo>
28 #include <ext/pod_char_traits.h>
29 #include <testsuite_hooks.h>
30 #include <testsuite_character.h>
32 void test01()
34 using namespace std;
35 using __gnu_test::pod_ushort;
36 typedef basic_string<pod_ushort> string_type;
37 typedef basic_stringbuf<pod_ushort> stringbuf_type;
38 typedef basic_ostream<pod_ushort> ostream_type;
40 bool test __attribute__((unused)) = true;
43 const string_type str01;
44 stringbuf_type* strbuf01 = 0;
45 stringbuf_type strbuf02(str01);
46 ostream_type ostr01(strbuf01);
47 ostream_type ostr02(&strbuf02);
49 // test negatives
50 try
52 ostream_type::sentry sentry01(ostr01);
54 catch (std::bad_cast& obj)
56 // Not ok, throws bad_cast because locale has no ctype facet,
57 // but none is needed for ostream::sentry.
58 VERIFY( false );
60 catch (...)
62 VERIFY( false );
65 // imbued.
66 const std::locale loc(std::locale::classic(), new std::ctype<pod_ushort>);
67 ostr01.imbue(loc);
68 try
70 ostream_type::sentry sentry01(ostr01);
71 VERIFY( bool(sentry01) == false );
73 catch (...)
75 VERIFY( false );
78 // test positive
79 try
81 ostream_type::sentry sentry03(ostr02);
83 catch (std::bad_cast& obj)
85 // Not ok, throws bad_cast because locale has no ctype facet,
86 // but none is needed for ostream::sentry.
87 VERIFY( false );
89 catch (...)
91 VERIFY( false );
94 // imbued.
95 ostr02.clear();
96 ostr02.imbue(loc);
97 try
99 ostream_type::sentry sentry03(ostr02);
100 VERIFY( bool(sentry03) == true );
102 catch (...)
104 VERIFY( false );
108 #if !__GXX_WEAK__
109 // Explicitly instantiate for systems with no COMDAT or weak support.
110 template
111 const std::basic_string<__gnu_test::pod_ushort>::size_type
112 std::basic_string<__gnu_test::pod_ushort>::_Rep::_S_max_size;
114 template
115 const __gnu_test::pod_ushort
116 std::basic_string<__gnu_test::pod_ushort>::_Rep::_S_terminal;
117 #endif
119 int main()
121 test01();
122 return 0;