[cp] Flag a few more import filters as EXOTIC
[LibreOffice.git] / salhelper / qa / test_api.cxx
blob2d4b8be0e2a83424668d8cf029e90a223a74ed64
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/config.h>
22 #include <typeinfo>
24 #include <osl/mutex.hxx>
25 #include <salhelper/condition.hxx>
26 #include <salhelper/dynload.hxx>
27 #include <salhelper/simplereferenceobject.hxx>
28 #include <cppunit/TestFixture.h>
29 #include <cppunit/extensions/HelperMacros.h>
30 #include <cppunit/plugin/TestPlugIn.h>
31 #include <memory>
33 namespace {
35 class DerivedCondition: public salhelper::Condition {
36 public:
37 explicit DerivedCondition(osl::Mutex & mutex): Condition(mutex) {}
39 protected:
40 virtual bool applies() const override { return false; }
43 class DerivedConditionWaiterTimedout:
44 public salhelper::ConditionWaiter::timedout
45 {};
47 class DerivedSimpleReferenceObject: public salhelper::SimpleReferenceObject {};
49 class Test: public CppUnit::TestFixture {
50 public:
51 void testCondition();
53 void testConditionWaiterTimedout();
55 void testORealDynamicLoader();
57 void testSimpleReferenceObject();
59 void testDerivedCondition();
61 void testDerivedConditionWaiterTimedout();
63 void testDerivedSimpleReferenceObject();
65 CPPUNIT_TEST_SUITE(Test);
66 CPPUNIT_TEST(testCondition);
67 CPPUNIT_TEST(testConditionWaiterTimedout);
68 CPPUNIT_TEST(testORealDynamicLoader);
69 CPPUNIT_TEST(testSimpleReferenceObject);
70 CPPUNIT_TEST(testDerivedCondition);
71 CPPUNIT_TEST(testDerivedConditionWaiterTimedout);
72 CPPUNIT_TEST(testDerivedSimpleReferenceObject);
73 CPPUNIT_TEST_SUITE_END();
76 void Test::testCondition() {
77 osl::Mutex mutex;
78 std::unique_ptr< salhelper::Condition > p(new DerivedCondition(mutex));
79 [[maybe_unused]] volatile auto const rtti = &typeid(salhelper::Condition);
82 void Test::testConditionWaiterTimedout() {
83 salhelper::ConditionWaiter::timedout x;
84 [[maybe_unused]] volatile auto const rtti = &typeid(salhelper::ConditionWaiter::timedout);
85 try {
86 throw salhelper::ConditionWaiter::timedout();
87 } catch (salhelper::ConditionWaiter::timedout &) {
88 } catch (...) {
89 CPPUNIT_FAIL("not caught");
93 void Test::testORealDynamicLoader() {
94 [[maybe_unused]] volatile auto const rtti = &typeid(salhelper::ORealDynamicLoader);
97 void Test::testSimpleReferenceObject() {
98 salhelper::SimpleReferenceObject * p = new DerivedSimpleReferenceObject;
99 delete static_cast< DerivedSimpleReferenceObject * >(p);
100 [[maybe_unused]] volatile auto const rtti = &typeid(salhelper::SimpleReferenceObject);
103 void Test::testDerivedCondition() {
104 osl::Mutex mutex;
105 // Next line tests that new doesn't throw
106 std::unique_ptr< salhelper::Condition > p(new DerivedCondition(mutex));
109 void Test::testDerivedConditionWaiterTimedout() {
110 // Next line tests that new doesn't throw
111 std::unique_ptr< salhelper::ConditionWaiter::timedout > p(
112 new DerivedConditionWaiterTimedout);
113 try {
114 throw DerivedConditionWaiterTimedout();
115 } catch (salhelper::ConditionWaiter::timedout &) {
116 } catch (...) {
117 CPPUNIT_FAIL("not caught");
121 void Test::testDerivedSimpleReferenceObject() {
122 salhelper::SimpleReferenceObject * p = new DerivedSimpleReferenceObject;
123 try {
124 CPPUNIT_ASSERT(dynamic_cast< DerivedSimpleReferenceObject * >(p) != nullptr);
125 } catch (...) {
126 delete static_cast< DerivedSimpleReferenceObject * >(p);
127 throw;
129 delete static_cast< DerivedSimpleReferenceObject * >(p);
132 CPPUNIT_TEST_SUITE_REGISTRATION(Test);
136 CPPUNIT_PLUGIN_IMPLEMENT();
138 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */