1 // This test may have similarities to the red5test, but we don't
2 // attempt to keep them in sync.
4 // Differences between red5 and rtmpy:
5 // rtmpy always returns an object: a single primitive type is
6 // convert to the corresponding object. If several arguments are
7 // sent, an array is returned. This array may contain primitive
10 note
("SWF" + OUTPUT_VERSION
+ " - " + System.capabilities
.version
+ "\n");
11 rcsid
="red5test.as - <bzr revno here>";
13 #define info _root
.note
14 #define note _root
.note
15 #define fail_check _root
.fail
16 #define pass_check _root
.pass
17 #define xfail_check _root
.xfail
18 #define xpass_check _root
.xpass
20 #include "../actionscript.all/check.as"
21 #include "../actionscript.all/utils.as"
25 endOfTest
= function()
27 // Should be incremented on connect
28 check_equals
(welcomecalls
, 1);
29 check_equals
(connectcalls
, 1);
36 // -P FlashVars='hostname=localhost,rtmptport5080=rtmpport=1935'
37 hostname
= RTMPY_HOST
;
39 if (rtmpport
== undefined) {
41 note
("No RTMP port specified, defaulting to "+rtmpport
);
43 rtmpuri
= "rtmp://"+hostname
+":"+rtmpport
+"/rtmpyecho";
47 note
("Running test 1");
49 o
.onResult
= function(arg
)
51 check_equals
(arguments.length
, 1);
52 check_equals
(arg
.toString
(), "hello");
53 check_equals
(typeof(arg
), "object");
56 nc
.call
("echo", o
, "hello");
61 note
("Running test 2");
63 o
.onResult
= function(arg
)
65 check_equals
(arguments.length
, 1);
66 check_equals
(typeof(arg
), "object");
67 check_equals
(arg
.toString
(), "24");
70 nc
.call
("echo", o
, 24);
73 // Send several arguments, get an array back.
76 note
("Running test 3");
78 o
.onResult
= function(arg
)
80 check_equals
(arguments.length
, 1);
81 check_equals
(typeof(arg
), "object");
82 check
(arg
.hasOwnProperty
("length"));
83 check_equals
(arg
.length
, 3);
85 check_equals
(typeof(arg
[0]), "number");
87 check_equals
(typeof(arg
[1]), "object");
88 check_equals
(typeof(arg
[1].x
), "number");
89 check_equals
(arg
[1].x
, 23);
90 check_equals
(typeof(arg
[1].y
), "number");
91 check_equals
(arg
[1].y
, 67);
92 check_equals
(typeof(arg
[1].text
), "string");
93 check_equals
(arg
[1].text
, "a string");
95 check_equals
(typeof(arg
[2]), "object");
96 check_equals
(arg
[2].length
, 5);
100 nc
.call
("echo", o
, 24, { x
:23, y
:67, text
:"a string" }, [ 1, 2, 3, 4, 5] );
106 note
("Running test 4");
108 o
.onResult
= function(arg
)
110 check_equals
(arguments.length
, 1);
111 check_equals
(typeof(arg
), "object");
112 check
(arg
.hasOwnProperty
("length"));
113 check_equals
(arg
.length
, 5);
116 check_equals
(arg
[0].__proto__
, Date.prototype
);
118 check_equals
(arg
[1], null);
119 check_equals
(typeof(arg
[2]), "object");
120 check_equals
(arg
[3], undefined);
121 check_equals
(arg
[4], null);
125 nc
.call
("echo", o
, new Date(0), new String(), {}, undefined, null);
130 note
("Running test 5");
132 o
.onResult
= function(arg
)
134 fail
("onResult called when call failed");
137 nc
.onStatus
= function(obj
) {
138 trace
(dumpObject
(obj
));
139 check_equals
(typeof(obj
), "object");
140 check
(obj
.hasOwnProperty
("level"));
141 check
(obj
.hasOwnProperty
("code"));
142 check
(obj
.hasOwnProperty
("description"));
143 check_equals
(obj
.level
, "error");
144 check_equals
(obj
.code
, "NetConnection.Call.Failed");
145 check_equals
(obj
.description
, "Unknown method u'nonexistentfunc'");
146 nc
.onStatus
= defaultOnStatus
;
150 nc
.call
("nonexistentfunc", o
, "hello", null);
155 note
("Running test 6");
157 o
.onResult
= function(obj
) {
158 trace
(dumpObject
(obj
));
162 nc
.call
("echo", o
, 1);
167 nc
.onStatus
= function(obj
) {
168 check_equals
(obj
.level
, "status");
169 check_equals
(obj
.code
, "NetConnection.Connect.Closed");
176 runtests
= function(nc
)
181 ncrtmp
= new NetConnection();
182 ncrtmp
.statuses
= new Array();
183 defaultOnStatus
= function()
185 this.statuses
.push
(arguments);
186 note
('NetConnection.onStatus called with args: ' + dumpObject
(arguments));
187 lastStatusArgs
= ncrtmp
.statuses
[ncrtmp
.statuses
.length
-1];
188 if ((lastStatusArgs
[0].level
== "status") && (lastStatusArgs
[0].code
== "NetConnection.Connect.Success")) {
189 pass
("RTMP connection - status Success");
191 fail
("RTMP connection - status Success");
196 ncrtmp
.onStatus
= defaultOnStatus
;
198 ncrtmp
.disconnected
= function(arg
) {
203 ncrtmp
.welcome
= function(arg
) {
205 check_equals
(arg
[0].toString
(), "You have connected!");
206 trace
(dumpObject
(arg
[1]));
210 ncrtmp
.initial
= function(arg
) {
212 check_equals
(arg
[0].toString
(), "connection attempt received");
215 check
(o
.hasOwnProperty
("fpad"));
216 check_equals
(typeof(o
.fpad
), "boolean");
217 check_equals
(o
.fpad
, false);
219 check
(o
.hasOwnProperty
("pageUrl"));
220 check_equals
(typeof(o
.pageUrl
), "undefined");
221 check_equals
(o
.pageUrl
, undefined);
223 check
(o
.hasOwnProperty
("videoFunction"));
224 check_equals
(typeof(o
.videoFunction
), "number");
225 check_equals
(o
.videoFunction
, 1);
227 check
(o
.hasOwnProperty
("tcUrl"));
228 check_equals
(typeof(o
.tcUrl
), "string");
229 check_equals
(o
.tcUrl
, rtmpuri
);
231 check
(o
.hasOwnProperty
("app"));
232 check_equals
(typeof(o
.app
), "string");
233 check_equals
(o
.app
, "rtmpyecho");
235 check
(o
.hasOwnProperty
("flashVer"));
236 check_equals
(typeof(o
.flashVer
), "string");
237 xcheck_equals
(o
.flashVer
, "Our own special nonsense custom version");
239 check
(o
.hasOwnProperty
("audioCodecs"));
240 check_equals
(typeof(o
.audioCodecs
), "number");
242 check
(o
.hasOwnProperty
("videoCodecs"));
243 check_equals
(typeof(o
.videoCodecs
), "number");
245 check
(o
.hasOwnProperty
("swfUrl"));
246 check_equals
(typeof(o
.swfUrl
), "string");
247 check_equals
(o
.swfUrl
, _url
);
249 check
(o
.hasOwnProperty
("capabilities"));
250 check_equals
(typeof(o
.capabilities
), "number");
252 trace
(dumpObject
(arg
[1]));
255 note
("Connecting to "+rtmpuri
);
257 $version
= "Our own special nonsense custom version";
258 ncrtmp
.connect
(rtmpuri
);