merged tag ooo/OOO330_m14
[LibreOffice.git] / extensions / test / ole / callUnoToJava.htm
blobfdc690d7ebfb932df0cfcfe62d7ed2e6f17a0c72
1 <HTML>
2 <HEAD>
3 <META NAME="GENERATOR" Content="Microsoft Developer Studio">
4 <META HTTP-EQUIV="Content-Type" content="text/html; charset=iso-8859-1">
5 <TITLE>Document Title</TITLE>
6 </HEAD>
7 <BODY id=theBody>
9 <script language="JScript">
10 function callOleTest( id)
12 var factory= new ActiveXObject("com.sun.star.ServiceManager");
13 var oletest= factory.createInstance("oletest.OleTest");
14 // alert(oletest);
16 switch( id)
18 case 1: // Test simple call of JScript object function from UNO
19 oletest.testInterface( new XCallback_Impl, 1);
20 break;
22 case 2:
23 // return value is the parameter object
24 oletest.testInterface( new XCallback_Impl, 2);
25 break;
26 //##################################################
27 // OUT parameter
28 //##################################################
29 case 3: // Test out parameter of type interface
30 oletest.testInterface( new XCallback_Impl, 3);
31 break;
32 case 4: // Test out parameter of type struct
33 oletest.testInterface( new XCallback_Impl, 4);
34 break;
35 case 5: // Test out parameter of type enum
36 oletest.testInterface( new XCallback_Impl, 5);
37 break;
38 case 6: // Test out parameter of type sequence<any>
39 oletest.testInterface( new XCallback_Impl, 6);
40 break;
41 case 7: // Test out parameter of type any
42 oletest.testInterface( new XCallback_Impl, 7);
43 break;
44 case 8: // Test out parameter of type bool
45 oletest.testInterface( new XCallback_Impl, 8);
46 break;
47 case 9: // Test out parameter of type char
48 oletest.testInterface( new XCallback_Impl, 9);
49 break;
50 case 10: // Test out parameter of type string
51 oletest.testInterface( new XCallback_Impl, 10);
52 break;
53 case 11: // Test out parameter of type float
54 oletest.testInterface( new XCallback_Impl, 11);
55 break;
56 case 12: // Test out parameter of type double
57 oletest.testInterface( new XCallback_Impl, 12);
58 break;
59 case 13: // Test out parameter of type byte
60 oletest.testInterface( new XCallback_Impl, 13);
61 break;
62 case 14: // Test out parameter of type short
63 oletest.testInterface( new XCallback_Impl, 14);
64 break;
65 case 15: // Test out parameter of type long
66 oletest.testInterface( new XCallback_Impl, 15);
67 break;
68 case 30: // outValuesMixed
69 oletest.testInterface( new XCallback_Impl, 30);
70 break;
71 case 31: // outValuesAll
72 oletest.testInterface( new XCallback_Impl, 31);
73 break;
74 //##################################################
75 // IN/OUT parameter
76 //##################################################
78 case 100: // inoutInterface
79 oletest.testInterface( new XCallback_Impl, 100);
80 break;
81 case 101: // inoutStruct
82 oletest.testInterface( new XCallback_Impl, 101);
83 break;
84 case 102: // inoutEnum
85 oletest.testInterface( new XCallback_Impl, 102);
86 break;
87 case 103: // inoutSeqAny
88 oletest.testInterface( new XCallback_Impl, 103);
89 break;
90 case 104: // inoutAny
91 oletest.testInterface( new XCallback_Impl, 104);
92 break;
93 case 105: // inoutBool
94 oletest.testInterface( new XCallback_Impl, 105);
95 break;
96 case 106: // inoutChar
97 oletest.testInterface( new XCallback_Impl, 106);
98 break;
99 case 107: // inoutString
100 oletest.testInterface( new XCallback_Impl, 107);
101 break;
102 case 108: // inoutFloat
103 oletest.testInterface( new XCallback_Impl, 108);
104 break;
105 case 109: // inoutDouble
106 oletest.testInterface( new XCallback_Impl, 109);
107 break;
108 case 110: // inoutByte
109 oletest.testInterface( new XCallback_Impl, 110);
110 break;
111 case 111: // inoutShort
112 oletest.testInterface( new XCallback_Impl, 111);
113 break;
114 case 112: // inoutLong
115 oletest.testInterface( new XCallback_Impl, 112);
116 break;
117 case 120: // inoutValuesAll
118 oletest.testInterface( new XCallback_Impl, 120);
119 break;
120 case 200: // inValues
121 oletest.testInterface( new XCallback_Impl, 200);
122 break;
124 // Call a COM object that has not been passed as parameter to a UNO component and
125 // hence no type information are available in the COM wrapper
126 // case 300:
127 //##################################################
128 // Attributes
129 //##################################################
130 case 400:
131 oletest.testInterface( new XCallback_Impl, 400);
132 break;
134 case 1000:
135 oletest.testInterface2(new MultiInterface(), 0);
136 break;
143 // The class --------------------------------------------
145 function XCallback_Impl()
148 // XCallback
149 this._environment= "JScript";
151 this.func1= XCallback_Impl_func1;
152 this.returnInterface= XCallback_Impl_returnInterface;
153 // #################################################
154 // OUT parameter
155 //###################################################
156 this.outInterface= XCallback_Impl_outInterface;
157 this.outStruct= XCallback_Impl_outStruct;
158 this.outEnum= XCallback_Impl_outEnum;
159 this.outSeqAny= XCallback_Impl_outSeqAny;
160 this.outAny= XCallback_Impl_outAny;
161 this.outBool= XCallback_Impl_outBool;
162 this.outChar= XCallback_Impl_outChar;
163 this.outString= XCallback_Impl_outString;
164 this.outFloat= XCallback_Impl_outFloat;
165 this.outDouble= XCallback_Impl_outDouble;
166 this.outByte= XCallback_Impl_outByte;
167 this.outShort= XCallback_Impl_outShort;
168 this.outLong= XCallback_Impl_outLong;
169 this.outValuesMixed= XCallback_Impl_outValuesMixed;
170 this.outValuesAll= XCallback_Impl_outValuesAll;
171 // #################################################
172 // IN/ OUT parameter
173 //###################################################
174 this.inoutInterface= XCallback_Impl_inoutInterface;
175 this.inoutStruct= XCallback_Impl_inoutStruct;
176 this.inoutEnum= XCallback_Impl_inoutEnum;
177 this.inoutSeqAny= XCallback_Impl_inoutSeqAny;
178 this.inoutAny= XCallback_Impl_inoutAny;
179 this.inoutBool= XCallback_Impl_inoutBool;
180 this.inoutChar= XCallback_Impl_inoutChar;
181 this.inoutString= XCallback_Impl_inoutString;
182 this.inoutFloat= XCallback_Impl_inoutFloat;
183 this.inoutDouble= XCallback_Impl_inoutDouble;
184 this.inoutByte= XCallback_Impl_inoutByte;
185 this.inoutShort= XCallback_Impl_inoutShort;
186 this.inoutLong= XCallback_Impl_inoutLong;
187 this.inoutValuesAll= XCallback_Impl_inoutValuesAll;
188 // #################################################
189 // IN parameter
190 //##################################################
191 this.inValues= XCallback_Impl_inValues;
193 // #################################################
194 // Attributes
195 //##################################################
196 this.simple= new XSimple_Impl();
202 function XCallback_Impl_func1()
204 alert("XCallback_Impl_func1");
206 function XCallback_Impl_returnInterface()
208 alert("XCallback::returnInterface called");
209 return new XSimple_Impl();
212 function XCallback_Impl_outInterface( outVal)
214 outVal[0]= new XSimple_Impl();
217 function XCallback_Impl_outLong( outVal)
219 alert("outLong");
221 function XCallback_Impl_outStruct( outVal)
223 var factory= new ActiveXObject("com.sun.star.ServiceManager");
224 var starCoreReflection = factory.createInstance("com.sun.star.reflection.CoreReflection");
225 var structClass = starCoreReflection.forName("oletest.SimpleStruct");
226 var outParam= new Array();
227 structClass.createObject(outParam);
228 var aStruct= outParam[0];
229 aStruct.message= "a Struct created in JScript";
230 outVal[0]= aStruct;
233 function XCallback_Impl_outEnum( outVal)
235 outVal[0]= 2;
237 function XCallback_Impl_outSeqAny( outVal)
239 var ar= new Array(1,2,3);
240 outVal[0]= ar;
242 function XCallback_Impl_outAny( outVal)
244 outVal[0]= "this is an Any";
246 function XCallback_Impl_outBool( outVal)
248 outVal[0]= true;
250 function XCallback_Impl_outChar( outVal)
252 outVal[0]= "a";
254 function XCallback_Impl_outString( outVal)
256 outVal[0]= "This string was created in JScript";
258 function XCallback_Impl_outFloat( outVal)
260 outVal[0]= 3.14;
262 function XCallback_Impl_outDouble( outVal)
264 outVal[0]= 3.145;
266 function XCallback_Impl_outByte( outVal)
268 outVal[0]= 100;
270 function XCallback_Impl_outShort( outVal)
272 outVal[0]= 1000;
274 function XCallback_Impl_outLong( outVal)
276 outVal[0]= 1000000;
278 function XCallback_Impl_outValuesMixed( inLong, outLong, inString)
280 alert("inVal long: " + inLong +" inString:" + inString);
281 outLong[0]= inLong + 1;
283 function XCallback_Impl_outValuesAll( xSimple, aSimpleStruct, aSimpleEnum, seqAny, aAny, aBool,
284 aChar, aString, aFloat, aDouble, aByte, aShort, aLong)
286 this.outInterface( xSimple);
287 this.outStruct( aSimpleStruct);
288 this.outEnum( aSimpleEnum);
289 this.outSeqAny( seqAny);
290 this.outAny( aAny);
291 this.outBool( aBool);
292 this.outChar( aChar);
293 this.outString( aString);
294 this.outFloat( aFloat);
295 this.outDouble( aDouble);
296 this.outByte( aByte);
297 this.outShort( aShort);
298 this.outLong( aLong);
301 function XCallback_Impl_inoutInterface( val)
303 val[0].func("calling on in parameter");
304 val[0]= new XSimple_Impl();
306 function XCallback_Impl_inoutStruct( val)
308 alert( val[0].message);
309 val[0].message= "property message changed in JScript";
311 function XCallback_Impl_inoutEnum(val)
313 alert("enum value +" + val);
314 val[0]= 2;
316 function XCallback_Impl_inoutSeqAny( val)
318 var vbar = new VBArray(val[0]);
319 var seq= vbar.toArray();
320 alert( seq[0] +" "+seq[1] +" " +seq[2]);
321 val[0]= new Array("jscript1", "jscript2","jscript3");
323 function XCallback_Impl_inoutAny(val)
325 alert( "JScript in any: " + val[0]);
326 val[0]= "a string from JScript";
328 function XCallback_Impl_inoutBool(val)
330 alert( "JScript in bool: " + val[0]);
331 val[0]= true;
333 function XCallback_Impl_inoutChar(val)
335 alert( "JScript in char: " + val[0]);
336 val[0]= 'b';
338 function XCallback_Impl_inoutString(val)
340 alert( "JScript in string: " + val[0]);
341 val[0]= " a JScript string";
343 function XCallback_Impl_inoutFloat(val)
345 alert( "JScript in float: " + val[0]);
346 val[0]= 4.14;
348 function XCallback_Impl_inoutDouble(val)
350 alert( "JScript in double: " + val[0]);
351 val[0]= 4.145;
354 function XCallback_Impl_inoutByte(val)
356 alert( "JScript in byte: " + val[0]);
357 val[0]= 100;
359 function XCallback_Impl_inoutShort(val)
361 alert( "JScript in short: " + val[0]);
362 val[0]= 1000;
364 function XCallback_Impl_inoutLong(val)
366 alert( "JScript in long: " + val[0]);
367 val[0]= 100000;
369 function XCallback_Impl_inoutValuesAll(aXSimple, aStruct, aEnum, aSeq,
370 aAny, aBool, aChar, aString, aFloat, aDouble,
371 aByte, aShort, aLong )
373 this.inoutInterface( aXSimple);
374 this.inoutStruct( aStruct);
375 this.inoutEnum( aEnum);
376 this.inoutSeqAny( aSeq);
377 this.inoutAny( aAny);
378 this.inoutBool( aBool);
379 this.inoutChar( aChar);
380 this.inoutString( aString);
381 this.inoutFloat( aFloat);
382 this.inoutDouble( aDouble);
383 this.inoutByte( aByte);
384 this.inoutShort( aShort);
385 this.inoutLong( aLong);
388 function XCallback_Impl_inValues( aChar, aLong, aString)
390 alert( "char : " + aChar + " long: " + aLong + " string: " + aString);
394 //################################################################
395 // class MultiInterface implements XSimple, XSimple2, XSimple3
396 //################################################################
397 function MultiInterface()
399 this._environment= "JScript";
400 this._implementedInterfaces= new Array( "oletest.XSimple", "oletest.XSimple2", "oletest.XSimple3");
401 // XSimple ---------------
402 this.getName= MultiInterface_getName;
403 this.func= MultiInterface_func;
404 this.func2= MultiInterface_func2;
405 this.func3= MultiInterface_func3;
406 // XSimple2
407 this.getName2= MultiInterface_getName2;
408 // XSimple3
409 this.getName3= MultiInterface_getName3;
413 function MultiInterface_getName()
415 return "JScript XSimple called";
417 function MultiInterface_func( message)
419 alert("JScript object (XSimple)-- " + message);
422 function MultiInterface_getName2()
424 return "JScript XSimple2 called";
426 function MultiInterface_func2( message)
428 alert("JScript object (XSimple2) -- " + message);
431 function MultiInterface_getName3()
433 return "JScript XSimple3 called";
435 function MultiInterface_func3( message)
437 alert("JScript object (XSimple3) -- " + message);
443 //XCallback_Impl_outValuesMixed( val1, outval, val2)
446 //XCallback_Impl_outValuesAll( xSimple, aSimpleStruct, aSimpleEnum, seqAny, aAny, aBool,
447 // aChar, aString, aFloat, aDouble, aByte, aShort, aLong, aUShort, aULong)
454 // class XSimple_Impl----------------------------------------------------------------------
455 function XSimple_Impl()
457 //XSimple
458 this.func= XSimple_Impl_func;
460 function XSimple_Impl_func( message)
462 alert( "XSimple called." + message);
466 </script>
470 <h2> Object in JScript</h2>
472 This test passes a XCallback to an UNO function of the UNO test control.
473 XCallback is implemented by the JScript class XCallback_Impl. The function
474 XCallback::func1 is then called from the UNO test control.
475 <br>
476 <button onclick='callOleTest( 1)'>go</Button>
477 <br>
478 On the UNO object the function testInterface is called which takes
479 a XCallback as parameter. XCallback is implemented in a JScript object.The function
480 returns a XSimple Interface. Then the UNO object calls XSimple::notify. This test shall
481 verify the correct conversion of the return value( IDispatch JScript object) to an XSimple object.<br>
482 <button onclick='callOleTest( 2)'>go</Button>
483 <br>
484 <h1> out parameter </h1>
485 The a JScript object of class XCallback_Impl is passed to the UNO OleTest Control as parameter.
486 According to the buttons the OleTest object calls a function on XCallback_Impl that has appropriate type
487 as out parameter.<br>
488 <button onclick='callOleTest( 3)'>interface</Button>
489 <button onclick='callOleTest( 4)'>struct</Button>
490 <button onclick='callOleTest( 5)'>enum</Button>
491 <button onclick='callOleTest( 6)'>sequence&lt;any&gt;</Button>
492 <button onclick='callOleTest( 7)'>any</Button>
493 <button onclick='callOleTest( 8)'>bool</Button>
494 <button onclick='callOleTest( 9)'>char</Button>
495 <button onclick='callOleTest( 10)'>string</Button>
496 <button onclick='callOleTest( 11)'>float</Button>
497 <button onclick='callOleTest( 12)'>double</Button>
498 <button onclick='callOleTest( 13)'>byte</Button>
499 <button onclick='callOleTest( 14)'>short</Button>
500 <button onclick='callOleTest( 15)'>long</Button>
501 <br>
502 Other test with out parameters <br>
503 <button onclick='callOleTest( 30)'>outValuesMixed</Button>
504 <button onclick='callOleTest( 31)'>outValuesAll</Button>
505 <h1> in out parameter </h1>
506 <button onclick='callOleTest( 100)'>interface</Button>
507 <button onclick='callOleTest( 101)'>struct</Button>
508 <button onclick='callOleTest( 102)'>enum</Button>
509 <button onclick='callOleTest( 103)'>seqence&lt;any&gt;</Button>
510 <button onclick='callOleTest( 104)'>any</Button>
511 <button onclick='callOleTest( 105)'>bool</Button>
512 <button onclick='callOleTest( 106)'>char</Button>
513 <button onclick='callOleTest( 107)'>string</Button>
514 <button onclick='callOleTest( 108)'>float</Button>
515 <button onclick='callOleTest( 109)'>double</Button>
516 <button onclick='callOleTest( 110)'>byte</Button>
517 <button onclick='callOleTest( 111)'>short</Button>
518 <button onclick='callOleTest( 112)'>long</Button>
519 <br>
520 <h1> Attributes </h1>
521 <button onclick='callOleTest( 400)'>getting XSimple</Button>
522 <br>
524 Other tests with inout parameters <br>
525 <button onclick='callOleTest( 120)'>inoutValuesAll</Button>
526 <h1>in parameters </h1>
527 <button onclick='callOleTest( 200)'>inValues</Button>
529 <h1> JScript object implements several interfaces </h1>
530 <button onclick='callOleTest( 1000)'>go</Button>
535 </body>
536 </html>