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