xref: /aoo4110/main/salhelper/qa/test_api.cxx (revision b1cdbd2c)
1*b1cdbd2cSJim Jagielski /**************************************************************
2*b1cdbd2cSJim Jagielski  *
3*b1cdbd2cSJim Jagielski  * Licensed to the Apache Software Foundation (ASF) under one
4*b1cdbd2cSJim Jagielski  * or more contributor license agreements.  See the NOTICE file
5*b1cdbd2cSJim Jagielski  * distributed with this work for additional information
6*b1cdbd2cSJim Jagielski  * regarding copyright ownership.  The ASF licenses this file
7*b1cdbd2cSJim Jagielski  * to you under the Apache License, Version 2.0 (the
8*b1cdbd2cSJim Jagielski  * "License"); you may not use this file except in compliance
9*b1cdbd2cSJim Jagielski  * with the License.  You may obtain a copy of the License at
10*b1cdbd2cSJim Jagielski  *
11*b1cdbd2cSJim Jagielski  *   http://www.apache.org/licenses/LICENSE-2.0
12*b1cdbd2cSJim Jagielski  *
13*b1cdbd2cSJim Jagielski  * Unless required by applicable law or agreed to in writing,
14*b1cdbd2cSJim Jagielski  * software distributed under the License is distributed on an
15*b1cdbd2cSJim Jagielski  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*b1cdbd2cSJim Jagielski  * KIND, either express or implied.  See the License for the
17*b1cdbd2cSJim Jagielski  * specific language governing permissions and limitations
18*b1cdbd2cSJim Jagielski  * under the License.
19*b1cdbd2cSJim Jagielski  *
20*b1cdbd2cSJim Jagielski  *************************************************************/
21*b1cdbd2cSJim Jagielski 
22*b1cdbd2cSJim Jagielski 
23*b1cdbd2cSJim Jagielski 
24*b1cdbd2cSJim Jagielski #include "sal/config.h"
25*b1cdbd2cSJim Jagielski 
26*b1cdbd2cSJim Jagielski #include <typeinfo>
27*b1cdbd2cSJim Jagielski 
28*b1cdbd2cSJim Jagielski namespace salhelper {
29*b1cdbd2cSJim Jagielski     class Condition;
30*b1cdbd2cSJim Jagielski     class ConditionModifier;
31*b1cdbd2cSJim Jagielski     class ConditionWaiter;
32*b1cdbd2cSJim Jagielski     class ORealDynamicLoader;
33*b1cdbd2cSJim Jagielski     class SimpleReferenceObject;
34*b1cdbd2cSJim Jagielski }
35*b1cdbd2cSJim Jagielski 
36*b1cdbd2cSJim Jagielski namespace {
37*b1cdbd2cSJim Jagielski 
getConditionTypeInfo()38*b1cdbd2cSJim Jagielski std::type_info const & getConditionTypeInfo()
39*b1cdbd2cSJim Jagielski { return typeid (salhelper::Condition *); }
40*b1cdbd2cSJim Jagielski 
getConditionModifierTypeInfo()41*b1cdbd2cSJim Jagielski std::type_info const & getConditionModifierTypeInfo()
42*b1cdbd2cSJim Jagielski { return typeid (salhelper::ConditionModifier *); }
43*b1cdbd2cSJim Jagielski 
getConditionWaiterTypeInfo()44*b1cdbd2cSJim Jagielski std::type_info const & getConditionWaiterTypeInfo()
45*b1cdbd2cSJim Jagielski { return typeid (salhelper::ConditionWaiter *); }
46*b1cdbd2cSJim Jagielski 
getORealDynamicLoaderTypeInfo()47*b1cdbd2cSJim Jagielski std::type_info const & getORealDynamicLoaderTypeInfo()
48*b1cdbd2cSJim Jagielski { return typeid (salhelper::ORealDynamicLoader *); }
49*b1cdbd2cSJim Jagielski 
getSimpleReferenceObjectTypeInfo()50*b1cdbd2cSJim Jagielski std::type_info const & getSimpleReferenceObjectTypeInfo()
51*b1cdbd2cSJim Jagielski { return typeid (salhelper::SimpleReferenceObject *); }
52*b1cdbd2cSJim Jagielski 
53*b1cdbd2cSJim Jagielski }
54*b1cdbd2cSJim Jagielski 
55*b1cdbd2cSJim Jagielski #include "testshl/simpleheader.hxx"
56*b1cdbd2cSJim Jagielski #include "osl/mutex.hxx"
57*b1cdbd2cSJim Jagielski #include "salhelper/condition.hxx"
58*b1cdbd2cSJim Jagielski #include "salhelper/dynload.hxx"
59*b1cdbd2cSJim Jagielski #include "salhelper/simplereferenceobject.hxx"
60*b1cdbd2cSJim Jagielski 
61*b1cdbd2cSJim Jagielski #include <memory>
62*b1cdbd2cSJim Jagielski 
63*b1cdbd2cSJim Jagielski namespace {
64*b1cdbd2cSJim Jagielski 
65*b1cdbd2cSJim Jagielski class DerivedCondition: public salhelper::Condition {
66*b1cdbd2cSJim Jagielski public:
DerivedCondition(osl::Mutex & mutex)67*b1cdbd2cSJim Jagielski     explicit DerivedCondition(osl::Mutex & mutex): Condition(mutex) {}
68*b1cdbd2cSJim Jagielski 
69*b1cdbd2cSJim Jagielski protected:
applies() const70*b1cdbd2cSJim Jagielski     virtual bool applies() const { return false; }
71*b1cdbd2cSJim Jagielski };
72*b1cdbd2cSJim Jagielski 
73*b1cdbd2cSJim Jagielski class DerivedConditionWaiterTimedout:
74*b1cdbd2cSJim Jagielski     public salhelper::ConditionWaiter::timedout
75*b1cdbd2cSJim Jagielski {};
76*b1cdbd2cSJim Jagielski 
77*b1cdbd2cSJim Jagielski class DerivedSimpleReferenceObject: public salhelper::SimpleReferenceObject {};
78*b1cdbd2cSJim Jagielski 
79*b1cdbd2cSJim Jagielski class Test: public CppUnit::TestFixture {
80*b1cdbd2cSJim Jagielski public:
81*b1cdbd2cSJim Jagielski     void testCondition();
82*b1cdbd2cSJim Jagielski 
83*b1cdbd2cSJim Jagielski     void testConditionModifier();
84*b1cdbd2cSJim Jagielski 
85*b1cdbd2cSJim Jagielski     void testConditionWaiter();
86*b1cdbd2cSJim Jagielski 
87*b1cdbd2cSJim Jagielski     void testConditionWaiterTimedout();
88*b1cdbd2cSJim Jagielski 
89*b1cdbd2cSJim Jagielski     void testORealDynamicLoader();
90*b1cdbd2cSJim Jagielski 
91*b1cdbd2cSJim Jagielski     void testSimpleReferenceObject();
92*b1cdbd2cSJim Jagielski 
93*b1cdbd2cSJim Jagielski     void testDerivedCondition();
94*b1cdbd2cSJim Jagielski 
95*b1cdbd2cSJim Jagielski     void testDerivedConditionWaiterTimedout();
96*b1cdbd2cSJim Jagielski 
97*b1cdbd2cSJim Jagielski     void testDerivedSimpleReferenceObject();
98*b1cdbd2cSJim Jagielski 
99*b1cdbd2cSJim Jagielski     CPPUNIT_TEST_SUITE(Test);
100*b1cdbd2cSJim Jagielski     CPPUNIT_TEST(testCondition);
101*b1cdbd2cSJim Jagielski     CPPUNIT_TEST(testConditionModifier);
102*b1cdbd2cSJim Jagielski     CPPUNIT_TEST(testConditionWaiter);
103*b1cdbd2cSJim Jagielski     CPPUNIT_TEST(testConditionWaiterTimedout);
104*b1cdbd2cSJim Jagielski     CPPUNIT_TEST(testORealDynamicLoader);
105*b1cdbd2cSJim Jagielski     CPPUNIT_TEST(testSimpleReferenceObject);
106*b1cdbd2cSJim Jagielski     CPPUNIT_TEST(testDerivedCondition);
107*b1cdbd2cSJim Jagielski     CPPUNIT_TEST(testDerivedConditionWaiterTimedout);
108*b1cdbd2cSJim Jagielski     CPPUNIT_TEST(testDerivedSimpleReferenceObject);
109*b1cdbd2cSJim Jagielski     CPPUNIT_TEST_SUITE_END();
110*b1cdbd2cSJim Jagielski };
111*b1cdbd2cSJim Jagielski 
testCondition()112*b1cdbd2cSJim Jagielski void Test::testCondition() {
113*b1cdbd2cSJim Jagielski     osl::Mutex mutex;
114*b1cdbd2cSJim Jagielski     std::auto_ptr< salhelper::Condition > p(new DerivedCondition(mutex));
115*b1cdbd2cSJim Jagielski     CPPUNIT_ASSERT(typeid (*p.get()) != typeid (salhelper::Condition));
116*b1cdbd2cSJim Jagielski     CPPUNIT_ASSERT(typeid (p.get()) == typeid (salhelper::Condition *));
117*b1cdbd2cSJim Jagielski     CPPUNIT_ASSERT(
118*b1cdbd2cSJim Jagielski         typeid (const_cast< salhelper::Condition const * >(p.get()))
119*b1cdbd2cSJim Jagielski         == typeid (salhelper::Condition const *));
120*b1cdbd2cSJim Jagielski     CPPUNIT_ASSERT(
121*b1cdbd2cSJim Jagielski         typeid (const_cast< salhelper::Condition volatile * >(p.get()))
122*b1cdbd2cSJim Jagielski         == typeid (salhelper::Condition volatile *));
123*b1cdbd2cSJim Jagielski     CPPUNIT_ASSERT(typeid (salhelper::Condition *) == getConditionTypeInfo());
124*b1cdbd2cSJim Jagielski }
125*b1cdbd2cSJim Jagielski 
testConditionModifier()126*b1cdbd2cSJim Jagielski void Test::testConditionModifier() {
127*b1cdbd2cSJim Jagielski     salhelper::ConditionModifier * p = 0;
128*b1cdbd2cSJim Jagielski     CPPUNIT_ASSERT(typeid (*p) == typeid (salhelper::ConditionModifier));
129*b1cdbd2cSJim Jagielski     CPPUNIT_ASSERT(typeid (p) == typeid (salhelper::ConditionModifier *));
130*b1cdbd2cSJim Jagielski     CPPUNIT_ASSERT(
131*b1cdbd2cSJim Jagielski         typeid (const_cast< salhelper::ConditionModifier const * >(p))
132*b1cdbd2cSJim Jagielski         == typeid (salhelper::ConditionModifier const *));
133*b1cdbd2cSJim Jagielski     CPPUNIT_ASSERT(
134*b1cdbd2cSJim Jagielski         typeid (const_cast< salhelper::ConditionModifier volatile * >(p))
135*b1cdbd2cSJim Jagielski         == typeid (salhelper::ConditionModifier volatile *));
136*b1cdbd2cSJim Jagielski     CPPUNIT_ASSERT(
137*b1cdbd2cSJim Jagielski         typeid (salhelper::ConditionModifier *)
138*b1cdbd2cSJim Jagielski         == getConditionModifierTypeInfo());
139*b1cdbd2cSJim Jagielski }
140*b1cdbd2cSJim Jagielski 
testConditionWaiter()141*b1cdbd2cSJim Jagielski void Test::testConditionWaiter() {
142*b1cdbd2cSJim Jagielski     salhelper::ConditionWaiter * p = 0;
143*b1cdbd2cSJim Jagielski     CPPUNIT_ASSERT(typeid (*p) == typeid (salhelper::ConditionWaiter));
144*b1cdbd2cSJim Jagielski     CPPUNIT_ASSERT(typeid (p) == typeid (salhelper::ConditionWaiter *));
145*b1cdbd2cSJim Jagielski     CPPUNIT_ASSERT(
146*b1cdbd2cSJim Jagielski         typeid (const_cast< salhelper::ConditionWaiter const * >(p))
147*b1cdbd2cSJim Jagielski         == typeid (salhelper::ConditionWaiter const *));
148*b1cdbd2cSJim Jagielski     CPPUNIT_ASSERT(
149*b1cdbd2cSJim Jagielski         typeid (const_cast< salhelper::ConditionWaiter volatile * >(p))
150*b1cdbd2cSJim Jagielski         == typeid (salhelper::ConditionWaiter volatile *));
151*b1cdbd2cSJim Jagielski     CPPUNIT_ASSERT(
152*b1cdbd2cSJim Jagielski         typeid (salhelper::ConditionWaiter *) == getConditionWaiterTypeInfo());
153*b1cdbd2cSJim Jagielski }
154*b1cdbd2cSJim Jagielski 
testConditionWaiterTimedout()155*b1cdbd2cSJim Jagielski void Test::testConditionWaiterTimedout() {
156*b1cdbd2cSJim Jagielski     salhelper::ConditionWaiter::timedout x;
157*b1cdbd2cSJim Jagielski     CPPUNIT_ASSERT(typeid (x) == typeid (salhelper::ConditionWaiter::timedout));
158*b1cdbd2cSJim Jagielski     CPPUNIT_ASSERT(
159*b1cdbd2cSJim Jagielski         typeid (&x) == typeid (salhelper::ConditionWaiter::timedout *));
160*b1cdbd2cSJim Jagielski     CPPUNIT_ASSERT(
161*b1cdbd2cSJim Jagielski         typeid (const_cast< salhelper::ConditionWaiter::timedout const * >(&x))
162*b1cdbd2cSJim Jagielski         == typeid (salhelper::ConditionWaiter::timedout const *));
163*b1cdbd2cSJim Jagielski     CPPUNIT_ASSERT(
164*b1cdbd2cSJim Jagielski         (typeid
165*b1cdbd2cSJim Jagielski          (const_cast< salhelper::ConditionWaiter::timedout volatile * >(&x)))
166*b1cdbd2cSJim Jagielski         == typeid (salhelper::ConditionWaiter::timedout volatile *));
167*b1cdbd2cSJim Jagielski     try {
168*b1cdbd2cSJim Jagielski         throw salhelper::ConditionWaiter::timedout();
169*b1cdbd2cSJim Jagielski     } catch (salhelper::ConditionWaiter::timedout &) {
170*b1cdbd2cSJim Jagielski     } catch (...) {
171*b1cdbd2cSJim Jagielski         CPPUNIT_FAIL("not caught");
172*b1cdbd2cSJim Jagielski     }
173*b1cdbd2cSJim Jagielski }
174*b1cdbd2cSJim Jagielski 
testORealDynamicLoader()175*b1cdbd2cSJim Jagielski void Test::testORealDynamicLoader() {
176*b1cdbd2cSJim Jagielski     salhelper::ORealDynamicLoader * p = 0;
177*b1cdbd2cSJim Jagielski     CPPUNIT_ASSERT(typeid (p) != typeid (salhelper::ORealDynamicLoader));
178*b1cdbd2cSJim Jagielski     CPPUNIT_ASSERT(typeid (p) == typeid (salhelper::ORealDynamicLoader *));
179*b1cdbd2cSJim Jagielski     CPPUNIT_ASSERT(
180*b1cdbd2cSJim Jagielski         typeid (const_cast< salhelper::ORealDynamicLoader const * >(p))
181*b1cdbd2cSJim Jagielski         == typeid (salhelper::ORealDynamicLoader const *));
182*b1cdbd2cSJim Jagielski     CPPUNIT_ASSERT(
183*b1cdbd2cSJim Jagielski         typeid (const_cast< salhelper::ORealDynamicLoader volatile * >(p))
184*b1cdbd2cSJim Jagielski         == typeid (salhelper::ORealDynamicLoader volatile *));
185*b1cdbd2cSJim Jagielski     CPPUNIT_ASSERT(
186*b1cdbd2cSJim Jagielski         typeid (salhelper::ORealDynamicLoader *)
187*b1cdbd2cSJim Jagielski         == getORealDynamicLoaderTypeInfo());
188*b1cdbd2cSJim Jagielski }
189*b1cdbd2cSJim Jagielski 
testSimpleReferenceObject()190*b1cdbd2cSJim Jagielski void Test::testSimpleReferenceObject() {
191*b1cdbd2cSJim Jagielski     salhelper::SimpleReferenceObject * p = new DerivedSimpleReferenceObject;
192*b1cdbd2cSJim Jagielski     try {
193*b1cdbd2cSJim Jagielski         CPPUNIT_ASSERT(
194*b1cdbd2cSJim Jagielski             typeid (*p) != typeid (salhelper::SimpleReferenceObject));
195*b1cdbd2cSJim Jagielski         CPPUNIT_ASSERT(
196*b1cdbd2cSJim Jagielski             typeid (p) == typeid (salhelper::SimpleReferenceObject *));
197*b1cdbd2cSJim Jagielski         CPPUNIT_ASSERT(
198*b1cdbd2cSJim Jagielski             typeid (const_cast< salhelper::SimpleReferenceObject const * >(p))
199*b1cdbd2cSJim Jagielski             == typeid (salhelper::SimpleReferenceObject const *));
200*b1cdbd2cSJim Jagielski         CPPUNIT_ASSERT(
201*b1cdbd2cSJim Jagielski             (typeid
202*b1cdbd2cSJim Jagielski              (const_cast< salhelper::SimpleReferenceObject volatile * >(p)))
203*b1cdbd2cSJim Jagielski             == typeid (salhelper::SimpleReferenceObject volatile *));
204*b1cdbd2cSJim Jagielski         CPPUNIT_ASSERT(
205*b1cdbd2cSJim Jagielski             typeid (salhelper::SimpleReferenceObject *)
206*b1cdbd2cSJim Jagielski             == getSimpleReferenceObjectTypeInfo());
207*b1cdbd2cSJim Jagielski     } catch (...) {
208*b1cdbd2cSJim Jagielski         delete static_cast< DerivedSimpleReferenceObject * >(p);
209*b1cdbd2cSJim Jagielski         throw;
210*b1cdbd2cSJim Jagielski     }
211*b1cdbd2cSJim Jagielski }
212*b1cdbd2cSJim Jagielski 
testDerivedCondition()213*b1cdbd2cSJim Jagielski void Test::testDerivedCondition() {
214*b1cdbd2cSJim Jagielski     osl::Mutex mutex;
215*b1cdbd2cSJim Jagielski     std::auto_ptr< salhelper::Condition > p(new DerivedCondition(mutex));
216*b1cdbd2cSJim Jagielski     CPPUNIT_ASSERT(dynamic_cast< DerivedCondition * >(p.get()) != 0);
217*b1cdbd2cSJim Jagielski }
218*b1cdbd2cSJim Jagielski 
testDerivedConditionWaiterTimedout()219*b1cdbd2cSJim Jagielski void Test::testDerivedConditionWaiterTimedout() {
220*b1cdbd2cSJim Jagielski     std::auto_ptr< salhelper::ConditionWaiter::timedout > p(
221*b1cdbd2cSJim Jagielski         new DerivedConditionWaiterTimedout);
222*b1cdbd2cSJim Jagielski     CPPUNIT_ASSERT(
223*b1cdbd2cSJim Jagielski         dynamic_cast< DerivedConditionWaiterTimedout * >(p.get()) != 0);
224*b1cdbd2cSJim Jagielski     try {
225*b1cdbd2cSJim Jagielski         throw DerivedConditionWaiterTimedout();
226*b1cdbd2cSJim Jagielski     } catch (salhelper::ConditionWaiter::timedout &) {
227*b1cdbd2cSJim Jagielski     } catch (...) {
228*b1cdbd2cSJim Jagielski         CPPUNIT_FAIL("not caught");
229*b1cdbd2cSJim Jagielski     }
230*b1cdbd2cSJim Jagielski }
231*b1cdbd2cSJim Jagielski 
testDerivedSimpleReferenceObject()232*b1cdbd2cSJim Jagielski void Test::testDerivedSimpleReferenceObject() {
233*b1cdbd2cSJim Jagielski     salhelper::SimpleReferenceObject * p = new DerivedSimpleReferenceObject;
234*b1cdbd2cSJim Jagielski     try {
235*b1cdbd2cSJim Jagielski         CPPUNIT_ASSERT(dynamic_cast< DerivedSimpleReferenceObject * >(p) != 0);
236*b1cdbd2cSJim Jagielski     } catch (...) {
237*b1cdbd2cSJim Jagielski         delete static_cast< DerivedSimpleReferenceObject * >(p);
238*b1cdbd2cSJim Jagielski         throw;
239*b1cdbd2cSJim Jagielski     }
240*b1cdbd2cSJim Jagielski }
241*b1cdbd2cSJim Jagielski 
242*b1cdbd2cSJim Jagielski CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(Test, "alltests");
243*b1cdbd2cSJim Jagielski 
244*b1cdbd2cSJim Jagielski }
245*b1cdbd2cSJim Jagielski 
246*b1cdbd2cSJim Jagielski NOADDITIONAL;
247