xref: /AOO41X/main/salhelper/qa/test_api.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir #include "sal/config.h"
29*cdf0e10cSrcweir 
30*cdf0e10cSrcweir #include <typeinfo>
31*cdf0e10cSrcweir 
32*cdf0e10cSrcweir namespace salhelper {
33*cdf0e10cSrcweir     class Condition;
34*cdf0e10cSrcweir     class ConditionModifier;
35*cdf0e10cSrcweir     class ConditionWaiter;
36*cdf0e10cSrcweir     class ORealDynamicLoader;
37*cdf0e10cSrcweir     class SimpleReferenceObject;
38*cdf0e10cSrcweir }
39*cdf0e10cSrcweir 
40*cdf0e10cSrcweir namespace {
41*cdf0e10cSrcweir 
42*cdf0e10cSrcweir std::type_info const & getConditionTypeInfo()
43*cdf0e10cSrcweir { return typeid (salhelper::Condition *); }
44*cdf0e10cSrcweir 
45*cdf0e10cSrcweir std::type_info const & getConditionModifierTypeInfo()
46*cdf0e10cSrcweir { return typeid (salhelper::ConditionModifier *); }
47*cdf0e10cSrcweir 
48*cdf0e10cSrcweir std::type_info const & getConditionWaiterTypeInfo()
49*cdf0e10cSrcweir { return typeid (salhelper::ConditionWaiter *); }
50*cdf0e10cSrcweir 
51*cdf0e10cSrcweir std::type_info const & getORealDynamicLoaderTypeInfo()
52*cdf0e10cSrcweir { return typeid (salhelper::ORealDynamicLoader *); }
53*cdf0e10cSrcweir 
54*cdf0e10cSrcweir std::type_info const & getSimpleReferenceObjectTypeInfo()
55*cdf0e10cSrcweir { return typeid (salhelper::SimpleReferenceObject *); }
56*cdf0e10cSrcweir 
57*cdf0e10cSrcweir }
58*cdf0e10cSrcweir 
59*cdf0e10cSrcweir #include "testshl/simpleheader.hxx"
60*cdf0e10cSrcweir #include "osl/mutex.hxx"
61*cdf0e10cSrcweir #include "salhelper/condition.hxx"
62*cdf0e10cSrcweir #include "salhelper/dynload.hxx"
63*cdf0e10cSrcweir #include "salhelper/simplereferenceobject.hxx"
64*cdf0e10cSrcweir 
65*cdf0e10cSrcweir #include <memory>
66*cdf0e10cSrcweir 
67*cdf0e10cSrcweir namespace {
68*cdf0e10cSrcweir 
69*cdf0e10cSrcweir class DerivedCondition: public salhelper::Condition {
70*cdf0e10cSrcweir public:
71*cdf0e10cSrcweir     explicit DerivedCondition(osl::Mutex & mutex): Condition(mutex) {}
72*cdf0e10cSrcweir 
73*cdf0e10cSrcweir protected:
74*cdf0e10cSrcweir     virtual bool applies() const { return false; }
75*cdf0e10cSrcweir };
76*cdf0e10cSrcweir 
77*cdf0e10cSrcweir class DerivedConditionWaiterTimedout:
78*cdf0e10cSrcweir     public salhelper::ConditionWaiter::timedout
79*cdf0e10cSrcweir {};
80*cdf0e10cSrcweir 
81*cdf0e10cSrcweir class DerivedSimpleReferenceObject: public salhelper::SimpleReferenceObject {};
82*cdf0e10cSrcweir 
83*cdf0e10cSrcweir class Test: public CppUnit::TestFixture {
84*cdf0e10cSrcweir public:
85*cdf0e10cSrcweir     void testCondition();
86*cdf0e10cSrcweir 
87*cdf0e10cSrcweir     void testConditionModifier();
88*cdf0e10cSrcweir 
89*cdf0e10cSrcweir     void testConditionWaiter();
90*cdf0e10cSrcweir 
91*cdf0e10cSrcweir     void testConditionWaiterTimedout();
92*cdf0e10cSrcweir 
93*cdf0e10cSrcweir     void testORealDynamicLoader();
94*cdf0e10cSrcweir 
95*cdf0e10cSrcweir     void testSimpleReferenceObject();
96*cdf0e10cSrcweir 
97*cdf0e10cSrcweir     void testDerivedCondition();
98*cdf0e10cSrcweir 
99*cdf0e10cSrcweir     void testDerivedConditionWaiterTimedout();
100*cdf0e10cSrcweir 
101*cdf0e10cSrcweir     void testDerivedSimpleReferenceObject();
102*cdf0e10cSrcweir 
103*cdf0e10cSrcweir     CPPUNIT_TEST_SUITE(Test);
104*cdf0e10cSrcweir     CPPUNIT_TEST(testCondition);
105*cdf0e10cSrcweir     CPPUNIT_TEST(testConditionModifier);
106*cdf0e10cSrcweir     CPPUNIT_TEST(testConditionWaiter);
107*cdf0e10cSrcweir     CPPUNIT_TEST(testConditionWaiterTimedout);
108*cdf0e10cSrcweir     CPPUNIT_TEST(testORealDynamicLoader);
109*cdf0e10cSrcweir     CPPUNIT_TEST(testSimpleReferenceObject);
110*cdf0e10cSrcweir     CPPUNIT_TEST(testDerivedCondition);
111*cdf0e10cSrcweir     CPPUNIT_TEST(testDerivedConditionWaiterTimedout);
112*cdf0e10cSrcweir     CPPUNIT_TEST(testDerivedSimpleReferenceObject);
113*cdf0e10cSrcweir     CPPUNIT_TEST_SUITE_END();
114*cdf0e10cSrcweir };
115*cdf0e10cSrcweir 
116*cdf0e10cSrcweir void Test::testCondition() {
117*cdf0e10cSrcweir     osl::Mutex mutex;
118*cdf0e10cSrcweir     std::auto_ptr< salhelper::Condition > p(new DerivedCondition(mutex));
119*cdf0e10cSrcweir     CPPUNIT_ASSERT(typeid (*p.get()) != typeid (salhelper::Condition));
120*cdf0e10cSrcweir     CPPUNIT_ASSERT(typeid (p.get()) == typeid (salhelper::Condition *));
121*cdf0e10cSrcweir     CPPUNIT_ASSERT(
122*cdf0e10cSrcweir         typeid (const_cast< salhelper::Condition const * >(p.get()))
123*cdf0e10cSrcweir         == typeid (salhelper::Condition const *));
124*cdf0e10cSrcweir     CPPUNIT_ASSERT(
125*cdf0e10cSrcweir         typeid (const_cast< salhelper::Condition volatile * >(p.get()))
126*cdf0e10cSrcweir         == typeid (salhelper::Condition volatile *));
127*cdf0e10cSrcweir     CPPUNIT_ASSERT(typeid (salhelper::Condition *) == getConditionTypeInfo());
128*cdf0e10cSrcweir }
129*cdf0e10cSrcweir 
130*cdf0e10cSrcweir void Test::testConditionModifier() {
131*cdf0e10cSrcweir     salhelper::ConditionModifier * p = 0;
132*cdf0e10cSrcweir     CPPUNIT_ASSERT(typeid (*p) == typeid (salhelper::ConditionModifier));
133*cdf0e10cSrcweir     CPPUNIT_ASSERT(typeid (p) == typeid (salhelper::ConditionModifier *));
134*cdf0e10cSrcweir     CPPUNIT_ASSERT(
135*cdf0e10cSrcweir         typeid (const_cast< salhelper::ConditionModifier const * >(p))
136*cdf0e10cSrcweir         == typeid (salhelper::ConditionModifier const *));
137*cdf0e10cSrcweir     CPPUNIT_ASSERT(
138*cdf0e10cSrcweir         typeid (const_cast< salhelper::ConditionModifier volatile * >(p))
139*cdf0e10cSrcweir         == typeid (salhelper::ConditionModifier volatile *));
140*cdf0e10cSrcweir     CPPUNIT_ASSERT(
141*cdf0e10cSrcweir         typeid (salhelper::ConditionModifier *)
142*cdf0e10cSrcweir         == getConditionModifierTypeInfo());
143*cdf0e10cSrcweir }
144*cdf0e10cSrcweir 
145*cdf0e10cSrcweir void Test::testConditionWaiter() {
146*cdf0e10cSrcweir     salhelper::ConditionWaiter * p = 0;
147*cdf0e10cSrcweir     CPPUNIT_ASSERT(typeid (*p) == typeid (salhelper::ConditionWaiter));
148*cdf0e10cSrcweir     CPPUNIT_ASSERT(typeid (p) == typeid (salhelper::ConditionWaiter *));
149*cdf0e10cSrcweir     CPPUNIT_ASSERT(
150*cdf0e10cSrcweir         typeid (const_cast< salhelper::ConditionWaiter const * >(p))
151*cdf0e10cSrcweir         == typeid (salhelper::ConditionWaiter const *));
152*cdf0e10cSrcweir     CPPUNIT_ASSERT(
153*cdf0e10cSrcweir         typeid (const_cast< salhelper::ConditionWaiter volatile * >(p))
154*cdf0e10cSrcweir         == typeid (salhelper::ConditionWaiter volatile *));
155*cdf0e10cSrcweir     CPPUNIT_ASSERT(
156*cdf0e10cSrcweir         typeid (salhelper::ConditionWaiter *) == getConditionWaiterTypeInfo());
157*cdf0e10cSrcweir }
158*cdf0e10cSrcweir 
159*cdf0e10cSrcweir void Test::testConditionWaiterTimedout() {
160*cdf0e10cSrcweir     salhelper::ConditionWaiter::timedout x;
161*cdf0e10cSrcweir     CPPUNIT_ASSERT(typeid (x) == typeid (salhelper::ConditionWaiter::timedout));
162*cdf0e10cSrcweir     CPPUNIT_ASSERT(
163*cdf0e10cSrcweir         typeid (&x) == typeid (salhelper::ConditionWaiter::timedout *));
164*cdf0e10cSrcweir     CPPUNIT_ASSERT(
165*cdf0e10cSrcweir         typeid (const_cast< salhelper::ConditionWaiter::timedout const * >(&x))
166*cdf0e10cSrcweir         == typeid (salhelper::ConditionWaiter::timedout const *));
167*cdf0e10cSrcweir     CPPUNIT_ASSERT(
168*cdf0e10cSrcweir         (typeid
169*cdf0e10cSrcweir          (const_cast< salhelper::ConditionWaiter::timedout volatile * >(&x)))
170*cdf0e10cSrcweir         == typeid (salhelper::ConditionWaiter::timedout volatile *));
171*cdf0e10cSrcweir     try {
172*cdf0e10cSrcweir         throw salhelper::ConditionWaiter::timedout();
173*cdf0e10cSrcweir     } catch (salhelper::ConditionWaiter::timedout &) {
174*cdf0e10cSrcweir     } catch (...) {
175*cdf0e10cSrcweir         CPPUNIT_FAIL("not caught");
176*cdf0e10cSrcweir     }
177*cdf0e10cSrcweir }
178*cdf0e10cSrcweir 
179*cdf0e10cSrcweir void Test::testORealDynamicLoader() {
180*cdf0e10cSrcweir     salhelper::ORealDynamicLoader * p = 0;
181*cdf0e10cSrcweir     CPPUNIT_ASSERT(typeid (p) != typeid (salhelper::ORealDynamicLoader));
182*cdf0e10cSrcweir     CPPUNIT_ASSERT(typeid (p) == typeid (salhelper::ORealDynamicLoader *));
183*cdf0e10cSrcweir     CPPUNIT_ASSERT(
184*cdf0e10cSrcweir         typeid (const_cast< salhelper::ORealDynamicLoader const * >(p))
185*cdf0e10cSrcweir         == typeid (salhelper::ORealDynamicLoader const *));
186*cdf0e10cSrcweir     CPPUNIT_ASSERT(
187*cdf0e10cSrcweir         typeid (const_cast< salhelper::ORealDynamicLoader volatile * >(p))
188*cdf0e10cSrcweir         == typeid (salhelper::ORealDynamicLoader volatile *));
189*cdf0e10cSrcweir     CPPUNIT_ASSERT(
190*cdf0e10cSrcweir         typeid (salhelper::ORealDynamicLoader *)
191*cdf0e10cSrcweir         == getORealDynamicLoaderTypeInfo());
192*cdf0e10cSrcweir }
193*cdf0e10cSrcweir 
194*cdf0e10cSrcweir void Test::testSimpleReferenceObject() {
195*cdf0e10cSrcweir     salhelper::SimpleReferenceObject * p = new DerivedSimpleReferenceObject;
196*cdf0e10cSrcweir     try {
197*cdf0e10cSrcweir         CPPUNIT_ASSERT(
198*cdf0e10cSrcweir             typeid (*p) != typeid (salhelper::SimpleReferenceObject));
199*cdf0e10cSrcweir         CPPUNIT_ASSERT(
200*cdf0e10cSrcweir             typeid (p) == typeid (salhelper::SimpleReferenceObject *));
201*cdf0e10cSrcweir         CPPUNIT_ASSERT(
202*cdf0e10cSrcweir             typeid (const_cast< salhelper::SimpleReferenceObject const * >(p))
203*cdf0e10cSrcweir             == typeid (salhelper::SimpleReferenceObject const *));
204*cdf0e10cSrcweir         CPPUNIT_ASSERT(
205*cdf0e10cSrcweir             (typeid
206*cdf0e10cSrcweir              (const_cast< salhelper::SimpleReferenceObject volatile * >(p)))
207*cdf0e10cSrcweir             == typeid (salhelper::SimpleReferenceObject volatile *));
208*cdf0e10cSrcweir         CPPUNIT_ASSERT(
209*cdf0e10cSrcweir             typeid (salhelper::SimpleReferenceObject *)
210*cdf0e10cSrcweir             == getSimpleReferenceObjectTypeInfo());
211*cdf0e10cSrcweir     } catch (...) {
212*cdf0e10cSrcweir         delete static_cast< DerivedSimpleReferenceObject * >(p);
213*cdf0e10cSrcweir         throw;
214*cdf0e10cSrcweir     }
215*cdf0e10cSrcweir }
216*cdf0e10cSrcweir 
217*cdf0e10cSrcweir void Test::testDerivedCondition() {
218*cdf0e10cSrcweir     osl::Mutex mutex;
219*cdf0e10cSrcweir     std::auto_ptr< salhelper::Condition > p(new DerivedCondition(mutex));
220*cdf0e10cSrcweir     CPPUNIT_ASSERT(dynamic_cast< DerivedCondition * >(p.get()) != 0);
221*cdf0e10cSrcweir }
222*cdf0e10cSrcweir 
223*cdf0e10cSrcweir void Test::testDerivedConditionWaiterTimedout() {
224*cdf0e10cSrcweir     std::auto_ptr< salhelper::ConditionWaiter::timedout > p(
225*cdf0e10cSrcweir         new DerivedConditionWaiterTimedout);
226*cdf0e10cSrcweir     CPPUNIT_ASSERT(
227*cdf0e10cSrcweir         dynamic_cast< DerivedConditionWaiterTimedout * >(p.get()) != 0);
228*cdf0e10cSrcweir     try {
229*cdf0e10cSrcweir         throw DerivedConditionWaiterTimedout();
230*cdf0e10cSrcweir     } catch (salhelper::ConditionWaiter::timedout &) {
231*cdf0e10cSrcweir     } catch (...) {
232*cdf0e10cSrcweir         CPPUNIT_FAIL("not caught");
233*cdf0e10cSrcweir     }
234*cdf0e10cSrcweir }
235*cdf0e10cSrcweir 
236*cdf0e10cSrcweir void Test::testDerivedSimpleReferenceObject() {
237*cdf0e10cSrcweir     salhelper::SimpleReferenceObject * p = new DerivedSimpleReferenceObject;
238*cdf0e10cSrcweir     try {
239*cdf0e10cSrcweir         CPPUNIT_ASSERT(dynamic_cast< DerivedSimpleReferenceObject * >(p) != 0);
240*cdf0e10cSrcweir     } catch (...) {
241*cdf0e10cSrcweir         delete static_cast< DerivedSimpleReferenceObject * >(p);
242*cdf0e10cSrcweir         throw;
243*cdf0e10cSrcweir     }
244*cdf0e10cSrcweir }
245*cdf0e10cSrcweir 
246*cdf0e10cSrcweir CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(Test, "alltests");
247*cdf0e10cSrcweir 
248*cdf0e10cSrcweir }
249*cdf0e10cSrcweir 
250*cdf0e10cSrcweir NOADDITIONAL;
251