Update ooo320-m1
[ooovba.git] / cppuhelper / test / testcontainer.cxx
blobacc33c7a50e8bcbb664e070a69ecc59c02441fc0
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: testcontainer.cxx,v $
10 * $Revision: 1.5 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_cppuhelper.hxx"
33 #include <osl/mutex.hxx>
35 #include <cppuhelper/interfacecontainer.hxx>
36 #include <cppuhelper/implbase1.hxx>
38 #include <com/sun/star/beans/XVetoableChangeListener.hpp>
40 using namespace ::cppu;
41 using namespace ::osl;
42 using namespace ::com::sun::star::lang;
43 using namespace ::com::sun::star::beans;
44 using namespace ::com::sun::star::uno;
47 class TestListener : public WeakImplHelper1< XVetoableChangeListener >
49 // Methods
50 virtual void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& /*Source*/ ) throw(::com::sun::star::uno::RuntimeException)
55 virtual void SAL_CALL vetoableChange( const ::com::sun::star::beans::PropertyChangeEvent& /*aEvent*/ )
56 throw(::com::sun::star::beans::PropertyVetoException, ::com::sun::star::uno::RuntimeException)
63 void test_interfacecontainer()
65 Mutex mutex;
68 OInterfaceContainerHelper helper( mutex );
70 Reference< XVetoableChangeListener > r1 = new TestListener();
71 Reference< XVetoableChangeListener > r2 = new TestListener();
72 Reference< XVetoableChangeListener > r3 = new TestListener();
74 helper.addInterface( r1 );
75 helper.addInterface( r2 );
76 helper.addInterface( r3 );
78 helper.disposeAndClear( EventObject() );
82 OInterfaceContainerHelper helper( mutex );
84 Reference< XVetoableChangeListener > r1 = new TestListener();
85 Reference< XVetoableChangeListener > r2 = new TestListener();
86 Reference< XVetoableChangeListener > r3 = new TestListener();
88 helper.addInterface( r1 );
89 helper.addInterface( r2 );
90 helper.addInterface( r3 );
92 OInterfaceIteratorHelper iterator( helper );
94 while( iterator.hasMoreElements() )
95 ((XVetoableChangeListener*)iterator.next())->vetoableChange( PropertyChangeEvent() );
97 helper.disposeAndClear( EventObject() );
101 OInterfaceContainerHelper helper( mutex );
103 Reference< XVetoableChangeListener > r1 = new TestListener();
104 Reference< XVetoableChangeListener > r2 = new TestListener();
105 Reference< XVetoableChangeListener > r3 = new TestListener();
107 helper.addInterface( r1 );
108 helper.addInterface( r2 );
109 helper.addInterface( r3 );
111 OInterfaceIteratorHelper iterator( helper );
113 ((XVetoableChangeListener*)iterator.next())->vetoableChange( PropertyChangeEvent() );
114 iterator.remove();
115 ((XVetoableChangeListener*)iterator.next())->vetoableChange( PropertyChangeEvent() );
116 iterator.remove();
117 ((XVetoableChangeListener*)iterator.next())->vetoableChange( PropertyChangeEvent() );
118 iterator.remove();
120 OSL_ASSERT( helper.getLength() == 0 );
121 helper.disposeAndClear( EventObject() );
125 OInterfaceContainerHelper helper( mutex );
127 Reference< XVetoableChangeListener > r1 = new TestListener();
128 Reference< XVetoableChangeListener > r2 = new TestListener();
129 Reference< XVetoableChangeListener > r3 = new TestListener();
131 helper.addInterface( r1 );
132 helper.addInterface( r2 );
133 helper.addInterface( r3 );
136 OInterfaceIteratorHelper iterator( helper );
137 while( iterator.hasMoreElements() )
139 Reference< XVetoableChangeListener > r = ((XVetoableChangeListener*)iterator.next());
140 if( r == r1 )
141 iterator.remove();
144 OSL_ASSERT( helper.getLength() == 2 );
146 OInterfaceIteratorHelper iterator( helper );
147 while( iterator.hasMoreElements() )
149 Reference< XVetoableChangeListener > r = ((XVetoableChangeListener*)iterator.next());
150 OSL_ASSERT( r != r1 && ( r == r2 || r == r3 ) );
154 helper.disposeAndClear( EventObject() );