1// Copyright (C) 2007-2015 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
27class Mycvtcc
28: public std::codecvt<char, char, std::mbstate_t>
29{
30protected:
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
57void test01()
58{
59  bool test __attribute__((unused)) = true;
60  using namespace std;
61
62  const char* name = "tmp_underflow_3.tst";
63  filebuf fbuf, fbufx;
64
65  fbuf.open(name, ios_base::out | ios_base::trunc);
66  VERIFY( fbuf.sputc('a') == 'a' );
67  VERIFY( fbuf.sputc('b') == 'b' );
68  VERIFY( fbuf.sputc('\n') == '\n' );
69  fbuf.close();
70
71  fbufx.pubimbue(locale(locale::classic(), new Mycvtcc));
72  fbufx.open(name, ios_base::in);
73  VERIFY( fbufx.sbumpc() == 'A' );
74  VERIFY( fbufx.sbumpc() == 'B' );
75  VERIFY( fbufx.sbumpc() == '\n' );
76  VERIFY( fbufx.sbumpc() == filebuf::traits_type::eof() );
77  fbufx.close();
78}
79
80int main()
81{
82  test01();
83  return 0;
84}
85