bump product version to 4.1.6.2
[LibreOffice.git] / cppuhelper / qa / weak / test_weak.cxx
blobfb2ee5134182f37c71a610fb6baf18859bdca4d5
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 <sal/types.h>
21 #include <cppunit/TestFixture.h>
22 #include <cppunit/extensions/HelperMacros.h>
23 #include <cppunit/plugin/TestPlugIn.h>
25 #include "com/sun/star/lang/DisposedException.hpp"
26 #include "com/sun/star/uno/Reference.hxx"
27 #include "com/sun/star/uno/RuntimeException.hpp"
28 #include "com/sun/star/uno/XAdapter.hpp"
29 #include "com/sun/star/uno/XReference.hpp"
30 #include "com/sun/star/uno/XWeak.hpp"
31 #include "cppuhelper/implbase1.hxx"
32 #include "cppuhelper/weak.hxx"
33 #include "rtl/ref.hxx"
34 #include "sal/types.h"
36 namespace {
38 class Reference: public cppu::WeakImplHelper1< css::uno::XReference > {
39 public:
40 Reference(): m_disposed(false) {}
42 virtual void SAL_CALL dispose() throw (css::uno::RuntimeException) {
43 m_disposed = true;
44 handleDispose();
47 bool isDisposed() const { return m_disposed; }
49 protected:
50 virtual void handleDispose() {};
52 private:
53 bool m_disposed;
56 class RuntimeExceptionReference: public Reference {
57 protected:
58 virtual void handleDispose() {
59 throw css::uno::RuntimeException();
63 class DisposedExceptionReference: public Reference {
64 protected:
65 virtual void handleDispose() {
66 throw css::lang::DisposedException();
70 class Test: public ::CppUnit::TestFixture {
71 public:
72 void testReferenceDispose();
74 CPPUNIT_TEST_SUITE(Test);
75 CPPUNIT_TEST(testReferenceDispose);
76 CPPUNIT_TEST_SUITE_END();
79 void Test::testReferenceDispose() {
80 css::uno::Reference< css::uno::XWeak > w(new ::cppu::OWeakObject);
81 css::uno::Reference< css::uno::XAdapter > a(w->queryAdapter());
82 ::rtl::Reference< Reference > r1(new RuntimeExceptionReference);
83 ::rtl::Reference< Reference > r2(new Reference);
84 ::rtl::Reference< Reference > r3(new DisposedExceptionReference);
85 a->addReference(r1.get());
86 a->addReference(r2.get());
87 a->addReference(r3.get());
88 w.clear();
89 CPPUNIT_ASSERT(r1->isDisposed());
90 CPPUNIT_ASSERT(r2->isDisposed());
91 CPPUNIT_ASSERT(r3->isDisposed());
94 CPPUNIT_TEST_SUITE_REGISTRATION(Test);
98 CPPUNIT_PLUGIN_IMPLEMENT();
100 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */