update dev300-m58
[ooovba.git] / salhelper / qa / test_api.cxx
blobad66df1367ec0b4a5b25065b98f1206acfcbbf7a
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: test_api.cxx,v $
10 * $Revision: 1.4 $
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"
33 #include <typeinfo>
35 namespace salhelper {
36 class Condition;
37 class ConditionModifier;
38 class ConditionWaiter;
39 class ORealDynamicLoader;
40 class SimpleReferenceObject;
43 namespace {
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"
68 #include <memory>
70 namespace {
72 class DerivedCondition: public salhelper::Condition {
73 public:
74 explicit DerivedCondition(osl::Mutex & mutex): Condition(mutex) {}
76 protected:
77 virtual bool applies() const { return false; }
80 class DerivedConditionWaiterTimedout:
81 public salhelper::ConditionWaiter::timedout
82 {};
84 class DerivedSimpleReferenceObject: public salhelper::SimpleReferenceObject {};
86 class Test: public CppUnit::TestFixture {
87 public:
88 void testCondition();
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() {
120 osl::Mutex mutex;
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 *));
124 CPPUNIT_ASSERT(
125 typeid (const_cast< salhelper::Condition const * >(p.get()))
126 == typeid (salhelper::Condition const *));
127 CPPUNIT_ASSERT(
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 *));
137 CPPUNIT_ASSERT(
138 typeid (const_cast< salhelper::ConditionModifier const * >(p))
139 == typeid (salhelper::ConditionModifier const *));
140 CPPUNIT_ASSERT(
141 typeid (const_cast< salhelper::ConditionModifier volatile * >(p))
142 == typeid (salhelper::ConditionModifier volatile *));
143 CPPUNIT_ASSERT(
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 *));
152 CPPUNIT_ASSERT(
153 typeid (const_cast< salhelper::ConditionWaiter const * >(p))
154 == typeid (salhelper::ConditionWaiter const *));
155 CPPUNIT_ASSERT(
156 typeid (const_cast< salhelper::ConditionWaiter volatile * >(p))
157 == typeid (salhelper::ConditionWaiter volatile *));
158 CPPUNIT_ASSERT(
159 typeid (salhelper::ConditionWaiter *) == getConditionWaiterTypeInfo());
162 void Test::testConditionWaiterTimedout() {
163 salhelper::ConditionWaiter::timedout x;
164 CPPUNIT_ASSERT(typeid (x) == typeid (salhelper::ConditionWaiter::timedout));
165 CPPUNIT_ASSERT(
166 typeid (&x) == typeid (salhelper::ConditionWaiter::timedout *));
167 CPPUNIT_ASSERT(
168 typeid (const_cast< salhelper::ConditionWaiter::timedout const * >(&x))
169 == typeid (salhelper::ConditionWaiter::timedout const *));
170 CPPUNIT_ASSERT(
171 (typeid
172 (const_cast< salhelper::ConditionWaiter::timedout volatile * >(&x)))
173 == typeid (salhelper::ConditionWaiter::timedout volatile *));
174 try {
175 throw salhelper::ConditionWaiter::timedout();
176 } catch (salhelper::ConditionWaiter::timedout &) {
177 } catch (...) {
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 *));
186 CPPUNIT_ASSERT(
187 typeid (const_cast< salhelper::ORealDynamicLoader const * >(p))
188 == typeid (salhelper::ORealDynamicLoader const *));
189 CPPUNIT_ASSERT(
190 typeid (const_cast< salhelper::ORealDynamicLoader volatile * >(p))
191 == typeid (salhelper::ORealDynamicLoader volatile *));
192 CPPUNIT_ASSERT(
193 typeid (salhelper::ORealDynamicLoader *)
194 == getORealDynamicLoaderTypeInfo());
197 void Test::testSimpleReferenceObject() {
198 salhelper::SimpleReferenceObject * p = new DerivedSimpleReferenceObject;
199 try {
200 CPPUNIT_ASSERT(
201 typeid (*p) != typeid (salhelper::SimpleReferenceObject));
202 CPPUNIT_ASSERT(
203 typeid (p) == typeid (salhelper::SimpleReferenceObject *));
204 CPPUNIT_ASSERT(
205 typeid (const_cast< salhelper::SimpleReferenceObject const * >(p))
206 == typeid (salhelper::SimpleReferenceObject const *));
207 CPPUNIT_ASSERT(
208 (typeid
209 (const_cast< salhelper::SimpleReferenceObject volatile * >(p)))
210 == typeid (salhelper::SimpleReferenceObject volatile *));
211 CPPUNIT_ASSERT(
212 typeid (salhelper::SimpleReferenceObject *)
213 == getSimpleReferenceObjectTypeInfo());
214 } catch (...) {
215 delete static_cast< DerivedSimpleReferenceObject * >(p);
216 throw;
220 void Test::testDerivedCondition() {
221 osl::Mutex mutex;
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);
229 CPPUNIT_ASSERT(
230 dynamic_cast< DerivedConditionWaiterTimedout * >(p.get()) != 0);
231 try {
232 throw DerivedConditionWaiterTimedout();
233 } catch (salhelper::ConditionWaiter::timedout &) {
234 } catch (...) {
235 CPPUNIT_FAIL("not caught");
239 void Test::testDerivedSimpleReferenceObject() {
240 salhelper::SimpleReferenceObject * p = new DerivedSimpleReferenceObject;
241 try {
242 CPPUNIT_ASSERT(dynamic_cast< DerivedSimpleReferenceObject * >(p) != 0);
243 } catch (...) {
244 delete static_cast< DerivedSimpleReferenceObject * >(p);
245 throw;
249 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(Test, "alltests");
253 NOADDITIONAL;