1// 1999-10-14 bkoz 2 3// Copyright (C) 1999, 2000, 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.6.1.1.2 class basic_istream::sentry 23 24#include <istream> 25#include <sstream> 26#include <typeinfo> 27#include <ext/pod_char_traits.h> 28#include <testsuite_hooks.h> 29#include <testsuite_character.h> 30 31void test01() 32{ 33 using namespace std; 34 using __gnu_test::pod_ushort; 35 typedef basic_string<pod_ushort> string_type; 36 typedef basic_stringbuf<pod_ushort> stringbuf_type; 37 typedef basic_istream<pod_ushort> istream_type; 38 39 bool test __attribute__((unused)) = true; 40 41 42 const string_type str01; 43 stringbuf_type strbuf01; 44 stringbuf_type strbuf02(str01); 45 istream_type istr01(&strbuf01); 46 istream_type istr02(&strbuf02); 47 48 // test negatives 49 try 50 { 51 istream_type::sentry sentry01(istr01); 52 } 53 catch (std::bad_cast& obj) 54 { 55 // Ok, throws bad_cast because locale has no ctype facet. 56 } 57 catch (...) 58 { 59 VERIFY( false ); 60 } 61 62 try 63 { 64 istream_type::sentry sentry02(istr01, true); 65 } 66 catch (std::bad_cast& obj) 67 { 68 // Ok, throws bad_cast because locale has no ctype facet. 69 } 70 catch (...) 71 { 72 VERIFY( false ); 73 } 74 75 // imbued. 76 const std::locale loc(std::locale::classic(), new std::ctype<pod_ushort>); 77 istr01.imbue(loc); 78 try 79 { 80 istream_type::sentry sentry01(istr01); 81 VERIFY( bool(sentry01) == false ); 82 } 83 catch (...) 84 { 85 VERIFY( false ); 86 } 87 88 try 89 { 90 istream_type::sentry sentry02(istr01, true); 91 VERIFY( bool(sentry02) == false ); 92 } 93 catch (...) 94 { 95 VERIFY( false ); 96 } 97 98 // test positive 99 try 100 { 101 istream_type::sentry sentry03(istr02); 102 } 103 catch (std::bad_cast& obj) 104 { 105 // Ok, throws bad_cast because locale has no ctype facet. 106 } 107 catch (...) 108 { 109 VERIFY( false ); 110 } 111 112 try 113 { 114 istream_type::sentry sentry04(istr02, true); 115 } 116 catch (std::bad_cast& obj) 117 { 118 // Ok, throws bad_cast because locale has no ctype facet. 119 } 120 catch (...) 121 { 122 VERIFY( false ); 123 } 124 125 // imbued. 126 istr02.imbue(loc); 127 try 128 { 129 istr02.clear(); 130 istream_type::sentry sentry03(istr02); 131 // ... as eofbit set. 132 VERIFY( bool(sentry03) == false ); 133 } 134 catch (...) 135 { 136 VERIFY( false ); 137 } 138 139 try 140 { 141 istr02.clear(); 142 istream_type::sentry sentry04(istr02, true); 143 VERIFY( bool(sentry04) == true ); 144 } 145 catch (...) 146 { 147 VERIFY( false ); 148 } 149} 150 151#if !__GXX_WEAK__ 152// Explicitly instantiate for systems with no COMDAT or weak support. 153template 154 const std::basic_string<__gnu_test::pod_ushort>::size_type 155 std::basic_string<__gnu_test::pod_ushort>::_Rep::_S_max_size; 156 157template 158 const __gnu_test::pod_ushort 159 std::basic_string<__gnu_test::pod_ushort>::_Rep::_S_terminal; 160#endif 161 162int main() 163{ 164 test01(); 165 return 0; 166} 167