• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // (C) Copyright 2008 CodeRage, LLC (turkanis at coderage dot com)
2 // (C) Copyright 2004-2007 Jonathan Turkanis
3 // Distributed under the Boost Software License, Version 1.0. (See accompanying
4 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt.)
5 
6 // See http://www.boost.org/libs/iostreams for documentation.
7 
8 #include <fstream>
9 #include <boost/iostreams/device/file.hpp>
10 #include <boost/iostreams/filtering_stream.hpp>
11 #include <boost/test/test_tools.hpp>
12 #include <boost/test/unit_test.hpp>
13 #include "detail/temp_file.hpp"
14 #include "detail/verification.hpp"
15 
16 using namespace std;
17 using namespace boost;
18 using namespace boost::iostreams;
19 using namespace boost::iostreams::test;
20 using boost::unit_test::test_suite;
21 
seekable_file_test()22 void seekable_file_test()
23 {
24     {
25         temp_file temp;
26         file f( temp.name(),
27                 BOOST_IOS::in | BOOST_IOS::out |
28                 BOOST_IOS::trunc | BOOST_IOS::binary);
29         filtering_stream<seekable> io(f);
30         io.exceptions(BOOST_IOS::failbit | BOOST_IOS::badbit);
31         BOOST_CHECK_MESSAGE(
32             test_seekable_in_chars(io),
33             "failed seeking within a file, in chars"
34         );
35     }
36 
37     {
38         temp_file temp;
39         file f( temp.name(),
40                 BOOST_IOS::in | BOOST_IOS::out |
41                 BOOST_IOS::trunc | BOOST_IOS::binary);
42         filtering_stream<seekable> io(f);
43         io.exceptions(BOOST_IOS::failbit | BOOST_IOS::badbit);
44         BOOST_CHECK_MESSAGE(
45             test_seekable_in_chunks(io),
46             "failed seeking within a file, in chunks"
47         );
48     }
49 }
50 
init_unit_test_suite(int,char * [])51 test_suite* init_unit_test_suite(int, char* [])
52 {
53     test_suite* test = BOOST_TEST_SUITE("seekable file test");
54     test->add(BOOST_TEST_CASE(&seekable_file_test));
55     return test;
56 }
57