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