1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <osl/mutex.hxx>
22 #include <cppuhelper/interfacecontainer.hxx>
23 #include <cppuhelper/implbase1.hxx>
25 #include <com/sun/star/beans/XVetoableChangeListener.hpp>
27 using namespace ::cppu
;
28 using namespace ::osl
;
29 using namespace ::com::sun::star::lang
;
30 using namespace ::com::sun::star::beans
;
31 using namespace ::com::sun::star::uno
;
34 class TestListener
: public WeakImplHelper1
< XVetoableChangeListener
>
38 virtual void SAL_CALL
disposing( const ::com::sun::star::lang::EventObject
& /*Source*/ ) throw(::com::sun::star::uno::RuntimeException
)
43 virtual void SAL_CALL
vetoableChange( const ::com::sun::star::beans::PropertyChangeEvent
& /*aEvent*/ )
44 throw(::com::sun::star::beans::PropertyVetoException
, ::com::sun::star::uno::RuntimeException
)
50 void test_interfacecontainer()
55 OInterfaceContainerHelper
helper( mutex
);
57 Reference
< XVetoableChangeListener
> r1
= new TestListener();
58 Reference
< XVetoableChangeListener
> r2
= new TestListener();
59 Reference
< XVetoableChangeListener
> r3
= new TestListener();
61 helper
.addInterface( r1
);
62 helper
.addInterface( r2
);
63 helper
.addInterface( r3
);
65 helper
.disposeAndClear( EventObject() );
69 OInterfaceContainerHelper
helper( mutex
);
71 Reference
< XVetoableChangeListener
> r1
= new TestListener();
72 Reference
< XVetoableChangeListener
> r2
= new TestListener();
73 Reference
< XVetoableChangeListener
> r3
= new TestListener();
75 helper
.addInterface( r1
);
76 helper
.addInterface( r2
);
77 helper
.addInterface( r3
);
79 OInterfaceIteratorHelper
iterator( helper
);
81 while( iterator
.hasMoreElements() )
82 ((XVetoableChangeListener
*)iterator
.next())->vetoableChange( PropertyChangeEvent() );
84 helper
.disposeAndClear( EventObject() );
88 OInterfaceContainerHelper
helper( mutex
);
90 Reference
< XVetoableChangeListener
> r1
= new TestListener();
91 Reference
< XVetoableChangeListener
> r2
= new TestListener();
92 Reference
< XVetoableChangeListener
> r3
= new TestListener();
94 helper
.addInterface( r1
);
95 helper
.addInterface( r2
);
96 helper
.addInterface( r3
);
98 OInterfaceIteratorHelper
iterator( helper
);
100 ((XVetoableChangeListener
*)iterator
.next())->vetoableChange( PropertyChangeEvent() );
102 ((XVetoableChangeListener
*)iterator
.next())->vetoableChange( PropertyChangeEvent() );
104 ((XVetoableChangeListener
*)iterator
.next())->vetoableChange( PropertyChangeEvent() );
107 OSL_ASSERT( helper
.getLength() == 0 );
108 helper
.disposeAndClear( EventObject() );
112 OInterfaceContainerHelper
helper( mutex
);
114 Reference
< XVetoableChangeListener
> r1
= new TestListener();
115 Reference
< XVetoableChangeListener
> r2
= new TestListener();
116 Reference
< XVetoableChangeListener
> r3
= new TestListener();
118 helper
.addInterface( r1
);
119 helper
.addInterface( r2
);
120 helper
.addInterface( r3
);
123 OInterfaceIteratorHelper
iterator( helper
);
124 while( iterator
.hasMoreElements() )
126 Reference
< XVetoableChangeListener
> r
= ((XVetoableChangeListener
*)iterator
.next());
131 OSL_ASSERT( helper
.getLength() == 2 );
133 OInterfaceIteratorHelper
iterator( helper
);
134 while( iterator
.hasMoreElements() )
136 Reference
< XVetoableChangeListener
> r
= ((XVetoableChangeListener
*)iterator
.next());
137 OSL_ASSERT( r
!= r1
&& ( r
== r2
|| r
== r3
) );
141 helper
.disposeAndClear( EventObject() );
145 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */