1// 1999-10-14 bkoz
2
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.
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 COPYING.  If not, write to the Free
18// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
19// USA.
20
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.
29
30// 27.6.1.1.2 class basic_istream::sentry
31
32#include <ostream>
33#include <sstream>
34#include <ext/pod_char_traits.h>
35#include <testsuite_hooks.h>
36#include <testsuite_character.h>
37
38void test01()
39{
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_ostream<pod_ushort> 	ostream_type;
45
46  bool test __attribute__((unused)) = true;
47
48
49  const string_type str01;
50  stringbuf_type* strbuf01 = NULL;
51  stringbuf_type strbuf02(str01);
52  ostream_type ostr01(strbuf01);
53  ostream_type ostr02(&strbuf02);
54
55  // test negatives
56  try
57    {
58      ostream_type::sentry sentry01(ostr01);
59    }
60  catch (std::bad_cast& obj)
61    {
62      // Not ok, throws bad_cast because locale has no ctype facet,
63      // but none is needed for ostream::sentry.
64      VERIFY( false );
65    }
66  catch (...)
67    {
68      VERIFY( false );
69    }
70
71  // imbued.
72  const std::locale loc(std::locale::classic(), new std::ctype<pod_ushort>);
73  ostr01.imbue(loc);
74  try
75    {
76      ostream_type::sentry sentry01(ostr01);
77      VERIFY( bool(sentry01) == false );
78    }
79  catch (...)
80    {
81      VERIFY( false );
82    }
83
84  // test positive
85  try
86    {
87      ostream_type::sentry sentry03(ostr02);
88    }
89  catch (std::bad_cast& obj)
90    {
91      // Not ok, throws bad_cast because locale has no ctype facet,
92      // but none is needed for ostream::sentry.
93      VERIFY( false );
94    }
95  catch (...)
96    {
97      VERIFY( false );
98    }
99
100  // imbued.
101  ostr02.clear();
102  ostr02.imbue(loc);
103  try
104    {
105      ostream_type::sentry sentry03(ostr02);
106      VERIFY( bool(sentry03) == true );
107    }
108  catch (...)
109    {
110      VERIFY( false );
111    }
112}
113
114#if !__GXX_WEAK__
115// Explicitly instantiate for systems with no COMDAT or weak support.
116template
117  std::basic_string<__gnu_test::pod_ushort>::size_type
118  std::basic_string<__gnu_test::pod_ushort>::_Rep::_S_max_size;
119
120template
121  __gnu_test::pod_ushort
122  std::basic_string<__gnu_test::pod_ushort>::_Rep::_S_terminal;
123#endif
124
125int main()
126{
127  test01();
128  return 0;
129}
130