1// Copyright (C) 2004 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 2, 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 COPYING.  If not, write to the Free
16// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
17// USA.
18
19// As a special exception, you may use this file as part of a free software
20// library without restriction.  Specifically, if other files instantiate
21// templates or use macros or inline functions from this file, or you compile
22// this file and link it with other files to produce an executable, this
23// file does not by itself cause the resulting executable to be covered by
24// the GNU General Public License.  This exception does not however
25// invalidate any other reasons why the executable file might be covered by
26// the GNU General Public License.
27
28#include <sstream>
29#include <locale>
30#include <iomanip>
31#include <testsuite_hooks.h>
32
33struct MyNP : std::numpunct<wchar_t>
34{
35  std::wstring do_truename() const;
36  std::wstring do_falsename() const;
37};
38
39std::wstring
40MyNP::do_truename() const
41{
42  std::wstring s(L"yea");
43  return s;
44}
45
46std::wstring
47MyNP::do_falsename() const
48{
49  std::wstring s(L"nay");
50  return s;
51}
52
53void
54test01()
55{
56  bool test __attribute__((unused)) = true;
57  const wchar_t lit[] = L"1 0\n"
58                        L"true false\n"
59                        L":  true:\n"
60                        L":true  :\n"
61                        L": false:\n"
62                        L":  1:\n"
63                        L":1  :\n"
64                        L":  0:\n"
65                        L"yea nay\n"
66                        L":   yea:\n"
67                        L":yea   :\n"
68                        L":   nay:\n";
69
70  std::wostringstream oss;
71  oss << true << L" " << false << std::endl;
72  oss << std::boolalpha;
73  oss << true << L" " << false << std::endl;
74
75  oss << L":" << std::setw(6) << std::internal << true << L":" << std::endl;
76  oss << L":" << std::setw(6) << std::left << true << L":" << std::endl;
77  oss << L":" << std::setw(6) << std::right << false << L":" << std::endl;
78  oss << std::noboolalpha;
79  oss << L":" << std::setw(3) << std::internal << true << L":" << std::endl;
80  oss << L":" << std::setw(3) << std::left << true << L":" << std::endl;
81  oss << L":" << std::setw(3) << std::right << false << L":" << std::endl;
82
83  std::locale loc = std::locale(std::locale::classic(), new MyNP);
84  oss.imbue(loc);
85
86  oss << std::boolalpha;
87  oss << true << L" " << false << std::endl;
88
89  oss << L":" << std::setw(6) << std::internal << true << L":" << std::endl;
90  oss << L":" << std::setw(6) << std::left << true << L":" << std::endl;
91  oss << L":" << std::setw(6) << std::right << false << L":" << std::endl;
92
93  VERIFY( oss.good() );
94  VERIFY( oss.str() == lit );
95}
96
97int
98main()
99{
100  test01();
101  return 0;
102}
103