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