1// Copyright (C) 2004-2015 Free Software Foundation, Inc.
2//
3// This file is part of the GNU ISO C++ Library.  This library is free
4// software; you can redistribute it and/or modify it under the
5// terms of the GNU General Public License as published by the
6// Free Software Foundation; either version 3, or (at your option)
7// any later version.
8
9// This library is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12// GNU General Public License for more details.
13
14// You should have received a copy of the GNU General Public License along
15// with this library; see the file COPYING3.  If not see
16// <http://www.gnu.org/licenses/>.
17
18
19#include <sstream>
20#include <locale>
21#include <iomanip>
22#include <testsuite_hooks.h>
23
24struct MyNP : std::numpunct<wchar_t>
25{
26  std::wstring do_truename() const;
27  std::wstring do_falsename() const;
28};
29
30std::wstring
31MyNP::do_truename() const
32{
33  std::wstring s(L"yea");
34  return s;
35}
36
37std::wstring
38MyNP::do_falsename() const
39{
40  std::wstring s(L"nay");
41  return s;
42}
43
44void
45test01()
46{
47  bool test __attribute__((unused)) = true;
48  const wchar_t lit[] = L"1 0\n"
49                        L"true false\n"
50                        L":  true:\n"
51                        L":true  :\n"
52                        L": false:\n"
53                        L":  1:\n"
54                        L":1  :\n"
55                        L":  0:\n"
56                        L"yea nay\n"
57                        L":   yea:\n"
58                        L":yea   :\n"
59                        L":   nay:\n";
60
61  std::wostringstream oss;
62  oss << true << L" " << false << std::endl;
63  oss << std::boolalpha;
64  oss << true << L" " << false << std::endl;
65
66  oss << L":" << std::setw(6) << std::internal << true << L":" << std::endl;
67  oss << L":" << std::setw(6) << std::left << true << L":" << std::endl;
68  oss << L":" << std::setw(6) << std::right << false << L":" << std::endl;
69  oss << std::noboolalpha;
70  oss << L":" << std::setw(3) << std::internal << true << L":" << std::endl;
71  oss << L":" << std::setw(3) << std::left << true << L":" << std::endl;
72  oss << L":" << std::setw(3) << std::right << false << L":" << std::endl;
73
74  std::locale loc = std::locale(std::locale::classic(), new MyNP);
75  oss.imbue(loc);
76
77  oss << std::boolalpha;
78  oss << true << L" " << false << std::endl;
79
80  oss << L":" << std::setw(6) << std::internal << true << L":" << std::endl;
81  oss << L":" << std::setw(6) << std::left << true << L":" << std::endl;
82  oss << L":" << std::setw(6) << std::right << false << L":" << std::endl;
83
84  VERIFY( oss.good() );
85  VERIFY( oss.str() == lit );
86}
87
88int
89main()
90{
91  test01();
92  return 0;
93}
94