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