Dead
[official-gcc.git] / gomp-20050608-branch / libstdc++-v3 / testsuite / 27_io / basic_ostream / inserters_other / wchar_t / 4.cc
blobcf2c8bc9f2ad8442af2510145a6a7240619f3ff9
1 // 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.
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.
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.
19 // 27.6.2.5.4 basic_ostream character inserters
21 #include <ostream>
22 #include <sstream>
23 #include <testsuite_hooks.h>
25 class test_buffer_1 : public std::wstreambuf
27 public:
28 test_buffer_1(const std::wstring& s)
29 : str(s), it(str.begin()) { }
31 protected:
32 virtual int_type
33 underflow()
34 { return (it != str.end() ? *it : WEOF); }
36 virtual int_type
37 uflow()
38 { return (it != str.end() ? *it++ : WEOF); }
40 private:
41 const std::wstring str;
42 std::wstring::const_iterator it;
46 class test_buffer_2 : public std::wstreambuf
48 public:
49 test_buffer_2(const std::wstring& s)
50 : str(s), it(str.begin()) { }
52 protected:
53 virtual int_type
54 underflow()
55 { return (it != str.end() ? *it : WEOF); }
57 virtual int_type
58 uflow()
59 { return (it != str.end() ? *it++ : WEOF); }
61 virtual std::streamsize
62 showmanyc()
63 { return std::distance(it, str.end()); }
65 private:
66 const std::wstring str;
67 std::wstring::const_iterator it;
71 class test_buffer_3 : public std::wstreambuf
73 public:
74 test_buffer_3(const std::wstring& s)
75 : str(s), it(str.begin()) { }
77 protected:
78 virtual int_type
79 underflow()
80 { return (it != str.end() ? *it : WEOF); }
82 virtual int_type
83 uflow()
84 { return (it != str.end() ? *it++ : WEOF); }
86 virtual std::streamsize
87 showmanyc()
89 std::streamsize ret = std::distance(it, str.end());
90 return ret > 0 ? ret : -1;
93 private:
94 const std::wstring str;
95 std::wstring::const_iterator it;
98 class test_buffer_4 : public std::wstreambuf
100 public:
101 test_buffer_4(const std::wstring& s)
102 : str(s), it(str.begin())
104 if (it != str.end())
106 buf[0] = *it++;
107 setg(buf, buf, buf+1);
111 protected:
112 virtual int_type
113 underflow()
114 { return (it != str.end() ? *it : WEOF); }
116 virtual int_type
117 uflow()
118 { return (it != str.end() ? *it++ : WEOF); }
120 virtual std::streamsize
121 showmanyc()
123 std::streamsize ret = std::distance(it, str.end());
124 return ret > 0 ? ret : -1;
127 private:
128 const std::wstring str;
129 std::wstring::const_iterator it;
130 wchar_t buf[1];
133 void test(const std::wstring& str, std::wstreambuf& buf)
135 bool test __attribute__((unused)) = true;
137 std::wostringstream out;
138 std::wistream in(&buf);
140 out << in.rdbuf();
142 if (out.str() != str)
143 VERIFY( false );
146 // libstdc++/6745
147 // libstdc++/8071
148 // libstdc++/8127
149 // Jonathan Lennox <lennox@cs.columbia.edu>
150 void test05()
152 std::wstring string_a(L"Hello, world!");
153 std::wstring string_b(L"");
155 test_buffer_1 buf1a(string_a);
156 test_buffer_1 buf1b(string_b);
158 test_buffer_2 buf2a(string_a);
159 test_buffer_2 buf2b(string_b);
161 test_buffer_3 buf3a(string_a);
162 test_buffer_3 buf3b(string_b);
164 test_buffer_4 buf4a(string_a);
165 test_buffer_4 buf4b(string_b);
167 test(string_a, buf1a);
168 test(string_b, buf1b);
170 test(string_a, buf2a);
171 test(string_b, buf2b);
173 test(string_a, buf3a);
174 test(string_b, buf3b);
176 test(string_a, buf4a);
177 test(string_b, buf4b);
180 int
181 main()
183 test05();
184 return 0;