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