xref: /trunk/main/stoc/test/testintrosp.cxx (revision 91144cd0085a7583d2099b982122deb2184ab956)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_stoc.hxx"
26 
27 #include <sal/main.h>
28 #include <cppuhelper/implbase1.hxx>
29 #include <cppuhelper/implbase4.hxx>
30 #include <cppuhelper/servicefactory.hxx>
31 #include <osl/diagnose.h>
32 
33 //#include <vos/dynload.hxx>
34 
35 #include <ModuleA/XIntroTest.hpp>
36 #include <com/sun/star/beans/XPropertySet.hpp>
37 #include <com/sun/star/beans/XIntrospection.hpp>
38 #include <com/sun/star/beans/PropertyAttribute.hpp>
39 #include <com/sun/star/beans/PropertyConcept.hpp>
40 #include <com/sun/star/beans/MethodConcept.hpp>
41 #include <com/sun/star/beans/XExactName.hpp>
42 #include <com/sun/star/container/XElementAccess.hpp>
43 #include <com/sun/star/container/XNameAccess.hpp>
44 #include <com/sun/star/container/XIndexAccess.hpp>
45 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
46 #include <com/sun/star/reflection/XIdlReflection.hpp>
47 //#include <com/sun/star/registry/XSimpleRegistry.hpp>
48 #include <com/sun/star/registry/XImplementationRegistration.hpp>
49 #include <com/sun/star/lang/XComponent.hpp>
50 
51 #include <stdio.h>
52 #include <string.h>
53 
54 
55 using namespace rtl;
56 using namespace cppu;
57 //using namespace vos;
58 using namespace ModuleA;
59 //using namespace ModuleB;
60 //using namespace ModuleC;
61 //using namespace ModuleA::ModuleB;
62 using namespace com::sun::star::uno;
63 using namespace com::sun::star::lang;
64 using namespace com::sun::star::beans;
65 using namespace com::sun::star::registry;
66 using namespace com::sun::star::reflection;
67 using namespace com::sun::star::container;
68 using namespace com::sun::star::beans::PropertyAttribute;
69 
70 
71 typedef WeakImplHelper4< XIntroTest, XPropertySet, XNameAccess, XIndexAccess > ImplIntroTestHelper;
72 typedef WeakImplHelper1< XPropertySetInfo > ImplPropertySetInfoHelper;
73 
74 
75 #define DEFAULT_INDEX_ACCESS_COUNT  10
76 #define DEFAULT_NAME_ACCESS_COUNT   5
77 
78 #if OSL_DEBUG_LEVEL > 0
79 #define TEST_ENSHURE(c, m)   OSL_ENSURE(c, m)
80 #else
81 #define TEST_ENSHURE(c, m)   OSL_VERIFY(c)
82 #endif
83 
84 //class IntroTestWritelnOutput;
85 
86 
87 
88 //**************************************************************
89 //*** Hilfs-Funktion, um vom Type eine XIdlClass zu bekommen ***
90 //**************************************************************
TypeToIdlClass(const Type & rType,const Reference<XMultiServiceFactory> & xMgr)91 Reference<XIdlClass> TypeToIdlClass( const Type& rType, const Reference< XMultiServiceFactory > & xMgr )
92 {
93     static Reference< XIdlReflection > xRefl;
94 
95     // void als Default-Klasse eintragen
96     Reference<XIdlClass> xRetClass;
97     typelib_TypeDescription * pTD = 0;
98     rType.getDescription( &pTD );
99     if( pTD )
100     {
101         OUString sOWName( pTD->pTypeName );
102         if( !xRefl.is() )
103         {
104             xRefl = Reference< XIdlReflection >( xMgr->createInstance(
105                 OUString::createFromAscii("com.sun.star.reflection.CoreReflection") ), UNO_QUERY );
106             OSL_ENSURE( xRefl.is(), "### no corereflection!" );
107         }
108         xRetClass = xRefl->forName( sOWName );
109     }
110     return xRetClass;
111 }
112 
113 
114 //****************************************************
115 //*** Hilfs-Funktion, um Any als UString auszugeben ***
116 //****************************************************
117 // ACHTUNG: Kann mal an eine zentrale Stelle uebernommen werden
118 // Wird zunaechst nur fuer einfache Datentypen ausgefuehrt
119 
AnyToString(const Any & aValue,sal_Bool bIncludeType,const Reference<XMultiServiceFactory> & xMgr)120 OUString AnyToString( const Any& aValue, sal_Bool bIncludeType, const Reference< XMultiServiceFactory > & xMgr )
121 {
122     Type aValType = aValue.getValueType();
123     TypeClass eType = aValType.getTypeClass();
124     char pBuffer[50];
125 
126     OUString aRetStr;
127     switch( eType )
128     {
129         case TypeClass_TYPE:            aRetStr = OUString::createFromAscii("TYPE TYPE");               break;
130         case TypeClass_INTERFACE:       aRetStr = OUString::createFromAscii("TYPE INTERFACE");      break;
131         case TypeClass_SERVICE:         aRetStr = OUString::createFromAscii("TYPE SERVICE");            break;
132         case TypeClass_STRUCT:          aRetStr = OUString::createFromAscii("TYPE STRUCT");         break;
133         case TypeClass_TYPEDEF:         aRetStr = OUString::createFromAscii("TYPE TYPEDEF");            break;
134         case TypeClass_UNION:           aRetStr = OUString::createFromAscii("TYPE UNION");          break;
135         case TypeClass_ENUM:            aRetStr = OUString::createFromAscii("TYPE ENUM");               break;
136         case TypeClass_EXCEPTION:       aRetStr = OUString::createFromAscii("TYPE EXCEPTION");      break;
137         case TypeClass_ARRAY:           aRetStr = OUString::createFromAscii("TYPE ARRAY");          break;
138         case TypeClass_SEQUENCE:        aRetStr = OUString::createFromAscii("TYPE SEQUENCE");           break;
139         case TypeClass_VOID:            aRetStr = OUString::createFromAscii("TYPE void");               break;
140         case TypeClass_ANY:             aRetStr = OUString::createFromAscii("TYPE any");                break;
141         case TypeClass_UNKNOWN:         aRetStr = OUString::createFromAscii("TYPE unknown");            break;
142         case TypeClass_BOOLEAN:
143         {
144             sal_Bool b = *(sal_Bool*)aValue.getValue();
145             //aRet.setValue( &b, getCppuBooleanType() );
146             //aValue >>= b;
147             aRetStr = OUString::valueOf( b );
148             break;
149         }
150         case TypeClass_CHAR:
151         {
152             sal_Unicode c = *(sal_Unicode*)aValue.getValue();
153             //aValue >>= c;
154             //getCppuCharType()
155             aRetStr = OUString::valueOf( c );
156             break;
157         }
158         case TypeClass_STRING:
159         {
160             aValue >>= aRetStr;
161             break;
162         }
163         case TypeClass_FLOAT:
164         {
165             float f(0.0);
166             aValue >>= f;
167             snprintf( pBuffer, sizeof( pBuffer ), "%f", f );
168             aRetStr = OUString( pBuffer, strlen( pBuffer ), RTL_TEXTENCODING_ASCII_US );
169             break;
170         }
171         case TypeClass_DOUBLE:
172         {
173             double d(0.0);
174             aValue >>= d;
175             snprintf( pBuffer, sizeof( pBuffer ), "%f", d );
176             aRetStr = OUString( pBuffer, strlen( pBuffer ), RTL_TEXTENCODING_ASCII_US );
177             break;
178         }
179         case TypeClass_BYTE:
180         {
181             sal_Int8 n(0);
182             aValue >>= n;
183             aRetStr = OUString::valueOf( (sal_Int32) n );
184             break;
185         }
186         case TypeClass_SHORT:
187         {
188             sal_Int16 n(0);
189             aValue >>= n;
190             aRetStr = OUString::valueOf( (sal_Int32) n );
191             break;
192         }
193         case TypeClass_LONG:
194         {
195             sal_Int32 n(0);
196             aValue >>= n;
197             aRetStr = OUString::valueOf( n );
198             break;
199         }
200         /*
201         case TypeClass_HYPER:
202         {
203             aRetStr = L"TYPE HYPER";
204             break;
205         }
206         case TypeClass_UNSIGNED_SHORT:
207         {
208             aRetStr = StringToUString(WSString(aValue.getUINT16()), CHARSET_SYSTEM);
209             break;
210         }
211         case TypeClass_UNSIGNED_LONG:
212         {
213             aRetStr = StringToUString(WSString(aValue.getUINT32()), CHARSET_SYSTEM);
214             break;
215         }
216         case TypeClass_UNSIGNED_HYPER:
217         {
218             aRetStr = L"TYPE UNSIGNED_HYPER";
219             break;
220         }
221         */
222     default: ;
223     }
224 
225     if( bIncludeType )
226     {
227         Reference< XIdlClass > xIdlClass = TypeToIdlClass( aValType, xMgr );
228         aRetStr = aRetStr + OUString( OUString::createFromAscii(" (Typ: ") ) + xIdlClass->getName() + OUString::createFromAscii(")");
229     }
230     return aRetStr;
231 }
232 
233 /*
234 // Hilfs-Funktion, um ein UString in einen Any zu konvertieren
235 UsrAny StringToAny( UString aStr, TypeClass eTargetType )
236 {
237     UsrAny aRetAny;
238     switch( eTargetType )
239     {
240         case TypeClass_INTERFACE:       break;
241         case TypeClass_SERVICE:         break;
242         case TypeClass_STRUCT:          break;
243         case TypeClass_TYPEDEF:         break;
244         case TypeClass_UNION:           break;
245         case TypeClass_ENUM:            break;
246         case TypeClass_EXCEPTION:       break;
247         case TypeClass_ARRAY:           break;
248         case TypeClass_SEQUENCE:        break;
249         case TypeClass_VOID:            break;
250         case TypeClass_ANY:             break;
251         case TypeClass_UNKNOWN:         break;
252         case TypeClass_BOOLEAN:         aRetAny.setBOOL( short(aStr)!=0 );  break;
253         case TypeClass_CHAR:            aRetAny.setChar( char(aStr) );      break;
254         case TypeClass_STRING:          aRetAny.setString( aStr );          break;
255         case TypeClass_FLOAT:           aRetAny.setFloat( (float)strtod( aStr.GetStr(), NULL ) );   break;
256         case TypeClass_DOUBLE:          aRetAny.setDouble( strtod( aStr.GetStr(), NULL ) ); break;
257         case TypeClass_BYTE:            aRetAny.setBYTE( BYTE(short(aStr)) );   break;
258         case TypeClass_SHORT:           aRetAny.setINT16( short(aStr) );    break;
259         case TypeClass_LONG:            aRetAny.setINT32( long(aStr) );     break;
260         case TypeClass_HYPER:           break;
261         case TypeClass_UNSIGNED_SHORT:  aRetAny.setUINT16( USHORT(aStr) );  break;
262         case TypeClass_UNSIGNED_LONG:   aRetAny.setUINT32( ULONG(aStr) );   break;
263         case TypeClass_UNSIGNED_HYPER:  break;
264     }
265     return aRetAny;
266 }
267 */
268 
269 
270 //*****************************************
271 //*** XPropertySetInfo fuer Test-Klasse ***
272 //*****************************************
273 
274 class ImplPropertySetInfo : public ImplPropertySetInfoHelper
275 {
276     friend class ImplIntroTest;
277 
278     Reference< XMultiServiceFactory > mxMgr;
279 
280 public:
ImplPropertySetInfo(const Reference<XMultiServiceFactory> & xMgr)281     ImplPropertySetInfo( const Reference< XMultiServiceFactory > & xMgr )
282         : mxMgr( xMgr ) {}
283         //: mxMgr( xMgr ), ImplPropertySetInfoHelper( xMgr ) {}
284 
285 /*
286     // Methoden von XInterface
287     virtual sal_Bool    SAL_CALL queryInterface( const Uik & rUik, Any & ifc ) throw( RuntimeException );
288     virtual void        SAL_CALL acquire() throw() { OWeakObject::acquire(); }
289     virtual void        SAL_CALL release() throw() { OWeakObject::release(); }
290     //ALT: sal_Bool queryInterface( Uik aUik, Reference<XInterface> & rOut );
291 */
292 
293     // Methods of XPropertySetInfo
294     virtual Sequence< Property > SAL_CALL getProperties(  );
295     virtual Property SAL_CALL getPropertyByName( const OUString& aName );
296     virtual sal_Bool SAL_CALL hasPropertyByName( const OUString& Name );
297     //virtual Sequence< Property > SAL_CALL getProperties(void) throw( RuntimeException );
298     //virtual Property SAL_CALL getPropertyByName(const OUString& Name) throw( RuntimeException );
299     //virtual sal_Bool SAL_CALL hasPropertyByName(const OUString& Name) throw( RuntimeException );
300 };
301 
302 
303 /*
304 // Methoden von XInterface
305 sal_Bool SAL_CALL ImplPropertySetInfo::queryInterface( const Uik & rUik, Any & ifc )
306     throw( RuntimeException )
307 {
308     // PropertySet-Implementation
309     if( com::sun::star::uno::queryInterface( rUik, ifc,
310                                              SAL_STATIC_CAST(XPropertySetInfo*, this) ) )
311         return sal_True;
312 
313     return OWeakObject::queryInterface( rUik, ifc );
314 }
315 
316 sal_Bool ImplPropertySetInfo::queryInterface( Uik aUik, Reference<XInterface> & rOut )
317 {
318     if( aUik == XPropertySetInfo::getSmartUik() )
319         rOut = (XPropertySetInfo *)this;
320     else
321         UsrObject::queryInterface( aUik, rOut );
322     return rOut.is();
323 }
324 */
325 
getProperties(void)326 Sequence< Property > ImplPropertySetInfo::getProperties(void)
327 {
328     static Sequence<Property> * pSeq = NULL;
329 
330     if( !pSeq )
331     {
332         // die Informationen f�r die Properties "Width", "Height" und "Name" anlegen
333         pSeq = new Sequence<Property>( 3 );
334         Property * pAry = pSeq->getArray();
335 
336         pAry[0].Name = OUString::createFromAscii("Factor");
337         pAry[0].Handle = -1;
338         pAry[0].Type = getCppuType( (double*) NULL );
339         //pAry[0].Type = TypeToIdlClass( getCppuType( (double*) NULL ), mxMgr );
340         //pAry[0].Type = Double_getReflection()->getIdlClass();
341         pAry[0].Attributes = BOUND | TRANSIENT;
342 
343         pAry[1].Name = OUString::createFromAscii("MyCount");
344         pAry[1].Handle = -1;
345         pAry[1].Type = getCppuType( (sal_Int32*) NULL );
346         //pAry[1].Type = TypeToIdlClass( getCppuType( (sal_Int32*) NULL ), mxMgr );
347         //pAry[1].Type = INT32_getReflection()->getIdlClass();
348         pAry[1].Attributes = BOUND | TRANSIENT;
349 
350         pAry[2].Name = OUString::createFromAscii("Info");
351         pAry[2].Handle = -1;
352         pAry[2].Type = getCppuType( (OUString*) NULL );
353         //pAry[2].Type = TypeToIdlClass( getCppuType( (OUString*) NULL ), mxMgr );
354         //pAry[2].Type = OUString_getReflection()->getIdlClass();
355         pAry[2].Attributes = TRANSIENT;
356     }
357     // Die Information �ber alle drei Properties liefern.
358     return *pSeq;
359 }
360 
getPropertyByName(const OUString & Name)361 Property ImplPropertySetInfo::getPropertyByName(const OUString& Name)
362 {
363     Sequence<Property> aSeq = getProperties();
364     const Property * pAry = aSeq.getConstArray();
365 
366     for( sal_Int32 i = aSeq.getLength(); i--; )
367     {
368         if( pAry[i].Name == Name )
369             return pAry[i];
370     }
371     // Property unbekannt, also leere liefern
372     return Property();
373 }
374 
hasPropertyByName(const OUString & Name)375 sal_Bool ImplPropertySetInfo::hasPropertyByName(const OUString& Name)
376 {
377     Sequence<Property> aSeq = getProperties();
378     const Property * pAry = aSeq.getConstArray();
379 
380     for( sal_Int32 i = aSeq.getLength(); i--; )
381     {
382         if( pAry[i].Name == Name )
383             return sal_True;
384     }
385     // Property unbekannt, also leere liefern
386     return sal_False;
387 }
388 
389 
390 
391 
392 //*****************************************************************
393 
394 
395 
396 class ImplIntroTest : public ImplIntroTestHelper
397 {
398     Reference< XMultiServiceFactory > mxMgr;
399 
400     friend class ImplPropertySetInfo;
401 
402     // Properties fuer das PropertySet
403     Any aAnyArray[10];
404 
405     // Optionale Schnittstelle fuer die writeln-Ausgabe
406     //IntroTestWritelnOutput* m_pOutput;
407 
408     Reference< XPropertySetInfo > m_xMyInfo;
409 
410     OUString m_ObjectName;
411 
412     sal_Int16 m_nMarkusAge;
413     sal_Int16 m_nMarkusChildrenCount;
414 
415     long m_lDroenk;
416     sal_Int16 m_nBla;
417     sal_Int16 m_nBlub;
418     sal_Int16 m_nGulp;
419     sal_Int16 m_nLaber;
420     TypeClass eTypeClass;
421     Sequence< OUString > aStringSeq;
422     Sequence< Sequence< Sequence< sal_Int16 > > > aMultSeq;
423     Reference< XIntroTest > m_xIntroTest;
424 
425     // Daten fuer NameAccess
426     Reference< XIntroTest >* pNameAccessTab;
427 
428     // Daten fuer IndexAccess
429     Reference< XIntroTest >* pIndexAccessTab;
430     sal_Int16 iIndexAccessCount;
431 
432     // struct-Properties
433     Property m_aFirstStruct;
434     PropertyValue m_aSecondStruct;
435 
436     // Listener merken (zunaechst einfach, nur einen pro Property)
437     Reference< XPropertyChangeListener > aPropChangeListener;
438     OUString aPropChangeListenerStr;
439     Reference< XVetoableChangeListener > aVetoPropChangeListener;
440     OUString aVetoPropChangeListenerStr;
441 
442     void Init( void );
443 
444 public:
ImplIntroTest(const Reference<XMultiServiceFactory> & xMgr)445     ImplIntroTest( const Reference< XMultiServiceFactory > & xMgr )
446         : mxMgr( xMgr )
447         //: mxMgr( xMgr ), ImplIntroTestHelper( xMgr )
448     {
449         Init();
450     }
451 
452     /*
453     ImplIntroTest( IntroTestWritelnOutput* pOutput_ )
454     {
455         Init();
456         m_pOutput = pOutput_;
457     }
458     */
459 
460     //SMART_UNO_DECLARATION(ImplIntroTest,UsrObject);
461 
462     //BOOL queryInterface( Uik aUik, Reference< XInterface > & rOut );
463     //Reference< XIdlClass > getIdlClass();
464 
465     // Trotz virtual inline, um Schreibarbeit zu sparen (nur fuer Testzwecke)
466     // XPropertySet
467     virtual Reference< XPropertySetInfo > SAL_CALL getPropertySetInfo(  );
468     virtual void SAL_CALL setPropertyValue( const OUString& aPropertyName, const Any& aValue );
469     virtual Any SAL_CALL getPropertyValue( const OUString& PropertyName );
addPropertyChangeListener(const OUString &,const Reference<XPropertyChangeListener> &)470     virtual void SAL_CALL addPropertyChangeListener( const OUString& /*aPropertyName*/, const Reference< XPropertyChangeListener >& /*xListener*/ )
471             {}
removePropertyChangeListener(const OUString &,const Reference<XPropertyChangeListener> &)472     virtual void SAL_CALL removePropertyChangeListener( const OUString& /*aPropertyName*/, const Reference< XPropertyChangeListener >& /*aListener*/ )
473             {}
addVetoableChangeListener(const OUString &,const Reference<XVetoableChangeListener> &)474     virtual void SAL_CALL addVetoableChangeListener( const OUString& /*PropertyName*/, const Reference< XVetoableChangeListener >& /*aListener*/ )
475             {}
removeVetoableChangeListener(const OUString &,const Reference<XVetoableChangeListener> &)476     virtual void SAL_CALL removeVetoableChangeListener( const OUString& /*PropertyName*/, const Reference< XVetoableChangeListener >& /*aListener*/ )
477             {}
478 
479     /*
480     virtual void setIndexedPropertyValue(const OUString& aPropertyName, INT32 nIndex, const Any& aValue) {}
481     virtual Any getIndexedPropertyValue(const UString& aPropertyName, INT32 nIndex) const { return Any(); }
482     virtual void addPropertyChangeListener(const UString& aPropertyName, const XPropertyChangeListenerRef& aListener)
483         THROWS( (UnknownPropertyException, WrappedTargetException, UsrSystemException) ) {}
484     virtual void removePropertyChangeListener(const UString& aPropertyName, const XPropertyChangeListenerRef& aListener)
485         THROWS( (UnknownPropertyException, WrappedTargetException, UsrSystemException) ) {}
486     virtual void addVetoableChangeListener(const UString& aPropertyName, const XVetoableChangeListenerRef& aListener)
487         THROWS( (UnknownPropertyException, WrappedTargetException, UsrSystemException) ) {}
488     virtual void removeVetoableChangeListener(const UString& aPropertyName, const XVetoableChangeListenerRef& aListener)
489         THROWS( (UnknownPropertyException, WrappedTargetException, UsrSystemException) ) {}
490         */
491 
492     // XIntroTest-Methoden
493     // Attributes
getObjectName()494     virtual OUString SAL_CALL getObjectName()
495         { return m_ObjectName; }
setObjectName(const OUString & _objectname)496     virtual void SAL_CALL setObjectName( const OUString& _objectname )
497         { m_ObjectName = _objectname; }
498     virtual OUString SAL_CALL getFirstName();
getLastName()499     virtual OUString SAL_CALL getLastName()
500         { return OUString( OUString::createFromAscii("Meyer") ); }
getAge()501     virtual sal_Int16 SAL_CALL getAge()
502         { return m_nMarkusAge; }
getChildrenCount()503     virtual sal_Int16 SAL_CALL getChildrenCount()
504         { return m_nMarkusChildrenCount; }
setChildrenCount(sal_Int16 _childrencount)505     virtual void SAL_CALL setChildrenCount( sal_Int16 _childrencount )
506         { m_nMarkusChildrenCount = _childrencount; }
getFirstStruct()507     virtual Property SAL_CALL getFirstStruct()
508         { return m_aFirstStruct; }
setFirstStruct(const Property & _firststruct)509     virtual void SAL_CALL setFirstStruct( const Property& _firststruct )
510         { m_aFirstStruct = _firststruct; }
getSecondStruct()511     virtual PropertyValue SAL_CALL getSecondStruct()
512         { return m_aSecondStruct; }
setSecondStruct(const PropertyValue & _secondstruct)513     virtual void SAL_CALL setSecondStruct( const PropertyValue& _secondstruct )
514         { m_aSecondStruct = _secondstruct; }
515 
516     // Methods
517     virtual void SAL_CALL writeln( const OUString& Text );
getDroenk()518     virtual sal_Int32 SAL_CALL getDroenk(  )
519         { return m_lDroenk; }
520     virtual Reference< ::ModuleA::XIntroTest > SAL_CALL getIntroTest(  );
getUps(sal_Int32 l)521     virtual sal_Int32 SAL_CALL getUps( sal_Int32 l )
522         { return 2*l; }
setDroenk(sal_Int32 l)523     virtual void SAL_CALL setDroenk( sal_Int32 l )
524         { m_lDroenk = l; }
getBla()525     virtual sal_Int16 SAL_CALL getBla(  )
526         { return m_nBla; }
setBla(sal_Int32 n)527     virtual void SAL_CALL setBla( sal_Int32 n )
528         { m_nBla = (sal_Int16)n; }
getBlub()529     virtual sal_Int16 SAL_CALL getBlub(  )
530         { return m_nBlub; }
setBlub(sal_Int16 n)531     virtual void SAL_CALL setBlub( sal_Int16 n )
532         { m_nBlub = n; }
getGulp()533     virtual sal_Int16 SAL_CALL getGulp(  )
534         { return m_nGulp; }
setGulp(sal_Int16 n)535     virtual sal_Int16 SAL_CALL setGulp( sal_Int16 n )
536         { m_nGulp = n; return 1; }
getTypeClass(sal_Int16)537     virtual TypeClass SAL_CALL getTypeClass( sal_Int16 /*n*/ )
538         { return eTypeClass; }
setTypeClass(TypeClass t,double,double)539     virtual void SAL_CALL setTypeClass( TypeClass t, double /*d1*/, double /*d2*/ )
540         { eTypeClass = t; }
getStrings()541     virtual Sequence< OUString > SAL_CALL getStrings(  )
542         { return aStringSeq; }
setStrings(const Sequence<OUString> & Strings)543     virtual void SAL_CALL setStrings( const Sequence< OUString >& Strings )
544         { aStringSeq = Strings; }
setStringsPerMethod(const Sequence<OUString> & Strings,sal_Int16)545     virtual void SAL_CALL setStringsPerMethod( const Sequence< OUString >& Strings, sal_Int16 /*n*/ )
546         { aStringSeq = Strings; }
getMultiSequence()547     virtual Sequence< Sequence< Sequence< sal_Int16 > > > SAL_CALL getMultiSequence(  )
548         { return aMultSeq; }
setMultiSequence(const Sequence<Sequence<Sequence<sal_Int16>>> & Seq)549     virtual void SAL_CALL setMultiSequence( const Sequence< Sequence< Sequence< sal_Int16 > > >& Seq )
550         { aMultSeq = Seq; }
551     virtual void SAL_CALL addPropertiesChangeListener( const Sequence< OUString >& PropertyNames, const Reference< XPropertiesChangeListener >& Listener );
552     virtual void SAL_CALL removePropertiesChangeListener( const Reference< XPropertiesChangeListener >& Listener );
553 
554 
555     // Methods of XElementAccess
556     virtual Type SAL_CALL getElementType(  );
557     virtual sal_Bool SAL_CALL hasElements(  );
558     //virtual XIdlClassRef getElementType(void) constTHROWS( (UsrSystemException) );
559     //virtual BOOL hasElements(void) const THROWS( (UsrSystemException) );
560 
561     // XNameAccess-Methoden
562     // Methods
563     virtual Any SAL_CALL getByName( const OUString& aName );
564     virtual Sequence< OUString > SAL_CALL getElementNames(  );
565     virtual sal_Bool SAL_CALL hasByName( const OUString& aName );
566     //virtual Any getByName(const UString& Name) const
567         //THROWS( (NoSuchElementException, WrappedTargetException, UsrSystemException) );
568     //virtual Sequence<UString> getElementNames(void) const THROWS( (UsrSystemException) );
569     //virtual BOOL hasByName(const UString& Name) const THROWS( (UsrSystemException) );
570 
571     // XIndexAccess-Methoden
572     // Methods
573     virtual sal_Int32 SAL_CALL getCount(  );
574     virtual Any SAL_CALL getByIndex( sal_Int32 Index );
575     //virtual INT32 getCount(void) const THROWS( (UsrSystemException) );
576     //virtual Any getByIndex(INT32 Index) const
577         //THROWS( (IndexOutOfBoundsException, WrappedTargetException, UsrSystemException) );
578 };
579 
580 //SMART_UNO_IMPLEMENTATION(ImplIntroTest,UsrObject)
581 
Init(void)582 void ImplIntroTest::Init( void )
583 {
584     // Eindeutigen Namen verpassen
585     static sal_Int32 nObjCount = 0;
586     OUString aName( OUString::createFromAscii("IntroTest-Obj Nr. ") );
587     aName += OUString::valueOf( nObjCount );
588     setObjectName( aName );
589 
590     // Properties initialisieren
591     aAnyArray[0] <<= 3.14;
592     aAnyArray[1] <<= (sal_Int32)42;
593     aAnyArray[2] <<= OUString( OUString::createFromAscii("Hallo") );
594 
595     // Output-Interface
596     //m_pOutput = NULL;
597 
598     // Einmal fuer den internen Gebrauch die PropertySetInfo abholen
599     m_xMyInfo = getPropertySetInfo();
600     m_xMyInfo->acquire();       // sonst raucht es am Programm-Ende ab
601 
602     m_nMarkusAge = 33;
603     m_nMarkusChildrenCount = 2;
604 
605     m_lDroenk = 314;
606     m_nBla = 42;
607     m_nBlub = 111;
608     m_nGulp = 99;
609     m_nLaber = 1;
610     eTypeClass = TypeClass_INTERFACE;
611 
612     // String-Sequence intitialisieren
613     aStringSeq.realloc( 3 );
614     OUString* pStr = aStringSeq.getArray();
615     pStr[ 0 ] = OUString( OUString::createFromAscii("String 0") );
616     pStr[ 1 ] = OUString( OUString::createFromAscii("String 1") );
617     pStr[ 2 ] = OUString( OUString::createFromAscii("String 2") );
618 
619     // structs initialisieren
620     m_aFirstStruct.Name = OUString::createFromAscii("FirstStruct-Name");
621     m_aFirstStruct.Handle = 77777;
622     //XIdlClassRef Type;
623     m_aFirstStruct.Attributes = -222;
624 
625     //XInterfaceRef Source;
626     Any Value;
627     Value <<= 2.718281828459;
628     m_aSecondStruct.Value = Value;
629     //XIdlClassRef ListenerType;
630     m_aSecondStruct.State = PropertyState_DIRECT_VALUE;
631 
632     // IndexAccess
633     iIndexAccessCount = DEFAULT_INDEX_ACCESS_COUNT;
634     pIndexAccessTab = NULL;
635     pNameAccessTab = NULL;
636 }
637 
638 /*
639 BOOL ImplIntroTest::queryInterface( Uik aUik, XInterfaceRef & rOut )
640 {
641     if( aUik == XIntroTest::getSmartUik() )
642         rOut = (XIntroTest*)this;
643     else if( aUik == XPropertySet::getSmartUik() )
644         rOut = (XPropertySet*)this;
645     else if( aUik == XNameAccess::getSmartUik() )
646         rOut = (XNameAccess*)this;
647     else if( aUik == XIndexAccess::getSmartUik() )
648         rOut = (XIndexAccess*)this;
649     else if( aUik == ((XElementAccess*)NULL)->getSmartUik() )
650         rOut = (XElementAccess*)(XIndexAccess *)this;
651     else
652         UsrObject::queryInterface( aUik, rOut );
653     return rOut.is();
654 }
655 
656 XIdlClassRef ImplIntroTest::getIdlClass()
657 {
658     static XIdlClassRef xClass = createStandardClass( L"ImplIntroTest",
659         UsrObject::getUsrObjectIdlClass(), 4,
660             XIntroTest_getReflection(),
661             XPropertySet_getReflection(),
662             XNameAccess_getReflection(),
663             XIndexAccess_getReflection() );
664     return xClass;
665 }
666 */
667 
getPropertySetInfo()668 Reference< XPropertySetInfo > ImplIntroTest::getPropertySetInfo()
669 {
670     static ImplPropertySetInfo aInfo( mxMgr );
671     // Alle Objekt haben die gleichen Properties, deshalb kann
672     // die Info f�r alle gleich sein
673     return &aInfo;
674 
675     //if( m_xMyInfo == NULL )
676     //  ((ImplIntroTest*)this)->m_xMyInfo = new ImplPropertySetInfo( this );
677     //return m_xMyInfo;
678 }
679 
setPropertyValue(const OUString & aPropertyName,const Any & aValue)680 void ImplIntroTest::setPropertyValue( const OUString& aPropertyName, const Any& aValue )
681 //void ImplIntroTest::setPropertyValue( const UString& aPropertyName, const Any& aValue )
682 //  THROWS( (UnknownPropertyException, PropertyVetoException, IllegalArgumentException, WrappedTargetException, UsrSystemException) )
683 {
684     if( aPropChangeListener.is() && aPropertyName == aPropChangeListenerStr )
685     {
686         PropertyChangeEvent aEvt;
687         aEvt.Source = (OWeakObject*)this;
688         aEvt.PropertyName = aPropertyName;
689         aEvt.PropertyHandle = 0L;
690         //aEvt.OldValue;
691         //aEvt.NewValue;
692         //aEvt.PropagationId;
693         aPropChangeListener->propertyChange( aEvt );
694     }
695     if( aVetoPropChangeListener.is() && aPropertyName == aVetoPropChangeListenerStr )
696     {
697         PropertyChangeEvent aEvt;
698         aEvt.Source = (OWeakObject*)this;
699         aEvt.PropertyName = aVetoPropChangeListenerStr;
700         aEvt.PropertyHandle = 0L;
701         //aEvt.OldValue;
702         //aEvt.NewValue;
703         //aEvt.PropagationId;
704         aVetoPropChangeListener->vetoableChange( aEvt );
705     }
706 
707     Sequence<Property> aPropSeq = m_xMyInfo->getProperties();
708     sal_Int32 nLen = aPropSeq.getLength();
709     for( sal_Int32 i = 0 ; i < nLen ; i++ )
710     {
711         Property aProp = aPropSeq.getArray()[ i ];
712         if( aProp.Name == aPropertyName )
713             aAnyArray[i] = aValue;
714     }
715 }
716 
getPropertyValue(const OUString & PropertyName)717 Any ImplIntroTest::getPropertyValue( const OUString& PropertyName )
718 //Any ImplIntroTest::getPropertyValue(const UString& aPropertyName) const
719     //THROWS( (UnknownPropertyException, WrappedTargetException, UsrSystemException) )
720 {
721     Sequence<Property> aPropSeq = m_xMyInfo->getProperties();
722     sal_Int32 nLen = aPropSeq.getLength();
723     for( sal_Int32 i = 0 ; i < nLen ; i++ )
724     {
725         Property aProp = aPropSeq.getArray()[ i ];
726         if( aProp.Name == PropertyName )
727             return aAnyArray[i];
728     }
729     return Any();
730 }
731 
getFirstName(void)732 OUString ImplIntroTest::getFirstName(void)
733 {
734     return OUString( OUString::createFromAscii("Markus") );
735 }
736 
writeln(const OUString & Text)737 void ImplIntroTest::writeln( const OUString& Text )
738 {
739     OString aStr( Text.getStr(), Text.getLength(), RTL_TEXTENCODING_ASCII_US );
740 
741     // Haben wir ein Output?
742     //if( m_pOutput )
743     //{
744         //m_pOutput->doWriteln( TextStr );
745     //}
746     // Sonst einfach rausbraten
747     //else
748     {
749         printf( "%s", aStr.getStr() );
750     }
751 }
752 
getIntroTest()753 Reference< XIntroTest > ImplIntroTest::getIntroTest()
754 //XIntroTestRef ImplIntroTest::getIntroTest(void) THROWS( (UsrSystemException) )
755 {
756     if( !m_xIntroTest.is() )
757         m_xIntroTest = new ImplIntroTest( mxMgr );
758     return m_xIntroTest;
759 }
760 
761 // Methoden von XElementAccess
getElementType()762 Type ImplIntroTest::getElementType(  )
763 //XIdlClassRef ImplIntroTest::getElementType(void) const THROWS( (UsrSystemException) )
764 {
765     // TODO
766     Type aRetType;
767     return aRetType;
768     //return Reference< XIdlClass >();
769     //return Void_getReflection()->getIdlClass();
770 }
771 
hasElements()772 sal_Bool ImplIntroTest::hasElements(  )
773 //BOOL ImplIntroTest::hasElements(void) const THROWS( (UsrSystemException) )
774 {
775     return sal_True;
776 }
777 
778 // XNameAccess-Methoden
getIndexForName(const OUString & ItemName)779 sal_Int32 getIndexForName( const OUString& ItemName )
780 {
781     OUString aLeftStr = ItemName.copy( 0, 4 );
782     if( aLeftStr == OUString::createFromAscii("Item") )
783     {
784         // TODO
785         OUString aNumStr = ItemName.copy( 4 );
786         //sal_Int32 iIndex = (INT32)UStringToString( aNumStr, CHARSET_SYSTEM );
787         //if( iIndex < DEFAULT_NAME_ACCESS_COUNT )
788             //return iIndex;
789     }
790     return -1;
791 }
792 
793 
getByName(const OUString & aName)794 Any ImplIntroTest::getByName( const OUString& aName )
795 //Any ImplIntroTest::getByName(const UString& Name) const
796     //THROWS( (NoSuchElementException, WrappedTargetException, UsrSystemException) )
797 {
798     Any aRetAny;
799 
800     if( !pNameAccessTab  )
801         ((ImplIntroTest*)this)->pNameAccessTab  = new Reference< XIntroTest >[ DEFAULT_NAME_ACCESS_COUNT ];
802 
803     sal_Int32 iIndex = getIndexForName( aName );
804     if( iIndex != -1 )
805     {
806         if( !pNameAccessTab[iIndex].is() )
807         {
808             ImplIntroTest* p = new ImplIntroTest( mxMgr );
809             OUString aName2( OUString::createFromAscii("IntroTest by Name-Access, Index = ") );
810             aName2 += OUString::valueOf( iIndex );
811             //aName2 = aName2 + StringToUString( String( iIndex ), CHARSET_SYSTEM );
812             p->setObjectName( aName2 );
813             pNameAccessTab[iIndex] = p;
814         }
815 
816         Reference< XIntroTest > xRet = pNameAccessTab[iIndex];
817         aRetAny = makeAny( xRet );
818 
819         //aRetAny.set( &xRet, XIntroTest_getReflection() );
820         //return (UsrObject*)(XIntroTest*)pNameAccessTab[iIndex];
821     }
822     return aRetAny;
823 }
824 
getElementNames()825 Sequence< OUString > ImplIntroTest::getElementNames(  )
826 //Sequence<UString> ImplIntroTest::getElementNames(void) const THROWS( (UsrSystemException) )
827 {
828     Sequence<OUString> aStrSeq( DEFAULT_NAME_ACCESS_COUNT );
829     OUString* pStr = aStrSeq.getArray();
830     for( sal_Int32 i = 0 ; i < DEFAULT_NAME_ACCESS_COUNT ; i++ )
831     {
832         OUString aName( OUString::createFromAscii("Item") );
833         aName += OUString::valueOf( i );
834         //aName = aName + StringToUString( i, CHARSET_SYSTEM );
835         pStr[i] = aName;
836     }
837     return aStrSeq;
838 }
839 
hasByName(const OUString & aName)840 sal_Bool ImplIntroTest::hasByName( const OUString& aName )
841 //BOOL ImplIntroTest::hasByName(const UString& Name) const THROWS( (UsrSystemException) )
842 {
843     return ( getIndexForName( aName ) != -1 );
844 }
845 
846 // XIndexAccess-Methoden
getCount()847 sal_Int32 ImplIntroTest::getCount(  )
848 //sal_Int32 ImplIntroTest::getCount(void) const THROWS( (UsrSystemException) )
849 {
850     return iIndexAccessCount;
851 }
852 
getByIndex(sal_Int32 Index)853 Any ImplIntroTest::getByIndex( sal_Int32 Index )
854 //Any ImplIntroTest::getByIndex( sal_Int32 Index ) const
855     //THROWS( (IndexOutOfBoundsException, WrappedTargetException, UsrSystemException) )
856 {
857     Any aRetAny;
858 
859     if( !pIndexAccessTab )
860         ((ImplIntroTest*)this)->pIndexAccessTab = new Reference< XIntroTest >[ iIndexAccessCount ];
861 
862     if( Index < iIndexAccessCount )
863     {
864         if( !pNameAccessTab[Index].is() )
865         {
866             ImplIntroTest* p = new ImplIntroTest( mxMgr );
867             OUString aName( OUString::createFromAscii("IntroTest by Index-Access, Index = ") );
868             aName += OUString::valueOf( Index );
869             //aName = aName + StringToUString( String( iIndex ), CHARSET_SYSTEM );
870             p->setObjectName( aName );
871             pIndexAccessTab[Index] = p;
872         }
873         Reference< XIntroTest > xRet = pIndexAccessTab[Index];
874         aRetAny = makeAny( xRet );
875     }
876     return aRetAny;
877 }
878 
addPropertiesChangeListener(const Sequence<OUString> &,const Reference<XPropertiesChangeListener> &)879 void ImplIntroTest::addPropertiesChangeListener( const Sequence< OUString >& /*PropertyNames*/,
880                                                  const Reference< XPropertiesChangeListener >& /*Listener*/ )
881 //void ImplIntroTest::addPropertiesChangeListener
882 //(const Sequence< UString >& PropertyNames, const XPropertiesChangeListenerRef& Listener)
883     //THROWS( (UsrSystemException) )
884 {
885 }
886 
removePropertiesChangeListener(const Reference<XPropertiesChangeListener> &)887 void ImplIntroTest::removePropertiesChangeListener
888 ( const Reference< XPropertiesChangeListener >& /*Listener*/ )
889 //void ImplIntroTest::removePropertiesChangeListener(const XPropertiesChangeListenerRef& Listener)
890     //THROWS( (UsrSystemException) )
891 {
892 }
893 
894 
895 
896 struct DefItem
897 {
898     char const * pName;
899     sal_Int32 nConcept;
900 };
901 
902 // Spezial-Wert fuer Method-Concept, um "normale" Funktionen kennzeichnen zu koennen
903 #define  MethodConcept_NORMAL_IMPL      0x80000000
904 
905 
906 // Test-Objekt liefern
getIntrospectionTestObject(const Reference<XMultiServiceFactory> & xMgr)907 Any getIntrospectionTestObject( const Reference< XMultiServiceFactory > & xMgr )
908 {
909     Any aObjAny;
910     Reference< XIntroTest > xTestObj = new ImplIntroTest( xMgr );
911     aObjAny.setValue( &xTestObj, ::getCppuType( (const Reference< XIntroTest > *)0 ) );
912     return aObjAny;
913 }
914 
test_introsp(Reference<XMultiServiceFactory> xMgr,Reference<XIdlReflection>,Reference<XIntrospection> xIntrospection)915 static sal_Bool test_introsp( Reference< XMultiServiceFactory > xMgr,
916                               Reference< XIdlReflection > /*xRefl*/, Reference< XIntrospection > xIntrospection )
917 {
918     DefItem pPropertyDefs[] =
919     {
920         { "Factor", PropertyConcept::PROPERTYSET },
921         { "MyCount", PropertyConcept::PROPERTYSET },
922         { "Info", PropertyConcept::PROPERTYSET },
923         { "ObjectName", PropertyConcept::ATTRIBUTES },
924         { "FirstName", PropertyConcept::ATTRIBUTES },
925         { "LastName", PropertyConcept::ATTRIBUTES },
926         { "Age", PropertyConcept::ATTRIBUTES },
927         { "ChildrenCount", PropertyConcept::ATTRIBUTES },
928         { "FirstStruct", PropertyConcept::ATTRIBUTES },
929         { "SecondStruct", PropertyConcept::ATTRIBUTES },
930         { "Droenk", PropertyConcept::METHODS },
931         { "IntroTest", PropertyConcept::METHODS },
932         { "Bla", PropertyConcept::METHODS },
933         { "Blub", PropertyConcept::METHODS },
934         { "Gulp", PropertyConcept::METHODS },
935         { "Strings", PropertyConcept::METHODS },
936         { "MultiSequence", PropertyConcept::METHODS },
937         { "PropertySetInfo", PropertyConcept::METHODS },
938         { "ElementType", PropertyConcept::METHODS },
939         { "ElementNames", PropertyConcept::METHODS },
940         { "Count", PropertyConcept::METHODS },
941         { "Types", PropertyConcept::METHODS },
942         { "ImplementationId", PropertyConcept::METHODS },
943         { NULL, 0 }
944     };
945 
946     // Tabelle der Property-Namen, die gefunden werden muessen
947 //  char* pDemandedPropNames[] =
948 //  {
949 //      "Factor",
950 //      "MyCount",
951 //      "Info",
952 //      "ObjectName",
953 //      "FirstName",
954 //      "LastName",
955 //      "Age",
956 //      "ChildrenCount",
957 //      "FirstStruct",
958 //      "SecondStruct",
959 //      "Droenk",
960 //      "IntroTest",
961 //      "Bla",
962 //      "Blub",
963 //      "Gulp",
964 //      "Strings",
965 //      "MultiSequence",
966 //      "PropertySetInfo",
967 //      "ElementType",
968 //      "ElementNames",
969 //      "Count",
970 //      "Types"
971 //      "ImplementationId"
972 //  };
973 
974     char const * pDemandedPropVals[] =
975     {
976         "3.140000",
977         "42",
978         "Hallo",
979         "IntroTest-Obj Nr. 0",
980         "Markus",
981         "Meyer",
982         "33",
983         "2",
984         "TYPE STRUCT",
985         "TYPE STRUCT",
986         "314",
987         "TYPE INTERFACE",
988         "42",
989         "111",
990         "99",
991         "TYPE SEQUENCE",
992         "TYPE SEQUENCE",
993         "TYPE INTERFACE",
994         "TYPE TYPE",
995         "TYPE SEQUENCE",
996         "10",
997         "TYPE SEQUENCE",
998         "TYPE SEQUENCE",
999     };
1000 
1001     char const * pDemandedModifiedPropVals[] =
1002     {
1003         "4.140000",
1004         "43",
1005         "Hallo (Modified!)",
1006         "IntroTest-Obj Nr. 0 (Modified!)",
1007         "Markus",
1008         "Meyer",
1009         "33",
1010         "3",
1011         "Wert wurde nicht modifiziert",
1012         "Wert wurde nicht modifiziert",
1013         "315",
1014         "Wert wurde nicht modifiziert",
1015         "42",
1016         "112",
1017         "99",
1018         "Wert wurde nicht modifiziert",
1019         "Wert wurde nicht modifiziert",
1020         "Wert wurde nicht modifiziert",
1021         "Wert wurde nicht modifiziert",
1022         "Wert wurde nicht modifiziert",
1023         "10",
1024         "Wert wurde nicht modifiziert"
1025         "Wert wurde nicht modifiziert"
1026     };
1027 
1028     char const * pDemandedPropTypes[] =
1029     {
1030         "double",
1031         "long",
1032         "string",
1033         "string",
1034         "string",
1035         "string",
1036         "short",
1037         "short",
1038         "com.sun.star.beans.Property",
1039         "com.sun.star.beans.PropertyValue",
1040         "long",
1041         "ModuleA.XIntroTest",
1042         "short",
1043         "short",
1044         "short",
1045         "[]string",
1046         "[][][]short",
1047         "com.sun.star.beans.XPropertySetInfo",
1048         "type",
1049         "[]string",
1050         "long",
1051         "[]type",
1052         "[]byte",
1053     };
1054     //is() nDemandedPropCount = 22;
1055 
1056 
1057     DefItem pMethodDefs[] =
1058     {
1059         { "queryInterface", MethodConcept_NORMAL_IMPL },
1060         { "acquire", MethodConcept::DANGEROUS },
1061         { "release", MethodConcept::DANGEROUS },
1062         { "writeln", MethodConcept_NORMAL_IMPL },
1063         { "getDroenk", MethodConcept::PROPERTY },
1064         { "getIntroTest", MethodConcept::PROPERTY },
1065         { "getUps", MethodConcept_NORMAL_IMPL },
1066         { "setDroenk", MethodConcept::PROPERTY },
1067         { "getBla", MethodConcept::PROPERTY },
1068         { "setBla", MethodConcept_NORMAL_IMPL },
1069         { "getBlub", MethodConcept::PROPERTY },
1070         { "setBlub", MethodConcept::PROPERTY },
1071         { "getGulp", MethodConcept::PROPERTY },
1072         { "setGulp", MethodConcept_NORMAL_IMPL },
1073         { "getTypeClass", MethodConcept_NORMAL_IMPL },
1074         { "setTypeClass", MethodConcept_NORMAL_IMPL },
1075         { "getStrings", MethodConcept::PROPERTY },
1076         { "setStrings", MethodConcept::PROPERTY },
1077         { "setStringsPerMethod", MethodConcept_NORMAL_IMPL },
1078         { "getMultiSequence", MethodConcept::PROPERTY },
1079         { "setMultiSequence", MethodConcept::PROPERTY },
1080         { "addPropertiesChangeListener", MethodConcept::LISTENER },
1081         { "removePropertiesChangeListener", MethodConcept::LISTENER },
1082         { "getPropertySetInfo", MethodConcept::PROPERTY },
1083         { "setPropertyValue", MethodConcept_NORMAL_IMPL },
1084         { "getPropertyValue", MethodConcept_NORMAL_IMPL },
1085         { "addPropertyChangeListener", MethodConcept::LISTENER },
1086         { "removePropertyChangeListener", MethodConcept::LISTENER },
1087         { "addVetoableChangeListener", MethodConcept::LISTENER },
1088         { "removeVetoableChangeListener", MethodConcept::LISTENER },
1089         { "getElementType", MethodConcept::PROPERTY | MethodConcept::NAMECONTAINER| MethodConcept::INDEXCONTAINER | MethodConcept::ENUMERATION  },
1090         { "hasElements", MethodConcept::NAMECONTAINER | MethodConcept::INDEXCONTAINER | MethodConcept::ENUMERATION },
1091         { "getByName", MethodConcept::NAMECONTAINER },
1092         { "getElementNames", MethodConcept::PROPERTY | MethodConcept::NAMECONTAINER },
1093         { "hasByName", MethodConcept::NAMECONTAINER },
1094         { "getCount", MethodConcept::PROPERTY | MethodConcept::INDEXCONTAINER },
1095         { "getByIndex", MethodConcept::INDEXCONTAINER },
1096         { "getTypes", MethodConcept::PROPERTY },
1097         { "getImplementationId", MethodConcept::PROPERTY },
1098         { "queryAdapter", MethodConcept_NORMAL_IMPL },
1099         { NULL, 0 }
1100     };
1101 
1102     OString aErrorStr;
1103 
1104     //******************************************************
1105 
1106     // Test-Objekt anlegen
1107     Any aObjAny = getIntrospectionTestObject( xMgr );
1108 
1109     // Introspection-Service holen
1110     //Reference< XMultiServiceFactory > xServiceManager(getProcessServiceManager(), USR_QUERY);
1111     //Reference< XIntrospection > xIntrospection( xMgr->createInstance(L"com.sun.star.beans.Introspection"), UNO_QUERY );
1112     //TEST_ENSHURE( xIntrospection.is(), "Creation of introspection instance failed" );
1113     //if( !xIntrospection.is() )
1114         //return sal_False;
1115 
1116     // und unspecten
1117     Reference< XIntrospectionAccess > xAccess = xIntrospection->inspect( aObjAny );
1118     xAccess = xIntrospection->inspect( aObjAny );
1119     xAccess = xIntrospection->inspect( aObjAny );
1120     TEST_ENSHURE( xAccess.is(), "introspection failed, no XIntrospectionAccess returned" );
1121     if( !xAccess.is() )
1122         return sal_False;
1123 
1124     // Ergebnis der Introspection pruefen
1125 
1126     // XPropertySet-UIK ermitteln
1127     Type aType = getCppuType( (Reference< XPropertySet >*) NULL );
1128     //typelib_InterfaceTypeDescription* pTypeDesc = NULL;
1129     //aType.getDescription( (typelib_TypeDescription**)&pTypeDesc );
1130     //Uik aPropertySetUik = *(Uik*)&pTypeDesc->aUik;
1131     //typelib_typedescription_release( (typelib_TypeDescription*)pTypeDesc );
1132 
1133     Reference< XInterface > xPropSetIface = xAccess->queryAdapter( aType );
1134     //Reference< XInterface > xPropSetIface = xAccess->queryAdapter( aPropertySetUik );
1135     Reference< XPropertySet > xPropSet( xPropSetIface, UNO_QUERY );
1136     //XPropertySetRef xPropSet = (XPropertySet*)xPropSetIface->
1137     //  queryInterface( XPropertySet::getSmartUik() );
1138     TEST_ENSHURE( xPropSet.is(), "Could not get XPropertySet by queryAdapter()" );
1139 
1140     // XExactName
1141     Reference< XExactName > xExactName( xAccess, UNO_QUERY );
1142     TEST_ENSHURE( xExactName.is(), "Introspection unterstuetzt kein ExactName" );
1143 
1144     // Schleife ueber alle Kombinationen von Concepts
1145     for( sal_Int32 nConcepts = 0 ; nConcepts < 16 ; nConcepts++ )
1146     {
1147 //printf( "*******************************************************\n" );
1148 //printf( "nConcepts = %ld\n", nConcepts );
1149 
1150         // Wieviele Properties sollten es sein
1151         sal_Int32 nDemandedPropCount = 0;
1152         sal_Int32 iList = 0;
1153         while( pPropertyDefs[ iList ].pName )
1154         {
1155             if( pPropertyDefs[ iList ].nConcept & nConcepts )
1156                 nDemandedPropCount++;
1157             iList++;
1158         }
1159 
1160         if( xPropSet.is() )
1161         {
1162             Reference< XPropertySetInfo > xPropSetInfo = xPropSet->getPropertySetInfo();
1163             //Sequence<Property> aRetSeq = xPropSetInfo->getProperties();
1164             Sequence<Property> aRetSeq = xAccess->getProperties( nConcepts );
1165 
1166             sal_Int32 nLen = aRetSeq.getLength();
1167 
1168             aErrorStr  = "Expected to find ";
1169             aErrorStr += OString::valueOf( nDemandedPropCount );
1170             aErrorStr += " properties but found ";
1171             aErrorStr += OString::valueOf( nLen );
1172             TEST_ENSHURE( nLen == nDemandedPropCount, aErrorStr.getStr() );
1173 
1174             // cout << "**********************************\n";
1175             // cout << "*** Ergebnis der Introspection ***\n";
1176             // cout << "**********************************\n";
1177             // cout << "\nIntrospection hat " << nLen << " Properties gefunden:\n";
1178 
1179             const Property* pProps = aRetSeq.getConstArray();
1180             Any aPropVal;
1181             sal_Int32 i;
1182             iList = 0;
1183             for( i = 0 ; i < nLen ; i++ )
1184             {
1185                 const Property aProp = pProps[ i ];
1186 
1187                 // Naechste Passende Methode in der Liste suchen
1188                 while( pPropertyDefs[ iList ].pName )
1189                 {
1190                     if( pPropertyDefs[ iList ].nConcept & nConcepts )
1191                         break;
1192                     iList++;
1193                 }
1194                 sal_Int32 iDemanded = iList;
1195                 iList++;
1196 
1197                 OUString aPropName = aProp.Name;
1198                 OString aNameStr( aPropName.getStr(), aPropName.getLength(), RTL_TEXTENCODING_ASCII_US );
1199                     //UStringToString(aPropName, CHARSET_SYSTEM);
1200 
1201 //printf( "Property = %s\n", aNameStr.getStr() );
1202 
1203                 OString aDemandedName = pPropertyDefs[ iDemanded ].pName;
1204                 //OString aDemandedName = pDemandedPropNames[ i ];
1205                 aErrorStr  = "Expected property \"";
1206                 aErrorStr += aDemandedName;
1207                 aErrorStr += "\", found \"";
1208                 aErrorStr += aNameStr;
1209                 aErrorStr += "\"";
1210                 TEST_ENSHURE( aNameStr == aDemandedName, aErrorStr.getStr() );
1211                 // cout << "Property " << (i+1) << ": \"" << (const char*)UStringToString(aPropName, CHARSET_SYSTEM) << "\"";
1212 
1213 
1214                 Type aPropType = aProp.Type;
1215                 OString aTypeNameStr( OUStringToOString(aPropType.getTypeName(), RTL_TEXTENCODING_ASCII_US) );
1216                 //Reference< XIdlClass > xPropType = aProp.Type;
1217                 //OString aTypeNameStr( xPropType->getName(), xPropType->getName().getLength(), RTL_TEXTENCODING_ASCII_US );
1218                 OString aDemandedTypeNameStr = pDemandedPropTypes[ iDemanded ];
1219                 //OString aDemandedTypeNameStr = pDemandedPropTypes[ i ];
1220                 aErrorStr  = "Property \"";
1221                 aErrorStr += aDemandedName;
1222                 aErrorStr += "\", expected type >";
1223                 aErrorStr += aDemandedTypeNameStr;
1224                 aErrorStr += "< found type >";
1225                 aErrorStr += aTypeNameStr;
1226                 aErrorStr += "<";
1227                 TEST_ENSHURE( aTypeNameStr == aDemandedTypeNameStr, aErrorStr.getStr() );
1228                 // cout << " (Prop-Typ: " << (const char*)UStringToString(xPropType->getName(), CHARSET_SYSTEM) << ")";
1229 
1230                 // Wert des Property lesen und ausgeben
1231                 aPropVal = xPropSet->getPropertyValue( aPropName );
1232                 // cout << "\n\tWert = " << (const char*)UStringToString(AnyToString( aPropVal, sal_True ), CHARSET_SYSTEM);
1233 
1234                 OString aValStr = OUStringToOString( AnyToString( aPropVal, sal_False, xMgr ), RTL_TEXTENCODING_ASCII_US );
1235                 OString aDemandedValStr = pDemandedPropVals[ iDemanded ];
1236                 //OString aDemandedValStr = pDemandedPropVals[ i ];
1237                 aErrorStr  = "Property \"";
1238                 aErrorStr += aDemandedName;
1239                 aErrorStr += "\", expected val >";
1240                 aErrorStr += aDemandedValStr;
1241                 aErrorStr += "< found val >";
1242                 aErrorStr += aValStr;
1243                 aErrorStr += "<";
1244                 TEST_ENSHURE( aValStr == aDemandedValStr, aErrorStr.getStr() );
1245 
1246                 // Wert pruefen und typgerecht modifizieren
1247                 TypeClass eType = aPropVal.getValueType().getTypeClass();
1248                 //Reference< XIdlClass > xIdlClass = aPropVal.getReflection()->getIdlClass();
1249                 //TypeClass eType = xIdlClass->getTypeClass();
1250                 Any aNewVal;
1251                 sal_Bool bModify = sal_True;
1252                 switch( eType )
1253                 {
1254                     case TypeClass_STRING:
1255                     {
1256                         OUString aStr;
1257                         aPropVal >>= aStr;
1258                         //OString aStr = aPropVal.getString();
1259                         aStr = aStr + OUString::createFromAscii(" (Modified!)");
1260                         aNewVal <<= aStr;
1261                         break;
1262                     }
1263                     case TypeClass_DOUBLE:
1264                     {
1265                         double d(0.0);
1266                         aPropVal >>= d;
1267                         aNewVal <<= d + 1.0;
1268                         break;
1269                     }
1270                     case TypeClass_SHORT:
1271                     {
1272                         sal_Int16 n(0);
1273                         aPropVal >>= n;
1274                         aNewVal <<= sal_Int16( n + 1 );
1275                         break;
1276                     }
1277                     case TypeClass_LONG:
1278                     {
1279                         sal_Int32 n(0);
1280                         aPropVal >>= n;
1281                         aNewVal <<= sal_Int32( n + 1 );
1282                         break;
1283                     }
1284                     default:
1285                         bModify = sal_False;
1286                         break;
1287                 }
1288 
1289                 // Modifizieren nur beim letzten Durchlauf
1290                 if( nConcepts == 15 )
1291                 {
1292                     // XExactName pruefen, dafuer alles gross machen
1293                     // (Introspection ist mit LowerCase implementiert, also anders machen)
1294                     OUString aUpperUStr = aPropName.toAsciiUpperCase();
1295                     OUString aExactName = xExactName->getExactName( aUpperUStr );
1296                     if( aExactName != aPropName )
1297                     {
1298                         aErrorStr  = "Property \"";
1299                         aErrorStr += OUStringToOString( aPropName, RTL_TEXTENCODING_ASCII_US );
1300                         aErrorStr += "\", not found as \"";
1301                         aErrorStr += OUStringToOString(aUpperUStr, RTL_TEXTENCODING_ASCII_US );
1302                         aErrorStr += "\" using XExactName";
1303                         TEST_ENSHURE( sal_False, aErrorStr.getStr() );
1304                     }
1305                 }
1306                 else
1307                 {
1308                     bModify = sal_False;
1309                 }
1310 
1311                 // Neuen Wert setzen, wieder lesen und ausgeben
1312                 if( bModify )
1313                 {
1314                     // cout.flush();
1315 
1316                     // 1.7.1999, UnknownPropertyException bei ReadOnly-Properties abfangen
1317                     try
1318                     {
1319                         xPropSet->setPropertyValue( aPropName, aNewVal );
1320                     }
1321                     catch(UnknownPropertyException e1)
1322                     {
1323                     }
1324 
1325                     aPropVal = xPropSet->getPropertyValue( aPropName );
1326                     // cout << "\n\tModifizierter Wert = " << (const char*) UStringToString(AnyToString( aPropVal, sal_True ), CHARSET_SYSTEM) << "\n";
1327 
1328                     OUString aStr = AnyToString( aPropVal, sal_False, xMgr );
1329                     OString aModifiedValStr = OUStringToOString( aStr, RTL_TEXTENCODING_ASCII_US );
1330                     OString aDemandedModifiedValStr = pDemandedModifiedPropVals[ i ];
1331                     aErrorStr  = "Property \"";
1332                     aErrorStr += aDemandedName;
1333                     aErrorStr += "\", expected modified val >";
1334                     aErrorStr += aDemandedModifiedValStr;
1335                     aErrorStr += "< found val >";
1336                     aErrorStr += aModifiedValStr;
1337                     aErrorStr += "<";
1338                     TEST_ENSHURE( aModifiedValStr == aDemandedModifiedValStr, aErrorStr.getStr() );
1339                 }
1340                 else
1341                 {
1342                     // cout << "\n\tWert wurde nicht modifiziert\n";
1343                 }
1344 
1345                 // Checken, ob alle Properties auch einzeln gefunden werden
1346                 aErrorStr  = "property \"";
1347                 aErrorStr += aDemandedName;
1348                 aErrorStr += "\" not found with hasProperty()";
1349                 OUString aWDemandedName = OStringToOUString(aDemandedName, RTL_TEXTENCODING_ASCII_US );
1350                 sal_Bool bProperty = xAccess->hasProperty( aWDemandedName, nConcepts );
1351                 //sal_Bool bProperty = xAccess->hasProperty( aWDemandedName, PropertyConcept::ALL - PropertyConcept::DANGEROUS );
1352                 TEST_ENSHURE( bProperty, aErrorStr.getStr() );
1353 
1354                 aErrorStr  = "property \"";
1355                 aErrorStr += aDemandedName;
1356                 aErrorStr += "\" not equal to same Property in sequence returned by getProperties()";
1357                 try
1358                 {
1359                     Property aGetProp = xAccess->getProperty( aWDemandedName, nConcepts );
1360                     //Property aGetProp = xAccess->getProperty( aWDemandedName, PropertyConcept::ALL );
1361                     //TEST_ENSHURE( aGetProp == aProp , aErrorStr.getStr() );
1362                 }
1363                 catch (RuntimeException e1)
1364                 {
1365                     aErrorStr  = "property \"";
1366                     aErrorStr += aDemandedName;
1367                     aErrorStr += "\", exception was thrown when trying getProperty()";
1368                     TEST_ENSHURE( sal_False, aErrorStr.getStr() );
1369                 }
1370 
1371             }
1372         }
1373     }
1374 
1375     // Schleife ueber alle Kombinationen von Concepts
1376     for( sal_Int32 nConcepts = 0 ; nConcepts < 128 ; nConcepts++ )
1377     {
1378 //printf( "*******************************************************\n" );
1379 //printf( "nConcepts = %ld\n", nConcepts );
1380 
1381         // Das 2^6-Bit steht fuer "den Rest"
1382         sal_Int32 nRealConcepts = nConcepts;
1383         if( nConcepts & 0x40 )
1384             nRealConcepts |= (0xFFFFFFFF - 0x3F);
1385 
1386         // Wieviele Methoden sollten es sein
1387         sal_Int32 nDemandedMethCount = 0;
1388         sal_Int32 iList = 0;
1389         while( pMethodDefs[ iList ].pName )
1390         {
1391             if( pMethodDefs[ iList ].nConcept & nRealConcepts )
1392                 nDemandedMethCount++;
1393             iList++;
1394         }
1395 
1396         // Methoden-Array ausgeben
1397         //aMethodSeq = xAccess->getMethods
1398         Sequence< Reference< XIdlMethod > > aMethodSeq = xAccess->getMethods( nRealConcepts );
1399         //Sequence<XIdlMethodRef> aMethodSeq = xAccess->getMethods
1400         //  ( MethodConcept::ALL - MethodConcept::DANGEROUS - MethodConcept::PROPERTY );
1401         sal_Int32 nLen = aMethodSeq.getLength();
1402         // cout << "\n\n*** Methoden ***\n";
1403         // cout << "Introspection hat " << nLen << " Methoden gefunden:\n";
1404 
1405         aErrorStr  = "Expected to find ";
1406         aErrorStr += OString::valueOf( nDemandedMethCount );
1407         aErrorStr += " methods but found ";
1408         aErrorStr += OString::valueOf( nLen );
1409         TEST_ENSHURE( nLen == nDemandedMethCount, aErrorStr.getStr() );
1410 
1411         const Reference< XIdlMethod >* pMethods = aMethodSeq.getConstArray();
1412         sal_Int32 i;
1413         iList = 0;
1414 
1415         for( i = 0 ; i < nLen ; i++ )
1416         {
1417             // Methode ansprechen
1418             const Reference< XIdlMethod >& rxMethod = pMethods[i];
1419 
1420             // Methode ausgeben
1421             OUString aMethName = rxMethod->getName();
1422             OString aNameStr = OUStringToOString(aMethName, RTL_TEXTENCODING_ASCII_US );
1423 
1424 //printf( "Method = %s\n", aNameStr.getStr() );
1425 
1426             // Naechste Passende Methode in der Liste suchen
1427             while( pMethodDefs[ iList ].pName )
1428             {
1429                 if( pMethodDefs[ iList ].nConcept & nRealConcepts )
1430                     break;
1431                 iList++;
1432             }
1433             OString aDemandedName = pMethodDefs[ iList ].pName;
1434             iList++;
1435 
1436             //OString aDemandedName = pDemandedMethNames[ i ];
1437             aErrorStr  = "Expected method \"";
1438             aErrorStr += aDemandedName;
1439             aErrorStr += "\", found \"";
1440             aErrorStr += aNameStr;
1441             aErrorStr += "\"";
1442             TEST_ENSHURE( aNameStr == aDemandedName, aErrorStr.getStr() );
1443             // cout << "Methode " << (i+1) << ": " << (const char*) UStringToString(rxMethod->getReturnType()->getName(), CHARSET_SYSTEM)
1444             //   << " " << (const char*) UStringToString(rxMethod->getName(), CHARSET_SYSTEM) << "( ";
1445 
1446             // Checken, ob alle Methoden auch einzeln gefunden werden
1447             aErrorStr  = "method \"";
1448             aErrorStr += aDemandedName;
1449             aErrorStr += "\" not found with hasMethod()";
1450             OUString aWDemandedName = OStringToOUString(aDemandedName, RTL_TEXTENCODING_ASCII_US );
1451             sal_Bool bMethod = xAccess->hasMethod( aWDemandedName, nRealConcepts );
1452             //sal_Bool bMethod = xAccess->hasMethod( aWDemandedName, MethodConcept::ALL );
1453             TEST_ENSHURE( bMethod, aErrorStr.getStr() );
1454 
1455             aErrorStr  = "method \"";
1456             aErrorStr += aDemandedName;
1457             aErrorStr += "\" not equal to same method in sequence returned by getMethods()";
1458             try
1459             {
1460                 Reference< XIdlMethod > xGetMethod = xAccess->getMethod( aWDemandedName, nRealConcepts );
1461                 //XIdlMethodRef xGetMethod = xAccess->getMethod( aWDemandedName, MethodConcept::ALL );
1462                 TEST_ENSHURE( xGetMethod == rxMethod , aErrorStr.getStr() );
1463             }
1464             catch (RuntimeException e1)
1465             {
1466                 aErrorStr  = "method \"";
1467                 aErrorStr += aDemandedName;
1468                 aErrorStr += "\", exception was thrown when trying getMethod()";
1469                 TEST_ENSHURE( sal_False, aErrorStr.getStr() );
1470             }
1471         }
1472     }
1473 
1474     // Listener-Klassen ausgeben
1475     Sequence< Type > aClassSeq = xAccess->getSupportedListeners();
1476     sal_Int32 nLen = aClassSeq.getLength();
1477     // cout << "\n\n*** Anmeldbare Listener ***\n";
1478     // cout << "Introspection hat " << nLen << " Listener gefunden:\n";
1479 
1480     const Type* pListeners = aClassSeq.getConstArray();
1481     for( sal_Int32 i = 0 ; i < nLen ; i++ )
1482     {
1483         // Methode ansprechen
1484         const Type& aListenerType = pListeners[i];
1485 
1486         // Namen besorgen
1487         OUString aListenerClassName = aListenerType.getTypeName();
1488         // cout << "Listener " << (i+1) << ": " << (const char*)UStringToString(aListenerClassName, CHARSET_SYSTEM) << "\n";
1489     }
1490 
1491 
1492     // Performance bei hasMethod testen.
1493     //CheckMethodPerformance( xAccess, "queryInterface", 100000 );
1494     //CheckMethodPerformance( xAccess, "getIdlClasses", 100000 );
1495 
1496     // cout.flush();
1497 
1498 
1499 
1500 
1501     return sal_True;
1502 }
1503 
1504 
SAL_IMPLEMENT_MAIN()1505 SAL_IMPLEMENT_MAIN()
1506 {
1507     Reference< XMultiServiceFactory > xMgr( createRegistryServiceFactory( OUString::createFromAscii("stoctest.rdb") ) );
1508 
1509     sal_Bool bSucc = sal_False;
1510     try
1511     {
1512         Reference< XImplementationRegistration > xImplReg(
1513             xMgr->createInstance( OUString::createFromAscii("com.sun.star.registry.ImplementationRegistration") ), UNO_QUERY );
1514         OSL_ENSURE( xImplReg.is(), "### no impl reg!" );
1515 
1516         // Register services
1517         OUString libName( RTL_CONSTASCII_USTRINGPARAM(
1518                               "reflection.uno" SAL_DLLEXTENSION) );
1519 //          ORealDynamicLoader::computeLibraryName( OUString::createFromAscii("corefl"), libName);
1520         fprintf(stderr, "1\n" );
1521         xImplReg->registerImplementation(OUString::createFromAscii("com.sun.star.loader.SharedLibrary"),
1522                                          libName, Reference< XSimpleRegistry >() );
1523         fprintf(stderr, "2\n" );
1524         Reference< XIdlReflection > xRefl( xMgr->createInstance( OUString::createFromAscii("com.sun.star.reflection.CoreReflection") ), UNO_QUERY );
1525         OSL_ENSURE( xRefl.is(), "### no corereflection!" );
1526 
1527         // Introspection
1528         libName = OUString::createFromAscii(
1529             "introspection.uno" SAL_DLLEXTENSION);
1530 //          ORealDynamicLoader::computeLibraryName( OUString::createFromAscii("insp"), libName);
1531         fprintf(stderr, "3\n" );
1532         xImplReg->registerImplementation(OUString::createFromAscii("com.sun.star.loader.SharedLibrary"),
1533                                          libName, Reference< XSimpleRegistry >() );
1534         fprintf(stderr, "4\n" );
1535         Reference< XIntrospection > xIntrosp( xMgr->createInstance( OUString::createFromAscii("com.sun.star.beans.Introspection") ), UNO_QUERY );
1536         OSL_ENSURE( xRefl.is(), "### no corereflection!" );
1537 
1538         fprintf(stderr, "before test_introsp\n" );
1539         bSucc = test_introsp( xMgr, xRefl, xIntrosp );
1540         fprintf(stderr, "after test_introsp\n" );
1541         //bSucc = test_corefl( xRefl );
1542     }
1543     catch (Exception & rExc)
1544     {
1545         OSL_ENSURE( sal_False, "### exception occurred!" );
1546         OString aMsg( OUStringToOString( rExc.Message, RTL_TEXTENCODING_ASCII_US ) );
1547         OSL_TRACE( "### exception occurred: " );
1548         OSL_TRACE( aMsg.getStr() );
1549         OSL_TRACE( "\n" );
1550     }
1551 
1552     Reference< XComponent >( xMgr, UNO_QUERY )->dispose();
1553 
1554     printf( "testintrosp %s !\n", (bSucc ? "succeeded" : "failed") );
1555     return (bSucc ? 0 : -1);
1556 }
1557 
1558 
1559 
1560 
1561 
1562 
1563 
1564 //*****************************
1565 //*** TEST-Implementationen ***
1566 //*****************************
1567 // Bleibt auf Dauer nicht drin, dient als exportierbare Test-Klasse
1568 // z.B. fuer Basic-Anbindung
1569