1 //===----------------------------------------------------------------------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 
10 // <streambuf>
11 
12 // template <class charT, class traits = char_traits<charT> >
13 // class basic_streambuf;
14 
15 // void pbump(int n);
16 //
17 // REQUIRES: long_tests
18 
19 #include <sstream>
20 #include <cassert>
21 #include "test_macros.h"
22 
23 struct SB : std::stringbuf
24 {
25   SB() : std::stringbuf(std::ios::ate|std::ios::out) { }
26   const char* pubpbase() const { return pbase(); }
27   const char* pubpptr() const { return pptr(); }
28 };
29 
30 int main()
31 {
32 #ifndef TEST_HAS_NO_EXCEPTIONS
33     try {
34 #endif
35         std::string str(2147483648, 'a');
36         SB sb;
37         sb.str(str);
38         assert(sb.pubpbase() <= sb.pubpptr());
39 #ifndef TEST_HAS_NO_EXCEPTIONS
40     }
41     catch (const std::length_error &) {} // maybe the string can't take 2GB
42     catch (const std::bad_alloc    &) {} // maybe we don't have enough RAM
43 #endif
44 }
45