| 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 |
// <sstream> |
| 10 |
|
| 11 |
// template <class charT, class traits = char_traits<charT>, class Allocator = allocator<charT> > |
| 12 |
// class basic_stringbuf |
| 13 |
|
| 14 |
// int_type underflow(); |
| 15 |
|
| 16 |
#include <sstream> |
| 17 |
#include <cassert> |
| 18 |
|
| 19 |
#include "test_macros.h" |
| 20 |
|
| 21 |
template <class CharT> |
| 22 |
struct testbuf |
| 23 |
: public std::basic_stringbuf<CharT> |
| 24 |
{ |
| 25 |
typedef std::basic_stringbuf<CharT> base; |
| 26 |
explicit testbuf(const std::basic_string<CharT>& str) |
| 27 |
: base(str) {} |
| 28 |
|
| 29 |
typename base::int_type underflow() {return base::underflow();} |
| 30 |
void pbump(int n) {base::pbump(n);} |
| 31 |
}; |
| 32 |
|
| 33 |
int main(int, char**) |
| 34 |
{ |
| 35 |
{ |
| 36 |
testbuf<char> sb("123"); |
| 37 |
sb.pbump(3); |
| 38 |
assert(sb.underflow() == '1'); |
| 39 |
assert(sb.underflow() == '1'); |
| 40 |
assert(sb.snextc() == '2'); |
| 41 |
assert(sb.underflow() == '2'); |
| 42 |
assert(sb.underflow() == '2'); |
| 43 |
assert(sb.snextc() == '3'); |
| 44 |
assert(sb.underflow() == '3'); |
| 45 |
assert(sb.underflow() == '3'); |
| 46 |
assert(sb.snextc() == std::char_traits<char>::eof()); |
| 47 |
assert(sb.underflow() == std::char_traits<char>::eof()); |
| 48 |
assert(sb.underflow() == std::char_traits<char>::eof()); |
| 49 |
sb.sputc('4'); |
| 50 |
assert(sb.underflow() == '4'); |
| 51 |
assert(sb.underflow() == '4'); |
| 52 |
} |
| 53 |
#ifndef TEST_HAS_NO_WIDE_CHARACTERS |
| 54 |
{ |
| 55 |
testbuf<wchar_t> sb(L"123"); |
| 56 |
sb.pbump(3); |
| 57 |
assert(sb.underflow() == L'1'); |
| 58 |
assert(sb.underflow() == L'1'); |
| 59 |
assert(sb.snextc() == L'2'); |
| 60 |
assert(sb.underflow() == L'2'); |
| 61 |
assert(sb.underflow() == L'2'); |
| 62 |
assert(sb.snextc() == L'3'); |
| 63 |
assert(sb.underflow() == L'3'); |
| 64 |
assert(sb.underflow() == L'3'); |
| 65 |
assert(sb.snextc() == std::char_traits<wchar_t>::eof()); |
| 66 |
assert(sb.underflow() == std::char_traits<wchar_t>::eof()); |
| 67 |
assert(sb.underflow() == std::char_traits<wchar_t>::eof()); |
| 68 |
sb.sputc(L'4'); |
| 69 |
assert(sb.underflow() == L'4'); |
| 70 |
assert(sb.underflow() == L'4'); |
| 71 |
} |
| 72 |
#endif // TEST_HAS_NO_WIDE_CHARACTERS |
| 73 |
|
| 74 |
return 0; |
| 75 |
} |