]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/assign/test/email_example.cpp
3e8b98ba08b46ea22b9031525cfea2ad5180e11a
1 // Boost.Assign library
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)
8 // For more information, see http://www.boost.org/libs/assign/
12 #include <boost/detail/workaround.hpp>
14 #if BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564))
15 # pragma warn -8091 // suppress warning in Boost.Test
16 # pragma warn -8057 // unused argument argc/argv in Boost.Test
19 #include <boost/assign/list_inserter.hpp>
20 #include <boost/test/test_tools.hpp>
21 #include <boost/function.hpp>
22 #include <boost/bind.hpp>
26 namespace ba
= boost::assign
;
37 typedef std::pair
<std::string
,address_option
> bcc_type
;
38 typedef std::vector
< bcc_type
> bcc_map
;
39 typedef std::map
<std::string
,address_option
> address_map
;
44 mutable address_map cc_list
;
45 mutable address_map to_list
;
52 add_to_map( address_map
& m
) : m(m
)
55 void operator()( const std::string
& name
, address_option ao
)
60 void operator()( const std::string
& name
)
62 m
[ name
] = check_addr_book
;
70 add_to_vector( bcc_map
& m
) : m(m
)
73 void operator()( const bcc_type
& r
)
81 ba::list_inserter
< add_to_map
>
82 add_cc( std::string name
, address_option ao
)
84 return ba::make_list_inserter( add_to_map( cc_list
) )( name
, ao
);
87 ba::list_inserter
< add_to_map
>
88 add_to( const std::string
& name
)
90 return ba::make_list_inserter( add_to_map( to_list
) )( name
);
93 ba::list_inserter
< add_to_vector
, bcc_type
>
94 add_bcc( const bcc_type
& bcc
)
96 return ba::make_list_inserter( add_to_vector( bcc_list
) )( bcc
);
100 cc_at( const std::string
& name
) const
102 return cc_list
[ name
];
106 to_at( const std::string
& name
) const
108 return to_list
[ name
];
112 bcc_at( unsigned index
) const
114 return bcc_list
.at( index
).second
;
120 void check_list_inserter()
122 using namespace boost::assign
;
125 e
.add_cc( "franz", email::dont_check_addr_book
)
126 ( "hanz", email::check_addr_book
)
127 ( "betty", email::dont_check_addr_book
);
128 BOOST_CHECK_EQUAL( e
.cc_at( "franz" ), email::dont_check_addr_book
);
129 BOOST_CHECK_EQUAL( e
.cc_at( "hanz" ), email::check_addr_book
);
130 BOOST_CHECK_EQUAL( e
.cc_at( "betty" ), email::dont_check_addr_book
);
132 e
.add_to( "betsy" )( "peter" );
133 BOOST_CHECK_EQUAL( e
.cc_at( "betsy" ), email::check_addr_book
);
134 BOOST_CHECK_EQUAL( e
.cc_at( "peter" ), email::check_addr_book
);
136 e
.add_bcc( email::bcc_type( "Mr. Foo", email::check_addr_book
) )
137 ( "Mr. Bar", email::dont_check_addr_book
);
138 BOOST_CHECK_EQUAL( e
.bcc_at( 0 ), email::check_addr_book
);
139 BOOST_CHECK_EQUAL( e
.bcc_at( 1 ), email::dont_check_addr_book
);
144 #include <boost/test/unit_test.hpp>
145 using boost::unit_test::test_suite
;
147 test_suite
* init_unit_test_suite( int argc
, char* argv
[] )
149 test_suite
* test
= BOOST_TEST_SUITE( "List Test Suite" );
151 test
->add( BOOST_TEST_CASE( &check_list_inserter
) );