Debian Codegraph @

libcxx/test/std/input.output/string.streams/stringstream/stringstream.members/gcount.pass.cpp

raw
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 // UNSUPPORTED: 32-bit-pointer
10 // REQUIRES: large_tests
11
12 // Android devices frequently don't have enough memory to run this test. Rather
13 // than throw std::bad_alloc, exhausting memory triggers the OOM Killer.
14 // UNSUPPORTED: LIBCXX-ANDROID-FIXME
15
16 // Test that tellp() does not break the stringstream after INT_MAX, due to use
17 // of pbump() that accept int.
18
19 #include <cassert>
20 #include <climits>
21 #include <sstream>
22 #include <string>
23
24 int main(int, char**) {
25 std::stringstream ss;
26 std::string payload(INT_MAX - 1, '\0');
27
28 ss.write(payload.data(), payload.size());
29 assert(ss.tellp() == INT_MAX - 1);
30
31 ss.write("a", 1);
32 assert(ss.tellp() == INT_MAX);
33
34 ss.write("b", 1);
35 assert(ss.tellp() == INT_MAX + 1ULL);
36 // it fails only after previous tellp() corrupts the internal field with int
37 // overflow
38 assert(ss.tellp() == INT_MAX + 1ULL);
39
40 return 0;
41 }