1 // 2001-06-05 Benjamin Kosnik <bkoz@redhat.com>
3 // Copyright (C) 2001, 2002 Free Software Foundation, Inc.
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)
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, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
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.4.2.1.6 class ios_base::init
35 #include <testsuite_hooks.h>
37 // char_traits specialization
41 struct char_traits
<unsigned short>
43 typedef unsigned short char_type
;
44 // Unsigned as wint_t in unsigned.
45 typedef unsigned long int_type
;
46 typedef streampos pos_type
;
47 typedef streamoff off_type
;
48 typedef mbstate_t state_type
;
51 assign(char_type
& __c1
, const char_type
& __c2
)
55 eq(const char_type
& __c1
, const char_type
& __c2
)
56 { return __c1
== __c2
; }
59 lt(const char_type
& __c1
, const char_type
& __c2
)
60 { return __c1
< __c2
; }
63 compare(const char_type
* __s1
, const char_type
* __s2
, size_t __n
)
65 for (size_t __i
= 0; __i
< __n
; ++__i
)
66 if (!eq(__s1
[__i
], __s2
[__i
]))
67 return lt(__s1
[__i
], __s2
[__i
]) ? -1 : 1;
72 length(const char_type
* __s
)
74 const char_type
* __p
= __s
;
80 static const char_type
*
81 find(const char_type
* __s
, size_t __n
, const char_type
& __a
)
83 for (const char_type
* __p
= __s
; size_t(__p
- __s
) < __n
; ++__p
)
84 if (*__p
== __a
) return __p
;
89 move(char_type
* __s1
, const char_type
* __s2
, size_t __n
)
90 { return (char_type
*) memmove(__s1
, __s2
, __n
* sizeof(char_type
)); }
93 copy(char_type
* __s1
, const char_type
* __s2
, size_t __n
)
94 { return (char_type
*) memcpy(__s1
, __s2
, __n
* sizeof(char_type
)); }
97 assign(char_type
* __s
, size_t __n
, char_type __a
)
99 for (char_type
* __p
= __s
; __p
< __s
+ __n
; ++__p
)
105 to_char_type(const int_type
& __c
)
106 { return char_type(); }
109 to_int_type(const char_type
& __c
) { return int_type(); }
112 eq_int_type(const int_type
& __c1
, const int_type
& __c2
)
113 { return __c1
== __c2
; }
116 eof() { return static_cast<int_type
>(-1); }
119 not_eof(const int_type
& __c
)
120 { return eq_int_type(__c
, eof()) ? int_type(0) : __c
; }
124 struct char_traits
<unsigned char>
126 typedef unsigned char char_type
;
127 // Unsigned as wint_t in unsigned.
128 typedef unsigned long int_type
;
129 typedef streampos pos_type
;
130 typedef streamoff off_type
;
131 typedef mbstate_t state_type
;
134 assign(char_type
& __c1
, const char_type
& __c2
)
138 eq(const char_type
& __c1
, const char_type
& __c2
)
139 { return __c1
== __c2
; }
142 lt(const char_type
& __c1
, const char_type
& __c2
)
143 { return __c1
< __c2
; }
146 compare(const char_type
* __s1
, const char_type
* __s2
, size_t __n
)
148 for (size_t __i
= 0; __i
< __n
; ++__i
)
149 if (!eq(__s1
[__i
], __s2
[__i
]))
150 return lt(__s1
[__i
], __s2
[__i
]) ? -1 : 1;
155 length(const char_type
* __s
)
157 const char_type
* __p
= __s
;
163 static const char_type
*
164 find(const char_type
* __s
, size_t __n
, const char_type
& __a
)
166 for (const char_type
* __p
= __s
; size_t(__p
- __s
) < __n
; ++__p
)
167 if (*__p
== __a
) return __p
;
172 move(char_type
* __s1
, const char_type
* __s2
, size_t __n
)
173 { return (char_type
*) memmove(__s1
, __s2
, __n
* sizeof(char_type
)); }
176 copy(char_type
* __s1
, const char_type
* __s2
, size_t __n
)
177 { return (char_type
*) memcpy(__s1
, __s2
, __n
* sizeof(char_type
)); }
180 assign(char_type
* __s
, size_t __n
, char_type __a
)
182 for (char_type
* __p
= __s
; __p
< __s
+ __n
; ++__p
)
188 to_char_type(const int_type
& __c
)
189 { return char_type(); }
192 to_int_type(const char_type
& __c
) { return int_type(); }
195 eq_int_type(const int_type
& __c1
, const int_type
& __c2
)
196 { return __c1
== __c2
; }
199 eof() { return static_cast<int_type
>(-1); }
202 not_eof(const int_type
& __c
)
203 { return eq_int_type(__c
, eof()) ? int_type(0) : __c
; }
207 class gnu_filebuf
: public std::filebuf
211 gnu_filebuf(int j
= 1): i(j
) { }
212 ~gnu_filebuf() { --i
; }
213 int get_i() { return i
;}
216 const int initial
= 4;
217 gnu_filebuf
buf(initial
);
219 // libstdc++/3045, in a vague way.
227 VERIFY( k1
== initial
);
229 std::cout
.rdbuf(&buf
);
232 VERIFY( k1
== initial
);
236 VERIFY( k1
== initial
);
238 std::cout
.rdbuf(&buf
);
239 std::ios_base::sync_with_stdio(false); // make sure doesn't clobber buf
242 VERIFY( k1
== initial
);
246 VERIFY( k1
== initial
);
248 std::cout
.rdbuf(&buf
);
249 std::ios_base::Init make_sure_initialized
;
252 VERIFY( k1
== initial
);
255 // Non-required instantiations don't have the required facets inbued,
256 // by default, into the locale object.
258 class gnu_ios
: public std::basic_ios
<char> { };
264 // 01: Doesn't call basic_ios::init, which uses ctype<char_type>..
265 // This should be unambiguously correct.
275 // 02: Calls basic_ios::init, which may call ctype<char_type>...
278 std::basic_string
<unsigned short> str
;
279 std::basic_ostringstream
<unsigned short> oss(str
);
281 // Try each member functions for unformatted io.
286 const unsigned short us
[4] = {1246, 433, 520, 0};
292 catch(const std::bad_cast
& obj
)
294 // Should be able to do the above without calling fill() and
295 // forcing a call to widen...
312 basic_istringstream
<unsigned char> iss_uc
;
313 unsigned char arr
[6] = { 'a', 'b', 'c', 'd', 'e' };
315 // Sentry uses locale info, so have to try one formatted input.
321 catch (bad_cast
& obj
)
323 catch (exception
& obj
)
330 catch (bad_cast
& obj
)
332 catch (exception
& obj
)
339 catch (bad_cast
& obj
)
341 catch (exception
& obj
)
346 basic_string
<unsigned char> s_uc(arr
);
349 catch (bad_cast
& obj
)
351 catch (exception
& obj
)
355 basic_ostringstream
<unsigned char> oss_uc
;
362 catch (bad_cast
& obj
)
364 catch (exception
& obj
)
374 std::cout
.rdbuf( &b1
);
375 std::cout
<< "hello\n";
380 // Explicitly instantiate for systems with no COMDAT or weak support.
382 std::basic_string
<unsigned short>::size_type
383 std::basic_string
<unsigned short>::_Rep::_S_max_size
;
387 std::basic_string
<unsigned short>::_Rep::_S_terminal
;
390 std::basic_string
<unsigned char>::size_type
391 std::basic_string
<unsigned char>::_Rep::_S_max_size
;
395 std::basic_string
<unsigned char>::_Rep::_S_terminal
;