]> git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/27_io/basic_filebuf/imbue/wchar_t/13582-2.cc
9661-1.cc: Include <cstdlib>.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 27_io / basic_filebuf / imbue / wchar_t / 13582-2.cc
1 // { dg-require-namedlocale "" }
2 // { dg-require-fork "" }
3 // { dg-require-mkfifo "" }
4
5 // 2004-01-11 Petur Runolfsson <peturr02@ru.is>
6
7 // Copyright (C) 2004, 2005, 2006, 2007 Free Software Foundation, Inc.
8 //
9 // This file is part of the GNU ISO C++ Library. This library is free
10 // software; you can redistribute it and/or modify it under the
11 // terms of the GNU General Public License as published by the
12 // Free Software Foundation; either version 2, or (at your option)
13 // any later version.
14
15 // This library is distributed in the hope that it will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 // GNU General Public License for more details.
19
20 // You should have received a copy of the GNU General Public License along
21 // with this library; see the file COPYING. If not, write to the Free
22 // Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
23 // USA.
24
25 // 27.8.1.4 Overridden virtual functions
26
27 #include <fstream>
28 #include <locale>
29 #include <cstdlib>
30
31 #include <unistd.h>
32 #include <sys/types.h>
33 #include <sys/stat.h>
34
35 #include <testsuite_hooks.h>
36
37 // libstdc++/13582
38 void test01()
39 {
40 bool test __attribute__((unused)) = true;
41 using namespace std;
42 using namespace __gnu_test;
43
44 locale loc_en(locale("en_US"));
45 locale loc_fr(locale("fr_FR"));
46
47 const char* name = "tmp_fifo_13582-2";
48 unlink(name);
49 mkfifo(name, S_IRWXU);
50
51 int child = fork();
52 if (child == 0)
53 {
54 filebuf fbout;
55 fbout.open(name, ios_base::out);
56 fbout.sputn("12345", 5);
57 fbout.pubsync();
58 sleep(2);
59 fbout.close();
60 exit(0);
61 }
62
63 wfilebuf fbin;
64 fbin.open(name, ios_base::in);
65 sleep(1);
66 wfilebuf::int_type n = fbin.sbumpc();
67 VERIFY( n == L'1' );
68 fbin.pubimbue(loc_en);
69 n = fbin.sbumpc();
70 VERIFY( n == L'2' );
71 fbin.pubimbue(loc_fr);
72 n = fbin.sbumpc();
73 VERIFY( n == L'3' );
74 n = fbin.sbumpc();
75 VERIFY( n == L'4' );
76 n = fbin.sbumpc();
77 VERIFY( n == L'5' );
78 n = fbin.sbumpc();
79 VERIFY( n == wfilebuf::traits_type::eof() );
80 }
81
82 int main()
83 {
84 test01();
85 return 0;
86 }