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 https://web.archive.org/web/20071014014301/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>
26 #include <boost/bimap/bimap.hpp>
27 #include <boost/bimap/list_of.hpp>
29 using namespace boost::bimaps;
34 void test_bimap_project()
38 tagged< int , left_tag >,
39 list_of< tagged< std::string, right_tag > >
45 bm.insert( bm_type::value_type(1,"1") );
46 bm.insert( bm_type::value_type(2,"2") );
48 bm_type:: iterator iter = bm.begin();
49 bm_type:: left_iterator left_iter = bm.left.find(1);
50 bm_type::right_iterator right_iter = bm.right.begin();
52 const bm_type & cbm = bm;
54 bm_type:: const_iterator citer = cbm.begin();
55 bm_type:: left_const_iterator left_citer = cbm.left.find(1);
56 bm_type::right_const_iterator right_citer = cbm.right.begin();
58 // non const projection
60 BOOST_CHECK( bm.project_up (bm.end()) == bm.end() );
61 BOOST_CHECK( bm.project_left (bm.end()) == bm.left.end() );
62 BOOST_CHECK( bm.project_right(bm.end()) == bm.right.end() );
64 BOOST_CHECK( bm.project_up (iter) == iter );
65 BOOST_CHECK( bm.project_left (iter) == left_iter );
66 BOOST_CHECK( bm.project_right(iter) == right_iter );
68 BOOST_CHECK( bm.project_up (left_iter) == iter );
69 BOOST_CHECK( bm.project_left (left_iter) == left_iter );
70 BOOST_CHECK( bm.project_right(left_iter) == right_iter );
72 BOOST_CHECK( bm.project_up (right_iter) == iter );
73 BOOST_CHECK( bm.project_left (right_iter) == left_iter );
74 BOOST_CHECK( bm.project_right(right_iter) == right_iter );
76 bm.project_up ( left_iter)->right = "u";
77 bm.project_left (right_iter)->second = "l";
78 bm.project_right( iter)->first = "r";
82 BOOST_CHECK( cbm.project_up (cbm.end()) == cbm.end() );
83 BOOST_CHECK( cbm.project_left (cbm.end()) == cbm.left.end() );
84 BOOST_CHECK( cbm.project_right(cbm.end()) == cbm.right.end() );
86 BOOST_CHECK( cbm.project_up (citer) == citer );
87 BOOST_CHECK( cbm.project_left (citer) == left_citer );
88 BOOST_CHECK( cbm.project_right(citer) == right_citer );
90 BOOST_CHECK( cbm.project_up (left_citer) == citer );
91 BOOST_CHECK( cbm.project_left (left_citer) == left_citer );
92 BOOST_CHECK( cbm.project_right(left_citer) == right_citer );
94 BOOST_CHECK( cbm.project_up (right_citer) == citer );
95 BOOST_CHECK( cbm.project_left (right_citer) == left_citer );
96 BOOST_CHECK( cbm.project_right(right_citer) == right_citer );
100 BOOST_CHECK( bm.project_up (left_citer) == iter );
101 BOOST_CHECK( bm.project_left (left_citer) == left_iter );
102 BOOST_CHECK( bm.project_right(left_citer) == right_iter );
104 BOOST_CHECK( cbm.project_up (right_iter) == citer );
105 BOOST_CHECK( cbm.project_left (right_iter) == left_citer );
106 BOOST_CHECK( cbm.project_right(right_iter) == right_citer );
108 bm.project_up ( left_citer)->right = "u";
109 bm.project_left (right_citer)->second = "l";
110 bm.project_right( citer)->first = "r";
114 BOOST_CHECK( bm.project< left_tag>(iter) == left_iter );
115 BOOST_CHECK( bm.project<right_tag>(iter) == right_iter );
117 BOOST_CHECK( bm.project< left_tag>(left_iter) == left_iter );
118 BOOST_CHECK( bm.project<right_tag>(left_iter) == right_iter );
120 BOOST_CHECK( bm.project< left_tag>(right_iter) == left_iter );
121 BOOST_CHECK( bm.project<right_tag>(right_iter) == right_iter );
123 BOOST_CHECK( cbm.project< left_tag>(citer) == left_citer );
124 BOOST_CHECK( cbm.project<right_tag>(citer) == right_citer );
126 BOOST_CHECK( cbm.project< left_tag>(left_citer) == left_citer );
127 BOOST_CHECK( cbm.project<right_tag>(left_citer) == right_citer );
129 BOOST_CHECK( cbm.project< left_tag>(right_citer) == left_citer );
130 BOOST_CHECK( cbm.project<right_tag>(right_citer) == right_citer );
132 bm.project< left_tag>(right_citer)->second = "l";
133 bm.project<right_tag>( left_citer)->first = "r";
138 int test_main( int, char* [] )
140 test_bimap_project();