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