1// 2003-03-08 Jerry Quinn <jlquinn@optonline.net> 2 3// Copyright (C) 2003-2015 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 3, 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 COPYING3. If not see 18// <http://www.gnu.org/licenses/>. 19 20#include <locale> 21#include <sstream> 22#include <testsuite_hooks.h> 23#include <testsuite_io.h> 24 25// libstdc++/9561 26template<typename T> 27void test_badbit() 28{ 29 using namespace std; 30 bool test __attribute__((unused)) = true; 31 32 locale loc(locale::classic(), new __gnu_test::fail_num_put_char); 33 ostringstream stream("jaylib - champion sound"); 34 stream.imbue(loc); 35 36 stream.exceptions(ios_base::badbit); 37 VERIFY( stream.rdstate() == ios_base::goodbit ); 38 39 try 40 { 41 T i = T(); 42 stream << i; 43 VERIFY( false ); 44 } 45 catch (const __gnu_test::facet_error&) 46 { 47 // stream should set badbit and rethrow facet_error. 48 VERIFY( stream.bad() ); 49 VERIFY( (stream.rdstate() & ios_base::failbit) == 0 ); 50 VERIFY( !stream.eof() ); 51 } 52 catch (...) 53 { 54 VERIFY(false); 55 } 56} 57 58 59int main() 60{ 61 test_badbit<bool>(); 62 test_badbit<short>(); 63 test_badbit<unsigned short>(); 64 test_badbit<int>(); 65 test_badbit<unsigned int>(); 66 test_badbit<long>(); 67 test_badbit<unsigned long>(); 68 69 test_badbit<float>(); 70 test_badbit<double>(); 71 72 return 0; 73} 74