1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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/TestFixture.h>
21 #include <cppunit/extensions/HelperMacros.h>
22 #include <cppunit/plugin/TestPlugIn.h>
24 #include <com/sun/star/lang/DisposedException.hpp>
25 #include <com/sun/star/uno/Reference.hxx>
26 #include <com/sun/star/uno/RuntimeException.hpp>
27 #include <com/sun/star/uno/XAdapter.hpp>
28 #include <com/sun/star/uno/XReference.hpp>
29 #include <com/sun/star/uno/XWeak.hpp>
30 #include <cppuhelper/implbase.hxx>
31 #include <cppuhelper/weak.hxx>
32 #include <rtl/ref.hxx>
33 #include <sal/types.h>
37 class Reference
: public cppu::WeakImplHelper
< css::uno::XReference
> {
39 Reference(): m_disposed(false) {}
41 void SAL_CALL
dispose() override
{
46 bool isDisposed() const { return m_disposed
; }
49 virtual void handleDispose() {};
55 class RuntimeExceptionReference
: public Reference
{
57 void handleDispose() override
{
58 throw css::uno::RuntimeException();
62 class DisposedExceptionReference
: public Reference
{
64 void handleDispose() override
{
65 throw css::lang::DisposedException();
69 class Test
: public ::CppUnit::TestFixture
{
71 void testReferenceDispose();
73 CPPUNIT_TEST_SUITE(Test
);
74 CPPUNIT_TEST(testReferenceDispose
);
75 CPPUNIT_TEST_SUITE_END();
78 void Test::testReferenceDispose() {
79 css::uno::Reference
< css::uno::XWeak
> w(new ::cppu::OWeakObject
);
80 css::uno::Reference
< css::uno::XAdapter
> a(w
->queryAdapter());
81 ::rtl::Reference
< Reference
> r1(new RuntimeExceptionReference
);
82 ::rtl::Reference
< Reference
> r2(new Reference
);
83 ::rtl::Reference
< Reference
> r3(new DisposedExceptionReference
);
88 CPPUNIT_ASSERT(r1
->isDisposed());
89 CPPUNIT_ASSERT(r2
->isDisposed());
90 CPPUNIT_ASSERT(r3
->isDisposed());
93 CPPUNIT_TEST_SUITE_REGISTRATION(Test
);
97 CPPUNIT_PLUGIN_IMPLEMENT();
99 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */