Make automated FSCommand invocation tests show player-side output.
[gnash.git] / testsuite / network.all / http.as
blob4bee1806cdc14c463a127cf6f4530ff8b6fc7b00
1 // This test relies on a default deploy of red5 on localhost
2 //
3 // Build with:
4 // makeswf -n network -o red5test.swf ../Dejagnu.swf red5test.as ../actionscript.all/dejagnu_so_fini.as
5 // Run with:
6 // firefox red5test.swf
7 // Or:
8 // gnash red5test.swf
9 //
12 #define info _root.note
13 #define note _root.note
14 #define fail_check _root.fail
15 #define pass_check _root.pass
16 #define xfail_check _root.xfail
17 #define xpass_check _root.xpass
19 note("SWF" + OUTPUT_VERSION + " - " + System.capabilities.version + "\n");
20 rcsid="red5test.as - <bzr revno here>";
22 #include "../actionscript.all/check.as"
23 #include "../actionscript.all/utils.as"
24 #include "../actionscript.all/dejagnu.as"
26 stop();
28 endOfTest = function()
30 //note("END OF TEST");
31 // check_totals(9);
32 totals();
33 play();
36 // -P FlashVars='hostname=localhost,rtmptport5080=rtmpport=1935'
37 if (hostname == undefined) {
38 hostname="localhost";
39 note("No hostname specified, defaulting to "+hostname);
42 if (rtmptport == undefined) {
43 rtmptport = 5080;
44 note("No HTTP port specified, defaulting to "+rtmptport);
47 if (rtmpport == undefined) {
48 rtmpport = 1935;
49 note("No HTTP port specified, defaulting to "+rtmpport);
52 nc = new NetConnection;
53 nc.statuses = new Array();
54 nc.onStatus = function()
56 note('NetConnection.onStatus called with args: '+dumpObject(arguments));
59 nc.onResult = function()
61 note('NetConnection.onResult called with args: '+dumpObject(arguments));
62 if ((lastStatusArgs[0].level == "status") && (lastStatusArgs[0].code == "NetConnection.Connect.Success")) {
63 pass("HTTP connection - status Success");
64 } else {
65 fail("HTTP connection - status Success");
69 function ResultHandler() {
70 this.onResult = function(result) {
71 note('default onResult called with args: '+dumpObject(arguments));
73 // this.onCustom = function(result) {
74 // note('default onCustom called with args: '+dumpObject(arguments));
75 // };
76 // this.onDebugEvents = function(result) {
77 // note('default onDebugEvents called with args: '+dumpObject(arguments));
78 // };
79 // this.onStatus = function(result) {
80 // note("default onStatus called with args: "+dumpObject(arguments));
81 // };
86 rtmpuri = "http://"+hostname+":"+rtmptport+"/echo/gateway";
87 note("Connecting to "+rtmpuri);
88 nc.connect(rtmpuri);
89 // The network connection is not opened at connect() time, but when
90 // the first call() is made.
92 if (nc.isConnected == false) { // now it is connected
93 pass("HTTP connection - status isConnected");
94 } else {
95 fail("HTTP connection - status isConnected");
98 nc.onResult = function()
100 note("Got a connection result back from the server.");
101 if (nc.isConnected == true) { // now it is connected
102 pass("HTTP connection - status isConnected");
103 } else {
104 fail("HTTP connection - status isConnected");
106 lastStatusArgs = nc.statuses[nc.statuses.length-1];
107 if ((lastStatusArgs[0].level == "status") && (lastStatusArgs[0].code == "NetConnection.Connect.Success")) {
108 pass("HTTP connection - status Success");
109 } else {
110 fail("HTTP connection - status Success");
116 // The Red5 echo tests Null, Undefined, Boolean True, Boolean False,
117 // String, Number, Array, Object, Date, Custom Class Remote Class
120 // This call starts the actual network connection
121 result1=false;;
122 o=new ResultHandler();
123 o.onResult = function()
125 note("Got a null result back from the HTTP server."+dumpObject(arguments));
126 note(arguments[0]);
127 if (arguments.length == 1) {
128 if (arguments[0] == null) {
129 result1=true;
133 nc.call("echo", o, null);
134 if (nc.isConnected == true) { // now it is connected
135 pass("HTTP connection - status isConnected");
136 } else {
137 fail("HTTP connection - status isConnected");
140 result2=false;
141 o=new ResultHandler();
142 o.onResult = function()
144 note("Got an undefined result back from the HTTP server."+dumpObject(arguments));
145 if (arguments.length == 1) {
146 if (arguments[0] == undefined) {
147 result2=true;
151 nc.call("echo", o, undefined);
153 // bt=new Boolean(true);
154 // o=new ResultHandler();
155 // o.onResult = function()
156 // {
157 // check_equals(arguments.toString(), trued);
158 // };
159 // nc.call("echo", o, bt);
161 // bf=new Boolean(false);
162 // nc.call("echo", o, bf);
164 // Empty String
165 result3=false;
166 tstr = new String();
167 o=new ResultHandler();
168 o.onResult = function()
170 note("Got a string result back from the HTTP server."+dumpObject(arguments));
171 if (arguments.length == 1) {
172 if (arguments[0].length == 0) {
173 result3 = true;
177 nc.call("echo", o, tstr);
179 // Hello World!
180 result4=false;
181 tstr2 = "Hello World!";
182 o=new ResultHandler();
183 o.onResult = function()
185 note("Got a string result back from the HTTP server."+dumpObject(arguments));
186 // note("ARG4 is: " +dumpObject(arguments[0]));
187 str = arguments[0].toString();
188 if (arguments.length == 1) {
189 if ((arguments[0].length == 12)
190 && (arguments[0].toString() == "Hello World!")) {
191 result4 = true;
195 nc.call("echo", o, tstr2);
197 // test1,test2,test3,test4
199 // Number 0
200 result5=false;
201 o=new ResultHandler();
202 o.onResult = function()
204 note("Got a numerical 0 result back from the HTTP server."+dumpObject(arguments));
205 if (arguments.length == 1) {
206 if (arguments[0] == 0) {
207 result5 = true;
211 nc.call("echo", o, 0);
213 // Number 1
214 result6=false;
215 o=new ResultHandler();
216 o.onResult = function()
218 note("Got a numerical 1 result back from the HTTP server."+dumpObject(arguments));
219 if (arguments.length == 1) {
220 if (arguments[0] == 1) {
221 result6 = true;
225 nc.call("echo", o, 1);
227 // Number -1
228 result7=false;
229 o=new ResultHandler();
230 o.onResult = function()
232 note("Got a numerical -1 result back from the HTTP server."+dumpObject(arguments));
233 if ((arguments.length == 1)) {
234 note("FIXME: "+arguments[0].to_number());
235 result7 = true;
238 nc.call("echo", o, -1);
240 // Number 256
241 result8=false;
242 o=new ResultHandler();
243 o.onResult = function()
245 note("Got a numerical 256 result back from the HTTP server."+dumpObject(arguments));
246 if (arguments.length == 1) {
247 if (arguments[0] == 256) {
248 result8 = true;
252 nc.call("echo", o, 256);
254 // Number -256
255 result9=false;
256 o=new ResultHandler();
257 o.onResult = function()
259 note("Got a numerical -256 result back from the HTTP server."+dumpObject(arguments));
260 if (arguments.length == 1) {
261 if (arguments[0] == -256) {
262 result9 = true;
266 nc.call("echo", o, -256);
268 // Number 65536
269 result10=false;
270 o=new ResultHandler();
271 o.onResult = function()
273 note("Got a numerical 65536 result back from the HTTP server."+dumpObject(arguments));
274 if (arguments.length == 1) {
275 if (arguments[0] == 65536) {
276 result10 = true;
280 nc.call("echo", o, 65536);
282 // Number -65536
283 result11=false;
284 o=new ResultHandler();
285 o.onResult = function()
287 note("Got a numerical -65536 result back from the HTTP server."+dumpObject(arguments));
288 if (arguments.length == 1) {
289 if (arguments[0] == -65536) {
290 result11 = true;
294 nc.call("echo", o, -65536);
296 // 1.5
297 result12=false;
298 o=new ResultHandler();
299 o.onResult = function()
301 note("Got a numerical 1.5 result back from the HTTP server."+dumpObject(arguments));
302 if (arguments.length == 1) {
303 if (arguments[0] == 1.5) {
304 result12 = true;
308 nc.call("echo", o, 1.5);
310 // -1.5
311 result13=false;
312 o=new ResultHandler();
313 o.onResult = function()
315 note("Got a numerical -1.5 result back from the HTTPserver."+dumpObject(arguments));
316 if (arguments.length == 1) {
317 if (arguments[0] == -1.5) {
318 result13 = true;
322 nc.call("echo", o, -1.5);
324 // Number NaN
325 result14=false;
326 o=new ResultHandler();
327 o.onResult = function()
329 note("Got a numerical NaN result back from the HTTP server."+dumpObject(arguments));
330 if (arguments.length == 1) {
331 if (arguments[0] == NaN) {
332 result14 = true;
336 nc.call("echo", o, NaN);
338 // Number Infinity
339 result15=false;
340 o=new ResultHandler();
341 o.onResult = function()
343 note("Got an numerical infinity result back from the HTTP server."+dumpObject(arguments));
344 if (arguments.length == 1) {
345 if (arguments[0] == infinity) {
346 result15 = true;
350 nc.call("echo", o, infinity);
352 // Number -Infinity
353 result16=false;
354 o=new ResultHandler();
355 o.onResult = function()
357 note("Got a numerical -infinity result back from the HTTP server."+dumpObject(arguments));
358 if (arguments.length == 1) {
359 if (arguments[0] == -infinity) {
360 result16 = true;
364 nc.call("echo", o, -infinity);
366 // o=new ResultHandler();
367 // o.onResult = function()
368 // {
369 // note("Got a result back from the server.");
370 // check_equals(arguments.toString(), '1,two,true,4,5,6');
371 // endOfTest();
372 // };
373 // nc.call("echo", o, 1, 'two', true, [4,5,6]);
375 // o=new ResultHandler();
376 // o.onResult = function()
377 // {
378 // note("Got a result back from the server.");
379 // check_equals(arguments.toString(), '1,2,3');
380 // };
381 // nc.call("echo", o, 1, 2, 3);
384 // Test empty array
385 tar = new Array();
386 result17=false;
387 o=new ResultHandler();
388 o.onResult = function()
390 note("Got an empty array result back from the HTTP server."+dumpObject(arguments));
391 if (arguments.length == 1) {
392 if (arguments[0].length == 0) {
393 result17 = true;
397 nc.call("echo", o, tar);
399 // Test array with only one item
400 result18=false;
401 tar = new Array();
402 tar.push(1);
403 o=new ResultHandler();
404 o.onResult = function()
406 note("Got a single item array result back from the HTTP server."+dumpObject(arguments));
407 if (arguments.length == 1) {
408 if (arguments[0][0] == 1) {
409 result18 = true;
413 nc.call("echo", o, tar);
415 // Test array with multiple items
416 result19=false;
417 tar = new Array();
418 tar.push(1);
419 tar.push(2);
420 tar.push(3);
421 o=new ResultHandler();
422 o.onResult = function()
424 note("Got an 3 item array result back from the HTTP server."+dumpObject(arguments));
425 if ((arguments.length == 1) && (arguments[0].length == 3)) {
426 if ((arguments[0][0] == 1) && (arguments[0][1] == 2) && (arguments[0][2] == 3)) {
427 result19 = true;
430 // note(arguments[0].toString());
431 // check_equals(arguments[0].toString(), "1.2.3");
433 nc.call("echo", o, tar);
435 // Test sparse array
436 result20=false;
437 tar2 = new Array();
438 tar2.push(1);
439 tar2.push();
440 tar2.push();
441 tar2.push();
442 tar2.push(5);
443 o=new ResultHandler();
444 o.onResult = function()
446 note("Got a sparse result back from the HTTP server."+dumpObject(arguments));
447 if ((arguments.length == 1) && (arguments[0].length == 2)) {
448 if ((arguments[0][0] == 1) && (arguments[0][1] == 5)) {
449 result20 = true;
452 // check_equals(arguments.toString(), "1..,,5");
454 nc.call("echo", o, tar2);
456 // Do the tests to see what happened last, to give the callbacks time
457 // to be executed, as they're a background thread.
458 if (result1) {
459 pass("RTMPT: Echo NULL Object");
460 } else {
461 fail("RTMPT: Echo NULL Object");
464 if (result2) {
465 pass("RTMPT: Echo UNDEFINED Object");
466 } else {
467 fail("RTMPT: Echo UNDEFINED Object");
470 if (result3) {
471 pass("RTMPT: Echo empty String");
472 } else {
473 fail("RTMPT: Echo empty String");
476 if (result4) {
477 pass("RTMPT: Echo short String");
478 } else {
479 fail("RTMPT: Echo short String");
482 if (result5) {
483 pass("RTMPT: Echo Number 0");
484 } else {
485 fail("RTMPT: Echo Number 0");
488 if (result6) {
489 pass("RTMPT: Echo Number 1");
490 } else {
491 fail("RTMPT: Echo Number 1");
494 if (result7) {
495 pass("RTMPT: Echo Number -1");
496 } else {
497 fail("RTMPT: Echo Number -1");
499 if (result8) {
500 pass("RTMPT: Echo Number 256");
501 } else {
502 fail("RTMPT: Echo Number 256");
504 if (result9) {
505 pass("RTMPT: Echo Number -256");
506 } else {
507 fail("RTMPT: Echo Number -256");
509 if (result10) {
510 pass("RTMPT: Echo Number 65536");
511 } else {
512 fail("RTMPT: Echo Number 65536");
514 if (result11) {
515 pass("RTMPT: Echo Number -65536");
516 } else {
517 fail("RTMPT: Echo Number -65536");
519 if (result12) {
520 pass("RTMPT: Echo Number 1.5");
521 } else {
522 fail("RTMPT: Echo Number 1.5");
524 if (result13) {
525 pass("RTMPT: Echo Number -1.5");
526 } else {
527 fail("RTMPT: Echo Number -1.5");
529 if (result14) {
530 pass("RTMPT: Echo Number NaN");
531 } else {
532 fail("RTMPT: Echo Number NaN");
534 if (result15) {
535 pass("RTMPT: Echo Number Infinity");
536 } else {
537 fail("RTMPT: Echo Number Infinity");
539 if (result16) {
540 pass("RTMPT: Echo Number -Infinity");
541 } else {
542 fail("RTMPT: Echo Number -Infinity");
545 if (result17) {
546 pass("RTMPT: Echo empty array");
547 } else {
548 fail("RTMPT: Echo empty array");
550 if (result18) {
551 pass("RTMPT: Echo 1 item array");
552 } else {
553 fail("RTMPT: Echo 1 item array");
555 if (result19) {
556 pass("RTMPT: Echo 3 item array");
557 } else {
558 fail("RTMPT: Echo 3 item array");
560 if (result20) {
561 pass("RTMPT: Echo sparse array");
562 } else {
563 fail("RTMPT: cho sparse array");