]> git.ipfire.org Git - thirdparty/gcc.git/blob - 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
1 // 2001-08-27 Benjamin Kosnik <bkoz@redhat.com>
2
3 // Copyright (C) 2001-2021 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 // 22.2.6.2.1 money_put members
21
22 #include <locale>
23 #include <sstream>
24 #include <testsuite_hooks.h>
25
26 void test04()
27 {
28 using namespace std;
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;
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;
51 iter_type ret1 = mp.put(res.begin(), false, oss, L' ', str);
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;
59 iter_type ret2 = mp.put(res.begin(), false, oss, L' ', ld);
60 wstring sanity2(res.begin(), ret2);
61 VERIFY( err == goodbit );
62 VERIFY( res == L"1943xxxxxxxxxxxxx" );
63 VERIFY( sanity2 == L"1943" );
64 }
65
66 int main()
67 {
68 test04();
69 return 0;
70 }