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 <sal/config.h>
21 #include <osl/mutex.hxx>
22 #include <salhelper/condition.hxx>
23 #include <salhelper/dynload.hxx>
24 #include <salhelper/simplereferenceobject.hxx>
25 #include <cppunit/TestFixture.h>
26 #include <cppunit/extensions/HelperMacros.h>
27 #include <cppunit/plugin/TestPlugIn.h>
32 class DerivedCondition
: public salhelper::Condition
{
34 explicit DerivedCondition(osl::Mutex
& mutex
): Condition(mutex
) {}
37 virtual bool applies() const override
{ return false; }
40 class DerivedConditionWaiterTimedout
:
41 public salhelper::ConditionWaiter::timedout
44 class DerivedSimpleReferenceObject
: public salhelper::SimpleReferenceObject
{};
46 class Test
: public CppUnit::TestFixture
{
50 void testConditionWaiterTimedout();
52 void testORealDynamicLoader();
54 void testSimpleReferenceObject();
56 void testDerivedCondition();
58 void testDerivedConditionWaiterTimedout();
60 void testDerivedSimpleReferenceObject();
62 CPPUNIT_TEST_SUITE(Test
);
63 CPPUNIT_TEST(testCondition
);
64 CPPUNIT_TEST(testConditionWaiterTimedout
);
65 CPPUNIT_TEST(testORealDynamicLoader
);
66 CPPUNIT_TEST(testSimpleReferenceObject
);
67 CPPUNIT_TEST(testDerivedCondition
);
68 CPPUNIT_TEST(testDerivedConditionWaiterTimedout
);
69 CPPUNIT_TEST(testDerivedSimpleReferenceObject
);
70 CPPUNIT_TEST_SUITE_END();
73 void Test::testCondition() {
75 std::unique_ptr
< salhelper::Condition
> p(new DerivedCondition(mutex
));
76 [[maybe_unused
]] volatile auto const rtti
= &typeid(salhelper::Condition
);
79 void Test::testConditionWaiterTimedout() {
80 salhelper::ConditionWaiter::timedout x
;
81 [[maybe_unused
]] volatile auto const rtti
= &typeid(salhelper::ConditionWaiter::timedout
);
83 throw salhelper::ConditionWaiter::timedout();
84 } catch (salhelper::ConditionWaiter::timedout
&) {
86 CPPUNIT_FAIL("not caught");
90 void Test::testORealDynamicLoader() {
91 [[maybe_unused
]] volatile auto const rtti
= &typeid(salhelper::ORealDynamicLoader
);
94 void Test::testSimpleReferenceObject() {
95 salhelper::SimpleReferenceObject
* p
= new DerivedSimpleReferenceObject
;
96 delete static_cast< DerivedSimpleReferenceObject
* >(p
);
97 [[maybe_unused
]] volatile auto const rtti
= &typeid(salhelper::SimpleReferenceObject
);
100 void Test::testDerivedCondition() {
102 // Next line tests that new doesn't throw
103 std::unique_ptr
< salhelper::Condition
> p(new DerivedCondition(mutex
));
106 void Test::testDerivedConditionWaiterTimedout() {
107 // Next line tests that new doesn't throw
108 std::unique_ptr
< salhelper::ConditionWaiter::timedout
> p(
109 new DerivedConditionWaiterTimedout
);
111 throw DerivedConditionWaiterTimedout();
112 } catch (salhelper::ConditionWaiter::timedout
&) {
114 CPPUNIT_FAIL("not caught");
118 void Test::testDerivedSimpleReferenceObject() {
119 salhelper::SimpleReferenceObject
* p
= new DerivedSimpleReferenceObject
;
121 CPPUNIT_ASSERT(dynamic_cast< DerivedSimpleReferenceObject
* >(p
) != nullptr);
123 delete static_cast< DerivedSimpleReferenceObject
* >(p
);
126 delete static_cast< DerivedSimpleReferenceObject
* >(p
);
129 CPPUNIT_TEST_SUITE_REGISTRATION(Test
);
133 CPPUNIT_PLUGIN_IMPLEMENT();
135 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */