1 //===----------------------------------------------------------------------===//
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
7 //===----------------------------------------------------------------------===//
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);
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
) {
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);
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);
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");
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");