aboutsummaryrefslogtreecommitdiff
path: root/libstdc++-v3/testsuite/24_iterators/istreambuf_iterator.cc
blob: 78d36331604ea1accd22d1b93c2c753ff4e7111f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
// 1999-06-28 bkoz

// Copyright (C) 1999 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library.  This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 2, or (at your option)
// any later version.

// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License along
// with this library; see the file COPYING.  If not, write to the Free
// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
// USA.

// 24.5.3 template class istreambuf_iterator

#include <sstream>
#include <iterator>
#include <debug_assert.h>

bool test01(void)
{

  typedef std::istreambuf_iterator<char> cistreambuf_iter;
  typedef cistreambuf_iter::streambuf_type cstreambuf_type;
  bool test = true;
  const char slit01[] = "playa hermosa, liberia, guanacaste";
  std::string str01(slit01);
  std::istringstream istrs00(str01);
  std::istringstream istrs01(str01);

  // ctor sanity checks
  cistreambuf_iter istrb_it01(istrs00);
  cistreambuf_iter istrb_it02;
  std::string tmp(istrb_it01, istrb_it02); 
  VERIFY( tmp == str01 );

  cistreambuf_iter istrb_it03(0);
  cistreambuf_iter istrb_it04;
  VERIFY( istrb_it03 == istrb_it04 );

  cistreambuf_iter istrb_it05(istrs01);
  cistreambuf_iter istrb_it06(istrs01.rdbuf());
  VERIFY( istrb_it05 == istrb_it06 );
  
  // bool equal(istreambuf_iter& b)
  cistreambuf_iter istrb_it07(0);
  cistreambuf_iter istrb_it08;
  VERIFY( istrb_it07.equal(istrb_it08) );
  cistreambuf_iter istrb_it09(0);
  cistreambuf_iter istrb_it10;
  VERIFY( istrb_it10.equal(istrb_it09) );

  cistreambuf_iter istrb_it11(istrs01);
  cistreambuf_iter istrb_it12(istrs01.rdbuf());
  VERIFY( istrb_it11.equal(istrb_it12) );
  cistreambuf_iter istrb_it13(istrs01);
  cistreambuf_iter istrb_it14(istrs01.rdbuf());
  VERIFY( istrb_it14.equal(istrb_it13) );

  cistreambuf_iter istrb_it15(istrs01);
  cistreambuf_iter istrb_it16;
  VERIFY( !(istrb_it15.equal(istrb_it16)) );
  cistreambuf_iter istrb_it17(istrs01);
  cistreambuf_iter istrb_it18;
  VERIFY( !(istrb_it18.equal(istrb_it17)) );

  // bool operator==(const istreambuf_iterator&a, const istreambuf_iterator& b)
  // bool operator!=(const istreambuf_iterator&a, const istreambuf_iterator& b)
  cistreambuf_iter istrb_it19(0);
  cistreambuf_iter istrb_it20;
  VERIFY( istrb_it19 == istrb_it20 );

  cistreambuf_iter istrb_it21(istrs01);
  cistreambuf_iter istrb_it22(istrs01.rdbuf());
  VERIFY( istrb_it22 == istrb_it21 );

  cistreambuf_iter istrb_it23(istrs01);
  cistreambuf_iter istrb_it24;
  VERIFY( istrb_it23 != istrb_it24 );

  cistreambuf_iter istrb_it25(0);
  cistreambuf_iter istrb_it26(istrs01.rdbuf());
  VERIFY( istrb_it25 != istrb_it26 );

  // charT operator*() const
  // istreambuf_iterator& operator++();
  // istreambuf_iterator& operator++(int);
  cistreambuf_iter istrb_it27(istrs01.rdbuf());
  char c;
  for (int i = 0; i < sizeof(slit01) - 2; ++i)
    {
      c = *istrb_it27++;
      VERIFY( c == slit01[i] );
    }

  std::istringstream istrs02(str01);
  cistreambuf_iter istrb_it28(istrs02);
  for (int i = 0; i < sizeof(slit01) - 3;)
    {
      c = *++istrb_it28;
      VERIFY( c == slit01[++i] );
    }

#ifdef DEBUG_ASSERT
  assert(test);
#endif

  return test;
}

int main()
{
  test01();

  return 0;
}