1176491Smarcel// Copyright (C) 2003-2015 Free Software Foundation, Inc.
2176491Smarcel//
3176491Smarcel// This file is part of the GNU ISO C++ Library.  This library is free
4176491Smarcel// software; you can redistribute it and/or modify it under the
5176491Smarcel// terms of the GNU General Public License as published by the
6176491Smarcel// Free Software Foundation; either version 3, or (at your option)
7176491Smarcel// any later version.
8176491Smarcel
9176491Smarcel// This library is distributed in the hope that it will be useful,
10176491Smarcel// but WITHOUT ANY WARRANTY; without even the implied warranty of
11176491Smarcel// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12176491Smarcel// GNU General Public License for more details.
13176491Smarcel
14176491Smarcel// You should have received a copy of the GNU General Public License along
15176491Smarcel// with this library; see the file COPYING3.  If not see
16176491Smarcel// <http://www.gnu.org/licenses/>.
17176491Smarcel
18176491Smarcel// 27.8.1.3 filebuf member functions
19176491Smarcel
20176491Smarcel// { dg-require-fileio "" }
21176491Smarcel
22176491Smarcel#include <locale>
23176491Smarcel#include <fstream>
24176491Smarcel#include <testsuite_hooks.h>
25176491Smarcel#include <testsuite_character.h>
26176491Smarcel
27176491Smarcel// libstdc++/12790
28176491Smarcelvoid test01()
29176491Smarcel{
30176491Smarcel  using namespace std;
31176491Smarcel  using __gnu_test::pod_uchar;
32176491Smarcel  typedef basic_filebuf<pod_uchar>::traits_type traits_type;
33176491Smarcel
34176491Smarcel  bool test __attribute__((unused)) = true;
35176491Smarcel  const char* name = "tmp_close_12790";
36176491Smarcel
37176491Smarcel  locale loc(locale::classic(),
38176491Smarcel	     new codecvt<traits_type::char_type, char,
39176491Smarcel	     traits_type::state_type>);
40176491Smarcel
41176491Smarcel  basic_filebuf<pod_uchar> fb;
42176491Smarcel  fb.pubsetbuf(0, 0);
43176491Smarcel  fb.pubimbue(loc);
44176491Smarcel
45176491Smarcel  fb.open(name, ios_base::out | ios_base::trunc);
46176491Smarcel  fb.sputc(pod_uchar::from<char>('b'));
47176491Smarcel  fb.sputc(pod_uchar::from<char>(0xff));
48176491Smarcel  fb.sputc(pod_uchar::from<char>(0));
49176491Smarcel
50178030Sgrehan  // Check that close() writes unshift sequence
51176491Smarcel  fb.close();
52176491Smarcel
53176491Smarcel  fb.open(name, ios_base::in | ios_base::out | ios_base::ate);
54176491Smarcel
55176491Smarcel  fb.sputc(pod_uchar::from<char>('a'));
56176491Smarcel  fb.sputc(pod_uchar::from<char>(0xff));
57176491Smarcel  fb.sputc(pod_uchar::from<char>(0));
58176491Smarcel
59176491Smarcel  fb.close();
60176491Smarcel
61176491Smarcel  fb.open(name, ios_base::in);
62176491Smarcel
63176491Smarcel  fb.sbumpc();
64176491Smarcel  fb.sbumpc();
65176491Smarcel  fb.sbumpc();
66176491Smarcel
67176491Smarcel  traits_type::int_type c = fb.sbumpc();
68176491Smarcel  VERIFY( c != traits_type::eof() );
69176491Smarcel  VERIFY( traits_type::eq(traits_type::to_char_type(c),
70176491Smarcel			  pod_uchar::from<char>('a')) );
71176491Smarcel
72176491Smarcel  fb.close();
73176491Smarcel}
74176491Smarcel
75176491Smarcelint main()
76176491Smarcel{
77176491Smarcel  test01();
78176491Smarcel  return 0;
79176491Smarcel}
80176491Smarcel