[12] | 1 | // Boost.Assign 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/assign/ |
---|
| 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/assign/std.hpp> |
---|
| 20 | #include <boost/test/test_tools.hpp> |
---|
| 21 | #include <utility> |
---|
| 22 | #include <string> |
---|
| 23 | |
---|
| 24 | using namespace std; |
---|
| 25 | using namespace boost::assign; |
---|
| 26 | |
---|
| 27 | template< typename K, typename V > |
---|
| 28 | inline pair<K,V> P( K k, V v ) |
---|
| 29 | { |
---|
| 30 | return make_pair( k, v ); |
---|
| 31 | } |
---|
| 32 | |
---|
| 33 | struct three |
---|
| 34 | { |
---|
| 35 | three( int, int, int ) { } |
---|
| 36 | three( const string&, const string&, const string& ) { } |
---|
| 37 | }; |
---|
| 38 | |
---|
| 39 | struct four |
---|
| 40 | { |
---|
| 41 | four( int, int, int, int ) { } |
---|
| 42 | four( const string&, const string&, const string&, const string& ) { } |
---|
| 43 | }; |
---|
| 44 | |
---|
| 45 | struct five |
---|
| 46 | { |
---|
| 47 | five( int, int, int, int, int ) { } |
---|
| 48 | five( const string&, const string&, const string&, |
---|
| 49 | const string&, const string& ) { } |
---|
| 50 | }; |
---|
| 51 | |
---|
| 52 | |
---|
| 53 | |
---|
| 54 | template< class C > |
---|
| 55 | void test_int_sequence() |
---|
| 56 | { |
---|
| 57 | C c; |
---|
| 58 | |
---|
| 59 | BOOST_CHECK_EQUAL( c.size(), 0u ); |
---|
| 60 | c +=1,2,3,4,5,6,7,8,9,10; |
---|
| 61 | BOOST_CHECK_EQUAL( c.size(), 10u ); |
---|
| 62 | } |
---|
| 63 | |
---|
| 64 | |
---|
| 65 | |
---|
| 66 | template< class C > |
---|
| 67 | void test_string_sequence() |
---|
| 68 | { |
---|
| 69 | C c; |
---|
| 70 | |
---|
| 71 | BOOST_CHECK_EQUAL( c.size(), 0u ); |
---|
| 72 | c += "1","2","3","4","5","6","7","8","9","10"; |
---|
| 73 | BOOST_CHECK_EQUAL( c.size(), 10u ); |
---|
| 74 | } |
---|
| 75 | |
---|
| 76 | |
---|
| 77 | |
---|
| 78 | typedef pair<string,int> tuple; |
---|
| 79 | |
---|
| 80 | template< class C > |
---|
| 81 | void test_tuple_sequence() |
---|
| 82 | { |
---|
| 83 | C c; |
---|
| 84 | |
---|
| 85 | BOOST_CHECK_EQUAL( c.size(), 0u ); |
---|
| 86 | c += P("1",1), P("2",2), P("3",3), P("4",4), P("5",5), P("6",6), |
---|
| 87 | P("7",7), P("8",8), P("9",9), P("10",10); |
---|
| 88 | BOOST_CHECK_EQUAL( c.size(), 10u ); |
---|
| 89 | } |
---|
| 90 | |
---|
| 91 | |
---|
| 92 | |
---|
| 93 | template< class M > |
---|
| 94 | void test_map() |
---|
| 95 | { |
---|
| 96 | M m; |
---|
| 97 | m += P( "january", 31 ), P( "february", 28 ), |
---|
| 98 | P( "march", 31 ), P( "april", 30 ), |
---|
| 99 | P( "may", 31 ), P( "june", 30 ), |
---|
| 100 | P( "july", 31 ), P( "august", 31 ), |
---|
| 101 | P( "september", 30 ), P( "october", 31 ), |
---|
| 102 | P( "november", 30 ), P( "december", 31 ); |
---|
| 103 | BOOST_CHECK_EQUAL( m.size(), 12u ); |
---|
| 104 | m.clear(); |
---|
| 105 | insert( m ) |
---|
| 106 | ( "january", 31 )( "february", 28 ) |
---|
| 107 | ( "march", 31 )( "april", 30 ) |
---|
| 108 | ( "may", 31 )( "june", 30 ) |
---|
| 109 | ( "july", 31 )( "august", 31 ) |
---|
| 110 | ( "september", 30 )( "october", 31 ) |
---|
| 111 | ( "november", 30 )( "december", 31 ); |
---|
| 112 | BOOST_CHECK_EQUAL( m.size(), 12u ); |
---|
| 113 | } |
---|
| 114 | |
---|
| 115 | |
---|
| 116 | |
---|
| 117 | void test_tuple() |
---|
| 118 | { |
---|
| 119 | vector<three> v_three; |
---|
| 120 | vector<four> v_four; |
---|
| 121 | vector<five> v_five; |
---|
| 122 | |
---|
| 123 | push_back( v_three ) (1,2,3) ("1","2","3"); |
---|
| 124 | push_back( v_four ) (1,2,3,4) ("1","2","3","4"); |
---|
| 125 | push_back( v_five ) (1,2,3,4,5) ("1","2","3","4","5"); |
---|
| 126 | BOOST_CHECK_EQUAL( v_three.size(), 2u ); |
---|
| 127 | BOOST_CHECK_EQUAL( v_four.size(), 2u ); |
---|
| 128 | BOOST_CHECK_EQUAL( v_five.size(), 2u ); |
---|
| 129 | |
---|
| 130 | } |
---|
| 131 | |
---|
| 132 | |
---|
| 133 | |
---|
| 134 | void check_std() |
---|
| 135 | { |
---|
| 136 | test_int_sequence< deque<int> >(); |
---|
| 137 | test_int_sequence< list<int> >(); |
---|
| 138 | test_int_sequence< vector<int> >(); |
---|
| 139 | test_int_sequence< set<int> >(); |
---|
| 140 | test_int_sequence< multiset<int> >(); |
---|
| 141 | test_int_sequence< stack<int> >(); |
---|
| 142 | test_int_sequence< queue<int> >(); |
---|
| 143 | test_int_sequence< priority_queue<int> >(); |
---|
| 144 | |
---|
| 145 | test_string_sequence< deque<string> >(); |
---|
| 146 | test_string_sequence< list<string> >(); |
---|
| 147 | test_string_sequence< vector<string> >(); |
---|
| 148 | test_string_sequence< set<string> >(); |
---|
| 149 | test_string_sequence< multiset<string> >(); |
---|
| 150 | test_string_sequence< stack<string> >(); |
---|
| 151 | test_string_sequence< queue<string> >(); |
---|
| 152 | test_string_sequence< priority_queue<string> >(); |
---|
| 153 | |
---|
| 154 | test_tuple_sequence< deque<tuple> >(); |
---|
| 155 | test_tuple_sequence< list<tuple> >(); |
---|
| 156 | test_tuple_sequence< vector<tuple> >(); |
---|
| 157 | test_tuple_sequence< set<tuple> >(); |
---|
| 158 | test_tuple_sequence< multiset<tuple> >(); |
---|
| 159 | test_tuple_sequence< stack<tuple> >(); |
---|
| 160 | test_tuple_sequence< queue<tuple> >(); |
---|
| 161 | test_tuple_sequence< priority_queue<tuple> >(); |
---|
| 162 | test_tuple(); |
---|
| 163 | |
---|
| 164 | deque<int> di; |
---|
| 165 | push_back( di )( 1 ); |
---|
| 166 | push_front( di )( 2 ); |
---|
| 167 | BOOST_CHECK_EQUAL( di[0], 2 ); |
---|
| 168 | BOOST_CHECK_EQUAL( di[1], 1 ); |
---|
| 169 | |
---|
| 170 | list<int> li; |
---|
| 171 | push_back( li )( 2 ); |
---|
| 172 | push_front( li )( 1 ); |
---|
| 173 | BOOST_CHECK_EQUAL( li.front(), 1 ); |
---|
| 174 | BOOST_CHECK_EQUAL( li.back(), 2 ); |
---|
| 175 | |
---|
| 176 | vector<int> vi; |
---|
| 177 | push_back( vi ) = 2,3; |
---|
| 178 | BOOST_CHECK_EQUAL( vi[0], 2 ); |
---|
| 179 | BOOST_CHECK_EQUAL( vi[1], 3 ); |
---|
| 180 | |
---|
| 181 | set<int> si; |
---|
| 182 | insert( si )( 4 ); |
---|
| 183 | BOOST_CHECK_EQUAL( *si.find( 4 ), 4 ); |
---|
| 184 | |
---|
| 185 | multiset<int> msi; |
---|
| 186 | insert( msi )( 5 ); |
---|
| 187 | BOOST_CHECK_EQUAL( *msi.find( 5 ), 5 ); |
---|
| 188 | |
---|
| 189 | stack<int> sti; |
---|
| 190 | push( sti )( 6 ); |
---|
| 191 | BOOST_CHECK_EQUAL( sti.top(), 6 ); |
---|
| 192 | |
---|
| 193 | queue<int> qi; |
---|
| 194 | push( qi )( 7 ); |
---|
| 195 | BOOST_CHECK_EQUAL( qi.back(), 7 ); |
---|
| 196 | |
---|
| 197 | priority_queue<int> pqi; |
---|
| 198 | push( pqi )( 8 ); |
---|
| 199 | BOOST_CHECK_EQUAL( pqi.top(), 8 ); |
---|
| 200 | |
---|
| 201 | test_map< map<string,int> >(); |
---|
| 202 | test_map< multimap<string,int> >(); |
---|
| 203 | |
---|
| 204 | } |
---|
| 205 | |
---|
| 206 | |
---|
| 207 | |
---|
| 208 | #include <boost/test/unit_test.hpp> |
---|
| 209 | using boost::unit_test::test_suite; |
---|
| 210 | |
---|
| 211 | test_suite* init_unit_test_suite( int argc, char* argv[] ) |
---|
| 212 | { |
---|
| 213 | test_suite* test = BOOST_TEST_SUITE( "List Test Suite" ); |
---|
| 214 | |
---|
| 215 | test->add( BOOST_TEST_CASE( &check_std ) ); |
---|
| 216 | |
---|
| 217 | return test; |
---|
| 218 | } |
---|
| 219 | |
---|