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 27 #include "sal/config.h" 28 29 #include "com/sun/star/lang/DisposedException.hpp" 30 #include "com/sun/star/uno/Reference.hxx" 31 #include "com/sun/star/uno/RuntimeException.hpp" 32 #include "com/sun/star/uno/XAdapter.hpp" 33 #include "com/sun/star/uno/XReference.hpp" 34 #include "com/sun/star/uno/XWeak.hpp" 35 #include "cppuhelper/implbase1.hxx" 36 #include "cppuhelper/weak.hxx" 37 #include "testshl/simpleheader.hxx" 38 #include "rtl/ref.hxx" 39 #include "sal/types.h" 40 41 namespace { 42 43 namespace css = com::sun::star; 44 45 class Reference: public cppu::WeakImplHelper1< css::uno::XReference > { 46 public: Reference()47 Reference(): m_disposed(false) {} 48 dispose()49 virtual void SAL_CALL dispose() throw (css::uno::RuntimeException) { 50 m_disposed = true; 51 handleDispose(); 52 } 53 isDisposed() const54 bool isDisposed() const { return m_disposed; } 55 56 protected: handleDispose()57 virtual void handleDispose() {}; 58 59 private: 60 bool m_disposed; 61 }; 62 63 class RuntimeExceptionReference: public Reference { 64 protected: handleDispose()65 virtual void handleDispose() { 66 throw css::uno::RuntimeException(); 67 } 68 }; 69 70 class DisposedExceptionReference: public Reference { 71 protected: handleDispose()72 virtual void handleDispose() { 73 throw css::lang::DisposedException(); 74 } 75 }; 76 77 class Test: public ::CppUnit::TestFixture { 78 public: 79 void testReferenceDispose(); 80 81 CPPUNIT_TEST_SUITE(Test); 82 CPPUNIT_TEST(testReferenceDispose); 83 CPPUNIT_TEST_SUITE_END(); 84 }; 85 testReferenceDispose()86void Test::testReferenceDispose() { 87 css::uno::Reference< css::uno::XWeak > w(new ::cppu::OWeakObject); 88 css::uno::Reference< css::uno::XAdapter > a(w->queryAdapter()); 89 ::rtl::Reference< Reference > r1(new RuntimeExceptionReference); 90 ::rtl::Reference< Reference > r2(new Reference); 91 ::rtl::Reference< Reference > r3(new DisposedExceptionReference); 92 a->addReference(r1.get()); 93 a->addReference(r2.get()); 94 a->addReference(r3.get()); 95 w.clear(); 96 CPPUNIT_ASSERT(r1->isDisposed()); 97 CPPUNIT_ASSERT(r2->isDisposed()); 98 CPPUNIT_ASSERT(r3->isDisposed()); 99 } 100 101 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(Test, "alltests"); 102 103 } 104 105 NOADDITIONAL; 106