summaryrefslogtreecommitdiff
path: root/extensions/test/ole/callUnoToJava.htm
blob: fdc690d7ebfb932df0cfcfe62d7ed2e6f17a0c72 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
<HTML>
<HEAD>
<META NAME="GENERATOR" Content="Microsoft Developer Studio">
<META HTTP-EQUIV="Content-Type" content="text/html; charset=iso-8859-1">
<TITLE>Document Title</TITLE>
</HEAD>
<BODY id=theBody>

<script language="JScript">
function callOleTest(	 id)
{   
	var factory= new ActiveXObject("com.sun.star.ServiceManager");
	var oletest= factory.createInstance("oletest.OleTest");
//	alert(oletest);
		
	switch( id)
	{
		case 1: // Test simple call of JScript object function from UNO
		oletest.testInterface( new XCallback_Impl, 1);
		break;

		case 2:
		// return value is the parameter object
		oletest.testInterface( new XCallback_Impl, 2);
		break;
		//##################################################
		// OUT parameter
		//##################################################
		case 3: // Test out parameter of type interface
		oletest.testInterface( new XCallback_Impl, 3);
		break;
		case 4: // Test out parameter of type struct
		oletest.testInterface( new XCallback_Impl, 4);
		break;
		case 5: // Test out parameter of type enum
		oletest.testInterface( new XCallback_Impl, 5);
		break;
		case 6: // Test out parameter of type sequence<any>
		oletest.testInterface( new XCallback_Impl, 6);
		break;
		case 7: // Test out parameter of type any
		oletest.testInterface( new XCallback_Impl, 7);
		break;
		case 8: // Test out parameter of type bool
		oletest.testInterface( new XCallback_Impl, 8);
		break;
		case 9: // Test out parameter of type char
		oletest.testInterface( new XCallback_Impl, 9);
		break;
		case 10: // Test out parameter of type string
		oletest.testInterface( new XCallback_Impl, 10);
		break;
		case 11: // Test out parameter of type float
		oletest.testInterface( new XCallback_Impl, 11);
		break;
		case 12: // Test out parameter of type double
		oletest.testInterface( new XCallback_Impl, 12);
		break;
		case 13: // Test out parameter of type byte
		oletest.testInterface( new XCallback_Impl, 13);
		break;
		case 14: // Test out parameter of type short
		oletest.testInterface( new XCallback_Impl, 14);
		break;
		case 15: // Test out parameter of type long
		oletest.testInterface( new XCallback_Impl, 15);
		break;
		case 30: //  outValuesMixed
		oletest.testInterface( new XCallback_Impl, 30);
		break;
		case 31: //  outValuesAll
		oletest.testInterface( new XCallback_Impl, 31);
		break;
		//##################################################
		// IN/OUT parameter
		//##################################################

		case 100: // inoutInterface
		oletest.testInterface( new XCallback_Impl, 100);
		break;
		case 101: // inoutStruct
		oletest.testInterface( new XCallback_Impl, 101);
		break;
		case 102: // inoutEnum
		oletest.testInterface( new XCallback_Impl, 102);
		break;
		case 103: // inoutSeqAny
		oletest.testInterface( new XCallback_Impl, 103);
		break;
		case 104: // inoutAny
		oletest.testInterface( new XCallback_Impl, 104);
		break;
		case 105: // inoutBool
		oletest.testInterface( new XCallback_Impl, 105);
		break;
		case 106: // inoutChar
		oletest.testInterface( new XCallback_Impl, 106);
		break;
		case 107: // inoutString
		oletest.testInterface( new XCallback_Impl, 107);
		break;
		case 108: // inoutFloat
		oletest.testInterface( new XCallback_Impl, 108);
		break;
		case 109: // inoutDouble
		oletest.testInterface( new XCallback_Impl, 109);
		break;
		case 110: // inoutByte
		oletest.testInterface( new XCallback_Impl, 110);
		break;
		case 111: // inoutShort
		oletest.testInterface( new XCallback_Impl, 111);
		break;
		case 112: // inoutLong
		oletest.testInterface( new XCallback_Impl, 112);
		break;
		case 120: // inoutValuesAll
		oletest.testInterface( new XCallback_Impl, 120);
		break;
		case 200: // inValues
		oletest.testInterface( new XCallback_Impl, 200);
		break;

		// Call a COM object that has not been passed as parameter to a UNO component and
		// hence no type information are available in the COM wrapper
//		case 300:
		//##################################################
		// Attributes
		//##################################################
		case 400:
		oletest.testInterface( new XCallback_Impl, 400);
		break;

		case 1000:
		oletest.testInterface2(new MultiInterface(), 0);
		break;
	}

}



// The class --------------------------------------------

function XCallback_Impl()
{
	
	// XCallback
	this._environment= "JScript";

	this.func1= XCallback_Impl_func1;
	this.returnInterface= XCallback_Impl_returnInterface;
	// #################################################
	// OUT parameter
	//###################################################
	this.outInterface= XCallback_Impl_outInterface;
	this.outStruct= XCallback_Impl_outStruct;
	this.outEnum= XCallback_Impl_outEnum;
	this.outSeqAny= XCallback_Impl_outSeqAny;
	this.outAny= XCallback_Impl_outAny;
	this.outBool= XCallback_Impl_outBool;
	this.outChar= XCallback_Impl_outChar;
	this.outString= XCallback_Impl_outString;
	this.outFloat= XCallback_Impl_outFloat;
	this.outDouble= XCallback_Impl_outDouble;
	this.outByte= XCallback_Impl_outByte;
	this.outShort= XCallback_Impl_outShort;
	this.outLong= XCallback_Impl_outLong;
	this.outValuesMixed= XCallback_Impl_outValuesMixed;
	this.outValuesAll= XCallback_Impl_outValuesAll;
	// #################################################
	// IN/ OUT parameter
	//###################################################
	this.inoutInterface= XCallback_Impl_inoutInterface;
	this.inoutStruct= XCallback_Impl_inoutStruct;
	this.inoutEnum= XCallback_Impl_inoutEnum;
	this.inoutSeqAny= XCallback_Impl_inoutSeqAny;
	this.inoutAny= XCallback_Impl_inoutAny;
	this.inoutBool= XCallback_Impl_inoutBool;
	this.inoutChar= XCallback_Impl_inoutChar;
	this.inoutString= XCallback_Impl_inoutString;
	this.inoutFloat= XCallback_Impl_inoutFloat;
	this.inoutDouble= XCallback_Impl_inoutDouble;
	this.inoutByte= XCallback_Impl_inoutByte;
	this.inoutShort= XCallback_Impl_inoutShort;
	this.inoutLong= XCallback_Impl_inoutLong;
	this.inoutValuesAll= XCallback_Impl_inoutValuesAll;
	// #################################################
	// IN parameter
	//##################################################
	this.inValues= XCallback_Impl_inValues;

	// #################################################
	// Attributes
	//##################################################
	this.simple= new XSimple_Impl();


}


function XCallback_Impl_func1()
{
	alert("XCallback_Impl_func1");
}
function XCallback_Impl_returnInterface()
{
	alert("XCallback::returnInterface called");
	return new XSimple_Impl();
}

function XCallback_Impl_outInterface( outVal)
{
	outVal[0]= new XSimple_Impl();
}

function XCallback_Impl_outLong( outVal)
{
	alert("outLong");
}
function XCallback_Impl_outStruct( outVal)
{
	var factory= new ActiveXObject("com.sun.star.ServiceManager");
    var starCoreReflection = factory.createInstance("com.sun.star.reflection.CoreReflection");
    var structClass = starCoreReflection.forName("oletest.SimpleStruct");
	var outParam= new Array();
	structClass.createObject(outParam);
	var aStruct= outParam[0];
	aStruct.message= "a Struct created in JScript";
	outVal[0]= aStruct;

}
function XCallback_Impl_outEnum( outVal)
{
	outVal[0]= 2;
}
function XCallback_Impl_outSeqAny( outVal)
{
	var ar= new Array(1,2,3);
	outVal[0]= ar;
}
function XCallback_Impl_outAny( outVal)
{
	outVal[0]= "this is an Any";
}
function XCallback_Impl_outBool( outVal)
{
	outVal[0]= true;
} 
function XCallback_Impl_outChar( outVal)
{
	outVal[0]= "a";
}
function XCallback_Impl_outString( outVal)
{
	outVal[0]= "This string was created in JScript";
}
function XCallback_Impl_outFloat( outVal)
{
	outVal[0]= 3.14;
}
function XCallback_Impl_outDouble( outVal)
{
	outVal[0]= 3.145;
}
function XCallback_Impl_outByte( outVal)
{
	outVal[0]= 100;
}
function XCallback_Impl_outShort( outVal)
{
	outVal[0]= 1000;
}
function XCallback_Impl_outLong( outVal)
{
	outVal[0]= 1000000;
}
function XCallback_Impl_outValuesMixed( inLong, outLong, inString)
{
	alert("inVal long: " + inLong +" inString:" + inString);
	outLong[0]= inLong + 1;
}
function XCallback_Impl_outValuesAll( xSimple, aSimpleStruct, aSimpleEnum, seqAny, aAny, aBool,
				aChar, aString, aFloat, aDouble, aByte, aShort, aLong)
{
	this.outInterface( xSimple);
	this.outStruct( aSimpleStruct);
	this.outEnum( aSimpleEnum);
	this.outSeqAny( seqAny);
	this.outAny( aAny);
	this.outBool( aBool);
	this.outChar( aChar);
	this.outString( aString);
	this.outFloat( aFloat);
	this.outDouble( aDouble);
	this.outByte( aByte);
	this.outShort( aShort);
	this.outLong( aLong);
}

function XCallback_Impl_inoutInterface( val)
{
	val[0].func("calling on in parameter");
	val[0]= new XSimple_Impl();
}
function XCallback_Impl_inoutStruct( val)
{
	alert( val[0].message);
	val[0].message= "property message changed in JScript";
}
function XCallback_Impl_inoutEnum(val)
{
	alert("enum value +" + val);
	val[0]= 2;
}
function XCallback_Impl_inoutSeqAny( val)
{
	var vbar = new VBArray(val[0]);
	var seq= vbar.toArray();
	alert( seq[0] +" "+seq[1] +" " +seq[2]);
	val[0]= new Array("jscript1", "jscript2","jscript3");
}
function XCallback_Impl_inoutAny(val)
{
	alert( "JScript in any: " + val[0]);
	val[0]= "a string from JScript";
}
function XCallback_Impl_inoutBool(val)
{
	alert( "JScript in bool: " + val[0]);
	val[0]= true;
}
function XCallback_Impl_inoutChar(val)
{
	alert( "JScript in char: " + val[0]);
	val[0]= 'b';
}
function XCallback_Impl_inoutString(val)
{
	alert( "JScript in string: " + val[0]);
	val[0]= " a JScript string";
}
function XCallback_Impl_inoutFloat(val)
{
	alert( "JScript in float: " + val[0]);
	val[0]= 4.14;
}
function XCallback_Impl_inoutDouble(val)
{
	alert( "JScript in double: " + val[0]);
	val[0]= 4.145;
}

function XCallback_Impl_inoutByte(val)
{
	alert( "JScript in byte: " + val[0]);
	val[0]= 100;
}
function XCallback_Impl_inoutShort(val)
{
	alert( "JScript in short: " + val[0]);
	val[0]= 1000;
}
function XCallback_Impl_inoutLong(val)
{
	alert( "JScript in long: " + val[0]);
	val[0]= 100000;
}
function XCallback_Impl_inoutValuesAll(aXSimple, aStruct, aEnum, aSeq, 
			aAny, aBool, aChar, aString,  aFloat, aDouble, 
			aByte, aShort,  aLong )
{
	this.inoutInterface( aXSimple);
	this.inoutStruct( aStruct);
	this.inoutEnum( aEnum);
	this.inoutSeqAny( aSeq);
	this.inoutAny( aAny);
	this.inoutBool( aBool);
	this.inoutChar( aChar);
	this.inoutString( aString);
	this.inoutFloat( aFloat);
	this.inoutDouble( aDouble);
	this.inoutByte( aByte);
	this.inoutShort( aShort);
	this.inoutLong( aLong);
}

function XCallback_Impl_inValues( aChar, aLong, aString)
{
	alert( "char : " + aChar + " long: " + aLong + " string: " + aString);
}


//################################################################
// class MultiInterface implements XSimple, XSimple2, XSimple3
//################################################################
function MultiInterface()
{
	this._environment= "JScript";
	this._implementedInterfaces= new Array( "oletest.XSimple", "oletest.XSimple2", "oletest.XSimple3");
	// XSimple ---------------
	this.getName= MultiInterface_getName;
	this.func= MultiInterface_func;
	this.func2= MultiInterface_func2;
	this.func3= MultiInterface_func3;
	// XSimple2
	this.getName2= MultiInterface_getName2;	
	// XSimple3
	this.getName3= MultiInterface_getName3;
}


function MultiInterface_getName()
{
	return "JScript XSimple called";
}
function MultiInterface_func( message)
{
	alert("JScript object (XSimple)-- " + message);
}

function MultiInterface_getName2()
{
	return "JScript XSimple2 called";
}
function MultiInterface_func2( message)
{
	alert("JScript object (XSimple2) -- " + message);
}

function MultiInterface_getName3()
{
	return "JScript XSimple3 called";
}
function MultiInterface_func3( message)
{
	alert("JScript object (XSimple3) -- " + message);
}




//XCallback_Impl_outValuesMixed( val1, outval, val2)
//{
//}
//XCallback_Impl_outValuesAll( xSimple, aSimpleStruct, aSimpleEnum, seqAny, aAny, aBool,
//				aChar, aString, aFloat, aDouble, aByte, aShort, aLong, aUShort, aULong)
//{
//	
//}



//  class XSimple_Impl----------------------------------------------------------------------
function XSimple_Impl()
{
	//XSimple
	this.func= XSimple_Impl_func;
}	
function XSimple_Impl_func( message)
{
	alert( "XSimple called." + message);
}


</script>



<h2> Object in JScript</h2>

This test passes a XCallback to an UNO function of the UNO test control.
XCallback is implemented by the JScript class XCallback_Impl. The function
XCallback::func1 is then called from the UNO test control.
<br>
<button onclick='callOleTest( 1)'>go</Button>
<br>
On the UNO object the function testInterface is called which takes
a XCallback as parameter. XCallback is implemented in a JScript object.The function
returns a XSimple Interface. Then the UNO object calls XSimple::notify. This test shall
verify the correct conversion of the return value( IDispatch JScript object) to an XSimple object.<br>
<button onclick='callOleTest( 2)'>go</Button>
<br>
<h1> out parameter </h1>
The a JScript object of class XCallback_Impl is passed to the UNO OleTest Control as parameter. 
According to the buttons the OleTest object calls a function on XCallback_Impl that has appropriate type
as out parameter.<br>
<button onclick='callOleTest( 3)'>interface</Button>
<button onclick='callOleTest( 4)'>struct</Button>
<button onclick='callOleTest( 5)'>enum</Button>
<button onclick='callOleTest( 6)'>sequence&lt;any&gt;</Button>
<button onclick='callOleTest( 7)'>any</Button>
<button onclick='callOleTest( 8)'>bool</Button>
<button onclick='callOleTest( 9)'>char</Button>
<button onclick='callOleTest( 10)'>string</Button>
<button onclick='callOleTest( 11)'>float</Button>
<button onclick='callOleTest( 12)'>double</Button>
<button onclick='callOleTest( 13)'>byte</Button>
<button onclick='callOleTest( 14)'>short</Button>
<button onclick='callOleTest( 15)'>long</Button>
<br>
Other test with out parameters <br>
<button onclick='callOleTest( 30)'>outValuesMixed</Button>
<button onclick='callOleTest( 31)'>outValuesAll</Button>
<h1> in out parameter </h1>
<button onclick='callOleTest( 100)'>interface</Button>
<button onclick='callOleTest( 101)'>struct</Button>
<button onclick='callOleTest( 102)'>enum</Button>
<button onclick='callOleTest( 103)'>seqence&lt;any&gt;</Button>
<button onclick='callOleTest( 104)'>any</Button>
<button onclick='callOleTest( 105)'>bool</Button>
<button onclick='callOleTest( 106)'>char</Button>
<button onclick='callOleTest( 107)'>string</Button>
<button onclick='callOleTest( 108)'>float</Button>
<button onclick='callOleTest( 109)'>double</Button>
<button onclick='callOleTest( 110)'>byte</Button>
<button onclick='callOleTest( 111)'>short</Button>
<button onclick='callOleTest( 112)'>long</Button>
<br>
<h1> Attributes </h1>
<button onclick='callOleTest( 400)'>getting XSimple</Button>
<br>

Other tests with inout parameters <br>
<button onclick='callOleTest( 120)'>inoutValuesAll</Button>
<h1>in parameters </h1>
<button onclick='callOleTest( 200)'>inValues</Button>

<h1> JScript object implements several interfaces </h1>
<button onclick='callOleTest( 1000)'>go</Button>




</body>
</html>