libstdc++: drop bogus 'dg_do run' directive
[official-gcc.git] / libstdc++-v3 / testsuite / 27_io / basic_filebuf / seekoff / char / 4.cc
blob4e2f51391cde7cb4cdf23bc107c7daeb5d12f966
1 // { dg-require-fileio "" }
3 // Copyright (C) 2010-2024 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.
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
22 #include <fstream>
23 #include <cstring>
24 #include <testsuite_hooks.h>
26 void test01()
28 using namespace std;
30 typedef filebuf::pos_type pos_type;
31 const char name[] = "tmp_seekoff-4.tst";
33 const size_t size = 12;
34 char buf[size];
35 streamsize n;
37 filebuf fb;
38 fb.open(name, ios_base::in | ios_base::out | ios_base::trunc);
40 n = fb.sputn("abcd", 4);
41 VERIFY( n == 4 );
43 fb.pubseekoff(0, ios_base::beg);
44 n = fb.sgetn(buf, 3);
45 VERIFY( n == 3 );
46 VERIFY( !memcmp(buf, "abc", 3) );
48 // Check read => write without pubseekoff(0, ios_base::cur)
50 n = fb.sputn("ef", 2);
51 VERIFY( n == 2 );
53 fb.pubseekoff(0, ios_base::beg);
55 n = fb.sgetn(buf, size);
56 VERIFY( n == 5 );
57 VERIFY( !memcmp(buf, "abcef", 5) );
59 fb.pubseekoff(0, ios_base::beg);
60 n = fb.sputn("gh", 2);
61 VERIFY( n == 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);
69 VERIFY( n == 4 );
71 fb.pubseekoff(0, ios_base::beg);
72 n = fb.sgetn(buf, 2);
73 VERIFY( n == 2 );
74 VERIFY( !memcmp(buf, "gh", 2) );
76 fb.pubseekoff(0, ios_base::end);
77 n = fb.sputn("mno", 3);
78 VERIFY( n == 3 );
80 fb.pubseekoff(0, ios_base::beg);
81 n = fb.sgetn(buf, size);
82 VERIFY( n == 12 );
83 VERIFY( !memcmp(buf, "ghcefijklmno", 12) );
85 fb.close();
88 int main()
90 test01();
91 return 0;