calc: on editing invalidation of view with different zoom is wrong
[LibreOffice.git] / testtools / source / bridgetest / cli / cli_cpp_bridgetest.cxx
blob04d9b3066f62fef602dfe4fea85dd2066e7629d5
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
21 #using <mscorlib.dll>
22 #using <System.dll>
23 #using <cli_basetypes.dll>
24 #using <cli_uretypes.dll>
25 #using <cli_ure.dll>
26 #using <cli_types_bridgetest.dll>
27 #include <cmath>
29 using namespace System;
30 using namespace System::Diagnostics;
31 using namespace System::Reflection;
32 using namespace System::Threading;
33 using namespace uno;
34 using namespace uno::util;
35 using namespace unoidl::com::sun::star::uno;
36 using namespace unoidl::com::sun::star::lang;
37 using namespace unoidl::test::testtools::bridgetest;
38 namespace foo
40 public __gc __interface MyInterface
45 namespace cpp_bridgetest
47 __gc class ORecursiveCall: public WeakBase, public XRecursiveCall
49 public:
50 void callRecursivly(XRecursiveCall * xCall, int nToCall)
52 Monitor::Enter(this);
53 try
56 if (nToCall > 0)
58 nToCall --;
59 xCall->callRecursivly(this, nToCall);
63 __finally
65 Monitor::Exit(this);
71 public __gc class Constants
73 public:
74 static String* STRING_TEST_CONSTANT = new String(S"\" paco\' chorizo\\\' \"\'");
77 public __gc class BridgeTest : public WeakBase, public XMain
79 static bool compareData(Object* val1, Object* val2)
81 if (val1 == 0 && val2 == 0 || val1 == val2)
82 return true;
83 if ((val1 == 0 && val2 != 0) ||
84 (val1 != 0 && val2 == 0) || val1->GetType() != val2->GetType())
85 return false;
87 bool ret = false;
88 Type* t1 = val1->GetType();
89 //Sequence
90 if (t1->IsArray)
92 ret = compareSequence(static_cast<Array*>(val1),
93 static_cast<Array*>(val2));
95 //String
96 else if (t1 == __typeof(String))
98 ret = val1->Equals(val2);
100 // Interface implementation
101 else if (t1->GetInterfaces()->Length > 0 && ! t1->IsValueType)
103 ret = val1 == val2;
105 // Struct
106 else if ( ! t1->IsValueType)
108 ret = compareStruct(val1, val2);
110 else if (t1 == __typeof(Any))
112 Any a1 = (Any) val1;
113 Any a2 = (Any) val2;
114 ret = a1.Type == a2.Type && compareData(a1.Value, a2.Value);
116 else
118 //Any, enum, int, bool char, float, double etc.
119 ret = val1->Equals(val2);
121 return ret;
124 // Arrays have only one dimension
125 static bool compareSequence(Array* ar1, Array* ar2)
127 Debug::Assert(ar1 != 0 && ar2 != 0);
128 Type* t1 = ar1->GetType();
129 Type* t2 = ar2->GetType();
131 if (!(ar1->Rank == 1 && ar2->Rank == 1
132 && ar1->Length == ar2->Length && t1->GetElementType() == t2->GetElementType()))
133 return false;
135 //arrays have same rank and size and element type.
136 int len = ar1->Length;
137 bool ret = true;
138 for (int i = 0; i < len; i++)
140 if (compareData(ar1->GetValue(i), ar2->GetValue(i)) == false)
142 ret = false;
143 break;
146 return ret;
149 static bool compareStruct(Object* val1, Object* val2)
151 Debug::Assert(val1 != 0 && val2 != 0);
152 Type* t1 = val1->GetType();
153 Type* t2 = val2->GetType();
154 if (t1 != t2)
155 return false;
156 FieldInfo* fields[] = t1->GetFields();
157 int cFields = fields->Length;
158 bool ret = true;
159 for (int i = 0; i < cFields; i++)
161 Object* fieldVal1 = fields[i]->GetValue(val1);
162 Object* fieldVal2 = fields[i]->GetValue(val2);
163 if ( ! compareData(fieldVal1, fieldVal2))
165 ret = false;
166 break;
169 return ret;
172 static bool check( bool b , String* message )
174 if ( ! b)
175 Console::WriteLine("{0} failed\n" , message);
176 return b;
179 static bool equals(TestElement* rData1, TestElement* rData2)
181 check( rData1->Bool == rData2->Bool, "### bool does not match!" );
182 check( rData1->Char == rData2->Char, "### char does not match!" );
183 check( rData1->Byte == rData2->Byte, "### byte does not match!" );
184 check( rData1->Short == rData2->Short, "### short does not match!" );
185 check( rData1->UShort == rData2->UShort, "### unsigned short does not match!" );
186 check( rData1->Long == rData2->Long, "### long does not match!" );
187 check( rData1->ULong == rData2->ULong, "### unsigned long does not match!" );
188 check( rData1->Hyper == rData2->Hyper, "### hyper does not match!" );
189 check( rData1->UHyper == rData2->UHyper, "### unsigned hyper does not match!" );
190 check( rData1->Float == rData2->Float, "### float does not match!" );
191 check( rData1->Double == rData2->Double, "### double does not match!" );
192 check( rData1->Enum == rData2->Enum, "### enum does not match!" );
193 check( rData1->String == rData2->String, "### string does not match!" );
194 check( rData1->Byte2 == rData2->Byte2, "### byte2 does not match!" );
195 check( rData1->Short2 == rData2->Short2, "### short2 does not match!" );
196 check( rData1->Interface == rData2->Interface, "### interface does not match!" );
197 check( compareData(__box(rData1->Any), __box(rData2->Any)), "### any does not match!" );
199 return (rData1->Bool == rData2->Bool &&
200 rData1->Char == rData2->Char &&
201 rData1->Byte == rData2->Byte &&
202 rData1->Short == rData2->Short &&
203 rData1->UShort == rData2->UShort &&
204 rData1->Long == rData2->Long &&
205 rData1->ULong == rData2->ULong &&
206 rData1->Hyper == rData2->Hyper &&
207 rData1->UHyper == rData2->UHyper &&
208 rData1->Float == rData2->Float &&
209 rData1->Double == rData2->Double &&
210 rData1->Enum == rData2->Enum &&
211 rData1->String == rData2->String &&
212 rData1->Byte2 == rData2->Byte2 &&
213 rData1->Short2 == rData2->Short2 &&
214 rData1->Interface == rData2->Interface &&
215 compareData(__box(rData1->Any), __box(rData2->Any)));
218 static void assign( TestElement* rData,
219 bool bBool, Char cChar, Byte nByte,
220 Int16 nShort, UInt16 nUShort,
221 Int32 nLong, UInt32 nULong,
222 Int64 nHyper, UInt64 nUHyper,
223 float fFloat, double fDouble,
224 TestEnum eEnum, String* rStr,
225 Byte nByte2, Int16 nShort2,
226 Object* xTest,
227 uno::Any rAny )
229 rData->Bool = bBool;
230 rData->Char = cChar;
231 rData->Byte = nByte;
232 rData->Short = nShort;
233 rData->UShort = nUShort;
234 rData->Long = nLong;
235 rData->ULong = nULong;
236 rData->Hyper = nHyper;
237 rData->UHyper = nUHyper;
238 rData->Float = fFloat;
239 rData->Double = fDouble;
240 rData->Enum = eEnum;
241 rData->String = rStr;
242 rData->Byte2 = nByte2;
243 rData->Short2 = nShort2;
244 rData->Interface = xTest;
245 rData->Any = rAny;
248 static void assign( TestDataElements* rData,
249 bool bBool, Char cChar, Byte nByte,
250 Int16 nShort, UInt16 nUShort,
251 Int32 nLong, UInt32 nULong,
252 Int64 nHyper, UInt64 nUHyper,
253 float fFloat, double fDouble,
254 TestEnum eEnum, String* rStr,
255 Byte nByte2, Int16 nShort2,
256 Object* xTest,
257 Any rAny,
258 TestElement* rSequence[])
260 assign( static_cast<TestElement*>(rData),
261 bBool, cChar, nByte, nShort, nUShort, nLong, nULong, nHyper, nUHyper, fFloat, fDouble,
262 eEnum, rStr, nByte2, nShort2, xTest, rAny );
263 rData->Sequence = rSequence;
266 static bool testAny(Type* typ, Object* value, XBridgeTest* xLBT )
268 Any any;
269 if (typ == 0)
270 any = Any(value->GetType(), value);
271 else
272 any = Any(typ, value);
274 Any any2 = xLBT->transportAny(any);
275 bool ret = compareData(__box(any), __box(any2));
276 if (!ret)
278 Console::WriteLine("any is different after roundtrip: in {0}, out {1}\n",
279 any.Type->FullName, any2.Type->FullName);
281 return ret;
285 static bool performAnyTest(XBridgeTest* xLBT, TestDataElements* data)
287 bool bReturn = true;
288 bReturn = testAny( 0, __box(data->Byte), xLBT ) && bReturn;
289 bReturn = testAny( 0, __box(data->Short), xLBT ) && bReturn;
290 bReturn = testAny( 0, __box(data->UShort), xLBT ) && bReturn;
291 bReturn = testAny( 0, __box(data->Long), xLBT ) && bReturn;
292 bReturn = testAny( 0, __box(data->ULong), xLBT ) && bReturn;
293 bReturn = testAny( 0, __box(data->Hyper), xLBT ) && bReturn;
294 bReturn = testAny( 0, __box(data->UHyper), xLBT ) && bReturn;
295 bReturn = testAny( 0, __box(data->Float), xLBT ) && bReturn;
296 bReturn = testAny( 0, __box(data->Double),xLBT ) && bReturn;
297 bReturn = testAny( 0, __box(data->Enum), xLBT ) && bReturn;
298 bReturn = testAny( 0, data->String,xLBT ) && bReturn;
299 bReturn = testAny( 0, data->Byte2,xLBT ) && bReturn;
300 bReturn = testAny( 0, data->Short2,xLBT ) && bReturn;
301 bReturn = testAny(__typeof(XWeak), data->Interface,xLBT ) && bReturn;
302 bReturn = testAny(0, data, xLBT ) && bReturn;
305 Any a1(true);
306 Any a2 = xLBT->transportAny( a1 );
307 bReturn = compareData(__box(a2), __box(a1)) && bReturn;
311 Any a1('A');
312 Any a2 = xLBT->transportAny(a1);
313 bReturn = compareData( __box(a2), __box(a1)) && bReturn;
315 return bReturn;
318 static bool performSequenceOfCallTest(XBridgeTest* xLBT)
320 int i,nRounds;
321 int nGlobalIndex = 0;
322 const int nWaitTimeSpanMUSec = 10000;
323 for( nRounds = 0 ; nRounds < 10 ; nRounds ++ )
325 for( i = 0 ; i < nRounds ; i ++ )
327 // fire oneways
328 xLBT->callOneway(nGlobalIndex, nWaitTimeSpanMUSec);
329 nGlobalIndex++;
332 // call synchron
333 xLBT->call(nGlobalIndex, nWaitTimeSpanMUSec);
334 nGlobalIndex++;
336 return xLBT->sequenceOfCallTestPassed();
340 static bool performRecursiveCallTest(XBridgeTest* xLBT)
342 xLBT->startRecursiveCall(new ORecursiveCall(), 50);
343 // on failure, the test would lock up or crash
344 return true;
347 static bool performQueryForUnknownType(XBridgeTest* xLBT)
349 bool bRet = false;
350 // test queryInterface for an unknown type
353 __try_cast<foo::MyInterface*>(xLBT);
355 catch( System::InvalidCastException*)
357 bRet = true;
360 return bRet;
364 static bool performTest(XBridgeTest* xLBT)
366 check( xLBT != 0, "### no test interface!" );
367 bool bRet = true;
368 if (xLBT != 0)
370 // this data is never ever granted access to by calls other than equals(), assign()!
371 TestDataElements* aData = new TestDataElements(); // test against this data
373 Object* xI= new WeakBase();
375 Any aAny( __typeof(Object), xI);
376 assign( static_cast<TestElement*>(aData),
377 true, '@', 17, 0x1234, 0xfedc, 0x12345678, 0xfedcba98,
378 0x123456789abcdef0, 0xfedcba9876543210,
379 17.0815f, M_PI, TestEnum::LOLA,
380 Constants::STRING_TEST_CONSTANT, xI,
381 aAny);
383 bRet = check( aData->Any.Value == xI, "### unexpected any!" ) && bRet;
384 bRet = check( !(aData->Any.Value != xI), "### unexpected any!" ) && bRet;
386 aData->Sequence = new TestElement*[2];
387 aData->Sequence[0] = new TestElement(
388 aData->Bool, aData->Char, aData->Byte, aData->Short,
389 aData->UShort, aData->Long, aData->ULong,
390 aData->Hyper, aData->UHyper, aData->Float,
391 aData->Double, aData->Enum, aData->String,
392 aData->Byte2, aData->Short2,
393 aData->Interface, aData->Any); //(TestElement) aData;
394 aData->Sequence[1] = new TestElement(); //is empty
396 // aData complete
398 // this is a manually copy of aData for first setting...
399 TestDataElements* aSetData = new TestDataElements;
400 Any aAnySet(__typeof(Object), xI);
401 assign( static_cast<TestElement*>(aSetData),
402 aData->Bool,
403 aData->Char,
404 aData->Byte,
405 aData->Short,
406 aData->UShort,
407 aData->Long, aData->ULong, aData->Hyper, aData->UHyper, aData->Float, aData->Double,
408 aData->Enum,
409 aData->String,
410 aData->Byte2,
411 aData->Short2,
413 aAnySet);
415 aSetData->Sequence = new TestElement*[2];
416 aSetData->Sequence[0] = new TestElement(
417 aSetData->Bool, aSetData->Char, aSetData->Byte, aSetData->Short,
418 aSetData->UShort, aSetData->Long, aSetData->ULong,
419 aSetData->Hyper, aSetData->UHyper, aSetData->Float,
420 aSetData->Double, aSetData->Enum, aSetData->String,
421 aSetData->Byte2, aSetData->Short2,
422 aSetData->Interface, aSetData->Any); //TestElement) aSetData;
423 aSetData->Sequence[1] = new TestElement(); // empty struct
425 xLBT->setValues(
426 aSetData->Bool,
427 aSetData->Char,
428 aSetData->Byte,
429 aSetData->Short,
430 aSetData->UShort,
431 aSetData->Long,
432 aSetData->ULong,
433 aSetData->Hyper,
434 aSetData->UHyper,
435 aSetData->Float,
436 aSetData->Double,
437 aSetData->Enum,
438 aSetData->String,
439 aSetData->Byte2,
440 aSetData->Short2,
441 aSetData->Interface,
442 aSetData->Any,
443 aSetData->Sequence,
444 aSetData );
447 TestDataElements* aRet = new TestDataElements();
448 TestDataElements* aRet2 = new TestDataElements();
449 xLBT->getValues(
450 & aRet->Bool,
451 & aRet->Char,
452 & aRet->Byte,
453 & aRet->Short,
454 & aRet->UShort,
455 & aRet->Long,
456 & aRet->ULong,
457 & aRet->Hyper,
458 & aRet->UHyper,
459 & aRet->Float,
460 & aRet->Double,
461 & aRet->Enum,
462 & aRet->String,
463 & aRet->Byte2,
464 & aRet->Short2,
465 & aRet->Interface,
466 & aRet->Any,
467 & aRet->Sequence,
468 & aRet2 );
470 bRet = check( compareData( aData, aRet ) && compareData( aData, aRet2 ) , "getValues test") && bRet;
472 // set last retrieved values
473 TestDataElements* aSV2ret = xLBT->setValues2(
474 & aRet->Bool,
475 & aRet->Char,
476 & aRet->Byte,
477 & aRet->Short,
478 & aRet->UShort,
479 & aRet->Long,
480 & aRet->ULong,
481 & aRet->Hyper,
482 & aRet->UHyper,
483 & aRet->Float,
484 & aRet->Double,
485 & aRet->Enum,
486 & aRet->String,
487 & aRet->Byte2,
488 & aRet->Short2,
489 & aRet->Interface,
490 & aRet->Any,
491 & aRet->Sequence,
492 & aRet2 );
494 // check inout sequence order
495 // => inout sequence parameter was switched by test objects
496 TestElement* temp = aRet->Sequence[ 0 ];
497 aRet->Sequence[ 0 ] = aRet->Sequence[ 1 ];
498 aRet->Sequence[ 1 ] = temp;
500 bRet = check(
501 compareData( aData, aSV2ret ) && compareData( aData, aRet2 ),
502 "getValues2 test") && bRet;
505 TestDataElements* aRet = new TestDataElements();
506 TestDataElements* aRet2 = new TestDataElements();
507 TestDataElements* aGVret = xLBT->getValues(
508 & aRet->Bool,
509 & aRet->Char,
510 & aRet->Byte,
511 & aRet->Short,
512 & aRet->UShort,
513 & aRet->Long,
514 & aRet->ULong,
515 & aRet->Hyper,
516 & aRet->UHyper,
517 & aRet->Float,
518 & aRet->Double,
519 & aRet->Enum,
520 & aRet->String,
521 & aRet->Byte2,
522 & aRet->Short2,
523 & aRet->Interface,
524 & aRet->Any,
525 & aRet->Sequence,
526 & aRet2 );
528 bRet = check( compareData( aData, aRet ) && compareData( aData, aRet2 ) && compareData( aData, aGVret ), "getValues test" ) && bRet;
530 // set last retrieved values
531 xLBT->Bool = aRet->Bool;
532 xLBT->Char = aRet->Char;
533 xLBT->Byte = aRet->Byte;
534 xLBT->Short = aRet->Short;
535 xLBT->UShort = aRet->UShort;
536 xLBT->Long = aRet->Long;
537 xLBT->ULong = aRet->ULong;
538 xLBT->Hyper = aRet->Hyper;
539 xLBT->UHyper = aRet->UHyper;
540 xLBT->Float = aRet->Float;
541 xLBT->Double = aRet->Double;
542 xLBT->Enum = aRet->Enum;
543 xLBT->String = aRet->String;
544 xLBT->Byte2 = aRet->Byte2;
545 xLBT->Short2 = aRet->Short2;
546 xLBT->Interface = aRet->Interface;
547 xLBT->Any = aRet->Any;
548 xLBT->Sequence = aRet->Sequence;
549 xLBT->Struct = aRet2;
552 TestDataElements* aRet = new TestDataElements();
553 TestDataElements* aRet2 = new TestDataElements();
554 aRet->Hyper = xLBT->Hyper;
555 aRet->UHyper = xLBT->UHyper;
556 aRet->Float = xLBT->Float;
557 aRet->Double = xLBT->Double;
558 aRet->Byte = xLBT->Byte;
559 aRet->Char = xLBT->Char;
560 aRet->Bool = xLBT->Bool;
561 aRet->Short = xLBT->Short;
562 aRet->UShort = xLBT->UShort;
563 aRet->Long = xLBT->Long;
564 aRet->ULong = xLBT->ULong;
565 aRet->Enum = xLBT->Enum;
566 aRet->String = xLBT->String;
567 aRet->Byte2 = xLBT->Byte2;
568 aRet->Short2 = xLBT->Short2;
569 aRet->Interface = xLBT->Interface;
570 aRet->Any = xLBT->Any;
571 aRet->Sequence = xLBT->Sequence;
572 aRet2 = xLBT->Struct;
574 bRet = check( compareData( aData, aRet ) && compareData( aData, aRet2 ) , "struct comparison test") && bRet;
576 bRet = check(performSequenceTest(xLBT), "sequence test") && bRet;
578 // any test
579 bRet = check( performAnyTest( xLBT , aData ) , "any test" ) && bRet;
581 // sequence of call test
582 bRet = check( performSequenceOfCallTest( xLBT ) , "sequence of call test" ) && bRet;
584 // recursive call test
585 bRet = check( performRecursiveCallTest( xLBT ) , "recursive test" ) && bRet;
587 bRet = (compareData( aData, aRet ) && compareData( aData, aRet2 )) && bRet ;
589 // check setting of null reference
590 xLBT->Interface = 0;
591 aRet->Interface = xLBT->Interface;
592 bRet = (aRet->Interface == 0) && bRet;
598 return bRet;
600 static bool performSequenceTest(XBridgeTest* xBT)
602 bool bRet = true;
603 XBridgeTest2* xBT2 = dynamic_cast<XBridgeTest2*>(xBT);
604 if ( xBT2 == 0)
605 return false;
607 // perform sequence tests (XBridgeTest2)
608 // create the sequence which are compared with the results
609 bool arBool __gc[] = new bool __gc [3];
610 arBool[0] = true; arBool[1] = false; arBool[2] = true;
611 Char arChar[] = new Char[3];
612 arChar[0] = 'A'; arChar[1] = 'B'; arChar[2] = 'C';
613 Byte arByte[] = new Byte[3];
614 arByte[0] = 1; arByte[1] = 2; arByte[2] = 0xff;
615 Int16 arShort[] = new Int16[3];
616 arShort[0] = Int16::MinValue; arShort[1] = 1; arShort[2] = Int16::MaxValue;
617 UInt16 arUShort[] = new UInt16[3];
618 arUShort[0] = UInt16::MinValue; arUShort[1] = 1; arUShort[2] = UInt16::MaxValue;
619 Int32 arLong[] = new Int32[3];
620 arLong[0] = Int32::MinValue; arLong[1] = 1; arLong[2] = Int32::MaxValue;
621 UInt32 arULong[] = new UInt32[3];
622 arULong[0] = UInt32::MinValue; arULong[1] = 1; arULong[2] = UInt32::MaxValue;
623 Int64 arHyper[] = new Int64[3];
624 arHyper[0] = Int64::MinValue; arHyper[1] = 1; arHyper[2] = Int64::MaxValue;
625 UInt64 arUHyper[] = new UInt64[3];
626 arUHyper[0] = UInt64::MinValue; arUHyper[1] = 1;
627 arUHyper[2] = UInt64::MaxValue;
628 Single arFloat[] = new Single[3];
629 arFloat[0] = 1.1f; arFloat[1] = 2.2f; arFloat[2] = 3.3f;
630 Double arDouble[] = new Double[3];
631 arDouble[0] = 1.11; arDouble[1] = 2.22; arDouble[2] = 3.33;
632 String* arString[] = new String*[3];
633 arString[0] = new String("String 1");
634 arString[1] = new String("String 2");
635 arString[2] = new String("String 3");
637 Any arAny[] = new Any[3];
638 arAny[0] = Any(true); arAny[1] = Any(11111); arAny[2] = Any(3.14);
639 Object* arObject[] = new Object*[3];
640 arObject[0] = new WeakBase(); arObject[1] = new WeakBase();
641 arObject[1] = new WeakBase();
643 Console::WriteLine(new String("cli_cpp_bridgetest: Workaround for C++ compiler bug:"
644 " using Array of Int32 instead of Array of enums w"));
645 Int32 arEnum[] = new Int32[3];
646 arEnum[0] = static_cast<Int32>(TestEnum::ONE);
647 arEnum[1] = static_cast<Int32>(TestEnum::TWO);
648 arEnum[2] = static_cast<Int32>(TestEnum::CHECK);
650 TestElement* arStruct[] = new TestElement*[3];
651 arStruct[0] = new TestElement(); arStruct[1] = new TestElement();
652 arStruct[2] = new TestElement();
653 assign( arStruct[0], true, '@', 17, 0x1234, 0xfedc, 0x12345678, 0xfedcba98,
654 0x123456789abcdef0, 0xfedcba9876543210, 17.0815f, M_PI,
655 TestEnum::LOLA, Constants::STRING_TEST_CONSTANT, 18, 0x5678, arObject[0],
656 Any( __typeof(Object), arObject[0]) );
657 assign( arStruct[1], true, 'A', 17, 0x1234, 0xfedc, 0x12345678, 0xfedcba98,
658 0x123456789abcdef0, 0xfedcba9876543210, 17.0815f, M_PI,
659 TestEnum::TWO, Constants::STRING_TEST_CONSTANT, 18, 0x5678, arObject[1],
660 Any( __typeof(Object), arObject[1]) );
661 assign( arStruct[2], true, 'B', 17, 0x1234, 0xfedc, 0x12345678, 0xfedcba98,
662 0x123456789abcdef0, 0xfedcba9876543210, 17.0815f, M_PI,
663 TestEnum::CHECK, Constants::STRING_TEST_CONSTANT, 18, 0x5678, arObject[2],
664 Any( __typeof(Object), arObject[2] ) );
666 Any seqAnyRet[] = xBT2->setSequenceAny(arAny);
667 bRet = check( compareData(seqAnyRet, arAny), "sequence test") && bRet;
668 Boolean seqBoolRet[] = xBT2->setSequenceBool(arBool);
669 bRet = check( compareData(seqBoolRet, arBool), "sequence test") && bRet;
670 Byte seqByteRet[] = xBT2->setSequenceByte(arByte);
671 bRet = check( compareData(seqByteRet, arByte), "sequence test") && bRet;
672 Char seqCharRet[] = xBT2->setSequenceChar(arChar);
673 bRet = check( compareData(seqCharRet, arChar), "sequence test") && bRet;
674 Int16 seqShortRet[] = xBT2->setSequenceShort(arShort);
675 bRet = check( compareData(seqShortRet, arShort), "sequence test") && bRet;
676 Int32 seqLongRet[] = xBT2->setSequenceLong(arLong);
677 bRet = check( compareData(seqLongRet, arLong), "sequence test") && bRet;
678 Int64 seqHyperRet[] = xBT2->setSequenceHyper(arHyper);
679 bRet = check( compareData(seqHyperRet,arHyper), "sequence test") && bRet;
680 Single seqFloatRet[] = xBT2->setSequenceFloat(arFloat);
681 bRet = check( compareData(seqFloatRet, arFloat), "sequence test") && bRet;
682 Double seqDoubleRet[] = xBT2->setSequenceDouble(arDouble);
683 bRet = check( compareData(seqDoubleRet, arDouble), "sequence test") && bRet;
684 xBT2->setSequenceEnum(arEnum);
685 //comparing seqEnumRet with arEnum will fail since they are of different
686 //types because of workaround. arEnum is Int32[].
687 Console::WriteLine(new String("cli_cpp_bridgetest: Test omitted because "
688 "of C++ compiler bug. XBridgeTest2::setSequenceEnum(sequence<TestEnum>)"));
689 UInt16 seqUShortRet[] = xBT2->setSequenceUShort(arUShort);
690 bRet = check( compareData(seqUShortRet, arUShort), "sequence test") && bRet;
691 UInt32 seqULongRet[] = xBT2->setSequenceULong(arULong);
692 bRet = check( compareData(seqULongRet, arULong), "sequence test") && bRet;
693 UInt64 seqUHyperRet[] = xBT2->setSequenceUHyper(arUHyper);
694 bRet = check( compareData(seqUHyperRet, arUHyper), "sequence test") && bRet;
695 Object* seqObjectRet[] = xBT2->setSequenceXInterface(arObject);
696 bRet = check( compareData(seqObjectRet, arObject), "sequence test") && bRet;
697 String* seqStringRet[] = xBT2->setSequenceString(arString);
698 bRet = check( compareData(seqStringRet, arString), "sequence test") && bRet;
699 TestElement* seqStructRet[] = xBT2->setSequenceStruct(arStruct);
700 bRet = check( compareData(seqStructRet, arStruct), "sequence test") && bRet;
703 Console::WriteLine(new String("cli_cpp_bridgetest: no test of "
704 "XBridgeTest2::setSequencesInOut and XBridgeTest2.setSequencesOut "
705 "because jagged arrays are not supported by C++ compiler"));
708 Any _arAny[] = new Any[0];
709 Any seqAnyRet[] = xBT2->setSequenceAny(_arAny);
710 bRet = check( compareData(seqAnyRet, _arAny), "sequence test") && bRet;
711 Boolean _arBool[] = new Boolean[0];
712 Boolean seqBoolRet[] = xBT2->setSequenceBool(_arBool);
713 bRet = check( compareData(seqBoolRet, _arBool), "sequence test") && bRet;
714 Byte _arByte[] = new Byte[0];
715 Byte seqByteRet[] = xBT2->setSequenceByte(_arByte);
716 bRet = check( compareData(seqByteRet, _arByte), "sequence test") && bRet;
717 Char _arChar[] = new Char[0];
718 Char seqCharRet[] = xBT2->setSequenceChar(_arChar);
719 bRet = check( compareData(seqCharRet, _arChar), "sequence test") && bRet;
720 Int16 _arShort[] = new Int16[0];
721 Int16 seqShortRet[] = xBT2->setSequenceShort(_arShort);
722 bRet = check( compareData(seqShortRet, _arShort), "sequence test") && bRet;
723 Int32 _arLong[] = new Int32[0];
724 Int32 seqLongRet[] = xBT2->setSequenceLong(_arLong);
725 bRet = check( compareData(seqLongRet, _arLong), "sequence test") && bRet;
726 Int64 _arHyper[] = new Int64[0];
727 Int64 seqHyperRet[] = xBT2->setSequenceHyper(_arHyper);
728 bRet = check( compareData(seqHyperRet, _arHyper), "sequence test") && bRet;
729 Single _arFloat[] = new Single[0];
730 Single seqFloatRet[] = xBT2->setSequenceFloat(_arFloat);
731 bRet = check( compareData(seqFloatRet, _arFloat), "sequence test") && bRet;
732 Double _arDouble[] = new Double[0];
733 Double seqDoubleRet[] = xBT2->setSequenceDouble(_arDouble);
734 bRet = check( compareData(seqDoubleRet, _arDouble), "sequence test") && bRet;
735 TestEnum _arEnum[] = new TestEnum[0];
736 xBT2->setSequenceEnum(_arEnum);
737 UInt16 _arUShort[] = new UInt16[0];
738 UInt16 seqUShortRet[] = xBT2->setSequenceUShort(_arUShort);
739 bRet = check( compareData(seqUShortRet, _arUShort), "sequence test") && bRet;
740 UInt32 _arULong[] = new UInt32[0];
741 UInt32 seqULongRet[] = xBT2->setSequenceULong(_arULong);
742 bRet = check( compareData(seqULongRet, _arULong), "sequence test") && bRet;
743 UInt64 _arUHyper[] = new UInt64[0];
744 UInt64 seqUHyperRet[] = xBT2->setSequenceUHyper(_arUHyper);
745 bRet = check( compareData(seqUHyperRet, _arUHyper), "sequence test") && bRet;
746 Object* _arObject[] = new Object*[0];
747 Object* seqObjectRet[] = xBT2->setSequenceXInterface(_arObject);
748 bRet = check( compareData(seqObjectRet, _arObject), "sequence test") && bRet;
749 String* _arString[] = new String*[0];
750 String* seqStringRet[] = xBT2->setSequenceString(_arString);
751 bRet = check( compareData(seqStringRet, _arString), "sequence test") && bRet;
752 TestElement* _arStruct[] = new TestElement*[0];
753 TestElement* seqStructRet[] = xBT2->setSequenceStruct(_arStruct);
754 bRet = check( compareData(seqStructRet, _arStruct), "sequence test") && bRet;
757 return bRet;
759 /** Test the System::Object method on the proxy object
761 static bool testObjectMethodsImplementation(XBridgeTest* xLBT)
763 bool ret = false;
764 Object* obj = new Object();
765 XBridgeTestBase* xBase = dynamic_cast<XBridgeTestBase*>(xLBT);
766 if (xBase == 0)
767 return false;
768 // Object.Equals
769 ret = xLBT->Equals(obj) == false;
770 ret = xLBT->Equals(xLBT) && ret;
771 ret = Object::Equals(obj, obj) && ret;
772 ret = Object::Equals(xLBT, xBase) && ret;
773 //Object.GetHashCode
774 // Don't know how to verify this. Currently it is not possible to get the object id from a proxy
775 int nHash = xLBT->GetHashCode();
776 ret = nHash == xBase->GetHashCode() && ret;
778 //Object.ToString
779 // Don't know how to verify this automatically.
780 String* s = xLBT->ToString();
781 ret = (s->Length > 0) && ret;
782 return ret;
786 static bool raiseOnewayException(XBridgeTest* xLBT)
788 bool bReturn = true;
789 String* sCompare = Constants::STRING_TEST_CONSTANT;
792 // Note : the exception may fly or not (e.g. remote scenario).
793 // When it flies, it must contain the correct elements.
794 xLBT->raiseRuntimeExceptionOneway(sCompare, xLBT->Interface );
796 catch (RuntimeException* e )
798 bReturn = ( xLBT->Interface == e->Context );
800 return bReturn;
804 static bool raiseException(XBridgeTest* xLBT )
806 int nCount = 0;
813 xLBT->raiseException(
814 5, Constants::STRING_TEST_CONSTANT, xLBT->Interface );
816 catch (unoidl::com::sun::star::lang::IllegalArgumentException* aExc)
818 if (aExc->ArgumentPosition == 5 &&
819 aExc->Context == xLBT->Interface)
821 ++nCount;
823 else
825 check( false, "### unexpected exception content!" );
828 /** it is certain, that the RuntimeException testing will fail,
829 if no */
830 xLBT->RuntimeException = 0;
833 catch (unoidl::com::sun::star::uno::RuntimeException* rExc)
835 if (rExc->Context == xLBT->Interface )
837 ++nCount;
839 else
841 check( false, "### unexpected exception content!" );
844 /** it is certain, that the RuntimeException testing will fail, if no */
845 xLBT->RuntimeException = (int) 0xcafebabe;
848 catch (unoidl::com::sun::star::uno::Exception* rExc)
850 if (rExc->Context == xLBT->Interface)
852 ++nCount;
854 else
857 check( false, "### unexpected exception content!" );
859 return (nCount == 3);
861 return false;
864 static private void perform_test( XBridgeTest* xLBT )
866 bool bRet= true;
867 bRet = check( performTest( xLBT ), "standard test" ) && bRet;
868 bRet = check( raiseException( xLBT ) , "exception test" )&& bRet;
869 bRet = check( raiseOnewayException( xLBT ), "oneway exception test" ) && bRet;
870 bRet = check( testObjectMethodsImplementation(xLBT), "object methods test") && bRet;
871 bRet = performQueryForUnknownType( xLBT ) && bRet;
872 if (! bRet)
874 throw new unoidl::com::sun::star::uno::RuntimeException(
875 new String("error: test failed!"), 0);
878 XComponentContext* m_xContext;
880 public:
881 explicit BridgeTest( XComponentContext* xContext )
883 m_xContext = xContext;
887 int run( String* args[] )
891 if (args->Length < 1)
893 throw new RuntimeException(
894 "missing argument for bridgetest!", this );
896 Object* test_obj =
897 m_xContext->getServiceManager()->createInstanceWithContext(
898 args[ 0 ], m_xContext );
899 if (test_obj == 0)
900 test_obj = m_xContext->getValueByName( args[ 0 ] ).Value;
902 Console::WriteLine(
903 "cli target bridgetest obj: {0}", test_obj->ToString() );
904 XBridgeTest* xTest = __try_cast<XBridgeTest*>(test_obj) ;
905 perform_test( xTest );
906 Console::WriteLine( "\n### cli_uno C++ bridgetest succeeded." );
907 return 0;
909 catch (unoidl::com::sun::star::uno::RuntimeException* )
911 throw;
913 catch (System::Exception* exc)
915 System::Text::StringBuilder* s = new System::Text::StringBuilder();
916 s->Append(S"cli_cpp_bridgetest: unexpected exception occurred in XMain::run. Original exception: ");
917 s->Append(exc->GetType()->Name);
918 s->Append(S"\n Message: ");
919 s->Append(exc->Message);
920 throw new unoidl::com::sun::star::uno::RuntimeException(
921 s->ToString(), 0);
928 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */