Version 4.0.0.1, tag libreoffice-4.0.0.1
[LibreOffice.git] / salhelper / qa / test_api.cxx
blobafddab10c204b4d78a08a7b77740ee2fa97064eb
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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"
22 #include <typeinfo>
24 namespace salhelper {
25 class Condition;
26 class ConditionModifier;
27 class ConditionWaiter;
28 class ORealDynamicLoader;
29 class SimpleReferenceObject;
32 namespace {
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>
60 #include <memory>
62 namespace {
64 class DerivedCondition: public salhelper::Condition {
65 public:
66 explicit DerivedCondition(osl::Mutex & mutex): Condition(mutex) {}
68 protected:
69 virtual bool applies() const { return false; }
72 class DerivedConditionWaiterTimedout:
73 public salhelper::ConditionWaiter::timedout
74 {};
76 class DerivedSimpleReferenceObject: public salhelper::SimpleReferenceObject {};
78 class Test: public CppUnit::TestFixture {
79 public:
80 void testCondition();
82 void testConditionModifier();
84 void testConditionWaiter();
86 void testConditionWaiterTimedout();
88 void testORealDynamicLoader();
90 void testSimpleReferenceObject();
92 void testDerivedCondition();
94 void testDerivedConditionWaiterTimedout();
96 void testDerivedSimpleReferenceObject();
98 CPPUNIT_TEST_SUITE(Test);
99 CPPUNIT_TEST(testCondition);
100 CPPUNIT_TEST(testConditionModifier);
101 CPPUNIT_TEST(testConditionWaiter);
102 CPPUNIT_TEST(testConditionWaiterTimedout);
103 CPPUNIT_TEST(testORealDynamicLoader);
104 CPPUNIT_TEST(testSimpleReferenceObject);
105 CPPUNIT_TEST(testDerivedCondition);
106 CPPUNIT_TEST(testDerivedConditionWaiterTimedout);
107 CPPUNIT_TEST(testDerivedSimpleReferenceObject);
108 CPPUNIT_TEST_SUITE_END();
111 void Test::testCondition() {
112 osl::Mutex mutex;
113 std::auto_ptr< salhelper::Condition > p(new DerivedCondition(mutex));
114 CPPUNIT_ASSERT(typeid (*p.get()) != typeid (salhelper::Condition));
115 CPPUNIT_ASSERT(typeid (p.get()) == typeid (salhelper::Condition *));
116 CPPUNIT_ASSERT(
117 typeid (const_cast< salhelper::Condition const * >(p.get()))
118 == typeid (salhelper::Condition const *));
119 CPPUNIT_ASSERT(
120 typeid (const_cast< salhelper::Condition volatile * >(p.get()))
121 == typeid (salhelper::Condition volatile *));
122 CPPUNIT_ASSERT(typeid (salhelper::Condition *) == getConditionTypeInfo());
125 void Test::testConditionModifier() {
126 salhelper::ConditionModifier * p = 0;
127 CPPUNIT_ASSERT(typeid (*p) == typeid (salhelper::ConditionModifier));
128 CPPUNIT_ASSERT(typeid (p) == typeid (salhelper::ConditionModifier *));
129 CPPUNIT_ASSERT(
130 typeid (const_cast< salhelper::ConditionModifier const * >(p))
131 == typeid (salhelper::ConditionModifier const *));
132 CPPUNIT_ASSERT(
133 typeid (const_cast< salhelper::ConditionModifier volatile * >(p))
134 == typeid (salhelper::ConditionModifier volatile *));
135 CPPUNIT_ASSERT(
136 typeid (salhelper::ConditionModifier *)
137 == getConditionModifierTypeInfo());
140 void Test::testConditionWaiter() {
141 salhelper::ConditionWaiter * p = 0;
142 CPPUNIT_ASSERT(typeid (*p) == typeid (salhelper::ConditionWaiter));
143 CPPUNIT_ASSERT(typeid (p) == typeid (salhelper::ConditionWaiter *));
144 CPPUNIT_ASSERT(
145 typeid (const_cast< salhelper::ConditionWaiter const * >(p))
146 == typeid (salhelper::ConditionWaiter const *));
147 CPPUNIT_ASSERT(
148 typeid (const_cast< salhelper::ConditionWaiter volatile * >(p))
149 == typeid (salhelper::ConditionWaiter volatile *));
150 CPPUNIT_ASSERT(
151 typeid (salhelper::ConditionWaiter *) == getConditionWaiterTypeInfo());
154 void Test::testConditionWaiterTimedout() {
155 salhelper::ConditionWaiter::timedout x;
156 CPPUNIT_ASSERT(typeid (x) == typeid (salhelper::ConditionWaiter::timedout));
157 CPPUNIT_ASSERT(
158 typeid (&x) == typeid (salhelper::ConditionWaiter::timedout *));
159 CPPUNIT_ASSERT(
160 typeid (const_cast< salhelper::ConditionWaiter::timedout const * >(&x))
161 == typeid (salhelper::ConditionWaiter::timedout const *));
162 CPPUNIT_ASSERT(
163 (typeid
164 (const_cast< salhelper::ConditionWaiter::timedout volatile * >(&x)))
165 == typeid (salhelper::ConditionWaiter::timedout volatile *));
166 try {
167 throw salhelper::ConditionWaiter::timedout();
168 } catch (salhelper::ConditionWaiter::timedout &) {
169 } catch (...) {
170 CPPUNIT_FAIL("not caught");
174 void Test::testORealDynamicLoader() {
175 salhelper::ORealDynamicLoader * p = 0;
176 CPPUNIT_ASSERT(typeid (p) != typeid (salhelper::ORealDynamicLoader));
177 CPPUNIT_ASSERT(typeid (p) == typeid (salhelper::ORealDynamicLoader *));
178 CPPUNIT_ASSERT(
179 typeid (const_cast< salhelper::ORealDynamicLoader const * >(p))
180 == typeid (salhelper::ORealDynamicLoader const *));
181 CPPUNIT_ASSERT(
182 typeid (const_cast< salhelper::ORealDynamicLoader volatile * >(p))
183 == typeid (salhelper::ORealDynamicLoader volatile *));
184 CPPUNIT_ASSERT(
185 typeid (salhelper::ORealDynamicLoader *)
186 == getORealDynamicLoaderTypeInfo());
189 void Test::testSimpleReferenceObject() {
190 salhelper::SimpleReferenceObject * p = new DerivedSimpleReferenceObject;
191 try {
192 CPPUNIT_ASSERT(
193 typeid (*p) != typeid (salhelper::SimpleReferenceObject));
194 CPPUNIT_ASSERT(
195 typeid (p) == typeid (salhelper::SimpleReferenceObject *));
196 CPPUNIT_ASSERT(
197 typeid (const_cast< salhelper::SimpleReferenceObject const * >(p))
198 == typeid (salhelper::SimpleReferenceObject const *));
199 CPPUNIT_ASSERT(
200 (typeid
201 (const_cast< salhelper::SimpleReferenceObject volatile * >(p)))
202 == typeid (salhelper::SimpleReferenceObject volatile *));
203 CPPUNIT_ASSERT(
204 typeid (salhelper::SimpleReferenceObject *)
205 == getSimpleReferenceObjectTypeInfo());
206 } catch (...) {
207 delete static_cast< DerivedSimpleReferenceObject * >(p);
208 throw;
212 void Test::testDerivedCondition() {
213 osl::Mutex mutex;
214 boost::scoped_ptr< salhelper::Condition > p(new DerivedCondition(mutex));
215 CPPUNIT_ASSERT(dynamic_cast< DerivedCondition * >(p.get()) != 0);
218 void Test::testDerivedConditionWaiterTimedout() {
219 boost::scoped_ptr< salhelper::ConditionWaiter::timedout > p(
220 new DerivedConditionWaiterTimedout);
221 CPPUNIT_ASSERT(
222 dynamic_cast< DerivedConditionWaiterTimedout * >(p.get()) != 0);
223 try {
224 throw DerivedConditionWaiterTimedout();
225 } catch (salhelper::ConditionWaiter::timedout &) {
226 } catch (...) {
227 CPPUNIT_FAIL("not caught");
231 void Test::testDerivedSimpleReferenceObject() {
232 salhelper::SimpleReferenceObject * p = new DerivedSimpleReferenceObject;
233 try {
234 CPPUNIT_ASSERT(dynamic_cast< DerivedSimpleReferenceObject * >(p) != 0);
235 } catch (...) {
236 delete static_cast< DerivedSimpleReferenceObject * >(p);
237 throw;
241 CPPUNIT_TEST_SUITE_REGISTRATION(Test);
245 CPPUNIT_PLUGIN_IMPLEMENT();
247 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */