Add automated tests on function-type FSCommand parameter passing.
[gnash.git] / testsuite / misc-ming.all / XMLSocketTest.as
blob586e82cbb96617d119cfd8272ceaf7d6d53d1a0c
2 #include "../actionscript.all/check.as"
4 xmlArray = [];
5 xmlArray[0] = 'Plain text';
6 xmlArray[1] = 'Plain *NEWLINE* text';
7 xmlArray[2] = 'Plain *NULL* text';
8 xmlArray[3] = 'Plain *NULL**NEWLINE* text';
9 xmlArray[4] = '<xml>Some XML</xml>';
10 xmlArray[5] = '<xml>Some XML*NEWLINE*</xml>';
11 xmlArray[6] = '<xml>Some XML*NULL*</xml>';
12 xmlArray[7] = '<xml>Some XML*NEWLINE**NULL*</xml>';
13 xmlArray[8] = undefined;
14 xmlArray[9] = 9;
15 xmlArray[10] = "";
16 a = "";
17 for (i = 0; i < 250; ++i) {
18 a += "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; // 60
20 xmlArray[11] = a;
21 xmlArray[12] = 'Last Item';
22 xmlArray[13] = 'closeNow';
23 xmlArray[14] = 'moo';
25 expectedArray = new Array();
26 expectedArray[0] = 'Plain text';
27 expectedArray[1] = 'Plain \n text';
28 expectedArray[2] = 'Plain ';
29 expectedArray[3] = ' text';
30 expectedArray[4] = 'Plain ';
31 expectedArray[5] = '\n text';
32 expectedArray[6] = '<xml>Some XML</xml>';
33 expectedArray[7] = '<xml>Some XML\n</xml>';
34 expectedArray[8] = '<xml>Some XML';
35 expectedArray[9] = '</xml>';
36 expectedArray[10] = '<xml>Some XML\n';
37 expectedArray[11] = '</xml>';
38 expectedArray[12] = 'undefined';
39 expectedArray[13] = 9;
40 expectedArray[14] = '';
41 // Don't check 15 (we'll only check length)
42 expectedArray[16] = 'Last Item';
44 gc = 0;
45 wait = 0;
46 count = -1;
47 connected = false;
49 var myXML;
51 function handleConnect(connectionStatus) {
52 check_equals(connectionStatus, true);
53 if (connectionStatus) {
54 trace('Connected');
55 connected = true;
56 if (gc < xmlArray.length) {
57 myXML.send(xmlArray[gc++]);
60 else { trace('Initial connection failed!'); }
61 };
63 // Store data and send next lot.
64 function handleData(data) {
65 receivedArray.push(data);
66 myXML.send(xmlArray[gc++]);
67 };
69 function handleDisconnect() {
70 trace('Connection lost.');
71 checkResults();
72 };
74 function test1()
76 trace("-- RUNNING TEST1 --");
77 myXML = new XMLSocket;
78 myXML.onConnect = handleConnect;
79 myXML.onData = handleData;
80 myXML.onClose = handleDisconnect;
81 receivedArray = new Array();
83 ret = myXML.connect("localhost", 2229);
84 check_equals(ret, true);
87 // Check that XMLSocket can be instanciated from subclass
88 // See https://savannah.gnu.org/bugs/?38084
89 function test2()
91 trace("-- RUNNING TEST2 --");
92 receivedArray = new Array();
94 SC1 = function() { };
95 SC1.name = 'SC1 ctor';
96 SC1.prototype = new XMLSocket();
98 // None of these get called
99 SC1.prototype.onConnect = function() { fail("SC1 prototype onConnect called"); };
100 SC1.prototype.onData = function() { fail("SC1 prototype onData called"); };
101 SC1.prototype.onClose = function() { fail("SC1 prototype onClose called"); };
103 //trace("SC1.constructor is: " + SC1.constructor);
104 //trace("SC1.constructor.name is: " + SC1.constructor.name);
105 //trace("SC1.__constructor__ is: " + SC1.__constructor__);
107 SC2 = function() { };
108 SC2.prototype = new SC1();
110 // None of these get called
111 SC2.prototype.onConnect = function() { fail("SC2 prototype onConnect called"); };
112 SC2.prototype.onData = function() { fail("SC2 prototype onData called"); };
113 SC2.prototype.onClose = function() { fail("SC2 prototype onClose called"); };
116 trace('About to instanciate an SC2 now');
117 o = new SC2();
118 o.onConnect = function() { fail("instance onConnect called"); };
119 o.onData = function() { fail("instance onData called"); };
120 o.onClose = function() { fail("instance onClose called"); };
122 ret = o.connect("localhost", 2229);
123 xcheck_equals(ret, true);
124 nextTest();
127 currtest = 0;
128 tests = new Array();
129 tests.push(test1);
130 tests.push(test2);
132 function nextTest()
134 if ( tests.length > currtest ) {
135 tests[currtest++]();
136 } else {
137 trace("ENDOFTEST");
138 loadMovie ("FSCommand:quit", "");
142 nextTest();
143 stop();
146 function checkResults() {
148 check_equals(receivedArray[0], expectedArray[0]);
149 check_equals(receivedArray[1], expectedArray[1]);
150 check_equals(receivedArray[2], expectedArray[2]);
151 check_equals(receivedArray[3], expectedArray[3]);
152 check_equals(receivedArray[4], expectedArray[4]);
153 check_equals(receivedArray[5], expectedArray[5]);
154 check_equals(receivedArray[6], expectedArray[6]);
155 check_equals(receivedArray[7], expectedArray[7]);
156 check_equals(receivedArray[8], expectedArray[8]);
157 check_equals(receivedArray[9], expectedArray[9]);
158 check_equals(receivedArray[10], expectedArray[10]);
159 check_equals(receivedArray[11], expectedArray[11]);
160 // NOTE: this ('undefined') fails with LNX 10,0,12,10
161 check_equals(receivedArray[12], expectedArray[12]);
162 check_equals(receivedArray[13], expectedArray[13]);
163 check_equals(receivedArray[14], expectedArray[14]);
164 check_equals(receivedArray[15].length, 15000);
165 check_equals(receivedArray[15].charAt(0), 'a');
166 check_equals(receivedArray[16], expectedArray[16]);
167 nextTest();