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