[libc++][doc] Updates format status.
[llvm-project.git] / libcxx / test / std / input.output / string.streams / stringbuf / stringbuf.members / str.pass.cpp
blob8cd3840b6841f785f38953dbfaa5e71b8cf6f45d
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 //===----------------------------------------------------------------------===//
9 // <sstream>
11 // template <class charT, class traits = char_traits<charT>, class Allocator = allocator<charT> >
12 // class basic_stringbuf
14 // void str(const basic_string<charT,traits,Allocator>& s);
16 #include <sstream>
17 #include <string>
18 #include <cassert>
20 #include "test_macros.h"
22 struct StringBuf : std::stringbuf {
23 explicit StringBuf(const char* s, std::ios_base::openmode mode) : basic_stringbuf(s, mode) {}
24 void public_setg(int a, int b, int c) {
25 char* p = eback();
26 this->setg(p + a, p + b, p + c);
30 static void test_altered_sequence_pointers() {
32 StringBuf src("hello world", std::ios_base::in);
33 src.public_setg(4, 6, 9);
34 std::stringbuf dest;
35 dest = std::move(src);
36 std::string str = dest.str();
37 assert(5 <= str.size() && str.size() <= 11);
38 LIBCPP_ASSERT(str == "o wor");
39 LIBCPP_ASSERT(dest.str() == "o wor");
42 StringBuf src("hello world", std::ios_base::in);
43 src.public_setg(4, 6, 9);
44 std::stringbuf dest;
45 dest.swap(src);
46 std::string str = dest.str();
47 assert(5 <= str.size() && str.size() <= 11);
48 LIBCPP_ASSERT(str == "o wor");
49 LIBCPP_ASSERT(dest.str() == "o wor");
53 int main(int, char**)
55 test_altered_sequence_pointers();
57 std::stringbuf buf("testing");
58 assert(buf.str() == "testing");
59 buf.str("another test");
60 assert(buf.str() == "another test");
62 #ifndef TEST_HAS_NO_WIDE_CHARACTERS
64 std::wstringbuf buf(L"testing");
65 assert(buf.str() == L"testing");
66 buf.str(L"another test");
67 assert(buf.str() == L"another test");
69 #endif
71 return 0;