open_pointer.pass.cpp revision 13aaf422e49fa4b66642966bfc6078b5d9adde12
1//===----------------------------------------------------------------------===//
2//
3//                     The LLVM Compiler Infrastructure
4//
5// This file is dual licensed under the MIT and the University of Illinois Open
6// Source Licenses. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10// <fstream>
11
12// basic_filebuf<charT,traits>* open(const char* s, ios_base::openmode mode);
13
14#include <fstream>
15#include <cassert>
16
17int main()
18{
19    char temp[L_tmpnam];
20    tmpnam(temp);
21    {
22        std::filebuf f;
23        assert(f.open(temp, std::ios_base::out) != 0);
24        assert(f.is_open());
25        assert(f.sputn("123", 3) == 3);
26    }
27    {
28        std::filebuf f;
29        assert(f.open(temp, std::ios_base::in) != 0);
30        assert(f.is_open());
31        assert(f.sbumpc() == '1');
32        assert(f.sbumpc() == '2');
33        assert(f.sbumpc() == '3');
34    }
35    remove(temp);
36    {
37        std::wfilebuf f;
38        assert(f.open(temp, std::ios_base::out) != 0);
39        assert(f.is_open());
40        assert(f.sputn(L"123", 3) == 3);
41    }
42    {
43        std::wfilebuf f;
44        assert(f.open(temp, std::ios_base::in) != 0);
45        assert(f.is_open());
46        assert(f.sbumpc() == L'1');
47        assert(f.sbumpc() == L'2');
48        assert(f.sbumpc() == L'3');
49    }
50    remove(temp);
51}
52