big merge from master, fix rpm creation, drop fetching swfdec
[gnash.git] / testsuite / misc-ming.all / SharedObjectTest.as
blob0c068106147fdf75c4b0c69e3e66ca1178e9d5d0
1 //
2 // Copyright (C) 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
3 //
4 // This program is free software; you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation; either version 3 of the License, or
7 // (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with this program; if not, write to the Free Software
16 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21 // NOTE: to test this with the proprietary player:
23 // $ make SharedObjectTestRunner
24 // $ ./SharedObjectTestRunner flashplayer ~/.macromedia/Flash_Player/#SharedObjects/<key>
25 //
26 // take a look at the #SharedObject dir to figure out what <key> should be
27 //
31 #define pass_check(x) _root.pass(x)
32 #define xpass_check(x) _root.xpass(x)
33 #define fail_check(x) _root.fail(x)
34 #define xfail_check(x) _root.xfail(x)
36 #define USE_DEJAGNU_MODULE
37 #include "../actionscript.all/check.as"
39 note();
40 note("NOTE: for this test to work you should have copied");
41 note(" testsuite/misc-ming.all/SharedObjectTest.sol/*.sol");
42 note(" to this flash player's appropriate SharedObject dir");
43 note();
45 so1 = SharedObject.getLocal("sol1");
47 check_equals(so1.data.num, 2);
48 check_equals(so1.data.str, 'a string');
49 check_equals(typeof(so1.data.tbool), 'boolean');
50 check_equals(so1.data.tbool, true);
51 check_equals(typeof(so1.data.fbool), 'boolean');
52 check_equals(so1.data.fbool, false);
54 // MovieClip value mc was NOT discarded, but written (or read?) as undefined
55 check(so1.data.hasOwnProperty('mc'));
56 check_equals(typeof(so1.data.mc), 'undefined');
58 // Function value was discarded
59 check(! so1.data.hasOwnProperty('fun') );
62 // Test reading mixed types in ECMA_ARRAY
63 check_equals(typeof(so1.data.ary), 'object');
64 check_equals(so1.data.ary.toString(), '1,true,string,null,');
65 check_equals(typeof(so1.data.ary[0]), 'number');
66 check_equals(typeof(so1.data.ary[1]), 'boolean');
67 check_equals(typeof(so1.data.ary[2]), 'string');
68 check_equals(typeof(so1.data.ary[3]), 'null');
69 check_equals(typeof(so1.data.ary[4]), 'undefined');
70 check_equals(so1.data.ary.length, 5);
71 // test composition
72 tmp = so1.data.ary; // work-around to an old Ming bug [ chokes on 'for (in in a.b.c)' ]
73 a=[]; for (i in tmp) a.push(i);
74 a.sort();
75 check_equals(a.toString(), '0,1,2,3,4'); // note: no 'length'
77 // Test reading ECMA_ARRAY
78 check_equals(typeof(so1.data.aryns), 'object');
79 check_equals(so1.data.aryns.toString(), '4,5,6,,,,,');
80 check_equals(so1.data.aryns.length, 8);
81 check_equals(so1.data.aryns.custom, 7);
82 // test composition
83 tmp = so1.data.aryns; // work-around to an old Ming bug [ chokes on 'for (in in a.b.c)' ]
84 a=[]; for (i in tmp) a.push(i);
85 a.sort();
86 check_equals(a.toString(), '0,1,2,custom'); // note: no 'length'
88 // Test reading STRICT_ARRAY
89 check_equals(typeof(so1.data.strictary), 'object');
90 check_equals(so1.data.strictary.toString(), 'a,b,c');
91 check_equals(so1.data.strictary.length, 3);
93 // Test reading OBJECT
94 check(so1.data.obj instanceOf Object);
95 check_equals(typeof(so1.data.obj), 'object');
96 check_equals(typeof(so1.data.obj.a), 'number');
97 check(so1.data.obj.hasOwnProperty('a'));
98 check(!so1.data.obj.hasOwnProperty('hidden'));
99 check(so1.data.obj.hasOwnProperty('mc'));
100 check_equals(typeof(so1.data.obj.mc), 'undefined');
101 // Function value was discarded
102 check(! so1.data.obj.hasOwnProperty('fun') );
104 // Test reading NUMBER
105 check_equals(so1.data.obj.a, 10);
107 // Test reading STRING
108 check_equals(typeof(so1.data.obj.b), 'string');
109 check_equals(so1.data.obj.b, '20');
111 // Test reading BOOLEAN
112 check_equals(typeof(so1.data.obj.c), 'boolean');
113 check_equals(so1.data.obj.c, true);
115 // Test reading REFERENCE
116 check_equals(typeof(so1.data.ref), 'object');
117 check_equals(so1.data.ref, so1.data.obj);
119 // Test reading DATE
120 check_equals(typeof(so1.data.dat), 'object');
121 check(so1.data.dat instanceof Date);
122 check_equals(so1.data.dat.getYear(), 70);
123 check_equals(so1.data.dat.getFullYear(), 1970);
124 check_equals(so1.data.dat.getMonth(), 0);
125 check_equals(so1.data.dat.getDate(), 1);
126 check_equals(so1.data.dat.getDay(), 4); // It was a Thursday
127 check_equals(so1.data.dat.getHours(), 0);
128 check_equals(so1.data.dat.getMinutes(), 0);
129 check_equals(so1.data.dat.getSeconds(), 0);
130 check_equals(so1.data.dat.getMilliseconds(), 0);
132 // Test reading LONG STRING
133 lstr = 'a';
134 for (var i=0; i<16; ++i) lstr = lstr+lstr; // 65536 long
135 check_equals(so1.data.lstr, lstr);
138 // force writing the sol or the adobe player won't save it
139 // again. This will also serve as a kind of reference for
140 // how the sol file was produced in the first place
141 so1.data.num = 2;
142 so1.data.str = 'a string';
143 so1.data.tbool = true;
144 so1.data.fbool = false;
146 so1.data.ary = [1,true,'string',null, undefined]; // ECMA_ARRAY
147 so1.data.ary.hidden = 6;
148 AsSetPropFlags(so1.data.ary, 'hidden', 1); // hide from enumeration, should not end into the sol file
151 so1.data.aryns = [4,5,6];
152 so1.data.aryns.fun = function() {}; // functions in arrays are simply skipped
153 so1.data.aryns.custom = 7;
154 so1.data.aryns.length = 8; // non-strict array (ECMA_ARRAY)
156 // This member is an attempt to trigger encoding
157 // of a STRICT array. The attempt seems to be
158 // unsuccessful tough, but no way to test with
159 // ActionScript. Time to look at the binary differences
160 // between the pp and gnash versions of the saved sol.
161 so1.data.strictary = ['a','b','c'];
163 so1.data.obj = {a:10,b:'20',c:true};
164 so1.data.obj.fun = function() {}; // functions in objects are simply skipped
165 so1.data.obj.mc = createEmptyMovieClip("mc1", 1); // movieclip values are skipped
167 //AsSetPropFlags(so1.data.obj, '__proto__', 0, 1); // if we unhide __proto__ we'll find it in the SharedObject
169 AsSetPropFlags(so1.data.obj, '__constructor__', 0, 1); // unhide __constructor__ (it's a function so will be skipped anyway)
170 AsSetPropFlags(so1.data.obj, 'constructor', 0, 1); // unhide constructor (it's a function so will be skipped anyway)
171 // so1.data.obj.constructor = 4; // if we override constructor we'll find it
173 so1.data.obj.hidden = 7;
174 AsSetPropFlags(so1.data.obj, 'hidden', 1); // hide from enumeration, should not end into the sol file
176 so1.data.ref = so1.data.obj;
178 so1.data.fun = function() {}; // functions in data
179 so1.data.mc = createEmptyMovieClip("mc2", 2); // movieclip values are skipped
181 //AsSetPropFlags(so1.data, '__proto__', 0, 1); // if we unhide __proto__ we'll find it in the SharedObject
182 AsSetPropFlags(so1.data, '__constructor__', 0, 1); // unhide __constructor__ (it's a function so will be skipped anyway)
183 AsSetPropFlags(so1.data, 'constructor', 0, 1); // unhide constructor (it's a function so will be skipped anyway)
185 so1.data.dat = new Date(70,0); // 1 Jan 1970 00:00:00 localtime
187 so1.data.lstr = lstr;
189 f = new Date(0);
190 f.valueOf = function() { return "Overridden date"; };
191 so1.data.fakedate = f;
193 g = new Date(0);
194 g.valueOf = function() { return 35; };
195 so1.data.fakedate2 = g;
197 so1.flush();
199 quit = function()
201 loadMovie('fscommand:quit', '');
204 note(" - Will quit in 5 seconds, feel free to explicitly quit otherwise -");
205 note();
207 setInterval(quit, 5000);
208 stop();
210 check_totals(53);