• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 // <strstream>
10 
11 // class strstreambuf
12 
13 // pos_type seekoff(off_type off, ios_base::seekdir way,
14 //                  ios_base::openmode which = ios_base::in | ios_base::out);
15 
16 #include <strstream>
17 #include <cassert>
18 
19 #include "test_macros.h"
20 
main(int,char **)21 int main(int, char**)
22 {
23     {
24         char buf[] = "0123456789";
25         std::strstreambuf sb(buf, 0);
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(3, std::ios_base::beg, std::ios_base::in) == 3);
33         assert(sb.sgetc() == '3');
34         assert(sb.pubseekoff(3, std::ios_base::cur, std::ios_base::in) == 6);
35         assert(sb.sgetc() == '6');
36         assert(sb.pubseekoff(-3, std::ios_base::end, std::ios_base::in) == 7);
37         assert(sb.sgetc() == '7');
38     }
39     {
40         char buf[] = "0123456789";
41         std::strstreambuf sb(buf, 0, buf);
42         assert(sb.pubseekoff(3, std::ios_base::beg, std::ios_base::in) == 3);
43         assert(sb.pubseekoff(3, std::ios_base::cur, std::ios_base::in) == 6);
44         assert(sb.pubseekoff(-3, std::ios_base::end, std::ios_base::in) == 7);
45         assert(sb.pubseekoff(3, std::ios_base::beg, std::ios_base::out | std::ios_base::in) == 3);
46         assert(sb.pubseekoff(3, std::ios_base::cur, std::ios_base::out | std::ios_base::in) == -1);
47         assert(sb.pubseekoff(-3, std::ios_base::end, std::ios_base::out | std::ios_base::in) == 7);
48         assert(sb.pubseekoff(3, std::ios_base::beg, std::ios_base::out) == 3);
49         assert(sb.sputc('a') == 'a');
50         assert(sb.str() == std::string("012a456789"));
51         assert(sb.pubseekoff(3, std::ios_base::cur, std::ios_base::out) == 7);
52         assert(sb.sputc('b') == 'b');
53         assert(sb.str() == std::string("012a456b89"));
54         assert(sb.pubseekoff(-3, std::ios_base::end, std::ios_base::out) == 7);
55         assert(sb.sputc('c') == 'c');
56         assert(sb.str() == std::string("012a456c89"));
57     }
58 
59   return 0;
60 }
61