]>
git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/char/4.cc
1 // { dg-require-fileio "" }
3 // Copyright (C) 2010-2019 Free Software Foundation, Inc.
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)
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.
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/>.
20 // 27.8.1.4 Overridden virtual functions
24 #include <testsuite_hooks.h>
30 typedef filebuf::pos_type pos_type
;
31 const char name
[] = "tmp_seekoff-4.tst";
33 const size_t size
= 12;
38 fb
.open(name
, ios_base::in
| ios_base::out
| ios_base::trunc
);
40 n
= fb
.sputn("abcd", 4);
43 fb
.pubseekoff(0, ios_base::beg
);
46 VERIFY( !memcmp(buf
, "abc", 3) );
48 // Check read => write without pubseekoff(0, ios_base::cur)
50 n
= fb
.sputn("ef", 2);
53 fb
.pubseekoff(0, ios_base::beg
);
55 n
= fb
.sgetn(buf
, size
);
57 VERIFY( !memcmp(buf
, "abcef", 5) );
59 fb
.pubseekoff(0, ios_base::beg
);
60 n
= fb
.sputn("gh", 2);
63 // Check write => read without pubseekoff(0, ios_base::cur)
65 n
= fb
.sgetn( buf
, 3 );
66 VERIFY( !memcmp(buf
, "cef", 3) );
68 n
= fb
.sputn("ijkl", 4);
71 fb
.pubseekoff(0, ios_base::beg
);
74 VERIFY( !memcmp(buf
, "gh", 2) );
76 fb
.pubseekoff(0, ios_base::end
);
77 n
= fb
.sputn("mno", 3);
80 fb
.pubseekoff(0, ios_base::beg
);
81 n
= fb
.sgetn(buf
, size
);
83 VERIFY( !memcmp(buf
, "ghcefijklmno", 12) );