]>
git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/27_io/basic_filebuf/seekoff/45628-2.cc
1 // Copyright (C) 2010-2016 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 bool test
__attribute__((unused
)) = true;
50 using __gnu_test::pod_uchar
;
51 std::locale
loc(std::locale::classic(),
52 new std::codecvt
<my_filebuf::traits_type::char_type
, char,
53 my_filebuf::traits_type::state_type
>);
55 my_filebuf::pos_type opos
[3], ipos
[3];
59 q
.open(name_01
, std::ios_base::in
| std::ios_base::out
60 | std::ios_base::trunc
);
62 q
.sputc(pod_uchar::from
<char>('a'));
63 opos
[0] = q
.pubseekoff(0, std::ios_base::cur
);
64 q
.sputc(pod_uchar::from
<char>('b'));
65 opos
[1] = q
.pubseekoff(0, std::ios_base::cur
);
66 q
.sputc(pod_uchar::from
<char>('c'));
67 opos
[2] = q
.pubseekoff(0, std::ios_base::cur
);
69 VERIFY( overflows
<= 9 ); // pubseekoff calls overflow twice if converting.
70 // NB: checking opos==ipos is not very rigorous as long as it flushes, since
71 // all positions will be at initial state.
72 q
.pubseekoff(0, std::ios_base::beg
);
75 VERIFY( underflows
== 1 );
77 ipos
[0] = q
.pubseekoff(0, std::ios_base::cur
);
78 VERIFY( ipos
[0] == opos
[0] );
80 ipos
[1] = q
.pubseekoff(0, std::ios_base::cur
);
81 VERIFY( ipos
[1] == opos
[1] );
83 ipos
[2] = q
.pubseekoff(0, std::ios_base::cur
);
84 VERIFY( ipos
[2] == opos
[2] );
86 VERIFY( underflows
== 1 ); // pubseekoff never flushes get area
88 // Bonus test: check automatic mode switches.
89 q
.sputc(pod_uchar::from
<char>('d'));
91 q
.pubseekpos( ipos
[1] );
92 q
.sputc(pod_uchar::from
<char>('e'));
94 VERIFY( my_filebuf::traits_type::eq(
95 my_filebuf::traits_type::to_char_type(q
.sgetc()),
96 pod_uchar::from
<char>('d')) );