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

Subversion Repositories scarts

[/] [scarts/] [trunk/] [toolchain/] [scarts-gcc/] [gcc-4.1.1/] [libstdc++-v3/] [testsuite/] [27_io/] [basic_istream/] [extractors_character/] [wchar_t/] [4.cc] - Blame information for rev 19

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 19 jlechner
// 2005-07-22  Paolo Carlini  <pcarlini@suse.de>
2
 
3
// Copyright (C) 2005 Free Software Foundation
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, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
19
// USA.
20
 
21
// 27.6.1.2.3 basic_istream::operator>>
22
 
23
#include <istream>
24
#include <string>
25
#include <fstream>
26
#include <testsuite_hooks.h>
27
 
28
using namespace std;
29
 
30
wstring prepare(wstring::size_type len, unsigned nchunks)
31
{
32
  wstring ret;
33
  for (unsigned i = 0; i < nchunks; ++i)
34
    {
35
      for (wstring::size_type j = 0; j < len; ++j)
36
        ret.push_back(L'a' + rand() % 26);
37
      len *= 2;
38
      ret.push_back(L' ');
39
    }
40
  return ret;
41
}
42
 
43
void check(wistream& stream, const wstring& str, unsigned nchunks)
44
{
45
  bool test __attribute__((unused)) = true;
46
 
47
  wchar_t* chunk = new wchar_t[str.size()];
48
  wmemset(chunk, L'X', str.size());
49
 
50
  wstring::size_type index = 0, index_new = 0;
51
  unsigned n = 0;
52
 
53
  while (stream >> chunk)
54
    {
55
      index_new = str.find(' ', index);
56
      VERIFY( !str.compare(index, index_new - index, chunk) );
57
      index = index_new + 1;
58
      ++n;
59
      wmemset(chunk, L'X', str.size());
60
    }
61
  VERIFY( stream.eof() );
62
  VERIFY( n == nchunks );
63
 
64
  delete[] chunk;
65
}
66
 
67
// istream& operator>>(istream&, charT*)
68
void test01()
69
{
70
  const char filename[] = "inserters_extractors-4.txt";
71
 
72
  const unsigned nchunks = 10;
73
  const wstring data = prepare(666, nchunks);
74
 
75
  wofstream ofstrm;
76
  ofstrm.open(filename);
77
  ofstrm.write(data.data(), data.size());
78
  ofstrm.close();
79
 
80
  wifstream ifstrm;
81
  ifstrm.open(filename);
82
  check(ifstrm, data, nchunks);
83
  ifstrm.close();
84
}
85
 
86
int main()
87
{
88
  test01();
89
  return 0;
90
}

powered by: WebSVN 2.1.0

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