Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / comphelper / qa / container / testifcontainer.cxx
blobd096b8fd874a3b5f13491deaab03c00a5c9cee2d
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 <cppunit/TestAssert.h>
21 #include <cppunit/TestFixture.h>
22 #include <cppunit/extensions/HelperMacros.h>
23 #include <osl/mutex.hxx>
24 #include <comphelper/interfacecontainer2.hxx>
25 #include <cppuhelper/implbase.hxx>
26 #include <com/sun/star/beans/XVetoableChangeListener.hpp>
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;
33 namespace
36 class TestInterfaceContainer2: public CppUnit::TestFixture
38 public:
39 void test1();
41 CPPUNIT_TEST_SUITE(TestInterfaceContainer2);
42 CPPUNIT_TEST(test1);
43 CPPUNIT_TEST_SUITE_END();
46 class TestListener : public cppu::WeakImplHelper< XVetoableChangeListener >
48 public:
49 // Methods
50 virtual void SAL_CALL disposing( const css::lang::EventObject& /*Source*/ ) override
55 virtual void SAL_CALL vetoableChange( const css::beans::PropertyChangeEvent& /*aEvent*/ ) override
61 void TestInterfaceContainer2::test1()
63 Mutex mutex;
66 comphelper::OInterfaceContainerHelper2 helper( mutex );
68 Reference< XVetoableChangeListener > r1 = new TestListener;
69 Reference< XVetoableChangeListener > r2 = new TestListener;
70 Reference< XVetoableChangeListener > r3 = new TestListener;
72 helper.addInterface( r1 );
73 helper.addInterface( r2 );
74 helper.addInterface( r3 );
76 helper.disposeAndClear( EventObject() );
80 comphelper::OInterfaceContainerHelper2 helper( mutex );
82 Reference< XVetoableChangeListener > r1 = new TestListener;
83 Reference< XVetoableChangeListener > r2 = new TestListener;
84 Reference< XVetoableChangeListener > r3 = new TestListener;
86 helper.addInterface( r1 );
87 helper.addInterface( r2 );
88 helper.addInterface( r3 );
90 comphelper::OInterfaceIteratorHelper2 iterator( helper );
92 while( iterator.hasMoreElements() )
93 static_cast<XVetoableChangeListener*>(iterator.next())->vetoableChange( PropertyChangeEvent() );
95 helper.disposeAndClear( EventObject() );
99 comphelper::OInterfaceContainerHelper2 helper( mutex );
101 Reference< XVetoableChangeListener > r1 = new TestListener;
102 Reference< XVetoableChangeListener > r2 = new TestListener;
103 Reference< XVetoableChangeListener > r3 = new TestListener;
105 helper.addInterface( r1 );
106 helper.addInterface( r2 );
107 helper.addInterface( r3 );
109 comphelper::OInterfaceIteratorHelper2 iterator( helper );
111 static_cast<XVetoableChangeListener*>(iterator.next())->vetoableChange( PropertyChangeEvent() );
112 iterator.remove();
113 static_cast<XVetoableChangeListener*>(iterator.next())->vetoableChange( PropertyChangeEvent() );
114 iterator.remove();
115 static_cast<XVetoableChangeListener*>(iterator.next())->vetoableChange( PropertyChangeEvent() );
116 iterator.remove();
118 CPPUNIT_ASSERT_EQUAL( static_cast<sal_Int32>(0), helper.getLength() );
119 helper.disposeAndClear( EventObject() );
123 comphelper::OInterfaceContainerHelper2 helper( mutex );
125 Reference< XVetoableChangeListener > r1 = new TestListener;
126 Reference< XVetoableChangeListener > r2 = new TestListener;
127 Reference< XVetoableChangeListener > r3 = new TestListener;
129 helper.addInterface( r1 );
130 helper.addInterface( r2 );
131 helper.addInterface( r3 );
134 comphelper::OInterfaceIteratorHelper2 iterator( helper );
135 while( iterator.hasMoreElements() )
137 Reference< XVetoableChangeListener > r = static_cast<XVetoableChangeListener*>(iterator.next());
138 if( r == r1 )
139 iterator.remove();
142 CPPUNIT_ASSERT_EQUAL( static_cast<sal_Int32>(2), helper.getLength() );
144 comphelper::OInterfaceIteratorHelper2 iterator( helper );
145 while( iterator.hasMoreElements() )
147 Reference< XVetoableChangeListener > r = static_cast<XVetoableChangeListener*>(iterator.next());
148 CPPUNIT_ASSERT( r != r1 );
149 CPPUNIT_ASSERT( r == r2 || r == r3 );
153 helper.disposeAndClear( EventObject() );
157 CPPUNIT_TEST_SUITE_REGISTRATION(TestInterfaceContainer2);
161 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */