1// 2001-06-05 Benjamin Kosnik  <bkoz@redhat.com>
2
3// Copyright (C) 2001, 2002, 2003 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.4.2.1.6 class ios_base::init
31
32#include <sstream>
33#include <testsuite_hooks.h>
34
35// char_traits specialization
36namespace std
37{
38  template<>
39    struct char_traits<unsigned short>
40    {
41      typedef unsigned short 	char_type;
42      // Unsigned as wint_t in unsigned.
43      typedef unsigned long  	int_type;
44      typedef streampos 	pos_type;
45      typedef streamoff 	off_type;
46      typedef mbstate_t 	state_type;
47
48      static void
49      assign(char_type& __c1, const char_type& __c2)
50      { __c1 = __c2; }
51
52      static bool
53      eq(const char_type& __c1, const char_type& __c2)
54      { return __c1 == __c2; }
55
56      static bool
57      lt(const char_type& __c1, const char_type& __c2)
58      { return __c1 < __c2; }
59
60      static int
61      compare(const char_type* __s1, const char_type* __s2, size_t __n)
62      {
63	for (size_t __i = 0; __i < __n; ++__i)
64	  if (!eq(__s1[__i], __s2[__i]))
65	    return lt(__s1[__i], __s2[__i]) ? -1 : 1;
66	return 0;
67      }
68
69      static size_t
70      length(const char_type* __s)
71      {
72	const char_type* __p = __s;
73	while (__p)
74	  ++__p;
75	return (__p - __s);
76      }
77
78      static const char_type*
79      find(const char_type* __s, size_t __n, const char_type& __a)
80      {
81	for (const char_type* __p = __s; size_t(__p - __s) < __n; ++__p)
82	  if (*__p == __a) return __p;
83	return 0;
84      }
85
86      static char_type*
87      move(char_type* __s1, const char_type* __s2, size_t __n)
88      { return (char_type*) memmove(__s1, __s2, __n * sizeof(char_type)); }
89
90      static char_type*
91      copy(char_type* __s1, const char_type* __s2, size_t __n)
92      { return (char_type*) memcpy(__s1, __s2, __n * sizeof(char_type)); }
93
94      static char_type*
95      assign(char_type* __s, size_t __n, char_type __a)
96      {
97	for (char_type* __p = __s; __p < __s + __n; ++__p)
98	  assign(*__p, __a);
99        return __s;
100      }
101
102      static char_type
103      to_char_type(const int_type&)
104      { return char_type(); }
105
106      static int_type
107      to_int_type(const char_type&) { return int_type(); }
108
109      static bool
110      eq_int_type(const int_type& __c1, const int_type& __c2)
111      { return __c1 == __c2; }
112
113      static int_type
114      eof() { return static_cast<int_type>(-1); }
115
116      static int_type
117      not_eof(const int_type& __c)
118      { return eq_int_type(__c, eof()) ? int_type(0) : __c; }
119    };
120} // namespace std
121
122// Non-required instantiations don't have the required facets inbued,
123// by default, into the locale object.
124// See 27.4.4.1
125
126void test02()
127{
128  bool test __attribute__((unused)) = true;
129
130  // 02: Calls basic_ios::init, which may call ctype<char_type>...
131  try
132    {
133      std::basic_string<unsigned short>        	str;
134      std::basic_ostringstream<unsigned short> 	oss(str);
135
136      // Try each member functions for unformatted io.
137      // put
138      oss.put(324);
139
140      // write
141      const unsigned short us[4] = {1246, 433, 520, 0};
142      oss.write(us, 4);
143
144      // flush
145      oss.flush();
146    }
147  catch(const std::bad_cast& obj)
148    {
149      // Should be able to do the above without calling fill() and
150      // forcing a call to widen...
151      test = false;
152    }
153  catch(...)
154    {
155      test = false;
156    }
157  VERIFY( test );
158}
159
160#if !__GXX_WEAK__
161// Explicitly instantiate for systems with no COMDAT or weak support.
162template
163  std::basic_string<unsigned short>::size_type
164  std::basic_string<unsigned short>::_Rep::_S_max_size;
165
166template
167  unsigned short
168  std::basic_string<unsigned short>::_Rep::_S_terminal;
169#endif
170
171int main()
172{
173  test02();
174  return 0;
175}
176