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/] [basic_ostream/] [inserters_other/] [wchar_t/] [4.cc] - Blame information for rev 19

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 19 jlechner
// Copyright (C) 2005 Free Software Foundation
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
// 27.6.2.5.4 basic_ostream character inserters
20
 
21
#include <ostream>
22
#include <sstream>
23
#include <testsuite_hooks.h>
24
 
25
class test_buffer_1 : public std::wstreambuf
26
{
27
public:
28
  test_buffer_1(const std::wstring& s)
29
  : str(s), it(str.begin()) { }
30
 
31
protected:
32
  virtual int_type
33
  underflow()
34
  { return (it != str.end() ? *it : WEOF); }
35
 
36
  virtual int_type
37
  uflow()
38
  { return (it != str.end() ? *it++ : WEOF); }
39
 
40
private:
41
  const std::wstring str;
42
  std::wstring::const_iterator it;
43
};
44
 
45
 
46
class test_buffer_2 : public std::wstreambuf
47
{
48
public:
49
  test_buffer_2(const std::wstring& s)
50
  : str(s), it(str.begin()) { }
51
 
52
protected:
53
  virtual int_type
54
  underflow()
55
  { return (it != str.end() ? *it : WEOF); }
56
 
57
  virtual int_type
58
  uflow()
59
  { return (it != str.end() ? *it++ : WEOF); }
60
 
61
  virtual std::streamsize
62
  showmanyc()
63
  { return std::distance(it, str.end()); }
64
 
65
private:
66
  const std::wstring str;
67
  std::wstring::const_iterator it;
68
};
69
 
70
 
71
class test_buffer_3 : public std::wstreambuf
72
{
73
public:
74
  test_buffer_3(const std::wstring& s)
75
  : str(s), it(str.begin()) { }
76
 
77
protected:
78
  virtual int_type
79
  underflow()
80
  { return (it != str.end() ? *it : WEOF); }
81
 
82
  virtual int_type
83
  uflow()
84
  { return (it != str.end() ? *it++ : WEOF); }
85
 
86
  virtual std::streamsize
87
  showmanyc()
88
  {
89
    std::streamsize ret = std::distance(it, str.end());
90
    return ret > 0 ? ret : -1;
91
  }
92
 
93
private:
94
  const std::wstring str;
95
  std::wstring::const_iterator it;
96
};
97
 
98
class test_buffer_4 : public std::wstreambuf
99
{
100
public:
101
  test_buffer_4(const std::wstring& s)
102
  : str(s), it(str.begin())
103
  {
104
    if (it != str.end())
105
      {
106
        buf[0] = *it++;
107
        setg(buf, buf, buf+1);
108
      }
109
  }
110
 
111
protected:
112
  virtual int_type
113
  underflow()
114
  { return (it != str.end() ? *it : WEOF); }
115
 
116
  virtual int_type
117
  uflow()
118
  { return (it != str.end() ? *it++ : WEOF); }
119
 
120
  virtual std::streamsize
121
  showmanyc()
122
  {
123
    std::streamsize ret = std::distance(it, str.end());
124
    return ret > 0 ? ret : -1;
125
  }
126
 
127
private:
128
  const std::wstring str;
129
  std::wstring::const_iterator it;
130
  wchar_t buf[1];
131
};
132
 
133
void test(const std::wstring& str, std::wstreambuf& buf)
134
{
135
  bool test __attribute__((unused)) = true;
136
 
137
  std::wostringstream out;
138
  std::wistream in(&buf);
139
 
140
  out << in.rdbuf();
141
 
142
  if (out.str() != str)
143
    VERIFY( false );
144
}
145
 
146
// libstdc++/6745
147
// libstdc++/8071
148
// libstdc++/8127
149
// Jonathan Lennox  <lennox@cs.columbia.edu>
150
void test05()
151
{
152
  std::wstring string_a(L"Hello, world!");
153
  std::wstring string_b(L"");
154
 
155
  test_buffer_1 buf1a(string_a);
156
  test_buffer_1 buf1b(string_b);
157
 
158
  test_buffer_2 buf2a(string_a);
159
  test_buffer_2 buf2b(string_b);
160
 
161
  test_buffer_3 buf3a(string_a);
162
  test_buffer_3 buf3b(string_b);
163
 
164
  test_buffer_4 buf4a(string_a);
165
  test_buffer_4 buf4b(string_b);
166
 
167
  test(string_a, buf1a);
168
  test(string_b, buf1b);
169
 
170
  test(string_a, buf2a);
171
  test(string_b, buf2b);
172
 
173
  test(string_a, buf3a);
174
  test(string_b, buf3b);
175
 
176
  test(string_a, buf4a);
177
  test(string_b, buf4b);
178
}
179
 
180
int
181
main()
182
{
183
  test05();
184
  return 0;
185
}

powered by: WebSVN 2.1.0

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