Home | History | Annotate | Download | only in depr.strstreambuf.cons
      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 // strstreambuf(char* gnext_arg, streamsize n, char* pbeg_arg = 0);
     15 
     16 #include <strstream>
     17 #include <cassert>
     18 
     19 int main()
     20 {
     21     {
     22         char buf[] = "abcd";
     23         std::strstreambuf sb(buf, sizeof(buf));
     24         assert(sb.sgetc() == 'a');
     25         assert(sb.snextc() == 'b');
     26         assert(sb.snextc() == 'c');
     27         assert(sb.snextc() == 'd');
     28         assert(sb.snextc() == 0);
     29         assert(sb.snextc() == EOF);
     30     }
     31     {
     32         char buf[] = "abcd";
     33         std::strstreambuf sb(buf, 0);
     34         assert(sb.sgetc() == 'a');
     35         assert(sb.snextc() == 'b');
     36         assert(sb.snextc() == 'c');
     37         assert(sb.snextc() == 'd');
     38         assert(sb.snextc() == EOF);
     39     }
     40     {
     41         char buf[] = "abcd";
     42         std::strstreambuf sb(buf, sizeof(buf), buf);
     43         assert(sb.sgetc() == EOF);
     44         assert(sb.sputc('e') == 'e');
     45         assert(sb.sputc('f') == 'f');
     46         assert(sb.sputc('g') == 'g');
     47         assert(sb.sputc('h') == 'h');
     48         assert(sb.sputc('i') == 'i');
     49         assert(sb.sputc('j') == EOF);
     50         assert(sb.sgetc() == 'e');
     51         assert(sb.snextc() == 'f');
     52         assert(sb.snextc() == 'g');
     53         assert(sb.snextc() == 'h');
     54         assert(sb.snextc() == 'i');
     55         assert(sb.snextc() == EOF);
     56     }
     57     {
     58         char buf[] = "abcd";
     59         std::strstreambuf sb(buf, 0, buf);
     60         assert(sb.sgetc() == EOF);
     61         assert(sb.sputc('e') == 'e');
     62         assert(sb.sputc('f') == 'f');
     63         assert(sb.sputc('g') == 'g');
     64         assert(sb.sputc('h') == 'h');
     65         assert(sb.sputc('i') == EOF);
     66         assert(sb.sgetc() == 'e');
     67         assert(sb.snextc() == 'f');
     68         assert(sb.snextc() == 'g');
     69         assert(sb.snextc() == 'h');
     70         assert(sb.snextc() == EOF);
     71     }
     72     {
     73         char buf[10] = "abcd";
     74         int s = std::strlen(buf);
     75         std::strstreambuf sb(buf, sizeof(buf)-s, buf + s);
     76         assert(sb.sgetc() == 'a');
     77         assert(sb.snextc() == 'b');
     78         assert(sb.snextc() == 'c');
     79         assert(sb.snextc() == 'd');
     80         assert(sb.snextc() == EOF);
     81         assert(sb.sputc('e') == 'e');
     82         assert(sb.sputc('f') == 'f');
     83         assert(sb.sputc('g') == 'g');
     84         assert(sb.sputc('h') == 'h');
     85         assert(sb.sputc('i') == 'i');
     86         assert(sb.sputc('j') == 'j');
     87         assert(sb.sputc('j') == EOF);
     88         assert(sb.sgetc() == 'e');
     89         assert(sb.snextc() == 'f');
     90         assert(sb.snextc() == 'g');
     91         assert(sb.snextc() == 'h');
     92         assert(sb.snextc() == 'i');
     93         assert(sb.snextc() == 'j');
     94         assert(sb.snextc() == EOF);
     95     }
     96 }
     97