1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 #include "sal/config.h" 29 30 #include <typeinfo> 31 32 namespace salhelper { 33 class Condition; 34 class ConditionModifier; 35 class ConditionWaiter; 36 class ORealDynamicLoader; 37 class SimpleReferenceObject; 38 } 39 40 namespace { 41 42 std::type_info const & getConditionTypeInfo() 43 { return typeid (salhelper::Condition *); } 44 45 std::type_info const & getConditionModifierTypeInfo() 46 { return typeid (salhelper::ConditionModifier *); } 47 48 std::type_info const & getConditionWaiterTypeInfo() 49 { return typeid (salhelper::ConditionWaiter *); } 50 51 std::type_info const & getORealDynamicLoaderTypeInfo() 52 { return typeid (salhelper::ORealDynamicLoader *); } 53 54 std::type_info const & getSimpleReferenceObjectTypeInfo() 55 { return typeid (salhelper::SimpleReferenceObject *); } 56 57 } 58 59 #include "testshl/simpleheader.hxx" 60 #include "osl/mutex.hxx" 61 #include "salhelper/condition.hxx" 62 #include "salhelper/dynload.hxx" 63 #include "salhelper/simplereferenceobject.hxx" 64 65 #include <memory> 66 67 namespace { 68 69 class DerivedCondition: public salhelper::Condition { 70 public: 71 explicit DerivedCondition(osl::Mutex & mutex): Condition(mutex) {} 72 73 protected: 74 virtual bool applies() const { return false; } 75 }; 76 77 class DerivedConditionWaiterTimedout: 78 public salhelper::ConditionWaiter::timedout 79 {}; 80 81 class DerivedSimpleReferenceObject: public salhelper::SimpleReferenceObject {}; 82 83 class Test: public CppUnit::TestFixture { 84 public: 85 void testCondition(); 86 87 void testConditionModifier(); 88 89 void testConditionWaiter(); 90 91 void testConditionWaiterTimedout(); 92 93 void testORealDynamicLoader(); 94 95 void testSimpleReferenceObject(); 96 97 void testDerivedCondition(); 98 99 void testDerivedConditionWaiterTimedout(); 100 101 void testDerivedSimpleReferenceObject(); 102 103 CPPUNIT_TEST_SUITE(Test); 104 CPPUNIT_TEST(testCondition); 105 CPPUNIT_TEST(testConditionModifier); 106 CPPUNIT_TEST(testConditionWaiter); 107 CPPUNIT_TEST(testConditionWaiterTimedout); 108 CPPUNIT_TEST(testORealDynamicLoader); 109 CPPUNIT_TEST(testSimpleReferenceObject); 110 CPPUNIT_TEST(testDerivedCondition); 111 CPPUNIT_TEST(testDerivedConditionWaiterTimedout); 112 CPPUNIT_TEST(testDerivedSimpleReferenceObject); 113 CPPUNIT_TEST_SUITE_END(); 114 }; 115 116 void Test::testCondition() { 117 osl::Mutex mutex; 118 std::auto_ptr< salhelper::Condition > p(new DerivedCondition(mutex)); 119 CPPUNIT_ASSERT(typeid (*p.get()) != typeid (salhelper::Condition)); 120 CPPUNIT_ASSERT(typeid (p.get()) == typeid (salhelper::Condition *)); 121 CPPUNIT_ASSERT( 122 typeid (const_cast< salhelper::Condition const * >(p.get())) 123 == typeid (salhelper::Condition const *)); 124 CPPUNIT_ASSERT( 125 typeid (const_cast< salhelper::Condition volatile * >(p.get())) 126 == typeid (salhelper::Condition volatile *)); 127 CPPUNIT_ASSERT(typeid (salhelper::Condition *) == getConditionTypeInfo()); 128 } 129 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 *)); 134 CPPUNIT_ASSERT( 135 typeid (const_cast< salhelper::ConditionModifier const * >(p)) 136 == typeid (salhelper::ConditionModifier const *)); 137 CPPUNIT_ASSERT( 138 typeid (const_cast< salhelper::ConditionModifier volatile * >(p)) 139 == typeid (salhelper::ConditionModifier volatile *)); 140 CPPUNIT_ASSERT( 141 typeid (salhelper::ConditionModifier *) 142 == getConditionModifierTypeInfo()); 143 } 144 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 *)); 149 CPPUNIT_ASSERT( 150 typeid (const_cast< salhelper::ConditionWaiter const * >(p)) 151 == typeid (salhelper::ConditionWaiter const *)); 152 CPPUNIT_ASSERT( 153 typeid (const_cast< salhelper::ConditionWaiter volatile * >(p)) 154 == typeid (salhelper::ConditionWaiter volatile *)); 155 CPPUNIT_ASSERT( 156 typeid (salhelper::ConditionWaiter *) == getConditionWaiterTypeInfo()); 157 } 158 159 void Test::testConditionWaiterTimedout() { 160 salhelper::ConditionWaiter::timedout x; 161 CPPUNIT_ASSERT(typeid (x) == typeid (salhelper::ConditionWaiter::timedout)); 162 CPPUNIT_ASSERT( 163 typeid (&x) == typeid (salhelper::ConditionWaiter::timedout *)); 164 CPPUNIT_ASSERT( 165 typeid (const_cast< salhelper::ConditionWaiter::timedout const * >(&x)) 166 == typeid (salhelper::ConditionWaiter::timedout const *)); 167 CPPUNIT_ASSERT( 168 (typeid 169 (const_cast< salhelper::ConditionWaiter::timedout volatile * >(&x))) 170 == typeid (salhelper::ConditionWaiter::timedout volatile *)); 171 try { 172 throw salhelper::ConditionWaiter::timedout(); 173 } catch (salhelper::ConditionWaiter::timedout &) { 174 } catch (...) { 175 CPPUNIT_FAIL("not caught"); 176 } 177 } 178 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 *)); 183 CPPUNIT_ASSERT( 184 typeid (const_cast< salhelper::ORealDynamicLoader const * >(p)) 185 == typeid (salhelper::ORealDynamicLoader const *)); 186 CPPUNIT_ASSERT( 187 typeid (const_cast< salhelper::ORealDynamicLoader volatile * >(p)) 188 == typeid (salhelper::ORealDynamicLoader volatile *)); 189 CPPUNIT_ASSERT( 190 typeid (salhelper::ORealDynamicLoader *) 191 == getORealDynamicLoaderTypeInfo()); 192 } 193 194 void Test::testSimpleReferenceObject() { 195 salhelper::SimpleReferenceObject * p = new DerivedSimpleReferenceObject; 196 try { 197 CPPUNIT_ASSERT( 198 typeid (*p) != typeid (salhelper::SimpleReferenceObject)); 199 CPPUNIT_ASSERT( 200 typeid (p) == typeid (salhelper::SimpleReferenceObject *)); 201 CPPUNIT_ASSERT( 202 typeid (const_cast< salhelper::SimpleReferenceObject const * >(p)) 203 == typeid (salhelper::SimpleReferenceObject const *)); 204 CPPUNIT_ASSERT( 205 (typeid 206 (const_cast< salhelper::SimpleReferenceObject volatile * >(p))) 207 == typeid (salhelper::SimpleReferenceObject volatile *)); 208 CPPUNIT_ASSERT( 209 typeid (salhelper::SimpleReferenceObject *) 210 == getSimpleReferenceObjectTypeInfo()); 211 } catch (...) { 212 delete static_cast< DerivedSimpleReferenceObject * >(p); 213 throw; 214 } 215 } 216 217 void Test::testDerivedCondition() { 218 osl::Mutex mutex; 219 std::auto_ptr< salhelper::Condition > p(new DerivedCondition(mutex)); 220 CPPUNIT_ASSERT(dynamic_cast< DerivedCondition * >(p.get()) != 0); 221 } 222 223 void Test::testDerivedConditionWaiterTimedout() { 224 std::auto_ptr< salhelper::ConditionWaiter::timedout > p( 225 new DerivedConditionWaiterTimedout); 226 CPPUNIT_ASSERT( 227 dynamic_cast< DerivedConditionWaiterTimedout * >(p.get()) != 0); 228 try { 229 throw DerivedConditionWaiterTimedout(); 230 } catch (salhelper::ConditionWaiter::timedout &) { 231 } catch (...) { 232 CPPUNIT_FAIL("not caught"); 233 } 234 } 235 236 void Test::testDerivedSimpleReferenceObject() { 237 salhelper::SimpleReferenceObject * p = new DerivedSimpleReferenceObject; 238 try { 239 CPPUNIT_ASSERT(dynamic_cast< DerivedSimpleReferenceObject * >(p) != 0); 240 } catch (...) { 241 delete static_cast< DerivedSimpleReferenceObject * >(p); 242 throw; 243 } 244 } 245 246 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(Test, "alltests"); 247 248 } 249 250 NOADDITIONAL; 251