]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/bimap/test/test_bimap_operator_bracket.cpp
update sources to v12.2.3
[ceph.git] / ceph / src / boost / libs / bimap / test / test_bimap_operator_bracket.cpp
1 // Boost.Bimap
2 //
3 // Copyright (c) 2006-2007 Matias Capeletto
4 //
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)
8
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
17
18 #include <boost/config.hpp>
19
20 // Boost.Test
21 #include <boost/test/minimal.hpp>
22
23 // Boost.Bimap
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>
30
31
32 void test_bimap_operator_bracket()
33 {
34 using namespace boost::bimaps;
35
36 // Simple test
37 {
38 typedef bimap< int, std::string > bm;
39
40 bm b;
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") );
45
46 BOOST_CHECK( b.left.at(1) == "1" );
47
48 // Out of range test
49 {
50 bool value_not_found_test_passed = false;
51 b.clear();
52 try
53 {
54 bool comp;
55 comp = b.left.at(2) < "banana";
56 }
57 catch( std::out_of_range & )
58 {
59 value_not_found_test_passed = true;
60 }
61
62 BOOST_CHECK( value_not_found_test_passed );
63 }
64 }
65
66 // Mutable data test (1)
67 {
68 typedef bimap<int, list_of<std::string> > bm;
69 bm b;
70
71 // Out of range test
72 {
73 bool value_not_found_test_passed = false;
74 b.clear();
75 try
76 {
77 bool comp;
78 comp = b.left.at(1) < "banana";
79 }
80 catch( std::out_of_range & )
81 {
82 value_not_found_test_passed = true;
83 }
84
85 BOOST_CHECK( value_not_found_test_passed );
86
87 }
88
89 // Out of range test (const version)
90 {
91 bool value_not_found_test_passed = false;
92 b.clear();
93 try
94 {
95 const bm & cb(b);
96 bool comp;
97 comp = cb.left.at(1) < "banana";
98 }
99 catch( std::out_of_range & )
100 {
101 value_not_found_test_passed = true;
102 }
103
104 BOOST_CHECK( value_not_found_test_passed );
105 }
106
107 BOOST_CHECK( b.left[1] == "" );
108 BOOST_CHECK( b.left.at(1) == "" );
109 b.left[2] = "two";
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" );
115
116 }
117
118 // Mutable data test (2)
119 {
120 typedef bimap< vector_of<int>, unordered_set_of<std::string> > bm;
121 bm b;
122
123 // Out of range test
124 {
125 bool value_not_found_test_passed = false;
126 b.clear();
127 try
128 {
129 bool comp;
130 comp = b.right.at("banana") < 1;
131 }
132 catch( std::out_of_range & )
133 {
134 value_not_found_test_passed = true;
135 }
136 BOOST_CHECK( value_not_found_test_passed );
137 }
138
139 // Out of range test (const version)
140 {
141 bool value_not_found_test_passed = false;
142 b.clear();
143 try
144 {
145 const bm & cb(b);
146 bool comp;
147 comp = cb.right.at("banana") < 1;
148 }
149 catch( std::out_of_range & )
150 {
151 value_not_found_test_passed = true;
152 }
153
154 BOOST_CHECK( value_not_found_test_passed );
155 }
156
157 b.right["one"];
158 BOOST_CHECK( b.size() == 1 );
159 b.right["two"] = 2;
160 BOOST_CHECK( b.right.at("two") == 2 );
161 b.right["two"] = -2;
162 BOOST_CHECK( b.right.at("two") == -2 );
163 b.right.at("two") = 2;
164 BOOST_CHECK( b.right.at("two") == 2 );
165 }
166
167 // Mutable data test (3)
168 {
169 typedef bimap< unconstrained_set_of<int>,
170 unordered_set_of<std::string>,
171 right_based > bm;
172
173 bm b;
174
175 b.right["one"];
176 BOOST_CHECK( b.size() == 1 );
177 b.right["two"] = 2;
178 BOOST_CHECK( b.right.at("two") == 2 );
179 b.right["two"] = -2;
180 BOOST_CHECK( b.right.at("two") == -2 );
181 b.right.at("two") = 2;
182 BOOST_CHECK( b.right.at("two") == 2 );
183 }
184
185 }
186
187 int test_main( int, char* [] )
188 {
189 test_bimap_operator_bracket();
190
191 return 0;
192 }
193