1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 // MARKER(update_precomp.py): autogen include statement, do not remove 25 #include "precompiled_cppuhelper.hxx" 26 #include <osl/mutex.hxx> 27 28 #include <cppuhelper/interfacecontainer.hxx> 29 #include <cppuhelper/implbase1.hxx> 30 31 #include <com/sun/star/beans/XVetoableChangeListener.hpp> 32 33 using namespace ::cppu; 34 using namespace ::osl; 35 using namespace ::com::sun::star::lang; 36 using namespace ::com::sun::star::beans; 37 using namespace ::com::sun::star::uno; 38 39 40 class TestListener : public WeakImplHelper1< XVetoableChangeListener > 41 { 42 // Methods disposing(const::com::sun::star::lang::EventObject &)43 virtual void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& /*Source*/ ) 44 { 45 46 } 47 vetoableChange(const::com::sun::star::beans::PropertyChangeEvent &)48 virtual void SAL_CALL vetoableChange( const ::com::sun::star::beans::PropertyChangeEvent& /*aEvent*/ ) 49 { 50 51 } 52 53 }; 54 test_interfacecontainer()55void test_interfacecontainer() 56 { 57 Mutex mutex; 58 59 { 60 OInterfaceContainerHelper helper( mutex ); 61 62 Reference< XVetoableChangeListener > r1 = new TestListener(); 63 Reference< XVetoableChangeListener > r2 = new TestListener(); 64 Reference< XVetoableChangeListener > r3 = new TestListener(); 65 66 helper.addInterface( r1 ); 67 helper.addInterface( r2 ); 68 helper.addInterface( r3 ); 69 70 helper.disposeAndClear( EventObject() ); 71 } 72 73 { 74 OInterfaceContainerHelper helper( mutex ); 75 76 Reference< XVetoableChangeListener > r1 = new TestListener(); 77 Reference< XVetoableChangeListener > r2 = new TestListener(); 78 Reference< XVetoableChangeListener > r3 = new TestListener(); 79 80 helper.addInterface( r1 ); 81 helper.addInterface( r2 ); 82 helper.addInterface( r3 ); 83 84 OInterfaceIteratorHelper iterator( helper ); 85 86 while( iterator.hasMoreElements() ) 87 ((XVetoableChangeListener*)iterator.next())->vetoableChange( PropertyChangeEvent() ); 88 89 helper.disposeAndClear( EventObject() ); 90 } 91 92 { 93 OInterfaceContainerHelper helper( mutex ); 94 95 Reference< XVetoableChangeListener > r1 = new TestListener(); 96 Reference< XVetoableChangeListener > r2 = new TestListener(); 97 Reference< XVetoableChangeListener > r3 = new TestListener(); 98 99 helper.addInterface( r1 ); 100 helper.addInterface( r2 ); 101 helper.addInterface( r3 ); 102 103 OInterfaceIteratorHelper iterator( helper ); 104 105 ((XVetoableChangeListener*)iterator.next())->vetoableChange( PropertyChangeEvent() ); 106 iterator.remove(); 107 ((XVetoableChangeListener*)iterator.next())->vetoableChange( PropertyChangeEvent() ); 108 iterator.remove(); 109 ((XVetoableChangeListener*)iterator.next())->vetoableChange( PropertyChangeEvent() ); 110 iterator.remove(); 111 112 OSL_ASSERT( helper.getLength() == 0 ); 113 helper.disposeAndClear( EventObject() ); 114 } 115 116 { 117 OInterfaceContainerHelper helper( mutex ); 118 119 Reference< XVetoableChangeListener > r1 = new TestListener(); 120 Reference< XVetoableChangeListener > r2 = new TestListener(); 121 Reference< XVetoableChangeListener > r3 = new TestListener(); 122 123 helper.addInterface( r1 ); 124 helper.addInterface( r2 ); 125 helper.addInterface( r3 ); 126 127 { 128 OInterfaceIteratorHelper iterator( helper ); 129 while( iterator.hasMoreElements() ) 130 { 131 Reference< XVetoableChangeListener > r = ((XVetoableChangeListener*)iterator.next()); 132 if( r == r1 ) 133 iterator.remove(); 134 } 135 } 136 OSL_ASSERT( helper.getLength() == 2 ); 137 { 138 OInterfaceIteratorHelper iterator( helper ); 139 while( iterator.hasMoreElements() ) 140 { 141 Reference< XVetoableChangeListener > r = ((XVetoableChangeListener*)iterator.next()); 142 OSL_ASSERT( r != r1 && ( r == r2 || r == r3 ) ); 143 } 144 } 145 146 helper.disposeAndClear( EventObject() ); 147 } 148 } 149