1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 // MARKER(update_precomp.py): autogen include statement, do not remove 29 #include "precompiled_cppuhelper.hxx" 30 31 #include "sal/config.h" 32 33 #include "com/sun/star/lang/DisposedException.hpp" 34 #include "com/sun/star/uno/Reference.hxx" 35 #include "com/sun/star/uno/RuntimeException.hpp" 36 #include "com/sun/star/uno/XAdapter.hpp" 37 #include "com/sun/star/uno/XReference.hpp" 38 #include "com/sun/star/uno/XWeak.hpp" 39 #include "cppuhelper/implbase1.hxx" 40 #include "cppuhelper/weak.hxx" 41 #include "testshl/simpleheader.hxx" 42 #include "rtl/ref.hxx" 43 #include "sal/types.h" 44 45 namespace { 46 47 namespace css = com::sun::star; 48 49 class Reference: public cppu::WeakImplHelper1< css::uno::XReference > { 50 public: 51 Reference(): m_disposed(false) {} 52 53 virtual void SAL_CALL dispose() throw (css::uno::RuntimeException) { 54 m_disposed = true; 55 handleDispose(); 56 } 57 58 bool isDisposed() const { return m_disposed; } 59 60 protected: 61 virtual void handleDispose() {}; 62 63 private: 64 bool m_disposed; 65 }; 66 67 class RuntimeExceptionReference: public Reference { 68 protected: 69 virtual void handleDispose() { 70 throw css::uno::RuntimeException(); 71 } 72 }; 73 74 class DisposedExceptionReference: public Reference { 75 protected: 76 virtual void handleDispose() { 77 throw css::lang::DisposedException(); 78 } 79 }; 80 81 class Test: public ::CppUnit::TestFixture { 82 public: 83 void testReferenceDispose(); 84 85 CPPUNIT_TEST_SUITE(Test); 86 CPPUNIT_TEST(testReferenceDispose); 87 CPPUNIT_TEST_SUITE_END(); 88 }; 89 90 void Test::testReferenceDispose() { 91 css::uno::Reference< css::uno::XWeak > w(new ::cppu::OWeakObject); 92 css::uno::Reference< css::uno::XAdapter > a(w->queryAdapter()); 93 ::rtl::Reference< Reference > r1(new RuntimeExceptionReference); 94 ::rtl::Reference< Reference > r2(new Reference); 95 ::rtl::Reference< Reference > r3(new DisposedExceptionReference); 96 a->addReference(r1.get()); 97 a->addReference(r2.get()); 98 a->addReference(r3.get()); 99 w.clear(); 100 CPPUNIT_ASSERT(r1->isDisposed()); 101 CPPUNIT_ASSERT(r2->isDisposed()); 102 CPPUNIT_ASSERT(r3->isDisposed()); 103 } 104 105 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(Test, "alltests"); 106 107 } 108 109 NOADDITIONAL; 110