Add automated tests on function-type FSCommand parameter passing.
[gnash.git] / testsuite / misc-ming.all / rtmpytest.as
blobbaf7ea2c0ec51b9647aa59fec2492920d74c44a5
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
8 // types.
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"
23 stop();
25 endOfTest = function()
27 // Should be incremented on connect
28 check_equals(welcomecalls, 1);
29 check_equals(connectcalls, 1);
31 totals(70);
32 trace("ENDOFTEST");
33 play();
36 // -P FlashVars='hostname=localhost,rtmptport5080=rtmpport=1935'
37 hostname = RTMPY_HOST;
39 if (rtmpport == undefined) {
40 rtmpport = 9984;
41 note("No RTMP port specified, defaulting to "+rtmpport);
43 rtmpuri = "rtmp://"+hostname+":"+rtmpport+"/rtmpyecho";
45 test1 = function(nc)
47 note("Running test 1");
48 o = {};
49 o.onResult = function(arg)
51 check_equals(arguments.length, 1);
52 check_equals(arg.toString(), "hello");
53 check_equals(typeof(arg), "object");
54 test2(nc);
56 nc.call("echo", o, "hello");
59 test2 = function(nc)
61 note("Running test 2");
62 o = {};
63 o.onResult = function(arg)
65 check_equals(arguments.length, 1);
66 check_equals(typeof(arg), "object");
67 check_equals(arg.toString(), "24");
68 test3(nc);
70 nc.call("echo", o, 24);
73 // Send several arguments, get an array back.
74 test3 = function(nc)
76 note("Running test 3");
77 o = {};
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);
98 test4(nc);
100 nc.call("echo", o, 24, { x:23, y:67, text:"a string" }, [ 1, 2, 3, 4, 5] );
103 // Send more things.
104 test4 = function(nc)
106 note("Running test 4");
107 o = {};
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);
115 // It's a date.
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);
123 test5(nc);
125 nc.call("echo", o, new Date(0), new String(), {}, undefined, null);
128 test5 = function(nc)
130 note("Running test 5");
131 o = {};
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;
147 test6(nc);
150 nc.call("nonexistentfunc", o, "hello", null);
153 test6 = function(nc)
155 note("Running test 6");
156 o = {};
157 o.onResult = function(obj) {
158 trace(dumpObject(obj));
159 test7(nc);
162 nc.call("echo", o, 1);
165 test7 = function(nc)
167 nc.onStatus = function(obj) {
168 check_equals(obj.level, "status");
169 check_equals(obj.code, "NetConnection.Connect.Closed");
170 endOfTest();
172 nc.close();
176 runtests = function(nc)
178 test1(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");
190 } else {
191 fail("RTMP connection - status Success");
193 runtests(this);
196 ncrtmp.onStatus = defaultOnStatus;
198 ncrtmp.disconnected = function(arg) {
199 fail("boohoo");
202 welcomecalls = 0;
203 ncrtmp.welcome = function(arg) {
204 ++welcomecalls;
205 check_equals(arg[0].toString(), "You have connected!");
206 trace(dumpObject(arg[1]));
209 connectcalls = 0;
210 ncrtmp.initial = function(arg) {
211 ++connectcalls;
212 check_equals(arg[0].toString(), "connection attempt received");
213 o = arg[1];
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);