1 //===----------------------------------------------------------------------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9
10 // <sstream>
11
12 // template <class charT, class traits = char_traits<charT>, class Allocator = allocator<charT> >
13 // class basic_stringbuf
14
15 // pos_type seekpos(pos_type sp,
16 // ios_base::openmode which = ios_base::in | ios_base::out);
17
18 #include <sstream>
19 #include <cassert>
20
main()21 int main()
22 {
23 {
24 std::stringbuf sb("0123456789", std::ios_base::in);
25 assert(sb.pubseekpos(3, std::ios_base::out) == -1);
26 assert(sb.pubseekpos(3, std::ios_base::in | std::ios_base::out) == -1);
27 assert(sb.pubseekpos(3, std::ios_base::in) == 3);
28 assert(sb.sgetc() == '3');
29 }
30 {
31 std::stringbuf sb("0123456789", std::ios_base::out);
32 assert(sb.pubseekpos(3, std::ios_base::in) == -1);
33 assert(sb.pubseekpos(3, std::ios_base::out | std::ios_base::in) == -1);
34 assert(sb.pubseekpos(3, std::ios_base::out) == 3);
35 assert(sb.sputc('a') == 'a');
36 assert(sb.str() == "012a456789");
37 }
38 {
39 std::stringbuf sb("0123456789");
40 assert(sb.pubseekpos(3, std::ios_base::in) == 3);
41 assert(sb.sgetc() == '3');
42 assert(sb.pubseekpos(3, std::ios_base::out | std::ios_base::in) == 3);
43 assert(sb.sgetc() == '3');
44 assert(sb.sputc('a') == 'a');
45 assert(sb.str() == "012a456789");
46 assert(sb.pubseekpos(3, std::ios_base::out) == 3);
47 assert(sb.sputc('3') == '3');
48 assert(sb.str() == "0123456789");
49 }
50 {
51 std::wstringbuf sb(L"0123456789", std::ios_base::in);
52 assert(sb.pubseekpos(3, std::ios_base::out) == -1);
53 assert(sb.pubseekpos(3, std::ios_base::in | std::ios_base::out) == -1);
54 assert(sb.pubseekpos(3, std::ios_base::in) == 3);
55 assert(sb.sgetc() == L'3');
56 }
57 {
58 std::wstringbuf sb(L"0123456789", std::ios_base::out);
59 assert(sb.pubseekpos(3, std::ios_base::in) == -1);
60 assert(sb.pubseekpos(3, std::ios_base::out | std::ios_base::in) == -1);
61 assert(sb.pubseekpos(3, std::ios_base::out) == 3);
62 assert(sb.sputc(L'a') == L'a');
63 assert(sb.str() == L"012a456789");
64 }
65 {
66 std::wstringbuf sb(L"0123456789");
67 assert(sb.pubseekpos(3, std::ios_base::in) == 3);
68 assert(sb.sgetc() == L'3');
69 assert(sb.pubseekpos(3, std::ios_base::out | std::ios_base::in) == 3);
70 assert(sb.sgetc() == L'3');
71 assert(sb.sputc(L'a') == L'a');
72 assert(sb.str() == L"012a456789");
73 assert(sb.pubseekpos(3, std::ios_base::out) == 3);
74 assert(sb.sputc(L'3') == L'3');
75 assert(sb.str() == L"0123456789");
76 }
77 }
78