tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / cppuhelper / qa / weak / test_weak.cxx
blob4db360b40e3adefa6aac9b0921480ea758c87012
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 <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>
35 namespace {
37 class Reference: public cppu::WeakImplHelper< css::uno::XReference > {
38 public:
39 Reference(): m_disposed(false) {}
41 void SAL_CALL dispose() override {
42 m_disposed = true;
43 handleDispose();
46 bool isDisposed() const { return m_disposed; }
48 protected:
49 virtual void handleDispose() {};
51 private:
52 bool m_disposed;
55 class RuntimeExceptionReference: public Reference {
56 protected:
57 void handleDispose() override {
58 throw css::uno::RuntimeException();
62 class DisposedExceptionReference: public Reference {
63 protected:
64 void handleDispose() override {
65 throw css::lang::DisposedException();
69 class Test: public ::CppUnit::TestFixture {
70 public:
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);
84 a->addReference(r1);
85 a->addReference(r2);
86 a->addReference(r3);
87 w.clear();
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: */