Update with current status
[gnash.git] / testsuite / misc-ming.all / remoting.as
blobedc8ce7ab7d5f5af0b0b4a3b8482b904dce27181
1 //
2 // Build with:
3 // makeswf -n network -o remoting.swf ../Dejagnu.swf remoting.as ../actionscript.all/dejagnu_so_fini.as
4 // Run with:
5 // firefox remoting.swf
6 // Or:
7 // gnash -v remoting.swf
8 //
9 //
11 #define info _root.note
12 #define note _root.note
13 #define fail_check _root.fail
14 #define pass_check _root.pass
15 #define xfail_check _root.xfail
16 #define xpass_check _root.xpass
18 note("SWF" + OUTPUT_VERSION + " - " + System.capabilities.version + "\n");
19 rcsid="remoting.as - <bzr revno here>";
21 #include "../actionscript.all/check.as"
22 #include "../actionscript.all/utils.as"
24 endOfTest = function()
26 //note("END OF TEST");
27 check_totals(140);
28 play();
32 if ( ! _root.hasOwnProperty('url') ) {
33 url=HTTP_TESTSUITE+'/remoting.php';
36 stop();
38 printInfo = function(result) {
39 note("remote_port: " + result['remote_port']);
40 note("request_id: " + result['request_id']);
41 note("message: " + result['message']);
42 note("arg1_type: " + result['arg1_type']);
43 note("hex: " + result['hex']);
44 //trace(result['message']);
47 function ResultHandler() {
48 this.onResult = function(result) {
49 note('default onResult called with args: '+dumpObject(arguments));
51 this.onCustom = function(result) {
52 note('default onCustom called with args: '+dumpObject(arguments));
54 this.onDebugEvents = function(result) {
55 note('default onDebugEvents called with args: '+dumpObject(arguments));
57 this.onStatus = function(result) {
58 note("default onStatus called with args: "+dumpObject(arguments));
62 nc = new NetConnection;
63 nc.statuses = new Array;
64 nc.onStatus = function()
66 this.statuses.push(arguments);
67 //note('NetConnection.onStatus called with args: '+dumpObject(arguments));
71 function test1()
73 o=new ResultHandler();
74 nc.call("unconnected", o);
75 check_equals(nc.statuses.length, 0);
76 check_equals(nc.isConnected, false);
77 check_equals(nc.statuses.length, 0);
79 // NOTE: next test aim is to trigger NetConnection.Connect.Failed.
80 // The only uri which stabily triggers that is the empty uri.
81 // Using a relative uri like 'invalid' does send Failed *only*
82 // when the SWF is loaded from filesystem, but doesn't if it
83 // is loaded from http. Also, 'file:///xxx' uri doesn't send
84 // the Failed message.
85 // WARNING: pp version LNX 10,0,12,10 often chokes and either
86 // segfaults or smashes the stack on this connect.
88 nc.connect('');
89 check_equals(nc.isConnected, false);
90 check_equals(nc.statuses.length, 1);
91 lastStatusArgs = nc.statuses[nc.statuses.length-1];
92 check_equals(lastStatusArgs.length, 1);
93 check_equals(lastStatusArgs[0].level, 'error');
94 check_equals(lastStatusArgs[0].code, 'NetConnection.Connect.Failed');
96 nc.connect(null);
97 check_equals(nc.isConnected, true);
98 check_equals(nc.statuses.length, 2);
99 lastStatusArgs = nc.statuses[nc.statuses.length-1];
100 check_equals(lastStatusArgs.length, 1);
101 check_equals(lastStatusArgs[0].level, 'status');
102 check_equals(lastStatusArgs[0].code, 'NetConnection.Connect.Success');
104 nc.connect(url);
105 check_equals(nc.isConnected, false);
106 check_equals(nc.statuses.length, 3);
107 lastStatusArgs = nc.statuses[nc.statuses.length-1];
108 check_equals(lastStatusArgs.length, 1);
109 check_equals(lastStatusArgs[0].level, 'status');
110 check_equals(lastStatusArgs[0].code, 'NetConnection.Connect.Closed');
112 o=new ResultHandler();
113 ary1=[1,2,3];
114 nc.call("ary_123", o, ary1); // 31
115 o.onResult = function(res) {
116 check_equals(nc.isConnected, false);
117 //note(printInfo(res));
118 connectionPort=res.remote_port;
119 check_equals(res.request_id, '/1');
120 check_equals(res.message, 'ary_123');
121 check_equals(res.arg1_type, 'STRICT_ARRAY');
122 check_equals(res.hex, '0a:00:00:00:01:0a:00:00:00:03:00:3f:f0:00:00:00:00:00:00:00:40:00:00:00:00:00:00:00:00:40:08:00:00:00:00:00:00');
123 test2();
127 function test2()
129 o=new ResultHandler();
130 ary2=[1,2,3]; ary2.custom='custom';
131 nc.call("ary_123custom", o, ary2); // 32
132 o.onResult = function(res) {
133 //note(printInfo(res));
134 check(res.remote_port != connectionPort);
135 connectionPort = res.remote_port;
136 check_equals(res.request_id, '/2');
137 check_equals(res.message, 'ary_123custom');
138 check_equals(res.arg1_type, 'ECMA_ARRAY');
139 check_equals(res.hex, '0a:00:00:00:01:08:00:00:00:03:00:01:30:00:3f:f0:00:00:00:00:00:00:00:01:31:00:40:00:00:00:00:00:00:00:00:01:32:00:40:08:00:00:00:00:00:00:00:06:63:75:73:74:6f:6d:02:00:06:63:75:73:74:6f:6d:00:00:09');
142 o=new ResultHandler();
143 ary3=[1,2,3]; ary3.length=255;
144 nc.call("ary_123length255", o, ary3); // 33
145 o.onResult = function(res) {
146 //note(printInfo(res));
147 check_equals(res.remote_port, connectionPort);
148 check_equals(res.request_id, '/3');
149 check_equals(res.message, 'ary_123length255');
150 check_equals(res.arg1_type, 'STRICT_ARRAY');
151 check_equals(res.hex, '0a:00:00:00:01:0a:00:00:00:ff:00:3f:f0:00:00:00:00:00:00:00:40:00:00:00:00:00:00:00:00:40:08:00:00:00:00:00:00:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06');
154 o=new ResultHandler();
155 ary4=[]; ary4[3]=3;
156 nc.call("ary__3", o, ary4); // 34
157 o.onResult = function(res) {
158 //note(printInfo(res));
159 check_equals(res.remote_port, connectionPort);
160 check_equals(res.request_id, '/4');
161 check_equals(res.message, 'ary__3');
162 check_equals(res.arg1_type, 'STRICT_ARRAY');
163 check_equals(res.hex, '0a:00:00:00:01:0a:00:00:00:04:06:06:06:00:40:08:00:00:00:00:00:00');
164 test5();
167 o=new ResultHandler();
168 ary5=[]; ary5['3']=3;
169 nc.call("ary_s3", o, ary5); // 35
170 o.onResult = function(res) {
171 //note(printInfo(res));
172 check_equals(res.remote_port, connectionPort);
173 check_equals(res.request_id, '/5');
174 check_equals(res.message, 'ary_s3');
175 check_equals(res.arg1_type, 'STRICT_ARRAY');
176 check_equals(res.hex, '0a:00:00:00:01:0a:00:00:00:04:06:06:06:00:40:08:00:00:00:00:00:00');
177 test6();
180 o=new ResultHandler();
181 ary6=['0','0','0'];
182 ary6.custom='custom'; ASSetPropFlags(ary6, 'custom', 1); // hide from enumeration
183 nc.call("ary_000_assetpropflags", o, ary6); // 36
184 o.onResult = function(res) {
185 //note(printInfo(res));
186 check_equals(res.remote_port, connectionPort);
187 check_equals(res.request_id, '/6');
188 check_equals(res.message, 'ary_000_assetpropflags');
189 check_equals(res.arg1_type, 'STRICT_ARRAY');
190 check_equals(res.hex, '0a:00:00:00:01:0a:00:00:00:03:02:00:01:30:02:00:01:30:02:00:01:30');
191 test7();
195 function test7()
197 o=new ResultHandler();
198 ary7=[]; ary7['2.5']=1;
199 nc.call("ary_float", o, ary7); // 37
200 o.onResult = function(res) {
201 //note(printInfo(res));
202 check(res.remote_port != connectionPort);
203 connectionPort = res.remote_port;
204 check_equals(res.request_id, '/7');
205 check_equals(res.message, 'ary_float');
206 check_equals(res.arg1_type, 'ECMA_ARRAY');
207 #if OUTPUT_VERSION > 6
208 check_equals(res.hex, '0a:00:00:00:01:08:00:00:00:00:00:03:32:2e:35:00:3f:f0:00:00:00:00:00:00:00:00:09');
209 #else
210 // The bug here is that gnash encodes 0 as the length of the array while
211 // the expected behaviour is to encode 3 (for SWF6 or lower!)
212 check_equals(res.hex, '0a:00:00:00:01:08:00:00:00:03:00:03:32:2e:35:00:3f:f0:00:00:00:00:00:00:00:00:09');
213 #endif
216 o=new ResultHandler();
217 ary8=[]; ary8['256']=1;
218 nc.call("ary_s256", o, ary8); // 38
219 o.onResult = function(res) {
220 //note(printInfo(res));
221 check_equals(res.remote_port, connectionPort);
222 check_equals(res.request_id, '/8');
223 check_equals(res.message, 'ary_s256');
224 check_equals(res.arg1_type, 'STRICT_ARRAY');
225 check_equals(res.hex, '0a:00:00:00:01:0a:00:00:01:01:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:06:00:3f:f0:00:00:00:00:00:00');
228 o=new ResultHandler();
229 ary9=[]; ary9['-1']=1;
230 nc.call("ary_sminus1", o, ary9); // 39
231 o.onResult = function(res) {
232 //note(printInfo(res));
233 check_equals(res.remote_port, connectionPort);
234 check_equals(res.request_id, '/9');
235 check_equals(res.message, 'ary_sminus1');
236 check_equals(res.arg1_type, 'ECMA_ARRAY');
237 check_equals(res.hex, '0a:00:00:00:01:08:00:00:00:00:00:02:2d:31:00:3f:f0:00:00:00:00:00:00:00:00:09');
240 o=new ResultHandler();
241 ary10=[]; ary10[-1]=1; // ECMA
242 nc.call("ary_minus1", o, ary10);
243 o.onResult = function(res) {
244 //note(printInfo(res));
245 check_equals(res.remote_port, connectionPort);
246 check_equals(res.request_id, '/10');
247 check_equals(res.message, 'ary_minus1');
248 check_equals(res.arg1_type, 'ECMA_ARRAY');
249 check_equals(res.hex, '0a:00:00:00:01:08:00:00:00:00:00:02:2d:31:00:3f:f0:00:00:00:00:00:00:00:00:09');
250 test11();
253 o=new ResultHandler();
254 ary11=['a','b','c']; // STRICT
255 nc.call("ary_abc", o, ary11); //
256 o.onResult = function(res) {
257 //note(printInfo(res));
258 check_equals(res.remote_port, connectionPort);
259 check_equals(res.request_id, '/11');
260 check_equals(res.message, 'ary_abc');
261 check_equals(res.arg1_type, 'STRICT_ARRAY');
262 check_equals(res.hex, '0a:00:00:00:01:0a:00:00:00:03:02:00:01:61:02:00:01:62:02:00:01:63');
265 o=new ResultHandler();
266 ary12=[]; ary12['']=1;
267 nc.call("ary_emptypropname", o, ary12); //
268 o.onResult = function(res) {
269 //note(printInfo(res));
270 check_equals(res.remote_port, connectionPort);
271 check_equals(res.request_id, '/12');
272 check_equals(res.message, 'ary_emptypropname');
273 check_equals(res.arg1_type, 'STRICT_ARRAY');
274 check_equals(res.hex, '0a:00:00:00:01:0a:00:00:00:00');
277 o=new ResultHandler();
278 ary13=[]; ary13[1] = ary11;
279 nc.call("ary_nested", o, ary13); //
280 o.onResult = function(res) {
281 //note(printInfo(res));
282 check_equals(res.remote_port, connectionPort);
283 check_equals(res.request_id, '/13');
284 check_equals(res.message, 'ary_nested');
285 check_equals(res.arg1_type, 'STRICT_ARRAY');
286 check_equals(res.hex, '0a:00:00:00:01:0a:00:00:00:02:06:0a:00:00:00:03:02:00:01:61:02:00:01:62:02:00:01:63');
287 test14();
291 function test14()
293 note('Connecting again to: '+url);
294 nc.connect(url); // reconnect, should reset call id
296 check_equals(nc.isConnected, false);
297 check_equals(nc.statuses.length, 4);
298 lastStatusArgs = nc.statuses[nc.statuses.length-1];
299 check_equals(lastStatusArgs.length, 1);
300 check_equals(lastStatusArgs[0].level, 'status');
301 check_equals(lastStatusArgs[0].code, 'NetConnection.Connect.Closed');
303 o=new ResultHandler();
304 ary13=[];
305 nc.call("ary_newconnect", o, ary13); //
306 o.onResult = function(res) {
307 //note(printInfo(res));
308 check(res.remote_port != connectionPort);
309 connectionPort = res.remote_port;
310 check_equals(res.request_id, '/1'); // connection is reset
311 check_equals(res.message, 'ary_newconnect');
312 check_equals(res.arg1_type, 'STRICT_ARRAY');
313 check_equals(res.hex, '0a:00:00:00:01:0a:00:00:00:00');
316 note('Connecting again to: '+url);
317 nc.connect(url); // reconnect, should reset call id
319 check_equals(nc.isConnected, false);
320 check_equals(nc.statuses.length, 5);
321 lastStatusArgs = nc.statuses[nc.statuses.length-1];
322 check_equals(lastStatusArgs.length, 1);
323 check_equals(lastStatusArgs[0].level, 'status');
324 check_equals(lastStatusArgs[0].code, 'NetConnection.Connect.Closed');
326 o=new ResultHandler();
327 ary13=[];
328 nc.call("ary_newconnect2", o, ary13); //
329 o.onResult = function(res) {
330 //note(printInfo(res));
331 check(res.remote_port != connectionPort);
332 connectionPort = res.remote_port;
333 check_equals(res.request_id, '/1'); // connection is reset
334 check_equals(res.message, 'ary_newconnect2');
335 check_equals(res.arg1_type, 'STRICT_ARRAY');
336 check_equals(res.hex, '0a:00:00:00:01:0a:00:00:00:00');
337 onEnterFrame = test15;
341 function test15()
343 delete onEnterFrame;
345 o=new ResultHandler();
346 ary13=[];
347 nc.call("ary_newconnect", o, ary13); //
348 o.onResult = function(res) {
349 //note(printInfo(res));
351 // connection ID is NOT reset if the call happens
352 // on next frame
353 check(res.remote_port != connectionPort);
354 connectionPort = res.remote_port;
355 check_equals(res.request_id, '/2');
356 check_equals(res.message, 'ary_newconnect');
357 check_equals(res.arg1_type, 'STRICT_ARRAY');
358 check_equals(res.hex, '0a:00:00:00:01:0a:00:00:00:00');
359 test16();
363 function test16()
365 o=new ResultHandler();
366 nc.call("noarg", o); // no arguments
367 o.onResult = function(res) {
368 //note(printInfo(res));
370 // connection ID is NOT reset if the call happens
371 // on next frame
372 check(res.remote_port != connectionPort);
373 connectionPort = res.remote_port;
374 check_equals(res.request_id, '/3');
375 check_equals(res.message, 'noarg');
376 check_equals(res.arg_count, '0');
377 check_equals(res.hex, '0a:00:00:00:00');
380 o=new ResultHandler();
381 nc.call("multiarg", o, [], 'a', {b:'c',d:1}, null, undefined);
382 o.onResult = function(res) {
383 //note(printInfo(res));
385 // connection ID is NOT reset if the call happens
386 // on next frame
387 check_equals(res.remote_port, connectionPort);
388 check_equals(res.request_id, '/4');
389 check_equals(res.message, 'multiarg');
390 check_equals(res.arg_count, '5');
391 check_equals(res.hex, '0a:00:00:00:05:0a:00:00:00:00:02:00:01:61:03:00:01:64:00:3f:f0:00:00:00:00:00:00:00:01:62:02:00:01:63:00:00:09:05:06');
394 o=new ResultHandler();
395 nc.call(25.53, o);
396 o.onResult = function(res) {
397 //note(printInfo(res));
398 check_equals(res.remote_port, connectionPort);
399 check_equals(res.request_id, '/5');
400 check_equals(res.message, '25.53');
401 check_equals(res.arg_count, '0');
402 check_equals(res.hex, '0a:00:00:00:00');
405 o=new ResultHandler();
406 nc.call(true, o);
407 o.onResult = function(res) {
408 //note(printInfo(res));
409 check_equals(res.remote_port, connectionPort);
410 check_equals(res.request_id, '/6');
411 check_equals(res.message, 'true');
412 check_equals(res.arg_count, '0');
413 check_equals(res.hex, '0a:00:00:00:00');
416 o=new ResultHandler();
417 n={}; n.toString=function() { return 'toString'; };
418 nc.call(n, o);
419 o.onResult = function(res) {
420 //note(printInfo(res));
421 check_equals(res.remote_port, connectionPort);
422 check_equals(res.request_id, '/7');
423 check_equals(res.message, 'toString');
424 check_equals(res.arg_count, '0');
425 check_equals(res.hex, '0a:00:00:00:00');
428 o=new ResultHandler();
429 nc.call('fail', o);
430 o.onResult = function(res) {
431 fail("onResult unexpectedly called");
432 test17();
434 o.onStatus = function(res) {
435 check_equals(res.remote_port, connectionPort);
436 check_equals(res.request_id, '/8');
437 check_equals(res.message, 'fail');
438 check_equals(res.arg_count, '0');
439 check_equals(res.hex, '0a:00:00:00:00');
440 test17();
444 function test17()
446 check_equals(nc.isConnected, false);
447 check_equals(nc.statuses.length, 5);
449 endOfTest();
453 // TODO: check encoding of calls w/out an handler, should
454 // have a request_id == '/' but we can't check immediately
455 // as we don't have the response handler....
457 test1();