Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1 | //===----------------------------------------------------------------------===// |
| 2 | // |
Howard Hinnant | f5256e1 | 2010-05-11 21:36:01 +0000 | [diff] [blame] | 3 | // The LLVM Compiler Infrastructure |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4 | // |
Howard Hinnant | b64f8b0 | 2010-11-16 22:09:02 +0000 | [diff] [blame] | 5 | // This file is dual licensed under the MIT and the University of Illinois Open |
| 6 | // Source Licenses. See LICENSE.TXT for details. |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
Howard Hinnant | bc8d3f9 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 10 | // <ostream> |
| 11 | |
| 12 | // template <class charT, class traits = char_traits<charT> > |
| 13 | // class basic_ostream::sentry; |
| 14 | |
| 15 | // ~sentry(); |
| 16 | |
| 17 | #include <ostream> |
| 18 | #include <cassert> |
| 19 | |
| 20 | int sync_called = 0; |
| 21 | |
| 22 | template <class CharT> |
| 23 | struct testbuf1 |
| 24 | : public std::basic_streambuf<CharT> |
| 25 | { |
| 26 | testbuf1() {} |
| 27 | |
| 28 | protected: |
| 29 | |
| 30 | int virtual sync() |
| 31 | { |
| 32 | ++sync_called; |
| 33 | return 1; |
| 34 | } |
| 35 | }; |
| 36 | |
| 37 | int main() |
| 38 | { |
| 39 | { |
| 40 | std::ostream os((std::streambuf*)0); |
| 41 | std::ostream::sentry s(os); |
| 42 | assert(!bool(s)); |
| 43 | } |
| 44 | assert(sync_called == 0); |
| 45 | { |
| 46 | testbuf1<char> sb; |
| 47 | std::ostream os(&sb); |
| 48 | std::ostream::sentry s(os); |
| 49 | assert(bool(s)); |
| 50 | } |
| 51 | assert(sync_called == 0); |
| 52 | { |
| 53 | testbuf1<char> sb; |
| 54 | std::ostream os(&sb); |
| 55 | std::ostream::sentry s(os); |
| 56 | assert(bool(s)); |
| 57 | unitbuf(os); |
| 58 | } |
| 59 | assert(sync_called == 1); |
| 60 | { |
| 61 | testbuf1<char> sb; |
| 62 | std::ostream os(&sb); |
| 63 | try |
| 64 | { |
| 65 | std::ostream::sentry s(os); |
| 66 | assert(bool(s)); |
| 67 | unitbuf(os); |
| 68 | throw 1; |
| 69 | } |
| 70 | catch (...) |
| 71 | { |
| 72 | } |
| 73 | assert(sync_called == 1); |
| 74 | } |
| 75 | } |