1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: testintrosp.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_stoc.hxx"
35 #include <cppuhelper/implbase1.hxx>
36 #include <cppuhelper/implbase4.hxx>
37 #include <cppuhelper/servicefactory.hxx>
38 #include <osl/diagnose.h>
40 //#include <vos/dynload.hxx>
42 #include <ModuleA/XIntroTest.hpp>
43 #include <com/sun/star/beans/XPropertySet.hpp>
44 #include <com/sun/star/beans/XIntrospection.hpp>
45 #include <com/sun/star/beans/PropertyAttribute.hpp>
46 #include <com/sun/star/beans/PropertyConcept.hpp>
47 #include <com/sun/star/beans/MethodConcept.hpp>
48 #include <com/sun/star/beans/XExactName.hpp>
49 #include <com/sun/star/container/XElementAccess.hpp>
50 #include <com/sun/star/container/XNameAccess.hpp>
51 #include <com/sun/star/container/XIndexAccess.hpp>
52 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
53 #include <com/sun/star/reflection/XIdlReflection.hpp>
54 //#include <com/sun/star/registry/XSimpleRegistry.hpp>
55 #include <com/sun/star/registry/XImplementationRegistration.hpp>
56 #include <com/sun/star/lang/XComponent.hpp>
64 //using namespace vos;
65 using namespace ModuleA
;
66 //using namespace ModuleB;
67 //using namespace ModuleC;
68 //using namespace ModuleA::ModuleB;
69 using namespace com::sun::star::uno
;
70 using namespace com::sun::star::lang
;
71 using namespace com::sun::star::beans
;
72 using namespace com::sun::star::registry
;
73 using namespace com::sun::star::reflection
;
74 using namespace com::sun::star::container
;
75 using namespace com::sun::star::beans::PropertyAttribute
;
78 typedef WeakImplHelper4
< XIntroTest
, XPropertySet
, XNameAccess
, XIndexAccess
> ImplIntroTestHelper
;
79 typedef WeakImplHelper1
< XPropertySetInfo
> ImplPropertySetInfoHelper
;
82 #define DEFAULT_INDEX_ACCESS_COUNT 10
83 #define DEFAULT_NAME_ACCESS_COUNT 5
85 #if OSL_DEBUG_LEVEL > 0
86 #define TEST_ENSHURE(c, m) OSL_ENSURE(c, m)
88 #define TEST_ENSHURE(c, m) OSL_VERIFY(c)
91 //class IntroTestWritelnOutput;
95 //**************************************************************
96 //*** Hilfs-Funktion, um vom Type eine XIdlClass zu bekommen ***
97 //**************************************************************
98 Reference
<XIdlClass
> TypeToIdlClass( const Type
& rType
, const Reference
< XMultiServiceFactory
> & xMgr
)
100 static Reference
< XIdlReflection
> xRefl
;
102 // void als Default-Klasse eintragen
103 Reference
<XIdlClass
> xRetClass
;
104 typelib_TypeDescription
* pTD
= 0;
105 rType
.getDescription( &pTD
);
108 OUString
sOWName( pTD
->pTypeName
);
111 xRefl
= Reference
< XIdlReflection
>( xMgr
->createInstance(
112 OUString::createFromAscii("com.sun.star.reflection.CoreReflection") ), UNO_QUERY
);
113 OSL_ENSURE( xRefl
.is(), "### no corereflection!" );
115 xRetClass
= xRefl
->forName( sOWName
);
121 //****************************************************
122 //*** Hilfs-Funktion, um Any als UString auszugeben ***
123 //****************************************************
124 // ACHTUNG: Kann mal an eine zentrale Stelle uebernommen werden
125 // Wird zunaechst nur fuer einfache Datentypen ausgefuehrt
127 OUString
AnyToString( const Any
& aValue
, sal_Bool bIncludeType
, const Reference
< XMultiServiceFactory
> & xMgr
)
129 Type aValType
= aValue
.getValueType();
130 TypeClass eType
= aValType
.getTypeClass();
136 case TypeClass_TYPE
: aRetStr
= OUString::createFromAscii("TYPE TYPE"); break;
137 case TypeClass_INTERFACE
: aRetStr
= OUString::createFromAscii("TYPE INTERFACE"); break;
138 case TypeClass_SERVICE
: aRetStr
= OUString::createFromAscii("TYPE SERVICE"); break;
139 case TypeClass_STRUCT
: aRetStr
= OUString::createFromAscii("TYPE STRUCT"); break;
140 case TypeClass_TYPEDEF
: aRetStr
= OUString::createFromAscii("TYPE TYPEDEF"); break;
141 case TypeClass_UNION
: aRetStr
= OUString::createFromAscii("TYPE UNION"); break;
142 case TypeClass_ENUM
: aRetStr
= OUString::createFromAscii("TYPE ENUM"); break;
143 case TypeClass_EXCEPTION
: aRetStr
= OUString::createFromAscii("TYPE EXCEPTION"); break;
144 case TypeClass_ARRAY
: aRetStr
= OUString::createFromAscii("TYPE ARRAY"); break;
145 case TypeClass_SEQUENCE
: aRetStr
= OUString::createFromAscii("TYPE SEQUENCE"); break;
146 case TypeClass_VOID
: aRetStr
= OUString::createFromAscii("TYPE void"); break;
147 case TypeClass_ANY
: aRetStr
= OUString::createFromAscii("TYPE any"); break;
148 case TypeClass_UNKNOWN
: aRetStr
= OUString::createFromAscii("TYPE unknown"); break;
149 case TypeClass_BOOLEAN
:
151 sal_Bool b
= *(sal_Bool
*)aValue
.getValue();
152 //aRet.setValue( &b, getCppuBooleanType() );
154 aRetStr
= OUString::valueOf( b
);
159 sal_Unicode c
= *(sal_Unicode
*)aValue
.getValue();
162 aRetStr
= OUString::valueOf( c
);
165 case TypeClass_STRING
:
170 case TypeClass_FLOAT
:
174 snprintf( pBuffer
, sizeof( pBuffer
), "%f", f
);
175 aRetStr
= OUString( pBuffer
, strlen( pBuffer
), RTL_TEXTENCODING_ASCII_US
);
178 case TypeClass_DOUBLE
:
182 snprintf( pBuffer
, sizeof( pBuffer
), "%f", d
);
183 aRetStr
= OUString( pBuffer
, strlen( pBuffer
), RTL_TEXTENCODING_ASCII_US
);
190 aRetStr
= OUString::valueOf( (sal_Int32
) n
);
193 case TypeClass_SHORT
:
197 aRetStr
= OUString::valueOf( (sal_Int32
) n
);
204 aRetStr
= OUString::valueOf( n
);
208 case TypeClass_HYPER:
210 aRetStr = L"TYPE HYPER";
213 case TypeClass_UNSIGNED_SHORT:
215 aRetStr = StringToUString(WSString(aValue.getUINT16()), CHARSET_SYSTEM);
218 case TypeClass_UNSIGNED_LONG:
220 aRetStr = StringToUString(WSString(aValue.getUINT32()), CHARSET_SYSTEM);
223 case TypeClass_UNSIGNED_HYPER:
225 aRetStr = L"TYPE UNSIGNED_HYPER";
234 Reference
< XIdlClass
> xIdlClass
= TypeToIdlClass( aValType
, xMgr
);
235 aRetStr
= aRetStr
+ OUString( OUString::createFromAscii(" (Typ: ") ) + xIdlClass
->getName() + OUString::createFromAscii(")");
241 // Hilfs-Funktion, um ein UString in einen Any zu konvertieren
242 UsrAny StringToAny( UString aStr, TypeClass eTargetType )
245 switch( eTargetType )
247 case TypeClass_INTERFACE: break;
248 case TypeClass_SERVICE: break;
249 case TypeClass_STRUCT: break;
250 case TypeClass_TYPEDEF: break;
251 case TypeClass_UNION: break;
252 case TypeClass_ENUM: break;
253 case TypeClass_EXCEPTION: break;
254 case TypeClass_ARRAY: break;
255 case TypeClass_SEQUENCE: break;
256 case TypeClass_VOID: break;
257 case TypeClass_ANY: break;
258 case TypeClass_UNKNOWN: break;
259 case TypeClass_BOOLEAN: aRetAny.setBOOL( short(aStr)!=0 ); break;
260 case TypeClass_CHAR: aRetAny.setChar( char(aStr) ); break;
261 case TypeClass_STRING: aRetAny.setString( aStr ); break;
262 case TypeClass_FLOAT: aRetAny.setFloat( (float)strtod( aStr.GetStr(), NULL ) ); break;
263 case TypeClass_DOUBLE: aRetAny.setDouble( strtod( aStr.GetStr(), NULL ) ); break;
264 case TypeClass_BYTE: aRetAny.setBYTE( BYTE(short(aStr)) ); break;
265 case TypeClass_SHORT: aRetAny.setINT16( short(aStr) ); break;
266 case TypeClass_LONG: aRetAny.setINT32( long(aStr) ); break;
267 case TypeClass_HYPER: break;
268 case TypeClass_UNSIGNED_SHORT: aRetAny.setUINT16( USHORT(aStr) ); break;
269 case TypeClass_UNSIGNED_LONG: aRetAny.setUINT32( ULONG(aStr) ); break;
270 case TypeClass_UNSIGNED_HYPER: break;
277 //*****************************************
278 //*** XPropertySetInfo fuer Test-Klasse ***
279 //*****************************************
281 class ImplPropertySetInfo
: public ImplPropertySetInfoHelper
283 friend class ImplIntroTest
;
285 Reference
< XMultiServiceFactory
> mxMgr
;
288 ImplPropertySetInfo( const Reference
< XMultiServiceFactory
> & xMgr
)
290 //: mxMgr( xMgr ), ImplPropertySetInfoHelper( xMgr ) {}
293 // Methoden von XInterface
294 virtual sal_Bool SAL_CALL queryInterface( const Uik & rUik, Any & ifc ) throw( RuntimeException );
295 virtual void SAL_CALL acquire() throw() { OWeakObject::acquire(); }
296 virtual void SAL_CALL release() throw() { OWeakObject::release(); }
297 //ALT: sal_Bool queryInterface( Uik aUik, Reference<XInterface> & rOut );
300 // Methods of XPropertySetInfo
301 virtual Sequence
< Property
> SAL_CALL
getProperties( )
302 throw(RuntimeException
);
303 virtual Property SAL_CALL
getPropertyByName( const OUString
& aName
)
304 throw(UnknownPropertyException
, RuntimeException
);
305 virtual sal_Bool SAL_CALL
hasPropertyByName( const OUString
& Name
)
306 throw(RuntimeException
);
307 //virtual Sequence< Property > SAL_CALL getProperties(void) throw( RuntimeException );
308 //virtual Property SAL_CALL getPropertyByName(const OUString& Name) throw( RuntimeException );
309 //virtual sal_Bool SAL_CALL hasPropertyByName(const OUString& Name) throw( RuntimeException );
314 // Methoden von XInterface
315 sal_Bool SAL_CALL ImplPropertySetInfo::queryInterface( const Uik & rUik, Any & ifc )
316 throw( RuntimeException )
318 // PropertySet-Implementation
319 if( com::sun::star::uno::queryInterface( rUik, ifc,
320 SAL_STATIC_CAST(XPropertySetInfo*, this) ) )
323 return OWeakObject::queryInterface( rUik, ifc );
326 sal_Bool ImplPropertySetInfo::queryInterface( Uik aUik, Reference<XInterface> & rOut )
328 if( aUik == XPropertySetInfo::getSmartUik() )
329 rOut = (XPropertySetInfo *)this;
331 UsrObject::queryInterface( aUik, rOut );
336 Sequence
< Property
> ImplPropertySetInfo::getProperties(void)
337 throw( RuntimeException
)
339 static Sequence
<Property
> * pSeq
= NULL
;
343 // die Informationen für die Properties "Width", "Height" und "Name" anlegen
344 pSeq
= new Sequence
<Property
>( 3 );
345 Property
* pAry
= pSeq
->getArray();
347 pAry
[0].Name
= OUString::createFromAscii("Factor");
349 pAry
[0].Type
= getCppuType( (double*) NULL
);
350 //pAry[0].Type = TypeToIdlClass( getCppuType( (double*) NULL ), mxMgr );
351 //pAry[0].Type = Double_getReflection()->getIdlClass();
352 pAry
[0].Attributes
= BOUND
| TRANSIENT
;
354 pAry
[1].Name
= OUString::createFromAscii("MyCount");
356 pAry
[1].Type
= getCppuType( (sal_Int32
*) NULL
);
357 //pAry[1].Type = TypeToIdlClass( getCppuType( (sal_Int32*) NULL ), mxMgr );
358 //pAry[1].Type = INT32_getReflection()->getIdlClass();
359 pAry
[1].Attributes
= BOUND
| TRANSIENT
;
361 pAry
[2].Name
= OUString::createFromAscii("Info");
363 pAry
[2].Type
= getCppuType( (OUString
*) NULL
);
364 //pAry[2].Type = TypeToIdlClass( getCppuType( (OUString*) NULL ), mxMgr );
365 //pAry[2].Type = OUString_getReflection()->getIdlClass();
366 pAry
[2].Attributes
= TRANSIENT
;
368 // Die Information über alle drei Properties liefern.
372 Property
ImplPropertySetInfo::getPropertyByName(const OUString
& Name
)
373 throw( UnknownPropertyException
, RuntimeException
)
375 Sequence
<Property
> aSeq
= getProperties();
376 const Property
* pAry
= aSeq
.getConstArray();
378 for( sal_Int32 i
= aSeq
.getLength(); i
--; )
380 if( pAry
[i
].Name
== Name
)
383 // Property unbekannt, also leere liefern
387 sal_Bool
ImplPropertySetInfo::hasPropertyByName(const OUString
& Name
)
388 throw( RuntimeException
)
390 Sequence
<Property
> aSeq
= getProperties();
391 const Property
* pAry
= aSeq
.getConstArray();
393 for( sal_Int32 i
= aSeq
.getLength(); i
--; )
395 if( pAry
[i
].Name
== Name
)
398 // Property unbekannt, also leere liefern
405 //*****************************************************************
409 class ImplIntroTest
: public ImplIntroTestHelper
411 Reference
< XMultiServiceFactory
> mxMgr
;
413 friend class ImplPropertySetInfo
;
415 // Properties fuer das PropertySet
418 // Optionale Schnittstelle fuer die writeln-Ausgabe
419 //IntroTestWritelnOutput* m_pOutput;
421 Reference
< XPropertySetInfo
> m_xMyInfo
;
423 OUString m_ObjectName
;
425 sal_Int16 m_nMarkusAge
;
426 sal_Int16 m_nMarkusChildrenCount
;
433 TypeClass eTypeClass
;
434 Sequence
< OUString
> aStringSeq
;
435 Sequence
< Sequence
< Sequence
< sal_Int16
> > > aMultSeq
;
436 Reference
< XIntroTest
> m_xIntroTest
;
438 // Daten fuer NameAccess
439 Reference
< XIntroTest
>* pNameAccessTab
;
441 // Daten fuer IndexAccess
442 Reference
< XIntroTest
>* pIndexAccessTab
;
443 sal_Int16 iIndexAccessCount
;
446 Property m_aFirstStruct
;
447 PropertyValue m_aSecondStruct
;
449 // Listener merken (zunaechst einfach, nur einen pro Property)
450 Reference
< XPropertyChangeListener
> aPropChangeListener
;
451 OUString aPropChangeListenerStr
;
452 Reference
< XVetoableChangeListener
> aVetoPropChangeListener
;
453 OUString aVetoPropChangeListenerStr
;
458 ImplIntroTest( const Reference
< XMultiServiceFactory
> & xMgr
)
460 //: mxMgr( xMgr ), ImplIntroTestHelper( xMgr )
466 ImplIntroTest( IntroTestWritelnOutput* pOutput_ )
469 m_pOutput = pOutput_;
473 //SMART_UNO_DECLARATION(ImplIntroTest,UsrObject);
475 //BOOL queryInterface( Uik aUik, Reference< XInterface > & rOut );
476 //Reference< XIdlClass > getIdlClass();
478 // Trotz virtual inline, um Schreibarbeit zu sparen (nur fuer Testzwecke)
480 virtual Reference
< XPropertySetInfo
> SAL_CALL
getPropertySetInfo( )
481 throw(RuntimeException
);
482 virtual void SAL_CALL
setPropertyValue( const OUString
& aPropertyName
, const Any
& aValue
)
483 throw(UnknownPropertyException
, PropertyVetoException
, IllegalArgumentException
, WrappedTargetException
, RuntimeException
);
484 virtual Any SAL_CALL
getPropertyValue( const OUString
& PropertyName
)
485 throw(UnknownPropertyException
, WrappedTargetException
, RuntimeException
);
486 virtual void SAL_CALL
addPropertyChangeListener( const OUString
& /*aPropertyName*/, const Reference
< XPropertyChangeListener
>& /*xListener*/ )
487 throw(UnknownPropertyException
, WrappedTargetException
, RuntimeException
)
489 virtual void SAL_CALL
removePropertyChangeListener( const OUString
& /*aPropertyName*/, const Reference
< XPropertyChangeListener
>& /*aListener*/ )
490 throw(UnknownPropertyException
, WrappedTargetException
, RuntimeException
)
492 virtual void SAL_CALL
addVetoableChangeListener( const OUString
& /*PropertyName*/, const Reference
< XVetoableChangeListener
>& /*aListener*/ )
493 throw(UnknownPropertyException
, WrappedTargetException
, RuntimeException
)
495 virtual void SAL_CALL
removeVetoableChangeListener( const OUString
& /*PropertyName*/, const Reference
< XVetoableChangeListener
>& /*aListener*/ )
496 throw(UnknownPropertyException
, WrappedTargetException
, RuntimeException
)
500 virtual void setIndexedPropertyValue(const OUString& aPropertyName, INT32 nIndex, const Any& aValue) {}
501 virtual Any getIndexedPropertyValue(const UString& aPropertyName, INT32 nIndex) const { return Any(); }
502 virtual void addPropertyChangeListener(const UString& aPropertyName, const XPropertyChangeListenerRef& aListener)
503 THROWS( (UnknownPropertyException, WrappedTargetException, UsrSystemException) ) {}
504 virtual void removePropertyChangeListener(const UString& aPropertyName, const XPropertyChangeListenerRef& aListener)
505 THROWS( (UnknownPropertyException, WrappedTargetException, UsrSystemException) ) {}
506 virtual void addVetoableChangeListener(const UString& aPropertyName, const XVetoableChangeListenerRef& aListener)
507 THROWS( (UnknownPropertyException, WrappedTargetException, UsrSystemException) ) {}
508 virtual void removeVetoableChangeListener(const UString& aPropertyName, const XVetoableChangeListenerRef& aListener)
509 THROWS( (UnknownPropertyException, WrappedTargetException, UsrSystemException) ) {}
512 // XIntroTest-Methoden
514 virtual OUString SAL_CALL
getObjectName() throw(RuntimeException
)
515 { return m_ObjectName
; }
516 virtual void SAL_CALL
setObjectName( const OUString
& _objectname
) throw(RuntimeException
)
517 { m_ObjectName
= _objectname
; }
518 virtual OUString SAL_CALL
getFirstName()
519 throw(RuntimeException
);
520 virtual OUString SAL_CALL
getLastName() throw(RuntimeException
)
521 { return OUString( OUString::createFromAscii("Meyer") ); }
522 virtual sal_Int16 SAL_CALL
getAge() throw(RuntimeException
)
523 { return m_nMarkusAge
; }
524 virtual sal_Int16 SAL_CALL
getChildrenCount() throw(RuntimeException
)
525 { return m_nMarkusChildrenCount
; }
526 virtual void SAL_CALL
setChildrenCount( sal_Int16 _childrencount
) throw(RuntimeException
)
527 { m_nMarkusChildrenCount
= _childrencount
; }
528 virtual Property SAL_CALL
getFirstStruct() throw(RuntimeException
)
529 { return m_aFirstStruct
; }
530 virtual void SAL_CALL
setFirstStruct( const Property
& _firststruct
) throw(RuntimeException
)
531 { m_aFirstStruct
= _firststruct
; }
532 virtual PropertyValue SAL_CALL
getSecondStruct() throw(RuntimeException
)
533 { return m_aSecondStruct
; }
534 virtual void SAL_CALL
setSecondStruct( const PropertyValue
& _secondstruct
) throw(RuntimeException
)
535 { m_aSecondStruct
= _secondstruct
; }
538 virtual void SAL_CALL
writeln( const OUString
& Text
)
539 throw(RuntimeException
);
540 virtual sal_Int32 SAL_CALL
getDroenk( ) throw(RuntimeException
)
541 { return m_lDroenk
; }
542 virtual Reference
< ::ModuleA::XIntroTest
> SAL_CALL
getIntroTest( ) throw(RuntimeException
);
543 virtual sal_Int32 SAL_CALL
getUps( sal_Int32 l
) throw(RuntimeException
)
545 virtual void SAL_CALL
setDroenk( sal_Int32 l
) throw(RuntimeException
)
547 virtual sal_Int16 SAL_CALL
getBla( ) throw(RuntimeException
)
549 virtual void SAL_CALL
setBla( sal_Int32 n
) throw(RuntimeException
)
550 { m_nBla
= (sal_Int16
)n
; }
551 virtual sal_Int16 SAL_CALL
getBlub( ) throw(RuntimeException
)
553 virtual void SAL_CALL
setBlub( sal_Int16 n
) throw(RuntimeException
)
555 virtual sal_Int16 SAL_CALL
getGulp( ) throw(RuntimeException
)
557 virtual sal_Int16 SAL_CALL
setGulp( sal_Int16 n
) throw(RuntimeException
)
558 { m_nGulp
= n
; return 1; }
559 virtual TypeClass SAL_CALL
getTypeClass( sal_Int16
/*n*/ ) throw(RuntimeException
)
560 { return eTypeClass
; }
561 virtual void SAL_CALL
setTypeClass( TypeClass t
, double /*d1*/, double /*d2*/ ) throw(RuntimeException
)
563 virtual Sequence
< OUString
> SAL_CALL
getStrings( ) throw(RuntimeException
)
564 { return aStringSeq
; }
565 virtual void SAL_CALL
setStrings( const Sequence
< OUString
>& Strings
) throw(RuntimeException
)
566 { aStringSeq
= Strings
; }
567 virtual void SAL_CALL
setStringsPerMethod( const Sequence
< OUString
>& Strings
, sal_Int16
/*n*/ ) throw(RuntimeException
)
568 { aStringSeq
= Strings
; }
569 virtual Sequence
< Sequence
< Sequence
< sal_Int16
> > > SAL_CALL
getMultiSequence( ) throw(RuntimeException
)
571 virtual void SAL_CALL
setMultiSequence( const Sequence
< Sequence
< Sequence
< sal_Int16
> > >& Seq
) throw(RuntimeException
)
573 virtual void SAL_CALL
addPropertiesChangeListener( const Sequence
< OUString
>& PropertyNames
, const Reference
< XPropertiesChangeListener
>& Listener
)
574 throw(RuntimeException
);
575 virtual void SAL_CALL
removePropertiesChangeListener( const Reference
< XPropertiesChangeListener
>& Listener
)
576 throw(RuntimeException
);
579 // Methods of XElementAccess
580 virtual Type SAL_CALL
getElementType( )
581 throw(RuntimeException
);
582 virtual sal_Bool SAL_CALL
hasElements( )
583 throw(RuntimeException
);
584 //virtual XIdlClassRef getElementType(void) constTHROWS( (UsrSystemException) );
585 //virtual BOOL hasElements(void) const THROWS( (UsrSystemException) );
587 // XNameAccess-Methoden
589 virtual Any SAL_CALL
getByName( const OUString
& aName
)
590 throw(NoSuchElementException
, WrappedTargetException
, RuntimeException
);
591 virtual Sequence
< OUString
> SAL_CALL
getElementNames( )
592 throw(RuntimeException
);
593 virtual sal_Bool SAL_CALL
hasByName( const OUString
& aName
)
594 throw(RuntimeException
);
595 //virtual Any getByName(const UString& Name) const
596 //THROWS( (NoSuchElementException, WrappedTargetException, UsrSystemException) );
597 //virtual Sequence<UString> getElementNames(void) const THROWS( (UsrSystemException) );
598 //virtual BOOL hasByName(const UString& Name) const THROWS( (UsrSystemException) );
600 // XIndexAccess-Methoden
602 virtual sal_Int32 SAL_CALL
getCount( )
603 throw(RuntimeException
);
604 virtual Any SAL_CALL
getByIndex( sal_Int32 Index
)
605 throw(IndexOutOfBoundsException
, WrappedTargetException
, RuntimeException
);
606 //virtual INT32 getCount(void) const THROWS( (UsrSystemException) );
607 //virtual Any getByIndex(INT32 Index) const
608 //THROWS( (IndexOutOfBoundsException, WrappedTargetException, UsrSystemException) );
611 //SMART_UNO_IMPLEMENTATION(ImplIntroTest,UsrObject)
613 void ImplIntroTest::Init( void )
615 // Eindeutigen Namen verpassen
616 static sal_Int32 nObjCount
= 0;
617 OUString
aName( OUString::createFromAscii("IntroTest-Obj Nr. ") );
618 aName
+= OUString::valueOf( nObjCount
);
619 setObjectName( aName
);
621 // Properties initialisieren
622 aAnyArray
[0] <<= 3.14;
623 aAnyArray
[1] <<= (sal_Int32
)42;
624 aAnyArray
[2] <<= OUString( OUString::createFromAscii("Hallo") );
629 // Einmal fuer den internen Gebrauch die PropertySetInfo abholen
630 m_xMyInfo
= getPropertySetInfo();
631 m_xMyInfo
->acquire(); // sonst raucht es am Programm-Ende ab
634 m_nMarkusChildrenCount
= 2;
641 eTypeClass
= TypeClass_INTERFACE
;
643 // String-Sequence intitialisieren
644 aStringSeq
.realloc( 3 );
645 OUString
* pStr
= aStringSeq
.getArray();
646 pStr
[ 0 ] = OUString( OUString::createFromAscii("String 0") );
647 pStr
[ 1 ] = OUString( OUString::createFromAscii("String 1") );
648 pStr
[ 2 ] = OUString( OUString::createFromAscii("String 2") );
650 // structs initialisieren
651 m_aFirstStruct
.Name
= OUString::createFromAscii("FirstStruct-Name");
652 m_aFirstStruct
.Handle
= 77777;
654 m_aFirstStruct
.Attributes
= -222;
656 //XInterfaceRef Source;
658 Value
<<= 2.718281828459;
659 m_aSecondStruct
.Value
= Value
;
660 //XIdlClassRef ListenerType;
661 m_aSecondStruct
.State
= PropertyState_DIRECT_VALUE
;
664 iIndexAccessCount
= DEFAULT_INDEX_ACCESS_COUNT
;
665 pIndexAccessTab
= NULL
;
666 pNameAccessTab
= NULL
;
670 BOOL ImplIntroTest::queryInterface( Uik aUik, XInterfaceRef & rOut )
672 if( aUik == XIntroTest::getSmartUik() )
673 rOut = (XIntroTest*)this;
674 else if( aUik == XPropertySet::getSmartUik() )
675 rOut = (XPropertySet*)this;
676 else if( aUik == XNameAccess::getSmartUik() )
677 rOut = (XNameAccess*)this;
678 else if( aUik == XIndexAccess::getSmartUik() )
679 rOut = (XIndexAccess*)this;
680 else if( aUik == ((XElementAccess*)NULL)->getSmartUik() )
681 rOut = (XElementAccess*)(XIndexAccess *)this;
683 UsrObject::queryInterface( aUik, rOut );
687 XIdlClassRef ImplIntroTest::getIdlClass()
689 static XIdlClassRef xClass = createStandardClass( L"ImplIntroTest",
690 UsrObject::getUsrObjectIdlClass(), 4,
691 XIntroTest_getReflection(),
692 XPropertySet_getReflection(),
693 XNameAccess_getReflection(),
694 XIndexAccess_getReflection() );
699 Reference
< XPropertySetInfo
> ImplIntroTest::getPropertySetInfo()
700 throw(RuntimeException
)
702 static ImplPropertySetInfo
aInfo( mxMgr
);
703 // Alle Objekt haben die gleichen Properties, deshalb kann
704 // die Info für alle gleich sein
707 //if( m_xMyInfo == NULL )
708 // ((ImplIntroTest*)this)->m_xMyInfo = new ImplPropertySetInfo( this );
712 void ImplIntroTest::setPropertyValue( const OUString
& aPropertyName
, const Any
& aValue
)
713 throw(UnknownPropertyException
, PropertyVetoException
, IllegalArgumentException
, WrappedTargetException
, RuntimeException
)
714 //void ImplIntroTest::setPropertyValue( const UString& aPropertyName, const Any& aValue )
715 // THROWS( (UnknownPropertyException, PropertyVetoException, IllegalArgumentException, WrappedTargetException, UsrSystemException) )
717 if( aPropChangeListener
.is() && aPropertyName
== aPropChangeListenerStr
)
719 PropertyChangeEvent aEvt
;
720 aEvt
.Source
= (OWeakObject
*)this;
721 aEvt
.PropertyName
= aPropertyName
;
722 aEvt
.PropertyHandle
= 0L;
725 //aEvt.PropagationId;
726 aPropChangeListener
->propertyChange( aEvt
);
728 if( aVetoPropChangeListener
.is() && aPropertyName
== aVetoPropChangeListenerStr
)
730 PropertyChangeEvent aEvt
;
731 aEvt
.Source
= (OWeakObject
*)this;
732 aEvt
.PropertyName
= aVetoPropChangeListenerStr
;
733 aEvt
.PropertyHandle
= 0L;
736 //aEvt.PropagationId;
737 aVetoPropChangeListener
->vetoableChange( aEvt
);
740 Sequence
<Property
> aPropSeq
= m_xMyInfo
->getProperties();
741 sal_Int32 nLen
= aPropSeq
.getLength();
742 for( sal_Int32 i
= 0 ; i
< nLen
; i
++ )
744 Property aProp
= aPropSeq
.getArray()[ i
];
745 if( aProp
.Name
== aPropertyName
)
746 aAnyArray
[i
] = aValue
;
750 Any
ImplIntroTest::getPropertyValue( const OUString
& PropertyName
)
751 throw(UnknownPropertyException
, WrappedTargetException
, RuntimeException
)
752 //Any ImplIntroTest::getPropertyValue(const UString& aPropertyName) const
753 //THROWS( (UnknownPropertyException, WrappedTargetException, UsrSystemException) )
755 Sequence
<Property
> aPropSeq
= m_xMyInfo
->getProperties();
756 sal_Int32 nLen
= aPropSeq
.getLength();
757 for( sal_Int32 i
= 0 ; i
< nLen
; i
++ )
759 Property aProp
= aPropSeq
.getArray()[ i
];
760 if( aProp
.Name
== PropertyName
)
766 OUString
ImplIntroTest::getFirstName(void)
767 throw(RuntimeException
)
769 return OUString( OUString::createFromAscii("Markus") );
772 void ImplIntroTest::writeln( const OUString
& Text
)
773 throw(RuntimeException
)
775 OString
aStr( Text
.getStr(), Text
.getLength(), RTL_TEXTENCODING_ASCII_US
);
777 // Haben wir ein Output?
780 //m_pOutput->doWriteln( TextStr );
782 // Sonst einfach rausbraten
785 printf( "%s", aStr
.getStr() );
789 Reference
< XIntroTest
> ImplIntroTest::getIntroTest()
790 throw(RuntimeException
)
791 //XIntroTestRef ImplIntroTest::getIntroTest(void) THROWS( (UsrSystemException) )
793 if( !m_xIntroTest
.is() )
794 m_xIntroTest
= new ImplIntroTest( mxMgr
);
798 // Methoden von XElementAccess
799 Type
ImplIntroTest::getElementType( )
800 throw(RuntimeException
)
801 //XIdlClassRef ImplIntroTest::getElementType(void) const THROWS( (UsrSystemException) )
806 //return Reference< XIdlClass >();
807 //return Void_getReflection()->getIdlClass();
810 sal_Bool
ImplIntroTest::hasElements( )
811 throw(RuntimeException
)
812 //BOOL ImplIntroTest::hasElements(void) const THROWS( (UsrSystemException) )
817 // XNameAccess-Methoden
818 sal_Int32
getIndexForName( const OUString
& ItemName
)
820 OUString aLeftStr
= ItemName
.copy( 0, 4 );
821 if( aLeftStr
== OUString::createFromAscii("Item") )
824 OUString aNumStr
= ItemName
.copy( 4 );
825 //sal_Int32 iIndex = (INT32)UStringToString( aNumStr, CHARSET_SYSTEM );
826 //if( iIndex < DEFAULT_NAME_ACCESS_COUNT )
833 Any
ImplIntroTest::getByName( const OUString
& aName
)
834 throw(NoSuchElementException
, WrappedTargetException
, RuntimeException
)
835 //Any ImplIntroTest::getByName(const UString& Name) const
836 //THROWS( (NoSuchElementException, WrappedTargetException, UsrSystemException) )
840 if( !pNameAccessTab
)
841 ((ImplIntroTest
*)this)->pNameAccessTab
= new Reference
< XIntroTest
>[ DEFAULT_NAME_ACCESS_COUNT
];
843 sal_Int32 iIndex
= getIndexForName( aName
);
846 if( !pNameAccessTab
[iIndex
].is() )
848 ImplIntroTest
* p
= new ImplIntroTest( mxMgr
);
849 OUString
aName2( OUString::createFromAscii("IntroTest by Name-Access, Index = ") );
850 aName2
+= OUString::valueOf( iIndex
);
851 //aName2 = aName2 + StringToUString( String( iIndex ), CHARSET_SYSTEM );
852 p
->setObjectName( aName2
);
853 pNameAccessTab
[iIndex
] = p
;
856 Reference
< XIntroTest
> xRet
= pNameAccessTab
[iIndex
];
857 aRetAny
= makeAny( xRet
);
859 //aRetAny.set( &xRet, XIntroTest_getReflection() );
860 //return (UsrObject*)(XIntroTest*)pNameAccessTab[iIndex];
865 Sequence
< OUString
> ImplIntroTest::getElementNames( )
866 throw(RuntimeException
)
867 //Sequence<UString> ImplIntroTest::getElementNames(void) const THROWS( (UsrSystemException) )
869 Sequence
<OUString
> aStrSeq( DEFAULT_NAME_ACCESS_COUNT
);
870 OUString
* pStr
= aStrSeq
.getArray();
871 for( sal_Int32 i
= 0 ; i
< DEFAULT_NAME_ACCESS_COUNT
; i
++ )
873 OUString
aName( OUString::createFromAscii("Item") );
874 aName
+= OUString::valueOf( i
);
875 //aName = aName + StringToUString( i, CHARSET_SYSTEM );
881 sal_Bool
ImplIntroTest::hasByName( const OUString
& aName
)
882 throw(RuntimeException
)
883 //BOOL ImplIntroTest::hasByName(const UString& Name) const THROWS( (UsrSystemException) )
885 return ( getIndexForName( aName
) != -1 );
888 // XIndexAccess-Methoden
889 sal_Int32
ImplIntroTest::getCount( )
890 throw(RuntimeException
)
891 //sal_Int32 ImplIntroTest::getCount(void) const THROWS( (UsrSystemException) )
893 return iIndexAccessCount
;
896 Any
ImplIntroTest::getByIndex( sal_Int32 Index
)
897 throw(IndexOutOfBoundsException
, WrappedTargetException
, RuntimeException
)
898 //Any ImplIntroTest::getByIndex( sal_Int32 Index ) const
899 //THROWS( (IndexOutOfBoundsException, WrappedTargetException, UsrSystemException) )
903 if( !pIndexAccessTab
)
904 ((ImplIntroTest
*)this)->pIndexAccessTab
= new Reference
< XIntroTest
>[ iIndexAccessCount
];
906 if( Index
< iIndexAccessCount
)
908 if( !pNameAccessTab
[Index
].is() )
910 ImplIntroTest
* p
= new ImplIntroTest( mxMgr
);
911 OUString
aName( OUString::createFromAscii("IntroTest by Index-Access, Index = ") );
912 aName
+= OUString::valueOf( Index
);
913 //aName = aName + StringToUString( String( iIndex ), CHARSET_SYSTEM );
914 p
->setObjectName( aName
);
915 pIndexAccessTab
[Index
] = p
;
917 Reference
< XIntroTest
> xRet
= pIndexAccessTab
[Index
];
918 aRetAny
= makeAny( xRet
);
923 void ImplIntroTest::addPropertiesChangeListener( const Sequence
< OUString
>& /*PropertyNames*/,
924 const Reference
< XPropertiesChangeListener
>& /*Listener*/ )
925 throw(RuntimeException
)
926 //void ImplIntroTest::addPropertiesChangeListener
927 //(const Sequence< UString >& PropertyNames, const XPropertiesChangeListenerRef& Listener)
928 //THROWS( (UsrSystemException) )
932 void ImplIntroTest::removePropertiesChangeListener
933 ( const Reference
< XPropertiesChangeListener
>& /*Listener*/ )
934 throw(RuntimeException
)
935 //void ImplIntroTest::removePropertiesChangeListener(const XPropertiesChangeListenerRef& Listener)
936 //THROWS( (UsrSystemException) )
948 // Spezial-Wert fuer Method-Concept, um "normale" Funktionen kennzeichnen zu koennen
949 #define MethodConcept_NORMAL_IMPL 0x80000000
952 // Test-Objekt liefern
953 Any
getIntrospectionTestObject( const Reference
< XMultiServiceFactory
> & xMgr
)
956 Reference
< XIntroTest
> xTestObj
= new ImplIntroTest( xMgr
);
957 aObjAny
.setValue( &xTestObj
, ::getCppuType( (const Reference
< XIntroTest
> *)0 ) );
961 static sal_Bool
test_introsp( Reference
< XMultiServiceFactory
> xMgr
,
962 Reference
< XIdlReflection
> /*xRefl*/, Reference
< XIntrospection
> xIntrospection
)
964 DefItem pPropertyDefs
[] =
966 { "Factor", PropertyConcept::PROPERTYSET
},
967 { "MyCount", PropertyConcept::PROPERTYSET
},
968 { "Info", PropertyConcept::PROPERTYSET
},
969 { "ObjectName", PropertyConcept::ATTRIBUTES
},
970 { "FirstName", PropertyConcept::ATTRIBUTES
},
971 { "LastName", PropertyConcept::ATTRIBUTES
},
972 { "Age", PropertyConcept::ATTRIBUTES
},
973 { "ChildrenCount", PropertyConcept::ATTRIBUTES
},
974 { "FirstStruct", PropertyConcept::ATTRIBUTES
},
975 { "SecondStruct", PropertyConcept::ATTRIBUTES
},
976 { "Droenk", PropertyConcept::METHODS
},
977 { "IntroTest", PropertyConcept::METHODS
},
978 { "Bla", PropertyConcept::METHODS
},
979 { "Blub", PropertyConcept::METHODS
},
980 { "Gulp", PropertyConcept::METHODS
},
981 { "Strings", PropertyConcept::METHODS
},
982 { "MultiSequence", PropertyConcept::METHODS
},
983 { "PropertySetInfo", PropertyConcept::METHODS
},
984 { "ElementType", PropertyConcept::METHODS
},
985 { "ElementNames", PropertyConcept::METHODS
},
986 { "Count", PropertyConcept::METHODS
},
987 { "Types", PropertyConcept::METHODS
},
988 { "ImplementationId", PropertyConcept::METHODS
},
992 // Tabelle der Property-Namen, die gefunden werden muessen
993 // char* pDemandedPropNames[] =
1012 // "PropertySetInfo",
1017 // "ImplementationId"
1020 char const * pDemandedPropVals
[] =
1025 "IntroTest-Obj Nr. 0",
1047 char const * pDemandedModifiedPropVals
[] =
1051 "Hallo (Modified!)",
1052 "IntroTest-Obj Nr. 0 (Modified!)",
1057 "Wert wurde nicht modifiziert",
1058 "Wert wurde nicht modifiziert",
1060 "Wert wurde nicht modifiziert",
1064 "Wert wurde nicht modifiziert",
1065 "Wert wurde nicht modifiziert",
1066 "Wert wurde nicht modifiziert",
1067 "Wert wurde nicht modifiziert",
1068 "Wert wurde nicht modifiziert",
1070 "Wert wurde nicht modifiziert"
1071 "Wert wurde nicht modifiziert"
1074 char const * pDemandedPropTypes
[] =
1084 "com.sun.star.beans.Property",
1085 "com.sun.star.beans.PropertyValue",
1087 "ModuleA.XIntroTest",
1093 "com.sun.star.beans.XPropertySetInfo",
1100 //is() nDemandedPropCount = 22;
1103 DefItem pMethodDefs
[] =
1105 { "queryInterface", MethodConcept_NORMAL_IMPL
},
1106 { "acquire", MethodConcept::DANGEROUS
},
1107 { "release", MethodConcept::DANGEROUS
},
1108 { "writeln", MethodConcept_NORMAL_IMPL
},
1109 { "getDroenk", MethodConcept::PROPERTY
},
1110 { "getIntroTest", MethodConcept::PROPERTY
},
1111 { "getUps", MethodConcept_NORMAL_IMPL
},
1112 { "setDroenk", MethodConcept::PROPERTY
},
1113 { "getBla", MethodConcept::PROPERTY
},
1114 { "setBla", MethodConcept_NORMAL_IMPL
},
1115 { "getBlub", MethodConcept::PROPERTY
},
1116 { "setBlub", MethodConcept::PROPERTY
},
1117 { "getGulp", MethodConcept::PROPERTY
},
1118 { "setGulp", MethodConcept_NORMAL_IMPL
},
1119 { "getTypeClass", MethodConcept_NORMAL_IMPL
},
1120 { "setTypeClass", MethodConcept_NORMAL_IMPL
},
1121 { "getStrings", MethodConcept::PROPERTY
},
1122 { "setStrings", MethodConcept::PROPERTY
},
1123 { "setStringsPerMethod", MethodConcept_NORMAL_IMPL
},
1124 { "getMultiSequence", MethodConcept::PROPERTY
},
1125 { "setMultiSequence", MethodConcept::PROPERTY
},
1126 { "addPropertiesChangeListener", MethodConcept::LISTENER
},
1127 { "removePropertiesChangeListener", MethodConcept::LISTENER
},
1128 { "getPropertySetInfo", MethodConcept::PROPERTY
},
1129 { "setPropertyValue", MethodConcept_NORMAL_IMPL
},
1130 { "getPropertyValue", MethodConcept_NORMAL_IMPL
},
1131 { "addPropertyChangeListener", MethodConcept::LISTENER
},
1132 { "removePropertyChangeListener", MethodConcept::LISTENER
},
1133 { "addVetoableChangeListener", MethodConcept::LISTENER
},
1134 { "removeVetoableChangeListener", MethodConcept::LISTENER
},
1135 { "getElementType", MethodConcept::PROPERTY
| MethodConcept::NAMECONTAINER
| MethodConcept::INDEXCONTAINER
| MethodConcept::ENUMERATION
},
1136 { "hasElements", MethodConcept::NAMECONTAINER
| MethodConcept::INDEXCONTAINER
| MethodConcept::ENUMERATION
},
1137 { "getByName", MethodConcept::NAMECONTAINER
},
1138 { "getElementNames", MethodConcept::PROPERTY
| MethodConcept::NAMECONTAINER
},
1139 { "hasByName", MethodConcept::NAMECONTAINER
},
1140 { "getCount", MethodConcept::PROPERTY
| MethodConcept::INDEXCONTAINER
},
1141 { "getByIndex", MethodConcept::INDEXCONTAINER
},
1142 { "getTypes", MethodConcept::PROPERTY
},
1143 { "getImplementationId", MethodConcept::PROPERTY
},
1144 { "queryAdapter", MethodConcept_NORMAL_IMPL
},
1150 //******************************************************
1152 // Test-Objekt anlegen
1153 Any aObjAny
= getIntrospectionTestObject( xMgr
);
1155 // Introspection-Service holen
1156 //Reference< XMultiServiceFactory > xServiceManager(getProcessServiceManager(), USR_QUERY);
1157 //Reference< XIntrospection > xIntrospection( xMgr->createInstance(L"com.sun.star.beans.Introspection"), UNO_QUERY );
1158 //TEST_ENSHURE( xIntrospection.is(), "Creation of introspection instance failed" );
1159 //if( !xIntrospection.is() )
1163 Reference
< XIntrospectionAccess
> xAccess
= xIntrospection
->inspect( aObjAny
);
1164 xAccess
= xIntrospection
->inspect( aObjAny
);
1165 xAccess
= xIntrospection
->inspect( aObjAny
);
1166 TEST_ENSHURE( xAccess
.is(), "introspection failed, no XIntrospectionAccess returned" );
1170 // Ergebnis der Introspection pruefen
1172 // XPropertySet-UIK ermitteln
1173 Type aType
= getCppuType( (Reference
< XPropertySet
>*) NULL
);
1174 //typelib_InterfaceTypeDescription* pTypeDesc = NULL;
1175 //aType.getDescription( (typelib_TypeDescription**)&pTypeDesc );
1176 //Uik aPropertySetUik = *(Uik*)&pTypeDesc->aUik;
1177 //typelib_typedescription_release( (typelib_TypeDescription*)pTypeDesc );
1179 Reference
< XInterface
> xPropSetIface
= xAccess
->queryAdapter( aType
);
1180 //Reference< XInterface > xPropSetIface = xAccess->queryAdapter( aPropertySetUik );
1181 Reference
< XPropertySet
> xPropSet( xPropSetIface
, UNO_QUERY
);
1182 //XPropertySetRef xPropSet = (XPropertySet*)xPropSetIface->
1183 // queryInterface( XPropertySet::getSmartUik() );
1184 TEST_ENSHURE( xPropSet
.is(), "Could not get XPropertySet by queryAdapter()" );
1187 Reference
< XExactName
> xExactName( xAccess
, UNO_QUERY
);
1188 TEST_ENSHURE( xExactName
.is(), "Introspection unterstuetzt kein ExactName" );
1190 // Schleife ueber alle Kombinationen von Concepts
1191 for( sal_Int32 nConcepts
= 0 ; nConcepts
< 16 ; nConcepts
++ )
1193 //printf( "*******************************************************\n" );
1194 //printf( "nConcepts = %ld\n", nConcepts );
1196 // Wieviele Properties sollten es sein
1197 sal_Int32 nDemandedPropCount
= 0;
1198 sal_Int32 iList
= 0;
1199 while( pPropertyDefs
[ iList
].pName
)
1201 if( pPropertyDefs
[ iList
].nConcept
& nConcepts
)
1202 nDemandedPropCount
++;
1208 Reference
< XPropertySetInfo
> xPropSetInfo
= xPropSet
->getPropertySetInfo();
1209 //Sequence<Property> aRetSeq = xPropSetInfo->getProperties();
1210 Sequence
<Property
> aRetSeq
= xAccess
->getProperties( nConcepts
);
1212 sal_Int32 nLen
= aRetSeq
.getLength();
1214 aErrorStr
= "Expected to find ";
1215 aErrorStr
+= OString::valueOf( nDemandedPropCount
);
1216 aErrorStr
+= " properties but found ";
1217 aErrorStr
+= OString::valueOf( nLen
);
1218 TEST_ENSHURE( nLen
== nDemandedPropCount
, aErrorStr
.getStr() );
1220 // cout << "**********************************\n";
1221 // cout << "*** Ergebnis der Introspection ***\n";
1222 // cout << "**********************************\n";
1223 // cout << "\nIntrospection hat " << nLen << " Properties gefunden:\n";
1225 const Property
* pProps
= aRetSeq
.getConstArray();
1229 for( i
= 0 ; i
< nLen
; i
++ )
1231 const Property aProp
= pProps
[ i
];
1233 // Naechste Passende Methode in der Liste suchen
1234 while( pPropertyDefs
[ iList
].pName
)
1236 if( pPropertyDefs
[ iList
].nConcept
& nConcepts
)
1240 sal_Int32 iDemanded
= iList
;
1243 OUString aPropName
= aProp
.Name
;
1244 OString
aNameStr( aPropName
.getStr(), aPropName
.getLength(), RTL_TEXTENCODING_ASCII_US
);
1245 //UStringToString(aPropName, CHARSET_SYSTEM);
1247 //printf( "Property = %s\n", aNameStr.getStr() );
1249 OString aDemandedName
= pPropertyDefs
[ iDemanded
].pName
;
1250 //OString aDemandedName = pDemandedPropNames[ i ];
1251 aErrorStr
= "Expected property \"";
1252 aErrorStr
+= aDemandedName
;
1253 aErrorStr
+= "\", found \"";
1254 aErrorStr
+= aNameStr
;
1256 TEST_ENSHURE( aNameStr
== aDemandedName
, aErrorStr
.getStr() );
1257 // cout << "Property " << (i+1) << ": \"" << (const char*)UStringToString(aPropName, CHARSET_SYSTEM) << "\"";
1260 Type aPropType
= aProp
.Type
;
1261 OString
aTypeNameStr( OUStringToOString(aPropType
.getTypeName(), RTL_TEXTENCODING_ASCII_US
) );
1262 //Reference< XIdlClass > xPropType = aProp.Type;
1263 //OString aTypeNameStr( xPropType->getName(), xPropType->getName().getLength(), RTL_TEXTENCODING_ASCII_US );
1264 OString aDemandedTypeNameStr
= pDemandedPropTypes
[ iDemanded
];
1265 //OString aDemandedTypeNameStr = pDemandedPropTypes[ i ];
1266 aErrorStr
= "Property \"";
1267 aErrorStr
+= aDemandedName
;
1268 aErrorStr
+= "\", expected type >";
1269 aErrorStr
+= aDemandedTypeNameStr
;
1270 aErrorStr
+= "< found type >";
1271 aErrorStr
+= aTypeNameStr
;
1273 TEST_ENSHURE( aTypeNameStr
== aDemandedTypeNameStr
, aErrorStr
.getStr() );
1274 // cout << " (Prop-Typ: " << (const char*)UStringToString(xPropType->getName(), CHARSET_SYSTEM) << ")";
1276 // Wert des Property lesen und ausgeben
1277 aPropVal
= xPropSet
->getPropertyValue( aPropName
);
1278 // cout << "\n\tWert = " << (const char*)UStringToString(AnyToString( aPropVal, sal_True ), CHARSET_SYSTEM);
1280 OString aValStr
= OUStringToOString( AnyToString( aPropVal
, sal_False
, xMgr
), RTL_TEXTENCODING_ASCII_US
);
1281 OString aDemandedValStr
= pDemandedPropVals
[ iDemanded
];
1282 //OString aDemandedValStr = pDemandedPropVals[ i ];
1283 aErrorStr
= "Property \"";
1284 aErrorStr
+= aDemandedName
;
1285 aErrorStr
+= "\", expected val >";
1286 aErrorStr
+= aDemandedValStr
;
1287 aErrorStr
+= "< found val >";
1288 aErrorStr
+= aValStr
;
1290 TEST_ENSHURE( aValStr
== aDemandedValStr
, aErrorStr
.getStr() );
1292 // Wert pruefen und typgerecht modifizieren
1293 TypeClass eType
= aPropVal
.getValueType().getTypeClass();
1294 //Reference< XIdlClass > xIdlClass = aPropVal.getReflection()->getIdlClass();
1295 //TypeClass eType = xIdlClass->getTypeClass();
1297 sal_Bool bModify
= sal_True
;
1300 case TypeClass_STRING
:
1304 //OString aStr = aPropVal.getString();
1305 aStr
= aStr
+ OUString::createFromAscii(" (Modified!)");
1309 case TypeClass_DOUBLE
:
1313 aNewVal
<<= d
+ 1.0;
1316 case TypeClass_SHORT
:
1320 aNewVal
<<= sal_Int16( n
+ 1 );
1323 case TypeClass_LONG
:
1327 aNewVal
<<= sal_Int32( n
+ 1 );
1331 bModify
= sal_False
;
1335 // Modifizieren nur beim letzten Durchlauf
1336 if( nConcepts
== 15 )
1338 // XExactName pruefen, dafuer alles gross machen
1339 // (Introspection ist mit LowerCase implementiert, also anders machen)
1340 OUString aUpperUStr
= aPropName
.toAsciiUpperCase();
1341 OUString aExactName
= xExactName
->getExactName( aUpperUStr
);
1342 if( aExactName
!= aPropName
)
1344 aErrorStr
= "Property \"";
1345 aErrorStr
+= OUStringToOString( aPropName
, RTL_TEXTENCODING_ASCII_US
);
1346 aErrorStr
+= "\", not found as \"";
1347 aErrorStr
+= OUStringToOString(aUpperUStr
, RTL_TEXTENCODING_ASCII_US
);
1348 aErrorStr
+= "\" using XExactName";
1349 TEST_ENSHURE( sal_False
, aErrorStr
.getStr() );
1354 bModify
= sal_False
;
1357 // Neuen Wert setzen, wieder lesen und ausgeben
1362 // 1.7.1999, UnknownPropertyException bei ReadOnly-Properties abfangen
1365 xPropSet
->setPropertyValue( aPropName
, aNewVal
);
1367 catch(UnknownPropertyException e1
)
1371 aPropVal
= xPropSet
->getPropertyValue( aPropName
);
1372 // cout << "\n\tModifizierter Wert = " << (const char*) UStringToString(AnyToString( aPropVal, sal_True ), CHARSET_SYSTEM) << "\n";
1374 OUString aStr
= AnyToString( aPropVal
, sal_False
, xMgr
);
1375 OString aModifiedValStr
= OUStringToOString( aStr
, RTL_TEXTENCODING_ASCII_US
);
1376 OString aDemandedModifiedValStr
= pDemandedModifiedPropVals
[ i
];
1377 aErrorStr
= "Property \"";
1378 aErrorStr
+= aDemandedName
;
1379 aErrorStr
+= "\", expected modified val >";
1380 aErrorStr
+= aDemandedModifiedValStr
;
1381 aErrorStr
+= "< found val >";
1382 aErrorStr
+= aModifiedValStr
;
1384 TEST_ENSHURE( aModifiedValStr
== aDemandedModifiedValStr
, aErrorStr
.getStr() );
1388 // cout << "\n\tWert wurde nicht modifiziert\n";
1391 // Checken, ob alle Properties auch einzeln gefunden werden
1392 aErrorStr
= "property \"";
1393 aErrorStr
+= aDemandedName
;
1394 aErrorStr
+= "\" not found with hasProperty()";
1395 OUString aWDemandedName
= OStringToOUString(aDemandedName
, RTL_TEXTENCODING_ASCII_US
);
1396 sal_Bool bProperty
= xAccess
->hasProperty( aWDemandedName
, nConcepts
);
1397 //sal_Bool bProperty = xAccess->hasProperty( aWDemandedName, PropertyConcept::ALL - PropertyConcept::DANGEROUS );
1398 TEST_ENSHURE( bProperty
, aErrorStr
.getStr() );
1400 aErrorStr
= "property \"";
1401 aErrorStr
+= aDemandedName
;
1402 aErrorStr
+= "\" not equal to same Property in sequence returned by getProperties()";
1405 Property aGetProp
= xAccess
->getProperty( aWDemandedName
, nConcepts
);
1406 //Property aGetProp = xAccess->getProperty( aWDemandedName, PropertyConcept::ALL );
1407 //TEST_ENSHURE( aGetProp == aProp , aErrorStr.getStr() );
1409 catch (RuntimeException e1
)
1411 aErrorStr
= "property \"";
1412 aErrorStr
+= aDemandedName
;
1413 aErrorStr
+= "\", exception was thrown when trying getProperty()";
1414 TEST_ENSHURE( sal_False
, aErrorStr
.getStr() );
1421 // Schleife ueber alle Kombinationen von Concepts
1422 for( sal_Int32 nConcepts
= 0 ; nConcepts
< 128 ; nConcepts
++ )
1424 //printf( "*******************************************************\n" );
1425 //printf( "nConcepts = %ld\n", nConcepts );
1427 // Das 2^6-Bit steht fuer "den Rest"
1428 sal_Int32 nRealConcepts
= nConcepts
;
1429 if( nConcepts
& 0x40 )
1430 nRealConcepts
|= (0xFFFFFFFF - 0x3F);
1432 // Wieviele Methoden sollten es sein
1433 sal_Int32 nDemandedMethCount
= 0;
1434 sal_Int32 iList
= 0;
1435 while( pMethodDefs
[ iList
].pName
)
1437 if( pMethodDefs
[ iList
].nConcept
& nRealConcepts
)
1438 nDemandedMethCount
++;
1442 // Methoden-Array ausgeben
1443 //aMethodSeq = xAccess->getMethods
1444 Sequence
< Reference
< XIdlMethod
> > aMethodSeq
= xAccess
->getMethods( nRealConcepts
);
1445 //Sequence<XIdlMethodRef> aMethodSeq = xAccess->getMethods
1446 // ( MethodConcept::ALL - MethodConcept::DANGEROUS - MethodConcept::PROPERTY );
1447 sal_Int32 nLen
= aMethodSeq
.getLength();
1448 // cout << "\n\n*** Methoden ***\n";
1449 // cout << "Introspection hat " << nLen << " Methoden gefunden:\n";
1451 aErrorStr
= "Expected to find ";
1452 aErrorStr
+= OString::valueOf( nDemandedMethCount
);
1453 aErrorStr
+= " methods but found ";
1454 aErrorStr
+= OString::valueOf( nLen
);
1455 TEST_ENSHURE( nLen
== nDemandedMethCount
, aErrorStr
.getStr() );
1457 const Reference
< XIdlMethod
>* pMethods
= aMethodSeq
.getConstArray();
1461 for( i
= 0 ; i
< nLen
; i
++ )
1463 // Methode ansprechen
1464 const Reference
< XIdlMethod
>& rxMethod
= pMethods
[i
];
1467 OUString aMethName
= rxMethod
->getName();
1468 OString aNameStr
= OUStringToOString(aMethName
, RTL_TEXTENCODING_ASCII_US
);
1470 //printf( "Method = %s\n", aNameStr.getStr() );
1472 // Naechste Passende Methode in der Liste suchen
1473 while( pMethodDefs
[ iList
].pName
)
1475 if( pMethodDefs
[ iList
].nConcept
& nRealConcepts
)
1479 OString aDemandedName
= pMethodDefs
[ iList
].pName
;
1482 //OString aDemandedName = pDemandedMethNames[ i ];
1483 aErrorStr
= "Expected method \"";
1484 aErrorStr
+= aDemandedName
;
1485 aErrorStr
+= "\", found \"";
1486 aErrorStr
+= aNameStr
;
1488 TEST_ENSHURE( aNameStr
== aDemandedName
, aErrorStr
.getStr() );
1489 // cout << "Methode " << (i+1) << ": " << (const char*) UStringToString(rxMethod->getReturnType()->getName(), CHARSET_SYSTEM)
1490 // << " " << (const char*) UStringToString(rxMethod->getName(), CHARSET_SYSTEM) << "( ";
1492 // Checken, ob alle Methoden auch einzeln gefunden werden
1493 aErrorStr
= "method \"";
1494 aErrorStr
+= aDemandedName
;
1495 aErrorStr
+= "\" not found with hasMethod()";
1496 OUString aWDemandedName
= OStringToOUString(aDemandedName
, RTL_TEXTENCODING_ASCII_US
);
1497 sal_Bool bMethod
= xAccess
->hasMethod( aWDemandedName
, nRealConcepts
);
1498 //sal_Bool bMethod = xAccess->hasMethod( aWDemandedName, MethodConcept::ALL );
1499 TEST_ENSHURE( bMethod
, aErrorStr
.getStr() );
1501 aErrorStr
= "method \"";
1502 aErrorStr
+= aDemandedName
;
1503 aErrorStr
+= "\" not equal to same method in sequence returned by getMethods()";
1506 Reference
< XIdlMethod
> xGetMethod
= xAccess
->getMethod( aWDemandedName
, nRealConcepts
);
1507 //XIdlMethodRef xGetMethod = xAccess->getMethod( aWDemandedName, MethodConcept::ALL );
1508 TEST_ENSHURE( xGetMethod
== rxMethod
, aErrorStr
.getStr() );
1510 catch (RuntimeException e1
)
1512 aErrorStr
= "method \"";
1513 aErrorStr
+= aDemandedName
;
1514 aErrorStr
+= "\", exception was thrown when trying getMethod()";
1515 TEST_ENSHURE( sal_False
, aErrorStr
.getStr() );
1520 // Listener-Klassen ausgeben
1521 Sequence
< Type
> aClassSeq
= xAccess
->getSupportedListeners();
1522 sal_Int32 nLen
= aClassSeq
.getLength();
1523 // cout << "\n\n*** Anmeldbare Listener ***\n";
1524 // cout << "Introspection hat " << nLen << " Listener gefunden:\n";
1526 const Type
* pListeners
= aClassSeq
.getConstArray();
1527 for( sal_Int32 i
= 0 ; i
< nLen
; i
++ )
1529 // Methode ansprechen
1530 const Type
& aListenerType
= pListeners
[i
];
1533 OUString aListenerClassName
= aListenerType
.getTypeName();
1534 // cout << "Listener " << (i+1) << ": " << (const char*)UStringToString(aListenerClassName, CHARSET_SYSTEM) << "\n";
1538 // Performance bei hasMethod testen.
1539 //CheckMethodPerformance( xAccess, "queryInterface", 100000 );
1540 //CheckMethodPerformance( xAccess, "getIdlClasses", 100000 );
1551 SAL_IMPLEMENT_MAIN()
1553 Reference
< XMultiServiceFactory
> xMgr( createRegistryServiceFactory( OUString::createFromAscii("stoctest.rdb") ) );
1555 sal_Bool bSucc
= sal_False
;
1558 Reference
< XImplementationRegistration
> xImplReg(
1559 xMgr
->createInstance( OUString::createFromAscii("com.sun.star.registry.ImplementationRegistration") ), UNO_QUERY
);
1560 OSL_ENSURE( xImplReg
.is(), "### no impl reg!" );
1562 // Register services
1563 OUString
libName( RTL_CONSTASCII_USTRINGPARAM(
1564 "reflection.uno" SAL_DLLEXTENSION
) );
1565 // ORealDynamicLoader::computeLibraryName( OUString::createFromAscii("corefl"), libName);
1566 fprintf(stderr
, "1\n" );
1567 xImplReg
->registerImplementation(OUString::createFromAscii("com.sun.star.loader.SharedLibrary"),
1568 libName
, Reference
< XSimpleRegistry
>() );
1569 fprintf(stderr
, "2\n" );
1570 Reference
< XIdlReflection
> xRefl( xMgr
->createInstance( OUString::createFromAscii("com.sun.star.reflection.CoreReflection") ), UNO_QUERY
);
1571 OSL_ENSURE( xRefl
.is(), "### no corereflection!" );
1574 libName
= OUString::createFromAscii(
1575 "introspection.uno" SAL_DLLEXTENSION
);
1576 // ORealDynamicLoader::computeLibraryName( OUString::createFromAscii("insp"), libName);
1577 fprintf(stderr
, "3\n" );
1578 xImplReg
->registerImplementation(OUString::createFromAscii("com.sun.star.loader.SharedLibrary"),
1579 libName
, Reference
< XSimpleRegistry
>() );
1580 fprintf(stderr
, "4\n" );
1581 Reference
< XIntrospection
> xIntrosp( xMgr
->createInstance( OUString::createFromAscii("com.sun.star.beans.Introspection") ), UNO_QUERY
);
1582 OSL_ENSURE( xRefl
.is(), "### no corereflection!" );
1584 fprintf(stderr
, "before test_introsp\n" );
1585 bSucc
= test_introsp( xMgr
, xRefl
, xIntrosp
);
1586 fprintf(stderr
, "after test_introsp\n" );
1587 //bSucc = test_corefl( xRefl );
1589 catch (Exception
& rExc
)
1591 OSL_ENSURE( sal_False
, "### exception occured!" );
1592 OString
aMsg( OUStringToOString( rExc
.Message
, RTL_TEXTENCODING_ASCII_US
) );
1593 OSL_TRACE( "### exception occured: " );
1594 OSL_TRACE( aMsg
.getStr() );
1598 Reference
< XComponent
>( xMgr
, UNO_QUERY
)->dispose();
1600 printf( "testintrosp %s !\n", (bSucc
? "succeeded" : "failed") );
1601 return (bSucc
? 0 : -1);
1610 //*****************************
1611 //*** TEST-Implementationen ***
1612 //*****************************
1613 // Bleibt auf Dauer nicht drin, dient als exportierbare Test-Klasse
1614 // z.B. fuer Basic-Anbindung