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"
26 class ConditionModifier
;
27 class ConditionWaiter
;
28 class ORealDynamicLoader
;
29 class SimpleReferenceObject
;
34 std::type_info
const & getConditionTypeInfo()
35 { return typeid (salhelper::Condition
*); }
37 std::type_info
const & getConditionModifierTypeInfo()
38 { return typeid (salhelper::ConditionModifier
*); }
40 std::type_info
const & getConditionWaiterTypeInfo()
41 { return typeid (salhelper::ConditionWaiter
*); }
43 std::type_info
const & getORealDynamicLoaderTypeInfo()
44 { return typeid (salhelper::ORealDynamicLoader
*); }
46 std::type_info
const & getSimpleReferenceObjectTypeInfo()
47 { return typeid (salhelper::SimpleReferenceObject
*); }
51 #include "osl/mutex.hxx"
52 #include "salhelper/condition.hxx"
53 #include "salhelper/dynload.hxx"
54 #include "salhelper/simplereferenceobject.hxx"
55 #include <cppunit/TestFixture.h>
56 #include <cppunit/extensions/HelperMacros.h>
57 #include <cppunit/plugin/TestPlugIn.h>
58 #include <boost/scoped_ptr.hpp>
64 class DerivedCondition
: public salhelper::Condition
{
66 explicit DerivedCondition(osl::Mutex
& mutex
): Condition(mutex
) {}
69 virtual bool applies() const { return false; }
72 class DerivedConditionWaiterTimedout
:
73 public salhelper::ConditionWaiter::timedout
76 class DerivedSimpleReferenceObject
: public salhelper::SimpleReferenceObject
{};
78 class Test
: public CppUnit::TestFixture
{
82 void testConditionModifier();
84 void testConditionWaiter();
86 void testConditionWaiterTimedout();
88 void testORealDynamicLoader();
90 void testSimpleReferenceObject();
92 void testDerivedCondition();
94 void testDerivedConditionWaiterTimedout();
96 void testDerivedSimpleReferenceObject();
98 CPPUNIT_TEST_SUITE(Test
);
99 CPPUNIT_TEST(testCondition
);
100 CPPUNIT_TEST(testConditionModifier
);
101 CPPUNIT_TEST(testConditionWaiter
);
102 CPPUNIT_TEST(testConditionWaiterTimedout
);
103 CPPUNIT_TEST(testORealDynamicLoader
);
104 CPPUNIT_TEST(testSimpleReferenceObject
);
105 CPPUNIT_TEST(testDerivedCondition
);
106 CPPUNIT_TEST(testDerivedConditionWaiterTimedout
);
107 CPPUNIT_TEST(testDerivedSimpleReferenceObject
);
108 CPPUNIT_TEST_SUITE_END();
111 void Test::testCondition() {
113 std::auto_ptr
< salhelper::Condition
> p(new DerivedCondition(mutex
));
114 CPPUNIT_ASSERT(typeid (*p
.get()) != typeid (salhelper::Condition
));
115 CPPUNIT_ASSERT(typeid (p
.get()) == typeid (salhelper::Condition
*));
117 typeid (const_cast< salhelper::Condition
const * >(p
.get()))
118 == typeid (salhelper::Condition
const *));
120 typeid (const_cast< salhelper::Condition
volatile * >(p
.get()))
121 == typeid (salhelper::Condition
volatile *));
122 CPPUNIT_ASSERT(typeid (salhelper::Condition
*) == getConditionTypeInfo());
125 void Test::testConditionModifier() {
126 salhelper::ConditionModifier
* p
= 0;
127 CPPUNIT_ASSERT(typeid (*p
) == typeid (salhelper::ConditionModifier
));
128 CPPUNIT_ASSERT(typeid (p
) == typeid (salhelper::ConditionModifier
*));
130 typeid (const_cast< salhelper::ConditionModifier
const * >(p
))
131 == typeid (salhelper::ConditionModifier
const *));
133 typeid (const_cast< salhelper::ConditionModifier
volatile * >(p
))
134 == typeid (salhelper::ConditionModifier
volatile *));
136 typeid (salhelper::ConditionModifier
*)
137 == getConditionModifierTypeInfo());
140 void Test::testConditionWaiter() {
141 salhelper::ConditionWaiter
* p
= 0;
142 CPPUNIT_ASSERT(typeid (*p
) == typeid (salhelper::ConditionWaiter
));
143 CPPUNIT_ASSERT(typeid (p
) == typeid (salhelper::ConditionWaiter
*));
145 typeid (const_cast< salhelper::ConditionWaiter
const * >(p
))
146 == typeid (salhelper::ConditionWaiter
const *));
148 typeid (const_cast< salhelper::ConditionWaiter
volatile * >(p
))
149 == typeid (salhelper::ConditionWaiter
volatile *));
151 typeid (salhelper::ConditionWaiter
*) == getConditionWaiterTypeInfo());
154 void Test::testConditionWaiterTimedout() {
155 salhelper::ConditionWaiter::timedout x
;
156 CPPUNIT_ASSERT(typeid (x
) == typeid (salhelper::ConditionWaiter::timedout
));
158 typeid (&x
) == typeid (salhelper::ConditionWaiter::timedout
*));
160 typeid (const_cast< salhelper::ConditionWaiter::timedout
const * >(&x
))
161 == typeid (salhelper::ConditionWaiter::timedout
const *));
164 (const_cast< salhelper::ConditionWaiter::timedout
volatile * >(&x
)))
165 == typeid (salhelper::ConditionWaiter::timedout
volatile *));
167 throw salhelper::ConditionWaiter::timedout();
168 } catch (salhelper::ConditionWaiter::timedout
&) {
170 CPPUNIT_FAIL("not caught");
174 void Test::testORealDynamicLoader() {
175 salhelper::ORealDynamicLoader
* p
= 0;
176 CPPUNIT_ASSERT(typeid (p
) != typeid (salhelper::ORealDynamicLoader
));
177 CPPUNIT_ASSERT(typeid (p
) == typeid (salhelper::ORealDynamicLoader
*));
179 typeid (const_cast< salhelper::ORealDynamicLoader
const * >(p
))
180 == typeid (salhelper::ORealDynamicLoader
const *));
182 typeid (const_cast< salhelper::ORealDynamicLoader
volatile * >(p
))
183 == typeid (salhelper::ORealDynamicLoader
volatile *));
185 typeid (salhelper::ORealDynamicLoader
*)
186 == getORealDynamicLoaderTypeInfo());
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
);
212 void Test::testDerivedCondition() {
214 boost::scoped_ptr
< salhelper::Condition
> p(new DerivedCondition(mutex
));
215 CPPUNIT_ASSERT(dynamic_cast< DerivedCondition
* >(p
.get()) != 0);
218 void Test::testDerivedConditionWaiterTimedout() {
219 boost::scoped_ptr
< salhelper::ConditionWaiter::timedout
> p(
220 new DerivedConditionWaiterTimedout
);
222 dynamic_cast< DerivedConditionWaiterTimedout
* >(p
.get()) != 0);
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
) != 0);
236 delete static_cast< DerivedSimpleReferenceObject
* >(p
);
241 CPPUNIT_TEST_SUITE_REGISTRATION(Test
);
245 CPPUNIT_PLUGIN_IMPLEMENT();
247 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */