[RISCV] Improve Errors for X1/X5/X1X5 Reg Classes (#126184)
[llvm-project.git] / libcxx / test / std / input.output / string.streams / stringbuf / stringbuf.virtuals / seekoff.pass.cpp
blob2bd558557e83378dfef4a0c021e601163d5f7295
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 // pos_type seekoff(off_type off, ios_base::seekdir way,
15 // ios_base::openmode which = ios_base::in | ios_base::out);
17 #include <sstream>
18 #include <cassert>
20 #include "test_macros.h"
22 int main(int, char**)
25 std::stringbuf sb(std::ios_base::in);
26 assert(sb.pubseekoff(3, std::ios_base::beg, std::ios_base::out) == -1);
27 assert(sb.pubseekoff(3, std::ios_base::cur, std::ios_base::out) == -1);
28 assert(sb.pubseekoff(-3, std::ios_base::end, std::ios_base::out) == -1);
29 assert(sb.pubseekoff(3, std::ios_base::beg, std::ios_base::in | std::ios_base::out) == -1);
30 assert(sb.pubseekoff(3, std::ios_base::cur, std::ios_base::in | std::ios_base::out) == -1);
31 assert(sb.pubseekoff(-3, std::ios_base::end, std::ios_base::in | std::ios_base::out) == -1);
32 assert(sb.pubseekoff(0, std::ios_base::beg, std::ios_base::in) == 0);
33 assert(sb.pubseekoff(0, std::ios_base::cur, std::ios_base::in) == 0);
34 assert(sb.pubseekoff(0, std::ios_base::end, std::ios_base::in) == 0);
37 std::stringbuf sb(std::ios_base::out);
38 assert(sb.pubseekoff(3, std::ios_base::beg, std::ios_base::in) == -1);
39 assert(sb.pubseekoff(3, std::ios_base::cur, std::ios_base::in) == -1);
40 assert(sb.pubseekoff(-3, std::ios_base::end, std::ios_base::in) == -1);
41 assert(sb.pubseekoff(3, std::ios_base::beg, std::ios_base::in | std::ios_base::out) == -1);
42 assert(sb.pubseekoff(3, std::ios_base::cur, std::ios_base::in | std::ios_base::out) == -1);
43 assert(sb.pubseekoff(-3, std::ios_base::end, std::ios_base::in | std::ios_base::out) == -1);
44 assert(sb.pubseekoff(0, std::ios_base::beg, std::ios_base::out) == 0);
45 assert(sb.pubseekoff(0, std::ios_base::cur, std::ios_base::out) == 0);
46 assert(sb.pubseekoff(0, std::ios_base::end, std::ios_base::out) == 0);
49 std::stringbuf sb("0123456789", std::ios_base::in);
50 assert(sb.pubseekoff(3, std::ios_base::beg, std::ios_base::out) == -1);
51 assert(sb.pubseekoff(3, std::ios_base::cur, std::ios_base::out) == -1);
52 assert(sb.pubseekoff(-3, std::ios_base::end, std::ios_base::out) == -1);
53 assert(sb.pubseekoff(3, std::ios_base::beg, std::ios_base::in | std::ios_base::out) == -1);
54 assert(sb.pubseekoff(3, std::ios_base::cur, std::ios_base::in | std::ios_base::out) == -1);
55 assert(sb.pubseekoff(-3, std::ios_base::end, std::ios_base::in | std::ios_base::out) == -1);
56 assert(sb.pubseekoff(3, std::ios_base::beg, std::ios_base::in) == 3);
57 assert(sb.sgetc() == '3');
58 assert(sb.pubseekoff(3, std::ios_base::cur, std::ios_base::in) == 6);
59 assert(sb.sgetc() == '6');
60 assert(sb.pubseekoff(-3, std::ios_base::end, std::ios_base::in) == 7);
61 assert(sb.sgetc() == '7');
64 std::stringbuf sb("0123456789", std::ios_base::out);
65 assert(sb.pubseekoff(3, std::ios_base::beg, std::ios_base::in) == -1);
66 assert(sb.pubseekoff(3, std::ios_base::cur, std::ios_base::in) == -1);
67 assert(sb.pubseekoff(-3, std::ios_base::end, std::ios_base::in) == -1);
68 assert(sb.pubseekoff(3, std::ios_base::beg, std::ios_base::out | std::ios_base::in) == -1);
69 assert(sb.pubseekoff(3, std::ios_base::cur, std::ios_base::out | std::ios_base::in) == -1);
70 assert(sb.pubseekoff(-3, std::ios_base::end, std::ios_base::out | std::ios_base::in) == -1);
71 assert(sb.pubseekoff(3, std::ios_base::beg, std::ios_base::out) == 3);
72 assert(sb.sputc('a') == 'a');
73 assert(sb.str() == "012a456789");
74 assert(sb.pubseekoff(3, std::ios_base::cur, std::ios_base::out) == 7);
75 assert(sb.sputc('b') == 'b');
76 assert(sb.str() == "012a456b89");
77 assert(sb.pubseekoff(-3, std::ios_base::end, std::ios_base::out) == 7);
78 assert(sb.sputc('c') == 'c');
79 assert(sb.str() == "012a456c89");
82 std::stringbuf sb("0123456789");
83 assert(sb.pubseekoff(3, std::ios_base::beg, std::ios_base::in) == 3);
84 assert(sb.sgetc() == '3');
85 assert(sb.pubseekoff(3, std::ios_base::cur, std::ios_base::in) == 6);
86 assert(sb.sgetc() == '6');
87 assert(sb.pubseekoff(-3, std::ios_base::end, std::ios_base::in) == 7);
88 assert(sb.sgetc() == '7');
89 assert(sb.pubseekoff(3, std::ios_base::beg, std::ios_base::out | std::ios_base::in) == 3);
90 assert(sb.sgetc() == '3');
91 assert(sb.sputc('a') == 'a');
92 assert(sb.str() == "012a456789");
93 assert(sb.pubseekoff(3, std::ios_base::cur, std::ios_base::out | std::ios_base::in) == -1);
94 assert(sb.pubseekoff(-3, std::ios_base::end, std::ios_base::out | std::ios_base::in) == 7);
95 assert(sb.sgetc() == '7');
96 assert(sb.sputc('c') == 'c');
97 assert(sb.str() == "012a456c89");
98 assert(sb.pubseekoff(3, std::ios_base::beg, std::ios_base::out) == 3);
99 assert(sb.sputc('3') == '3');
100 assert(sb.str() == "0123456c89");
101 assert(sb.pubseekoff(3, std::ios_base::cur, std::ios_base::out) == 7);
102 assert(sb.sputc('7') == '7');
103 assert(sb.str() == "0123456789");
104 assert(sb.pubseekoff(-3, std::ios_base::end, std::ios_base::out) == 7);
105 assert(sb.sputc('c') == 'c');
106 assert(sb.str() == "0123456c89");
108 #ifndef TEST_HAS_NO_WIDE_CHARACTERS
110 std::wstringbuf sb(L"0123456789", std::ios_base::in);
111 assert(sb.pubseekoff(3, std::ios_base::beg, std::ios_base::out) == -1);
112 assert(sb.pubseekoff(3, std::ios_base::cur, std::ios_base::out) == -1);
113 assert(sb.pubseekoff(-3, std::ios_base::end, std::ios_base::out) == -1);
114 assert(sb.pubseekoff(3, std::ios_base::beg, std::ios_base::in | std::ios_base::out) == -1);
115 assert(sb.pubseekoff(3, std::ios_base::cur, std::ios_base::in | std::ios_base::out) == -1);
116 assert(sb.pubseekoff(-3, std::ios_base::end, std::ios_base::in | std::ios_base::out) == -1);
117 assert(sb.pubseekoff(3, std::ios_base::beg, std::ios_base::in) == 3);
118 assert(sb.sgetc() == L'3');
119 assert(sb.pubseekoff(3, std::ios_base::cur, std::ios_base::in) == 6);
120 assert(sb.sgetc() == L'6');
121 assert(sb.pubseekoff(-3, std::ios_base::end, std::ios_base::in) == 7);
122 assert(sb.sgetc() == L'7');
125 std::wstringbuf sb(L"0123456789", std::ios_base::out);
126 assert(sb.pubseekoff(3, std::ios_base::beg, std::ios_base::in) == -1);
127 assert(sb.pubseekoff(3, std::ios_base::cur, std::ios_base::in) == -1);
128 assert(sb.pubseekoff(-3, std::ios_base::end, std::ios_base::in) == -1);
129 assert(sb.pubseekoff(3, std::ios_base::beg, std::ios_base::out | std::ios_base::in) == -1);
130 assert(sb.pubseekoff(3, std::ios_base::cur, std::ios_base::out | std::ios_base::in) == -1);
131 assert(sb.pubseekoff(-3, std::ios_base::end, std::ios_base::out | std::ios_base::in) == -1);
132 assert(sb.pubseekoff(3, std::ios_base::beg, std::ios_base::out) == 3);
133 assert(sb.sputc(L'a') == L'a');
134 assert(sb.str() == L"012a456789");
135 assert(sb.pubseekoff(3, std::ios_base::cur, std::ios_base::out) == 7);
136 assert(sb.sputc(L'b') == L'b');
137 assert(sb.str() == L"012a456b89");
138 assert(sb.pubseekoff(-3, std::ios_base::end, std::ios_base::out) == 7);
139 assert(sb.sputc(L'c') == L'c');
140 assert(sb.str() == L"012a456c89");
143 std::wstringbuf sb(L"0123456789");
144 assert(sb.pubseekoff(3, std::ios_base::beg, std::ios_base::in) == 3);
145 assert(sb.sgetc() == L'3');
146 assert(sb.pubseekoff(3, std::ios_base::cur, std::ios_base::in) == 6);
147 assert(sb.sgetc() == L'6');
148 assert(sb.pubseekoff(-3, std::ios_base::end, std::ios_base::in) == 7);
149 assert(sb.sgetc() == L'7');
150 assert(sb.pubseekoff(3, std::ios_base::beg, std::ios_base::out | std::ios_base::in) == 3);
151 assert(sb.sgetc() == L'3');
152 assert(sb.sputc(L'a') == L'a');
153 assert(sb.str() == L"012a456789");
154 assert(sb.pubseekoff(3, std::ios_base::cur, std::ios_base::out | std::ios_base::in) == -1);
155 assert(sb.pubseekoff(-3, std::ios_base::end, std::ios_base::out | std::ios_base::in) == 7);
156 assert(sb.sgetc() == L'7');
157 assert(sb.sputc(L'c') == L'c');
158 assert(sb.str() == L"012a456c89");
159 assert(sb.pubseekoff(3, std::ios_base::beg, std::ios_base::out) == 3);
160 assert(sb.sputc(L'3') == L'3');
161 assert(sb.str() == L"0123456c89");
162 assert(sb.pubseekoff(3, std::ios_base::cur, std::ios_base::out) == 7);
163 assert(sb.sputc(L'7') == L'7');
164 assert(sb.str() == L"0123456789");
165 assert(sb.pubseekoff(-3, std::ios_base::end, std::ios_base::out) == 7);
166 assert(sb.sputc(L'c') == L'c');
167 assert(sb.str() == L"0123456c89");
169 #endif // TEST_HAS_NO_WIDE_CHARACTERS
171 return 0;