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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-dev/] [or1k-gcc/] [libstdc++-v3/] [testsuite/] [27_io/] [basic_filebuf/] [seekoff/] [char/] [4.cc] - Blame information for rev 749

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

Line No. Rev Author Line
1 742 jeremybenn
// { dg-require-fileio "" }
2
 
3
// Copyright (C) 2010 Free Software Foundation, Inc.
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 3, 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 COPYING3.  If not see
18
// <http://www.gnu.org/licenses/>.
19
 
20
// 27.8.1.4 Overridden virtual functions
21
 
22
#include <fstream>
23
#include <cstring>
24
#include <testsuite_hooks.h>
25
 
26
void test01()
27
{
28
  using namespace std;
29
  bool test __attribute__((unused)) = true;
30
 
31
  typedef filebuf::pos_type pos_type;
32
  const char name[] = "tmp_seekoff-4.tst";
33
 
34
  const size_t size = 12;
35
  char buf[size];
36
  streamsize n;
37
 
38
  filebuf fb;
39
  fb.open(name, ios_base::in | ios_base::out | ios_base::trunc);
40
 
41
  n = fb.sputn("abcd", 4);
42
  VERIFY( n == 4 );
43
 
44
  fb.pubseekoff(0, ios_base::beg);
45
  n = fb.sgetn(buf, 3);
46
  VERIFY( n == 3 );
47
  VERIFY( !memcmp(buf, "abc", 3) );
48
 
49
  // Check read => write without pubseekoff(0, ios_base::cur)
50
 
51
  n = fb.sputn("ef", 2);
52
  VERIFY( n == 2 );
53
 
54
  fb.pubseekoff(0, ios_base::beg);
55
 
56
  n = fb.sgetn(buf, size);
57
  VERIFY( n == 5 );
58
  VERIFY( !memcmp(buf, "abcef", 5) );
59
 
60
  fb.pubseekoff(0, ios_base::beg);
61
  n = fb.sputn("gh", 2);
62
  VERIFY( n == 2 );
63
 
64
  // Check write => read without pubseekoff(0, ios_base::cur)
65
 
66
  n = fb.sgetn( buf, 3 );
67
  VERIFY( !memcmp(buf, "cef", 3) );
68
 
69
  n = fb.sputn("ijkl", 4);
70
  VERIFY( n == 4 );
71
 
72
  fb.pubseekoff(0, ios_base::beg);
73
  n = fb.sgetn(buf, 2);
74
  VERIFY( n == 2 );
75
  VERIFY( !memcmp(buf, "gh", 2) );
76
 
77
  fb.pubseekoff(0, ios_base::end);
78
  n = fb.sputn("mno", 3);
79
  VERIFY( n == 3 );
80
 
81
  fb.pubseekoff(0, ios_base::beg);
82
  n = fb.sgetn(buf, size);
83
  VERIFY( n == 12 );
84
  VERIFY( !memcmp(buf, "ghcefijklmno", 12) );
85
 
86
  fb.close();
87
}
88
 
89
int main()
90
{
91
  test01();
92
  return 0;
93
}

powered by: WebSVN 2.1.0

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