Reverting merge from trunk
[official-gcc.git] / libstdc++-v3 / testsuite / 27_io / basic_filebuf / underflow / char / 3.cc
blob3d4fc629a3626db1a84876ed97f6493badfed90a
1 // Copyright (C) 2007-2013 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.
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.
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/>.
18 // 27.8.1.4 Overridden virtual functions
20 // { dg-require-fileio "" }
22 #include <fstream>
23 #include <cctype>
24 #include <locale>
25 #include <testsuite_hooks.h>
27 class Mycvtcc
28 : public std::codecvt<char, char, std::mbstate_t>
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
38 from_next = from, to_next = to;
40 if (from_next == from_end || to_next == to_limit)
41 return partial;
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;
51 virtual bool
52 do_always_noconv() const throw()
53 { return false; }
56 // See Novell Bug 255122
57 void test01()
59 bool test __attribute__((unused)) = true;
60 using namespace std;
62 const char* name = "tmp_underflow_3.tst";
63 filebuf fbuf, fbufx;
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();
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();
80 int main()
82 test01();
83 return 0;