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