Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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