]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
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 | #include <boost/detail/workaround.hpp> | |
12 | ||
20effc67 | 13 | #if BOOST_WORKAROUND(BOOST_BORLANDC, BOOST_TESTED_AT(0x564)) |
b32b8144 | 14 | # pragma warn -8091 // suppress warning in Boost.Test |
7c673cae FG |
15 | # pragma warn -8057 // unused argument argc/argv in Boost.Test |
16 | #endif | |
17 | ||
18 | ||
19 | #include <boost/assign/ptr_map_inserter.hpp> | |
20 | #include <boost/test/test_tools.hpp> | |
21 | #include <boost/ptr_container/ptr_map.hpp> | |
22 | #include <typeinfo> | |
23 | #include <string> | |
24 | ||
25 | // | |
26 | // abstract base class definition | |
27 | // | |
28 | struct abstract_base | |
29 | { | |
30 | virtual ~abstract_base() {} | |
31 | virtual void foo() = 0; | |
32 | virtual abstract_base* clone() const = 0; | |
33 | }; | |
34 | ||
35 | struct implementation : abstract_base | |
36 | { | |
37 | implementation() | |
38 | { } | |
39 | ||
40 | implementation( const implementation& ) | |
41 | { } | |
42 | ||
43 | implementation( int ) | |
44 | { } | |
45 | ||
46 | implementation( int, int ) | |
47 | { } | |
48 | ||
49 | implementation( int, std::string, int, std::string ) | |
50 | { } | |
51 | ||
52 | virtual void foo() {} | |
53 | virtual abstract_base* clone() const | |
54 | { | |
55 | return new implementation( *this ); | |
56 | } | |
57 | }; | |
58 | ||
59 | ||
60 | void check_ptr_map_inserter() | |
61 | { | |
62 | ||
63 | #ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING | |
64 | ||
65 | boost::ptr_map<std::string, abstract_base> m; | |
66 | boost::assign::ptr_map_insert<implementation>( m ) | |
67 | ( "foo", 1, "two", 3, "four" ) | |
68 | ( "bar", 41, "42", 43, "44" ); | |
69 | BOOST_CHECK_EQUAL( m.size(), 2u ); | |
70 | BOOST_CHECK( typeid(m.at("foo")) == typeid(implementation) ); | |
71 | ||
72 | #endif | |
73 | ||
74 | boost::ptr_map<std::string,implementation> m2; | |
75 | boost::assign::ptr_map_insert( m2 ) | |
76 | ( "foobar", 1, "two", 3, "four" ) | |
77 | ( "key1" )( "key2" )( "key3" )( "key4" ) | |
78 | ( "key5", 42 )( "key6", 42, 42 ); | |
79 | ||
80 | BOOST_CHECK_EQUAL( m2.size(), 7u ); | |
81 | boost::assign::ptr_map_insert( m2 )( "key1" ); | |
82 | BOOST_CHECK_EQUAL( m2.size(), 7u ); // duplicates not inserted | |
83 | ||
84 | } | |
85 | ||
86 | ||
87 | ||
88 | #include <boost/test/unit_test.hpp> | |
89 | using boost::unit_test::test_suite; | |
90 | ||
91 | test_suite* init_unit_test_suite( int argc, char* argv[] ) | |
92 | { | |
93 | test_suite* test = BOOST_TEST_SUITE( "List Test Suite" ); | |
94 | ||
95 | test->add( BOOST_TEST_CASE( &check_ptr_map_inserter ) ); | |
96 | ||
97 | return test; | |
98 | } | |
99 |