summaryrefslogtreecommitdiffstats
path: root/libcxx/test/std/depr/depr.str.strstreams/depr.strstreambuf/depr.strstreambuf.cons/ucp_size_ucp.pass.cpp
blob: e71fa031ebcbad1f2240884f4653f5521ba7d4ad (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

// ADDITIONAL_COMPILE_FLAGS: -D_LIBCPP_DISABLE_DEPRECATION_WARNINGS -D_LIBCPP_ENABLE_CXX26_REMOVED_STRSTREAM

// <strstream>

// class strstreambuf

// strstreambuf(unsigned char* gnext_arg, streamsize n, unsigned char* pbeg_arg = 0);

#include <strstream>
#include <cassert>
#include <cstring>

#include "test_macros.h"

int main(int, char**)
{
    {
        unsigned char buf[] = "abcd";
        std::strstreambuf sb(buf, sizeof(buf));
        assert(sb.sgetc() == 'a');
        assert(sb.snextc() == 'b');
        assert(sb.snextc() == 'c');
        assert(sb.snextc() == 'd');
        assert(sb.snextc() == 0);
        assert(sb.snextc() == EOF);
    }
    {
        unsigned char buf[] = "abcd";
        std::strstreambuf sb(buf, 0);
        assert(sb.sgetc() == 'a');
        assert(sb.snextc() == 'b');
        assert(sb.snextc() == 'c');
        assert(sb.snextc() == 'd');
        assert(sb.snextc() == EOF);
    }
    {
        unsigned char buf[] = "abcd";
        std::strstreambuf sb(buf, sizeof(buf), buf);
        assert(sb.sgetc() == EOF);
        assert(sb.sputc('e') == 'e');
        assert(sb.sputc('f') == 'f');
        assert(sb.sputc('g') == 'g');
        assert(sb.sputc('h') == 'h');
        assert(sb.sputc('i') == 'i');
        assert(sb.sputc('j') == EOF);
        assert(sb.sgetc() == 'e');
        assert(sb.snextc() == 'f');
        assert(sb.snextc() == 'g');
        assert(sb.snextc() == 'h');
        assert(sb.snextc() == 'i');
        assert(sb.snextc() == EOF);
    }
    {
        unsigned char buf[] = "abcd";
        std::strstreambuf sb(buf, 0, buf);
        assert(sb.sgetc() == EOF);
        assert(sb.sputc('e') == 'e');
        assert(sb.sputc('f') == 'f');
        assert(sb.sputc('g') == 'g');
        assert(sb.sputc('h') == 'h');
        assert(sb.sputc('i') == EOF);
        assert(sb.sgetc() == 'e');
        assert(sb.snextc() == 'f');
        assert(sb.snextc() == 'g');
        assert(sb.snextc() == 'h');
        assert(sb.snextc() == EOF);
    }
    {
        unsigned char buf[10] = "abcd";
        std::size_t s = std::strlen((char*)buf);
        std::strstreambuf sb(buf, sizeof(buf) - s, buf + s);
        assert(sb.sgetc() == 'a');
        assert(sb.snextc() == 'b');
        assert(sb.snextc() == 'c');
        assert(sb.snextc() == 'd');
        assert(sb.snextc() == EOF);
        assert(sb.sputc('e') == 'e');
        assert(sb.sputc('f') == 'f');
        assert(sb.sputc('g') == 'g');
        assert(sb.sputc('h') == 'h');
        assert(sb.sputc('i') == 'i');
        assert(sb.sputc('j') == 'j');
        assert(sb.sputc('j') == EOF);
        assert(sb.sgetc() == 'e');
        assert(sb.snextc() == 'f');
        assert(sb.snextc() == 'g');
        assert(sb.snextc() == 'h');
        assert(sb.snextc() == 'i');
        assert(sb.snextc() == 'j');
        assert(sb.snextc() == EOF);
    }

  return 0;
}