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 #if !defined(OSL_DEBUG_LEVEL) || OSL_DEBUG_LEVEL == 0
21 # undef OSL_DEBUG_LEVEL
22 # define OSL_DEBUG_LEVEL 2
28 #include <cppuhelper/implbase1.hxx>
29 #include <cppuhelper/implbase2.hxx>
30 #include <cppuhelper/implbase3.hxx>
31 #include <cppuhelper/implbase4.hxx>
32 #include <cppuhelper/implbase5.hxx>
33 #include <cppuhelper/implbase6.hxx>
34 #include <cppuhelper/implbase7.hxx>
35 #include <cppuhelper/implbase8.hxx>
36 #include <cppuhelper/implbase9.hxx>
37 #include <cppuhelper/implbase10.hxx>
38 #include <cppuhelper/implbase11.hxx>
39 #include <cppuhelper/implbase12.hxx>
41 #include <cppuhelper/compbase1.hxx>
42 #include <cppuhelper/compbase2.hxx>
43 #include <cppuhelper/compbase3.hxx>
44 #include <cppuhelper/compbase4.hxx>
45 #include <cppuhelper/compbase5.hxx>
46 #include <cppuhelper/compbase6.hxx>
47 #include <cppuhelper/compbase7.hxx>
48 #include <cppuhelper/compbase8.hxx>
49 #include <cppuhelper/compbase9.hxx>
50 #include <cppuhelper/compbase10.hxx>
51 #include <cppuhelper/compbase11.hxx>
52 #include <cppuhelper/compbase12.hxx>
54 #include <osl/diagnose.h>
55 #include <cppuhelper/servicefactory.hxx>
56 #include <cppuhelper/exc_hlp.hxx>
59 #include <test/BA.hpp>
60 #include <test/CA.hpp>
61 #include <test/DBA.hpp>
63 #include <test/FE.hpp>
68 #include <com/sun/star/lang/IllegalAccessException.hpp>
73 using namespace com::sun::star
;
74 using namespace com::sun::star::uno
;
76 using ::rtl::OUString
;
77 using ::rtl::OUStringToOString
;
81 struct TestImpl
: public ImplHelper4
< CA
, DBA
, FE
, G
>
86 { OSL_TRACE( "> TestImpl dtor called... <\n" ); }
88 virtual Any SAL_CALL
queryInterface( const Type
& rType
) throw(RuntimeException
)
89 { return ImplHelper4
< CA
, DBA
, FE
, G
>::queryInterface( rType
); }
90 virtual void SAL_CALL
acquire( ) throw()
92 virtual void SAL_CALL
release( ) throw()
93 { if (! --nRef
) delete this; }
96 virtual OUString SAL_CALL
a() throw(RuntimeException
)
97 { return OUString("a"); }
99 virtual OUString SAL_CALL
ba() throw(RuntimeException
)
100 { return OUString("ba"); }
102 virtual OUString SAL_CALL
ca() throw(RuntimeException
)
103 { return OUString("ca"); }
105 virtual OUString SAL_CALL
dba() throw(RuntimeException
)
106 { return OUString("dba"); }
108 virtual OUString SAL_CALL
e() throw(RuntimeException
)
109 { return OUString("e"); }
111 virtual OUString SAL_CALL
fe() throw(RuntimeException
)
112 { return OUString("fe"); }
114 virtual OUString SAL_CALL
g() throw(RuntimeException
)
115 { return OUString("g"); }
119 struct TestWeakAggImpl
: public WeakAggImplHelper4
< CA
, DBA
, FE
, G
>
121 virtual ~TestWeakAggImpl()
122 { OSL_TRACE( "> TestWeakAggImpl dtor called... <\n" ); }
125 virtual OUString SAL_CALL
a() throw(RuntimeException
)
126 { return OUString("a"); }
128 virtual OUString SAL_CALL
ba() throw(RuntimeException
)
129 { return OUString("ba"); }
131 virtual OUString SAL_CALL
ca() throw(RuntimeException
)
132 { return OUString("ca"); }
134 virtual OUString SAL_CALL
dba() throw(RuntimeException
)
135 { return OUString("dba"); }
137 virtual OUString SAL_CALL
e() throw(RuntimeException
)
138 { return OUString("e"); }
140 virtual OUString SAL_CALL
fe() throw(RuntimeException
)
141 { return OUString("fe"); }
143 virtual OUString SAL_CALL
g() throw(RuntimeException
)
144 { return OUString("g"); }
148 struct TestWeakImpl
: public WeakImplHelper4
< CA
, DBA
, FE
, G
>
152 virtual ~TestWeakImpl()
153 { OSL_TRACE( "> TestWeakImpl dtor called... <\n" ); }
156 virtual OUString SAL_CALL
a() throw(RuntimeException
)
157 { return OUString("a"); }
159 virtual OUString SAL_CALL
ba() throw(RuntimeException
)
160 { return OUString("ba"); }
162 virtual OUString SAL_CALL
ca() throw(RuntimeException
)
163 { return OUString("ca"); }
165 virtual OUString SAL_CALL
dba() throw(RuntimeException
)
166 { return OUString("dba"); }
168 virtual OUString SAL_CALL
e() throw(RuntimeException
)
169 { return OUString("e"); }
171 virtual OUString SAL_CALL
fe() throw(RuntimeException
)
172 { return OUString("fe"); }
174 virtual OUString SAL_CALL
g() throw(RuntimeException
)
175 { return OUString("g"); }
180 TestWeakImpl(int, int) {}
182 TestWeakImpl(int, int, int) {}
184 TestWeakImpl(int, int, int, int) {}
186 TestWeakImpl(int, int, int, int, int) {}
188 TestWeakImpl(int, int, int, int, int, int, int = 0) {}
192 struct TestWeakComponentImpl
: public WeakComponentImplHelper4
< CA
, DBA
, FE
, G
>
195 TestWeakComponentImpl()
196 : WeakComponentImplHelper4
< CA
, DBA
, FE
, G
>( m
)
198 virtual ~TestWeakComponentImpl()
199 { OSL_TRACE( "> TestWeakComponentImpl dtor called... <\n" ); }
201 void SAL_CALL
disposing()
202 { OSL_TRACE( "> TestWeakComponentImpl disposing called... <\n" ); }
205 virtual OUString SAL_CALL
a() throw(RuntimeException
)
206 { return OUString("a"); }
208 virtual OUString SAL_CALL
ba() throw(RuntimeException
)
209 { return OUString("ba"); }
211 virtual OUString SAL_CALL
ca() throw(RuntimeException
)
212 { return OUString("ca"); }
214 virtual OUString SAL_CALL
dba() throw(RuntimeException
)
215 { return OUString("dba"); }
217 virtual OUString SAL_CALL
e() throw(RuntimeException
)
218 { return OUString("e"); }
220 virtual OUString SAL_CALL
fe() throw(RuntimeException
)
221 { return OUString("fe"); }
223 virtual OUString SAL_CALL
g() throw(RuntimeException
)
224 { return OUString("g"); }
228 struct TestWeakAggComponentImpl
: public WeakAggComponentImplHelper4
< CA
, DBA
, FE
, G
>
231 TestWeakAggComponentImpl()
232 : WeakAggComponentImplHelper4
< CA
, DBA
, FE
, G
>( m
)
234 virtual ~TestWeakAggComponentImpl()
235 { OSL_TRACE( "> TestWeakAggComponentImpl dtor called... <\n" ); }
237 void SAL_CALL
disposing()
238 { OSL_TRACE( "> TestWeakAggComponentImpl disposing called... <\n" ); }
241 virtual OUString SAL_CALL
a() throw(RuntimeException
)
242 { return OUString("a"); }
244 virtual OUString SAL_CALL
ba() throw(RuntimeException
)
245 { return OUString("ba"); }
247 virtual OUString SAL_CALL
ca() throw(RuntimeException
)
248 { return OUString("ca"); }
250 virtual OUString SAL_CALL
dba() throw(RuntimeException
)
251 { return OUString("dba"); }
253 virtual OUString SAL_CALL
e() throw(RuntimeException
)
254 { return OUString("e"); }
256 virtual OUString SAL_CALL
fe() throw(RuntimeException
)
257 { return OUString("fe"); }
259 virtual OUString SAL_CALL
g() throw(RuntimeException
)
260 { return OUString("g"); }
264 struct TestImplInh
: public ImplInheritanceHelper2
< TestWeakImpl
, H
, I
>
268 explicit TestImplInh(int):
269 ImplInheritanceHelper2
< TestWeakImpl
, H
, I
>(1) {}
271 TestImplInh(int, int):
272 ImplInheritanceHelper2
< TestWeakImpl
, H
, I
>(1, 2) {}
274 TestImplInh(int, int, int):
275 ImplInheritanceHelper2
< TestWeakImpl
, H
, I
>(1, 2, 3) {}
277 TestImplInh(int, int, int, int):
278 ImplInheritanceHelper2
< TestWeakImpl
, H
, I
>(1, 2, 3, 4) {}
280 TestImplInh(int, int, int, int, int):
281 ImplInheritanceHelper2
< TestWeakImpl
, H
, I
>(1, 2, 3, 4, 5) {}
283 TestImplInh(int, int, int, int, int, int):
284 ImplInheritanceHelper2
< TestWeakImpl
, H
, I
>(1, 2, 3, 4, 5, 6) {}
286 virtual ~TestImplInh()
287 { OSL_TRACE( "> TestWeakImplInh dtor called... <\n" ); }
290 virtual OUString SAL_CALL
h() throw(RuntimeException
)
291 { return OUString("h"); }
293 virtual OUString SAL_CALL
i() throw(RuntimeException
)
294 { return OUString("i"); }
298 struct TestAggImplInh
: public AggImplInheritanceHelper2
< TestWeakAggImpl
, H
, I
>
300 virtual ~TestAggImplInh()
301 { OSL_TRACE( "> TestAggImplInh dtor called... <\n" ); }
304 virtual OUString SAL_CALL
h() throw(RuntimeException
)
305 { return OUString("h2"); }
307 virtual OUString SAL_CALL
i() throw(RuntimeException
)
308 { return OUString("i2"); }
312 static bool isIn( Sequence
< Type
> const & rTypes
, char const * name
)
314 OUString
str( OUString::createFromAscii( name
) );
315 Type
const * pTypes
= rTypes
.getConstArray();
316 for ( sal_Int32 nPos
= rTypes
.getLength(); nPos
--; )
318 if (pTypes
[ nPos
].getTypeName().equals( str
))
325 static void dotest( const Reference
< XInterface
> & xOriginal
)
327 Reference
< lang::XTypeProvider
> xTP( xOriginal
, UNO_QUERY
);
328 Sequence
< sal_Int8
> id( xTP
->getImplementationId() );
329 Sequence
< Type
> types( xTP
->getTypes() );
330 ::fprintf( stderr
, "> supported types: " );
332 for ( ; n
< types
.getLength(); ++n
)
334 OString
str( OUStringToOString( types
[ n
].getTypeName(), RTL_TEXTENCODING_ASCII_US
) );
335 ::fprintf( stderr
, (n
< (types
.getLength()-1)) ? "%s, " : "%s; type-id=\n", str
.getStr() );
337 for ( n
= 0; n
< 16; ++n
)
339 ::fprintf( stderr
, n
< 15 ? "%x " : "%x \n", id
[ n
] );
342 Reference
< A
> xa( xOriginal
, UNO_QUERY
);
343 OSL_ENSURE( xa
->a() == "a", "### A failed!" );
344 Reference
< BA
> xba( xa
, UNO_QUERY
);
345 OSL_ENSURE( xba
->ba() == "ba", "### BA failed!" );
346 OSL_ENSURE( xba
->a() == "a", "### BA failed!" );
347 Reference
< CA
> xca( xba
, UNO_QUERY
);
348 OSL_ENSURE( xca
->ca() == "ca", "### CA failed!" );
349 OSL_ENSURE( xca
->a() == "a", "### CA failed!" );
350 Reference
< DBA
> xdba( xca
, UNO_QUERY
);
351 OSL_ENSURE( xdba
->dba() == "dba", "### DBA failed!" );
352 OSL_ENSURE( xdba
->ba() == "ba", "### DBA failed!" );
353 OSL_ENSURE( xdba
->a() == "a", "### DBA failed!" );
354 Reference
< E
> xe( xdba
, UNO_QUERY
);
355 OSL_ENSURE( xe
->e() == "e", "### E failed!" );
356 Reference
< FE
> xfe( xe
, UNO_QUERY
);
357 OSL_ENSURE( xfe
->fe() == "fe", "### FE failed!" );
358 Reference
< G
> xg( xfe
, UNO_QUERY
);
359 OSL_ENSURE( xg
->g() == "g", "### G failed!" );
360 OSL_ENSURE( xg
->a() == "a", "### G failed!" );
363 Reference
< lang::XTypeProvider
> xProv( xg
, UNO_QUERY
);
364 Sequence
< Type
> aTypes( xProv
->getTypes() );
366 // CA, DBA, FE, G, XTypeProvider
367 OSL_ASSERT( isIn( aTypes
, "test.CA" ) );
368 OSL_ASSERT( isIn( aTypes
, "test.DBA" ) );
369 OSL_ASSERT( isIn( aTypes
, "test.FE") );
370 OSL_ASSERT( isIn( aTypes
, "test.G") );
371 OSL_ASSERT( isIn( aTypes
, "com.sun.star.lang.XTypeProvider") );
373 Reference
< XWeak
> xWeak( xg
, UNO_QUERY
);
376 OSL_ASSERT( isIn( aTypes
, "com.sun.star.uno.XWeak") );
378 Reference
< lang::XComponent
> xComp( xg
, UNO_QUERY
);
381 OSL_ASSERT( isIn( aTypes
, "com.sun.star.lang.XComponent") );
384 Reference
< XAggregation
> xAgg( xg
, UNO_QUERY
);
387 OSL_ASSERT( isIn( aTypes
, "com.sun.star.uno.XAggregation") );
389 Reference
< H
> xH( xg
, UNO_QUERY
);
392 OSL_ASSERT( isIn( aTypes
, "test.H") );
394 Reference
< I
> xI( xg
, UNO_QUERY
);
397 OSL_ASSERT( isIn( aTypes
, "test.I") );
400 OSL_ENSURE( xg
== xOriginal
, "### root!" );
409 lang::IllegalAccessException exc
)
423 void test_ImplHelper( const Reference
< lang::XMultiServiceFactory
> & /*xSF*/ )
425 Reference
< XInterface
> xImpl( (lang::XTypeProvider
*)new TestImpl() );
426 Reference
< lang::XTypeProvider
> xTP1( xImpl
, UNO_QUERY
);
427 Reference
< XInterface
> xWeakImpl( (OWeakObject
*)new TestWeakImpl() );
428 Reference
< lang::XTypeProvider
> xTP2( xWeakImpl
, UNO_QUERY
);
429 Reference
< XInterface
> xWeakAggImpl( (OWeakObject
*)new TestWeakAggImpl() );
430 Reference
< lang::XTypeProvider
> xTP3( xWeakAggImpl
, UNO_QUERY
);
431 Reference
< XInterface
> xWeakComponentImpl( (OWeakObject
*)new TestWeakComponentImpl() );
432 Reference
< lang::XTypeProvider
> xTP4( xWeakComponentImpl
, UNO_QUERY
);
433 Reference
< XInterface
> xWeakAggComponentImpl( (OWeakObject
*)new TestWeakAggComponentImpl() );
434 Reference
< lang::XTypeProvider
> xTP5( xWeakAggComponentImpl
, UNO_QUERY
);
437 xTP1
->getImplementationId() != xTP2
->getImplementationId() &&
438 xTP1
->getImplementationId() != xTP3
->getImplementationId() &&
439 xTP1
->getImplementationId() != xTP4
->getImplementationId() &&
440 xTP1
->getImplementationId() != xTP5
->getImplementationId() &&
441 xTP2
->getImplementationId() != xTP3
->getImplementationId() &&
442 xTP2
->getImplementationId() != xTP4
->getImplementationId() &&
443 xTP2
->getImplementationId() != xTP5
->getImplementationId() &&
444 xTP3
->getImplementationId() != xTP4
->getImplementationId() &&
445 xTP3
->getImplementationId() != xTP5
->getImplementationId() &&
446 xTP4
->getImplementationId() != xTP5
->getImplementationId() );
451 dotest( xWeakAggImpl
);
452 dotest( xWeakComponentImpl
);
453 dotest( xWeakAggComponentImpl
);
455 xWeakImpl
= (OWeakObject
*)new TestImplInh();
456 Reference
< lang::XTypeProvider
> xTP6( xWeakImpl
, UNO_QUERY
);
458 Reference
< H
> xH( xWeakImpl
, UNO_QUERY
);
459 Reference
< I
> xI( xH
, UNO_QUERY
);
460 OSL_ASSERT( xH
->h() == "h" );
461 OSL_ASSERT( xI
->i() == "i" );
463 xWeakAggImpl
= (OWeakObject
*)new TestAggImplInh();
464 Reference
< lang::XTypeProvider
> xTP7( xWeakAggImpl
, UNO_QUERY
);
465 dotest( xWeakAggImpl
);
466 xH
.set( xWeakAggImpl
, UNO_QUERY
);
467 xI
.set( xH
, UNO_QUERY
);
468 OSL_ASSERT( xH
->h() == "h2" );
469 OSL_ASSERT( xI
->i() == "i2" );
473 xTP6
->getImplementationId() != xTP1
->getImplementationId() &&
474 xTP6
->getImplementationId() != xTP2
->getImplementationId() &&
475 xTP6
->getImplementationId() != xTP3
->getImplementationId() &&
476 xTP6
->getImplementationId() != xTP4
->getImplementationId() &&
477 xTP6
->getImplementationId() != xTP5
->getImplementationId() &&
478 xTP6
->getImplementationId() != xTP7
->getImplementationId() &&
479 xTP7
->getImplementationId() != xTP1
->getImplementationId() &&
480 xTP7
->getImplementationId() != xTP2
->getImplementationId() &&
481 xTP7
->getImplementationId() != xTP3
->getImplementationId() &&
482 xTP7
->getImplementationId() != xTP4
->getImplementationId() &&
483 xTP7
->getImplementationId() != xTP5
->getImplementationId() );
486 bool exc_succ
= false;
487 lang::IllegalAccessException
exc(
488 OUString("testtest"),
490 // exception helper tests
497 Any
a( getCaughtException() );
498 OSL_ASSERT( a
== exc
);
504 catch (lang::IllegalAccessException
& e
)
506 OSL_ASSERT( exc
.Message
== e
.Message
&& exc
.Context
== e
.Context
);
514 Any
a2( getCaughtException() );
515 OSL_ASSERT( (a2
== a
) && (a2
== exc
) );
521 catch (lang::IllegalAccessException
&)
523 Any
a3( getCaughtException() );
524 OSL_ASSERT( (a3
== a
) && (a3
== a2
) && (a3
== exc
) );
530 OSL_ASSERT( exc_succ
);
534 throwException( makeAny( RuntimeException(
535 OUString("runtime exc"), xImpl
) ) );
537 catch (RuntimeException
& rExc
)
539 OSL_ENSURE( rExc
.Message
== "runtime exc" && rExc
.Context
== xImpl
, "### unexpected exception content!" );
542 throwException( makeAny( Exception(
543 OUString("exc"), rExc
.Context
) ) );
545 catch (lang::IllegalAccessException
&)
547 OSL_FAIL( "### unexpected IllegalAccessException exception caught!" );
549 catch (Exception
& rExc2
)
551 OSL_ENSURE( rExc2
.Message
== "exc" && rExc2
.Context
== xImpl
, "### unexpected exception content!" );
554 throwException( makeAny( lang::IllegalAccessException(
555 OUString("axxess exc"), rExc2
.Context
) ) );
557 catch (lang::IllegalAccessException
& rExc3
)
559 OSL_ENSURE( rExc3
.Message
== "axxess exc" && rExc3
.Context
== xImpl
, "### unexpected exception content!" );
567 OSL_FAIL( "### exception test failed!" );
570 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */