]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/testsuite/22_locale/money_put/put/wchar_t/4.cc
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 22_locale / money_put / put / wchar_t / 4.cc
CommitLineData
5f8d36fe
BK
1// 2001-08-27 Benjamin Kosnik <bkoz@redhat.com>
2
8d9254fc 3// Copyright (C) 2001-2020 Free Software Foundation, Inc.
5f8d36fe
BK
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
748086b7 8// Free Software Foundation; either version 3, or (at your option)
5f8d36fe
BK
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
748086b7
JJ
17// with this library; see the file COPYING3. If not see
18// <http://www.gnu.org/licenses/>.
5f8d36fe
BK
19
20// 22.2.6.2.1 money_put members
21
22#include <locale>
23#include <sstream>
24#include <testsuite_hooks.h>
25
26void test04()
27{
28 using namespace std;
5f8d36fe
BK
29
30 // Check money_put works with other iterators besides streambuf
31 // output iterators. (As long as output_iterator requirements are met.)
32 typedef wstring::iterator iter_type;
33 typedef money_put<wchar_t, iter_type> mon_put_type;
34 const ios_base::iostate goodbit = ios_base::goodbit;
5f8d36fe
BK
35 ios_base::iostate err = goodbit;
36 const locale loc_c = locale::classic();
37 // woman, art, thief (stole the blues)
38 const wstring str(L"1943 Janis Joplin");
39 const long double ld = 1943.0;
40 const wstring x(str.size(), 'x'); // have to have allocated wstring!
41 wstring res;
42
43 ostringstream oss;
44 oss.imbue(locale(loc_c, new mon_put_type));
45
46 // Iterator advanced, state, output.
47 const mon_put_type& mp = use_facet<mon_put_type>(oss.getloc());
48
49 // 01 wstring
50 res = x;
82507bc9 51 iter_type ret1 = mp.put(res.begin(), false, oss, L' ', str);
5f8d36fe
BK
52 wstring sanity1(res.begin(), ret1);
53 VERIFY( err == goodbit );
54 VERIFY( res == L"1943xxxxxxxxxxxxx" );
55 VERIFY( sanity1 == L"1943" );
56
57 // 02 long double
58 res = x;
82507bc9 59 iter_type ret2 = mp.put(res.begin(), false, oss, L' ', ld);
5f8d36fe
BK
60 wstring sanity2(res.begin(), ret2);
61 VERIFY( err == goodbit );
62 VERIFY( res == L"1943xxxxxxxxxxxxx" );
63 VERIFY( sanity2 == L"1943" );
64}
65
66int main()
67{
68 test04();
69 return 0;
70}