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.)
6 // See http://www.boost.org/libs/iostreams for documentation.
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"
17 using boost::unit_test::test_suite;
22 using namespace boost::iostreams;
23 using namespace boost::iostreams::test;
27 //--------------stream<array_source>-------------------------------//
31 stream<array_source> first(&seq[0], &seq[0] + seq.size());
32 ifstream second(test.name().c_str(), BOOST_IOS::in | BOOST_IOS::binary);
34 compare_streams_in_chars(first, second),
35 "failed reading from stream<array_source> in chars"
41 stream<array_source> first(&seq[0], &seq[0] + seq.size());
42 ifstream second(test.name().c_str(), BOOST_IOS::in | BOOST_IOS::binary);
44 compare_streams_in_chunks(first, second),
45 "failed reading from stream<array_source> in chunks"
49 //--------------stream<array_sink>---------------------------------//
52 vector<char> first(data_reps * data_length(), '?');
53 stream<array_sink> out(&first[0], &first[0] + first.size());
54 write_data_in_chars(out);
55 ifstream second(test.name().c_str(), BOOST_IOS::in | BOOST_IOS::binary);
57 compare_container_and_stream(first, second),
58 "failed writing to stream<array_sink> in chars"
63 vector<char> first(data_reps * data_length(), '?');
64 stream<array_sink> out(&first[0], &first[0] + first.size());
65 write_data_in_chunks(out);
66 ifstream second(test.name().c_str(), BOOST_IOS::in | BOOST_IOS::binary);
68 compare_container_and_stream(first, second),
69 "failed writing to stream<array_sink> in chunks"
73 //--------------random access---------------------------------------------//
76 vector<char> first(data_reps * data_length(), '?');
77 stream<boost::iostreams::array> io(&first[0], &first[0] + first.size());
79 test_seekable_in_chars(io),
80 "failed seeking within stream<array>, in chars"
85 vector<char> first(data_reps * data_length(), '?');
86 stream<boost::iostreams::array> io(&first[0], &first[0] + first.size());
88 test_seekable_in_chars(io),
89 "failed seeking within stream<array>, in chunks"
94 test_suite* init_unit_test_suite(int, char* [])
96 test_suite* test = BOOST_TEST_SUITE("array test");
97 test->add(BOOST_TEST_CASE(&array_test));