OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-dev/] [or1k-gcc/] [libstdc++-v3/] [testsuite/] [27_io/] [objects/] [wchar_t/] [9661-1.cc] - Blame information for rev 746

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 742 jeremybenn
// { dg-require-fork "" }
2
// { dg-require-mkfifo "" }
3
 
4
// 2003-04-30  Petur Runolfsson <peturr02@ru.is>
5
 
6
// Copyright (C) 2003, 2004, 2005, 2006, 2007, 2009
7
// 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 3, 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 COPYING3.  If not see
22
// <http://www.gnu.org/licenses/>.
23
 
24
// No asserts, avoid leaking the semaphores if a VERIFY fails.
25
#undef _GLIBCXX_ASSERT
26
 
27
#include <testsuite_hooks.h>
28
#include <cstdio>
29
#include <cstdlib>
30
#include <iostream>
31
#include <unistd.h>
32
#include <signal.h>
33
#include <fcntl.h>
34
#include <sys/types.h>
35
#include <sys/stat.h>
36
 
37
// Check that wcin.rdbuf()->sputbackc() puts characters back to stdin.
38
// If wcin.rdbuf() is a filebuf, this succeeds when stdin is a regular
39
// file, but fails otherwise, hence the named fifo.
40
bool test01()
41
{
42
  using namespace std;
43
  using namespace __gnu_test;
44
 
45
  bool test __attribute__((unused)) = true;
46
 
47
  const char* name = "tmp_fifo5";
48
 
49
  signal(SIGPIPE, SIG_IGN);
50
 
51
  unlink(name);
52
  mkfifo(name, S_IRWXU);
53
  semaphore s1, s2;
54
 
55
  int child = fork();
56
  VERIFY( child != -1 );
57
 
58
  if (child == 0)
59
    {
60
      FILE* file = fopen(name, "w");
61
      fputs("Whatever\n", file);
62
      fflush(file);
63
      s1.signal();
64
      s2.wait();
65
      fclose(file);
66
      s1.signal();
67
      exit(0);
68
    }
69
 
70
  VERIFY( freopen(name, "r", stdin) );
71
  s1.wait();
72
 
73
  wint_t c1 = fgetwc(stdin);
74
  VERIFY( c1 != WEOF );
75
  wint_t c2 = wcin.rdbuf()->sputbackc(L'a');
76
  VERIFY( c2 != WEOF );
77
  VERIFY( c2 == L'a' );
78
 
79
  wint_t c3 = fgetwc(stdin);
80
  VERIFY( c3 != WEOF );
81
  VERIFY( c3 == c2 );
82
  wint_t c4 = ungetwc(L'b', stdin);
83
  VERIFY( c4 != WEOF );
84
  VERIFY( c4 == L'b' );
85
 
86
  wint_t c5 = wcin.rdbuf()->sgetc();
87
  VERIFY( c5 != WEOF );
88
  VERIFY( c5 == c4 );
89
  s2.signal();
90
  s1.wait();
91
 
92
  return test;
93
}
94
 
95
int main()
96
{
97
  return !test01();
98
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.