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 <boost/iostreams/detail/fstream.hpp> |
9 | #include <boost/iostreams/device/array.hpp> |
10 | #include <boost/iostreams/stream.hpp> |
11 | #include <boost/test/test_tools.hpp> |
12 | #include <boost/test/unit_test.hpp> |
13 | #include "detail/sequence.hpp" |
14 | #include "detail/temp_file.hpp" |
15 | #include "detail/verification.hpp" |
16 | |
17 | using boost::unit_test::test_suite; |
18 | |
19 | void array_test() |
20 | { |
21 | using namespace std; |
22 | using namespace boost::iostreams; |
23 | using namespace boost::iostreams::test; |
24 | |
25 | test_file test; |
26 | |
27 | //--------------stream<array_source>-------------------------------// |
28 | |
29 | { |
30 | test_sequence<> seq; |
31 | stream<array_source> first(&seq[0], &seq[0] + seq.size()); |
32 | ifstream second(test.name().c_str(), BOOST_IOS::in | BOOST_IOS::binary); |
33 | BOOST_CHECK_MESSAGE( |
34 | compare_streams_in_chars(first, second), |
35 | "failed reading from stream<array_source> in chars" |
36 | ); |
37 | } |
38 | |
39 | { |
40 | test_sequence<> seq; |
41 | stream<array_source> first(&seq[0], &seq[0] + seq.size()); |
42 | ifstream second(test.name().c_str(), BOOST_IOS::in | BOOST_IOS::binary); |
43 | BOOST_CHECK_MESSAGE( |
44 | compare_streams_in_chunks(first, second), |
45 | "failed reading from stream<array_source> in chunks" |
46 | ); |
47 | } |
48 | |
49 | //--------------stream<array_sink>---------------------------------// |
50 | |
51 | { |
52 | vector<char> first(data_reps * data_length(), '?'); |
53 | stream<array_sink> out(&first[0], &first[0] + first.size()); |
54 | write_data_in_chars(os&: out); |
55 | ifstream second(test.name().c_str(), BOOST_IOS::in | BOOST_IOS::binary); |
56 | BOOST_CHECK_MESSAGE( |
57 | compare_container_and_stream(first, second), |
58 | "failed writing to stream<array_sink> in chars" |
59 | ); |
60 | } |
61 | |
62 | { |
63 | vector<char> first(data_reps * data_length(), '?'); |
64 | stream<array_sink> out(&first[0], &first[0] + first.size()); |
65 | write_data_in_chunks(os&: out); |
66 | ifstream second(test.name().c_str(), BOOST_IOS::in | BOOST_IOS::binary); |
67 | BOOST_CHECK_MESSAGE( |
68 | compare_container_and_stream(first, second), |
69 | "failed writing to stream<array_sink> in chunks" |
70 | ); |
71 | } |
72 | |
73 | //--------------random access---------------------------------------------// |
74 | |
75 | { |
76 | vector<char> first(data_reps * data_length(), '?'); |
77 | stream<boost::iostreams::array> io(&first[0], &first[0] + first.size()); |
78 | BOOST_CHECK_MESSAGE( |
79 | test_seekable_in_chars(io), |
80 | "failed seeking within stream<array>, in chars" |
81 | ); |
82 | } |
83 | |
84 | { |
85 | vector<char> first(data_reps * data_length(), '?'); |
86 | stream<boost::iostreams::array> io(&first[0], &first[0] + first.size()); |
87 | BOOST_CHECK_MESSAGE( |
88 | test_seekable_in_chars(io), |
89 | "failed seeking within stream<array>, in chunks" |
90 | ); |
91 | } |
92 | } |
93 | |
94 | test_suite* init_unit_test_suite(int, char* []) |
95 | { |
96 | test_suite* test = BOOST_TEST_SUITE("array test" ); |
97 | test->add(BOOST_TEST_CASE(&array_test)); |
98 | return test; |
99 | } |
100 | |