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