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 // pos_type seekpos(pos_type sp,
15 // ios_base::openmode which = ios_base::in | ios_base::out);
16
17 #include <sstream>
18 #include <cassert>
19
20 #include "test_macros.h"
21
main(int,char **)22 int main(int, char**)
23 {
24 {
25 std::stringbuf sb("0123456789", std::ios_base::in);
26 assert(sb.pubseekpos(3, std::ios_base::out) == -1);
27 assert(sb.pubseekpos(3, std::ios_base::in | std::ios_base::out) == -1);
28 assert(sb.pubseekpos(3, std::ios_base::in) == 3);
29 assert(sb.sgetc() == '3');
30 }
31 {
32 std::stringbuf sb("0123456789", std::ios_base::out);
33 assert(sb.pubseekpos(3, std::ios_base::in) == -1);
34 assert(sb.pubseekpos(3, std::ios_base::out | std::ios_base::in) == -1);
35 assert(sb.pubseekpos(3, std::ios_base::out) == 3);
36 assert(sb.sputc('a') == 'a');
37 assert(sb.str() == "012a456789");
38 }
39 {
40 std::stringbuf sb("0123456789");
41 assert(sb.pubseekpos(3, std::ios_base::in) == 3);
42 assert(sb.sgetc() == '3');
43 assert(sb.pubseekpos(3, std::ios_base::out | std::ios_base::in) == 3);
44 assert(sb.sgetc() == '3');
45 assert(sb.sputc('a') == 'a');
46 assert(sb.str() == "012a456789");
47 assert(sb.pubseekpos(3, std::ios_base::out) == 3);
48 assert(sb.sputc('3') == '3');
49 assert(sb.str() == "0123456789");
50 }
51 {
52 std::wstringbuf sb(L"0123456789", std::ios_base::in);
53 assert(sb.pubseekpos(3, std::ios_base::out) == -1);
54 assert(sb.pubseekpos(3, std::ios_base::in | std::ios_base::out) == -1);
55 assert(sb.pubseekpos(3, std::ios_base::in) == 3);
56 assert(sb.sgetc() == L'3');
57 }
58 {
59 std::wstringbuf sb(L"0123456789", std::ios_base::out);
60 assert(sb.pubseekpos(3, std::ios_base::in) == -1);
61 assert(sb.pubseekpos(3, std::ios_base::out | std::ios_base::in) == -1);
62 assert(sb.pubseekpos(3, std::ios_base::out) == 3);
63 assert(sb.sputc(L'a') == L'a');
64 assert(sb.str() == L"012a456789");
65 }
66 {
67 std::wstringbuf sb(L"0123456789");
68 assert(sb.pubseekpos(3, std::ios_base::in) == 3);
69 assert(sb.sgetc() == L'3');
70 assert(sb.pubseekpos(3, std::ios_base::out | std::ios_base::in) == 3);
71 assert(sb.sgetc() == L'3');
72 assert(sb.sputc(L'a') == L'a');
73 assert(sb.str() == L"012a456789");
74 assert(sb.pubseekpos(3, std::ios_base::out) == 3);
75 assert(sb.sputc(L'3') == L'3');
76 assert(sb.str() == L"0123456789");
77 }
78
79 return 0;
80 }
81