Branch data 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/types.h>
21 : :
22 : : #include <cppunit/TestSuite.h>
23 : : #include <cppunit/TestFixture.h>
24 : : #include <cppunit/TestCase.h>
25 : : #include <cppunit/plugin/TestPlugIn.h>
26 : : #include <cppunit/extensions/HelperMacros.h>
27 : :
28 : : #include "Interface1.hpp"
29 : :
30 : : #include "rtl/ustring.hxx"
31 : : #include "sal/types.h"
32 : :
33 : : namespace
34 : : {
35 : :
36 : : using ::com::sun::star::uno::Type;
37 : : using ::com::sun::star::uno::Any;
38 : : using ::com::sun::star::uno::Reference;
39 : : using ::com::sun::star::uno::RuntimeException;
40 : : using ::com::sun::star::uno::UNO_SET_THROW;
41 : :
42 : : class Foo: public Interface1
43 : : {
44 : : public:
45 : 5 : Foo()
46 : 5 : :m_refCount(0)
47 : : {
48 : 5 : }
49 : :
50 : 0 : virtual Any SAL_CALL queryInterface(const Type & _type)
51 : : throw (RuntimeException)
52 : : {
53 : 0 : Any aInterface;
54 [ # # ][ # # ]: 0 : if (_type == getCppuType< Reference< XInterface > >())
55 : : {
56 [ # # ]: 0 : Reference< XInterface > ref( static_cast< XInterface * >( this ) );
57 : 0 : aInterface.setValue( &ref, _type );
58 : : }
59 [ # # ][ # # ]: 0 : else if (_type == getCppuType< Reference< Interface1 > >())
60 : : {
61 [ # # ]: 0 : Reference< Interface1 > ref( this );
62 : 0 : aInterface.setValue( &ref, _type );
63 : : }
64 : :
65 : 0 : return Any();
66 : : }
67 : :
68 : 25 : virtual void SAL_CALL acquire() throw ()
69 : : {
70 : 25 : osl_incrementInterlockedCount( &m_refCount );
71 : 25 : }
72 : :
73 : 25 : virtual void SAL_CALL release() throw ()
74 : : {
75 [ + + ]: 25 : if ( 0 == osl_decrementInterlockedCount( &m_refCount ) )
76 [ + - ]: 5 : delete this;
77 : 25 : }
78 : :
79 : : protected:
80 : 10 : virtual ~Foo()
81 : 5 : {
82 [ - + ]: 10 : }
83 : :
84 : : private:
85 : : Foo(Foo &); // not declared
86 : : Foo& operator =(const Foo&); // not declared
87 : :
88 : : private:
89 : : oslInterlockedCount m_refCount;
90 : : };
91 : :
92 [ - + ]: 15 : class Test: public ::CppUnit::TestFixture
93 : : {
94 : :
95 : : public:
96 : : void testUnoSetThrow();
97 : :
98 [ + - ][ + - ]: 10 : CPPUNIT_TEST_SUITE(Test);
[ + - ][ + - ]
[ # # ]
99 [ + - ][ + - ]: 5 : CPPUNIT_TEST(testUnoSetThrow);
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ]
100 [ + - ][ + - ]: 10 : CPPUNIT_TEST_SUITE_END();
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
101 : : };
102 : :
103 : 5 : void Test::testUnoSetThrow()
104 : : {
105 : 5 : Reference< Interface1 > xNull;
106 [ + - ][ + - ]: 5 : Reference< Interface1 > xFoo( new Foo );
107 : :
108 : : // ctor taking Reference< interface_type >
109 : 5 : bool bCaughtException = false;
110 [ - + ][ + - ]: 10 : try { Reference< Interface1 > x( xNull, UNO_SET_THROW ); (void)x; } catch( const RuntimeException& ) { bCaughtException = true; }
111 [ + - ][ + - ]: 5 : CPPUNIT_ASSERT_EQUAL( true, bCaughtException );
[ + - ][ + - ]
[ + - ][ # # ]
112 : :
113 : 5 : bCaughtException = false;
114 [ # # ][ + - ]: 5 : try { Reference< Interface1 > x( xFoo, UNO_SET_THROW ); (void)x; } catch( const RuntimeException& ) { bCaughtException = true; }
115 [ + - ][ + - ]: 10 : CPPUNIT_ASSERT_EQUAL( false, bCaughtException );
[ + - ][ + - ]
[ + - ][ - + ]
116 : :
117 : : // ctor taking interface_type*
118 : 5 : bCaughtException = false;
119 [ - + ][ + - ]: 10 : try { Reference< Interface1 > x( xNull.get(), UNO_SET_THROW ); (void)x; } catch( const RuntimeException& ) { bCaughtException = true; }
[ + - ]
120 [ + - ][ + - ]: 5 : CPPUNIT_ASSERT_EQUAL( true, bCaughtException );
[ + - ][ + - ]
[ + - ][ # # ]
121 : :
122 : 5 : bCaughtException = false;
123 [ + - ][ # # ]: 5 : try { Reference< Interface1 > x( xFoo.get(), UNO_SET_THROW ); (void)x; } catch( const RuntimeException& ) { bCaughtException = true; }
[ + - ]
124 [ + - ][ + - ]: 10 : CPPUNIT_ASSERT_EQUAL( false, bCaughtException );
[ + - ][ + - ]
[ + - ][ - + ]
125 : :
126 : 5 : Reference< Interface1 > x;
127 : : // "set" taking Reference< interface_type >
128 : 5 : bCaughtException = false;
129 [ + - ][ - + ]: 10 : try { x.set( xNull, UNO_SET_THROW ); } catch( const RuntimeException& ) { bCaughtException = true; }
130 [ + - ][ + - ]: 5 : CPPUNIT_ASSERT_EQUAL( true, bCaughtException );
[ + - ][ + - ]
[ + - ][ # # ]
131 : :
132 : 5 : bCaughtException = false;
133 [ + - # # ]: 5 : try { x.set( xFoo, UNO_SET_THROW ); } catch( const RuntimeException& ) { bCaughtException = true; }
134 [ + - ][ + - ]: 10 : CPPUNIT_ASSERT_EQUAL( false, bCaughtException );
[ + - ][ + - ]
[ + - ][ - + ]
135 : :
136 : : // "set" taking interface_type*
137 : 5 : bCaughtException = false;
138 [ - + ][ + - ]: 10 : try { x.set( xNull.get(), UNO_SET_THROW ); } catch( const RuntimeException& ) { bCaughtException = true; }
[ + - ]
139 [ + - ][ + - ]: 5 : CPPUNIT_ASSERT_EQUAL( true, bCaughtException );
[ + - ][ + - ]
[ + - ][ # # ]
140 : :
141 : 5 : bCaughtException = false;
142 [ + - # # ]: 5 : try { x.set( xFoo.get(), UNO_SET_THROW ); } catch( const RuntimeException& ) { bCaughtException = true; }
[ + - ]
143 [ + - ][ + - ]: 5 : CPPUNIT_ASSERT_EQUAL( false, bCaughtException );
[ + - ][ + - ]
[ + - ]
144 [ - + ]: 10 : }
145 : :
146 : 5 : CPPUNIT_TEST_SUITE_REGISTRATION(Test);
147 : :
148 : : } // namespace
149 : :
150 [ + - ][ + - ]: 20 : CPPUNIT_PLUGIN_IMPLEMENT();
[ + - ][ + - ]
[ + - ][ # # ]
151 : :
152 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|