| 1 | //===----------------------------------------------------------------------===// |
| 2 | // |
| 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | // See https://llvm.org/LICENSE.txt for license information. |
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | |
| 9 | // <sstream> |
| 10 | |
| 11 | // template <class charT, class traits = char_traits<charT>, class Allocator = allocator<charT> > |
| 12 | // class basic_stringbuf |
| 13 | |
| 14 | // template <class charT, class traits, class Allocator> |
| 15 | // void swap(basic_stringbuf<charT, traits, Allocator>& x, |
| 16 | // basic_stringbuf<charT, traits, Allocator>& y); |
| 17 | |
| 18 | #include <sstream> |
| 19 | #include <cassert> |
| 20 | |
| 21 | #include "test_macros.h" |
| 22 | |
| 23 | int main(int, char**) |
| 24 | { |
| 25 | { |
| 26 | std::stringbuf buf1("testing" ); |
| 27 | std::stringbuf buf; |
| 28 | swap(buf, buf1); |
| 29 | assert(buf.str() == "testing" ); |
| 30 | assert(buf1.str() == "" ); |
| 31 | } |
| 32 | { |
| 33 | std::stringbuf buf1("testing" , std::ios_base::in); |
| 34 | std::stringbuf buf; |
| 35 | swap(buf, buf1); |
| 36 | assert(buf.str() == "testing" ); |
| 37 | assert(buf1.str() == "" ); |
| 38 | } |
| 39 | { |
| 40 | std::stringbuf buf1("testing" , std::ios_base::out); |
| 41 | std::stringbuf buf; |
| 42 | swap(buf, buf1); |
| 43 | assert(buf.str() == "testing" ); |
| 44 | assert(buf1.str() == "" ); |
| 45 | } |
| 46 | #ifndef TEST_HAS_NO_WIDE_CHARACTERS |
| 47 | { |
| 48 | std::wstringbuf buf1(L"testing" ); |
| 49 | std::wstringbuf buf; |
| 50 | swap(buf, buf1); |
| 51 | assert(buf.str() == L"testing" ); |
| 52 | assert(buf1.str() == L"" ); |
| 53 | } |
| 54 | { |
| 55 | std::wstringbuf buf1(L"testing" , std::ios_base::in); |
| 56 | std::wstringbuf buf; |
| 57 | swap(buf, buf1); |
| 58 | assert(buf.str() == L"testing" ); |
| 59 | assert(buf1.str() == L"" ); |
| 60 | } |
| 61 | { |
| 62 | std::wstringbuf buf1(L"testing" , std::ios_base::out); |
| 63 | std::wstringbuf buf; |
| 64 | swap(buf, buf1); |
| 65 | assert(buf.str() == L"testing" ); |
| 66 | assert(buf1.str() == L"" ); |
| 67 | } |
| 68 | #endif // TEST_HAS_NO_WIDE_CHARACTERS |
| 69 | |
| 70 | return 0; |
| 71 | } |
| 72 | |