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