Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/boost_1_34_1/libs/range/test/sub_range.cpp @ 33

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

updated boost from 1_33_1 to 1_34_1

File size: 3.8 KB
Line 
1// Boost.Range library
2//
3//  Copyright Thorsten Ottosen 2003-2004. Use, modification and
4//  distribution is subject to the Boost Software License, Version
5//  1.0. (See accompanying file LICENSE_1_0.txt or copy at
6//  http://www.boost.org/LICENSE_1_0.txt)
7//
8// For more information, see http://www.boost.org/libs/range/
9//
10
11
12#include <boost/detail/workaround.hpp>
13
14#if BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564))
15#  pragma warn -8091 // supress warning in Boost.Test
16#  pragma warn -8057 // unused argument argc/argv in Boost.Test
17#endif
18
19#include <boost/range/sub_range.hpp>
20#include <boost/test/test_tools.hpp>
21#include <iostream>
22#include <string>
23#include <vector>
24
25using namespace boost;
26using namespace std;
27
28void check_sub_range()
29{
30     
31    typedef string::iterator               iterator;
32    typedef string::const_iterator         const_iterator;
33    typedef iterator_range<iterator>       irange;
34    typedef iterator_range<const_iterator> cirange;
35    string       str  = "hello world";
36    const string cstr = "const world";
37    irange r    = make_iterator_range( str );
38    r           = make_iterator_range( str.begin(), str.end() );
39    cirange r2  = make_iterator_range( cstr );
40    r2          = make_iterator_range( cstr.begin(), cstr.end() );
41    r2          = make_iterator_range( str );
42 
43    typedef sub_range<string>       srange;
44    typedef sub_range<const string> csrange;
45    srange s     = r;
46    BOOST_CHECK( r == r );
47    BOOST_CHECK( s == r );
48    s            = make_iterator_range( str );
49    csrange s2   = r;
50    s2           = r2;
51    s2           = make_iterator_range( cstr );
52    BOOST_CHECK( r2 == r2 );
53    BOOST_CHECK( s2 != r2 );
54    s2           = make_iterator_range( str );
55    BOOST_CHECK( !(s != s) );
56   
57    BOOST_CHECK( r.begin() == s.begin() );
58    BOOST_CHECK( r2.begin()== s2.begin() );
59    BOOST_CHECK( r.end()   == s.end() );
60    BOOST_CHECK( r2.end()  == s2.end() );
61    BOOST_CHECK_EQUAL( r.size(), s.size() );
62    BOOST_CHECK_EQUAL( r2.size(), s2.size() );
63   
64//#if BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564))
65//    if( !(bool)r )
66//        BOOST_CHECK( false );
67//    if( !(bool)r2 )
68//        BOOST_CHECK( false );
69//    if( !(bool)s )
70//        BOOST_CHECK( false );
71//    if( !(bool)s2 )
72//        BOOST_CHECK( false );   
73//#else
74    if( !r )
75        BOOST_CHECK( false );
76    if( !r2 )
77        BOOST_CHECK( false );
78    if( !s )
79        BOOST_CHECK( false );
80    if( !s2 )
81        BOOST_CHECK( false );
82//#endif   
83
84    cout << r << r2 << s << s2;
85   
86    string res  = copy_range<string>( r );
87    BOOST_CHECK( equal( res.begin(), res.end(), r.begin() ) );
88   
89    r.empty();
90    s.empty();
91    r.size();
92    s.size();
93
94    srange rr = make_iterator_range( str );
95    BOOST_CHECK( rr.equal( r ) );
96
97    rr  = make_iterator_range( str.begin(), str.begin() + 5 );
98    BOOST_CHECK( rr == "hello" );
99    BOOST_CHECK( rr != "hell" );
100    BOOST_CHECK( rr < "hello dude" );
101    BOOST_CHECK( "hello" == rr );
102    BOOST_CHECK( "hell"  != rr );
103    BOOST_CHECK( ! ("hello dude" < rr ) );
104   
105    irange rrr = rr;
106    BOOST_CHECK( rrr == rr );
107    BOOST_CHECK( !( rrr != rr ) );
108    BOOST_CHECK( !( rrr < rr ) );
109
110    const irange cr = make_iterator_range( str );
111    BOOST_CHECK_EQUAL( cr.front(), 'h' );
112    BOOST_CHECK_EQUAL( cr.back(), 'd' );
113    BOOST_CHECK_EQUAL( cr[1], 'e' );
114
115    rrr = make_iterator_range( str, 1, -1 );
116    BOOST_CHECK( rrr == "ello worl" );
117    rrr = make_iterator_range( rrr, -1, 1 );
118    BOOST_CHECK( rrr == str );
119    rrr.front() = 'H';
120    rrr.back()  = 'D';
121    rrr[1]      = 'E';
122    BOOST_CHECK( rrr == "HEllo worlD" );
123}   
124
125#include <boost/test/unit_test.hpp>
126using boost::unit_test::test_suite;
127
128test_suite* init_unit_test_suite( int argc, char* argv[] )
129{
130    test_suite* test = BOOST_TEST_SUITE( "Range Test Suite" );
131
132    test->add( BOOST_TEST_CASE( &check_sub_range ) );
133
134    return test;
135}
136
137
138
139
140
Note: See TracBrowser for help on using the repository browser.