blob: b04b8b0acc91a9b25da1cd54cb66728a338d0267 [file] [log] [blame]
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001//===----------------------------------------------------------------------===//
2//
Howard Hinnantf5256e12010-05-11 21:36:01 +00003// The LLVM Compiler Infrastructure
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004//
Howard Hinnantb64f8b02010-11-16 22:09:02 +00005// This file is dual licensed under the MIT and the University of Illinois Open
6// Source Licenses. See LICENSE.TXT for details.
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00007//
8//===----------------------------------------------------------------------===//
9
10// <streambuf>
11
12// template <class charT, class traits = char_traits<charT> >
13// class basic_streambuf;
14
15// int_type sputc(char_type c);
16
17#include <streambuf>
18#include <cassert>
19
20int overflow_called = 0;
21
22struct test
23 : public std::basic_streambuf<char>
24{
25 typedef std::basic_streambuf<char> base;
26
27 test() {}
28
29 void setg(char* gbeg, char* gnext, char* gend)
30 {
31 base::setg(gbeg, gnext, gend);
32 }
33 void setp(char* pbeg, char* pend)
34 {
35 base::setp(pbeg, pend);
36 }
37
38protected:
Dan Albert1d4a1ed2016-05-25 22:36:09 -070039 int_type overflow(int_type c = traits_type::eof())
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000040 {
41 ++overflow_called;
42 return 'a';
43 }
44};
45
46int main()
47{
48 {
49 test t;
50 assert(overflow_called == 0);
51 assert(t.sputc('A') == 'a');
52 assert(overflow_called == 1);
53 char out[3] = {0};
54 t.setp(out, out+sizeof(out));
55 assert(t.sputc('A') == 'A');
56 assert(overflow_called == 1);
57 assert(out[0] == 'A');
58 assert(t.sputc('B') == 'B');
59 assert(overflow_called == 1);
60 assert(out[0] == 'A');
61 assert(out[1] == 'B');
62 }
63}