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

Subversion Repositories openrisc_me

[/] [openrisc/] [trunk/] [gnu-src/] [gcc-4.5.1/] [libstdc++-v3/] [testsuite/] [27_io/] [basic_istream/] [getline/] [wchar_t/] [2.cc] - Blame information for rev 424

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 424 jeremybenn
// Copyright (C) 2004, 2009 Free Software Foundation
2
//
3
// This file is part of the GNU ISO C++ Library.  This library is free
4
// software; you can redistribute it and/or modify it under the
5
// terms of the GNU General Public License as published by the
6
// Free Software Foundation; either version 3, or (at your option)
7
// any later version.
8
 
9
// This library is distributed in the hope that it will be useful,
10
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
// GNU General Public License for more details.
13
 
14
// You should have received a copy of the GNU General Public License along
15
// with this library; see the file COPYING3.  If not see
16
// <http://www.gnu.org/licenses/>.
17
 
18
// 27.6.1.3 unformatted input functions
19
 
20
#include <cwchar> // for wcslen
21
#include <istream>
22
#include <sstream>
23
#include <testsuite_hooks.h>
24
 
25
// [patch] bits/istream.tcc - getline(char_type*,streamsize,char_type)
26
// http://gcc.gnu.org/ml/libstdc++/2000-07/msg00003.html
27
void
28
test05()
29
{
30
  const wchar_t* charray = L"\n"
31
L"a\n"
32
L"aa\n"
33
L"aaa\n"
34
L"aaaa\n"
35
L"aaaaa\n"
36
L"aaaaaa\n"
37
L"aaaaaaa\n"
38
L"aaaaaaaa\n"
39
L"aaaaaaaaa\n"
40
L"aaaaaaaaaa\n"
41
L"aaaaaaaaaaa\n"
42
L"aaaaaaaaaaaa\n"
43
L"aaaaaaaaaaaaa\n"
44
L"aaaaaaaaaaaaaa\n";
45
 
46
  bool test __attribute__((unused)) = true;
47
  const std::streamsize it = 5;
48
  std::streamsize br = 0;
49
  wchar_t tmp[it];
50
  std::wstringbuf sb(charray, std::ios_base::in);
51
  std::wistream ifs(&sb);
52
  std::streamsize blen = std::wcslen(charray);
53
  VERIFY(!(!ifs));
54
  while(ifs.getline(tmp, it) || ifs.gcount())
55
    {
56
      br += ifs.gcount();
57
      if(ifs.eof())
58
        {
59
          // Just sanity checks to make sure we've extracted the same
60
          // number of chars that were in the streambuf
61
          VERIFY( br == blen );
62
          // Also, we should only set the failbit if we could
63
          // _extract_ no chars from the stream, i.e. the first read
64
          // returned EOF. 
65
          VERIFY( ifs.fail() && ifs.gcount() == 0 );
66
        }
67
      else if(ifs.fail())
68
        {
69
          // delimiter not read
70
          //
71
          // either
72
          // -> extracted no characters
73
          // or
74
          // -> n - 1 characters are stored
75
          ifs.clear(ifs.rdstate() & ~std::ios::failbit);
76
          VERIFY( (ifs.gcount() == 0) || (std::wcslen(tmp) == it - 1) );
77
          VERIFY( !(!ifs) );
78
          continue;
79
        }
80
      else
81
        {
82
          // delimiter was read.
83
          //
84
          // -> wcslen(__s) < n - 1 
85
          // -> delimiter was seen -> gcount() > wcslen(__s)
86
          VERIFY( ifs.gcount() == static_cast<std::streamsize>(std::wcslen(tmp)
87
                                                               + 1) );
88
          continue;
89
        }
90
    }
91
}
92
 
93
int
94
main()
95
{
96
  test05();
97
  return 0;
98
}

powered by: WebSVN 2.1.0

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