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(BOOST_BORLANDC, BOOST_TESTED_AT(0x564))
15# pragma warn -8091 // suppress 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
24using std::deque;
25using std::list;
26using std::vector;
27using std::set;
28using std::multiset;
29using std::map;
30using std::multimap;
31using std::stack;
32using std::queue;
33using std::priority_queue;
34using std::string;
35using std::pair;
36using std::make_pair;
37using namespace boost::assign;
38
39template< typename K, typename V >
40inline pair<K,V> P( K k, V v )
41{
42 return make_pair( k, v );
43}
44
45struct three
46{
47 three( int, int, int ) { }
48 three( const string&, const string&, const string& ) { }
49};
50
51struct four
52{
53 four( int, int, int, int ) { }
54 four( const string&, const string&, const string&, const string& ) { }
55};
56
57struct 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
66template< class C >
67void 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
78template< class C >
79void 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
90typedef pair<string,int> two_tuple;
91
92template< class C >
93void test_tuple_sequence()
94{
95 C c;
96
97 BOOST_CHECK_EQUAL( c.size(), 0u );
98 c += P(k: "1",v: 1), P(k: "2",v: 2), P(k: "3",v: 3), P(k: "4",v: 4), P(k: "5",v: 5), P(k: "6",v: 6),
99 P(k: "7",v: 7), P(k: "8",v: 8), P(k: "9",v: 9), P(k: "10",v: 10);
100 BOOST_CHECK_EQUAL( c.size(), 10u );
101}
102
103
104
105template< class M >
106void test_map()
107{
108 M m;
109 m += P( k: "january", v: 31 ), P( k: "february", v: 28 ),
110 P( k: "march", v: 31 ), P( k: "april", v: 30 ),
111 P( k: "may", v: 31 ), P( k: "june", v: 30 ),
112 P( k: "july", v: 31 ), P( k: "august", v: 31 ),
113 P( k: "september", v: 30 ), P( k: "october", v: 31 ),
114 P( k: "november", v: 30 ), P( k: "december", v: 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
129void test_tuple()
130{
131 vector<three> v_three;
132 vector<four> v_four;
133 vector<five> v_five;
134
135 push_back( c&: v_three ) (1,2,3) ("1","2","3");
136 push_back( c&: v_four ) (1,2,3,4) ("1","2","3","4");
137 push_back( c&: 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
146void 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( c&: di )( 1 );
178 push_front( c&: di )( 2 );
179 BOOST_CHECK_EQUAL( di[0], 2 );
180 BOOST_CHECK_EQUAL( di[1], 1 );
181
182 list<int> li;
183 push_back( c&: li )( 2 );
184 push_front( c&: li )( 1 );
185 BOOST_CHECK_EQUAL( li.front(), 1 );
186 BOOST_CHECK_EQUAL( li.back(), 2 );
187
188 vector<int> vi;
189 push_back( c&: vi ) = 2,3;
190 BOOST_CHECK_EQUAL( vi[0], 2 );
191 BOOST_CHECK_EQUAL( vi[1], 3 );
192
193 set<int> si;
194 insert( c&: si )( 4 );
195 BOOST_CHECK_EQUAL( *si.find( 4 ), 4 );
196
197 multiset<int> msi;
198 insert( c&: msi )( 5 );
199 BOOST_CHECK_EQUAL( *msi.find( 5 ), 5 );
200
201 stack<int> sti;
202 push( c&: sti )( 6 );
203 BOOST_CHECK_EQUAL( sti.top(), 6 );
204
205 queue<int> qi;
206 push( c&: qi )( 7 );
207 BOOST_CHECK_EQUAL( qi.back(), 7 );
208
209 priority_queue<int> pqi;
210 push( c&: 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>
221using boost::unit_test::test_suite;
222
223test_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
232

source code of boost/libs/assign/test/std.cpp