1209920Snwhitehorn// 2001-08-27 Benjamin Kosnik <bkoz@redhat.com> 2209920Snwhitehorn 3209920Snwhitehorn// Copyright (C) 2001-2015 Free Software Foundation, Inc. 4209920Snwhitehorn// 5209920Snwhitehorn// This file is part of the GNU ISO C++ Library. This library is free 6209920Snwhitehorn// software; you can redistribute it and/or modify it under the 7209920Snwhitehorn// terms of the GNU General Public License as published by the 8209920Snwhitehorn// Free Software Foundation; either version 3, or (at your option) 9209920Snwhitehorn// any later version. 10209920Snwhitehorn 11209920Snwhitehorn// This library is distributed in the hope that it will be useful, 12209920Snwhitehorn// but WITHOUT ANY WARRANTY; without even the implied warranty of 13209920Snwhitehorn// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14209920Snwhitehorn// GNU General Public License for more details. 15209920Snwhitehorn 16209920Snwhitehorn// You should have received a copy of the GNU General Public License along 17209920Snwhitehorn// with this library; see the file COPYING3. If not see 18209920Snwhitehorn// <http://www.gnu.org/licenses/>. 19209920Snwhitehorn 20209920Snwhitehorn// 22.2.6.2.1 money_put members 21209920Snwhitehorn 22209920Snwhitehorn#include <locale> 23209920Snwhitehorn#include <sstream> 24209920Snwhitehorn#include <testsuite_hooks.h> 25209920Snwhitehorn 26209920Snwhitehornvoid test04() 27209920Snwhitehorn{ 28209920Snwhitehorn using namespace std; 29209920Snwhitehorn bool test __attribute__((unused)) = true; 30209920Snwhitehorn 31209920Snwhitehorn // Check money_put works with other iterators besides streambuf 32209920Snwhitehorn // output iterators. (As long as output_iterator requirements are met.) 33209920Snwhitehorn typedef string::iterator iter_type; 34209920Snwhitehorn typedef money_put<char, iter_type> mon_put_type; 35209920Snwhitehorn const ios_base::iostate goodbit = ios_base::goodbit; 36209920Snwhitehorn ios_base::iostate err = goodbit; 37209920Snwhitehorn const locale loc_c = locale::classic(); 38209920Snwhitehorn // woman, art, thief (stole the blues) 39209920Snwhitehorn const string str("1943 Janis Joplin"); 40209920Snwhitehorn const long double ld = 1943.0; 41209920Snwhitehorn const string x(str.size(), 'x'); // have to have allocated string! 42209920Snwhitehorn string res; 43209920Snwhitehorn 44209920Snwhitehorn ostringstream oss; 45209920Snwhitehorn oss.imbue(locale(loc_c, new mon_put_type)); 46209920Snwhitehorn 47209920Snwhitehorn // Iterator advanced, state, output. 48209920Snwhitehorn const mon_put_type& mp = use_facet<mon_put_type>(oss.getloc()); 49209920Snwhitehorn 50209920Snwhitehorn // 01 string 51209920Snwhitehorn res = x; 52209920Snwhitehorn iter_type ret1 = mp.put(res.begin(), false, oss, ' ', str); 53209920Snwhitehorn string sanity1(res.begin(), ret1); 54209920Snwhitehorn VERIFY( err == goodbit ); 55209920Snwhitehorn VERIFY( res == "1943xxxxxxxxxxxxx" ); 56209920Snwhitehorn VERIFY( sanity1 == "1943" ); 57209920Snwhitehorn 58209920Snwhitehorn // 02 long double 59209920Snwhitehorn res = x; 60209920Snwhitehorn iter_type ret2 = mp.put(res.begin(), false, oss, ' ', ld); 61209920Snwhitehorn string sanity2(res.begin(), ret2); 62209920Snwhitehorn VERIFY( err == goodbit ); 63209920Snwhitehorn VERIFY( res == "1943xxxxxxxxxxxxx" ); 64209920Snwhitehorn VERIFY( sanity2 == "1943" ); 65209920Snwhitehorn} 66209920Snwhitehorn 67209920Snwhitehornint main() 68209920Snwhitehorn{ 69209920Snwhitehorn test04(); 70209920Snwhitehorn return 0; 71209920Snwhitehorn} 72209920Snwhitehorn