1 | // fstream_test.cpp --------------------------------------------------------// |
---|
2 | |
---|
3 | // Copyright Beman Dawes 2002. |
---|
4 | // Use, modification, and distribution is subject to the Boost Software |
---|
5 | // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at |
---|
6 | // http://www.boost.org/LICENSE_1_0.txt) |
---|
7 | |
---|
8 | // See library home page at http://www.boost.org/libs/filesystem |
---|
9 | |
---|
10 | #include <boost/filesystem/fstream.hpp> |
---|
11 | #include <string> |
---|
12 | #include <cstdio> // for std::remove |
---|
13 | |
---|
14 | namespace fs = boost::filesystem; |
---|
15 | |
---|
16 | #include <boost/config.hpp> |
---|
17 | #ifdef BOOST_NO_STDC_NAMESPACE |
---|
18 | namespace std { using ::remove; } |
---|
19 | #endif |
---|
20 | |
---|
21 | #include <boost/test/minimal.hpp> |
---|
22 | |
---|
23 | int test_main( int, char*[] ) |
---|
24 | { |
---|
25 | { // basic_filebuf runtime results are ignored; as long as they don't crash |
---|
26 | // or throw we are satisfied |
---|
27 | fs::basic_filebuf<char> bfb; |
---|
28 | fs::filebuf cfb; |
---|
29 | |
---|
30 | bfb.open( "fstream_test_bffoo", std::ios_base::in ); |
---|
31 | cfb.open( "fstream_test_bffoo", std::ios_base::in ); |
---|
32 | |
---|
33 | # ifndef BOOST_NO_STD_WSTRING |
---|
34 | fs::wfilebuf wfb; |
---|
35 | wfb.open( "fstream_test_bffoo", std::ios_base::in ); |
---|
36 | # endif |
---|
37 | } |
---|
38 | |
---|
39 | std::remove( "fstream_test_bfoo" ); |
---|
40 | std::remove( "fstream_test_cfoo" ); |
---|
41 | # ifndef BOOST_NO_STD_WSTRING |
---|
42 | std::remove( "fstream_test_wfoo" ); |
---|
43 | # endif |
---|
44 | { |
---|
45 | fs::basic_ofstream<char> bofs( "fstream_test_bfoo" ); |
---|
46 | fs::ofstream cofs( "fstream_test_cfoo" ); |
---|
47 | |
---|
48 | BOOST_CHECK( bofs.is_open() ); |
---|
49 | BOOST_CHECK( cofs.is_open() ); |
---|
50 | |
---|
51 | bofs << "fstream_test_bfoo"; |
---|
52 | cofs << "fstream_test_cfoo"; |
---|
53 | |
---|
54 | // these will fail, but they still test the interface |
---|
55 | bofs.open( "fstream_test_bfoo" ); |
---|
56 | cofs.open( "fstream_test_cfoo" ); |
---|
57 | |
---|
58 | # ifndef BOOST_NO_STD_WSTRING |
---|
59 | fs::wofstream wofs( "fstream_test_wfoo" ); |
---|
60 | BOOST_CHECK( wofs.is_open() ); |
---|
61 | wofs << L"fstream_test_wfoo"; |
---|
62 | wofs.open( "fstream_test_wfoo" ); // expected to fail |
---|
63 | # endif |
---|
64 | } |
---|
65 | |
---|
66 | { |
---|
67 | fs::basic_ifstream<char> bifs( "fstream_test_bfoo" ); |
---|
68 | fs::ifstream cifs( "fstream_test_cfoo" ); |
---|
69 | |
---|
70 | BOOST_CHECK( bifs.is_open() ); |
---|
71 | BOOST_CHECK( cifs.is_open() ); |
---|
72 | |
---|
73 | std::string b; |
---|
74 | std::string c; |
---|
75 | |
---|
76 | bifs >> b; |
---|
77 | cifs >> c; |
---|
78 | |
---|
79 | BOOST_CHECK( b == "fstream_test_bfoo" ); |
---|
80 | BOOST_CHECK( c == "fstream_test_cfoo" ); |
---|
81 | |
---|
82 | // these will fail, but they still test the interface |
---|
83 | bifs.open( "fstream_test_bfoo" ); |
---|
84 | cifs.open( "fstream_test_cfoo" ); |
---|
85 | |
---|
86 | # ifndef BOOST_NO_STD_WSTRING |
---|
87 | fs::wifstream wifs( "fstream_test_wfoo" ); |
---|
88 | BOOST_CHECK( wifs.is_open() ); |
---|
89 | std::wstring w; |
---|
90 | wifs >> w; |
---|
91 | BOOST_CHECK( w == L"fstream_test_wfoo" ); |
---|
92 | wifs.open( "fstream_test_wfoo" ); // expected to fail |
---|
93 | # endif |
---|
94 | } |
---|
95 | |
---|
96 | { |
---|
97 | fs::basic_fstream<char> bfs( "fstream_test_bfoo" ); |
---|
98 | fs::fstream cfs( "fstream_test_cfoo" ); |
---|
99 | |
---|
100 | BOOST_CHECK( bfs.is_open() ); |
---|
101 | BOOST_CHECK( cfs.is_open() ); |
---|
102 | |
---|
103 | std::string b; |
---|
104 | std::string c; |
---|
105 | |
---|
106 | bfs >> b; |
---|
107 | cfs >> c; |
---|
108 | |
---|
109 | BOOST_CHECK( b == "fstream_test_bfoo" ); |
---|
110 | BOOST_CHECK( c == "fstream_test_cfoo" ); |
---|
111 | |
---|
112 | // these will fail, but they still test the interface |
---|
113 | bfs.open( "fstream_test_bfoo" ); |
---|
114 | cfs.open( "fstream_test_cfoo" ); |
---|
115 | |
---|
116 | # ifndef BOOST_NO_STD_WSTRING |
---|
117 | fs::wfstream wfs( "fstream_test_wfoo" ); |
---|
118 | BOOST_CHECK( wfs.is_open() ); |
---|
119 | std::wstring w; |
---|
120 | wfs >> w; |
---|
121 | BOOST_CHECK( w == L"fstream_test_wfoo" ); |
---|
122 | wfs.open( "fstream_test_wfoo" ); // expected to fail |
---|
123 | # endif |
---|
124 | } |
---|
125 | |
---|
126 | // std::remove( "fstream_test_bfoo" ); |
---|
127 | // std::remove( "fstream_test_cfoo" ); |
---|
128 | // # ifndef BOOST_NO_STD_WSTRING |
---|
129 | // std::remove( "fstream_test_wfoo" ); |
---|
130 | // # endif |
---|
131 | return 0; |
---|
132 | } |
---|