1// 2001-06-05 Benjamin Kosnik <bkoz@redhat.com> 2 3// Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2009 4// Free Software Foundation, Inc. 5// 6// This file is part of the GNU ISO C++ Library. This library is free 7// software; you can redistribute it and/or modify it under the 8// terms of the GNU General Public License as published by the 9// Free Software Foundation; either version 3, or (at your option) 10// any later version. 11 12// This library is distributed in the hope that it will be useful, 13// but WITHOUT ANY WARRANTY; without even the implied warranty of 14// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15// GNU General Public License for more details. 16 17// You should have received a copy of the GNU General Public License along 18// with this library; see the file COPYING3. If not see 19// <http://www.gnu.org/licenses/>. 20 21 22// 27.4.2.1.6 class ios_base::init 23 24#include <sstream> 25#include <typeinfo> 26#include <cstring> 27#include <testsuite_hooks.h> 28 29// char_traits specialization 30namespace std 31{ 32 template<> 33 struct char_traits<unsigned short> 34 { 35 typedef unsigned short char_type; 36 // Unsigned as wint_t in unsigned. 37 typedef unsigned long int_type; 38 typedef streampos pos_type; 39 typedef streamoff off_type; 40 typedef mbstate_t state_type; 41 42 static void 43 assign(char_type& __c1, const char_type& __c2) 44 { __c1 = __c2; } 45 46 static bool 47 eq(const char_type& __c1, const char_type& __c2) 48 { return __c1 == __c2; } 49 50 static bool 51 lt(const char_type& __c1, const char_type& __c2) 52 { return __c1 < __c2; } 53 54 static int 55 compare(const char_type* __s1, const char_type* __s2, size_t __n) 56 { 57 for (size_t __i = 0; __i < __n; ++__i) 58 if (!eq(__s1[__i], __s2[__i])) 59 return lt(__s1[__i], __s2[__i]) ? -1 : 1; 60 return 0; 61 } 62 63 static size_t 64 length(const char_type* __s) 65 { 66 const char_type* __p = __s; 67 while (__p) 68 ++__p; 69 return (__p - __s); 70 } 71 72 static const char_type* 73 find(const char_type* __s, size_t __n, const char_type& __a) 74 { 75 for (const char_type* __p = __s; size_t(__p - __s) < __n; ++__p) 76 if (*__p == __a) return __p; 77 return 0; 78 } 79 80 static char_type* 81 move(char_type* __s1, const char_type* __s2, size_t __n) 82 { return (char_type*) memmove(__s1, __s2, __n * sizeof(char_type)); } 83 84 static char_type* 85 copy(char_type* __s1, const char_type* __s2, size_t __n) 86 { return (char_type*) memcpy(__s1, __s2, __n * sizeof(char_type)); } 87 88 static char_type* 89 assign(char_type* __s, size_t __n, char_type __a) 90 { 91 for (char_type* __p = __s; __p < __s + __n; ++__p) 92 assign(*__p, __a); 93 return __s; 94 } 95 96 static char_type 97 to_char_type(const int_type&) 98 { return char_type(); } 99 100 static int_type 101 to_int_type(const char_type&) { return int_type(); } 102 103 static bool 104 eq_int_type(const int_type& __c1, const int_type& __c2) 105 { return __c1 == __c2; } 106 107 static int_type 108 eof() { return static_cast<int_type>(-1); } 109 110 static int_type 111 not_eof(const int_type& __c) 112 { return eq_int_type(__c, eof()) ? int_type(0) : __c; } 113 }; 114} // namespace std 115 116// Non-required instantiations don't have the required facets inbued, 117// by default, into the locale object. 118// See 27.4.4.1 119 120void test02() 121{ 122 bool test __attribute__((unused)) = true; 123 124 // 02: Calls basic_ios::init, which may call ctype<char_type>... 125 try 126 { 127 std::basic_string<unsigned short> str; 128 std::basic_ostringstream<unsigned short> oss(str); 129 130 // Try each member functions for unformatted io. 131 // put 132 oss.put(324); 133 134 // write 135 const unsigned short us[4] = {1246, 433, 520, 0}; 136 oss.write(us, 4); 137 138 // flush 139 oss.flush(); 140 } 141 catch(const std::bad_cast& obj) 142 { 143 // Should be able to do the above without calling fill() and 144 // forcing a call to widen... 145 test = false; 146 } 147 catch(...) 148 { 149 test = false; 150 } 151 VERIFY( test ); 152} 153 154#if !__GXX_WEAK__ 155// Explicitly instantiate for systems with no COMDAT or weak support. 156template 157 const std::basic_string<unsigned short>::size_type 158 std::basic_string<unsigned short>::_Rep::_S_max_size; 159 160template 161 const unsigned short 162 std::basic_string<unsigned short>::_Rep::_S_terminal; 163#endif 164 165int main() 166{ 167 test02(); 168 return 0; 169} 170