2 // Copyright (C) 2005, 2006, 2007, 2009, 2010 Free Software
5 // This program is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation; either version 3 of the License, or
8 // (at your option) any later version.
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software
17 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 // Test case for SharedObject ActionScript class
21 // compile this test case with Ming makeswf, and then
22 // execute it like this gnash -1 -r 0 -v out.swf
25 rcsid
="SharedObject.as";
28 var sharedobjectObj
= new SharedObject;
30 // test the SharedObject constuctor
31 check_equals
(typeof(sharedobjectObj
), 'object');
34 // test the SharedObject.getlocal method
35 check_equals
(typeof(sharedobjectObj
.getLocal
), 'undefined');
36 check_equals
(typeof(SharedObject.getLocal
), 'function');
38 #if OUTPUT_VERSION
> 5
40 check
(SharedObject.prototype
.hasOwnProperty
("connect"));
41 check
(SharedObject.prototype
.hasOwnProperty
("send"));
42 check
(SharedObject.prototype
.hasOwnProperty
("flush"));
43 check
(SharedObject.prototype
.hasOwnProperty
("getSize"));
44 check
(SharedObject.prototype
.hasOwnProperty
("setFps"));
45 check
(SharedObject.prototype
.hasOwnProperty
("clear"));
46 check
(SharedObject.prototype
.hasOwnProperty
("close"));
47 check
(!SharedObject.prototype
.hasOwnProperty
("data"));
49 check
(!SharedObject.prototype
.hasOwnProperty
("getLocal"));
50 check
(!SharedObject.prototype
.hasOwnProperty
("getRemote"));
51 check
(!SharedObject.prototype
.hasOwnProperty
("getDiskUsage"));
52 check
(!SharedObject.prototype
.hasOwnProperty
("deleteAll"));
53 check
(SharedObject.hasOwnProperty
("getLocal"));
54 check
(SharedObject.hasOwnProperty
("getRemote"));
55 check
(SharedObject.hasOwnProperty
("getDiskUsage"));
56 check
(SharedObject.hasOwnProperty
("deleteAll"));
58 check_equals
(typeof(sharedobjectObj
.connect
), 'function');
59 check_equals
(typeof(sharedobjectObj
.send
), 'function');
60 check_equals
(typeof(sharedobjectObj
.flush
), 'function');
61 check_equals
(typeof(sharedobjectObj
.close
), 'function');
62 check_equals
(typeof(sharedobjectObj
.getSize
), 'function');
63 check_equals
(typeof(sharedobjectObj
.setFps
), 'function');
64 check_equals
(typeof(sharedobjectObj
.clear
), 'function');
65 check_equals
(typeof(sharedobjectObj
.data
), 'undefined');
67 check_equals
(typeof(sharedobjectObj
.connect
), 'undefined');
68 check_equals
(typeof(sharedobjectObj
.send
), 'undefined');
69 check_equals
(typeof(sharedobjectObj
.flush
), 'undefined');
70 check_equals
(typeof(sharedobjectObj
.close
), 'undefined');
71 check_equals
(typeof(sharedobjectObj
.getSize
), 'undefined');
72 check_equals
(typeof(sharedobjectObj
.setFps
), 'undefined');
73 check_equals
(typeof(sharedobjectObj
.clear
), 'undefined');
76 // FIXME: Test code that will soon be a formal test case.
77 so
= SharedObject.getLocal
("level1/level2/settings", "/");
78 #if OUTPUT_VERSION
> 5
79 check_equals
(so
.getSize
(), 297);
81 check
(so
instanceof SharedObject);
87 #if OUTPUT_VERSION
> 5
88 check_equals
(so
.getSize
(), 297);
90 // public data that gets written
91 #if OUTPUT_VERSION
> 5
92 check
(so
.hasOwnProperty
("data"));
93 check
(!so
.data
.hasOwnProperty
("toString"));
94 check
(!so
.data
.hasOwnProperty
("valueOf"));
95 check_equals
(typeof(so
.data
.valueOf
), "function");
99 so
.data
.echosuppression
= false;
100 so
.data
.defaultmicrophone
= "/dev/input/mic";
101 so
.data
.defaultcamera
= "";
102 so
.data
.defaultklimit
= 100.0;
103 so
.data
.defaultalways
= false;
104 so
.data
.crossdomainAllow
= true;
105 so
.data
.crossdomainAlways
= true;
106 so
.data
.allowThirdPartyLSOAccess
= true;
107 so
.data
.localSecPath
= "";
108 so
.data
.localSecPathTime
= 1.19751160683e+12;
111 // Verify that a new getLocal call using
112 // the same "id" returns the same in-memory object.
113 so
.data
.tmp
= "custom value";
114 so2
= SharedObject.getLocal
("level1/level2/settings", "/");
115 check_equals
(so2
.data
.tmp
, "custom value");
116 check_equals
(so2
.data
.toString
(), "[object Object]");
117 check_equals
(so
, so2
);
119 #if OUTPUT_VERSION
> 5
120 check_equals
(so2
.getSize
(), 318);
121 check_equals
(so
.getSize
(), 318);
124 // Check SOL names validity.
125 so2bis
= SharedObject.getLocal
("level1//level2/settings", "/");
126 check_equals
(typeof(so2bis
), 'null'); // invalid path
127 so2bis
= SharedObject.getLocal
("a");
128 check_equals
(typeof(so2bis
), 'object');
129 so2bis
= SharedObject.getLocal
("a~");
130 check_equals
(typeof(so2bis
), 'null');
131 so2bis
= SharedObject.getLocal
("a ");
132 check_equals
(typeof(so2bis
), 'null');
133 so2bis
= SharedObject.getLocal
("a'");
134 check_equals
(typeof(so2bis
), 'null');
135 so2bis
= SharedObject.getLocal
("%");
136 check_equals
(typeof(so2bis
), 'object');
137 so2bis
= SharedObject.getLocal
("a%");
138 check_equals
(typeof(so2bis
), 'object');
139 so2bis
= SharedObject.getLocal
("a&");
140 check_equals
(typeof(so2bis
), 'null');
141 so2bis
= SharedObject.getLocal
("a\\");
142 check_equals
(typeof(so2bis
), 'null');
143 so2bis
= SharedObject.getLocal
("a;");
144 check_equals
(typeof(so2bis
), 'null');
145 so2bis
= SharedObject.getLocal
("a:");
146 check_equals
(typeof(so2bis
), 'null');
147 so2bis
= SharedObject.getLocal
("a\"");
148 check_equals
(typeof(so2bis
), 'null');
149 so2bis
= SharedObject.getLocal
("a,");
150 check_equals
(typeof(so2bis
), 'null');
151 so2bis
= SharedObject.getLocal
("a>");
152 check_equals
(typeof(so2bis
), 'null');
153 so2bis
= SharedObject.getLocal
("a<");
154 check_equals
(typeof(so2bis
), 'null');
155 so2bis
= SharedObject.getLocal
("a#");
156 check_equals
(typeof(so2bis
), 'null');
157 so2bis
= SharedObject.getLocal
("a?");
158 check_equals
(typeof(so2bis
), 'null');
159 so2bis
= SharedObject.getLocal
("a(");
160 check_equals
(typeof(so2bis
), 'object');
161 so2bis
= SharedObject.getLocal
("a)");
162 check_equals
(typeof(so2bis
), 'object');
163 so2bis
= SharedObject.getLocal
("a{");
164 check_equals
(typeof(so2bis
), 'object');
165 so2bis
= SharedObject.getLocal
("a}");
166 check_equals
(typeof(so2bis
), 'object');
167 so2bis
= SharedObject.getLocal
("a$");
168 check_equals
(typeof(so2bis
), 'object');
169 so2bis
= SharedObject.getLocal
("a!");
170 check_equals
(typeof(so2bis
), 'object');
171 so2bis
= SharedObject.getLocal
("ΓΌ");
172 check_equals
(typeof(so2bis
), 'object');
173 so2bis
= SharedObject.getLocal
("a*");
174 check_equals
(typeof(so2bis
), 'object');
176 so2bis
= SharedObject.getLocal
("level1/./level2/settings", "/");
177 check_equals
(typeof(so2bis
), 'object'); // valid path
178 check
(so2bis
!= so2
); // but not recognized as the same as level1/./level2/settings
182 #if OUTPUT_VERSION
> 5
183 check_equals
(so
.getSize
(), 297);
186 // But a getLocal call using a *different* "id" returns
187 // a different SharedObject...
188 so3
= SharedObject.getLocal
("level1/level2/settings3", "/");
191 #if OUTPUT_VERSION
> 5
192 check_equals
(so3
.getSize
(), 0);
195 // Doesn't make much sense to test the rest for SWF5
196 #if OUTPUT_VERSION
> 5
198 // trace(so.getSize());
200 check_equals
(typeof(ret
), 'boolean');
201 check_equals
(ret
, true);
203 newso
= SharedObject.getLocal
("level1/level2/settings", "/");
204 check_equals
(typeof(newso
), 'object');
205 trace
(newso
.getSize
());
206 #if OUTPUT_VERSION
> 5
207 check_equals
(newso
.getSize
(), 297);
210 if (typeof(newso
.data
) != 'undefined') {
211 trace
("New Shared Object, checking data...");
212 trace
(typeof(newso
.data
.gain
));
213 check_equals
(typeof(newso
.data
.gain
), 'number');
214 check_equals
(newso
.data
.gain
, so
.data
.gain
);
215 check_equals
(typeof(newso
.data
.echosuppression
), 'boolean');
216 check_equals
(newso
.data
.echosuppression
, so
.data
.echosuppression
);
217 check_equals
(typeof(newso
.data
.defaultmicrophone
), 'string');
218 check_equals
(newso
.data
.defaultmicrophone
, so
.data
.defaultmicrophone
);
219 check_equals
(typeof(newso
.data
.defaultcamera
), 'string');
220 check_equals
(newso
.data
.defaultcamera
, '');
221 check_equals
(typeof(newso
.data
.defaultklimit
), 'number');
222 check_equals
(newso
.data
.defaultklimit
, so
.data
.defaultklimit
);
223 check_equals
(typeof(newso
.data
.defaultalways
), 'boolean');
224 check_equals
(newso
.data
.defaultalways
, so
.data
.defaultalways
);
226 check_equals
(typeof(newso
.data
.crossdomainAllow
), 'boolean');
227 check_equals
(newso
.data
.crossdomainAllow
, true);
228 check_equals
(typeof(newso
.data
.crossdomainAlways
), 'boolean');
229 check_equals
(newso
.data
.crossdomainAlways
, true);
230 check_equals
(typeof(newso
.data
.allowThirdPartyLSOAccess
), 'boolean');
231 check_equals
(newso
.data
.allowThirdPartyLSOAccess
, true);
232 check_equals
(typeof(newso
.data
.localSecPath
), 'string');
233 check_equals
(newso
.data
.localSecPath
, '');
234 check_equals
(typeof(newso
.data
.localSecPathTime
), 'number');
235 check_equals
(newso
.data
.localSecPathTime
, 1.19751160683e+12);
237 trace
("New Shared Object doesn't exist!");
240 /// Check localPath argument.
242 // It seems this is quite restrictive, using a non-normalized text match
243 // for the path, and removing the first directory for filesystem loads. Case
244 // is irrelevant, however.
246 note
("Some of the following tests (all preceded by a 'checking' message) will fail when run over the network. Only the tests where an object is expected should fail");
248 so4
= SharedObject.getLocal
("Another-one", "/subdir");
249 check_equals
(so4
.getSize
(), undefined);
250 check_equals
(typeof(so4
), "null");
252 check_equals
(typeof(so4
.data
), 'undefined');
254 check_equals
(typeof(ret
), 'undefined');
256 so4
= SharedObject.getLocal
("name", "subdir");
257 check_equals
(typeof(so4
), "null");
259 so4
= SharedObject.getLocal
("name", "http://ahost/subdir");
260 check_equals
(typeof(so4
), "null");
262 ourPath
= SWFDIR
+ "/";
263 note
("checking getLocal with path: " + ourPath
);
264 so4
= SharedObject.getLocal
("name", ourPath
);
265 check_equals
(typeof(so4
), "null");
267 ourPath
= ourPath
.substr
(0, ourPath
.lastIndexOf
("/"));
268 note
("checking getLocal with path: " + ourPath
);
269 so4
= SharedObject.getLocal
("name", ourPath
);
270 check_equals
(typeof(so4
), "null");
272 // Knock the first directory off. This is also confirmed to work with
273 // a SWF in /tmp/, but it can't really be tested here.
274 ourPath
= ourPath
.substr
(ourPath
.indexOf
("/", 1));
275 note
("checking getLocal with path: " + ourPath
);
276 so4
= SharedObject.getLocal
("name", ourPath
);
277 check_equals
(typeof(so4
), "object");
280 note
("checking getLocal with path: " + ourPath
.toUpperCase
());
281 so4
= SharedObject.getLocal
("name", ourPath
.toUpperCase
());
282 check_equals
(typeof(so4
), "object");
284 // Knock the last directory off
285 ourPath
= ourPath
.substr
(0, ourPath
.lastIndexOf
("/"));
286 note
("checking getLocal with path: " + ourPath
);
287 so4
= SharedObject.getLocal
("name", ourPath
);
288 check_equals
(typeof(so4
), "object");
290 // Put one trailing slash on
292 note
("checking getLocal with path: " + ourPath
);
293 so4
= SharedObject.getLocal
("name", ourPath
);
294 check_equals
(typeof(so4
), "object");
296 // Put another trailing slash on
298 note
("checking getLocal with path: " + ourPath
);
299 so4
= SharedObject.getLocal
("name", ourPath
);
300 xcheck_equals
(typeof(so4
), "null");
302 // Take the last slash off and add a bit of rubbish
303 ourPath
= ourPath
.substr
(0, ourPath
.lastIndexOf
("/"));
304 ourPath
+= "aswfd.df";
305 note
("checking getLocal with path: " + ourPath
);
306 so4
= SharedObject.getLocal
("name", ourPath
);
307 check_equals
(typeof(so4
), "null");
309 //------------------------------------------
310 // Test that if 'data' is a getter-setter,
311 // it isn't called on .flush()
312 //------------------------------------------
314 so5
= SharedObject.getLocal
("getset");
315 check
(so5
instanceof SharedObject);
316 dataGet
= function() { getCalls
++; return new Object(); };
318 so5
.addProperty
('data', dataGet
, dataGet
);
320 check_equals
(getCalls
, 1); // the getter works
323 check_equals
(ret
, true);
324 check_equals
(getCalls
, 0); // flush didn't cal the getter
326 //------------------------------------------
327 // Test that 'data' is enumerable, read-only
328 // and protected from deletion
329 //------------------------------------------
331 so6
= SharedObject.getLocal
("so6");
332 check
(so6
.hasOwnProperty
("data"));
334 check_equals
(ret
, true);
337 for (var i
in so6
) a
.push
(i
);
338 check_equals
(a
.toString
(), 'data');
340 check_equals
(typeof(so
.data
), 'object');
342 check_equals
(typeof(so
.data
), 'object');
344 //------------------------------------------
345 // Test calling getLocal with no args
346 //------------------------------------------
348 so7
= SharedObject.getLocal
();
349 #if OUTPUT_VERSION
> 6
350 // produces 'undefined.sol'
351 check
(so7
instanceof SharedObject);
354 check_equals
(typeof(so7
), 'null');
358 #if OUTPUT_VERSION
< 7
359 check_equals
(ret
, undefined);
361 check_equals
(ret
, true);
364 so8
= SharedObject.getLocal
('');
365 check_equals
(typeof(so8
), 'null');
367 so9
= SharedObject.getLocal
('', 'something');
368 check_equals
(typeof(so9
), 'null');
370 //------------------------------------------
372 //------------------------------------------