3 // Copyright (c) 2006-2007 Matias Capeletto
5 // Distributed under the Boost Software License, Version 1.0.
6 // (See accompanying file LICENSE_1_0.txt or copy at
7 // http://www.boost.org/LICENSE_1_0.txt)
9 // VC++ 8.0 warns on usage of certain Standard Library and API functions that
10 // can be cause buffer overruns or other possible security issues if misused.
11 // See http://msdn.microsoft.com/msdnmag/issues/05/05/SafeCandC/default.aspx
12 // But the wording of the warning is misleading and unsettling, there are no
13 // portable alternative functions, and VC++ 8.0's own libraries use the
14 // functions in question. So turn off the warnings.
15 #define _CRT_SECURE_NO_DEPRECATE
16 #define _SCL_SECURE_NO_DEPRECATE
18 #include <boost/config.hpp>
21 #include <boost/test/minimal.hpp>
24 #include <boost/bimap/support/lambda.hpp>
25 #include <boost/bimap/bimap.hpp>
26 #include <boost/bimap/unordered_set_of.hpp>
27 #include <boost/bimap/list_of.hpp>
28 #include <boost/bimap/vector_of.hpp>
29 #include <boost/bimap/unconstrained_set_of.hpp>
32 void test_bimap_operator_bracket()
34 using namespace boost::bimaps
;
38 typedef bimap
< int, std::string
> bm
;
41 b
.insert( bm::value_type(0,"0") );
42 b
.insert( bm::value_type(1,"1") );
43 b
.insert( bm::value_type(2,"2") );
44 b
.insert( bm::value_type(3,"3") );
46 BOOST_CHECK( b
.left
.at(1) == "1" );
50 bool value_not_found_test_passed
= false;
55 comp
= b
.left
.at(2) < "banana";
57 catch( std::out_of_range
& )
59 value_not_found_test_passed
= true;
62 BOOST_CHECK( value_not_found_test_passed
);
66 // Mutable data test (1)
68 typedef bimap
<int, list_of
<std::string
> > bm
;
73 bool value_not_found_test_passed
= false;
78 comp
= b
.left
.at(1) < "banana";
80 catch( std::out_of_range
& )
82 value_not_found_test_passed
= true;
85 BOOST_CHECK( value_not_found_test_passed
);
89 // Out of range test (const version)
91 bool value_not_found_test_passed
= false;
97 comp
= cb
.left
.at(1) < "banana";
99 catch( std::out_of_range
& )
101 value_not_found_test_passed
= true;
104 BOOST_CHECK( value_not_found_test_passed
);
107 BOOST_CHECK( b
.left
[1] == "" );
108 BOOST_CHECK( b
.left
.at(1) == "" );
110 BOOST_CHECK( b
.left
.at(2) == "two" );
111 b
.left
[2] = "<<two>>";
112 BOOST_CHECK( b
.left
.at(2) == "<<two>>" );
113 b
.left
.at(2) = "two";
114 BOOST_CHECK( b
.left
.at(2) == "two" );
118 // Mutable data test (2)
120 typedef bimap
< vector_of
<int>, unordered_set_of
<std::string
> > bm
;
125 bool value_not_found_test_passed
= false;
130 comp
= b
.right
.at("banana") < 1;
132 catch( std::out_of_range
& )
134 value_not_found_test_passed
= true;
136 BOOST_CHECK( value_not_found_test_passed
);
139 // Out of range test (const version)
141 bool value_not_found_test_passed
= false;
147 comp
= cb
.right
.at("banana") < 1;
149 catch( std::out_of_range
& )
151 value_not_found_test_passed
= true;
154 BOOST_CHECK( value_not_found_test_passed
);
158 BOOST_CHECK( b
.size() == 1 );
160 BOOST_CHECK( b
.right
.at("two") == 2 );
162 BOOST_CHECK( b
.right
.at("two") == -2 );
163 b
.right
.at("two") = 2;
164 BOOST_CHECK( b
.right
.at("two") == 2 );
167 // Mutable data test (3)
169 typedef bimap
< unconstrained_set_of
<int>,
170 unordered_set_of
<std::string
>,
176 BOOST_CHECK( b
.size() == 1 );
178 BOOST_CHECK( b
.right
.at("two") == 2 );
180 BOOST_CHECK( b
.right
.at("two") == -2 );
181 b
.right
.at("two") = 2;
182 BOOST_CHECK( b
.right
.at("two") == 2 );
187 int test_main( int, char* [] )
189 test_bimap_operator_bracket();