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