Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / comphelper / qa / container / testifcontainer3.cxx
blobe300adeda12eb654ff21165c4ffae7fca8160730
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/interfacecontainer3.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
35 class TestInterfaceContainer3 : public CppUnit::TestFixture
37 public:
38 void test1();
40 CPPUNIT_TEST_SUITE(TestInterfaceContainer3);
41 CPPUNIT_TEST(test1);
42 CPPUNIT_TEST_SUITE_END();
45 class TestListener : public cppu::WeakImplHelper<XVetoableChangeListener>
47 public:
48 // Methods
49 virtual void SAL_CALL disposing(const css::lang::EventObject& /*Source*/) override {}
51 virtual void SAL_CALL vetoableChange(const css::beans::PropertyChangeEvent& /*aEvent*/) override
56 void TestInterfaceContainer3::test1()
58 Mutex mutex;
61 comphelper::OInterfaceContainerHelper3<XVetoableChangeListener> helper(mutex);
63 Reference<XVetoableChangeListener> r1 = new TestListener;
64 Reference<XVetoableChangeListener> r2 = new TestListener;
65 Reference<XVetoableChangeListener> r3 = new TestListener;
67 helper.addInterface(r1);
68 helper.addInterface(r2);
69 helper.addInterface(r3);
71 helper.disposeAndClear(EventObject());
75 comphelper::OInterfaceContainerHelper3<XVetoableChangeListener> helper(mutex);
77 Reference<XVetoableChangeListener> r1 = new TestListener;
78 Reference<XVetoableChangeListener> r2 = new TestListener;
79 Reference<XVetoableChangeListener> r3 = new TestListener;
81 helper.addInterface(r1);
82 helper.addInterface(r2);
83 helper.addInterface(r3);
85 comphelper::OInterfaceIteratorHelper3 iterator(helper);
87 while (iterator.hasMoreElements())
88 iterator.next()->vetoableChange(PropertyChangeEvent());
90 helper.disposeAndClear(EventObject());
94 comphelper::OInterfaceContainerHelper3<XVetoableChangeListener> helper(mutex);
96 Reference<XVetoableChangeListener> r1 = new TestListener;
97 Reference<XVetoableChangeListener> r2 = new TestListener;
98 Reference<XVetoableChangeListener> r3 = new TestListener;
100 helper.addInterface(r1);
101 helper.addInterface(r2);
102 helper.addInterface(r3);
104 comphelper::OInterfaceIteratorHelper3 iterator(helper);
106 iterator.next()->vetoableChange(PropertyChangeEvent());
107 iterator.remove();
108 iterator.next()->vetoableChange(PropertyChangeEvent());
109 iterator.remove();
110 iterator.next()->vetoableChange(PropertyChangeEvent());
111 iterator.remove();
113 CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(0), helper.getLength());
114 helper.disposeAndClear(EventObject());
118 comphelper::OInterfaceContainerHelper3<XVetoableChangeListener> helper(mutex);
120 Reference<XVetoableChangeListener> r1 = new TestListener;
121 Reference<XVetoableChangeListener> r2 = new TestListener;
122 Reference<XVetoableChangeListener> r3 = new TestListener;
124 helper.addInterface(r1);
125 helper.addInterface(r2);
126 helper.addInterface(r3);
129 comphelper::OInterfaceIteratorHelper3 iterator(helper);
130 while (iterator.hasMoreElements())
132 Reference<XVetoableChangeListener> r = iterator.next();
133 if (r == r1)
134 iterator.remove();
137 CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(2), helper.getLength());
139 comphelper::OInterfaceIteratorHelper3 iterator(helper);
140 while (iterator.hasMoreElements())
142 Reference<XVetoableChangeListener> r = iterator.next();
143 CPPUNIT_ASSERT(r != r1);
144 CPPUNIT_ASSERT(r == r2 || r == r3);
148 helper.disposeAndClear(EventObject());
152 comphelper::OInterfaceContainerHelper3<XVetoableChangeListener> helper(mutex);
154 Reference<XVetoableChangeListener> r1 = new TestListener;
156 helper.addInterface(r1);
159 comphelper::OInterfaceIteratorHelper3 iterator(helper);
160 iterator.next();
161 iterator.remove();
163 CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(0), helper.getLength());
167 CPPUNIT_TEST_SUITE_REGISTRATION(TestInterfaceContainer3);
170 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */