libcxx

libcxx mirror with random patches
git clone https://git.neptards.moe/neptards/libcxx.git
Log | Files | Refs

scp_size_scp.pass.cpp (3058B)


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