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>
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>
35 std::type_info
const & getConditionTypeInfo()
36 { return typeid (salhelper::Condition
*); }
38 std::type_info
const & getConditionModifierTypeInfo()
39 { return typeid (salhelper::ConditionModifier
*); }
41 std::type_info
const & getConditionWaiterTypeInfo()
42 { return typeid (salhelper::ConditionWaiter
*); }
44 std::type_info
const & getORealDynamicLoaderTypeInfo()
45 { return typeid (salhelper::ORealDynamicLoader
*); }
47 std::type_info
const & getSimpleReferenceObjectTypeInfo()
48 { return typeid (salhelper::SimpleReferenceObject
*); }
54 class DerivedCondition
: public salhelper::Condition
{
56 explicit DerivedCondition(osl::Mutex
& mutex
): Condition(mutex
) {}
59 virtual bool applies() const override
{ return false; }
62 class DerivedConditionWaiterTimedout
:
63 public salhelper::ConditionWaiter::timedout
66 class DerivedSimpleReferenceObject
: public salhelper::SimpleReferenceObject
{};
68 class Test
: public CppUnit::TestFixture
{
72 void testConditionModifier();
74 void testConditionWaiter();
76 void testConditionWaiterTimedout();
78 void testORealDynamicLoader();
80 void testSimpleReferenceObject();
82 void testDerivedCondition();
84 void testDerivedConditionWaiterTimedout();
86 void testDerivedSimpleReferenceObject();
88 CPPUNIT_TEST_SUITE(Test
);
89 CPPUNIT_TEST(testCondition
);
90 CPPUNIT_TEST(testConditionModifier
);
91 CPPUNIT_TEST(testConditionWaiter
);
92 CPPUNIT_TEST(testConditionWaiterTimedout
);
93 CPPUNIT_TEST(testORealDynamicLoader
);
94 CPPUNIT_TEST(testSimpleReferenceObject
);
95 CPPUNIT_TEST(testDerivedCondition
);
96 CPPUNIT_TEST(testDerivedConditionWaiterTimedout
);
97 CPPUNIT_TEST(testDerivedSimpleReferenceObject
);
98 CPPUNIT_TEST_SUITE_END();
101 void Test::testCondition() {
103 std::unique_ptr
< salhelper::Condition
> p(new DerivedCondition(mutex
));
104 CPPUNIT_ASSERT(typeid(*p
) != typeid(salhelper::Condition
));
105 CPPUNIT_ASSERT(bool(typeid (p
.get()) == typeid (salhelper::Condition
*)));
107 typeid (const_cast< salhelper::Condition
const * >(p
.get()))
108 == typeid (salhelper::Condition
const *)));
110 typeid (const_cast< salhelper::Condition
volatile * >(p
.get()))
111 == typeid (salhelper::Condition
volatile *)));
112 CPPUNIT_ASSERT(bool(typeid (salhelper::Condition
*) == getConditionTypeInfo()));
116 #pragma warning (push)
117 #pragma warning (disable: 4189) // 'p': local variable is initialized but not referenced
121 void Test::testConditionModifier() {
122 salhelper::ConditionModifier
* p
= nullptr;
123 CPPUNIT_ASSERT(bool(typeid (*p
) == typeid (salhelper::ConditionModifier
)));
124 CPPUNIT_ASSERT(bool(typeid (p
) == typeid (salhelper::ConditionModifier
*)));
126 typeid (const_cast< salhelper::ConditionModifier
const * >(p
))
127 == typeid (salhelper::ConditionModifier
const *)));
129 typeid (const_cast< salhelper::ConditionModifier
volatile * >(p
))
130 == typeid (salhelper::ConditionModifier
volatile *)));
132 typeid (salhelper::ConditionModifier
*)
133 == getConditionModifierTypeInfo()));
136 void Test::testConditionWaiter() {
137 salhelper::ConditionWaiter
* p
= nullptr;
138 CPPUNIT_ASSERT(bool(typeid (*p
) == typeid (salhelper::ConditionWaiter
)));
139 CPPUNIT_ASSERT(bool(typeid (p
) == typeid (salhelper::ConditionWaiter
*)));
141 typeid (const_cast< salhelper::ConditionWaiter
const * >(p
))
142 == typeid (salhelper::ConditionWaiter
const *)));
144 typeid (const_cast< salhelper::ConditionWaiter
volatile * >(p
))
145 == typeid (salhelper::ConditionWaiter
volatile *)));
147 typeid (salhelper::ConditionWaiter
*) == getConditionWaiterTypeInfo()));
150 void Test::testConditionWaiterTimedout() {
151 salhelper::ConditionWaiter::timedout x
;
152 CPPUNIT_ASSERT(bool(typeid (x
) == typeid (salhelper::ConditionWaiter::timedout
)));
154 typeid (&x
) == typeid (salhelper::ConditionWaiter::timedout
*)));
156 typeid (const_cast< salhelper::ConditionWaiter::timedout
const * >(&x
))
157 == typeid (salhelper::ConditionWaiter::timedout
const *)));
160 (const_cast< salhelper::ConditionWaiter::timedout
volatile * >(&x
)))
161 == typeid (salhelper::ConditionWaiter::timedout
volatile *)));
163 throw salhelper::ConditionWaiter::timedout();
164 } catch (salhelper::ConditionWaiter::timedout
&) {
166 CPPUNIT_FAIL("not caught");
170 void Test::testORealDynamicLoader() {
171 salhelper::ORealDynamicLoader
* p
= nullptr;
172 CPPUNIT_ASSERT(typeid (p
) != typeid (salhelper::ORealDynamicLoader
));
173 CPPUNIT_ASSERT(bool(typeid (p
) == typeid (salhelper::ORealDynamicLoader
*)));
175 typeid (const_cast< salhelper::ORealDynamicLoader
const * >(p
))
176 == typeid (salhelper::ORealDynamicLoader
const *)));
178 typeid (const_cast< salhelper::ORealDynamicLoader
volatile * >(p
))
179 == typeid (salhelper::ORealDynamicLoader
volatile *)));
181 typeid (salhelper::ORealDynamicLoader
*)
182 == getORealDynamicLoaderTypeInfo()));
186 #pragma warning (pop)
189 void Test::testSimpleReferenceObject() {
190 salhelper::SimpleReferenceObject
* p
= new DerivedSimpleReferenceObject
;
193 typeid (*p
) != typeid (salhelper::SimpleReferenceObject
));
195 typeid (p
) == typeid (salhelper::SimpleReferenceObject
*)));
197 typeid (const_cast< salhelper::SimpleReferenceObject
const * >(p
))
198 == typeid (salhelper::SimpleReferenceObject
const *)));
201 (const_cast< salhelper::SimpleReferenceObject
volatile * >(p
)))
202 == typeid (salhelper::SimpleReferenceObject
volatile *)));
204 typeid (salhelper::SimpleReferenceObject
*)
205 == getSimpleReferenceObjectTypeInfo()));
207 delete static_cast< DerivedSimpleReferenceObject
* >(p
);
210 delete static_cast< DerivedSimpleReferenceObject
* >(p
);
213 void Test::testDerivedCondition() {
215 // Next line tests that new doesn't throw
216 std::unique_ptr
< salhelper::Condition
> p(new DerivedCondition(mutex
));
219 void Test::testDerivedConditionWaiterTimedout() {
220 // Next line tests that new doesn't throw
221 std::unique_ptr
< salhelper::ConditionWaiter::timedout
> p(
222 new DerivedConditionWaiterTimedout
);
224 throw DerivedConditionWaiterTimedout();
225 } catch (salhelper::ConditionWaiter::timedout
&) {
227 CPPUNIT_FAIL("not caught");
231 void Test::testDerivedSimpleReferenceObject() {
232 salhelper::SimpleReferenceObject
* p
= new DerivedSimpleReferenceObject
;
234 CPPUNIT_ASSERT(dynamic_cast< DerivedSimpleReferenceObject
* >(p
) != nullptr);
236 delete static_cast< DerivedSimpleReferenceObject
* >(p
);
239 delete static_cast< DerivedSimpleReferenceObject
* >(p
);
242 CPPUNIT_TEST_SUITE_REGISTRATION(Test
);
246 CPPUNIT_PLUGIN_IMPLEMENT();
248 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */