1// { dg-require-iconv "ISO-8859-1" } 2 3// Copyright (C) 2006, 2007, 2009 Free Software Foundation 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// 22.1.1.2 locale constructors and destructors [lib.locale.cons] 21 22#include <cwchar> // for mbstate_t 23#include <locale> 24#include <stdexcept> 25#include <typeinfo> 26#include <testsuite_hooks.h> 27#include <ext/codecvt_specializations.h> 28 29typedef std::codecvt<char, char, std::mbstate_t> c_codecvt; 30 31#ifdef _GLIBCXX_USE_WCHAR_T 32typedef std::codecvt<wchar_t, char, std::mbstate_t> w_codecvt; 33#endif 34 35class gnu_facet: public std::locale::facet 36{ 37public: 38 static std::locale::id id; 39}; 40 41std::locale::id gnu_facet::id; 42 43void test01() 44{ 45 using namespace std; 46 typedef unsigned short int_type; 47 typedef char ext_type; 48 typedef __gnu_cxx::encoding_state state_type; 49 typedef codecvt<int_type, ext_type, state_type> unicode_codecvt; 50 51 bool test __attribute__((unused)) = true; 52 53 // unicode_codecvt 54 locale loc01(locale::classic()); 55 locale loc13(locale::classic(), new unicode_codecvt); 56 VERIFY( loc01 != loc13 ); 57 VERIFY( loc13.name() == "*" ); 58 try 59 { 60 VERIFY( has_facet<c_codecvt>(loc13) ); 61#ifdef _GLIBCXX_USE_WCHAR_T 62 VERIFY( has_facet<w_codecvt>(loc13) ); 63#endif 64 VERIFY( has_facet<unicode_codecvt>(loc13) ); 65 } 66 catch(...) 67 { VERIFY( false ); } 68 69 try 70 { use_facet<gnu_facet>(loc13); } 71 catch(bad_cast& obj) 72 { VERIFY( true ); } 73 catch(...) 74 { VERIFY( false ); } 75} 76 77int main() 78{ 79 test01(); 80 return 0; 81} 82