]> git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/ext/stdio_filebuf/char/10063-1.cc
11.cc: Include <cstring>.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / ext / stdio_filebuf / char / 10063-1.cc
1 // Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007
2 // Free Software Foundation
3 //
4 // This file is part of the GNU ISO C++ Library. This library is free
5 // software; you can redistribute it and/or modify it under the
6 // terms of the GNU General Public License as published by the
7 // Free Software Foundation; either version 2, or (at your option)
8 // any later version.
9
10 // This library is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
14
15 // You should have received a copy of the GNU General Public License along
16 // with this library; see the file COPYING. If not, write to the Free
17 // Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
18 // USA.
19
20 // { dg-require-fileio "" }
21
22 #include <cstdio>
23 #include <fstream>
24 #include <cstring>
25 #include <ext/stdio_filebuf.h>
26 #include <testsuite_hooks.h>
27
28 void test1()
29 {
30 using namespace std;
31 bool test __attribute__((unused)) = true;
32
33 FILE* file = fopen("tmp_10063-1", "w");
34 putc('0', file);
35 putc('1', file);
36 {
37 __gnu_cxx::stdio_filebuf<char> sbuf(file, ios_base::out);
38 sbuf.sputc('2');
39 sbuf.sputc('3');
40 }
41 putc('4', file);
42 fclose(file);
43
44 filebuf fbuf;
45 fbuf.open("tmp_10063-1", ios_base::in);
46 char buf[10];
47 streamsize n = fbuf.sgetn(buf, sizeof(buf));
48 fbuf.close();
49
50 VERIFY(n == 5);
51 VERIFY(!memcmp(buf, "01234", 5));
52 }
53
54 int main()
55 {
56 test1();
57 return 0;
58 }