1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 // MARKER(update_precomp.py): autogen include statement, do not remove 29 #include "precompiled_cppuhelper.hxx" 30 #include <osl/mutex.hxx> 31 32 #include <cppuhelper/interfacecontainer.hxx> 33 #include <cppuhelper/implbase1.hxx> 34 35 #include <com/sun/star/beans/XVetoableChangeListener.hpp> 36 37 using namespace ::cppu; 38 using namespace ::osl; 39 using namespace ::com::sun::star::lang; 40 using namespace ::com::sun::star::beans; 41 using namespace ::com::sun::star::uno; 42 43 44 class TestListener : public WeakImplHelper1< XVetoableChangeListener > 45 { 46 // Methods 47 virtual void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& /*Source*/ ) throw(::com::sun::star::uno::RuntimeException) 48 { 49 50 } 51 52 virtual void SAL_CALL vetoableChange( const ::com::sun::star::beans::PropertyChangeEvent& /*aEvent*/ ) 53 throw(::com::sun::star::beans::PropertyVetoException, ::com::sun::star::uno::RuntimeException) 54 { 55 56 } 57 58 }; 59 60 void test_interfacecontainer() 61 { 62 Mutex mutex; 63 64 { 65 OInterfaceContainerHelper helper( mutex ); 66 67 Reference< XVetoableChangeListener > r1 = new TestListener(); 68 Reference< XVetoableChangeListener > r2 = new TestListener(); 69 Reference< XVetoableChangeListener > r3 = new TestListener(); 70 71 helper.addInterface( r1 ); 72 helper.addInterface( r2 ); 73 helper.addInterface( r3 ); 74 75 helper.disposeAndClear( EventObject() ); 76 } 77 78 { 79 OInterfaceContainerHelper helper( mutex ); 80 81 Reference< XVetoableChangeListener > r1 = new TestListener(); 82 Reference< XVetoableChangeListener > r2 = new TestListener(); 83 Reference< XVetoableChangeListener > r3 = new TestListener(); 84 85 helper.addInterface( r1 ); 86 helper.addInterface( r2 ); 87 helper.addInterface( r3 ); 88 89 OInterfaceIteratorHelper iterator( helper ); 90 91 while( iterator.hasMoreElements() ) 92 ((XVetoableChangeListener*)iterator.next())->vetoableChange( PropertyChangeEvent() ); 93 94 helper.disposeAndClear( EventObject() ); 95 } 96 97 { 98 OInterfaceContainerHelper helper( mutex ); 99 100 Reference< XVetoableChangeListener > r1 = new TestListener(); 101 Reference< XVetoableChangeListener > r2 = new TestListener(); 102 Reference< XVetoableChangeListener > r3 = new TestListener(); 103 104 helper.addInterface( r1 ); 105 helper.addInterface( r2 ); 106 helper.addInterface( r3 ); 107 108 OInterfaceIteratorHelper iterator( helper ); 109 110 ((XVetoableChangeListener*)iterator.next())->vetoableChange( PropertyChangeEvent() ); 111 iterator.remove(); 112 ((XVetoableChangeListener*)iterator.next())->vetoableChange( PropertyChangeEvent() ); 113 iterator.remove(); 114 ((XVetoableChangeListener*)iterator.next())->vetoableChange( PropertyChangeEvent() ); 115 iterator.remove(); 116 117 OSL_ASSERT( helper.getLength() == 0 ); 118 helper.disposeAndClear( EventObject() ); 119 } 120 121 { 122 OInterfaceContainerHelper helper( mutex ); 123 124 Reference< XVetoableChangeListener > r1 = new TestListener(); 125 Reference< XVetoableChangeListener > r2 = new TestListener(); 126 Reference< XVetoableChangeListener > r3 = new TestListener(); 127 128 helper.addInterface( r1 ); 129 helper.addInterface( r2 ); 130 helper.addInterface( r3 ); 131 132 { 133 OInterfaceIteratorHelper iterator( helper ); 134 while( iterator.hasMoreElements() ) 135 { 136 Reference< XVetoableChangeListener > r = ((XVetoableChangeListener*)iterator.next()); 137 if( r == r1 ) 138 iterator.remove(); 139 } 140 } 141 OSL_ASSERT( helper.getLength() == 2 ); 142 { 143 OInterfaceIteratorHelper iterator( helper ); 144 while( iterator.hasMoreElements() ) 145 { 146 Reference< XVetoableChangeListener > r = ((XVetoableChangeListener*)iterator.next()); 147 OSL_ASSERT( r != r1 && ( r == r2 || r == r3 ) ); 148 } 149 } 150 151 helper.disposeAndClear( EventObject() ); 152 } 153 } 154