1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: test_weak.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_cppuhelper.hxx"
34 #include "sal/config.h"
36 #include "com/sun/star/lang/DisposedException.hpp"
37 #include "com/sun/star/uno/Reference.hxx"
38 #include "com/sun/star/uno/RuntimeException.hpp"
39 #include "com/sun/star/uno/XAdapter.hpp"
40 #include "com/sun/star/uno/XReference.hpp"
41 #include "com/sun/star/uno/XWeak.hpp"
42 #include "cppuhelper/implbase1.hxx"
43 #include "cppuhelper/weak.hxx"
44 #include "cppunit/simpleheader.hxx"
45 #include "rtl/ref.hxx"
46 #include "sal/types.h"
50 namespace css
= com::sun::star
;
52 class Reference
: public cppu::WeakImplHelper1
< css::uno::XReference
> {
54 Reference(): m_disposed(false) {}
56 virtual void SAL_CALL
dispose() throw (css::uno::RuntimeException
) {
61 bool isDisposed() const { return m_disposed
; }
64 virtual void handleDispose() {};
70 class RuntimeExceptionReference
: public Reference
{
72 virtual void handleDispose() {
73 throw css::uno::RuntimeException();
77 class DisposedExceptionReference
: public Reference
{
79 virtual void handleDispose() {
80 throw css::lang::DisposedException();
84 class Test
: public ::CppUnit::TestFixture
{
86 void testReferenceDispose();
88 CPPUNIT_TEST_SUITE(Test
);
89 CPPUNIT_TEST(testReferenceDispose
);
90 CPPUNIT_TEST_SUITE_END();
93 void Test::testReferenceDispose() {
94 css::uno::Reference
< css::uno::XWeak
> w(new ::cppu::OWeakObject
);
95 css::uno::Reference
< css::uno::XAdapter
> a(w
->queryAdapter());
96 ::rtl::Reference
< Reference
> r1(new RuntimeExceptionReference
);
97 ::rtl::Reference
< Reference
> r2(new Reference
);
98 ::rtl::Reference
< Reference
> r3(new DisposedExceptionReference
);
99 a
->addReference(r1
.get());
100 a
->addReference(r2
.get());
101 a
->addReference(r3
.get());
103 CPPUNIT_ASSERT(r1
->isDisposed());
104 CPPUNIT_ASSERT(r2
->isDisposed());
105 CPPUNIT_ASSERT(r3
->isDisposed());
108 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(Test
, "alltests");