]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/testsuite/24_iterators/istreambuf_iterator.cc
acinclude.m4 (GLIBCPP_CONFIGURE_TESTSUITE): New macro, calls...
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 24_iterators / istreambuf_iterator.cc
CommitLineData
b2dad0e3
BK
1// 1999-06-28 bkoz
2
a85afd69 3// Copyright (C) 1999, 2001 Free Software Foundation, Inc.
b2dad0e3
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
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, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
19// USA.
20
21// 24.5.3 template class istreambuf_iterator
22
23#include <sstream>
24#include <iterator>
fe413112 25#include <testsuite_hooks.h>
b2dad0e3 26
b581eaf7
BK
27void test01()
28{
29 using namespace std;
30
31 // Check for required base class.
32 typedef istreambuf_iterator<char> test_iterator;
33 typedef char_traits<char>::off_type off_type;
34 typedef iterator<input_iterator_tag, char, off_type, char*, char&> base_iterator;
35
36 istringstream isstream("this tag");
37 test_iterator r_it(isstream);
38 base_iterator* base = &r_it;
39
40 // Check for required typedefs
41 typedef test_iterator::value_type value_type;
42 typedef test_iterator::difference_type difference_type;
43 typedef test_iterator::pointer pointer;
44 typedef test_iterator::reference reference;
45 typedef test_iterator::iterator_category iteratory_category;
46
47 typedef test_iterator::char_type char_type;
48 typedef test_iterator::traits_type traits_type;
49 typedef test_iterator::istream_type istream_type;
50 typedef test_iterator::streambuf_type streambuf_type;
51}
52
53bool test02(void)
b2dad0e3
BK
54{
55
56 typedef std::istreambuf_iterator<char> cistreambuf_iter;
57 typedef cistreambuf_iter::streambuf_type cstreambuf_type;
58 bool test = true;
59 const char slit01[] = "playa hermosa, liberia, guanacaste";
60 std::string str01(slit01);
61 std::istringstream istrs00(str01);
62 std::istringstream istrs01(str01);
63
64 // ctor sanity checks
65 cistreambuf_iter istrb_it01(istrs00);
66 cistreambuf_iter istrb_it02;
67 std::string tmp(istrb_it01, istrb_it02);
aa1b2f7d 68 VERIFY( tmp == str01 );
b2dad0e3
BK
69
70 cistreambuf_iter istrb_it03(0);
71 cistreambuf_iter istrb_it04;
aa1b2f7d 72 VERIFY( istrb_it03 == istrb_it04 );
b2dad0e3
BK
73
74 cistreambuf_iter istrb_it05(istrs01);
75 cistreambuf_iter istrb_it06(istrs01.rdbuf());
aa1b2f7d 76 VERIFY( istrb_it05 == istrb_it06 );
b2dad0e3
BK
77
78 // bool equal(istreambuf_iter& b)
79 cistreambuf_iter istrb_it07(0);
80 cistreambuf_iter istrb_it08;
aa1b2f7d 81 VERIFY( istrb_it07.equal(istrb_it08) );
b2dad0e3
BK
82 cistreambuf_iter istrb_it09(0);
83 cistreambuf_iter istrb_it10;
aa1b2f7d 84 VERIFY( istrb_it10.equal(istrb_it09) );
b2dad0e3
BK
85
86 cistreambuf_iter istrb_it11(istrs01);
87 cistreambuf_iter istrb_it12(istrs01.rdbuf());
aa1b2f7d 88 VERIFY( istrb_it11.equal(istrb_it12) );
b2dad0e3
BK
89 cistreambuf_iter istrb_it13(istrs01);
90 cistreambuf_iter istrb_it14(istrs01.rdbuf());
aa1b2f7d 91 VERIFY( istrb_it14.equal(istrb_it13) );
b2dad0e3
BK
92
93 cistreambuf_iter istrb_it15(istrs01);
94 cistreambuf_iter istrb_it16;
aa1b2f7d 95 VERIFY( !(istrb_it15.equal(istrb_it16)) );
b2dad0e3
BK
96 cistreambuf_iter istrb_it17(istrs01);
97 cistreambuf_iter istrb_it18;
aa1b2f7d 98 VERIFY( !(istrb_it18.equal(istrb_it17)) );
b2dad0e3
BK
99
100 // bool operator==(const istreambuf_iterator&a, const istreambuf_iterator& b)
101 // bool operator!=(const istreambuf_iterator&a, const istreambuf_iterator& b)
102 cistreambuf_iter istrb_it19(0);
103 cistreambuf_iter istrb_it20;
aa1b2f7d 104 VERIFY( istrb_it19 == istrb_it20 );
b2dad0e3
BK
105
106 cistreambuf_iter istrb_it21(istrs01);
107 cistreambuf_iter istrb_it22(istrs01.rdbuf());
aa1b2f7d 108 VERIFY( istrb_it22 == istrb_it21 );
b2dad0e3
BK
109
110 cistreambuf_iter istrb_it23(istrs01);
111 cistreambuf_iter istrb_it24;
aa1b2f7d 112 VERIFY( istrb_it23 != istrb_it24 );
b2dad0e3
BK
113
114 cistreambuf_iter istrb_it25(0);
115 cistreambuf_iter istrb_it26(istrs01.rdbuf());
aa1b2f7d 116 VERIFY( istrb_it25 != istrb_it26 );
b2dad0e3
BK
117
118 // charT operator*() const
119 // istreambuf_iterator& operator++();
120 // istreambuf_iterator& operator++(int);
121 cistreambuf_iter istrb_it27(istrs01.rdbuf());
122 char c;
123 for (int i = 0; i < sizeof(slit01) - 2; ++i)
124 {
125 c = *istrb_it27++;
aa1b2f7d 126 VERIFY( c == slit01[i] );
b2dad0e3
BK
127 }
128
129 std::istringstream istrs02(str01);
130 cistreambuf_iter istrb_it28(istrs02);
a85afd69 131 for (int i = 0; i < sizeof(slit01) - 2;)
b2dad0e3
BK
132 {
133 c = *++istrb_it28;
aa1b2f7d 134 VERIFY( c == slit01[++i] );
b2dad0e3
BK
135 }
136
137#ifdef DEBUG_ASSERT
138 assert(test);
139#endif
140
141 return test;
142}
143
a85afd69 144// libstdc++/2627
b581eaf7 145void test03()
a85afd69
BK
146{
147 bool test = true;
148 const std::string s("free the vieques");
149
150 // 1
151 std::string res_postfix;
152 std::istringstream iss01(s);
153 std::istreambuf_iterator<char> isbufit01(iss01);
154 for (int j = 0; j < s.size(); ++j, isbufit01++)
155 res_postfix += *isbufit01;
156
157 // 2
158 std::string res_prefix;
159 std::istringstream iss02(s);
160 std::istreambuf_iterator<char> isbufit02(iss02);
161 for (int j = 0; j < s.size(); ++j, ++isbufit02)
162 res_prefix += *isbufit02;
163
164 // 3 mixed
165 std::string res_mixed;
166 std::istringstream iss03(s);
167 std::istreambuf_iterator<char> isbufit03(iss03);
168 for (int j = 0; j < int(s.size() / 2); ++j)
169 {
170 res_mixed += *isbufit03;
171 ++isbufit03;
172 res_mixed += *isbufit03;
173 isbufit03++;
174 }
175
176 VERIFY ( res_postfix == res_prefix );
177 VERIFY ( res_mixed == res_prefix );
178}
179
b2dad0e3
BK
180int main()
181{
182 test01();
a85afd69 183 test02();
b581eaf7 184 test03();
b2dad0e3
BK
185 return 0;
186}