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 : namespace {
61 :
62 4 : class DerivedCondition: public salhelper::Condition {
63 : public:
64 2 : explicit DerivedCondition(osl::Mutex & mutex): Condition(mutex) {}
65 :
66 : protected:
67 0 : virtual bool applies() const SAL_OVERRIDE { return false; }
68 : };
69 :
70 5 : class DerivedConditionWaiterTimedout:
71 : public salhelper::ConditionWaiter::timedout
72 : {};
73 :
74 6 : class DerivedSimpleReferenceObject: public salhelper::SimpleReferenceObject {};
75 :
76 27 : class Test: public CppUnit::TestFixture {
77 : public:
78 : void testCondition();
79 :
80 : void testConditionModifier();
81 :
82 : void testConditionWaiter();
83 :
84 : void testConditionWaiterTimedout();
85 :
86 : void testORealDynamicLoader();
87 :
88 : void testSimpleReferenceObject();
89 :
90 : void testDerivedCondition();
91 :
92 : void testDerivedConditionWaiterTimedout();
93 :
94 : void testDerivedSimpleReferenceObject();
95 :
96 2 : CPPUNIT_TEST_SUITE(Test);
97 1 : CPPUNIT_TEST(testCondition);
98 1 : CPPUNIT_TEST(testConditionModifier);
99 1 : CPPUNIT_TEST(testConditionWaiter);
100 1 : CPPUNIT_TEST(testConditionWaiterTimedout);
101 1 : CPPUNIT_TEST(testORealDynamicLoader);
102 1 : CPPUNIT_TEST(testSimpleReferenceObject);
103 1 : CPPUNIT_TEST(testDerivedCondition);
104 1 : CPPUNIT_TEST(testDerivedConditionWaiterTimedout);
105 1 : CPPUNIT_TEST(testDerivedSimpleReferenceObject);
106 2 : CPPUNIT_TEST_SUITE_END();
107 : };
108 :
109 1 : void Test::testCondition() {
110 1 : osl::Mutex mutex;
111 2 : boost::scoped_ptr< salhelper::Condition > p(new DerivedCondition(mutex));
112 1 : CPPUNIT_ASSERT(typeid (*p.get()) != typeid (salhelper::Condition));
113 1 : CPPUNIT_ASSERT(typeid (p.get()) == typeid (salhelper::Condition *));
114 2 : CPPUNIT_ASSERT(
115 : typeid (const_cast< salhelper::Condition const * >(p.get()))
116 1 : == typeid (salhelper::Condition const *));
117 2 : CPPUNIT_ASSERT(
118 : typeid (const_cast< salhelper::Condition volatile * >(p.get()))
119 1 : == typeid (salhelper::Condition volatile *));
120 2 : CPPUNIT_ASSERT(typeid (salhelper::Condition *) == getConditionTypeInfo());
121 1 : }
122 :
123 1 : void Test::testConditionModifier() {
124 1 : salhelper::ConditionModifier * p = 0;
125 1 : CPPUNIT_ASSERT(typeid (*p) == typeid (salhelper::ConditionModifier));
126 1 : CPPUNIT_ASSERT(typeid (p) == typeid (salhelper::ConditionModifier *));
127 2 : CPPUNIT_ASSERT(
128 : typeid (const_cast< salhelper::ConditionModifier const * >(p))
129 1 : == typeid (salhelper::ConditionModifier const *));
130 2 : CPPUNIT_ASSERT(
131 : typeid (const_cast< salhelper::ConditionModifier volatile * >(p))
132 1 : == typeid (salhelper::ConditionModifier volatile *));
133 2 : CPPUNIT_ASSERT(
134 : typeid (salhelper::ConditionModifier *)
135 1 : == getConditionModifierTypeInfo());
136 1 : }
137 :
138 1 : void Test::testConditionWaiter() {
139 1 : salhelper::ConditionWaiter * p = 0;
140 1 : CPPUNIT_ASSERT(typeid (*p) == typeid (salhelper::ConditionWaiter));
141 1 : CPPUNIT_ASSERT(typeid (p) == typeid (salhelper::ConditionWaiter *));
142 2 : CPPUNIT_ASSERT(
143 : typeid (const_cast< salhelper::ConditionWaiter const * >(p))
144 1 : == typeid (salhelper::ConditionWaiter const *));
145 2 : CPPUNIT_ASSERT(
146 : typeid (const_cast< salhelper::ConditionWaiter volatile * >(p))
147 1 : == typeid (salhelper::ConditionWaiter volatile *));
148 2 : CPPUNIT_ASSERT(
149 1 : typeid (salhelper::ConditionWaiter *) == getConditionWaiterTypeInfo());
150 1 : }
151 :
152 1 : void Test::testConditionWaiterTimedout() {
153 1 : salhelper::ConditionWaiter::timedout x;
154 1 : CPPUNIT_ASSERT(typeid (x) == typeid (salhelper::ConditionWaiter::timedout));
155 2 : CPPUNIT_ASSERT(
156 1 : typeid (&x) == typeid (salhelper::ConditionWaiter::timedout *));
157 2 : CPPUNIT_ASSERT(
158 : typeid (const_cast< salhelper::ConditionWaiter::timedout const * >(&x))
159 1 : == typeid (salhelper::ConditionWaiter::timedout const *));
160 2 : CPPUNIT_ASSERT(
161 : (typeid
162 : (const_cast< salhelper::ConditionWaiter::timedout volatile * >(&x)))
163 1 : == typeid (salhelper::ConditionWaiter::timedout volatile *));
164 : try {
165 1 : throw salhelper::ConditionWaiter::timedout();
166 1 : } catch (salhelper::ConditionWaiter::timedout &) {
167 0 : } catch (...) {
168 0 : CPPUNIT_FAIL("not caught");
169 1 : }
170 1 : }
171 :
172 1 : void Test::testORealDynamicLoader() {
173 1 : salhelper::ORealDynamicLoader * p = 0;
174 1 : CPPUNIT_ASSERT(typeid (p) != typeid (salhelper::ORealDynamicLoader));
175 1 : CPPUNIT_ASSERT(typeid (p) == typeid (salhelper::ORealDynamicLoader *));
176 2 : CPPUNIT_ASSERT(
177 : typeid (const_cast< salhelper::ORealDynamicLoader const * >(p))
178 1 : == typeid (salhelper::ORealDynamicLoader const *));
179 2 : CPPUNIT_ASSERT(
180 : typeid (const_cast< salhelper::ORealDynamicLoader volatile * >(p))
181 1 : == typeid (salhelper::ORealDynamicLoader volatile *));
182 2 : CPPUNIT_ASSERT(
183 : typeid (salhelper::ORealDynamicLoader *)
184 1 : == getORealDynamicLoaderTypeInfo());
185 1 : }
186 :
187 1 : void Test::testSimpleReferenceObject() {
188 1 : salhelper::SimpleReferenceObject * p = new DerivedSimpleReferenceObject;
189 : try {
190 2 : CPPUNIT_ASSERT(
191 1 : typeid (*p) != typeid (salhelper::SimpleReferenceObject));
192 2 : CPPUNIT_ASSERT(
193 1 : typeid (p) == typeid (salhelper::SimpleReferenceObject *));
194 2 : CPPUNIT_ASSERT(
195 : typeid (const_cast< salhelper::SimpleReferenceObject const * >(p))
196 1 : == typeid (salhelper::SimpleReferenceObject const *));
197 2 : CPPUNIT_ASSERT(
198 : (typeid
199 : (const_cast< salhelper::SimpleReferenceObject volatile * >(p)))
200 1 : == typeid (salhelper::SimpleReferenceObject volatile *));
201 2 : CPPUNIT_ASSERT(
202 : typeid (salhelper::SimpleReferenceObject *)
203 1 : == getSimpleReferenceObjectTypeInfo());
204 0 : } catch (...) {
205 0 : delete static_cast< DerivedSimpleReferenceObject * >(p);
206 0 : throw;
207 : }
208 1 : delete static_cast< DerivedSimpleReferenceObject * >(p);
209 1 : }
210 :
211 1 : void Test::testDerivedCondition() {
212 1 : osl::Mutex mutex;
213 2 : boost::scoped_ptr< salhelper::Condition > p(new DerivedCondition(mutex));
214 2 : CPPUNIT_ASSERT(dynamic_cast< DerivedCondition * >(p.get()) != 0);
215 1 : }
216 :
217 1 : void Test::testDerivedConditionWaiterTimedout() {
218 : boost::scoped_ptr< salhelper::ConditionWaiter::timedout > p(
219 1 : new DerivedConditionWaiterTimedout);
220 2 : CPPUNIT_ASSERT(
221 1 : dynamic_cast< DerivedConditionWaiterTimedout * >(p.get()) != 0);
222 : try {
223 1 : throw DerivedConditionWaiterTimedout();
224 1 : } catch (salhelper::ConditionWaiter::timedout &) {
225 0 : } catch (...) {
226 0 : CPPUNIT_FAIL("not caught");
227 1 : }
228 1 : }
229 :
230 1 : void Test::testDerivedSimpleReferenceObject() {
231 1 : salhelper::SimpleReferenceObject * p = new DerivedSimpleReferenceObject;
232 : try {
233 1 : CPPUNIT_ASSERT(dynamic_cast< DerivedSimpleReferenceObject * >(p) != 0);
234 0 : } catch (...) {
235 0 : delete static_cast< DerivedSimpleReferenceObject * >(p);
236 0 : throw;
237 : }
238 1 : delete static_cast< DerivedSimpleReferenceObject * >(p);
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: */
|