]> 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-2016 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 bool test __attribute__((unused)) = true;
30
31 // Check money_put works with other iterators besides streambuf
32 // output iterators. (As long as output_iterator requirements are met.)
33 typedef wstring::iterator iter_type;
34 typedef money_put<wchar_t, iter_type> mon_put_type;
35 const ios_base::iostate goodbit = ios_base::goodbit;
36 ios_base::iostate err = goodbit;
37 const locale loc_c = locale::classic();
38 // woman, art, thief (stole the blues)
39 const wstring str(L"1943 Janis Joplin");
40 const long double ld = 1943.0;
41 const wstring x(str.size(), 'x'); // have to have allocated wstring!
42 wstring res;
43
44 ostringstream oss;
45 oss.imbue(locale(loc_c, new mon_put_type));
46
47 // Iterator advanced, state, output.
48 const mon_put_type& mp = use_facet<mon_put_type>(oss.getloc());
49
50 // 01 wstring
51 res = x;
52 iter_type ret1 = mp.put(res.begin(), false, oss, L' ', str);
53 wstring sanity1(res.begin(), ret1);
54 VERIFY( err == goodbit );
55 VERIFY( res == L"1943xxxxxxxxxxxxx" );
56 VERIFY( sanity1 == L"1943" );
57
58 // 02 long double
59 res = x;
60 iter_type ret2 = mp.put(res.begin(), false, oss, L' ', ld);
61 wstring sanity2(res.begin(), ret2);
62 VERIFY( err == goodbit );
63 VERIFY( res == L"1943xxxxxxxxxxxxx" );
64 VERIFY( sanity2 == L"1943" );
65 }
66
67 int main()
68 {
69 test04();
70 return 0;
71 }