OSDN Git Service

PR target/38707
[pf3gnuchains/gcc-fork.git] / libstdc++-v3 / testsuite / 27_io / basic_istream / read / wchar_t / 38678.cc
1 // Copyright (C) 2009 Free Software Foundation
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 2, 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 COPYING.  If not, write to the Free
16 // Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
17 // USA.
18
19 // 27.6.1.3 unformatted input functions
20
21 #include <istream>
22 #include <streambuf>
23 #include <testsuite_hooks.h>
24
25 // libstdc++/38678
26 void test01()
27 {
28   bool test __attribute__((unused)) = true;
29
30   static wchar_t x = L'0';
31
32   struct : std::wstreambuf
33   {
34     wchar_t c;
35
36     int_type
37     underflow()
38     {
39       c = x++;
40       setg(&c, &c, &c + 1);
41       return traits_type::to_int_type(c);
42     }
43
44     std::streamsize
45     xsgetn(wchar_t*, std::streamsize)
46     {
47       VERIFY( !"xsgetn should not be called" );
48       return 0;
49     }
50   } sb;
51
52   std::wistream in(&sb);
53
54   wchar_t s[4] = L"";
55
56   in.read(s, 4);
57
58   VERIFY( in.good() );
59   VERIFY( 4 == in.gcount() );
60   VERIFY( L'0' == s[0] && L'1' == s[1] && L'2' == s[2] && L'3' == s[3] );
61 }
62
63 int main()
64 {
65   test01();
66   return 0;
67 }