1 // Boost.Assign library
2 //
3 // Copyright Thorsten Ottosen 2003-2006. 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
13 #if BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564))
14 # pragma warn -8091 // suppress warning in Boost.Test
15 # pragma warn -8057 // unused argument argc/argv in Boost.Test
16 #endif
17
18
19 #include <boost/assign/ptr_list_inserter.hpp>
20 #include <boost/test/test_tools.hpp>
21 #include <boost/ptr_container/ptr_deque.hpp>
22 #include <boost/ptr_container/ptr_set.hpp>
23 #include <typeinfo>
24
25 struct Foo
26 {
27 int i;
28
FooFoo29 Foo() : i(0)
30 { }
FooFoo31 Foo( int i ) : i(i)
32 { }
FooFoo33 Foo( int i, int ) : i(i)
34 { }
FooFoo35 Foo( const char*, int i, int ) : i(i)
36 { }
37
~FooFoo38 virtual ~Foo()
39 { }
40 };
41
42 struct FooBar : Foo
43 {
FooBarFooBar44 FooBar( int i ) : Foo(i)
45 { }
46
FooBarFooBar47 FooBar( int i, const char* )
48 { }
49 };
50
operator <(const Foo & l,const Foo & r)51 inline bool operator<( const Foo& l, const Foo& r )
52 {
53 return l.i < r.i;
54 }
55
check_ptr_list_inserter()56 void check_ptr_list_inserter()
57 {
58 using namespace std;
59 using namespace boost;
60 using namespace boost::assign;
61
62 ptr_deque<Foo> deq;
63 ptr_push_back( deq )()();
64 BOOST_CHECK( deq.size() == 2u );
65
66 ptr_push_front( deq )( 3 )( 42, 42 )( "foo", 42, 42 );
67 BOOST_CHECK( deq.size() == 5u );
68
69 ptr_set<Foo> a_set;
70 ptr_insert( a_set )()( 1 )( 2, 2 )( "foo", 3, 3 );
71 BOOST_CHECK( a_set.size() == 4u );
72 ptr_insert( a_set )()()()();
73 BOOST_CHECK( a_set.size() == 4u ); // duplicates not inserted
74
75 #ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING
76
77 ptr_push_back<FooBar>( deq )( 42, "42" );
78 BOOST_CHECK_EQUAL( deq.size(), 6u );
79 BOOST_CHECK( typeid(deq[5u]) == typeid(FooBar) );
80
81 ptr_push_front<FooBar>( deq )( 42, "42" );
82 BOOST_CHECK_EQUAL( deq.size(), 7u );
83 BOOST_CHECK( typeid(deq[0]) == typeid(FooBar) );
84
85 ptr_insert<FooBar>( a_set )( 4 );
86 BOOST_CHECK( a_set.size() == 5u );
87 BOOST_CHECK( typeid(*--a_set.end()) == typeid(FooBar) );
88
89 #endif
90
91 }
92
93
94
95 #include <boost/test/unit_test.hpp>
96 using boost::unit_test::test_suite;
97
init_unit_test_suite(int argc,char * argv[])98 test_suite* init_unit_test_suite( int argc, char* argv[] )
99 {
100 test_suite* test = BOOST_TEST_SUITE( "List Test Suite" );
101
102 test->add( BOOST_TEST_CASE( &check_ptr_list_inserter ) );
103
104 return test;
105 }
106
107