1 | // (C) Copyright Jonathan Turkanis 2004 |
---|
2 | // Distributed under the Boost Software License, Version 1.0. (See accompanying |
---|
3 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt.) |
---|
4 | |
---|
5 | // See http://www.boost.org/libs/iostreams for documentation. |
---|
6 | |
---|
7 | #include <fstream> |
---|
8 | #include <boost/config.hpp> // MSVC. |
---|
9 | #include <boost/detail/workaround.hpp> |
---|
10 | #include <boost/iostreams/copy.hpp> |
---|
11 | #include <boost/iostreams/device/file.hpp> |
---|
12 | #include <boost/test/test_tools.hpp> |
---|
13 | #include <boost/test/unit_test.hpp> |
---|
14 | #include "detail/temp_file.hpp" |
---|
15 | #include "detail/verification.hpp" |
---|
16 | |
---|
17 | using namespace std; |
---|
18 | using namespace boost; |
---|
19 | using namespace boost::iostreams; |
---|
20 | using namespace boost::iostreams::test; |
---|
21 | using boost::unit_test::test_suite; |
---|
22 | |
---|
23 | void copy_test() |
---|
24 | { |
---|
25 | test_file test; |
---|
26 | |
---|
27 | { |
---|
28 | temp_file dest; |
---|
29 | ifstream first(test.name().c_str(), in_mode); |
---|
30 | ofstream second(dest.name().c_str(), out_mode); |
---|
31 | boost::iostreams::copy(first, second); |
---|
32 | first.close(); |
---|
33 | second.close(); |
---|
34 | BOOST_CHECK_MESSAGE( |
---|
35 | compare_files(test.name(), dest.name()), |
---|
36 | "failed copying from stream to stream" |
---|
37 | ); |
---|
38 | } |
---|
39 | |
---|
40 | { |
---|
41 | temp_file dest; |
---|
42 | ifstream first(test.name().c_str(), in_mode); |
---|
43 | boost::iostreams::copy(first, file_sink(dest.name(), out_mode)); |
---|
44 | first.close(); |
---|
45 | BOOST_CHECK_MESSAGE( |
---|
46 | compare_files(test.name(), dest.name()), |
---|
47 | "failed copying from stream to file_sink" |
---|
48 | ); |
---|
49 | } |
---|
50 | |
---|
51 | { |
---|
52 | temp_file dest; |
---|
53 | ofstream second(dest.name().c_str(), out_mode); |
---|
54 | boost::iostreams::copy(file_source(test.name(), in_mode), second); |
---|
55 | second.close(); |
---|
56 | BOOST_CHECK_MESSAGE( |
---|
57 | compare_files(test.name(), dest.name()), |
---|
58 | "failed copying from file_source to stream" |
---|
59 | ); |
---|
60 | } |
---|
61 | |
---|
62 | { |
---|
63 | temp_file dest; |
---|
64 | boost::iostreams::copy( file_source(test.name(), in_mode), |
---|
65 | file_sink(dest.name(), out_mode) ); |
---|
66 | BOOST_CHECK_MESSAGE( |
---|
67 | compare_files(test.name(), dest.name()), |
---|
68 | "failed copying from file_source to file_sink" |
---|
69 | ); |
---|
70 | } |
---|
71 | } |
---|
72 | |
---|
73 | test_suite* init_unit_test_suite(int, char* []) |
---|
74 | { |
---|
75 | test_suite* test = BOOST_TEST_SUITE("copy test"); |
---|
76 | test->add(BOOST_TEST_CASE(©_test)); |
---|
77 | return test; |
---|
78 | } |
---|