xref: /aoo41x/main/stoc/test/testcorefl.cxx (revision cdf0e10c)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_stoc.hxx"
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir #include <sal/main.h>
32*cdf0e10cSrcweir #include <osl/diagnose.h>
33*cdf0e10cSrcweir 
34*cdf0e10cSrcweir #if OSL_DEBUG_LEVEL > 0
35*cdf0e10cSrcweir #define TEST_ENSHURE(c, m)   OSL_ENSURE(c, m)
36*cdf0e10cSrcweir #else
37*cdf0e10cSrcweir #define TEST_ENSHURE(c, m)   OSL_VERIFY(c)
38*cdf0e10cSrcweir #endif
39*cdf0e10cSrcweir 
40*cdf0e10cSrcweir #include <cppuhelper/servicefactory.hxx>
41*cdf0e10cSrcweir #include <cppuhelper/weak.hxx>
42*cdf0e10cSrcweir #include <cppuhelper/implbase1.hxx>
43*cdf0e10cSrcweir 
44*cdf0e10cSrcweir #include <ModuleA/XInterface1.hpp>
45*cdf0e10cSrcweir #include <ModuleC/XInterfaceA.hpp>
46*cdf0e10cSrcweir #include <ModuleC/XInterfaceB.hpp>
47*cdf0e10cSrcweir #include <ModuleC/ModuleC.hpp>
48*cdf0e10cSrcweir 
49*cdf0e10cSrcweir #include <com/sun/star/container/XHierarchicalNameAccess.hpp>
50*cdf0e10cSrcweir #include <com/sun/star/lang/XComponent.hpp>
51*cdf0e10cSrcweir #include <com/sun/star/reflection/XIdlReflection.hpp>
52*cdf0e10cSrcweir #include <com/sun/star/reflection/XIdlField2.hpp>
53*cdf0e10cSrcweir #include <com/sun/star/beans/XPropertySet.hpp>
54*cdf0e10cSrcweir #include <com/sun/star/registry/XSimpleRegistry.hpp>
55*cdf0e10cSrcweir #include <com/sun/star/registry/XImplementationRegistration.hpp>
56*cdf0e10cSrcweir 
57*cdf0e10cSrcweir #include <rtl/ustrbuf.hxx>
58*cdf0e10cSrcweir 
59*cdf0e10cSrcweir #include <stdio.h>
60*cdf0e10cSrcweir 
61*cdf0e10cSrcweir 
62*cdf0e10cSrcweir using namespace rtl;
63*cdf0e10cSrcweir using namespace cppu;
64*cdf0e10cSrcweir using namespace osl;
65*cdf0e10cSrcweir using namespace ModuleA;
66*cdf0e10cSrcweir using namespace ModuleB;
67*cdf0e10cSrcweir using namespace ModuleC;
68*cdf0e10cSrcweir using namespace ModuleA::ModuleB;
69*cdf0e10cSrcweir using namespace com::sun::star;
70*cdf0e10cSrcweir using namespace com::sun::star::uno;
71*cdf0e10cSrcweir using namespace com::sun::star::lang;
72*cdf0e10cSrcweir using namespace com::sun::star::beans;
73*cdf0e10cSrcweir using namespace com::sun::star::registry;
74*cdf0e10cSrcweir using namespace com::sun::star::reflection;
75*cdf0e10cSrcweir using namespace com::sun::star::container;
76*cdf0e10cSrcweir 
77*cdf0e10cSrcweir 
78*cdf0e10cSrcweir //==================================================================================================
79*cdf0e10cSrcweir class OInterfaceA : public WeakImplHelper1< XInterfaceA >
80*cdf0e10cSrcweir {
81*cdf0e10cSrcweir public:
82*cdf0e10cSrcweir 
83*cdf0e10cSrcweir     virtual void SAL_CALL methodA(void) throw (RuntimeException)
84*cdf0e10cSrcweir 		{}
85*cdf0e10cSrcweir 
86*cdf0e10cSrcweir     virtual void SAL_CALL methodB(sal_Int16 /*aShort*/) throw (RuntimeException)
87*cdf0e10cSrcweir 		{}
88*cdf0e10cSrcweir     virtual Sequence< StructB > SAL_CALL methodC(const StructC& /*aStructC*/, StructA& /*aStructA*/) throw (RuntimeException)
89*cdf0e10cSrcweir 		{ return Sequence< StructB >(); }
90*cdf0e10cSrcweir };
91*cdf0e10cSrcweir 
92*cdf0e10cSrcweir //==================================================================================================
93*cdf0e10cSrcweir static inline bool uik_equals( const Uik & rUik1, const Uik & rUik2 )
94*cdf0e10cSrcweir {
95*cdf0e10cSrcweir 	return (rUik1.m_Data1 == rUik2.m_Data1 &&
96*cdf0e10cSrcweir 			rUik1.m_Data2 == rUik2.m_Data2 &&
97*cdf0e10cSrcweir 			rUik1.m_Data3 == rUik2.m_Data3 &&
98*cdf0e10cSrcweir 			rUik1.m_Data4 == rUik2.m_Data4 &&
99*cdf0e10cSrcweir 			rUik1.m_Data5 == rUik2.m_Data5);
100*cdf0e10cSrcweir }
101*cdf0e10cSrcweir //==================================================================================================
102*cdf0e10cSrcweir static sal_Bool test_corefl( const Reference< XIdlReflection > & xRefl )
103*cdf0e10cSrcweir {
104*cdf0e10cSrcweir 	Reference< XIdlClass > xClass;
105*cdf0e10cSrcweir 	Reference< XHierarchicalNameAccess > xHNameAccess( xRefl, UNO_QUERY );
106*cdf0e10cSrcweir 	TEST_ENSHURE(xHNameAccess.is(), "### cannot get XHierarchicalNameAccess!" );
107*cdf0e10cSrcweir 
108*cdf0e10cSrcweir 	TEST_ENSHURE(xRefl->forName(OUString::createFromAscii("ModuleA.StructA"))->getName() == OUString::createFromAscii("ModuleA.StructA"), "test_RegCoreReflection(): error 2b");
109*cdf0e10cSrcweir 	TEST_ENSHURE(xRefl->forName(OUString::createFromAscii("ModuleA.ExceptionB"))->getTypeClass() == TypeClass_EXCEPTION, "test_RegCoreReflection(): error 2c");
110*cdf0e10cSrcweir 	TEST_ENSHURE(xRefl->forName(OUString::createFromAscii("ModuleA.ModuleB.EnumA")).is(), "test_RegCoreReflection(): error 2e");
111*cdf0e10cSrcweir 	// const
112*cdf0e10cSrcweir 
113*cdf0e10cSrcweir 	TEST_ENSHURE(*(const sal_Bool *)xHNameAccess->getByHierarchicalName(OUString::createFromAscii("ModuleC.aConstBoolean")).getValue() == aConstBoolean, "test_RegCoreReflection(): error 4c");
114*cdf0e10cSrcweir 	TEST_ENSHURE(*(const sal_Int8 *)xHNameAccess->getByHierarchicalName(OUString::createFromAscii("ModuleC.aConstByte")).getValue() == aConstByte, "test_RegCoreReflection(): error 4e");
115*cdf0e10cSrcweir 	TEST_ENSHURE(xHNameAccess->getByHierarchicalName(OUString::createFromAscii("ModuleC.aConstShort")) == aConstShort, "test_RegCoreReflection(): error 4g");
116*cdf0e10cSrcweir 	TEST_ENSHURE(xHNameAccess->getByHierarchicalName(OUString::createFromAscii("ModuleC.aConstUShort")) == aConstUShort, "test_RegCoreReflection(): error 4i");
117*cdf0e10cSrcweir 	TEST_ENSHURE(xHNameAccess->getByHierarchicalName(OUString::createFromAscii("ModuleC.aConstLong")) == aConstLong, "test_RegCoreReflection(): error 4k");
118*cdf0e10cSrcweir 	TEST_ENSHURE(xHNameAccess->getByHierarchicalName(OUString::createFromAscii("ModuleC.aConstULong")) == aConstULong, "test_RegCoreReflection(): error 4m");
119*cdf0e10cSrcweir //  	TEST_ENSHURE(xHNameAccess->getByHierarchicalName(OUString::createFromAscii("ModuleC.aConstFloat")) == aConstFloat, "test_RegCoreReflection(): error 4o");
120*cdf0e10cSrcweir //  	TEST_ENSHURE(xHNameAccess->getByHierarchicalName(OUString::createFromAscii("ModuleC.aConstDouble")) == aConstDouble, "test_RegCoreReflection(): error 4q");
121*cdf0e10cSrcweir 
122*cdf0e10cSrcweir 	// Enums
123*cdf0e10cSrcweir 
124*cdf0e10cSrcweir 	xClass = xRefl->forName(OUString::createFromAscii("ModuleA.ModuleB.EnumA"));
125*cdf0e10cSrcweir 
126*cdf0e10cSrcweir 	TEST_ENSHURE(xClass.is(), "test_RegCoreReflection(): error 5");
127*cdf0e10cSrcweir 
128*cdf0e10cSrcweir 	Sequence<Reference< XIdlField > > fields = xClass->getFields();
129*cdf0e10cSrcweir 
130*cdf0e10cSrcweir 	TEST_ENSHURE(
131*cdf0e10cSrcweir 		(fields.getLength() == 3) &&
132*cdf0e10cSrcweir 		(fields.getArray()[0]->getName() == OUString( RTL_CONSTASCII_USTRINGPARAM("VAL_1") )) &&
133*cdf0e10cSrcweir 		(*(EnumA*)fields.getArray()[0]->get(Any()).getValue() == EnumA_VAL_1) &&
134*cdf0e10cSrcweir 		(fields.getArray()[1]->getName() == OUString( RTL_CONSTASCII_USTRINGPARAM("VAL_2") )) &&
135*cdf0e10cSrcweir 		(*(EnumA*)fields.getArray()[1]->get(Any()).getValue() == EnumA_VAL_2) &&
136*cdf0e10cSrcweir 		(fields.getArray()[2]->getName() == OUString( RTL_CONSTASCII_USTRINGPARAM("VAL_3") )) &&
137*cdf0e10cSrcweir 		(*(EnumA*)fields.getArray()[2]->get(Any()).getValue() == EnumA_VAL_3),
138*cdf0e10cSrcweir 		"test_RegCoreReflection(): error 6");
139*cdf0e10cSrcweir 
140*cdf0e10cSrcweir 
141*cdf0e10cSrcweir 	// Interface
142*cdf0e10cSrcweir 
143*cdf0e10cSrcweir 	Reference< XIdlClass > xA = xRefl->forName( OUString::createFromAscii("ModuleC.XInterfaceB") );
144*cdf0e10cSrcweir 
145*cdf0e10cSrcweir 	xClass = xRefl->forName(OUString::createFromAscii("ModuleC.XInterfaceB"));
146*cdf0e10cSrcweir 
147*cdf0e10cSrcweir 	TEST_ENSHURE(xClass == xA, "test_RegCoreReflection(): error 7");
148*cdf0e10cSrcweir 	TEST_ENSHURE(xClass.is(), "test_RegCoreReflection(): error 7a");
149*cdf0e10cSrcweir 
150*cdf0e10cSrcweir 	typelib_TypeDescription * pTD = 0;
151*cdf0e10cSrcweir 	OUString aModuleName( RTL_CONSTASCII_USTRINGPARAM("ModuleC.XInterfaceB") );
152*cdf0e10cSrcweir 	typelib_typedescription_getByName( &pTD, aModuleName.pData );
153*cdf0e10cSrcweir 	TEST_ENSHURE( pTD, "### cannot get typedescription for ModuleC.XInterfaceB!" );
154*cdf0e10cSrcweir 
155*cdf0e10cSrcweir 	TEST_ENSHURE( uik_equals( *(Uik *)&((typelib_InterfaceTypeDescription *)pTD)->aUik,
156*cdf0e10cSrcweir 							  xClass->getUik() ),
157*cdf0e10cSrcweir 				  "test_RegCoreReflection(): error 8" );
158*cdf0e10cSrcweir 	typelib_typedescription_release( pTD );
159*cdf0e10cSrcweir 
160*cdf0e10cSrcweir 	TEST_ENSHURE(xClass->getSuperclasses().getLength() == 1, "test_RegCoreReflection(): error 9");
161*cdf0e10cSrcweir 	TEST_ENSHURE(xClass->getSuperclasses().getArray()[0]->getName() == OUString::createFromAscii("ModuleC.XInterfaceA"), "test_RegCoreReflection(): error 10");
162*cdf0e10cSrcweir 	TEST_ENSHURE(xClass->getMethods().getLength() == 7, "test_RegCoreReflection(): error 11");
163*cdf0e10cSrcweir 	TEST_ENSHURE(xA->getMethods().getLength() == 7, "test_RegCoreReflection(): error 11a");
164*cdf0e10cSrcweir 	TEST_ENSHURE(xClass->getMethods().getArray()[3]->getName() == OUString::createFromAscii("methodA"), "test_RegCoreReflection(): 12");
165*cdf0e10cSrcweir 	TEST_ENSHURE(xClass->getMethods().getArray()[3]->getReturnType()->getTypeClass() == TypeClass_VOID, "test_RegCoreReflection(): error 13");
166*cdf0e10cSrcweir 	TEST_ENSHURE(xClass->getMethods().getArray()[3]->getParameterTypes().getLength() == 0, "test_RegCoreReflection(): error 14");
167*cdf0e10cSrcweir 	TEST_ENSHURE(xClass->getMethods().getArray()[3]->getExceptionTypes().getLength() == 0, "test_RegCoreReflection(): error 15");
168*cdf0e10cSrcweir 	TEST_ENSHURE(xClass->getMethods().getArray()[4]->getName() == OUString( RTL_CONSTASCII_USTRINGPARAM("methodB") ), "test_RegCoreReflection(): error 16");
169*cdf0e10cSrcweir 	TEST_ENSHURE(xClass->getMethods().getArray()[4]->getMode() == MethodMode_ONEWAY, "test_RegCoreReflection(): error 16a");
170*cdf0e10cSrcweir 	TEST_ENSHURE(xClass->getMethods().getArray()[4]->getReturnType()->getTypeClass() == TypeClass_VOID, "test_RegCoreReflection(): error 16");
171*cdf0e10cSrcweir 	TEST_ENSHURE(xClass->getMethods().getArray()[4]->getParameterTypes().getLength() == 1, "test_RegCoreReflection(): error 17");
172*cdf0e10cSrcweir 	TEST_ENSHURE(xClass->getMethods().getArray()[4]->getParameterTypes().getArray()[0]->getTypeClass() == TypeClass_SHORT, "test_RegCoreReflection(): error 18");
173*cdf0e10cSrcweir 	TEST_ENSHURE(xClass->getMethods().getArray()[4]->getParameterInfos().getArray()[0].aName == OUString( RTL_CONSTASCII_USTRINGPARAM("aShort") ), "test_RegCoreReflection(): error 18a");
174*cdf0e10cSrcweir 	TEST_ENSHURE(xClass->getMethods().getArray()[4]->getParameterInfos().getArray()[0].aType == xRefl->forName( OUString( RTL_CONSTASCII_USTRINGPARAM("short") ) ), "test_RegCoreReflection(): error 18b");
175*cdf0e10cSrcweir 	TEST_ENSHURE(xClass->getMethods().getArray()[4]->getParameterInfos().getArray()[0].aMode == ParamMode_IN, "test_RegCoreReflection(): error 18c");
176*cdf0e10cSrcweir 	TEST_ENSHURE(xClass->getMethods().getArray()[4]->getExceptionTypes().getLength() == 0, "test_RegCoreReflection(): error 19");
177*cdf0e10cSrcweir 	TEST_ENSHURE(xClass->getMethods().getArray()[5]->getName() == OUString::createFromAscii("methodC"), "test_RegCoreReflection(): error 20");
178*cdf0e10cSrcweir 	TEST_ENSHURE(xClass->getMethods().getArray()[5]->getMode() == MethodMode_TWOWAY, "test_RegCoreReflection(): error 20a");
179*cdf0e10cSrcweir 	TEST_ENSHURE(xClass->getMethods().getArray()[5]->getReturnType()->getTypeClass() == TypeClass_SEQUENCE, "test_RegCoreReflection(): error 21");
180*cdf0e10cSrcweir 	TEST_ENSHURE(xClass->getMethods().getArray()[5]->getReturnType()->getComponentType()->getTypeClass() == TypeClass_STRUCT, "test_RegCoreReflection(): error 22");
181*cdf0e10cSrcweir 	TEST_ENSHURE(xClass->getMethods().getArray()[5]->getReturnType()->getComponentType()->getName() == OUString::createFromAscii("ModuleA.StructB"), "test_RegCoreReflection(): error 23");
182*cdf0e10cSrcweir 	TEST_ENSHURE(xClass->getMethods().getArray()[5]->getParameterTypes().getLength() == 2, "test_RegCoreReflection(): error 24");
183*cdf0e10cSrcweir 	TEST_ENSHURE(xClass->getMethods().getArray()[5]->getParameterTypes().getArray()[0]->getTypeClass() == TypeClass_STRUCT, "test_RegCoreReflection(): error 25");
184*cdf0e10cSrcweir 	TEST_ENSHURE(xClass->getMethods().getArray()[5]->getParameterTypes().getArray()[0]->getName() == OUString::createFromAscii("ModuleA.StructC"), "test_RegCoreReflection(): error 26");
185*cdf0e10cSrcweir 	TEST_ENSHURE(xClass->getMethods().getArray()[5]->getParameterTypes().getArray()[1]->getTypeClass() == TypeClass_STRUCT, "test_RegCoreReflection(): error 27");
186*cdf0e10cSrcweir 	TEST_ENSHURE(xClass->getMethods().getArray()[5]->getParameterTypes().getArray()[1]->getName() == OUString::createFromAscii("ModuleA.StructA"), "test_RegCoreReflection(): error 28");
187*cdf0e10cSrcweir 	TEST_ENSHURE(xClass->getMethods().getArray()[5]->getExceptionTypes().getLength() == 0, "test_RegCoreReflection(): error 29");
188*cdf0e10cSrcweir 	TEST_ENSHURE(xClass->getMethods().getArray()[6]->getName() == OUString::createFromAscii("methodD"), "test_RegCoreReflection(): error 30");
189*cdf0e10cSrcweir 	TEST_ENSHURE(xClass->getMethods().getArray()[6]->getReturnType()->getTypeClass() == TypeClass_INTERFACE, "test_RegCoreReflection(): error 31");
190*cdf0e10cSrcweir 	TEST_ENSHURE(xClass->getMethods().getArray()[6]->getReturnType()->getName() == OUString::createFromAscii("ModuleC.XInterfaceA"), "test_RegCoreReflection(): error 32");
191*cdf0e10cSrcweir 	TEST_ENSHURE(xClass->getMethods().getArray()[6]->getParameterTypes().getLength() == 1, "test_RegCoreReflection(): error 33");
192*cdf0e10cSrcweir 	TEST_ENSHURE(xClass->getMethods().getArray()[6]->getParameterTypes().getArray()[0]->getTypeClass() == TypeClass_ENUM, "test_RegCoreReflection(): error 34");
193*cdf0e10cSrcweir 	TEST_ENSHURE(xClass->getMethods().getArray()[6]->getParameterTypes().getArray()[0]->getName() == OUString::createFromAscii("ModuleA.ModuleB.EnumA"), "test_RegCoreReflection(): error 35");
194*cdf0e10cSrcweir 	TEST_ENSHURE(xClass->getMethods().getArray()[6]->getExceptionTypes().getLength() == 3, "test_RegCoreReflection(): error 36");
195*cdf0e10cSrcweir 	TEST_ENSHURE(xClass->getMethods().getArray()[6]->getExceptionTypes().getArray()[0]->getTypeClass() == TypeClass_EXCEPTION, "test_RegCoreReflection(): error 37");
196*cdf0e10cSrcweir 	TEST_ENSHURE(xClass->getMethods().getArray()[6]->getExceptionTypes().getArray()[0]->getName() == OUString::createFromAscii("ModuleA.ExceptionA"), "test_RegCoreReflection(): error 38");
197*cdf0e10cSrcweir 	TEST_ENSHURE(xClass->getMethods().getArray()[6]->getExceptionTypes().getArray()[1]->getTypeClass() == TypeClass_EXCEPTION, "test_RegCoreReflection(): error 38");
198*cdf0e10cSrcweir 	TEST_ENSHURE(xClass->getMethods().getArray()[6]->getExceptionTypes().getArray()[1]->getName() == OUString::createFromAscii("ModuleA.ExceptionB"), "test_RegCoreReflection(): error 39");
199*cdf0e10cSrcweir 	TEST_ENSHURE(xClass->getMethods().getArray()[6]->getExceptionTypes().getArray()[2]->getTypeClass() == TypeClass_EXCEPTION, "test_RegCoreReflection(): error 40");
200*cdf0e10cSrcweir 	TEST_ENSHURE(xClass->getMethods().getArray()[6]->getExceptionTypes().getArray()[2]->getName() == OUString::createFromAscii("ModuleA.ExceptionC"), "test_RegCoreReflection(): error 41");
201*cdf0e10cSrcweir 	TEST_ENSHURE(xClass->getMethods().getArray()[6]->getExceptionTypes().getArray()[2]->getFields().getLength() == 3, "test_RegCoreReflection(): error 42");
202*cdf0e10cSrcweir 	TEST_ENSHURE(xClass->getMethods().getArray()[6]->getExceptionTypes().getArray()[2]->getFields().getArray()[0]->getType()->getTypeClass() == TypeClass_BOOLEAN, "test_RegCoreReflection(): error 43");
203*cdf0e10cSrcweir 	TEST_ENSHURE(xClass->getMethods().getArray()[6]->getExceptionTypes().getArray()[2]->getFields().getArray()[0]->getType()->getName() == OUString::createFromAscii("boolean"), "test_RegCoreReflection(): error 43a");
204*cdf0e10cSrcweir 	TEST_ENSHURE(xClass->getMethods().getArray()[6]->getExceptionTypes().getArray()[2]->getFields().getArray()[1]->getType()->getTypeClass() == TypeClass_STRUCT, "test_RegCoreReflection(): error 44");
205*cdf0e10cSrcweir 	TEST_ENSHURE(xClass->getMethods().getArray()[6]->getExceptionTypes().getArray()[2]->getFields().getArray()[1]->getType()->getName() == OUString::createFromAscii("ModuleA.StructC"), "test_RegCoreReflection(): error 45");
206*cdf0e10cSrcweir 	TEST_ENSHURE(xClass->getMethods().getArray()[6]->getExceptionTypes().getArray()[2]->getFields().getArray()[2]->getType()->getTypeClass() == TypeClass_INTERFACE, "test_RegCoreReflection(): error 46");
207*cdf0e10cSrcweir 	TEST_ENSHURE(xClass->getMethods().getArray()[6]->getExceptionTypes().getArray()[2]->getFields().getArray()[2]->getType()->getName() == OUString::createFromAscii("ModuleA.XInterface1"), "test_RegCoreReflection(): error 47");
208*cdf0e10cSrcweir 
209*cdf0e10cSrcweir 	// SequenceReflections
210*cdf0e10cSrcweir 
211*cdf0e10cSrcweir 	TEST_ENSHURE(xRefl->forName( OUString::createFromAscii("[]ModuleA.StructA") )->getTypeClass() == TypeClass_SEQUENCE, "test_RegCoreReflection(): error 48");
212*cdf0e10cSrcweir 	TEST_ENSHURE(xRefl->forName( OUString::createFromAscii("[]ModuleA.StructA") )->getComponentType().is(), "test_RegCoreReflection(): error 49");
213*cdf0e10cSrcweir 	TEST_ENSHURE(xRefl->forName( OUString::createFromAscii("[][]ModuleA.StructA") )->getComponentType()->getComponentType()->getName() == OUString::createFromAscii("ModuleA.StructA"), "test_RegCoreReflection(): error 50");
214*cdf0e10cSrcweir 	TEST_ENSHURE(xRefl->forName( OUString::createFromAscii("[]com.sun.star.uno.XInterface") ) == xRefl->forName(OUString( RTL_CONSTASCII_USTRINGPARAM("ModuleA.StructC") ))->getField(OUString::createFromAscii("aInterfaceSeq"))->getType(), "test_RegCoreReflection(): error 51");
215*cdf0e10cSrcweir 
216*cdf0e10cSrcweir 	StructC aStructC;
217*cdf0e10cSrcweir 	aStructC.aLong = aConstLong;
218*cdf0e10cSrcweir 	aStructC.aShort = aConstShort;
219*cdf0e10cSrcweir 	aStructC.aFloat = aConstFloat;
220*cdf0e10cSrcweir 	aStructC.aDouble = aConstDouble;
221*cdf0e10cSrcweir 	aStructC.aInterfaceSeq = Sequence<Reference<XInterface > >();
222*cdf0e10cSrcweir 
223*cdf0e10cSrcweir 	Any aAny;
224*cdf0e10cSrcweir 
225*cdf0e10cSrcweir 	xRefl->forName(OUString::createFromAscii("ModuleA.StructC"))->getField(OUString::createFromAscii("aInterfaceSeq"))->getType()->createObject(aAny);
226*cdf0e10cSrcweir 
227*cdf0e10cSrcweir 	TEST_ENSHURE(aAny.getValueType() == ::getCppuType( (const Sequence<Reference< XInterface > > *)0 ), "test_RegCoreReflection(): error 51a");
228*cdf0e10cSrcweir 
229*cdf0e10cSrcweir 	Any aStructAny(&aStructC, ::getCppuType( (const StructC *) 0 ));
230*cdf0e10cSrcweir 
231*cdf0e10cSrcweir 	sal_Int32 nLong = aConstLong * 2;
232*cdf0e10cSrcweir 	aAny.setValue( &nLong, ::getCppuType( (const sal_Int32 *)0 ) );
233*cdf0e10cSrcweir 
234*cdf0e10cSrcweir 	TEST_ENSHURE(*(sal_Int32*)xRefl->forName(OUString( RTL_CONSTASCII_USTRINGPARAM("ModuleA.StructA") ))->getField(OUString( RTL_CONSTASCII_USTRINGPARAM("aLong") ))->get(
235*cdf0e10cSrcweir 		Any(&aStructC, ::getCppuType( (const StructC *)0 ))).getValue() == aConstLong, "test_RegCoreReflection(): error 52");
236*cdf0e10cSrcweir 	TEST_ENSHURE(xRefl->forName(OUString::createFromAscii("ModuleA.StructA"))->getField(OUString( RTL_CONSTASCII_USTRINGPARAM("aLong") ))->getAccessMode() == FieldAccessMode_READWRITE, "test_RegCoreReflection(): error 52a");
237*cdf0e10cSrcweir     Reference< XIdlField2 > rField ( xRefl->forName(OUString( RTL_CONSTASCII_USTRINGPARAM("ModuleA.StructC") ))->getField(OUString( RTL_CONSTASCII_USTRINGPARAM("aLong") )) , UNO_QUERY );
238*cdf0e10cSrcweir     rField->set(aStructAny, aAny);
239*cdf0e10cSrcweir 	TEST_ENSHURE(*(sal_Int32*)xRefl->forName(OUString::createFromAscii("ModuleA.StructB"))->getField(OUString( RTL_CONSTASCII_USTRINGPARAM("aLong") ))->get(aStructAny).getValue() == *(sal_Int32*)aAny.getValue(), "test_RegCoreReflection(): error 53");
240*cdf0e10cSrcweir 
241*cdf0e10cSrcweir 	xRefl->forName( OUString::createFromAscii("[]ModuleA.StructA") )->createObject(aAny);
242*cdf0e10cSrcweir 
243*cdf0e10cSrcweir 	TEST_ENSHURE(aAny.getValueTypeName().equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("[]ModuleA.StructA")), "test_RegCoreReflection(): error 54");
244*cdf0e10cSrcweir 	xRefl->forName(OUString::createFromAscii("[][]ModuleA.StructA"))->createObject(aAny);
245*cdf0e10cSrcweir 
246*cdf0e10cSrcweir 	TEST_ENSHURE(aAny.getValueTypeName().equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("[][]ModuleA.StructA") ), "test_RegCoreReflection(): error 56");
247*cdf0e10cSrcweir 
248*cdf0e10cSrcweir //  	xClass = xRefl->forName(OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.beans.XIntroTest") ));
249*cdf0e10cSrcweir 
250*cdf0e10cSrcweir //  	TEST_ENSHURE(xClass.is(), "test_RegCoreReflection(): error 58");
251*cdf0e10cSrcweir //  	TEST_ENSHURE(xClass->getMethod(OUString::createFromAscii("getStrings"))->getReturnType()->getTypeClass() == TypeClass_SEQUENCE, "test_RegCoreReflection(): error 59");
252*cdf0e10cSrcweir //  	TEST_ENSHURE(xClass->getMethod(OUString::createFromAscii("getStrings"))->getReturnType()->getComponentType()->getName() == OUString::createFromAscii("string"), "test_RegCoreReflection(): error 60");
253*cdf0e10cSrcweir 
254*cdf0e10cSrcweir //  	xClass->getMethod(OUString::createFromAscii("getStrings"))->getReturnType()->createObject(aAny);
255*cdf0e10cSrcweir //  	TEST_ENSHURE(aAny.getValueTypeName().equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("[]string") ),  "test_RegCoreReflection(): error 61");
256*cdf0e10cSrcweir 
257*cdf0e10cSrcweir 	TEST_ENSHURE(xRefl->forName(OUString::createFromAscii("[][][]unsigned long"))->getComponentType()->getComponentType()->getComponentType()->getTypeClass() == TypeClass_UNSIGNED_LONG, "test_RegCoreReflection(): error 62");
258*cdf0e10cSrcweir 
259*cdf0e10cSrcweir 	try
260*cdf0e10cSrcweir 	{
261*cdf0e10cSrcweir         fprintf( stderr, "%1\n" );
262*cdf0e10cSrcweir 		Any bla = xRefl->forName(OUString::createFromAscii("ModuleA.StructC"))->getField(OUString::createFromAscii("aString"))->get(Any());
263*cdf0e10cSrcweir 		TEST_ENSHURE(sal_False, "test_RegCoreReflection(): error 63");
264*cdf0e10cSrcweir 		return sal_False;
265*cdf0e10cSrcweir 	}
266*cdf0e10cSrcweir 	catch (IllegalArgumentException &)
267*cdf0e10cSrcweir 	{
268*cdf0e10cSrcweir 	}
269*cdf0e10cSrcweir 
270*cdf0e10cSrcweir 	try
271*cdf0e10cSrcweir 	{
272*cdf0e10cSrcweir         fprintf( stderr, "%2\n" );
273*cdf0e10cSrcweir 		Any blup;
274*cdf0e10cSrcweir 		blup <<= aStructC;
275*cdf0e10cSrcweir 		Any gulp;
276*cdf0e10cSrcweir         rField = Reference< XIdlField2 > ( xRefl->forName(OUString::createFromAscii("ModuleA.StructC"))->getField(OUString::createFromAscii("aString")) , UNO_QUERY);
277*cdf0e10cSrcweir         rField->set( blup, gulp);
278*cdf0e10cSrcweir //  		xRefl->forName(OUString::createFromAscii("ModuleA.StructC"))->getField(OUString::createFromAscii("aString"))->set(blup, gulp);
279*cdf0e10cSrcweir 		TEST_ENSHURE(sal_False, "test_RegCoreReflection(): error 64");
280*cdf0e10cSrcweir 		return sal_False;
281*cdf0e10cSrcweir 	}
282*cdf0e10cSrcweir 	catch (IllegalArgumentException &)
283*cdf0e10cSrcweir 	{
284*cdf0e10cSrcweir 	}
285*cdf0e10cSrcweir 
286*cdf0e10cSrcweir 	try
287*cdf0e10cSrcweir 	{
288*cdf0e10cSrcweir         fprintf( stderr, "%3\n" );
289*cdf0e10cSrcweir 		Any gulp;
290*cdf0e10cSrcweir 		gulp <<= 3.14f;
291*cdf0e10cSrcweir 		Any blup;
292*cdf0e10cSrcweir 		blup <<= aStructC;
293*cdf0e10cSrcweir         rField = Reference< XIdlField2 > (
294*cdf0e10cSrcweir             xRefl->forName(OUString::createFromAscii("ModuleA.StructC"))->getField(OUString::createFromAscii("aString")) , UNO_QUERY);
295*cdf0e10cSrcweir 		xRefl->forName(OUString::createFromAscii("ModuleA.StructC"))->getField(OUString::createFromAscii("aString"))->set(blup, gulp);
296*cdf0e10cSrcweir 		TEST_ENSHURE(sal_False, "test_RegCoreReflection(): error 65");
297*cdf0e10cSrcweir 		return sal_False;
298*cdf0e10cSrcweir 	}
299*cdf0e10cSrcweir 	catch (IllegalArgumentException &)
300*cdf0e10cSrcweir 	{
301*cdf0e10cSrcweir 	}
302*cdf0e10cSrcweir 
303*cdf0e10cSrcweir 	Any gulp;
304*cdf0e10cSrcweir 	gulp <<= OUString(OUString::createFromAscii("Test"));
305*cdf0e10cSrcweir 	Any blup;
306*cdf0e10cSrcweir 	blup <<= aStructC;
307*cdf0e10cSrcweir 	xRefl->forName(OUString::createFromAscii("ModuleA.StructC"))->getField(OUString::createFromAscii("aString"))->set(blup, gulp);
308*cdf0e10cSrcweir 
309*cdf0e10cSrcweir 	Reference< XInterfaceA > xAI = new OInterfaceA();
310*cdf0e10cSrcweir 
311*cdf0e10cSrcweir 	try
312*cdf0e10cSrcweir 	{
313*cdf0e10cSrcweir 		Sequence< Any > params;
314*cdf0e10cSrcweir         fprintf( stderr, "%4\n" );
315*cdf0e10cSrcweir 
316*cdf0e10cSrcweir 		Any a;
317*cdf0e10cSrcweir 		a <<= xAI;
318*cdf0e10cSrcweir 		Any bla = xRefl->forName(OUString::createFromAscii("ModuleC.XInterfaceA"))->getMethod(OUString::createFromAscii("methodC"))->invoke(a, params);
319*cdf0e10cSrcweir 		TEST_ENSHURE(sal_False, "test_RegCoreReflection(): error 66");
320*cdf0e10cSrcweir 		return sal_False;
321*cdf0e10cSrcweir 	}
322*cdf0e10cSrcweir 	catch (IllegalArgumentException &)
323*cdf0e10cSrcweir 	{
324*cdf0e10cSrcweir 	}
325*cdf0e10cSrcweir 
326*cdf0e10cSrcweir 	StructA aStructA;
327*cdf0e10cSrcweir 
328*cdf0e10cSrcweir 	{
329*cdf0e10cSrcweir 		Sequence< Any > params(2);
330*cdf0e10cSrcweir 
331*cdf0e10cSrcweir 		params.getArray()[0].setValue(&aStructC, ::getCppuType( (const StructC *)0 ));
332*cdf0e10cSrcweir 		params.getArray()[1].setValue(&aStructC, ::getCppuType( (const StructC *)0 ));
333*cdf0e10cSrcweir 
334*cdf0e10cSrcweir 		Any a;
335*cdf0e10cSrcweir 		a <<= xAI;
336*cdf0e10cSrcweir 		Any bla = xRefl->forName(OUString::createFromAscii("ModuleC.XInterfaceA"))->getMethod(OUString::createFromAscii("methodC"))->invoke(a, params);
337*cdf0e10cSrcweir 	}
338*cdf0e10cSrcweir 	try
339*cdf0e10cSrcweir 	{
340*cdf0e10cSrcweir 		Sequence< Any > params(2);
341*cdf0e10cSrcweir 
342*cdf0e10cSrcweir 		params.getArray()[0].setValue(&aStructA, ::getCppuType( (const StructA *)0 ));
343*cdf0e10cSrcweir 		params.getArray()[1].setValue(&aStructA, ::getCppuType( (const StructA *)0 ));
344*cdf0e10cSrcweir 
345*cdf0e10cSrcweir 		Any a;
346*cdf0e10cSrcweir 		a <<= xAI;
347*cdf0e10cSrcweir 		Any bla = xRefl->forName(OUString::createFromAscii("ModuleC.XInterfaceA"))->getMethod(OUString::createFromAscii("methodC"))->invoke(a, params);
348*cdf0e10cSrcweir 		TEST_ENSHURE(sal_False, "test_RegCoreReflection(): error 67");
349*cdf0e10cSrcweir 		return sal_False;
350*cdf0e10cSrcweir 	}
351*cdf0e10cSrcweir 	catch (IllegalArgumentException &)
352*cdf0e10cSrcweir 	{
353*cdf0e10cSrcweir 	}
354*cdf0e10cSrcweir 
355*cdf0e10cSrcweir 	Sequence< Any > params(2);
356*cdf0e10cSrcweir 
357*cdf0e10cSrcweir 	params.getArray()[0].setValue(&aStructC, ::getCppuType( (const StructC *)0 ));
358*cdf0e10cSrcweir 	params.getArray()[1].setValue(&aStructA, ::getCppuType( (const StructA *)0 ));
359*cdf0e10cSrcweir 
360*cdf0e10cSrcweir 	Any a;
361*cdf0e10cSrcweir 	a <<= xAI;
362*cdf0e10cSrcweir 	TEST_ENSHURE(xRefl->forName(OUString::createFromAscii("ModuleC.XInterfaceA"))->getMethod(OUString::createFromAscii("methodC"))->invoke(a, params).getValueType()
363*cdf0e10cSrcweir 		== ::getCppuType( (const Sequence<StructB> *)0 ), "test_RegCoreReflection(): error 68");
364*cdf0e10cSrcweir 
365*cdf0e10cSrcweir 	return sal_True;
366*cdf0e10cSrcweir }
367*cdf0e10cSrcweir 
368*cdf0e10cSrcweir SAL_IMPLEMENT_MAIN()
369*cdf0e10cSrcweir {
370*cdf0e10cSrcweir 	sal_Bool bSucc = sal_False;
371*cdf0e10cSrcweir 	try
372*cdf0e10cSrcweir 	{
373*cdf0e10cSrcweir 		OUString aLibName( RTL_CONSTASCII_USTRINGPARAM(
374*cdf0e10cSrcweir                                "reflection.uno" SAL_DLLEXTENSION) );
375*cdf0e10cSrcweir 
376*cdf0e10cSrcweir         Reference< XMultiServiceFactory > xMgr(
377*cdf0e10cSrcweir             createRegistryServiceFactory(
378*cdf0e10cSrcweir                 OUString( RTL_CONSTASCII_USTRINGPARAM("stoctest.rdb") ) ) );
379*cdf0e10cSrcweir         Reference< XComponentContext > xContext;
380*cdf0e10cSrcweir         Reference< beans::XPropertySet > xProps( xMgr, UNO_QUERY );
381*cdf0e10cSrcweir         OSL_ASSERT( xProps.is() );
382*cdf0e10cSrcweir         xProps->getPropertyValue(
383*cdf0e10cSrcweir             OUString( RTL_CONSTASCII_USTRINGPARAM("DefaultContext") ) ) >>=
384*cdf0e10cSrcweir             xContext;
385*cdf0e10cSrcweir         OSL_ASSERT( xContext.is() );
386*cdf0e10cSrcweir 
387*cdf0e10cSrcweir         Reference< XIdlReflection > xRefl;
388*cdf0e10cSrcweir         xContext->getValueByName(
389*cdf0e10cSrcweir             OUString(
390*cdf0e10cSrcweir                 RTL_CONSTASCII_USTRINGPARAM(
391*cdf0e10cSrcweir                     "/singletons/com.sun.star.reflection.theCoreReflection")) )
392*cdf0e10cSrcweir                         >>= xRefl;
393*cdf0e10cSrcweir         OSL_ENSURE(
394*cdf0e10cSrcweir             xRefl.is(), "### CoreReflection singleton not accessable!?" );
395*cdf0e10cSrcweir 
396*cdf0e10cSrcweir 		bSucc = test_corefl( xRefl );
397*cdf0e10cSrcweir 
398*cdf0e10cSrcweir         Reference< XComponent >( xContext, UNO_QUERY )->dispose();
399*cdf0e10cSrcweir 	}
400*cdf0e10cSrcweir 	catch (Exception & rExc)
401*cdf0e10cSrcweir 	{
402*cdf0e10cSrcweir 		OSL_ENSURE( sal_False, "### exception occured!" );
403*cdf0e10cSrcweir 		OString aMsg(
404*cdf0e10cSrcweir             OUStringToOString( rExc.Message, RTL_TEXTENCODING_ASCII_US ) );
405*cdf0e10cSrcweir 		OSL_TRACE( "### exception occured: " );
406*cdf0e10cSrcweir 		OSL_TRACE( aMsg.getStr() );
407*cdf0e10cSrcweir 		OSL_TRACE( "\n" );
408*cdf0e10cSrcweir 	}
409*cdf0e10cSrcweir 
410*cdf0e10cSrcweir 	printf( "testcorefl %s !\n", (bSucc ? "succeeded" : "failed") );
411*cdf0e10cSrcweir 	return (bSucc ? 0 : -1);
412*cdf0e10cSrcweir }
413