blob: 4b0a16537d30ee6968a5699093172e189de1ffe3 [file] [log] [blame]
Howard Hinnant3e519522010-05-11 19:42:16 +00001//===----------------------------------------------------------------------===//
2//
3// ÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊÊThe LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10// <fstream>
11
12// int_type pbackfail(int_type c = traits::eof());
13
14// This test is not entirely portable
15
16#include <fstream>
17#include <cassert>
18
19template <class CharT>
20struct test_buf
21 : public std::basic_filebuf<CharT>
22{
23 typedef std::basic_filebuf<CharT> base;
24 typedef typename base::char_type char_type;
25 typedef typename base::int_type int_type;
26 typedef typename base::traits_type traits_type;
27
28 char_type* eback() const {return base::eback();}
29 char_type* gptr() const {return base::gptr();}
30 char_type* egptr() const {return base::egptr();}
31 void gbump(int n) {base::gbump(n);}
32
33 virtual int_type pbackfail(int_type c = traits_type::eof()) {return base::pbackfail(c);}
34};
35
36int main()
37{
38 {
39 test_buf<char> f;
40 assert(f.open("underflow.dat", std::ios_base::in) != 0);
41 assert(f.is_open());
42 assert(f.sbumpc() == '1');
43 assert(f.sgetc() == '2');
44 assert(f.pbackfail('a') == -1);
45 }
46 {
47 test_buf<char> f;
48 assert(f.open("underflow.dat", std::ios_base::in | std::ios_base::out) != 0);
49 assert(f.is_open());
50 assert(f.sbumpc() == '1');
51 assert(f.sgetc() == '2');
52 assert(f.pbackfail('a') == 'a');
53 assert(f.sbumpc() == 'a');
54 assert(f.sgetc() == '2');
55 }
56}