1 | // |
2 | // Boost.Pointer Container |
3 | // |
4 | // Copyright Thorsten Ottosen 2003-2005. Use, modification and |
5 | // distribution is subject to the Boost Software License, Version |
6 | // 1.0. (See accompanying file LICENSE_1_0.txt or copy at |
7 | // http://www.boost.org/LICENSE_1_0.txt) |
8 | // |
9 | // For more information, see http://www.boost.org/libs/ptr_container/ |
10 | // |
11 | |
12 | #include "test_data.hpp" |
13 | #include <boost/ptr_container/ptr_map.hpp> |
14 | #include <boost/ptr_container/detail/ptr_container_disable_deprecated.hpp> |
15 | #include <boost/test/unit_test.hpp> |
16 | #include <string> |
17 | |
18 | using namespace std; |
19 | |
20 | #if defined(BOOST_PTR_CONTAINER_DISABLE_DEPRECATED) |
21 | #pragma GCC diagnostic push |
22 | #pragma GCC diagnostic ignored "-Wdeprecated-declarations" |
23 | #endif |
24 | |
25 | void test_ptr_map_adapter() |
26 | { |
27 | //typedef_test< ptr_map<int, Base>, Derived >(); |
28 | //typedef_test< ptr_map<int, Value>, Value >(); |
29 | |
30 | //associative_container_test< ptr_map<int, Base>, Base, Derived >(); |
31 | //associative_container_test< ptr_map<int, Value>, Value, Value >(); |
32 | |
33 | //typedef_test< ptr_multimap<int, Base>, Derived >(); |
34 | //typedef_test< ptr_multimap<int, Value>, Value >(); |
35 | |
36 | //associative_container_test< ptr_multimap<int, Base>, Base, Derived >(); |
37 | //associative_container_test< ptr_multimap<int, Value>, Value, Value >(); |
38 | |
39 | string joe = "joe" ; |
40 | string brian = "brian" ; |
41 | |
42 | ptr_map<string,int> m; |
43 | m.insert( key&: joe, x: new int( 4 ) ); |
44 | #ifndef BOOST_NO_AUTO_PTR |
45 | m.insert( key: brian, x: std::auto_ptr<int>( new int( 6 ) ) ); |
46 | #endif |
47 | #ifndef BOOST_NO_CXX11_SMART_PTR |
48 | m.insert( key: brian, x: std::unique_ptr<int>( new int( 6 ) ) ); |
49 | #endif |
50 | m[ joe ] += 56; |
51 | m[ brian ] += 10; |
52 | |
53 | try |
54 | { |
55 | m[ "hans" ] = 4; |
56 | } |
57 | catch( const bad_ptr_container_operation& ) |
58 | { } |
59 | |
60 | ptr_map<string,int> m2; |
61 | m2.insert( before: m2.begin(), p: *m.begin() ); |
62 | BOOST_CHECK( m != m2 ); |
63 | BOOST_CHECK( m2 < m ); |
64 | m2.insert( before: m2.begin(), key&: joe, x: new int(5) ); |
65 | BOOST_CHECK( m != m2 ); |
66 | BOOST_CHECK( m2 > m ); |
67 | |
68 | ptr_multimap<string,int> m3; |
69 | m3.insert( before: m3.begin(), p: *m.begin() ); |
70 | BOOST_CHECK( m3.size() == 1u ); |
71 | m3.insert( before: m3.begin(), key&: brian, x: new int(11 ) ); |
72 | BOOST_CHECK( m3.size() == 2u ); |
73 | } |
74 | |
75 | #if defined(BOOST_PTR_CONTAINER_DISABLE_DEPRECATED) |
76 | #pragma GCC diagnostic pop |
77 | #endif |
78 | |
79 | using boost::unit_test::test_suite; |
80 | |
81 | test_suite* init_unit_test_suite( int argc, char* argv[] ) |
82 | { |
83 | test_suite* test = BOOST_TEST_SUITE( "Pointer Container Test Suite" ); |
84 | |
85 | test->add( BOOST_TEST_CASE( &test_ptr_map_adapter ) ); |
86 | |
87 | return test; |
88 | } |
89 | |