1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 29*cdf0e10cSrcweir #include "precompiled_testtools.hxx" 30*cdf0e10cSrcweir 31*cdf0e10cSrcweir #using <mscorlib.dll> 32*cdf0e10cSrcweir #using <System.dll> 33*cdf0e10cSrcweir #using <cli_basetypes.dll> 34*cdf0e10cSrcweir #using <cli_uretypes.dll> 35*cdf0e10cSrcweir #using <cli_ure.dll> 36*cdf0e10cSrcweir #using <cli_types_bridgetest.dll> 37*cdf0e10cSrcweir 38*cdf0e10cSrcweir using namespace System; 39*cdf0e10cSrcweir using namespace System::Diagnostics; 40*cdf0e10cSrcweir using namespace System::Reflection; 41*cdf0e10cSrcweir using namespace System::Threading; 42*cdf0e10cSrcweir using namespace uno; 43*cdf0e10cSrcweir using namespace uno::util; 44*cdf0e10cSrcweir using namespace unoidl::com::sun::star::uno; 45*cdf0e10cSrcweir using namespace unoidl::com::sun::star::lang; 46*cdf0e10cSrcweir //using namespace unoidl::com::sun::star::test::bridge; 47*cdf0e10cSrcweir using namespace unoidl::test::testtools::bridgetest; 48*cdf0e10cSrcweir namespace foo 49*cdf0e10cSrcweir { 50*cdf0e10cSrcweir public __gc __interface MyInterface 51*cdf0e10cSrcweir { 52*cdf0e10cSrcweir }; 53*cdf0e10cSrcweir } 54*cdf0e10cSrcweir 55*cdf0e10cSrcweir namespace cpp_bridgetest 56*cdf0e10cSrcweir { 57*cdf0e10cSrcweir __gc class ORecursiveCall: public WeakBase, public XRecursiveCall 58*cdf0e10cSrcweir { 59*cdf0e10cSrcweir public: 60*cdf0e10cSrcweir void callRecursivly(XRecursiveCall * xCall, int nToCall) 61*cdf0e10cSrcweir { 62*cdf0e10cSrcweir Monitor::Enter(this); 63*cdf0e10cSrcweir try 64*cdf0e10cSrcweir { 65*cdf0e10cSrcweir { 66*cdf0e10cSrcweir if (nToCall > 0) 67*cdf0e10cSrcweir { 68*cdf0e10cSrcweir nToCall --; 69*cdf0e10cSrcweir xCall->callRecursivly(this, nToCall); 70*cdf0e10cSrcweir } 71*cdf0e10cSrcweir } 72*cdf0e10cSrcweir } 73*cdf0e10cSrcweir __finally 74*cdf0e10cSrcweir { 75*cdf0e10cSrcweir Monitor::Exit(this); 76*cdf0e10cSrcweir } 77*cdf0e10cSrcweir 78*cdf0e10cSrcweir } 79*cdf0e10cSrcweir }; 80*cdf0e10cSrcweir 81*cdf0e10cSrcweir public __gc class Constants 82*cdf0e10cSrcweir { 83*cdf0e10cSrcweir public: 84*cdf0e10cSrcweir static String* STRING_TEST_CONSTANT = new String(S"\" paco\' chorizo\\\' \"\'"); 85*cdf0e10cSrcweir }; 86*cdf0e10cSrcweir 87*cdf0e10cSrcweir public __gc class BridgeTest : public WeakBase, public XMain 88*cdf0e10cSrcweir { 89*cdf0e10cSrcweir static bool compareData(Object* val1, Object* val2) 90*cdf0e10cSrcweir { 91*cdf0e10cSrcweir if (val1 == 0 && val2 == 0 || val1 == val2) 92*cdf0e10cSrcweir return true; 93*cdf0e10cSrcweir if ((val1 == 0 && val2 != 0) || 94*cdf0e10cSrcweir (val1 != 0 && val2 == 0) || val1->GetType() != val2->GetType()) 95*cdf0e10cSrcweir return false; 96*cdf0e10cSrcweir 97*cdf0e10cSrcweir bool ret = false; 98*cdf0e10cSrcweir Type* t1 = val1->GetType(); 99*cdf0e10cSrcweir //Sequence 100*cdf0e10cSrcweir if (t1->IsArray) 101*cdf0e10cSrcweir { 102*cdf0e10cSrcweir ret = compareSequence(static_cast<Array*>(val1), 103*cdf0e10cSrcweir static_cast<Array*>(val2)); 104*cdf0e10cSrcweir } 105*cdf0e10cSrcweir //String 106*cdf0e10cSrcweir else if (t1 == __typeof(String)) 107*cdf0e10cSrcweir { 108*cdf0e10cSrcweir ret = val1->Equals(val2); 109*cdf0e10cSrcweir } 110*cdf0e10cSrcweir // Interface implementation 111*cdf0e10cSrcweir else if (t1->GetInterfaces()->Length > 0 && ! t1->IsValueType) 112*cdf0e10cSrcweir { 113*cdf0e10cSrcweir ret = val1 == val2; 114*cdf0e10cSrcweir } 115*cdf0e10cSrcweir // Struct 116*cdf0e10cSrcweir else if ( ! t1->IsValueType) 117*cdf0e10cSrcweir { 118*cdf0e10cSrcweir ret = compareStruct(val1, val2); 119*cdf0e10cSrcweir } 120*cdf0e10cSrcweir else if (t1 == __typeof(Any)) 121*cdf0e10cSrcweir { 122*cdf0e10cSrcweir Any a1 = (Any) val1; 123*cdf0e10cSrcweir Any a2 = (Any) val2; 124*cdf0e10cSrcweir ret = a1.Type == a2.Type && compareData(a1.Value, a2.Value); 125*cdf0e10cSrcweir } 126*cdf0e10cSrcweir else if (t1->IsValueType) 127*cdf0e10cSrcweir { 128*cdf0e10cSrcweir //Any, enum, int, bool char, float, double etc. 129*cdf0e10cSrcweir ret = val1->Equals(val2); 130*cdf0e10cSrcweir } 131*cdf0e10cSrcweir else 132*cdf0e10cSrcweir { 133*cdf0e10cSrcweir Debug::Assert(false); 134*cdf0e10cSrcweir } 135*cdf0e10cSrcweir return ret; 136*cdf0e10cSrcweir } 137*cdf0e10cSrcweir 138*cdf0e10cSrcweir // Arrays have only one dimension 139*cdf0e10cSrcweir static bool compareSequence(Array* ar1, Array* ar2) 140*cdf0e10cSrcweir { 141*cdf0e10cSrcweir Debug::Assert(ar1 != 0 && ar2 != 0); 142*cdf0e10cSrcweir Type* t1 = ar1->GetType(); 143*cdf0e10cSrcweir Type* t2 = ar2->GetType(); 144*cdf0e10cSrcweir 145*cdf0e10cSrcweir if (!(ar1->Rank == 1 && ar2->Rank == 1 146*cdf0e10cSrcweir && ar1->Length == ar2->Length && t1->GetElementType() == t2->GetElementType())) 147*cdf0e10cSrcweir return false; 148*cdf0e10cSrcweir 149*cdf0e10cSrcweir //arrays have same rank and size and element type. 150*cdf0e10cSrcweir int len = ar1->Length; 151*cdf0e10cSrcweir bool ret = true; 152*cdf0e10cSrcweir for (int i = 0; i < len; i++) 153*cdf0e10cSrcweir { 154*cdf0e10cSrcweir if (compareData(ar1->GetValue(i), ar2->GetValue(i)) == false) 155*cdf0e10cSrcweir { 156*cdf0e10cSrcweir ret = false; 157*cdf0e10cSrcweir break; 158*cdf0e10cSrcweir } 159*cdf0e10cSrcweir } 160*cdf0e10cSrcweir return ret; 161*cdf0e10cSrcweir } 162*cdf0e10cSrcweir 163*cdf0e10cSrcweir static bool compareStruct(Object* val1, Object* val2) 164*cdf0e10cSrcweir { 165*cdf0e10cSrcweir Debug::Assert(val1 != 0 && val2 != 0); 166*cdf0e10cSrcweir Type* t1 = val1->GetType(); 167*cdf0e10cSrcweir Type* t2 = val2->GetType(); 168*cdf0e10cSrcweir if (t1 != t2) 169*cdf0e10cSrcweir return false; 170*cdf0e10cSrcweir FieldInfo* fields[] = t1->GetFields(); 171*cdf0e10cSrcweir int cFields = fields->Length; 172*cdf0e10cSrcweir bool ret = true; 173*cdf0e10cSrcweir for (int i = 0; i < cFields; i++) 174*cdf0e10cSrcweir { 175*cdf0e10cSrcweir Object* fieldVal1 = fields[i]->GetValue(val1); 176*cdf0e10cSrcweir Object* fieldVal2 = fields[i]->GetValue(val2); 177*cdf0e10cSrcweir if ( ! compareData(fieldVal1, fieldVal2)) 178*cdf0e10cSrcweir { 179*cdf0e10cSrcweir ret = false; 180*cdf0e10cSrcweir break; 181*cdf0e10cSrcweir } 182*cdf0e10cSrcweir } 183*cdf0e10cSrcweir return ret; 184*cdf0e10cSrcweir } 185*cdf0e10cSrcweir 186*cdf0e10cSrcweir static bool check( bool b , String* message ) 187*cdf0e10cSrcweir { 188*cdf0e10cSrcweir if ( ! b) 189*cdf0e10cSrcweir Console::WriteLine("{0} failed\n" , message); 190*cdf0e10cSrcweir return b; 191*cdf0e10cSrcweir } 192*cdf0e10cSrcweir 193*cdf0e10cSrcweir static bool equals(TestElement* rData1, TestElement* rData2) 194*cdf0e10cSrcweir { 195*cdf0e10cSrcweir check( rData1->Bool == rData2->Bool, "### bool does not match!" ); 196*cdf0e10cSrcweir check( rData1->Char == rData2->Char, "### char does not match!" ); 197*cdf0e10cSrcweir check( rData1->Byte == rData2->Byte, "### byte does not match!" ); 198*cdf0e10cSrcweir check( rData1->Short == rData2->Short, "### short does not match!" ); 199*cdf0e10cSrcweir check( rData1->UShort == rData2->UShort, "### unsigned short does not match!" ); 200*cdf0e10cSrcweir check( rData1->Long == rData2->Long, "### long does not match!" ); 201*cdf0e10cSrcweir check( rData1->ULong == rData2->ULong, "### unsigned long does not match!" ); 202*cdf0e10cSrcweir check( rData1->Hyper == rData2->Hyper, "### hyper does not match!" ); 203*cdf0e10cSrcweir check( rData1->UHyper == rData2->UHyper, "### unsigned hyper does not match!" ); 204*cdf0e10cSrcweir check( rData1->Float == rData2->Float, "### float does not match!" ); 205*cdf0e10cSrcweir check( rData1->Double == rData2->Double, "### double does not match!" ); 206*cdf0e10cSrcweir check( rData1->Enum == rData2->Enum, "### enum does not match!" ); 207*cdf0e10cSrcweir check( rData1->String == rData2->String, "### string does not match!" ); 208*cdf0e10cSrcweir check( rData1->Interface == rData2->Interface, "### interface does not match!" ); 209*cdf0e10cSrcweir check( compareData(__box(rData1->Any), __box(rData2->Any)), "### any does not match!" ); 210*cdf0e10cSrcweir 211*cdf0e10cSrcweir return (rData1->Bool == rData2->Bool && 212*cdf0e10cSrcweir rData1->Char == rData2->Char && 213*cdf0e10cSrcweir rData1->Byte == rData2->Byte && 214*cdf0e10cSrcweir rData1->Short == rData2->Short && 215*cdf0e10cSrcweir rData1->UShort == rData2->UShort && 216*cdf0e10cSrcweir rData1->Long == rData2->Long && 217*cdf0e10cSrcweir rData1->ULong == rData2->ULong && 218*cdf0e10cSrcweir rData1->Hyper == rData2->Hyper && 219*cdf0e10cSrcweir rData1->UHyper == rData2->UHyper && 220*cdf0e10cSrcweir rData1->Float == rData2->Float && 221*cdf0e10cSrcweir rData1->Double == rData2->Double && 222*cdf0e10cSrcweir rData1->Enum == rData2->Enum && 223*cdf0e10cSrcweir rData1->String == rData2->String && 224*cdf0e10cSrcweir rData1->Interface == rData2->Interface && 225*cdf0e10cSrcweir compareData(__box(rData1->Any), __box(rData2->Any))); 226*cdf0e10cSrcweir } 227*cdf0e10cSrcweir 228*cdf0e10cSrcweir static void assign( TestElement* rData, 229*cdf0e10cSrcweir bool bBool, Char cChar, Byte nByte, 230*cdf0e10cSrcweir Int16 nShort, UInt16 nUShort, 231*cdf0e10cSrcweir Int32 nLong, UInt32 nULong, 232*cdf0e10cSrcweir Int64 nHyper, UInt64 nUHyper, 233*cdf0e10cSrcweir float fFloat, double fDouble, 234*cdf0e10cSrcweir TestEnum eEnum, String* rStr, 235*cdf0e10cSrcweir Object* xTest, 236*cdf0e10cSrcweir uno::Any rAny ) 237*cdf0e10cSrcweir { 238*cdf0e10cSrcweir rData->Bool = bBool; 239*cdf0e10cSrcweir rData->Char = cChar; 240*cdf0e10cSrcweir rData->Byte = nByte; 241*cdf0e10cSrcweir rData->Short = nShort; 242*cdf0e10cSrcweir rData->UShort = nUShort; 243*cdf0e10cSrcweir rData->Long = nLong; 244*cdf0e10cSrcweir rData->ULong = nULong; 245*cdf0e10cSrcweir rData->Hyper = nHyper; 246*cdf0e10cSrcweir rData->UHyper = nUHyper; 247*cdf0e10cSrcweir rData->Float = fFloat; 248*cdf0e10cSrcweir rData->Double = fDouble; 249*cdf0e10cSrcweir rData->Enum = eEnum; 250*cdf0e10cSrcweir rData->String = rStr; 251*cdf0e10cSrcweir rData->Interface = xTest; 252*cdf0e10cSrcweir rData->Any = rAny; 253*cdf0e10cSrcweir } 254*cdf0e10cSrcweir 255*cdf0e10cSrcweir static void assign( TestDataElements* rData, 256*cdf0e10cSrcweir bool bBool, Char cChar, Byte nByte, 257*cdf0e10cSrcweir Int16 nShort, UInt16 nUShort, 258*cdf0e10cSrcweir Int32 nLong, UInt32 nULong, 259*cdf0e10cSrcweir Int64 nHyper, UInt64 nUHyper, 260*cdf0e10cSrcweir float fFloat, double fDouble, 261*cdf0e10cSrcweir TestEnum eEnum, String* rStr, 262*cdf0e10cSrcweir Object* xTest, 263*cdf0e10cSrcweir Any rAny, 264*cdf0e10cSrcweir TestElement* rSequence[]) 265*cdf0e10cSrcweir { 266*cdf0e10cSrcweir assign( static_cast<TestElement*>(rData), 267*cdf0e10cSrcweir bBool, cChar, nByte, nShort, nUShort, nLong, nULong, nHyper, nUHyper, fFloat, fDouble, 268*cdf0e10cSrcweir eEnum, rStr, xTest, rAny ); 269*cdf0e10cSrcweir rData->Sequence = rSequence; 270*cdf0e10cSrcweir } 271*cdf0e10cSrcweir 272*cdf0e10cSrcweir static bool testAny(Type* typ, Object* value, XBridgeTest* xLBT ) 273*cdf0e10cSrcweir { 274*cdf0e10cSrcweir Any any; 275*cdf0e10cSrcweir if (typ == 0) 276*cdf0e10cSrcweir any = Any(value->GetType(), value); 277*cdf0e10cSrcweir else 278*cdf0e10cSrcweir any = Any(typ, value); 279*cdf0e10cSrcweir 280*cdf0e10cSrcweir Any any2 = xLBT->transportAny(any); 281*cdf0e10cSrcweir bool ret = compareData(__box(any), __box(any2)); 282*cdf0e10cSrcweir if (!ret) 283*cdf0e10cSrcweir { 284*cdf0e10cSrcweir Console::WriteLine("any is different after roundtrip: in {0}, out {1}\n", 285*cdf0e10cSrcweir any.Type->FullName, any2.Type->FullName); 286*cdf0e10cSrcweir } 287*cdf0e10cSrcweir return ret; 288*cdf0e10cSrcweir } 289*cdf0e10cSrcweir 290*cdf0e10cSrcweir 291*cdf0e10cSrcweir 292*cdf0e10cSrcweir static bool performAnyTest(XBridgeTest* xLBT, TestDataElements* data) 293*cdf0e10cSrcweir { 294*cdf0e10cSrcweir bool bReturn = true; 295*cdf0e10cSrcweir bReturn = testAny( 0, __box(data->Byte), xLBT ) && bReturn; 296*cdf0e10cSrcweir bReturn = testAny( 0, __box(data->Short), xLBT ) && bReturn; 297*cdf0e10cSrcweir bReturn = testAny( 0, __box(data->UShort), xLBT ) && bReturn; 298*cdf0e10cSrcweir bReturn = testAny( 0, __box(data->Long), xLBT ) && bReturn; 299*cdf0e10cSrcweir bReturn = testAny( 0, __box(data->ULong), xLBT ) && bReturn; 300*cdf0e10cSrcweir bReturn = testAny( 0, __box(data->Hyper), xLBT ) && bReturn; 301*cdf0e10cSrcweir bReturn = testAny( 0, __box(data->UHyper), xLBT ) && bReturn; 302*cdf0e10cSrcweir bReturn = testAny( 0, __box(data->Float), xLBT ) && bReturn; 303*cdf0e10cSrcweir bReturn = testAny( 0, __box(data->Double),xLBT ) && bReturn; 304*cdf0e10cSrcweir bReturn = testAny( 0, __box(data->Enum), xLBT ) && bReturn; 305*cdf0e10cSrcweir bReturn = testAny( 0, data->String,xLBT ) && bReturn; 306*cdf0e10cSrcweir bReturn = testAny(__typeof(XWeak), data->Interface,xLBT ) && bReturn; 307*cdf0e10cSrcweir bReturn = testAny(0, data, xLBT ) && bReturn; 308*cdf0e10cSrcweir 309*cdf0e10cSrcweir { 310*cdf0e10cSrcweir Any a1(true); 311*cdf0e10cSrcweir Any a2 = xLBT->transportAny( a1 ); 312*cdf0e10cSrcweir bReturn = compareData(__box(a2), __box(a1)) && bReturn; 313*cdf0e10cSrcweir } 314*cdf0e10cSrcweir 315*cdf0e10cSrcweir { 316*cdf0e10cSrcweir Any a1('A'); 317*cdf0e10cSrcweir Any a2 = xLBT->transportAny(a1); 318*cdf0e10cSrcweir bReturn = compareData( __box(a2), __box(a1)) && bReturn; 319*cdf0e10cSrcweir } 320*cdf0e10cSrcweir return bReturn; 321*cdf0e10cSrcweir } 322*cdf0e10cSrcweir 323*cdf0e10cSrcweir static bool performSequenceOfCallTest(XBridgeTest* xLBT) 324*cdf0e10cSrcweir { 325*cdf0e10cSrcweir int i,nRounds; 326*cdf0e10cSrcweir int nGlobalIndex = 0; 327*cdf0e10cSrcweir const int nWaitTimeSpanMUSec = 10000; 328*cdf0e10cSrcweir for( nRounds = 0 ; nRounds < 10 ; nRounds ++ ) 329*cdf0e10cSrcweir { 330*cdf0e10cSrcweir for( i = 0 ; i < nRounds ; i ++ ) 331*cdf0e10cSrcweir { 332*cdf0e10cSrcweir // fire oneways 333*cdf0e10cSrcweir xLBT->callOneway(nGlobalIndex, nWaitTimeSpanMUSec); 334*cdf0e10cSrcweir nGlobalIndex++; 335*cdf0e10cSrcweir } 336*cdf0e10cSrcweir 337*cdf0e10cSrcweir // call synchron 338*cdf0e10cSrcweir xLBT->call(nGlobalIndex, nWaitTimeSpanMUSec); 339*cdf0e10cSrcweir nGlobalIndex++; 340*cdf0e10cSrcweir } 341*cdf0e10cSrcweir return xLBT->sequenceOfCallTestPassed(); 342*cdf0e10cSrcweir } 343*cdf0e10cSrcweir 344*cdf0e10cSrcweir 345*cdf0e10cSrcweir 346*cdf0e10cSrcweir 347*cdf0e10cSrcweir static bool performRecursiveCallTest(XBridgeTest* xLBT) 348*cdf0e10cSrcweir { 349*cdf0e10cSrcweir xLBT->startRecursiveCall(new ORecursiveCall(), 50); 350*cdf0e10cSrcweir // on failure, the test would lock up or crash 351*cdf0e10cSrcweir return true; 352*cdf0e10cSrcweir } 353*cdf0e10cSrcweir 354*cdf0e10cSrcweir static bool performQueryForUnknownType(XBridgeTest* xLBT) 355*cdf0e10cSrcweir { 356*cdf0e10cSrcweir bool bRet = false; 357*cdf0e10cSrcweir // test queryInterface for an unknown type 358*cdf0e10cSrcweir try 359*cdf0e10cSrcweir { 360*cdf0e10cSrcweir __try_cast<foo::MyInterface*>(xLBT); 361*cdf0e10cSrcweir } 362*cdf0e10cSrcweir catch( System::InvalidCastException*) 363*cdf0e10cSrcweir { 364*cdf0e10cSrcweir bRet = true; 365*cdf0e10cSrcweir } 366*cdf0e10cSrcweir 367*cdf0e10cSrcweir return bRet; 368*cdf0e10cSrcweir } 369*cdf0e10cSrcweir 370*cdf0e10cSrcweir // //================================================================================================== 371*cdf0e10cSrcweir static bool performTest(XBridgeTest* xLBT) 372*cdf0e10cSrcweir { 373*cdf0e10cSrcweir check( xLBT != 0, "### no test interface!" ); 374*cdf0e10cSrcweir bool bRet = true; 375*cdf0e10cSrcweir if (xLBT != 0) 376*cdf0e10cSrcweir { 377*cdf0e10cSrcweir // this data is never ever granted access to by calls other than equals(), assign()! 378*cdf0e10cSrcweir TestDataElements* aData = new TestDataElements(); // test against this data 379*cdf0e10cSrcweir 380*cdf0e10cSrcweir Object* xI= new WeakBase(); 381*cdf0e10cSrcweir 382*cdf0e10cSrcweir Any aAny( __typeof(Object), xI); 383*cdf0e10cSrcweir assign( static_cast<TestElement*>(aData), 384*cdf0e10cSrcweir true, '@', 17, 0x1234, 0xfedc, 0x12345678, 0xfedcba98, 385*cdf0e10cSrcweir 0x123456789abcdef0, 0xfedcba9876543210, 386*cdf0e10cSrcweir 17.0815f, 3.1415926359, TestEnum::LOLA, 387*cdf0e10cSrcweir Constants::STRING_TEST_CONSTANT, xI, 388*cdf0e10cSrcweir aAny); 389*cdf0e10cSrcweir 390*cdf0e10cSrcweir bRet = check( aData->Any.Value == xI, "### unexpected any!" ) && bRet; 391*cdf0e10cSrcweir bRet = check( !(aData->Any.Value != xI), "### unexpected any!" ) && bRet; 392*cdf0e10cSrcweir 393*cdf0e10cSrcweir aData->Sequence = new TestElement*[2]; 394*cdf0e10cSrcweir aData->Sequence[0] = new TestElement( 395*cdf0e10cSrcweir aData->Bool, aData->Char, aData->Byte, aData->Short, 396*cdf0e10cSrcweir aData->UShort, aData->Long, aData->ULong, 397*cdf0e10cSrcweir aData->Hyper, aData->UHyper, aData->Float, 398*cdf0e10cSrcweir aData->Double, aData->Enum, aData->String, 399*cdf0e10cSrcweir aData->Interface, aData->Any); //(TestElement) aData; 400*cdf0e10cSrcweir aData->Sequence[1] = new TestElement(); //is empty 401*cdf0e10cSrcweir 402*cdf0e10cSrcweir // aData complete 403*cdf0e10cSrcweir // 404*cdf0e10cSrcweir // this is a manually copy of aData for first setting... 405*cdf0e10cSrcweir TestDataElements* aSetData = new TestDataElements; 406*cdf0e10cSrcweir Any aAnySet(__typeof(Object), xI); 407*cdf0e10cSrcweir assign( static_cast<TestElement*>(aSetData), 408*cdf0e10cSrcweir aData->Bool, 409*cdf0e10cSrcweir aData->Char, 410*cdf0e10cSrcweir aData->Byte, 411*cdf0e10cSrcweir aData->Short, 412*cdf0e10cSrcweir aData->UShort, 413*cdf0e10cSrcweir aData->Long, aData->ULong, aData->Hyper, aData->UHyper, aData->Float, aData->Double, 414*cdf0e10cSrcweir aData->Enum, 415*cdf0e10cSrcweir aData->String, 416*cdf0e10cSrcweir xI, 417*cdf0e10cSrcweir aAnySet); 418*cdf0e10cSrcweir 419*cdf0e10cSrcweir aSetData->Sequence = new TestElement*[2]; 420*cdf0e10cSrcweir aSetData->Sequence[0] = new TestElement( 421*cdf0e10cSrcweir aSetData->Bool, aSetData->Char, aSetData->Byte, aSetData->Short, 422*cdf0e10cSrcweir aSetData->UShort, aSetData->Long, aSetData->ULong, 423*cdf0e10cSrcweir aSetData->Hyper, aSetData->UHyper, aSetData->Float, 424*cdf0e10cSrcweir aSetData->Double, aSetData->Enum, aSetData->String, 425*cdf0e10cSrcweir aSetData->Interface, aSetData->Any); //TestElement) aSetData; 426*cdf0e10cSrcweir aSetData->Sequence[1] = new TestElement(); // empty struct 427*cdf0e10cSrcweir 428*cdf0e10cSrcweir xLBT->setValues( 429*cdf0e10cSrcweir aSetData->Bool, aSetData->Char, aSetData->Byte, aSetData->Short, aSetData->UShort, 430*cdf0e10cSrcweir aSetData->Long, aSetData->ULong, aSetData->Hyper, aSetData->UHyper, aSetData->Float, aSetData->Double, 431*cdf0e10cSrcweir aSetData->Enum, aSetData->String, aSetData->Interface, aSetData->Any, aSetData->Sequence, aSetData ); 432*cdf0e10cSrcweir 433*cdf0e10cSrcweir { 434*cdf0e10cSrcweir TestDataElements* aRet = new TestDataElements(); 435*cdf0e10cSrcweir TestDataElements* aRet2 = new TestDataElements(); 436*cdf0e10cSrcweir xLBT->getValues( 437*cdf0e10cSrcweir & aRet->Bool, & aRet->Char, & aRet->Byte, & aRet->Short, & aRet->UShort, 438*cdf0e10cSrcweir & aRet->Long, & aRet->ULong, & aRet->Hyper, & aRet->UHyper, 439*cdf0e10cSrcweir & aRet->Float, & aRet->Double, & aRet->Enum, & aRet->String, 440*cdf0e10cSrcweir & aRet->Interface, & aRet->Any, & aRet->Sequence, & aRet2 ); 441*cdf0e10cSrcweir 442*cdf0e10cSrcweir bRet = check( compareData( aData, aRet ) && compareData( aData, aRet2 ) , "getValues test") && bRet; 443*cdf0e10cSrcweir 444*cdf0e10cSrcweir // set last retrieved values 445*cdf0e10cSrcweir TestDataElements* aSV2ret = xLBT->setValues2( 446*cdf0e10cSrcweir & aRet->Bool, & aRet->Char, & aRet->Byte, & aRet->Short, & aRet->UShort, 447*cdf0e10cSrcweir & aRet->Long, & aRet->ULong, & aRet->Hyper, & aRet->UHyper, & aRet->Float, 448*cdf0e10cSrcweir & aRet->Double, & aRet->Enum, & aRet->String, & aRet->Interface, & aRet->Any, 449*cdf0e10cSrcweir & aRet->Sequence, & aRet2 ); 450*cdf0e10cSrcweir 451*cdf0e10cSrcweir // check inout sequence order 452*cdf0e10cSrcweir // => inout sequence parameter was switched by test objects 453*cdf0e10cSrcweir TestElement* temp = aRet->Sequence[ 0 ]; 454*cdf0e10cSrcweir aRet->Sequence[ 0 ] = aRet->Sequence[ 1 ]; 455*cdf0e10cSrcweir aRet->Sequence[ 1 ] = temp; 456*cdf0e10cSrcweir 457*cdf0e10cSrcweir bRet = check( 458*cdf0e10cSrcweir compareData( aData, aSV2ret ) && compareData( aData, aRet2 ), 459*cdf0e10cSrcweir "getValues2 test") && bRet; 460*cdf0e10cSrcweir } 461*cdf0e10cSrcweir { 462*cdf0e10cSrcweir TestDataElements* aRet = new TestDataElements(); 463*cdf0e10cSrcweir TestDataElements* aRet2 = new TestDataElements(); 464*cdf0e10cSrcweir TestDataElements* aGVret = xLBT->getValues( 465*cdf0e10cSrcweir & aRet->Bool, & aRet->Char, & aRet->Byte, & aRet->Short, 466*cdf0e10cSrcweir & aRet->UShort, & aRet->Long, & aRet->ULong, & aRet->Hyper, 467*cdf0e10cSrcweir & aRet->UHyper, & aRet->Float, & aRet->Double, & aRet->Enum, 468*cdf0e10cSrcweir & aRet->String, & aRet->Interface, & aRet->Any, & aRet->Sequence, 469*cdf0e10cSrcweir & aRet2 ); 470*cdf0e10cSrcweir 471*cdf0e10cSrcweir bRet = check( compareData( aData, aRet ) && compareData( aData, aRet2 ) && compareData( aData, aGVret ), "getValues test" ) && bRet; 472*cdf0e10cSrcweir 473*cdf0e10cSrcweir // set last retrieved values 474*cdf0e10cSrcweir xLBT->Bool = aRet->Bool; 475*cdf0e10cSrcweir xLBT->Char = aRet->Char; 476*cdf0e10cSrcweir xLBT->Byte = aRet->Byte; 477*cdf0e10cSrcweir xLBT->Short = aRet->Short; 478*cdf0e10cSrcweir xLBT->UShort = aRet->UShort; 479*cdf0e10cSrcweir xLBT->Long = aRet->Long; 480*cdf0e10cSrcweir xLBT->ULong = aRet->ULong; 481*cdf0e10cSrcweir xLBT->Hyper = aRet->Hyper; 482*cdf0e10cSrcweir xLBT->UHyper = aRet->UHyper; 483*cdf0e10cSrcweir xLBT->Float = aRet->Float; 484*cdf0e10cSrcweir xLBT->Double = aRet->Double; 485*cdf0e10cSrcweir xLBT->Enum = aRet->Enum; 486*cdf0e10cSrcweir xLBT->String = aRet->String; 487*cdf0e10cSrcweir xLBT->Interface = aRet->Interface; 488*cdf0e10cSrcweir xLBT->Any = aRet->Any; 489*cdf0e10cSrcweir xLBT->Sequence = aRet->Sequence; 490*cdf0e10cSrcweir xLBT->Struct = aRet2; 491*cdf0e10cSrcweir } 492*cdf0e10cSrcweir { 493*cdf0e10cSrcweir TestDataElements* aRet = new TestDataElements(); 494*cdf0e10cSrcweir TestDataElements* aRet2 = new TestDataElements(); 495*cdf0e10cSrcweir aRet->Hyper = xLBT->Hyper; 496*cdf0e10cSrcweir aRet->UHyper = xLBT->UHyper; 497*cdf0e10cSrcweir aRet->Float = xLBT->Float; 498*cdf0e10cSrcweir aRet->Double = xLBT->Double; 499*cdf0e10cSrcweir aRet->Byte = xLBT->Byte; 500*cdf0e10cSrcweir aRet->Char = xLBT->Char; 501*cdf0e10cSrcweir aRet->Bool = xLBT->Bool; 502*cdf0e10cSrcweir aRet->Short = xLBT->Short; 503*cdf0e10cSrcweir aRet->UShort = xLBT->UShort; 504*cdf0e10cSrcweir aRet->Long = xLBT->Long; 505*cdf0e10cSrcweir aRet->ULong = xLBT->ULong; 506*cdf0e10cSrcweir aRet->Enum = xLBT->Enum; 507*cdf0e10cSrcweir aRet->String = xLBT->String; 508*cdf0e10cSrcweir aRet->Interface = xLBT->Interface; 509*cdf0e10cSrcweir aRet->Any = xLBT->Any; 510*cdf0e10cSrcweir aRet->Sequence = xLBT->Sequence; 511*cdf0e10cSrcweir aRet2 = xLBT->Struct; 512*cdf0e10cSrcweir 513*cdf0e10cSrcweir bRet = check( compareData( aData, aRet ) && compareData( aData, aRet2 ) , "struct comparison test") && bRet; 514*cdf0e10cSrcweir 515*cdf0e10cSrcweir bRet = check(performSequenceTest(xLBT), "sequence test") && bRet; 516*cdf0e10cSrcweir 517*cdf0e10cSrcweir // any test 518*cdf0e10cSrcweir bRet = check( performAnyTest( xLBT , aData ) , "any test" ) && bRet; 519*cdf0e10cSrcweir 520*cdf0e10cSrcweir // sequence of call test 521*cdf0e10cSrcweir bRet = check( performSequenceOfCallTest( xLBT ) , "sequence of call test" ) && bRet; 522*cdf0e10cSrcweir 523*cdf0e10cSrcweir // recursive call test 524*cdf0e10cSrcweir bRet = check( performRecursiveCallTest( xLBT ) , "recursive test" ) && bRet; 525*cdf0e10cSrcweir 526*cdf0e10cSrcweir bRet = (compareData( aData, aRet ) && compareData( aData, aRet2 )) && bRet ; 527*cdf0e10cSrcweir 528*cdf0e10cSrcweir // check setting of null reference 529*cdf0e10cSrcweir xLBT->Interface = 0; 530*cdf0e10cSrcweir aRet->Interface = xLBT->Interface; 531*cdf0e10cSrcweir bRet = (aRet->Interface == 0) && bRet; 532*cdf0e10cSrcweir 533*cdf0e10cSrcweir } 534*cdf0e10cSrcweir 535*cdf0e10cSrcweir 536*cdf0e10cSrcweir } 537*cdf0e10cSrcweir return bRet; 538*cdf0e10cSrcweir } 539*cdf0e10cSrcweir static bool performSequenceTest(XBridgeTest* xBT) 540*cdf0e10cSrcweir { 541*cdf0e10cSrcweir bool bRet = true; 542*cdf0e10cSrcweir XBridgeTest2* xBT2 = dynamic_cast<XBridgeTest2*>(xBT); 543*cdf0e10cSrcweir if ( xBT2 == 0) 544*cdf0e10cSrcweir return false; 545*cdf0e10cSrcweir 546*cdf0e10cSrcweir // perform sequence tests (XBridgeTest2) 547*cdf0e10cSrcweir // create the sequence which are compared with the results 548*cdf0e10cSrcweir bool arBool __gc[] = new bool __gc [3]; 549*cdf0e10cSrcweir arBool[0] = true; arBool[1] = false; arBool[2] = true; 550*cdf0e10cSrcweir Char arChar[] = new Char[3]; 551*cdf0e10cSrcweir arChar[0] = 'A'; arChar[1] = 'B'; arChar[2] = 'C'; 552*cdf0e10cSrcweir Byte arByte[] = new Byte[3]; 553*cdf0e10cSrcweir arByte[0] = 1; arByte[1] = 2; arByte[2] = 0xff; 554*cdf0e10cSrcweir Int16 arShort[] = new Int16[3]; 555*cdf0e10cSrcweir arShort[0] = Int16::MinValue; arShort[1] = 1; arShort[2] = Int16::MaxValue; 556*cdf0e10cSrcweir UInt16 arUShort[] = new UInt16[3]; 557*cdf0e10cSrcweir arUShort[0] = UInt16::MinValue; arUShort[1] = 1; arUShort[2] = UInt16::MaxValue; 558*cdf0e10cSrcweir Int32 arLong[] = new Int32[3]; 559*cdf0e10cSrcweir arLong[0] = Int32::MinValue; arLong[1] = 1; arLong[2] = Int32::MaxValue; 560*cdf0e10cSrcweir UInt32 arULong[] = new UInt32[3]; 561*cdf0e10cSrcweir arULong[0] = UInt32::MinValue; arULong[1] = 1; arULong[2] = UInt32::MaxValue; 562*cdf0e10cSrcweir Int64 arHyper[] = new Int64[3]; 563*cdf0e10cSrcweir arHyper[0] = Int64::MinValue; arHyper[1] = 1; arHyper[2] = Int64::MaxValue; 564*cdf0e10cSrcweir UInt64 arUHyper[] = new UInt64[3]; 565*cdf0e10cSrcweir arUHyper[0] = UInt64::MinValue; arUHyper[1] = 1; 566*cdf0e10cSrcweir arUHyper[2] = UInt64::MaxValue; 567*cdf0e10cSrcweir Single arFloat[] = new Single[3]; 568*cdf0e10cSrcweir arFloat[0] = 1.1f; arFloat[1] = 2.2f; arFloat[2] = 3.3f; 569*cdf0e10cSrcweir Double arDouble[] = new Double[3]; 570*cdf0e10cSrcweir arDouble[0] = 1.11; arDouble[1] = 2.22; arDouble[2] = 3.33; 571*cdf0e10cSrcweir String* arString[] = new String*[3]; 572*cdf0e10cSrcweir arString[0] = new String("String 1"); 573*cdf0e10cSrcweir arString[1] = new String("String 2"); 574*cdf0e10cSrcweir arString[2] = new String("String 3"); 575*cdf0e10cSrcweir 576*cdf0e10cSrcweir Any arAny[] = new Any[3]; 577*cdf0e10cSrcweir arAny[0] = Any(true); arAny[1] = Any(11111); arAny[2] = Any(3.14); 578*cdf0e10cSrcweir Object* arObject[] = new Object*[3]; 579*cdf0e10cSrcweir arObject[0] = new WeakBase(); arObject[1] = new WeakBase(); 580*cdf0e10cSrcweir arObject[1] = new WeakBase(); 581*cdf0e10cSrcweir 582*cdf0e10cSrcweir //TestEnum arEnum[] = new TestEnum[3]; 583*cdf0e10cSrcweir //arEnum[0] = TestEnum::ONE; arEnum[1] = TestEnum::TWO; 584*cdf0e10cSrcweir //arEnum[2] = TestEnum::CHECK; 585*cdf0e10cSrcweir Console::WriteLine(new String("cli_cpp_bridgetest: Workaround for C++ compiler bug:" 586*cdf0e10cSrcweir " using Array of Int32 instead of Array of enums w")); 587*cdf0e10cSrcweir Int32 arEnum[] = new Int32[3]; 588*cdf0e10cSrcweir arEnum[0] = static_cast<Int32>(TestEnum::ONE); 589*cdf0e10cSrcweir arEnum[1] = static_cast<Int32>(TestEnum::TWO); 590*cdf0e10cSrcweir arEnum[2] = static_cast<Int32>(TestEnum::CHECK); 591*cdf0e10cSrcweir 592*cdf0e10cSrcweir TestElement* arStruct[] = new TestElement*[3]; 593*cdf0e10cSrcweir arStruct[0] = new TestElement(); arStruct[1] = new TestElement(); 594*cdf0e10cSrcweir arStruct[2] = new TestElement(); 595*cdf0e10cSrcweir assign( arStruct[0], true, '@', 17, 0x1234, 0xfedc, 0x12345678, 0xfedcba98, 596*cdf0e10cSrcweir 0x123456789abcdef0, 0xfedcba9876543210, 17.0815f, 3.1415926359, 597*cdf0e10cSrcweir TestEnum::LOLA, Constants::STRING_TEST_CONSTANT, arObject[0], 598*cdf0e10cSrcweir Any( __typeof(Object), arObject[0]) ); 599*cdf0e10cSrcweir assign( arStruct[1], true, 'A', 17, 0x1234, 0xfedc, 0x12345678, 0xfedcba98, 600*cdf0e10cSrcweir 0x123456789abcdef0, 0xfedcba9876543210, 17.0815f, 3.1415926359, 601*cdf0e10cSrcweir TestEnum::TWO, Constants::STRING_TEST_CONSTANT, arObject[1], 602*cdf0e10cSrcweir Any( __typeof(Object), arObject[1]) ); 603*cdf0e10cSrcweir assign( arStruct[2], true, 'B', 17, 0x1234, 0xfedc, 0x12345678, 0xfedcba98, 604*cdf0e10cSrcweir 0x123456789abcdef0, 0xfedcba9876543210, 17.0815f, 3.1415926359, 605*cdf0e10cSrcweir TestEnum::CHECK, Constants::STRING_TEST_CONSTANT, arObject[2], 606*cdf0e10cSrcweir Any( __typeof(Object), arObject[2] ) ); 607*cdf0e10cSrcweir 608*cdf0e10cSrcweir 609*cdf0e10cSrcweir // int[][][] arLong3 = new int[][][]{ 610*cdf0e10cSrcweir // new int[][]{new int[]{1,2,3},new int[]{4,5,6}, new int[]{7,8,9} }, 611*cdf0e10cSrcweir // new int [][]{new int[]{1,2,3},new int[]{4,5,6}, new int[]{7,8,9}}, 612*cdf0e10cSrcweir // new int[][]{new int[]{1,2,3},new int[]{4,5,6}, new int[]{7,8,9}}}; 613*cdf0e10cSrcweir 614*cdf0e10cSrcweir { 615*cdf0e10cSrcweir 616*cdf0e10cSrcweir // Console::WriteLine(new String("cli_cpp_bridgetest: 617*cdf0e10cSrcweir // int[][] seqSeqRet = xBT2->setDim2(arLong3[0]); 618*cdf0e10cSrcweir // bRet = check( compareData(seqSeqRet, arLong3[0]), "sequence test") && bRet; 619*cdf0e10cSrcweir // int[][][] seqSeqRet2 = xBT2->setDim3(arLong3); 620*cdf0e10cSrcweir // bRet = check( compareData(seqSeqRet2, arLong3), "sequence test") && bRet; 621*cdf0e10cSrcweir 622*cdf0e10cSrcweir Any seqAnyRet[] = xBT2->setSequenceAny(arAny); 623*cdf0e10cSrcweir bRet = check( compareData(seqAnyRet, arAny), "sequence test") && bRet; 624*cdf0e10cSrcweir Boolean seqBoolRet[] = xBT2->setSequenceBool(arBool); 625*cdf0e10cSrcweir bRet = check( compareData(seqBoolRet, arBool), "sequence test") && bRet; 626*cdf0e10cSrcweir Byte seqByteRet[] = xBT2->setSequenceByte(arByte); 627*cdf0e10cSrcweir bRet = check( compareData(seqByteRet, arByte), "sequence test") && bRet; 628*cdf0e10cSrcweir Char seqCharRet[] = xBT2->setSequenceChar(arChar); 629*cdf0e10cSrcweir bRet = check( compareData(seqCharRet, arChar), "sequence test") && bRet; 630*cdf0e10cSrcweir Int16 seqShortRet[] = xBT2->setSequenceShort(arShort); 631*cdf0e10cSrcweir bRet = check( compareData(seqShortRet, arShort), "sequence test") && bRet; 632*cdf0e10cSrcweir Int32 seqLongRet[] = xBT2->setSequenceLong(arLong); 633*cdf0e10cSrcweir bRet = check( compareData(seqLongRet, arLong), "sequence test") && bRet; 634*cdf0e10cSrcweir Int64 seqHyperRet[] = xBT2->setSequenceHyper(arHyper); 635*cdf0e10cSrcweir bRet = check( compareData(seqHyperRet,arHyper), "sequence test") && bRet; 636*cdf0e10cSrcweir Single seqFloatRet[] = xBT2->setSequenceFloat(arFloat); 637*cdf0e10cSrcweir bRet = check( compareData(seqFloatRet, arFloat), "sequence test") && bRet; 638*cdf0e10cSrcweir Double seqDoubleRet[] = xBT2->setSequenceDouble(arDouble); 639*cdf0e10cSrcweir bRet = check( compareData(seqDoubleRet, arDouble), "sequence test") && bRet; 640*cdf0e10cSrcweir xBT2->setSequenceEnum(arEnum); 641*cdf0e10cSrcweir //comparing seqEnumRet with arEnum will fail since they are of different 642*cdf0e10cSrcweir //types because of workaround. arEnum is Int32[]. 643*cdf0e10cSrcweir Console::WriteLine(new String("cli_cpp_bridgetest: Test omitted because " 644*cdf0e10cSrcweir "of C++ compiler bug. XBridgeTest2::setSequenceEnum(sequence<TestEnum>)")); 645*cdf0e10cSrcweir // bRet = check( compareData(seqEnumRet, arEnum), "sequence test") && bRet; 646*cdf0e10cSrcweir UInt16 seqUShortRet[] = xBT2->setSequenceUShort(arUShort); 647*cdf0e10cSrcweir bRet = check( compareData(seqUShortRet, arUShort), "sequence test") && bRet; 648*cdf0e10cSrcweir UInt32 seqULongRet[] = xBT2->setSequenceULong(arULong); 649*cdf0e10cSrcweir bRet = check( compareData(seqULongRet, arULong), "sequence test") && bRet; 650*cdf0e10cSrcweir UInt64 seqUHyperRet[] = xBT2->setSequenceUHyper(arUHyper); 651*cdf0e10cSrcweir bRet = check( compareData(seqUHyperRet, arUHyper), "sequence test") && bRet; 652*cdf0e10cSrcweir Object* seqObjectRet[] = xBT2->setSequenceXInterface(arObject); 653*cdf0e10cSrcweir bRet = check( compareData(seqObjectRet, arObject), "sequence test") && bRet; 654*cdf0e10cSrcweir String* seqStringRet[] = xBT2->setSequenceString(arString); 655*cdf0e10cSrcweir bRet = check( compareData(seqStringRet, arString), "sequence test") && bRet; 656*cdf0e10cSrcweir TestElement* seqStructRet[] = xBT2->setSequenceStruct(arStruct); 657*cdf0e10cSrcweir bRet = check( compareData(seqStructRet, arStruct), "sequence test") && bRet; 658*cdf0e10cSrcweir } 659*cdf0e10cSrcweir { 660*cdf0e10cSrcweir // Boolean arBoolTemp[] = static_cast<Boolean[]>( arBool->Clone()); 661*cdf0e10cSrcweir // Char arCharTemp[] = static_cast<Char[]>(arChar->Clone()); 662*cdf0e10cSrcweir // Byte arByteTemp[] = static_cast<Byte[]>(arByte->Clone()); 663*cdf0e10cSrcweir // Int16 arShortTemp[] = static_cast<Int16[]>(arShort->Clone()); 664*cdf0e10cSrcweir // UInt16 arUShortTemp[] = static_cast<UInt16[]>(arUShort->Clone()); 665*cdf0e10cSrcweir // Int32 arLongTemp[] = static_cast<Int32[]>(arLong->Clone()); 666*cdf0e10cSrcweir // UInt32 arULongTemp[] = static_cast<UInt32[]>(arULong->Clone()); 667*cdf0e10cSrcweir // Int64 arHyperTemp[] = static_cast<Int64[]>(arHyper->Clone()); 668*cdf0e10cSrcweir // UInt64 arUHyperTemp[] = static_cast<UInt64[]>(arUHyper->Clone()); 669*cdf0e10cSrcweir // Single arFloatTemp[] = static_cast<Single[]>(arFloat->Clone()); 670*cdf0e10cSrcweir // Double arDoubleTemp[] = static_cast<Double[]>(arDouble->Clone()); 671*cdf0e10cSrcweir // TestEnum arEnumTemp[] = static_cast<TestEnum[]>(arEnum->Clone()); 672*cdf0e10cSrcweir // String* arStringTemp[] = static_cast<String*[]>(arString->Clone()); 673*cdf0e10cSrcweir // Object* arObjectTemp = static_cast<Object*[]>(arObject->Clone()); 674*cdf0e10cSrcweir // Any arAnyTemp[] = static_cast<Any[]>(arAny->Clone()); 675*cdf0e10cSrcweir // // make sure this are has the same contents as arLong3[0] 676*cdf0e10cSrcweir // int[][] arLong2Temp = new int[][]{new int[]{1,2,3},new int[]{4,5,6}, new int[]{7,8,9} }; 677*cdf0e10cSrcweir // // make sure this are has the same contents as arLong3 678*cdf0e10cSrcweir // int[][][] arLong3Temp = new int[][][]{ 679*cdf0e10cSrcweir // new int[][]{new int[]{1,2,3},new int[]{4,5,6}, new int[]{7,8,9} }, 680*cdf0e10cSrcweir // new int [][]{new int[]{1,2,3},new int[]{4,5,6}, new int[]{7,8,9}}, 681*cdf0e10cSrcweir // new int[][]{new int[]{1,2,3},new int[]{4,5,6}, new int[]{7,8,9}}}; 682*cdf0e10cSrcweir Console::WriteLine(new String("cli_cpp_bridgetest: no test of " 683*cdf0e10cSrcweir "XBridgeTest2::setSequencesInOut and XBridgeTest2.setSequencesOut " 684*cdf0e10cSrcweir "because jagged arrays are not supported by C++ compiler")); 685*cdf0e10cSrcweir // xBT2->setSequencesInOut(& arBoolTemp, & arCharTemp, & arByteTemp, 686*cdf0e10cSrcweir // & arShortTemp, & arUShortTemp, & arLongTemp, 687*cdf0e10cSrcweir // & arULongTemp,& arHyperTemp, & arUHyperTemp, 688*cdf0e10cSrcweir // & arFloatTemp,& arDoubleTemp, & arEnumTemp, 689*cdf0e10cSrcweir // & arStringTemp, & arObjectTemp, 690*cdf0e10cSrcweir // & arAnyTemp, & arLong2Temp, & arLong3Temp); 691*cdf0e10cSrcweir // bRet = check( 692*cdf0e10cSrcweir // compareData(arBoolTemp, arBool) && 693*cdf0e10cSrcweir // compareData(arCharTemp , arChar) && 694*cdf0e10cSrcweir // compareData(arByteTemp , arByte) && 695*cdf0e10cSrcweir // compareData(arShortTemp , arShort) && 696*cdf0e10cSrcweir // compareData(arUShortTemp , arUShort) && 697*cdf0e10cSrcweir // compareData(arLongTemp , arLong) && 698*cdf0e10cSrcweir // compareData(arULongTemp , arULong) && 699*cdf0e10cSrcweir // compareData(arHyperTemp , arHyper) && 700*cdf0e10cSrcweir // compareData(arUHyperTemp , arUHyper) && 701*cdf0e10cSrcweir // compareData(arFloatTemp , arFloat) && 702*cdf0e10cSrcweir // compareData(arDoubleTemp , arDouble) && 703*cdf0e10cSrcweir // compareData(arEnumTemp , arEnum) && 704*cdf0e10cSrcweir // compareData(arStringTemp , arString) && 705*cdf0e10cSrcweir // compareData(arObjectTemp , arObject) && 706*cdf0e10cSrcweir // compareData(arAnyTemp , arAny) && 707*cdf0e10cSrcweir // compareData(arLong2Temp , arLong3[0]) && 708*cdf0e10cSrcweir // compareData(arLong3Temp , arLong3), "sequence test") && bRet; 709*cdf0e10cSrcweir 710*cdf0e10cSrcweir //Boolean arBoolOut[]; 711*cdf0e10cSrcweir //Char arCharOut[]; 712*cdf0e10cSrcweir //Byte arByteOut[]; 713*cdf0e10cSrcweir //Int16 arShortOut[]; 714*cdf0e10cSrcweir //UInt16 arUShortOut[]; 715*cdf0e10cSrcweir //Int32 arLongOut[]; 716*cdf0e10cSrcweir //UInt32 arULongOut[]; 717*cdf0e10cSrcweir //Int64 arHyperOut[]; 718*cdf0e10cSrcweir //UInt64 arUHyperOut[]; 719*cdf0e10cSrcweir //Single arFloatOut[]; 720*cdf0e10cSrcweir //Double arDoubleOut[]; 721*cdf0e10cSrcweir //TestEnum arEnumOut[]; 722*cdf0e10cSrcweir //String* arStringOut[]; 723*cdf0e10cSrcweir //Object* arObjectOut[]; 724*cdf0e10cSrcweir //Any arAnyOut[]; 725*cdf0e10cSrcweir // int[][] arLong2Out; 726*cdf0e10cSrcweir // int[][][] arLong3Out; 727*cdf0e10cSrcweir 728*cdf0e10cSrcweir // xBT2->setSequencesOut(out arBoolOut, out arCharOut, out arByteOut, 729*cdf0e10cSrcweir // out arShortOut, out arUShortOut, out arLongOut, 730*cdf0e10cSrcweir // out arULongOut, out arHyperOut, out arUHyperOut, 731*cdf0e10cSrcweir // out arFloatOut, out arDoubleOut, out arEnumOut, 732*cdf0e10cSrcweir // out arStringOut, out arObjectOut, out arAnyOut, 733*cdf0e10cSrcweir // out arLong2Out, out arLong3Out); 734*cdf0e10cSrcweir // bRet = check( 735*cdf0e10cSrcweir // compareData(arBoolOut, arBool) && 736*cdf0e10cSrcweir // compareData(arCharOut, arChar) && 737*cdf0e10cSrcweir // compareData(arByteOut, arByte) && 738*cdf0e10cSrcweir // compareData(arShortOut, arShort) && 739*cdf0e10cSrcweir // compareData(arUShortOut, arUShort) && 740*cdf0e10cSrcweir // compareData(arLongOut, arLong) && 741*cdf0e10cSrcweir // compareData(arULongOut, arULong) && 742*cdf0e10cSrcweir // compareData(arHyperOut, arHyper) && 743*cdf0e10cSrcweir // compareData(arUHyperOut, arUHyper) && 744*cdf0e10cSrcweir // compareData(arFloatOut, arFloat) && 745*cdf0e10cSrcweir // compareData(arDoubleOut, arDouble) && 746*cdf0e10cSrcweir // compareData(arEnumOut, arEnum) && 747*cdf0e10cSrcweir // compareData(arStringOut, arString) && 748*cdf0e10cSrcweir // compareData(arObjectOut, arObject) && 749*cdf0e10cSrcweir // compareData(arAnyOut, arAny) && 750*cdf0e10cSrcweir // compareData(arLong2Out, arLong3[0]) && 751*cdf0e10cSrcweir // compareData(arLong3Out, arLong3), "sequence test") && bRet; 752*cdf0e10cSrcweir } 753*cdf0e10cSrcweir { 754*cdf0e10cSrcweir //test with empty sequences 755*cdf0e10cSrcweir // int[][] _arLong2 = new int[0][]; 756*cdf0e10cSrcweir // int[][] seqSeqRet = xBT2->setDim2(_arLong2); 757*cdf0e10cSrcweir // bRet = check( compareData(seqSeqRet, _arLong2), "sequence test") && bRet; 758*cdf0e10cSrcweir // int[][][] _arLong3 = new int[0][][]; 759*cdf0e10cSrcweir // int[][][] seqSeqRet2 = xBT2->setDim3(_arLong3); 760*cdf0e10cSrcweir // bRet = check( compareData(seqSeqRet2, _arLong3), "sequence test") && bRet; 761*cdf0e10cSrcweir Any _arAny[] = new Any[0]; 762*cdf0e10cSrcweir Any seqAnyRet[] = xBT2->setSequenceAny(_arAny); 763*cdf0e10cSrcweir bRet = check( compareData(seqAnyRet, _arAny), "sequence test") && bRet; 764*cdf0e10cSrcweir Boolean _arBool[] = new Boolean[0]; 765*cdf0e10cSrcweir Boolean seqBoolRet[] = xBT2->setSequenceBool(_arBool); 766*cdf0e10cSrcweir bRet = check( compareData(seqBoolRet, _arBool), "sequence test") && bRet; 767*cdf0e10cSrcweir Byte _arByte[] = new Byte[0]; 768*cdf0e10cSrcweir Byte seqByteRet[] = xBT2->setSequenceByte(_arByte); 769*cdf0e10cSrcweir bRet = check( compareData(seqByteRet, _arByte), "sequence test") && bRet; 770*cdf0e10cSrcweir Char _arChar[] = new Char[0]; 771*cdf0e10cSrcweir Char seqCharRet[] = xBT2->setSequenceChar(_arChar); 772*cdf0e10cSrcweir bRet = check( compareData(seqCharRet, _arChar), "sequence test") && bRet; 773*cdf0e10cSrcweir Int16 _arShort[] = new Int16[0]; 774*cdf0e10cSrcweir Int16 seqShortRet[] = xBT2->setSequenceShort(_arShort); 775*cdf0e10cSrcweir bRet = check( compareData(seqShortRet, _arShort), "sequence test") && bRet; 776*cdf0e10cSrcweir Int32 _arLong[] = new Int32[0]; 777*cdf0e10cSrcweir Int32 seqLongRet[] = xBT2->setSequenceLong(_arLong); 778*cdf0e10cSrcweir bRet = check( compareData(seqLongRet, _arLong), "sequence test") && bRet; 779*cdf0e10cSrcweir Int64 _arHyper[] = new Int64[0]; 780*cdf0e10cSrcweir Int64 seqHyperRet[] = xBT2->setSequenceHyper(_arHyper); 781*cdf0e10cSrcweir bRet = check( compareData(seqHyperRet, _arHyper), "sequence test") && bRet; 782*cdf0e10cSrcweir Single _arFloat[] = new Single[0]; 783*cdf0e10cSrcweir Single seqFloatRet[] = xBT2->setSequenceFloat(_arFloat); 784*cdf0e10cSrcweir bRet = check( compareData(seqFloatRet, _arFloat), "sequence test") && bRet; 785*cdf0e10cSrcweir Double _arDouble[] = new Double[0]; 786*cdf0e10cSrcweir Double seqDoubleRet[] = xBT2->setSequenceDouble(_arDouble); 787*cdf0e10cSrcweir bRet = check( compareData(seqDoubleRet, _arDouble), "sequence test") && bRet; 788*cdf0e10cSrcweir TestEnum _arEnum[] = new TestEnum[0]; 789*cdf0e10cSrcweir xBT2->setSequenceEnum(_arEnum); 790*cdf0e10cSrcweir // compiler bug: _arEnum has type System.Enum and not TestEnum 791*cdf0e10cSrcweir // bRet = check( compareData(seqEnumRet, _arEnum), "sequence test") && bRet; 792*cdf0e10cSrcweir UInt16 _arUShort[] = new UInt16[0]; 793*cdf0e10cSrcweir UInt16 seqUShortRet[] = xBT2->setSequenceUShort(_arUShort); 794*cdf0e10cSrcweir bRet = check( compareData(seqUShortRet, _arUShort), "sequence test") && bRet; 795*cdf0e10cSrcweir UInt32 _arULong[] = new UInt32[0]; 796*cdf0e10cSrcweir UInt32 seqULongRet[] = xBT2->setSequenceULong(_arULong); 797*cdf0e10cSrcweir bRet = check( compareData(seqULongRet, _arULong), "sequence test") && bRet; 798*cdf0e10cSrcweir UInt64 _arUHyper[] = new UInt64[0]; 799*cdf0e10cSrcweir UInt64 seqUHyperRet[] = xBT2->setSequenceUHyper(_arUHyper); 800*cdf0e10cSrcweir bRet = check( compareData(seqUHyperRet, _arUHyper), "sequence test") && bRet; 801*cdf0e10cSrcweir Object* _arObject[] = new Object*[0]; 802*cdf0e10cSrcweir Object* seqObjectRet[] = xBT2->setSequenceXInterface(_arObject); 803*cdf0e10cSrcweir bRet = check( compareData(seqObjectRet, _arObject), "sequence test") && bRet; 804*cdf0e10cSrcweir String* _arString[] = new String*[0]; 805*cdf0e10cSrcweir String* seqStringRet[] = xBT2->setSequenceString(_arString); 806*cdf0e10cSrcweir bRet = check( compareData(seqStringRet, _arString), "sequence test") && bRet; 807*cdf0e10cSrcweir TestElement* _arStruct[] = new TestElement*[0]; 808*cdf0e10cSrcweir TestElement* seqStructRet[] = xBT2->setSequenceStruct(_arStruct); 809*cdf0e10cSrcweir bRet = check( compareData(seqStructRet, _arStruct), "sequence test") && bRet; 810*cdf0e10cSrcweir 811*cdf0e10cSrcweir } 812*cdf0e10cSrcweir return bRet; 813*cdf0e10cSrcweir } 814*cdf0e10cSrcweir /** Test the System::Object method on the proxy object 815*cdf0e10cSrcweir */ 816*cdf0e10cSrcweir static bool testObjectMethodsImplemention(XBridgeTest* xLBT) 817*cdf0e10cSrcweir { 818*cdf0e10cSrcweir bool ret = false; 819*cdf0e10cSrcweir Object* obj = new Object(); 820*cdf0e10cSrcweir XBridgeTestBase* xBase = dynamic_cast<XBridgeTestBase*>(xLBT); 821*cdf0e10cSrcweir if (xBase == 0) 822*cdf0e10cSrcweir return false; 823*cdf0e10cSrcweir // Object.Equals 824*cdf0e10cSrcweir ret = xLBT->Equals(obj) == false; 825*cdf0e10cSrcweir ret = xLBT->Equals(xLBT) && ret; 826*cdf0e10cSrcweir ret = Object::Equals(obj, obj) && ret; 827*cdf0e10cSrcweir ret = Object::Equals(xLBT, xBase) && ret; 828*cdf0e10cSrcweir //Object.GetHashCode 829*cdf0e10cSrcweir // Don't know how to verify this. Currently it is not possible to get the object id from a proxy 830*cdf0e10cSrcweir int nHash = xLBT->GetHashCode(); 831*cdf0e10cSrcweir ret = nHash == xBase->GetHashCode() && ret; 832*cdf0e10cSrcweir 833*cdf0e10cSrcweir //Object.ToString 834*cdf0e10cSrcweir // Don't know how to verify this automatically. 835*cdf0e10cSrcweir String* s = xLBT->ToString(); 836*cdf0e10cSrcweir ret = (s->Length > 0) && ret; 837*cdf0e10cSrcweir return ret; 838*cdf0e10cSrcweir } 839*cdf0e10cSrcweir 840*cdf0e10cSrcweir 841*cdf0e10cSrcweir static bool raiseOnewayException(XBridgeTest* xLBT) 842*cdf0e10cSrcweir { 843*cdf0e10cSrcweir bool bReturn = true; 844*cdf0e10cSrcweir String* sCompare = Constants::STRING_TEST_CONSTANT; 845*cdf0e10cSrcweir try 846*cdf0e10cSrcweir { 847*cdf0e10cSrcweir // Note : the exception may fly or not (e.g. remote scenario). 848*cdf0e10cSrcweir // When it flies, it must contain the correct elements. 849*cdf0e10cSrcweir xLBT->raiseRuntimeExceptionOneway(sCompare, xLBT->Interface ); 850*cdf0e10cSrcweir } 851*cdf0e10cSrcweir catch (RuntimeException* e ) 852*cdf0e10cSrcweir { 853*cdf0e10cSrcweir bReturn = ( xLBT->Interface == e->Context ); 854*cdf0e10cSrcweir } 855*cdf0e10cSrcweir return bReturn; 856*cdf0e10cSrcweir } 857*cdf0e10cSrcweir 858*cdf0e10cSrcweir // //================================================================================================== 859*cdf0e10cSrcweir static bool raiseException(XBridgeTest* xLBT ) 860*cdf0e10cSrcweir { 861*cdf0e10cSrcweir int nCount = 0; 862*cdf0e10cSrcweir try 863*cdf0e10cSrcweir { 864*cdf0e10cSrcweir try 865*cdf0e10cSrcweir { 866*cdf0e10cSrcweir try 867*cdf0e10cSrcweir { 868*cdf0e10cSrcweir xLBT->raiseException( 869*cdf0e10cSrcweir 5, Constants::STRING_TEST_CONSTANT, xLBT->Interface ); 870*cdf0e10cSrcweir } 871*cdf0e10cSrcweir catch (unoidl::com::sun::star::lang::IllegalArgumentException* aExc) 872*cdf0e10cSrcweir { 873*cdf0e10cSrcweir if (aExc->ArgumentPosition == 5 && 874*cdf0e10cSrcweir aExc->Context == xLBT->Interface) 875*cdf0e10cSrcweir { 876*cdf0e10cSrcweir ++nCount; 877*cdf0e10cSrcweir } 878*cdf0e10cSrcweir else 879*cdf0e10cSrcweir { 880*cdf0e10cSrcweir check( false, "### unexpected exception content!" ); 881*cdf0e10cSrcweir } 882*cdf0e10cSrcweir 883*cdf0e10cSrcweir /** it is certain, that the RuntimeException testing will fail, 884*cdf0e10cSrcweir if no */ 885*cdf0e10cSrcweir xLBT->RuntimeException = 0; 886*cdf0e10cSrcweir } 887*cdf0e10cSrcweir } 888*cdf0e10cSrcweir catch (unoidl::com::sun::star::uno::RuntimeException* rExc) 889*cdf0e10cSrcweir { 890*cdf0e10cSrcweir if (rExc->Context == xLBT->Interface ) 891*cdf0e10cSrcweir { 892*cdf0e10cSrcweir ++nCount; 893*cdf0e10cSrcweir } 894*cdf0e10cSrcweir else 895*cdf0e10cSrcweir { 896*cdf0e10cSrcweir check( false, "### unexpected exception content!" ); 897*cdf0e10cSrcweir } 898*cdf0e10cSrcweir 899*cdf0e10cSrcweir /** it is certain, that the RuntimeException testing will fail, if no */ 900*cdf0e10cSrcweir xLBT->RuntimeException = (int) 0xcafebabe; 901*cdf0e10cSrcweir } 902*cdf0e10cSrcweir } 903*cdf0e10cSrcweir catch (unoidl::com::sun::star::uno::Exception* rExc) 904*cdf0e10cSrcweir { 905*cdf0e10cSrcweir if (rExc->Context == xLBT->Interface) 906*cdf0e10cSrcweir { 907*cdf0e10cSrcweir ++nCount; 908*cdf0e10cSrcweir } 909*cdf0e10cSrcweir else 910*cdf0e10cSrcweir 911*cdf0e10cSrcweir { 912*cdf0e10cSrcweir check( false, "### unexpected exception content!" ); 913*cdf0e10cSrcweir } 914*cdf0e10cSrcweir return (nCount == 3); 915*cdf0e10cSrcweir } 916*cdf0e10cSrcweir return false; 917*cdf0e10cSrcweir } 918*cdf0e10cSrcweir 919*cdf0e10cSrcweir static private void perform_test( XBridgeTest* xLBT ) 920*cdf0e10cSrcweir { 921*cdf0e10cSrcweir bool bRet= true;; 922*cdf0e10cSrcweir bRet = check( performTest( xLBT ), "standard test" ) && bRet; 923*cdf0e10cSrcweir bRet = check( raiseException( xLBT ) , "exception test" )&& bRet; 924*cdf0e10cSrcweir bRet = check( raiseOnewayException( xLBT ), "oneway exception test" ) && bRet; 925*cdf0e10cSrcweir bRet = check( testObjectMethodsImplemention(xLBT), "object methods test") && bRet; 926*cdf0e10cSrcweir bRet = performQueryForUnknownType( xLBT ) && bRet; 927*cdf0e10cSrcweir if (! bRet) 928*cdf0e10cSrcweir { 929*cdf0e10cSrcweir throw new unoidl::com::sun::star::uno::RuntimeException( 930*cdf0e10cSrcweir new String("error: test failed!"), 0); 931*cdf0e10cSrcweir } 932*cdf0e10cSrcweir } 933*cdf0e10cSrcweir XComponentContext* m_xContext; 934*cdf0e10cSrcweir 935*cdf0e10cSrcweir public: 936*cdf0e10cSrcweir BridgeTest( XComponentContext* xContext ) 937*cdf0e10cSrcweir { 938*cdf0e10cSrcweir m_xContext = xContext; 939*cdf0e10cSrcweir } 940*cdf0e10cSrcweir 941*cdf0e10cSrcweir 942*cdf0e10cSrcweir 943*cdf0e10cSrcweir int run( String* args[] ) 944*cdf0e10cSrcweir { 945*cdf0e10cSrcweir try 946*cdf0e10cSrcweir { 947*cdf0e10cSrcweir if (args->Length < 1) 948*cdf0e10cSrcweir { 949*cdf0e10cSrcweir throw new RuntimeException( 950*cdf0e10cSrcweir "missing argument for bridgetest!", this ); 951*cdf0e10cSrcweir } 952*cdf0e10cSrcweir Object* test_obj = 953*cdf0e10cSrcweir m_xContext->getServiceManager()->createInstanceWithContext( 954*cdf0e10cSrcweir args[ 0 ], m_xContext ); 955*cdf0e10cSrcweir if (test_obj == 0) 956*cdf0e10cSrcweir test_obj = m_xContext->getValueByName( args[ 0 ] ).Value; 957*cdf0e10cSrcweir 958*cdf0e10cSrcweir Console::WriteLine( 959*cdf0e10cSrcweir "cli target bridgetest obj: {0}", test_obj->ToString() ); 960*cdf0e10cSrcweir XBridgeTest* xTest = __try_cast<XBridgeTest*>(test_obj) ; 961*cdf0e10cSrcweir perform_test( xTest ); 962*cdf0e10cSrcweir Console::WriteLine( "\n### cli_uno C++ bridgetest succeeded." ); 963*cdf0e10cSrcweir return 0; 964*cdf0e10cSrcweir } 965*cdf0e10cSrcweir catch (unoidl::com::sun::star::uno::RuntimeException* ) 966*cdf0e10cSrcweir { 967*cdf0e10cSrcweir throw; 968*cdf0e10cSrcweir } 969*cdf0e10cSrcweir catch (System::Exception* exc) 970*cdf0e10cSrcweir { 971*cdf0e10cSrcweir System::Text::StringBuilder* s = new System::Text::StringBuilder(); 972*cdf0e10cSrcweir s->Append(S"cli_cpp_bridgetest: unexpected exception occured in XMain::run. Original exception: "); 973*cdf0e10cSrcweir s->Append(exc->GetType()->Name); 974*cdf0e10cSrcweir s->Append(S"\n Message: "); 975*cdf0e10cSrcweir s->Append(exc->Message); 976*cdf0e10cSrcweir throw new unoidl::com::sun::star::uno::RuntimeException( 977*cdf0e10cSrcweir s->ToString(), 0); 978*cdf0e10cSrcweir } 979*cdf0e10cSrcweir } 980*cdf0e10cSrcweir }; 981*cdf0e10cSrcweir 982*cdf0e10cSrcweir } 983