]> git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/27_io/objects/char/7.cc
locale_facets.tcc: Tweak to avoid warnings.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 27_io / objects / char / 7.cc
1 // 2003-04-26 Petur Runolfsson <peturr02@ru.is>
2
3 // Copyright (C) 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.3 Standard iostream objects
22
23 // XXX cygwin does not support mkfifo
24 // { dg-do run { xfail *-*-cygwin* } }
25
26 #include <fstream>
27 #include <iostream>
28 #include <unistd.h>
29 #include <signal.h>
30 #include <fcntl.h>
31 #include <sys/types.h>
32 #include <sys/stat.h>
33 #include <testsuite_hooks.h>
34
35 // Check that cout.flush() is called when last ios_base::Init is destroyed.
36 void test07()
37 {
38 using namespace std;
39 bool test __attribute__((unused)) = true;
40
41 const char* name = "tmp_fifo4";
42
43 signal(SIGPIPE, SIG_IGN);
44
45 unlink(name);
46 mkfifo(name, S_IRWXU);
47
48 int child = fork();
49 VERIFY( child != -1 );
50
51 if (child == 0)
52 {
53 filebuf fbout;
54 sleep(1);
55 fbout.open(name, ios_base::out);
56 cout.rdbuf(&fbout);
57 fbout.sputc('a');
58 sleep(2);
59 // NB: fbout is *not* destroyed here!
60 exit(0);
61 }
62
63 filebuf fbin;
64 fbin.open(name, ios_base::in);
65 sleep(2);
66 filebuf::int_type c = fbin.sbumpc();
67 VERIFY( c != filebuf::traits_type::eof() );
68 VERIFY( c == filebuf::traits_type::to_int_type('a') );
69
70 fbin.close();
71 }
72
73 int
74 main()
75 {
76 test07();
77 return 0;
78 }