]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/testsuite/27_io/objects/char/7.cc
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 27_io / objects / char / 7.cc
CommitLineData
34f4edf8
MM
1// { dg-require-fork "" }
2// { dg-require-mkfifo "" }
3
2aacd735
BK
4// 2003-04-26 Petur Runolfsson <peturr02@ru.is>
5
99dee823 6// Copyright (C) 2003-2021 Free Software Foundation, Inc.
2aacd735
BK
7//
8// This file is part of the GNU ISO C++ Library. This library is free
9// software; you can redistribute it and/or modify it under the
10// terms of the GNU General Public License as published by the
748086b7 11// Free Software Foundation; either version 3, or (at your option)
2aacd735
BK
12// any later version.
13
14// This library is distributed in the hope that it will be useful,
15// but WITHOUT ANY WARRANTY; without even the implied warranty of
16// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17// GNU General Public License for more details.
18
19// You should have received a copy of the GNU General Public License along
748086b7
JJ
20// with this library; see the file COPYING3. If not see
21// <http://www.gnu.org/licenses/>.
2aacd735
BK
22
23// 27.3 Standard iostream objects
24
25#include <fstream>
26#include <iostream>
debac9f4 27#include <cstdlib>
2aacd735
BK
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.
9339bda8 36bool test07()
2aacd735
BK
37{
38 using namespace std;
ea1ea21a 39 using namespace __gnu_test;
118c8424 40 bool test = true;
2aacd735
BK
41
42 const char* name = "tmp_fifo4";
43
44 signal(SIGPIPE, SIG_IGN);
45
46 unlink(name);
34f4edf8 47 mkfifo(name, S_IRWXU);
8f1032c1
MM
48 semaphore s1;
49
2aacd735 50 int child = fork();
118c8424 51 test &= bool( child != -1 );
2aacd735
BK
52
53 if (child == 0)
54 {
55 filebuf fbout;
f196bdc4 56 fbout.open(name, ios_base::in|ios_base::out);
118c8424 57 test &= bool( fbout.is_open() );
9339bda8 58 s1.wait();
2aacd735
BK
59 cout.rdbuf(&fbout);
60 fbout.sputc('a');
2aacd735
BK
61 // NB: fbout is *not* destroyed here!
62 exit(0);
63 }
64
65 filebuf fbin;
66 fbin.open(name, ios_base::in);
9339bda8 67 s1.signal();
2aacd735 68 filebuf::int_type c = fbin.sbumpc();
118c8424
PC
69 test &= bool( c != filebuf::traits_type::eof() );
70 test &= bool( c == filebuf::traits_type::to_int_type('a') );
2aacd735
BK
71
72 fbin.close();
9339bda8
PC
73
74 return test;
2aacd735
BK
75}
76
77int
78main()
79{
9339bda8 80 return !test07();
2aacd735 81}