1// 2004-06-20  Paolo Carlini  <pcarlini@suse.de>
2
3// Copyright (C) 2004-2015 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// 27.6.1.3 unformatted input functions
21// @require@ %-*.tst %-*.txt
22// @diff@ %-*.tst %-*.txt
23
24// { dg-require-fileio "" }
25
26#include <istream>
27#include <fstream>
28#include <limits>
29#include <testsuite_hooks.h>
30
31// istream& ignore(streamsize n)
32void
33test01()
34{
35  using namespace std;
36  bool test __attribute__((unused)) = true;
37
38  const char filename[] ="istream_unformatted-1.txt";
39  ios_base::iostate state1, state2;
40
41  ifstream ifstrm;
42  ifstrm.open(filename);
43
44  state1 = ifstrm.rdstate();
45  VERIFY( state1 == ios_base::goodbit );
46  VERIFY( ifstrm.peek() == '1' );
47  state2 = ifstrm.rdstate();
48  VERIFY( state1 == state2 );
49
50  state1 = ifstrm.rdstate();
51  ifstrm.ignore(1);
52  VERIFY( ifstrm.gcount() == 1 );
53  state2 = ifstrm.rdstate();
54  VERIFY( state1 == state2 );
55  VERIFY( ifstrm.peek() == '2' );
56
57  state1 = ifstrm.rdstate();
58  ifstrm.ignore(10);
59  VERIFY( ifstrm.gcount() == 10 );
60  state2 = ifstrm.rdstate();
61  VERIFY( state1 == state2 );
62  VERIFY( ifstrm.peek() == '1' );
63
64  state1 = ifstrm.rdstate();
65  ifstrm.ignore(100);
66  VERIFY( ifstrm.gcount() == 100 );
67  state2 = ifstrm.rdstate();
68  VERIFY( state1 == state2 );
69  VERIFY( ifstrm.peek() == '2' );
70
71  state1 = ifstrm.rdstate();
72  ifstrm.ignore(1000);
73  VERIFY( ifstrm.gcount() == 1000 );
74  state2 = ifstrm.rdstate();
75  VERIFY( state1 == state2 );
76  VERIFY( ifstrm.peek() == '1' );
77
78  state1 = ifstrm.rdstate();
79  ifstrm.ignore(10000);
80  VERIFY( ifstrm.gcount() == 10000 );
81  state2 = ifstrm.rdstate();
82  VERIFY( state1 == state2 );
83  VERIFY( ifstrm.peek() == '2' );
84
85  state1 = ifstrm.rdstate();
86  ifstrm.ignore(numeric_limits<streamsize>::max());
87  VERIFY( ifstrm.gcount() == 5389 );
88  state2 = ifstrm.rdstate();
89  VERIFY( state1 != state2 );
90  VERIFY( state2 == ios_base::eofbit );
91}
92
93int
94main()
95{
96  test01();
97  return 0;
98}
99