1129fa3d1SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3129fa3d1SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4129fa3d1SAndrew Rist * or more contributor license agreements. See the NOTICE file 5129fa3d1SAndrew Rist * distributed with this work for additional information 6129fa3d1SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7129fa3d1SAndrew Rist * to you under the Apache License, Version 2.0 (the 8129fa3d1SAndrew Rist * "License"); you may not use this file except in compliance 9129fa3d1SAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 11129fa3d1SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 13129fa3d1SAndrew Rist * Unless required by applicable law or agreed to in writing, 14129fa3d1SAndrew Rist * software distributed under the License is distributed on an 15129fa3d1SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16129fa3d1SAndrew Rist * KIND, either express or implied. See the License for the 17129fa3d1SAndrew Rist * specific language governing permissions and limitations 18129fa3d1SAndrew Rist * under the License. 19cdf0e10cSrcweir * 20129fa3d1SAndrew Rist *************************************************************/ 21129fa3d1SAndrew Rist 22129fa3d1SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 25cdf0e10cSrcweir #include "precompiled_cppu.hxx" 26cdf0e10cSrcweir 27cdf0e10cSrcweir #include "sal/config.h" 28cdf0e10cSrcweir 29cdf0e10cSrcweir #include "Interface1.hpp" 30cdf0e10cSrcweir 31cdf0e10cSrcweir #include "rtl/ustring.hxx" 32cdf0e10cSrcweir #include "sal/types.h" 33*4ad76906SDamjan Jovanovic #include "gtest/gtest.h" 34cdf0e10cSrcweir 35cdf0e10cSrcweir namespace 36cdf0e10cSrcweir { 37cdf0e10cSrcweir 38cdf0e10cSrcweir using ::com::sun::star::uno::Type; 39cdf0e10cSrcweir using ::com::sun::star::uno::Any; 40cdf0e10cSrcweir using ::com::sun::star::uno::Reference; 41cdf0e10cSrcweir using ::com::sun::star::uno::RuntimeException; 42cdf0e10cSrcweir using ::com::sun::star::uno::UNO_SET_THROW; 43cdf0e10cSrcweir 44cdf0e10cSrcweir class Foo: public Interface1 45cdf0e10cSrcweir { 46cdf0e10cSrcweir public: 47cdf0e10cSrcweir Foo() 48cdf0e10cSrcweir :m_refCount(0) 49cdf0e10cSrcweir { 50cdf0e10cSrcweir } 51cdf0e10cSrcweir 52cdf0e10cSrcweir virtual Any SAL_CALL queryInterface(const Type & _type) 53cdf0e10cSrcweir throw (RuntimeException) 54cdf0e10cSrcweir { 55cdf0e10cSrcweir Any aInterface; 56cdf0e10cSrcweir if (_type == getCppuType< Reference< XInterface > >()) 57cdf0e10cSrcweir { 58cdf0e10cSrcweir Reference< XInterface > ref( static_cast< XInterface * >( this ) ); 59cdf0e10cSrcweir aInterface.setValue( &ref, _type ); 60cdf0e10cSrcweir } 61cdf0e10cSrcweir else if (_type == getCppuType< Reference< Interface1 > >()) 62cdf0e10cSrcweir { 63cdf0e10cSrcweir Reference< Interface1 > ref( this ); 64cdf0e10cSrcweir aInterface.setValue( &ref, _type ); 65cdf0e10cSrcweir } 66cdf0e10cSrcweir 67cdf0e10cSrcweir return Any(); 68cdf0e10cSrcweir } 69cdf0e10cSrcweir 70cdf0e10cSrcweir virtual void SAL_CALL acquire() throw () 71cdf0e10cSrcweir { 72cdf0e10cSrcweir osl_incrementInterlockedCount( &m_refCount ); 73cdf0e10cSrcweir } 74cdf0e10cSrcweir 75cdf0e10cSrcweir virtual void SAL_CALL release() throw () 76cdf0e10cSrcweir { 77cdf0e10cSrcweir if ( 0 == osl_decrementInterlockedCount( &m_refCount ) ) 78cdf0e10cSrcweir delete this; 79cdf0e10cSrcweir } 80cdf0e10cSrcweir 81cdf0e10cSrcweir protected: 82cdf0e10cSrcweir virtual ~Foo() 83cdf0e10cSrcweir { 84cdf0e10cSrcweir } 85cdf0e10cSrcweir 86cdf0e10cSrcweir private: 87cdf0e10cSrcweir Foo(Foo &); // not declared 88cdf0e10cSrcweir Foo& operator =(const Foo&); // not declared 89cdf0e10cSrcweir 90cdf0e10cSrcweir private: 91cdf0e10cSrcweir oslInterlockedCount m_refCount; 92cdf0e10cSrcweir }; 93cdf0e10cSrcweir 94*4ad76906SDamjan Jovanovic class Test: public ::testing::Test 95cdf0e10cSrcweir { 96cdf0e10cSrcweir 97cdf0e10cSrcweir public: 98cdf0e10cSrcweir }; 99cdf0e10cSrcweir 100*4ad76906SDamjan Jovanovic TEST_F(Test, testUnoSetThrow) 101cdf0e10cSrcweir { 102cdf0e10cSrcweir Reference< Interface1 > xNull; 103cdf0e10cSrcweir Reference< Interface1 > xFoo( new Foo ); 104cdf0e10cSrcweir 105cdf0e10cSrcweir // ctor taking Reference< interface_type > 106cdf0e10cSrcweir bool bCaughtException = false; 107cdf0e10cSrcweir try { Reference< Interface1 > x( xNull, UNO_SET_THROW ); (void)x; } catch( const RuntimeException& ) { bCaughtException = true; } 108*4ad76906SDamjan Jovanovic ASSERT_EQ( true, bCaughtException ); 109cdf0e10cSrcweir 110cdf0e10cSrcweir bCaughtException = false; 111cdf0e10cSrcweir try { Reference< Interface1 > x( xFoo, UNO_SET_THROW ); (void)x; } catch( const RuntimeException& ) { bCaughtException = true; } 112*4ad76906SDamjan Jovanovic ASSERT_EQ( false, bCaughtException ); 113cdf0e10cSrcweir 114cdf0e10cSrcweir // ctor taking interface_type* 115cdf0e10cSrcweir bCaughtException = false; 116cdf0e10cSrcweir try { Reference< Interface1 > x( xNull.get(), UNO_SET_THROW ); (void)x; } catch( const RuntimeException& ) { bCaughtException = true; } 117*4ad76906SDamjan Jovanovic ASSERT_EQ( true, bCaughtException ); 118cdf0e10cSrcweir 119cdf0e10cSrcweir bCaughtException = false; 120cdf0e10cSrcweir try { Reference< Interface1 > x( xFoo.get(), UNO_SET_THROW ); (void)x; } catch( const RuntimeException& ) { bCaughtException = true; } 121*4ad76906SDamjan Jovanovic ASSERT_EQ( false, bCaughtException ); 122cdf0e10cSrcweir 123cdf0e10cSrcweir Reference< Interface1 > x; 124cdf0e10cSrcweir // "set" taking Reference< interface_type > 125cdf0e10cSrcweir bCaughtException = false; 126cdf0e10cSrcweir try { x.set( xNull, UNO_SET_THROW ); } catch( const RuntimeException& ) { bCaughtException = true; } 127*4ad76906SDamjan Jovanovic ASSERT_EQ( true, bCaughtException ); 128cdf0e10cSrcweir 129cdf0e10cSrcweir bCaughtException = false; 130cdf0e10cSrcweir try { x.set( xFoo, UNO_SET_THROW ); } catch( const RuntimeException& ) { bCaughtException = true; } 131*4ad76906SDamjan Jovanovic ASSERT_EQ( false, bCaughtException ); 132cdf0e10cSrcweir 133cdf0e10cSrcweir // "set" taking interface_type* 134cdf0e10cSrcweir bCaughtException = false; 135cdf0e10cSrcweir try { x.set( xNull.get(), UNO_SET_THROW ); } catch( const RuntimeException& ) { bCaughtException = true; } 136*4ad76906SDamjan Jovanovic ASSERT_EQ( true, bCaughtException ); 137cdf0e10cSrcweir 138cdf0e10cSrcweir bCaughtException = false; 139cdf0e10cSrcweir try { x.set( xFoo.get(), UNO_SET_THROW ); } catch( const RuntimeException& ) { bCaughtException = true; } 140*4ad76906SDamjan Jovanovic ASSERT_EQ( false, bCaughtException ); 141cdf0e10cSrcweir } 142cdf0e10cSrcweir 143cdf0e10cSrcweir } // namespace 144