OpenCores
URL https://opencores.org/ocsvn/scarts/scarts/trunk

Subversion Repositories scarts

[/] [scarts/] [trunk/] [toolchain/] [scarts-gcc/] [gcc-4.1.1/] [libstdc++-v3/] [testsuite/] [27_io/] [manipulators/] [basefield/] [char/] [1.cc] - Blame information for rev 19

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 19 jlechner
// 981027 ncm work with libstdc++v3
2
 
3
// Copyright (C) 1997, 1998, 1999, 2002 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 2, 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 COPYING.  If not, write to the Free
18
// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
19
// USA.
20
 
21
// As a special exception, you may use this file as part of a free software
22
// library without restriction.  Specifically, if other files instantiate
23
// templates or use macros or inline functions from this file, or you compile
24
// this file and link it with other files to produce an executable, this
25
// file does not by itself cause the resulting executable to be covered by
26
// the GNU General Public License.  This exception does not however
27
// invalidate any other reasons why the executable file might be covered by
28
// the GNU General Public License.
29
 
30
#include <sstream>
31
#include <locale>
32
#include <iomanip>
33
#include <testsuite_hooks.h>
34
 
35
struct MyNP : std::numpunct<char>
36
{
37
  std::string do_grouping() const;
38
  char do_thousands_sep() const;
39
};
40
 
41
std::string
42
MyNP::do_grouping() const
43
{
44
  std::string s("\3");
45
  return s;
46
}
47
 
48
char
49
MyNP::do_thousands_sep() const
50
{ return ' '; }
51
 
52
void test01()
53
{
54
  bool test __attribute__((unused)) = true;
55
  const char lit[] = "0123 456\n"
56
                     ": 01 234 567:\n"
57
                     ":0123 456   :\n"
58
                     ":    012 345:\n"
59
                     ":     01 234:\n"
60
                     ":0726 746 425:\n"
61
                     ":04 553 207 :\n"
62
                     ":   0361 100:\n"
63
                     ":       0173:\n"
64
                     "0x12 345 678\n"
65
                     "|0x000012 345 678|\n"
66
                     "|0x12 345 6780000|\n"
67
                     "|00000x12 345 678|\n"
68
                     "|0x000012 345 678|\n";
69
 
70
  std::ostringstream oss;
71
  oss.imbue(std::locale(std::locale(), new MyNP));
72
 
73
  // Octals
74
  oss << std::oct << std::showbase;
75
  oss << 0123456l << std::endl;
76
 
77
  oss << ":" << std::setw(11);
78
  oss << 01234567l << ":" << std::endl;
79
 
80
  oss << ":" << std::setw(11) << std::left;
81
  oss << 0123456l << ":" << std::endl;
82
 
83
  oss << ":" << std::setw(11) << std::right;
84
  oss << 012345l << ":" << std::endl;
85
 
86
  oss << ":" << std::setw(11) << std::internal;
87
  oss << 01234l << ":" << std::endl;
88
 
89
  oss << ":" << std::setw(11);
90
  oss << 123456789l << ":" << std::endl;
91
 
92
  oss << ":" << std::setw(11) << std::left;
93
  oss << 1234567l << ":" << std::endl;
94
 
95
  oss << ":" << std::setw(11) << std::right;
96
  oss << 123456l << ":" << std::endl;
97
 
98
  oss << ":" << std::setw(11) << std::internal;
99
  oss << 123l << ":" << std::endl;
100
 
101
  // Hexadecimals
102
  oss << std::hex << std::setfill('0');
103
  oss << 0x12345678l << std::endl;
104
 
105
  oss << "|" << std::setw(16);
106
  oss << 0x12345678l << "|" << std::endl;
107
 
108
  oss << "|" << std::setw(16) << std::left;
109
  oss << 0x12345678l << "|" << std::endl;
110
 
111
  oss << "|" << std::setw(16) << std::right;
112
  oss << 0x12345678l << "|" << std::endl;
113
 
114
  oss << "|" << std::setw(16) << std::internal;
115
  oss << 0x12345678l << "|" << std::endl;
116
 
117
  VERIFY( oss.good() );
118
  VERIFY( oss.str() == lit );
119
}
120
 
121
int
122
main()
123
{
124
  test01();
125
  return 0;
126
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.