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