| 1 |
// Copyright (C) 2007-2025 Free Software Foundation, Inc. |
| 2 |
// |
| 3 |
// This file is part of the GNU ISO C++ Library. This library is free |
| 4 |
// software; you can redistribute it and/or modify it under the |
| 5 |
// terms of the GNU General Public License as published by the |
| 6 |
// Free Software Foundation; either version 3, or (at your option) |
| 7 |
// any later version. |
| 8 |
|
| 9 |
// This library is distributed in the hope that it will be useful, |
| 10 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 |
// GNU General Public License for more details. |
| 13 |
|
| 14 |
// You should have received a copy of the GNU General Public License along |
| 15 |
// with this library; see the file COPYING3. If not see |
| 16 |
// <http://www.gnu.org/licenses/>. |
| 17 |
|
| 18 |
// 27.8.1.4 Overridden virtual functions |
| 19 |
|
| 20 |
// { dg-require-fileio "" } |
| 21 |
|
| 22 |
#include <fstream> |
| 23 |
#include <cctype> |
| 24 |
#include <locale> |
| 25 |
#include <testsuite_hooks.h> |
| 26 |
|
| 27 |
class Mycvtcc |
| 28 |
: public std::codecvt<char, char, std::mbstate_t> |
| 29 |
{ |
| 30 |
protected: |
| 31 |
virtual result |
| 32 |
do_in(state_type&, |
| 33 |
const extern_type* from, const extern_type* from_end, |
| 34 |
const extern_type*& from_next, |
| 35 |
intern_type* to, intern_type* to_limit, |
| 36 |
intern_type*& to_next) const |
| 37 |
{ |
| 38 |
from_next = from, to_next = to; |
| 39 |
|
| 40 |
if (from_next == from_end || to_next == to_limit) |
| 41 |
return partial; |
| 42 |
|
| 43 |
if (std::islower(*from_next)) |
| 44 |
*to_next = std::toupper(*from_next); |
| 45 |
else |
| 46 |
*to_next = *from_next; |
| 47 |
++from_next, ++to_next; |
| 48 |
return ok; |
| 49 |
} |
| 50 |
|
| 51 |
virtual bool |
| 52 |
do_always_noconv() const throw() |
| 53 |
{ return false; } |
| 54 |
}; |
| 55 |
|
| 56 |
// See Novell Bug 255122 |
| 57 |
void test01() |
| 58 |
{ |
| 59 |
using namespace std; |
| 60 |
|
| 61 |
const char* name = "tmp_underflow_3.tst"; |
| 62 |
filebuf fbuf, fbufx; |
| 63 |
|
| 64 |
fbuf.open(name, ios_base::out | ios_base::trunc); |
| 65 |
VERIFY( fbuf.sputc('a') == 'a' ); |
| 66 |
VERIFY( fbuf.sputc('b') == 'b' ); |
| 67 |
VERIFY( fbuf.sputc('\n') == '\n' ); |
| 68 |
fbuf.close(); |
| 69 |
|
| 70 |
fbufx.pubimbue(locale(locale::classic(), new Mycvtcc)); |
| 71 |
fbufx.open(name, ios_base::in); |
| 72 |
VERIFY( fbufx.sbumpc() == 'A' ); |
| 73 |
VERIFY( fbufx.sbumpc() == 'B' ); |
| 74 |
VERIFY( fbufx.sbumpc() == '\n' ); |
| 75 |
VERIFY( fbufx.sbumpc() == filebuf::traits_type::eof() ); |
| 76 |
fbufx.close(); |
| 77 |
} |
| 78 |
|
| 79 |
int main() |
| 80 |
{ |
| 81 |
test01(); |
| 82 |
return 0; |
| 83 |
} |