Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/boost_1_34_1/libs/iostreams/test/array_test.cpp @ 29

Last change on this file since 29 was 29, checked in by landauf, 16 years ago

updated boost from 1_33_1 to 1_34_1

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