]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/testsuite/27_io/basic_filebuf/underflow/char/10097.cc
re PR c++/12007 (Multiple inheritance float pass by value fails)
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 27_io / basic_filebuf / underflow / char / 10097.cc
CommitLineData
23cac885
BK
1// 2001-05-21 Benjamin Kosnik <bkoz@redhat.com>
2
3// Copyright (C) 2001, 2002, 2003 Free Software Foundation, Inc.
4//
5// This file is part of the GNU ISO C++ Library. This library is free
6// software; you can redistribute it and/or modify it under the
7// terms of the GNU General Public License as published by the
8// Free Software Foundation; either version 2, or (at your option)
9// any later version.
10
11// This library is distributed in the hope that it will be useful,
12// but WITHOUT ANY WARRANTY; without even the implied warranty of
13// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14// GNU General Public License for more details.
15
16// You should have received a copy of the GNU General Public License along
17// with this library; see the file COPYING. If not, write to the Free
18// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
19// USA.
20
21// 27.8.1.4 Overridden virtual functions
22
23#include <fstream>
24#include <unistd.h>
25#include <signal.h>
26#include <fcntl.h>
27#include <sys/types.h>
28#include <sys/stat.h>
29#include <testsuite_hooks.h>
30
31class UnderBuf : public std::filebuf
32{
33public:
34 int_type
35 pub_underflow()
36 { return underflow(); }
37
38 std::streamsize
39 pub_showmanyc()
40 { return showmanyc(); }
41};
42
43// libstdc++/10097
44// filebuf::underflow drops characters.
45void test16()
46{
47 using namespace std;
ea1ea21a 48 using namespace __gnu_test;
11f10e6b 49 bool test __attribute__((unused)) = true;
23cac885
BK
50
51 const char* name = "tmp_fifo1";
52
53 signal(SIGPIPE, SIG_IGN);
54 unlink(name);
55
ea1ea21a 56 if (0 != try_mkfifo(name, S_IRWXU))
23cac885
BK
57 {
58 VERIFY( false );
59 }
60
61 int fval = fork();
62 if (fval == -1)
63 {
64 unlink(name);
65 VERIFY( false );
66 }
67 else if (fval == 0)
68 {
69 filebuf fbout;
70 fbout.open(name, ios_base::out);
71 fbout.sputn("0123456789", 10);
72 fbout.pubsync();
73 sleep(2);
74 fbout.close();
75 exit(0);
76 }
77
78 UnderBuf fb;
79 fb.open(name, ios_base::in);
80 sleep(1);
81
82 fb.sgetc();
83 streamsize n = fb.pub_showmanyc();
84
85 while (n > 0)
86 {
87 --n;
88
89 UnderBuf::int_type c = fb.pub_underflow();
90 VERIFY( c != UnderBuf::traits_type::eof() );
91
92 fb.sbumpc();
93 }
94
95 fb.close();
96}
97
11f10e6b 98int main()
23cac885
BK
99{
100 test16();
101 return 0;
102}