1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: test_api.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #include "sal/config.h"
37 class ConditionModifier
;
38 class ConditionWaiter
;
39 class ORealDynamicLoader
;
40 class SimpleReferenceObject
;
45 std::type_info
const & getConditionTypeInfo()
46 { return typeid (salhelper::Condition
*); }
48 std::type_info
const & getConditionModifierTypeInfo()
49 { return typeid (salhelper::ConditionModifier
*); }
51 std::type_info
const & getConditionWaiterTypeInfo()
52 { return typeid (salhelper::ConditionWaiter
*); }
54 std::type_info
const & getORealDynamicLoaderTypeInfo()
55 { return typeid (salhelper::ORealDynamicLoader
*); }
57 std::type_info
const & getSimpleReferenceObjectTypeInfo()
58 { return typeid (salhelper::SimpleReferenceObject
*); }
62 #include "cppunit/simpleheader.hxx"
63 #include "osl/mutex.hxx"
64 #include "salhelper/condition.hxx"
65 #include "salhelper/dynload.hxx"
66 #include "salhelper/simplereferenceobject.hxx"
72 class DerivedCondition
: public salhelper::Condition
{
74 explicit DerivedCondition(osl::Mutex
& mutex
): Condition(mutex
) {}
77 virtual bool applies() const { return false; }
80 class DerivedConditionWaiterTimedout
:
81 public salhelper::ConditionWaiter::timedout
84 class DerivedSimpleReferenceObject
: public salhelper::SimpleReferenceObject
{};
86 class Test
: public CppUnit::TestFixture
{
90 void testConditionModifier();
92 void testConditionWaiter();
94 void testConditionWaiterTimedout();
96 void testORealDynamicLoader();
98 void testSimpleReferenceObject();
100 void testDerivedCondition();
102 void testDerivedConditionWaiterTimedout();
104 void testDerivedSimpleReferenceObject();
106 CPPUNIT_TEST_SUITE(Test
);
107 CPPUNIT_TEST(testCondition
);
108 CPPUNIT_TEST(testConditionModifier
);
109 CPPUNIT_TEST(testConditionWaiter
);
110 CPPUNIT_TEST(testConditionWaiterTimedout
);
111 CPPUNIT_TEST(testORealDynamicLoader
);
112 CPPUNIT_TEST(testSimpleReferenceObject
);
113 CPPUNIT_TEST(testDerivedCondition
);
114 CPPUNIT_TEST(testDerivedConditionWaiterTimedout
);
115 CPPUNIT_TEST(testDerivedSimpleReferenceObject
);
116 CPPUNIT_TEST_SUITE_END();
119 void Test::testCondition() {
121 std::auto_ptr
< salhelper::Condition
> p(new DerivedCondition(mutex
));
122 CPPUNIT_ASSERT(typeid (*p
.get()) != typeid (salhelper::Condition
));
123 CPPUNIT_ASSERT(typeid (p
.get()) == typeid (salhelper::Condition
*));
125 typeid (const_cast< salhelper::Condition
const * >(p
.get()))
126 == typeid (salhelper::Condition
const *));
128 typeid (const_cast< salhelper::Condition
volatile * >(p
.get()))
129 == typeid (salhelper::Condition
volatile *));
130 CPPUNIT_ASSERT(typeid (salhelper::Condition
*) == getConditionTypeInfo());
133 void Test::testConditionModifier() {
134 salhelper::ConditionModifier
* p
= 0;
135 CPPUNIT_ASSERT(typeid (*p
) == typeid (salhelper::ConditionModifier
));
136 CPPUNIT_ASSERT(typeid (p
) == typeid (salhelper::ConditionModifier
*));
138 typeid (const_cast< salhelper::ConditionModifier
const * >(p
))
139 == typeid (salhelper::ConditionModifier
const *));
141 typeid (const_cast< salhelper::ConditionModifier
volatile * >(p
))
142 == typeid (salhelper::ConditionModifier
volatile *));
144 typeid (salhelper::ConditionModifier
*)
145 == getConditionModifierTypeInfo());
148 void Test::testConditionWaiter() {
149 salhelper::ConditionWaiter
* p
= 0;
150 CPPUNIT_ASSERT(typeid (*p
) == typeid (salhelper::ConditionWaiter
));
151 CPPUNIT_ASSERT(typeid (p
) == typeid (salhelper::ConditionWaiter
*));
153 typeid (const_cast< salhelper::ConditionWaiter
const * >(p
))
154 == typeid (salhelper::ConditionWaiter
const *));
156 typeid (const_cast< salhelper::ConditionWaiter
volatile * >(p
))
157 == typeid (salhelper::ConditionWaiter
volatile *));
159 typeid (salhelper::ConditionWaiter
*) == getConditionWaiterTypeInfo());
162 void Test::testConditionWaiterTimedout() {
163 salhelper::ConditionWaiter::timedout x
;
164 CPPUNIT_ASSERT(typeid (x
) == typeid (salhelper::ConditionWaiter::timedout
));
166 typeid (&x
) == typeid (salhelper::ConditionWaiter::timedout
*));
168 typeid (const_cast< salhelper::ConditionWaiter::timedout
const * >(&x
))
169 == typeid (salhelper::ConditionWaiter::timedout
const *));
172 (const_cast< salhelper::ConditionWaiter::timedout
volatile * >(&x
)))
173 == typeid (salhelper::ConditionWaiter::timedout
volatile *));
175 throw salhelper::ConditionWaiter::timedout();
176 } catch (salhelper::ConditionWaiter::timedout
&) {
178 CPPUNIT_FAIL("not caught");
182 void Test::testORealDynamicLoader() {
183 salhelper::ORealDynamicLoader
* p
= 0;
184 CPPUNIT_ASSERT(typeid (p
) != typeid (salhelper::ORealDynamicLoader
));
185 CPPUNIT_ASSERT(typeid (p
) == typeid (salhelper::ORealDynamicLoader
*));
187 typeid (const_cast< salhelper::ORealDynamicLoader
const * >(p
))
188 == typeid (salhelper::ORealDynamicLoader
const *));
190 typeid (const_cast< salhelper::ORealDynamicLoader
volatile * >(p
))
191 == typeid (salhelper::ORealDynamicLoader
volatile *));
193 typeid (salhelper::ORealDynamicLoader
*)
194 == getORealDynamicLoaderTypeInfo());
197 void Test::testSimpleReferenceObject() {
198 salhelper::SimpleReferenceObject
* p
= new DerivedSimpleReferenceObject
;
201 typeid (*p
) != typeid (salhelper::SimpleReferenceObject
));
203 typeid (p
) == typeid (salhelper::SimpleReferenceObject
*));
205 typeid (const_cast< salhelper::SimpleReferenceObject
const * >(p
))
206 == typeid (salhelper::SimpleReferenceObject
const *));
209 (const_cast< salhelper::SimpleReferenceObject
volatile * >(p
)))
210 == typeid (salhelper::SimpleReferenceObject
volatile *));
212 typeid (salhelper::SimpleReferenceObject
*)
213 == getSimpleReferenceObjectTypeInfo());
215 delete static_cast< DerivedSimpleReferenceObject
* >(p
);
220 void Test::testDerivedCondition() {
222 std::auto_ptr
< salhelper::Condition
> p(new DerivedCondition(mutex
));
223 CPPUNIT_ASSERT(dynamic_cast< DerivedCondition
* >(p
.get()) != 0);
226 void Test::testDerivedConditionWaiterTimedout() {
227 std::auto_ptr
< salhelper::ConditionWaiter::timedout
> p(
228 new DerivedConditionWaiterTimedout
);
230 dynamic_cast< DerivedConditionWaiterTimedout
* >(p
.get()) != 0);
232 throw DerivedConditionWaiterTimedout();
233 } catch (salhelper::ConditionWaiter::timedout
&) {
235 CPPUNIT_FAIL("not caught");
239 void Test::testDerivedSimpleReferenceObject() {
240 salhelper::SimpleReferenceObject
* p
= new DerivedSimpleReferenceObject
;
242 CPPUNIT_ASSERT(dynamic_cast< DerivedSimpleReferenceObject
* >(p
) != 0);
244 delete static_cast< DerivedSimpleReferenceObject
* >(p
);
249 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(Test
, "alltests");