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