]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/testsuite/27_io/basic_filebuf/open/wchar_t/1.cc
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 27_io / basic_filebuf / open / wchar_t / 1.cc
CommitLineData
8d9254fc 1// Copyright (C) 2018-2020 Free Software Foundation, Inc.
b0292359
JW
2//
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)
7// any later version.
8
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.
13
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/>.
17
18// { dg-do run { target *-*-mingw* } }
19// { dg-require-fileio "" }
20
21#include <fstream>
22#include <testsuite_hooks.h>
23
24const wchar_t name_01[] = L"filebuf_members-1.tst";
25const wchar_t name_02[] = L"filebuf_members-1.txt";
26
27// Test member functions.
28void test01()
29{
30 const wchar_t* name_03 = L"filebuf_members-w3"; // empty file, need to create
31
32 std::filebuf fb_01; // in
33 std::filebuf fb_02; // out
34 std::filebuf fb_03; // in | out
35
36 // bool is_open()
37 VERIFY( !fb_01.is_open() );
38 VERIFY( !fb_02.is_open() );
39 VERIFY( !fb_03.is_open() );
40
41 // filebuf_type* open(const wchar_t* __s, ios_base::openmode __mode)
42 fb_01.open(name_01, std::ios_base::in | std::ios_base::ate);
43 VERIFY( fb_01.is_open() );
44
45 // Try to open two different files without closing the first:
46 // Should keep the old file attached, and disregard attempt to overthrow.
47 std::filebuf* f = fb_02.open(name_02, std::ios_base::in | std::ios_base::out
48 | std::ios_base::trunc);
49 VERIFY( f );
50 VERIFY( fb_02.is_open() );
51
52 f = fb_02.open(name_03, std::ios_base::in | std::ios_base::out);
53 VERIFY( !f );
54 VERIFY( fb_02.is_open() );
55
56 fb_03.open(name_03, std::ios_base::out | std::ios_base::trunc);
57 VERIFY( fb_03.is_open() );
58}
59
60void test02()
61{
62 std::wfilebuf fb;
63 fb.open(name_01, std::wios::in);
64 VERIFY( fb.is_open() );
65}
66
67int
68main()
69{
70 test01();
71 test02();
72}