Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 :
21 : #include <stdio.h>
22 : #include <string.h>
23 : #include <osl/diagnose.h>
24 : #include "osl/diagnose.hxx"
25 : #include <osl/time.h>
26 : #include <sal/types.h>
27 : #include "typelib/typedescription.hxx"
28 : #include <uno/dispatcher.hxx>
29 : #include "uno/mapping.hxx"
30 : #include <uno/data.h>
31 : #include "uno/environment.hxx"
32 :
33 : #include <cppuhelper/factory.hxx>
34 : #include <cppuhelper/implbase2.hxx>
35 : #include <cppuhelper/implbase1.hxx>
36 :
37 : #include <com/sun/star/lang/XServiceInfo.hpp>
38 : #include <com/sun/star/lang/XComponent.hpp>
39 : #include <com/sun/star/lang/XMain.hpp>
40 : #include <com/sun/star/bridge/UnoUrlResolver.hpp>
41 : #include <com/sun/star/bridge/XUnoUrlResolver.hpp>
42 : #include "com/sun/star/uno/RuntimeException.hpp"
43 : #include "com/sun/star/uno/Type.hxx"
44 :
45 : #include "test/testtools/bridgetest/BadConstructorArguments.hpp"
46 : #include "test/testtools/bridgetest/TestPolyStruct.hpp"
47 : #include "test/testtools/bridgetest/XBridgeTest.hpp"
48 : #include "test/testtools/bridgetest/XBridgeTest2.hpp"
49 : #include "test/testtools/bridgetest/XMulti.hpp"
50 :
51 : #include "currentcontextchecker.hxx"
52 : #include "multi.hxx"
53 :
54 : using namespace osl;
55 : using namespace cppu;
56 : using namespace com::sun::star::uno;
57 : using namespace com::sun::star::lang;
58 : using namespace com::sun::star::registry;
59 : using namespace com::sun::star::bridge;
60 : using namespace test::testtools::bridgetest;
61 :
62 : using ::rtl::OUString;
63 : using ::rtl::OString;
64 : using ::rtl::OUStringToOString;
65 :
66 : #define SERVICENAME "com.sun.star.test.bridge.BridgeTest"
67 : #define IMPLNAME "com.sun.star.comp.bridge.BridgeTest"
68 :
69 : #define OUSTR(x) ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(x) )
70 : #define STRING_TEST_CONSTANT "\" paco\' chorizo\\\' \"\'"
71 :
72 : namespace bridge_test
73 : {
74 : template< class T>
75 : Sequence<T> cloneSequence(const Sequence<T>& val);
76 :
77 : //--------------------------------------------------------------------------------------------------
78 1 : inline static Sequence< OUString > getSupportedServiceNames()
79 : {
80 1 : OUString aName( RTL_CONSTASCII_USTRINGPARAM(SERVICENAME) );
81 1 : return Sequence< OUString >( &aName, 1 );
82 : }
83 :
84 571 : static bool check( bool b , char const * message )
85 : {
86 571 : if ( ! b )
87 0 : fprintf( stderr, "%s failed\n" , message );
88 571 : return b;
89 : }
90 :
91 : namespace {
92 :
93 2 : bool checkEmpty(rtl::OUString const & string, char const * message) {
94 2 : bool ok = string.isEmpty();
95 2 : if (!ok) {
96 : fprintf(
97 : stderr, "%s failed: %s\n", message,
98 0 : rtl::OUStringToOString(string, RTL_TEXTENCODING_UTF8).getStr());
99 : }
100 2 : return ok;
101 : }
102 :
103 : }
104 :
105 : //==================================================================================================
106 : class TestBridgeImpl : public osl::DebugBase<TestBridgeImpl>,
107 : public WeakImplHelper2< XMain, XServiceInfo >
108 : {
109 : Reference< XComponentContext > m_xContext;
110 :
111 : public:
112 1 : TestBridgeImpl( const Reference< XComponentContext > & xContext )
113 1 : : m_xContext( xContext )
114 1 : {}
115 2 : virtual ~TestBridgeImpl()
116 1 : {
117 2 : }
118 :
119 : // XServiceInfo
120 : virtual OUString SAL_CALL getImplementationName() throw (RuntimeException);
121 : virtual sal_Bool SAL_CALL supportsService( const OUString & rServiceName ) throw (RuntimeException);
122 : virtual Sequence< OUString > SAL_CALL getSupportedServiceNames() throw (RuntimeException);
123 :
124 : // XMain
125 : virtual sal_Int32 SAL_CALL run( const Sequence< OUString > & rArgs ) throw (RuntimeException);
126 : };
127 :
128 : //==================================================================================================
129 33 : static sal_Bool equals( const TestElement & rData1, const TestElement & rData2 )
130 : {
131 33 : check( rData1.Bool == rData2.Bool, "### bool does not match!" );
132 33 : check( rData1.Char == rData2.Char, "### char does not match!" );
133 33 : check( rData1.Byte == rData2.Byte, "### byte does not match!" );
134 33 : check( rData1.Short == rData2.Short, "### short does not match!" );
135 33 : check( rData1.UShort == rData2.UShort, "### unsigned short does not match!" );
136 33 : check( rData1.Long == rData2.Long, "### long does not match!" );
137 33 : check( rData1.ULong == rData2.ULong, "### unsigned long does not match!" );
138 33 : check( rData1.Hyper == rData2.Hyper, "### hyper does not match!" );
139 33 : check( rData1.UHyper == rData2.UHyper, "### unsigned hyper does not match!" );
140 33 : check( rData1.Float == rData2.Float, "### float does not match!" );
141 33 : check( rData1.Double == rData2.Double, "### double does not match!" );
142 33 : check( rData1.Enum == rData2.Enum, "### enum does not match!" );
143 33 : check( rData1.String == rData2.String, "### string does not match!" );
144 33 : check( rData1.Interface == rData2.Interface, "### interface does not match!" );
145 33 : check( rData1.Any == rData2.Any, "### any does not match!" );
146 :
147 : return (rData1.Bool == rData2.Bool &&
148 : rData1.Char == rData2.Char &&
149 : rData1.Byte == rData2.Byte &&
150 : rData1.Short == rData2.Short &&
151 : rData1.UShort == rData2.UShort &&
152 : rData1.Long == rData2.Long &&
153 : rData1.ULong == rData2.ULong &&
154 : rData1.Hyper == rData2.Hyper &&
155 : rData1.UHyper == rData2.UHyper &&
156 : rData1.Float == rData2.Float &&
157 : rData1.Double == rData2.Double &&
158 : rData1.Enum == rData2.Enum &&
159 33 : rData1.String == rData2.String &&
160 33 : rData1.Interface == rData2.Interface &&
161 99 : rData1.Any == rData2.Any);
162 : }
163 : //==================================================================================================
164 11 : static sal_Bool equals( const TestData & rData1, const TestData & rData2 )
165 : {
166 : sal_Int32 nLen;
167 :
168 44 : if ((rData1.Sequence == rData2.Sequence) &&
169 11 : equals( (const TestElement &)rData1, (const TestElement &)rData2 ) &&
170 22 : (nLen = rData1.Sequence.getLength()) == rData2.Sequence.getLength())
171 : {
172 : // once again by hand sequence ==
173 11 : const TestElement * pElements1 = rData1.Sequence.getConstArray();
174 11 : const TestElement * pElements2 = rData2.Sequence.getConstArray();
175 11 : for ( ; nLen--; )
176 : {
177 22 : if (! equals( pElements1[nLen], pElements2[nLen] ))
178 : {
179 0 : check( sal_False, "### sequence element did not match!" );
180 0 : return sal_False;
181 : }
182 : }
183 11 : return sal_True;
184 : }
185 0 : return sal_False;
186 : }
187 : //==================================================================================================
188 5 : static void assign( TestElement & rData,
189 : sal_Bool bBool, sal_Unicode cChar, sal_Int8 nByte,
190 : sal_Int16 nShort, sal_uInt16 nUShort,
191 : sal_Int32 nLong, sal_uInt32 nULong,
192 : sal_Int64 nHyper, sal_uInt64 nUHyper,
193 : float fFloat, double fDouble,
194 : TestEnum eEnum, const ::rtl::OUString& rStr,
195 : const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& xTest,
196 : const ::com::sun::star::uno::Any& rAny )
197 : {
198 5 : rData.Bool = bBool;
199 5 : rData.Char = cChar;
200 5 : rData.Byte = nByte;
201 5 : rData.Short = nShort;
202 5 : rData.UShort = nUShort;
203 5 : rData.Long = nLong;
204 5 : rData.ULong = nULong;
205 5 : rData.Hyper = nHyper;
206 5 : rData.UHyper = nUHyper;
207 5 : rData.Float = fFloat;
208 5 : rData.Double = fDouble;
209 5 : rData.Enum = eEnum;
210 5 : rData.String = rStr;
211 5 : rData.Interface = xTest;
212 5 : rData.Any = rAny;
213 5 : }
214 :
215 : namespace {
216 :
217 : template < typename T >
218 14 : bool testAny(
219 : T const & value, Reference< XBridgeTest > const & xLBT,
220 : char const * typeName = 0)
221 : {
222 14 : Any any;
223 14 : any <<= value;
224 14 : Any any2 = xLBT->transportAny(any);
225 14 : bool success = true;
226 14 : if (any != any2) {
227 : fprintf(
228 : stderr, "any is different after roundtrip: in %s, out %s\n",
229 : OUStringToOString(
230 : any.getValueType().getTypeName(),
231 : RTL_TEXTENCODING_ASCII_US).getStr(),
232 : OUStringToOString(
233 : any2.getValueType().getTypeName(),
234 0 : RTL_TEXTENCODING_ASCII_US).getStr());
235 0 : success = false;
236 : }
237 14 : if (typeName != 0
238 : && !any2.getValueType().getTypeName().equalsAscii(typeName))
239 : {
240 : fprintf(
241 : stderr, "any has wrong type after roundtrip: %s instead of %s\n",
242 : OUStringToOString(
243 : any2.getValueType().getTypeName(),
244 : RTL_TEXTENCODING_ASCII_US).getStr(),
245 0 : typeName);
246 0 : success = false;
247 : }
248 14 : return success;
249 : }
250 :
251 : }
252 :
253 1 : static sal_Bool performAnyTest( const Reference< XBridgeTest > &xLBT, const TestData &data)
254 : {
255 1 : bool bReturn = true;
256 1 : bReturn = testAny( data.Byte ,xLBT ) && bReturn;
257 1 : bReturn = testAny( data.Short,xLBT ) && bReturn;
258 1 : bReturn = testAny( data.UShort,xLBT ) && bReturn;
259 1 : bReturn = testAny( data.Long,xLBT ) && bReturn;
260 1 : bReturn = testAny( data.ULong,xLBT ) && bReturn;
261 1 : bReturn = testAny( data.Hyper,xLBT ) && bReturn;
262 1 : bReturn = testAny( data.UHyper,xLBT ) && bReturn;
263 1 : bReturn = testAny( data.Float,xLBT ) && bReturn;
264 1 : bReturn = testAny( data.Double,xLBT ) && bReturn;
265 1 : bReturn = testAny( data.Enum,xLBT ) && bReturn;
266 1 : bReturn = testAny( data.String,xLBT ) && bReturn;
267 1 : bReturn = testAny( data.Interface,xLBT ) && bReturn;
268 1 : bReturn = testAny( data, xLBT ) && bReturn;
269 : bReturn &= testAny(
270 : TestPolyStruct< sal_Unicode >(' '), xLBT,
271 1 : "test.testtools.bridgetest.TestPolyStruct<char>");
272 :
273 1 : Any a;
274 : {
275 1 : a.setValue( &(data.Bool) , getCppuBooleanType() );
276 1 : Any a2 = xLBT->transportAny( a );
277 1 : OSL_ASSERT( a2 == a );
278 : }
279 :
280 : {
281 1 : a.setValue( &(data.Char) , getCppuCharType() );
282 1 : Any a2 = xLBT->transportAny( a );
283 1 : OSL_ASSERT( a2 == a );
284 : }
285 :
286 1 : return bReturn;
287 : }
288 :
289 : //_______________________________________________________________________________________
290 1 : static sal_Bool performSequenceOfCallTest( const Reference < XBridgeTest > &xLBT )
291 : {
292 : sal_Int32 i,nRounds;
293 1 : sal_Int32 nGlobalIndex = 0;
294 1 : const sal_Int32 nWaitTimeSpanMUSec = 10000;
295 11 : for( nRounds = 0 ; nRounds < 10 ; nRounds ++ )
296 : {
297 55 : for( i = 0 ; i < nRounds ; i ++ )
298 : {
299 : // fire oneways
300 45 : xLBT->callOneway( nGlobalIndex , nWaitTimeSpanMUSec );
301 45 : nGlobalIndex ++;
302 : }
303 :
304 : // call synchron
305 10 : xLBT->call( nGlobalIndex , nWaitTimeSpanMUSec );
306 10 : nGlobalIndex ++;
307 : }
308 :
309 1 : return xLBT->sequenceOfCallTestPassed();
310 : }
311 :
312 3 : class ORecursiveCall : public WeakImplHelper1< XRecursiveCall >
313 : {
314 : private:
315 : Mutex m_mutex;
316 :
317 : public:
318 25 : void SAL_CALL callRecursivly(
319 : const ::com::sun::star::uno::Reference< XRecursiveCall >& xCall,
320 : sal_Int32 nToCall )
321 : throw(::com::sun::star::uno::RuntimeException)
322 : {
323 25 : MutexGuard guard( m_mutex );
324 25 : if( nToCall )
325 : {
326 25 : nToCall --;
327 25 : xCall->callRecursivly( this , nToCall );
328 25 : }
329 :
330 25 : }
331 : };
332 :
333 :
334 : //_______________________________________________________________________________________
335 1 : static sal_Bool performRecursiveCallTest( const Reference < XBridgeTest > & xLBT )
336 : {
337 1 : xLBT->startRecursiveCall( new ORecursiveCall , 50 );
338 : // on failure, the test would lock up or crash
339 1 : return sal_True;
340 : }
341 :
342 : class MyClass : public osl::DebugBase<MyClass>, public OWeakObject
343 : {
344 : public:
345 : MyClass();
346 : virtual ~MyClass();
347 : virtual void SAL_CALL acquire() throw ();
348 : virtual void SAL_CALL release() throw ();
349 : };
350 :
351 : //______________________________________________________________________________
352 1 : MyClass::MyClass()
353 : {
354 1 : }
355 : //______________________________________________________________________________
356 2 : MyClass::~MyClass()
357 : {
358 2 : }
359 : //______________________________________________________________________________
360 80 : void MyClass::acquire() throw ()
361 : {
362 80 : OWeakObject::acquire();
363 80 : }
364 : //______________________________________________________________________________
365 80 : void MyClass::release() throw ()
366 : {
367 80 : OWeakObject::release();
368 80 : }
369 :
370 : //==================================================================================================
371 1 : static sal_Bool performTest(
372 : const Reference<XComponentContext> & xContext,
373 : const Reference<XBridgeTest > & xLBT,
374 : bool noCurrentContext )
375 : {
376 1 : check(xLBT.is(), "### no test interface!");
377 1 : bool bRet = true;
378 1 : if (xLBT.is()) {
379 : // this data is never ever granted access to by calls other than
380 : // equals(), assign()!
381 1 : TestData aData; // test against this data
382 1 : Reference< XInterface > xI(new MyClass);
383 : assign(
384 : (TestElement &) aData, true, '@', 17, 0x1234, 0xFEDC, 0x12345678,
385 : 0xFEDCBA98, SAL_CONST_INT64(0x123456789ABCDEF0),
386 : SAL_CONST_UINT64(0xFEDCBA9876543210), 17.0815f, 3.1415926359,
387 : TestEnum_LOLA, OUSTR(STRING_TEST_CONSTANT), xI,
388 1 : Any(&xI, getCppuType((Reference< XInterface > const *) 0)));
389 1 : bRet &= check(aData.Any == xI, "### unexpected any!");
390 1 : bRet &= check(!(aData.Any != xI), "### unexpected any!");
391 1 : aData.Sequence.realloc(2);
392 1 : aData.Sequence[0] = *(TestElement const *) &aData;
393 : // aData.Sequence[1] is empty
394 : // aSetData is a manually copy of aData for first setting:
395 1 : TestData aSetData;
396 : assign(
397 : (TestElement &) aSetData, aData.Bool, aData.Char, aData.Byte,
398 : aData.Short, aData.UShort, aData.Long, aData.ULong, aData.Hyper,
399 : aData.UHyper, aData.Float, aData.Double, aData.Enum, aData.String,
400 1 : xI, Any(&xI, getCppuType((Reference< XInterface > const *) 0)));
401 1 : aSetData.Sequence.realloc(2);
402 1 : aSetData.Sequence[0] = *(TestElement const *) &aSetData;
403 : // aSetData.Sequence[1] is empty
404 1 : xLBT->setValues(
405 : aSetData.Bool, aSetData.Char, aSetData.Byte, aSetData.Short,
406 : aSetData.UShort, aSetData.Long, aSetData.ULong, aSetData.Hyper,
407 : aSetData.UHyper, aSetData.Float, aSetData.Double, aSetData.Enum,
408 : aSetData.String, aSetData.Interface, aSetData.Any,
409 1 : aSetData.Sequence, aSetData);
410 : {
411 1 : TestData aRet;
412 1 : TestData aRet2;
413 1 : xLBT->getValues(
414 : aRet.Bool, aRet.Char, aRet.Byte, aRet.Short, aRet.UShort,
415 : aRet.Long, aRet.ULong, aRet.Hyper, aRet.UHyper, aRet.Float,
416 : aRet.Double, aRet.Enum, aRet.String, aRet.Interface, aRet.Any,
417 1 : aRet.Sequence, aRet2);
418 : bRet &= check(
419 1 : equals(aData, aRet) && equals(aData, aRet2), "getValues test");
420 : // Set last retrieved values:
421 : TestData aSV2ret(
422 1 : xLBT->setValues2(
423 : aRet.Bool, aRet.Char, aRet.Byte, aRet.Short, aRet.UShort,
424 : aRet.Long, aRet.ULong, aRet.Hyper, aRet.UHyper, aRet.Float,
425 : aRet.Double, aRet.Enum, aRet.String, aRet.Interface,
426 1 : aRet.Any, aRet.Sequence, aRet2));
427 : // Check inout sequence order (=> inout sequence parameter was
428 : // switched by test objects):
429 1 : TestElement temp(aRet.Sequence[0]);
430 1 : aRet.Sequence[0] = aRet.Sequence[1];
431 1 : aRet.Sequence[1] = temp;
432 : bRet &= check(
433 2 : equals(aData, aSV2ret) && equals(aData, aRet2),
434 2 : "getValues2 test");
435 : }
436 : {
437 1 : TwoFloats aIn(1.1f, 2.2f);
438 1 : TwoFloats aOut = xLBT->echoTwoFloats(aIn);
439 1 : bRet = check( memcmp(&aIn, &aOut, sizeof(TwoFloats)) == 0, "two floats struct test" ) && bRet;
440 : }
441 : {
442 1 : FourFloats aIn(3.3f, 4.4f, 5.5f, 6.6f);
443 1 : FourFloats aOut = xLBT->echoFourFloats(aIn);
444 1 : bRet = check( memcmp(&aIn, &aOut, sizeof(FourFloats)) == 0, "four floats struct test" ) && bRet;
445 : }
446 : {
447 1 : MixedFloatAndInteger aIn(7.7f, 8);
448 1 : MixedFloatAndInteger aOut = xLBT->echoMixedFloatAndInteger(aIn);
449 1 : bRet = check( memcmp(&aIn, &aOut, sizeof(MixedFloatAndInteger)) == 0, "mixed float and integer struct test" ) && bRet;
450 : }
451 : {
452 1 : ThreeByteStruct aIn(9, 10, 11);
453 1 : ThreeByteStruct aOut = xLBT->echoThreeByteStruct(aIn);
454 1 : bRet = check( memcmp(&aIn, &aOut, sizeof(ThreeByteStruct)) == 0, "three byte struct test" ) && bRet;
455 : }
456 : {
457 1 : TestData aRet;
458 1 : TestData aRet2;
459 : TestData aGVret(
460 1 : xLBT->getValues(
461 : aRet.Bool, aRet.Char, aRet.Byte, aRet.Short, aRet.UShort,
462 : aRet.Long, aRet.ULong, aRet.Hyper, aRet.UHyper, aRet.Float,
463 : aRet.Double, aRet.Enum, aRet.String, aRet.Interface,
464 1 : aRet.Any, aRet.Sequence, aRet2));
465 : bRet &= check(
466 2 : (equals(aData, aRet) && equals(aData, aRet2) &&
467 1 : equals(aData, aGVret)),
468 3 : "getValues test");
469 : // Set last retrieved values:
470 1 : xLBT->setBool(aRet.Bool);
471 1 : xLBT->setChar(aRet.Char);
472 1 : xLBT->setByte(aRet.Byte);
473 1 : xLBT->setShort(aRet.Short);
474 1 : xLBT->setUShort(aRet.UShort);
475 1 : xLBT->setLong(aRet.Long);
476 1 : xLBT->setULong(aRet.ULong);
477 1 : xLBT->setHyper(aRet.Hyper);
478 1 : xLBT->setUHyper(aRet.UHyper);
479 1 : xLBT->setFloat(aRet.Float);
480 1 : xLBT->setDouble(aRet.Double);
481 1 : xLBT->setEnum(aRet.Enum);
482 1 : xLBT->setString(aRet.String);
483 1 : xLBT->setInterface(aRet.Interface);
484 1 : xLBT->setAny(aRet.Any);
485 1 : xLBT->setSequence(aRet.Sequence);
486 1 : xLBT->setStruct(aRet2);
487 : }
488 : {
489 1 : TestData aRet;
490 1 : aRet.Hyper = xLBT->getHyper();
491 1 : aRet.UHyper = xLBT->getUHyper();
492 1 : aRet.Float = xLBT->getFloat();
493 1 : aRet.Double = xLBT->getDouble();
494 1 : aRet.Byte = xLBT->getByte();
495 1 : aRet.Char = xLBT->getChar();
496 1 : aRet.Bool = xLBT->getBool();
497 1 : aRet.Short = xLBT->getShort();
498 1 : aRet.UShort = xLBT->getUShort();
499 1 : aRet.Long = xLBT->getLong();
500 1 : aRet.ULong = xLBT->getULong();
501 1 : aRet.Enum = xLBT->getEnum();
502 1 : aRet.String = xLBT->getString();
503 1 : aRet.Interface = xLBT->getInterface();
504 1 : aRet.Any = xLBT->getAny();
505 1 : aRet.Sequence = xLBT->getSequence();
506 1 : TestData aRet2(xLBT->getStruct());
507 : bRet &= check(
508 2 : equals(aData, aRet) && equals(aData, aRet2),
509 2 : "struct comparison test");
510 : {
511 1 : SmallStruct aIn(1, 2);
512 1 : SmallStruct aOut(xLBT->echoSmallStruct(aIn));
513 : bRet &= check(
514 1 : memcmp(&aIn, &aOut, sizeof(SmallStruct)) == 0,
515 1 : "small struct test");
516 : }
517 : {
518 1 : MediumStruct aIn(1, 2, 3, 4);
519 1 : MediumStruct aOut(xLBT->echoMediumStruct(aIn));
520 : bRet &= check(
521 1 : memcmp(&aIn, &aOut, sizeof(MediumStruct)) == 0,
522 1 : "medium struct test");
523 : }
524 : {
525 1 : BigStruct aIn(1, 2, 3, 4, 5, 6, 7, 8);
526 1 : BigStruct aOut(xLBT->echoBigStruct(aIn));
527 : bRet &= check(
528 1 : memcmp(&aIn, &aOut, sizeof(BigStruct)) == 0,
529 1 : "big struct test");
530 : }
531 : {
532 1 : sal_Int32 i2 = xLBT->testPPCAlignment(0, 0, 0, 0, 0xBEAF);
533 1 : bRet &= check(i2 == 0xBEAF, "ppc-style alignment test");
534 : }
535 : {
536 1 : double d1 = xLBT->testTenDoubles(0.1, 0.2, 0.3, 0.4, 0.5,
537 1 : 0.6, 0.7, 0.8, 0.9, 1.0);
538 1 : bRet &= check(d1 == 5.5, "armhf doubles test");
539 : }
540 : // Test extended attributes that raise exceptions:
541 : try {
542 1 : xLBT->getRaiseAttr1();
543 0 : bRet &= check(false, "getRaiseAttr1 did not throw");
544 1 : } catch (const RuntimeException &) {
545 0 : } catch (...) {
546 0 : bRet &= check(false, "getRaiseAttr1 threw wrong type");
547 : }
548 : try {
549 1 : xLBT->setRaiseAttr1(0);
550 0 : bRet &= check(false, "setRaiseAttr1 did not throw");
551 1 : } catch (const IllegalArgumentException &) {
552 0 : } catch (...) {
553 0 : bRet &= check(false, "setRaiseAttr1 threw wrong type");
554 : }
555 : try {
556 1 : xLBT->getRaiseAttr2();
557 0 : bRet &= check(false, "getRaiseAttr2 did not throw");
558 1 : } catch (const IllegalArgumentException &) {
559 0 : } catch (...) {
560 0 : bRet &= check(false, "getRaiseAttr2 threw wrong type");
561 : }
562 : // Test instantiated polymorphic struct types:
563 : {
564 : bRet &= check(
565 1 : (xLBT->transportPolyBoolean(
566 2 : TestPolyStruct< sal_Bool >(true)).
567 : member),
568 1 : "transportPolyBoolean");
569 1 : TestPolyStruct< sal_Int64 > tps1(12345);
570 1 : xLBT->transportPolyHyper(tps1);
571 1 : bRet &= check(tps1.member == 12345, "transportPolyHyper");
572 1 : Sequence< Any > seq(2);
573 1 : seq[0] <<= static_cast< sal_uInt32 >(33);
574 1 : seq[1] <<= rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ABC"));
575 1 : TestPolyStruct< Sequence< Any > > tps2(seq);
576 1 : TestPolyStruct< Sequence< Any > > tps3;
577 1 : xLBT->transportPolySequence(tps2, tps3);
578 : bRet &= check(
579 1 : tps3.member.getLength() == 2,
580 1 : "transportPolySequence, length");
581 1 : sal_uInt32 v0 = sal_uInt32();
582 1 : tps3.member[0] >>= v0;
583 1 : bRet &= check(v0 == 33, "transportPolySequence, element 0");
584 1 : rtl::OUString v1;
585 1 : tps3.member[1] >>= v1;
586 1 : bRet &= check( v1 == "ABC", "transportPolySequence, element 1" );
587 : bRet &= check(
588 1 : xLBT->getNullPolyLong().member == 0, "getNullPolyLong");
589 : bRet &= check(
590 2 : xLBT->getNullPolyString().member.isEmpty(),
591 1 : "getNullPolyString");
592 : bRet &= check(
593 2 : xLBT->getNullPolyType().member == Type(),
594 1 : "getNullPolyType");
595 1 : Any nullAny(xLBT->getNullPolyAny().member);
596 : bRet &= check(
597 : (((nullAny.getValueTypeName() ==
598 : rtl::OUString(
599 : RTL_CONSTASCII_USTRINGPARAM(
600 4 : "com.sun.star.uno.XInterface"))) &&
601 : !static_cast< Reference< XInterface > const * >(
602 0 : nullAny.getValue())->is())
603 3 : || nullAny == Any()),
604 6 : "getNullPolyAny");
605 : bRet &= check(
606 2 : xLBT->getNullPolySequence().member.getLength() == 0,
607 1 : "getNullPolySequence");
608 : bRet &= check(
609 1 : xLBT->getNullPolyEnum().member == TestEnum_TEST,
610 1 : "getNullPolyEnum");
611 : bRet &= check(
612 1 : xLBT->getNullPolyBadEnum().member == TestBadEnum_M,
613 1 : "getNullPolyBadEnum");
614 : bRet &= check(
615 1 : xLBT->getNullPolyStruct().member.member == 0,
616 1 : "getNullPolyStruct");
617 : bRet &= check(
618 2 : !xLBT->getNullPolyInterface().member.is(),
619 2 : "getNullPolyInterface");
620 : }
621 : // Any test:
622 1 : bRet &= check(performAnyTest(xLBT , aData), "any test");
623 : // Sequence of call test:
624 : bRet &= check(
625 1 : performSequenceOfCallTest(xLBT), "sequence of call test");
626 : // Recursive call test:
627 1 : bRet &= check(performRecursiveCallTest(xLBT), "recursive test");
628 : bRet &= check(
629 2 : equals(aData, aRet) && equals(aData, aRet2),
630 2 : "recursive test results");
631 : // Multiple inheritance test:
632 : bRet &= checkEmpty(
633 2 : testtools::bridgetest::testMulti(xLBT->getMulti()),
634 2 : "remote multi");
635 : bRet &= checkEmpty(
636 2 : xLBT->testMulti(new testtools::bridgetest::Multi),
637 2 : "local multi");
638 1 : }
639 : }
640 : {
641 1 : Reference< XBridgeTest2 > xBT2(xLBT, UNO_QUERY);
642 1 : if (!xBT2.is()) {
643 0 : return bRet;
644 : }
645 : // Perform sequence tests (XBridgeTest2); create the sequence which is
646 : // compared with the results:
647 1 : sal_Bool _arBool[] = { true, false, true };
648 1 : sal_Unicode _arChar[] = { 0x0065, 0x0066, 0x0067 };
649 1 : sal_Int8 _arByte[] = { 1, 2, -1 };
650 1 : sal_Int16 _arShort[] = { -0x8000, 1, 0x7FFF };
651 1 : sal_uInt16 _arUShort[] = { 0 , 1, 0xFFFF };
652 : sal_Int32 _arLong[] = {
653 1 : static_cast< sal_Int32 >(0x80000000), 1, 0x7FFFFFFF };
654 1 : sal_uInt32 _arULong[] = { 0, 1, 0xFFFFFFFF };
655 : sal_Int64 _arHyper[] = {
656 : static_cast< sal_Int64 >(SAL_CONST_INT64(0x8000000000000000)), 1,
657 1 : SAL_CONST_INT64(0x7FFFFFFFFFFFFFFF) };
658 1 : sal_uInt64 _arUHyper[] = { 0, 1, SAL_CONST_UINT64(0xFFFFFFFFFFFFFFFF) };
659 1 : float _arFloat[] = { 1.1f, 2.2f, 3.3f };
660 1 : double _arDouble[] = { 1.11, 2.22, 3.33 };
661 : OUString _arString[] = {
662 : OUString(RTL_CONSTASCII_USTRINGPARAM("String 1")),
663 : OUString(RTL_CONSTASCII_USTRINGPARAM("String 2")),
664 4 : OUString(RTL_CONSTASCII_USTRINGPARAM("String 3")) };
665 1 : sal_Bool _aBool = true;
666 1 : sal_Int32 _aInt = 0xBABEBABE;
667 1 : float _aFloat = 3.14f;
668 1 : Any _any1(&_aBool, getCppuBooleanType());
669 1 : Any _any2(&_aInt, getCppuType((sal_Int32 *) 0));
670 1 : Any _any3(&_aFloat, getCppuType((float *) 0));
671 4 : Any _arAny[] = { _any1, _any2, _any3 };
672 4 : Reference< XInterface > _arObj[3];
673 1 : _arObj[0] = new OWeakObject();
674 1 : _arObj[1] = new OWeakObject();
675 1 : _arObj[2] = new OWeakObject();
676 1 : TestEnum _arEnum[] = { TestEnum_ONE, TestEnum_TWO, TestEnum_CHECK };
677 4 : TestElement _arStruct[3];
678 : assign(
679 : _arStruct[0], true, '@', 17, 0x1234, 0xFEDC, 0x12345678, 0xFEDCBA98,
680 : SAL_CONST_INT64(0x123456789ABCDEF0),
681 : SAL_CONST_UINT64(0xFEDCBA9876543210), 17.0815f, 3.1415926359,
682 : TestEnum_LOLA, OUSTR(STRING_TEST_CONSTANT), _arObj[0],
683 1 : Any(&_arObj[0], getCppuType((Reference< XInterface > const *) 0)));
684 : assign(
685 : _arStruct[1], true, 'A', 17, 0x1234, 0xFEDC, 0x12345678, 0xFEDCBA98,
686 : SAL_CONST_INT64(0x123456789ABCDEF0),
687 : SAL_CONST_UINT64(0xFEDCBA9876543210), 17.0815f, 3.1415926359,
688 : TestEnum_TWO, OUSTR(STRING_TEST_CONSTANT), _arObj[1],
689 1 : Any(&_arObj[1], getCppuType((Reference< XInterface > const *) 0)));
690 : assign(
691 : _arStruct[2], true, 'B', 17, 0x1234, 0xFEDC, 0x12345678, 0xFEDCBA98,
692 : SAL_CONST_INT64(0x123456789ABCDEF0),
693 : SAL_CONST_UINT64(0xFEDCBA9876543210), 17.0815f, 3.1415926359,
694 : TestEnum_CHECK, OUSTR(STRING_TEST_CONSTANT), _arObj[2],
695 1 : Any(&_arObj[2], getCppuType((Reference< XInterface > const *) 0)));
696 : {
697 1 : Sequence<sal_Bool> arBool(_arBool, 3);
698 1 : Sequence<sal_Unicode> arChar( _arChar, 3);
699 1 : Sequence<sal_Int8> arByte(_arByte, 3);
700 1 : Sequence<sal_Int16> arShort(_arShort, 3);
701 1 : Sequence<sal_uInt16> arUShort(_arUShort, 3);
702 1 : Sequence<sal_Int32> arLong(_arLong, 3);
703 1 : Sequence<sal_uInt32> arULong(_arULong, 3);
704 1 : Sequence<sal_Int64> arHyper(_arHyper, 3);
705 1 : Sequence<sal_uInt64> arUHyper(_arUHyper, 3);
706 1 : Sequence<float> arFloat(_arFloat, 3);
707 1 : Sequence<double> arDouble(_arDouble, 3);
708 1 : Sequence<OUString> arString(_arString, 3);
709 1 : Sequence<Any> arAny(_arAny, 3);
710 1 : Sequence<Reference<XInterface> > arObject(_arObj, 3);
711 1 : Sequence<TestEnum> arEnum(_arEnum, 3);
712 1 : Sequence<TestElement> arStruct(_arStruct, 3);
713 4 : Sequence<Sequence<sal_Int32> > _arSeqLong2[3];
714 4 : for (int j = 0; j != 3; ++j) {
715 12 : Sequence< sal_Int32 > _arSeqLong[3];
716 12 : for (int i = 0; i != 3; ++i) {
717 9 : _arSeqLong[i] = Sequence< sal_Int32 >(_arLong, 3);
718 : }
719 : _arSeqLong2[j] = Sequence< Sequence< sal_Int32 > >(
720 3 : _arSeqLong, 3);
721 12 : }
722 : Sequence< Sequence< Sequence< sal_Int32> > > arLong3(
723 1 : _arSeqLong2, 3);
724 : Sequence< Sequence< sal_Int32 > > seqSeqRet(
725 1 : xBT2->setDim2(arLong3[0]));
726 1 : bRet &= check(seqSeqRet == arLong3[0], "sequence test");
727 : Sequence< Sequence< Sequence< sal_Int32 > > > seqSeqRet2(
728 1 : xBT2->setDim3(arLong3));
729 1 : bRet &= check(seqSeqRet2 == arLong3, "sequence test");
730 1 : Sequence< Any > seqAnyRet(xBT2->setSequenceAny(arAny));
731 1 : bRet &= check(seqAnyRet == arAny, "sequence test");
732 1 : Sequence< sal_Bool > seqBoolRet(xBT2->setSequenceBool(arBool));
733 1 : bRet &= check(seqBoolRet == arBool, "sequence test");
734 1 : Sequence< sal_Int8 > seqByteRet(xBT2->setSequenceByte(arByte));
735 1 : bRet &= check(seqByteRet == arByte, "sequence test");
736 1 : Sequence< sal_Unicode > seqCharRet(xBT2->setSequenceChar(arChar));
737 1 : bRet &= check(seqCharRet == arChar, "sequence test");
738 1 : Sequence< sal_Int16 > seqShortRet(xBT2->setSequenceShort(arShort));
739 1 : bRet &= check(seqShortRet == arShort, "sequence test");
740 1 : Sequence< sal_Int32 > seqLongRet(xBT2->setSequenceLong(arLong));
741 1 : bRet &= check(seqLongRet == arLong, "sequence test");
742 1 : Sequence< sal_Int64 > seqHyperRet(xBT2->setSequenceHyper(arHyper));
743 1 : bRet &= check(seqHyperRet == arHyper, "sequence test");
744 1 : Sequence< float > seqFloatRet(xBT2->setSequenceFloat(arFloat));
745 1 : bRet &= check(seqFloatRet == arFloat, "sequence test");
746 1 : Sequence< double > seqDoubleRet(xBT2->setSequenceDouble(arDouble));
747 1 : bRet &= check(seqDoubleRet == arDouble, "sequence test");
748 1 : Sequence< TestEnum > seqEnumRet(xBT2->setSequenceEnum(arEnum));
749 1 : bRet &= check(seqEnumRet == arEnum, "sequence test");
750 : Sequence< sal_uInt16 > seqUShortRet(
751 1 : xBT2->setSequenceUShort(arUShort));
752 1 : bRet &= check(seqUShortRet == arUShort, "sequence test");
753 1 : Sequence< sal_uInt32 > seqULongRet(xBT2->setSequenceULong(arULong));
754 1 : bRet &= check(seqULongRet == arULong, "sequence test");
755 : Sequence< sal_uInt64 > seqUHyperRet(
756 1 : xBT2->setSequenceUHyper(arUHyper));
757 1 : bRet &= check(seqUHyperRet == arUHyper, "sequence test");
758 : Sequence< Reference< XInterface > > seqObjectRet(
759 1 : xBT2->setSequenceXInterface(arObject));
760 1 : bRet &= check(seqObjectRet == arObject, "sequence test");
761 : Sequence< OUString > seqStringRet(
762 1 : xBT2->setSequenceString(arString));
763 1 : bRet &= check(seqStringRet == arString, "sequence test");
764 : Sequence< TestElement > seqStructRet(
765 1 : xBT2->setSequenceStruct(arStruct));
766 1 : bRet &= check(seqStructRet == arStruct, "sequence test");
767 1 : Sequence< sal_Bool > arBoolTemp(cloneSequence(arBool));
768 1 : Sequence< sal_Unicode > arCharTemp(cloneSequence(arChar));
769 1 : Sequence< sal_Int8 > arByteTemp(cloneSequence(arByte));
770 1 : Sequence< sal_Int16 > arShortTemp(cloneSequence(arShort));
771 1 : Sequence< sal_uInt16 > arUShortTemp(cloneSequence(arUShort));
772 1 : Sequence< sal_Int32 > arLongTemp(cloneSequence(arLong));
773 1 : Sequence< sal_uInt32 > arULongTemp(cloneSequence(arULong));
774 1 : Sequence< sal_Int64 > arHyperTemp(cloneSequence(arHyper));
775 1 : Sequence< sal_uInt64 > arUHyperTemp(cloneSequence(arUHyper));
776 1 : Sequence< float > arFloatTemp(cloneSequence(arFloat));
777 1 : Sequence< double > arDoubleTemp(cloneSequence(arDouble));
778 1 : Sequence< TestEnum > arEnumTemp(cloneSequence(arEnum));
779 1 : Sequence< OUString > arStringTemp(cloneSequence(arString));
780 : Sequence< Reference< XInterface > > arObjectTemp(
781 1 : cloneSequence(arObject));
782 1 : Sequence< Any > arAnyTemp(cloneSequence(arAny));
783 1 : Sequence< Sequence< sal_Int32 > > arLong2Temp(arLong3[0]);
784 1 : Sequence< Sequence< Sequence< sal_Int32 > > > arLong3Temp(arLong3);
785 1 : xBT2->setSequencesInOut(
786 : arBoolTemp, arCharTemp, arByteTemp, arShortTemp, arUShortTemp,
787 : arLongTemp,arULongTemp, arHyperTemp, arUHyperTemp, arFloatTemp,
788 : arDoubleTemp, arEnumTemp, arStringTemp, arObjectTemp, arAnyTemp,
789 1 : arLong2Temp, arLong3Temp);
790 : bRet &= check(
791 2 : (arBoolTemp == arBool && arCharTemp == arChar &&
792 2 : arByteTemp == arByte && arShortTemp == arShort &&
793 2 : arUShortTemp == arUShort && arLongTemp == arLong &&
794 2 : arULongTemp == arULong && arHyperTemp == arHyper &&
795 2 : arUHyperTemp == arUHyper && arFloatTemp == arFloat &&
796 2 : arDoubleTemp == arDouble && arEnumTemp == arEnum &&
797 2 : arStringTemp == arString && arObjectTemp == arObject &&
798 2 : arAnyTemp == arAny && arLong2Temp == arLong3[0] &&
799 1 : arLong3Temp == arLong3),
800 17 : "sequence test");
801 1 : Sequence< sal_Bool > arBoolOut;
802 1 : Sequence< sal_Unicode > arCharOut;
803 1 : Sequence< sal_Int8 > arByteOut;
804 1 : Sequence< sal_Int16 > arShortOut;
805 1 : Sequence< sal_uInt16 > arUShortOut;
806 1 : Sequence< sal_Int32 > arLongOut;
807 1 : Sequence< sal_uInt32 > arULongOut;
808 1 : Sequence< sal_Int64 > arHyperOut;
809 1 : Sequence< sal_uInt64 > arUHyperOut;
810 1 : Sequence< float > arFloatOut;
811 1 : Sequence< double > arDoubleOut;
812 1 : Sequence< TestEnum > arEnumOut;
813 1 : Sequence< OUString > arStringOut;
814 1 : Sequence< Reference< XInterface > > arObjectOut;
815 1 : Sequence< Any > arAnyOut;
816 1 : Sequence< Sequence< sal_Int32 > > arLong2Out;
817 1 : Sequence< Sequence< Sequence< sal_Int32 > > > arLong3Out;
818 1 : xBT2->setSequencesOut(
819 : arBoolOut, arCharOut, arByteOut, arShortOut, arUShortOut,
820 : arLongOut,arULongOut, arHyperOut, arUHyperOut, arFloatOut,
821 : arDoubleOut, arEnumOut, arStringOut, arObjectOut, arAnyOut,
822 1 : arLong2Out, arLong3Out);
823 : bRet &= check(
824 2 : (arBoolOut == arBool && arCharOut == arChar &&
825 2 : arByteOut == arByte && arShortOut == arShort &&
826 2 : arUShortOut == arUShort && arLongOut == arLong &&
827 2 : arULongOut == arULong && arHyperOut == arHyper &&
828 2 : arUHyperOut == arUHyper && arFloatOut == arFloat &&
829 2 : arDoubleOut == arDouble && arEnumOut == arEnum &&
830 2 : arStringOut == arString && arObjectOut == arObject &&
831 2 : arAnyOut == arAny && arLong2Out == arLong3[0] &&
832 1 : arLong3Out == arLong3),
833 20 : "sequence test");
834 : }
835 : {
836 : // Test with empty sequences:
837 1 : Sequence< Sequence< sal_Int32 > > arLong2;
838 1 : Sequence< Sequence< sal_Int32 > > seqSeqRet(xBT2->setDim2(arLong2));
839 1 : bRet &= check(seqSeqRet == arLong2, "sequence test");
840 1 : Sequence< Sequence< Sequence< sal_Int32 > > > arLong3;
841 : Sequence< Sequence< Sequence< sal_Int32 > > > seqSeqRet2(
842 1 : xBT2->setDim3(arLong3));
843 1 : bRet &= check(seqSeqRet2 == arLong3, "sequence test");
844 1 : Sequence< Any > arAny;
845 1 : Sequence< Any > seqAnyRet(xBT2->setSequenceAny(arAny));
846 1 : bRet &= check(seqAnyRet == arAny, "sequence test");
847 1 : Sequence< sal_Bool > arBool;
848 1 : Sequence< sal_Bool > seqBoolRet(xBT2->setSequenceBool(arBool));
849 1 : bRet &= check(seqBoolRet == arBool, "sequence test");
850 1 : Sequence< sal_Int8 > arByte;
851 1 : Sequence< sal_Int8 > seqByteRet(xBT2->setSequenceByte(arByte));
852 1 : bRet &= check(seqByteRet == arByte, "sequence test");
853 1 : Sequence< sal_Unicode > arChar;
854 1 : Sequence< sal_Unicode > seqCharRet(xBT2->setSequenceChar(arChar));
855 1 : bRet &= check(seqCharRet == arChar, "sequence test");
856 1 : Sequence< sal_Int16 > arShort;
857 1 : Sequence< sal_Int16 > seqShortRet(xBT2->setSequenceShort(arShort));
858 1 : bRet &= check(seqShortRet == arShort, "sequence test");
859 1 : Sequence< sal_Int32 > arLong;
860 1 : Sequence< sal_Int32 > seqLongRet(xBT2->setSequenceLong(arLong));
861 1 : bRet &= check(seqLongRet == arLong, "sequence test");
862 1 : Sequence< sal_Int64 > arHyper;
863 1 : Sequence< sal_Int64 > seqHyperRet(xBT2->setSequenceHyper(arHyper));
864 1 : bRet &= check(seqHyperRet == arHyper, "sequence test");
865 1 : Sequence< float > arFloat;
866 1 : Sequence< float > seqFloatRet(xBT2->setSequenceFloat(arFloat));
867 1 : bRet &= check(seqFloatRet == arFloat, "sequence test");
868 1 : Sequence< double > arDouble;
869 1 : Sequence< double > seqDoubleRet(xBT2->setSequenceDouble(arDouble));
870 1 : bRet &= check(seqDoubleRet == arDouble, "sequence test");
871 1 : Sequence< TestEnum > arEnum;
872 1 : Sequence< TestEnum > seqEnumRet(xBT2->setSequenceEnum(arEnum));
873 1 : bRet &= check(seqEnumRet == arEnum, "sequence test");
874 1 : Sequence< sal_uInt16 > arUShort;
875 : Sequence< sal_uInt16 > seqUShortRet(
876 1 : xBT2->setSequenceUShort(arUShort));
877 1 : bRet &= check(seqUShortRet == arUShort, "sequence test");
878 1 : Sequence< sal_uInt32 > arULong;
879 1 : Sequence< sal_uInt32 > seqULongRet(xBT2->setSequenceULong(arULong));
880 1 : bRet &= check(seqULongRet == arULong, "sequence test");
881 1 : Sequence< sal_uInt64 > arUHyper;
882 : Sequence< sal_uInt64 > seqUHyperRet(
883 1 : xBT2->setSequenceUHyper(arUHyper));
884 1 : bRet &= check(seqUHyperRet == arUHyper, "sequence test");
885 1 : Sequence< Reference< XInterface > > arObject;
886 : Sequence< Reference< XInterface > > seqObjectRet(
887 1 : xBT2->setSequenceXInterface(arObject));
888 1 : bRet &= check(seqObjectRet == arObject, "sequence test");
889 1 : Sequence< OUString > arString;
890 : Sequence< OUString > seqStringRet(
891 1 : xBT2->setSequenceString(arString));
892 1 : bRet &= check(seqStringRet == arString, "sequence test");
893 1 : Sequence< TestElement > arStruct;
894 : Sequence< TestElement > seqStructRet(
895 1 : xBT2->setSequenceStruct(arStruct));
896 1 : bRet &= check(seqStructRet == arStruct, "sequence test");
897 : }
898 : // Issue #i60341# shows that the most interesting case is were Java
899 : // calls the constructors; however, since this client is currently not
900 : // available in Java, while the server is, the logic is reversed here:
901 : try {
902 1 : xBT2->testConstructorsService(xContext);
903 0 : } catch (const BadConstructorArguments &) {
904 0 : bRet = false;
905 : }
906 1 : if (!noCurrentContext) {
907 3 : if (!(new testtools::bridgetest::CurrentContextChecker)->perform(
908 3 : xBT2->getCurrentContextChecker(), 0, 1))
909 : {
910 0 : bRet = false;
911 : }
912 3 : if (!(new testtools::bridgetest::CurrentContextChecker)->perform(
913 3 : xBT2->getCurrentContextChecker(), 0, 2))
914 : {
915 0 : bRet = false;
916 : }
917 3 : if (!(new testtools::bridgetest::CurrentContextChecker)->perform(
918 3 : xBT2->getCurrentContextChecker(), 1, 2))
919 : {
920 0 : bRet = false;
921 : }
922 3 : if (!(new testtools::bridgetest::CurrentContextChecker)->perform(
923 3 : xBT2->getCurrentContextChecker(), 1, 3))
924 : {
925 0 : bRet = false;
926 : }
927 13 : }
928 : }
929 1 : return bRet;
930 : }
931 :
932 1 : static sal_Bool raiseOnewayException( const Reference < XBridgeTest > & xLBT )
933 : {
934 1 : sal_Bool bReturn = sal_True;
935 1 : OUString sCompare = OUSTR(STRING_TEST_CONSTANT);
936 1 : Reference<XInterface> const x(xLBT->getInterface());
937 : try
938 : {
939 : // Note : the exception may fly or not (e.g. remote scenario).
940 : // When it flies, it must contain the correct elements.
941 1 : xLBT->raiseRuntimeExceptionOneway( sCompare, x );
942 : }
943 1 : catch( const RuntimeException & e )
944 : {
945 : bReturn = (
946 : #if OSL_DEBUG_LEVEL == 0
947 : // java stack traces trash Message
948 1 : e.Message == sCompare &&
949 : #endif
950 3 : xLBT->getInterface() == e.Context &&
951 4 : x == e.Context );
952 : }
953 1 : return bReturn;
954 : }
955 :
956 : //==================================================================================================
957 1 : static sal_Bool raiseException( const Reference< XBridgeTest > & xLBT )
958 : {
959 1 : sal_Int32 nCount = 0;
960 : try
961 : {
962 : try
963 : {
964 : try
965 : {
966 1 : TestData aRet, aRet2;
967 1 : xLBT->raiseException(
968 : 5, OUSTR(STRING_TEST_CONSTANT),
969 2 : xLBT->getInterface() );
970 : }
971 1 : catch (const IllegalArgumentException &rExc)
972 : {
973 5 : if (rExc.ArgumentPosition == 5 &&
974 : #if OSL_DEBUG_LEVEL == 0
975 : // java stack traces trash Message
976 1 : rExc.Message.compareToAscii( STRING_TEST_CONSTANT ) == 0 &&
977 : #endif
978 3 : rExc.Context == xLBT->getInterface())
979 : {
980 : #ifdef COMPCHECK
981 : //When we check if a new compiler still works then we must not call
982 : //getRuntimeException because it uses cppu::getCaughtException which
983 : //does only work if all libs are build with the same runtime.
984 : return true;
985 : #else
986 1 : ++nCount;
987 : #endif
988 : }
989 : else
990 : {
991 0 : check( sal_False, "### unexpected exception content!" );
992 : }
993 :
994 : /** it is certain, that the RuntimeException testing will fail, if no */
995 1 : xLBT->getRuntimeException();
996 : }
997 : }
998 1 : catch (const RuntimeException & rExc)
999 : {
1000 2 : if (rExc.Context == xLBT->getInterface()
1001 : #if OSL_DEBUG_LEVEL == 0
1002 : // java stack traces trash Message
1003 1 : && rExc.Message.compareToAscii( STRING_TEST_CONSTANT ) == 0
1004 : #endif
1005 : )
1006 : {
1007 1 : ++nCount;
1008 : }
1009 : else
1010 : {
1011 0 : check( sal_False, "### unexpected exception content!" );
1012 : }
1013 :
1014 : /** it is certain, that the RuntimeException testing will fail, if no */
1015 1 : xLBT->setRuntimeException( 0xcafebabe );
1016 : }
1017 : }
1018 1 : catch (const Exception & rExc)
1019 : {
1020 2 : if (rExc.Context == xLBT->getInterface()
1021 : #if OSL_DEBUG_LEVEL == 0
1022 : // java stack traces trash Message
1023 1 : && rExc.Message.compareToAscii( STRING_TEST_CONSTANT ) == 0
1024 : #endif
1025 : )
1026 : {
1027 1 : ++nCount;
1028 : }
1029 : else
1030 : {
1031 0 : check( sal_False, "### unexpected exception content!" );
1032 : }
1033 1 : return (nCount == 3);
1034 : }
1035 0 : return sal_False;
1036 : }
1037 :
1038 : /* Returns an acquired sequence
1039 : */
1040 15 : uno_Sequence* cloneSequence(const uno_Sequence* val, const Type& type)
1041 : {
1042 15 : TypeDescription td(type);
1043 15 : td.makeComplete();
1044 15 : typelib_TypeDescription* pTdRaw = td.get();
1045 : typelib_IndirectTypeDescription* pIndirectTd =
1046 15 : (typelib_IndirectTypeDescription*) pTdRaw;
1047 :
1048 15 : typelib_TypeDescription* pTdElem = pIndirectTd->pType->pType;
1049 15 : sal_Int8* buf = new sal_Int8[pTdElem->nSize * val->nElements];
1050 15 : sal_Int8* pBufCur = buf;
1051 :
1052 15 : uno_Sequence* retSeq = NULL;
1053 15 : switch (pTdElem->eTypeClass)
1054 : {
1055 : case TypeClass_SEQUENCE:
1056 : {
1057 0 : Type _tElem(pTdElem->pWeakRef);
1058 0 : for (int i = 0; i < val->nElements; i++)
1059 : {
1060 0 : sal_Int8 *pValBuf = (sal_Int8 *)(&val->elements + i * pTdElem->nSize);
1061 :
1062 : uno_Sequence* seq = cloneSequence(
1063 : *(uno_Sequence**) (pValBuf),
1064 0 : _tElem);
1065 0 : *((uno_Sequence**) pBufCur) = seq;
1066 0 : pBufCur += pTdElem->nSize;
1067 : }
1068 0 : break;
1069 : }
1070 : default:
1071 : uno_type_sequence_construct(
1072 : &retSeq, type.getTypeLibType(), (void*) val->elements,
1073 15 : val->nElements, reinterpret_cast< uno_AcquireFunc >(cpp_acquire));
1074 15 : break;
1075 : }
1076 15 : delete[] buf;
1077 15 : return retSeq;
1078 : }
1079 :
1080 : template< class T>
1081 15 : Sequence<T> cloneSequence(const Sequence<T>& val)
1082 : {
1083 15 : Sequence<T> seq( cloneSequence(val.get(), getCppuType(&val)), SAL_NO_ACQUIRE);
1084 15 : return seq;
1085 : }
1086 :
1087 : template< class T >
1088 1 : inline bool makeSurrogate(
1089 : Reference< T > & rOut, Reference< T > const & rOriginal )
1090 : {
1091 1 : rOut.clear();
1092 1 : if (! rOriginal.is())
1093 0 : return false;
1094 :
1095 1 : Environment aCppEnv_official;
1096 1 : Environment aUnoEnv_ano;
1097 1 : Environment aCppEnv_ano;
1098 :
1099 : OUString aCppEnvTypeName(
1100 1 : RTL_CONSTASCII_USTRINGPARAM(CPPU_CURRENT_LANGUAGE_BINDING_NAME) );
1101 : OUString aUnoEnvTypeName(
1102 1 : RTL_CONSTASCII_USTRINGPARAM(UNO_LB_UNO) );
1103 : // official:
1104 : uno_getEnvironment(
1105 : reinterpret_cast< uno_Environment ** >( &aCppEnv_official ),
1106 1 : aCppEnvTypeName.pData, 0 );
1107 : // anonymous:
1108 : uno_createEnvironment(
1109 : reinterpret_cast< uno_Environment ** >( &aCppEnv_ano ),
1110 1 : aCppEnvTypeName.pData, 0 );
1111 : uno_createEnvironment(
1112 : reinterpret_cast< uno_Environment ** >( &aUnoEnv_ano ),
1113 1 : aUnoEnvTypeName.pData, 0 );
1114 :
1115 1 : UnoInterfaceReference unoI;
1116 1 : Mapping cpp2uno( aCppEnv_official.get(), aUnoEnv_ano.get() );
1117 1 : Mapping uno2cpp( aUnoEnv_ano.get(), aCppEnv_ano.get() );
1118 1 : if (!cpp2uno.is() || !uno2cpp.is())
1119 : {
1120 : throw RuntimeException(
1121 : OUSTR("cannot get C++-UNO mappings!"),
1122 0 : Reference< XInterface >() );
1123 : }
1124 1 : cpp2uno.mapInterface(
1125 : reinterpret_cast< void ** >( &unoI.m_pUnoI ),
1126 : rOriginal.get(), ::getCppuType( &rOriginal ) );
1127 1 : if (! unoI.is())
1128 : {
1129 : throw RuntimeException(
1130 : OUSTR("mapping C++ to binary UNO failed!"),
1131 0 : Reference< XInterface >() );
1132 : }
1133 1 : uno2cpp.mapInterface(
1134 : reinterpret_cast< void ** >( &rOut ),
1135 : unoI.get(), ::getCppuType( &rOriginal ) );
1136 1 : if (! rOut.is())
1137 : {
1138 : throw RuntimeException(
1139 : OUSTR("mapping binary UNO to C++ failed!"),
1140 0 : Reference< XInterface >() );
1141 : }
1142 :
1143 1 : return rOut.is();
1144 : }
1145 :
1146 : //==================================================================================================
1147 1 : sal_Int32 TestBridgeImpl::run( const Sequence< OUString > & rArgs )
1148 : throw (RuntimeException)
1149 : {
1150 1 : bool bRet = false;
1151 : try
1152 : {
1153 1 : if (! rArgs.getLength())
1154 : {
1155 : throw RuntimeException( OUString( RTL_CONSTASCII_USTRINGPARAM(
1156 : "no test object specified!\n"
1157 : "usage : ServiceName of test object | -u unourl of test object\n" ) ),
1158 0 : Reference< XInterface >() );
1159 : }
1160 :
1161 1 : Reference< XInterface > xOriginal;
1162 : bool remote;
1163 : sal_Int32 i;
1164 1 : if( rArgs.getLength() > 1 && 0 == rArgs[0].compareToAscii( "-u" ) )
1165 : {
1166 0 : remote = true;
1167 0 : i = 2;
1168 : }
1169 : else
1170 : {
1171 1 : remote = false;
1172 1 : i = 1;
1173 : }
1174 1 : bool noCurrentContext = false;
1175 1 : if ( i < rArgs.getLength() && rArgs[i] == "noCurrentContext" )
1176 : {
1177 0 : noCurrentContext = true;
1178 0 : ++i;
1179 : }
1180 1 : bool stress = false;
1181 1 : if ( i < rArgs.getLength() && rArgs[i] == "stress" )
1182 : {
1183 0 : stress = true;
1184 0 : ++i;
1185 : }
1186 :
1187 0 : for (;;) {
1188 1 : Reference< XInterface > o;
1189 1 : if (remote) {
1190 0 : o = UnoUrlResolver::create(m_xContext)->resolve(rArgs[1]);
1191 : } else {
1192 2 : o = m_xContext->getServiceManager()->createInstanceWithContext(
1193 1 : rArgs[0], m_xContext);
1194 : }
1195 1 : if (!stress) {
1196 1 : xOriginal = o;
1197 : break;
1198 : }
1199 1 : }
1200 :
1201 1 : if (! xOriginal.is())
1202 : {
1203 : throw RuntimeException(
1204 : OUString( RTL_CONSTASCII_USTRINGPARAM(
1205 : "cannot get test object!") ),
1206 0 : Reference< XInterface >() );
1207 : }
1208 1 : Reference< XBridgeTest > xTest( xOriginal, UNO_QUERY );
1209 1 : if (! xTest.is())
1210 : {
1211 : throw RuntimeException(
1212 : OUString( RTL_CONSTASCII_USTRINGPARAM("test object does not implement XBridgeTest!") ),
1213 0 : Reference< XInterface >() );
1214 : }
1215 :
1216 1 : Reference<XBridgeTest > xLBT;
1217 1 : bRet = check( makeSurrogate( xLBT, xTest ), "makeSurrogate" );
1218 : bRet = check(
1219 1 : performTest( m_xContext, xLBT, noCurrentContext ), "standard test" )
1220 1 : && bRet;
1221 1 : bRet = check( raiseException( xLBT ) , "exception test" )&& bRet;
1222 1 : bRet = check( raiseOnewayException( xLBT ),
1223 1 : "oneway exception test" ) && bRet;
1224 1 : if (! bRet)
1225 : {
1226 : throw RuntimeException(
1227 : OUString( RTL_CONSTASCII_USTRINGPARAM("error: test failed!") ),
1228 0 : Reference< XInterface >() );
1229 1 : }
1230 : }
1231 0 : catch (const Exception & exc)
1232 : {
1233 0 : OString cstr( OUStringToOString( exc.Message, RTL_TEXTENCODING_ASCII_US ) );
1234 0 : fprintf( stderr, "exception occurred: %s\n", cstr.getStr() );
1235 0 : throw;
1236 : }
1237 :
1238 1 : return bRet ? 0 : 1;
1239 : }
1240 :
1241 : // XServiceInfo
1242 : //__________________________________________________________________________________________________
1243 0 : OUString TestBridgeImpl::getImplementationName()
1244 : throw (RuntimeException)
1245 : {
1246 0 : return OUString( RTL_CONSTASCII_USTRINGPARAM(IMPLNAME) );
1247 : }
1248 : //__________________________________________________________________________________________________
1249 0 : sal_Bool TestBridgeImpl::supportsService( const OUString & rServiceName )
1250 : throw (RuntimeException)
1251 : {
1252 0 : const Sequence< OUString > & rSNL = getSupportedServiceNames();
1253 0 : const OUString * pArray = rSNL.getConstArray();
1254 0 : for ( sal_Int32 nPos = rSNL.getLength(); nPos--; )
1255 : {
1256 0 : if (pArray[nPos] == rServiceName)
1257 0 : return sal_True;
1258 : }
1259 0 : return sal_False;
1260 : }
1261 : //__________________________________________________________________________________________________
1262 0 : Sequence< OUString > TestBridgeImpl::getSupportedServiceNames()
1263 : throw (RuntimeException)
1264 : {
1265 0 : return bridge_test::getSupportedServiceNames();
1266 : }
1267 :
1268 : // ...
1269 :
1270 : //==================================================================================================
1271 1 : static Reference< XInterface > SAL_CALL TestBridgeImpl_create(
1272 : const Reference< XComponentContext > & xContext )
1273 : {
1274 : return Reference< XInterface >(
1275 1 : static_cast< OWeakObject * >( new TestBridgeImpl( xContext ) ) );
1276 : }
1277 :
1278 : }
1279 :
1280 : extern "C"
1281 : {
1282 : //==================================================================================================
1283 1 : SAL_DLLPUBLIC_EXPORT void * SAL_CALL component_getFactory(
1284 : const sal_Char * pImplName, void * pServiceManager,
1285 : SAL_UNUSED_PARAMETER void * )
1286 : {
1287 1 : void * pRet = 0;
1288 :
1289 1 : if (pServiceManager && rtl_str_compare( pImplName, IMPLNAME ) == 0)
1290 : {
1291 : Reference< XInterface > xFactory(
1292 : createSingleComponentFactory(
1293 : bridge_test::TestBridgeImpl_create,
1294 : OUString( RTL_CONSTASCII_USTRINGPARAM(IMPLNAME) ),
1295 1 : bridge_test::getSupportedServiceNames() ) );
1296 :
1297 1 : if (xFactory.is())
1298 : {
1299 1 : xFactory->acquire();
1300 1 : pRet = xFactory.get();
1301 1 : }
1302 : }
1303 :
1304 1 : return pRet;
1305 : }
1306 : }
1307 :
1308 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|