1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include "sal/config.h"
26 class ConditionModifier
;
27 class ConditionWaiter
;
28 class ORealDynamicLoader
;
29 class SimpleReferenceObject
;
34 std::type_info
const & getConditionTypeInfo()
35 { return typeid (salhelper::Condition
*); }
37 std::type_info
const & getConditionModifierTypeInfo()
38 { return typeid (salhelper::ConditionModifier
*); }
40 std::type_info
const & getConditionWaiterTypeInfo()
41 { return typeid (salhelper::ConditionWaiter
*); }
43 std::type_info
const & getORealDynamicLoaderTypeInfo()
44 { return typeid (salhelper::ORealDynamicLoader
*); }
46 std::type_info
const & getSimpleReferenceObjectTypeInfo()
47 { return typeid (salhelper::SimpleReferenceObject
*); }
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>
62 class DerivedCondition
: public salhelper::Condition
{
64 explicit DerivedCondition(osl::Mutex
& mutex
): Condition(mutex
) {}
67 virtual bool applies() const SAL_OVERRIDE
{ return false; }
70 class DerivedConditionWaiterTimedout
:
71 public salhelper::ConditionWaiter::timedout
74 class DerivedSimpleReferenceObject
: public salhelper::SimpleReferenceObject
{};
76 class Test
: public CppUnit::TestFixture
{
80 void testConditionModifier();
82 void testConditionWaiter();
84 void testConditionWaiterTimedout();
86 void testORealDynamicLoader();
88 void testSimpleReferenceObject();
90 void testDerivedCondition();
92 void testDerivedConditionWaiterTimedout();
94 void testDerivedSimpleReferenceObject();
96 CPPUNIT_TEST_SUITE(Test
);
97 CPPUNIT_TEST(testCondition
);
98 CPPUNIT_TEST(testConditionModifier
);
99 CPPUNIT_TEST(testConditionWaiter
);
100 CPPUNIT_TEST(testConditionWaiterTimedout
);
101 CPPUNIT_TEST(testORealDynamicLoader
);
102 CPPUNIT_TEST(testSimpleReferenceObject
);
103 CPPUNIT_TEST(testDerivedCondition
);
104 CPPUNIT_TEST(testDerivedConditionWaiterTimedout
);
105 CPPUNIT_TEST(testDerivedSimpleReferenceObject
);
106 CPPUNIT_TEST_SUITE_END();
109 void Test::testCondition() {
111 boost::scoped_ptr
< salhelper::Condition
> p(new DerivedCondition(mutex
));
112 CPPUNIT_ASSERT(typeid (*p
.get()) != typeid (salhelper::Condition
));
113 CPPUNIT_ASSERT(typeid (p
.get()) == typeid (salhelper::Condition
*));
115 typeid (const_cast< salhelper::Condition
const * >(p
.get()))
116 == typeid (salhelper::Condition
const *));
118 typeid (const_cast< salhelper::Condition
volatile * >(p
.get()))
119 == typeid (salhelper::Condition
volatile *));
120 CPPUNIT_ASSERT(typeid (salhelper::Condition
*) == getConditionTypeInfo());
124 // MSVC 2012 warns about the "p" being unused
125 #pragma warning (push, 1)
126 #pragma warning (disable: 4189)
130 void Test::testConditionModifier() {
131 salhelper::ConditionModifier
* p
= 0;
132 CPPUNIT_ASSERT(typeid (*p
) == typeid (salhelper::ConditionModifier
));
133 CPPUNIT_ASSERT(typeid (p
) == typeid (salhelper::ConditionModifier
*));
135 typeid (const_cast< salhelper::ConditionModifier
const * >(p
))
136 == typeid (salhelper::ConditionModifier
const *));
138 typeid (const_cast< salhelper::ConditionModifier
volatile * >(p
))
139 == typeid (salhelper::ConditionModifier
volatile *));
141 typeid (salhelper::ConditionModifier
*)
142 == getConditionModifierTypeInfo());
145 void Test::testConditionWaiter() {
146 salhelper::ConditionWaiter
* p
= 0;
147 CPPUNIT_ASSERT(typeid (*p
) == typeid (salhelper::ConditionWaiter
));
148 CPPUNIT_ASSERT(typeid (p
) == typeid (salhelper::ConditionWaiter
*));
150 typeid (const_cast< salhelper::ConditionWaiter
const * >(p
))
151 == typeid (salhelper::ConditionWaiter
const *));
153 typeid (const_cast< salhelper::ConditionWaiter
volatile * >(p
))
154 == typeid (salhelper::ConditionWaiter
volatile *));
156 typeid (salhelper::ConditionWaiter
*) == getConditionWaiterTypeInfo());
159 void Test::testConditionWaiterTimedout() {
160 salhelper::ConditionWaiter::timedout x
;
161 CPPUNIT_ASSERT(typeid (x
) == typeid (salhelper::ConditionWaiter::timedout
));
163 typeid (&x
) == typeid (salhelper::ConditionWaiter::timedout
*));
165 typeid (const_cast< salhelper::ConditionWaiter::timedout
const * >(&x
))
166 == typeid (salhelper::ConditionWaiter::timedout
const *));
169 (const_cast< salhelper::ConditionWaiter::timedout
volatile * >(&x
)))
170 == typeid (salhelper::ConditionWaiter::timedout
volatile *));
172 throw salhelper::ConditionWaiter::timedout();
173 } catch (salhelper::ConditionWaiter::timedout
&) {
175 CPPUNIT_FAIL("not caught");
179 void Test::testORealDynamicLoader() {
180 salhelper::ORealDynamicLoader
* p
= 0;
181 CPPUNIT_ASSERT(typeid (p
) != typeid (salhelper::ORealDynamicLoader
));
182 CPPUNIT_ASSERT(typeid (p
) == typeid (salhelper::ORealDynamicLoader
*));
184 typeid (const_cast< salhelper::ORealDynamicLoader
const * >(p
))
185 == typeid (salhelper::ORealDynamicLoader
const *));
187 typeid (const_cast< salhelper::ORealDynamicLoader
volatile * >(p
))
188 == typeid (salhelper::ORealDynamicLoader
volatile *));
190 typeid (salhelper::ORealDynamicLoader
*)
191 == getORealDynamicLoaderTypeInfo());
195 #pragma warning (pop)
198 void Test::testSimpleReferenceObject() {
199 salhelper::SimpleReferenceObject
* p
= new DerivedSimpleReferenceObject
;
202 typeid (*p
) != typeid (salhelper::SimpleReferenceObject
));
204 typeid (p
) == typeid (salhelper::SimpleReferenceObject
*));
206 typeid (const_cast< salhelper::SimpleReferenceObject
const * >(p
))
207 == typeid (salhelper::SimpleReferenceObject
const *));
210 (const_cast< salhelper::SimpleReferenceObject
volatile * >(p
)))
211 == typeid (salhelper::SimpleReferenceObject
volatile *));
213 typeid (salhelper::SimpleReferenceObject
*)
214 == getSimpleReferenceObjectTypeInfo());
216 delete static_cast< DerivedSimpleReferenceObject
* >(p
);
219 delete static_cast< DerivedSimpleReferenceObject
* >(p
);
222 void Test::testDerivedCondition() {
224 boost::scoped_ptr
< salhelper::Condition
> p(new DerivedCondition(mutex
));
225 CPPUNIT_ASSERT(dynamic_cast< DerivedCondition
* >(p
.get()) != 0);
228 void Test::testDerivedConditionWaiterTimedout() {
229 boost::scoped_ptr
< salhelper::ConditionWaiter::timedout
> p(
230 new DerivedConditionWaiterTimedout
);
232 dynamic_cast< DerivedConditionWaiterTimedout
* >(p
.get()) != 0);
234 throw DerivedConditionWaiterTimedout();
235 } catch (salhelper::ConditionWaiter::timedout
&) {
237 CPPUNIT_FAIL("not caught");
241 void Test::testDerivedSimpleReferenceObject() {
242 salhelper::SimpleReferenceObject
* p
= new DerivedSimpleReferenceObject
;
244 CPPUNIT_ASSERT(dynamic_cast< DerivedSimpleReferenceObject
* >(p
) != 0);
246 delete static_cast< DerivedSimpleReferenceObject
* >(p
);
249 delete static_cast< DerivedSimpleReferenceObject
* >(p
);
252 CPPUNIT_TEST_SUITE_REGISTRATION(Test
);
256 CPPUNIT_PLUGIN_IMPLEMENT();
258 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */