]>
git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/45628-2.cc
1 // Copyright (C) 2010-2022 Free Software Foundation, Inc.
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)
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.
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/>.
18 // { dg-require-fileio "" }
21 #include <testsuite_hooks.h>
22 #include <testsuite_character.h>
24 const char name_01
[] = "tmp_seekoff_45628.tst";
26 unsigned underflows
, overflows
;
29 : public std::basic_filebuf
<__gnu_test::pod_uchar
>
35 return std::basic_filebuf
<__gnu_test::pod_uchar
>::underflow();
41 return std::basic_filebuf
<__gnu_test::pod_uchar
>::overflow(c
);
48 using __gnu_test::pod_uchar
;
49 std::locale
loc(std::locale::classic(),
50 new std::codecvt
<my_filebuf::traits_type::char_type
, char,
51 my_filebuf::traits_type::state_type
>);
53 my_filebuf::pos_type opos
[3], ipos
[3];
57 q
.open(name_01
, std::ios_base::in
| std::ios_base::out
58 | std::ios_base::trunc
);
60 q
.sputc(pod_uchar::from
<char>('a'));
61 opos
[0] = q
.pubseekoff(0, std::ios_base::cur
);
62 q
.sputc(pod_uchar::from
<char>('b'));
63 opos
[1] = q
.pubseekoff(0, std::ios_base::cur
);
64 q
.sputc(pod_uchar::from
<char>('c'));
65 opos
[2] = q
.pubseekoff(0, std::ios_base::cur
);
67 VERIFY( overflows
<= 9 ); // pubseekoff calls overflow twice if converting.
68 // NB: checking opos==ipos is not very rigorous as long as it flushes, since
69 // all positions will be at initial state.
70 q
.pubseekoff(0, std::ios_base::beg
);
73 VERIFY( underflows
== 1 );
75 ipos
[0] = q
.pubseekoff(0, std::ios_base::cur
);
76 VERIFY( ipos
[0] == opos
[0] );
78 ipos
[1] = q
.pubseekoff(0, std::ios_base::cur
);
79 VERIFY( ipos
[1] == opos
[1] );
81 ipos
[2] = q
.pubseekoff(0, std::ios_base::cur
);
82 VERIFY( ipos
[2] == opos
[2] );
84 VERIFY( underflows
== 1 ); // pubseekoff never flushes get area
86 // Bonus test: check automatic mode switches.
87 q
.sputc(pod_uchar::from
<char>('d'));
89 q
.pubseekpos( ipos
[1] );
90 q
.sputc(pod_uchar::from
<char>('e'));
92 VERIFY( my_filebuf::traits_type::eq(
93 my_filebuf::traits_type::to_char_type(q
.sgetc()),
94 pod_uchar::from
<char>('d')) );