]> git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/24_iterators/ostreambuf_iterator/2.cc
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 24_iterators / ostreambuf_iterator / 2.cc
1 // 2001-04-30 Benjamin Kosnik <bkoz@redhat.com>
2
3 // Copyright (C) 2001-2020 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 3, 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 COPYING3. If not see
18 // <http://www.gnu.org/licenses/>.
19
20 // 24.5.4 template class ostreambuf_iterator
21
22 #include <sstream>
23 #include <iterator>
24 #include <testsuite_hooks.h>
25
26 void test02(void)
27 {
28 typedef std::ostreambuf_iterator<char> costreambuf_iter;
29 typedef costreambuf_iter::streambuf_type cstreambuf_type;
30 const char slit01[] = "playa hermosa, liberia, guanacaste";
31 const char slit02[] = "bodega bay, lost coast, california";
32 std::string str01(slit01);
33 std::string str02(slit02);
34 std::string tmp;
35 std::stringbuf strbuf01;
36 std::stringbuf strbuf02(str01);
37 std::ostringstream ostrs00(str01);
38 std::ostringstream ostrs01(str01);
39
40 // ctor sanity checks
41 costreambuf_iter ostrb_it01(ostrs00);
42 VERIFY( !ostrb_it01.failed() );
43 ostrb_it01++;
44 ++ostrb_it01;
45 VERIFY( !ostrb_it01.failed() );
46 ostrb_it01 = 'a';
47 VERIFY( !ostrb_it01.failed() );
48 *ostrb_it01;
49 VERIFY( !ostrb_it01.failed() );
50
51 costreambuf_iter ostrb_it02(0);
52 VERIFY( ostrb_it02.failed() );
53 ostrb_it02++;
54 ++ostrb_it02;
55 VERIFY( ostrb_it02.failed() );
56 *ostrb_it02;
57 VERIFY( ostrb_it02.failed() );
58 ostrb_it02 = 'a';
59 VERIFY( ostrb_it02.failed() );
60
61 // charT operator*() const
62 // ostreambuf_iterator& operator++();
63 // ostreambuf_iterator& operator++(int);
64 costreambuf_iter ostrb_it27(ostrs01);
65 VERIFY( !ostrb_it27.failed() );
66 int j = str02.size();
67 for (int i = 0; i < j; ++i)
68 ostrb_it27 = str02[i];
69 VERIFY( !ostrb_it27.failed() );
70 tmp = ostrs01.str();
71 VERIFY ( tmp != str01 );
72 VERIFY ( tmp == str02 );
73
74 costreambuf_iter ostrb_it28(ostrs00);
75 VERIFY( !ostrb_it28.failed() );
76 j = ostrs00.str().size();
77 for (int i = 0; i < j + 2; ++i)
78 ostrb_it28 = 'b';
79 VERIFY( !ostrb_it28.failed() );
80 tmp = ostrs00.str();
81 VERIFY ( tmp != str01 );
82 VERIFY ( tmp != str02 );
83 }
84
85 int main()
86 {
87 test02();
88 return 0;
89 }