2
// Copyright (C) 2007, 2008 Free Software Foundation, Inc.
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.
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>
26
// take a look at the #SharedObject dir to figure out what <key> should be
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"
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");
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);
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);
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);
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);
86
check_equals(a.toString(), '0,1,2,custom'); // note: no 'length'
88
// Test reading OBJECT
89
check(so1.data.obj instanceOf Object);
90
check_equals(typeof(so1.data.obj), 'object');
91
check_equals(typeof(so1.data.obj.a), 'number');
92
check(so1.data.obj.hasOwnProperty('a'));
93
check(!so1.data.obj.hasOwnProperty('hidden'));
94
check(so1.data.obj.hasOwnProperty('mc'));
95
check_equals(typeof(so1.data.obj.mc), 'undefined');
96
// Function value was discarded
97
check(! so1.data.obj.hasOwnProperty('fun') );
99
// Test reading NUMBER
100
check_equals(so1.data.obj.a, 10);
102
// Test reading STRING
103
check_equals(typeof(so1.data.obj.b), 'string');
104
check_equals(so1.data.obj.b, '20');
106
// Test reading BOOLEAN
107
check_equals(typeof(so1.data.obj.c), 'boolean');
108
check_equals(so1.data.obj.c, true);
110
// Test reading REFERENCE
111
check_equals(typeof(so1.data.ref), 'object');
112
check_equals(so1.data.ref, so1.data.obj);
114
// force writing the sol or the adobe player won't save it
115
// again. This will also serve as a kind of reference for
116
// how the sol file was produced in the first place
118
so1.data.str = 'a string';
119
so1.data.tbool = true;
120
so1.data.fbool = false;
122
so1.data.ary = [1,true,'string',null, undefined]; // ECMA_ARRAY
123
so1.data.ary.hidden = 6;
124
AsSetPropFlags(so1.data.ary, 'hidden', 1); // hide from enumeration, should not end into the sol file
127
so1.data.aryns = [4,5,6];
128
so1.data.aryns.fun = function() {}; // functions in arrays are simply skipped
129
so1.data.aryns.custom = 7;
130
so1.data.aryns.length = 8; // non-strict array (ECMA_ARRAY)
132
so1.data.obj = {a:10,b:'20',c:true};
133
so1.data.obj.fun = function() {}; // functions in objects are simply skipped
134
so1.data.obj.mc = createEmptyMovieClip("mc1", 1); // movieclip values are skipped
136
//AsSetPropFlags(so1.data.obj, '__proto__', 0, 1); // if we unhide __proto__ we'll find it in the SharedObject
138
AsSetPropFlags(so1.data.obj, '__constructor__', 0, 1); // unhide __constructor__ (it's a function so will be skipped anyway)
139
AsSetPropFlags(so1.data.obj, 'constructor', 0, 1); // unhide constructor (it's a function so will be skipped anyway)
140
// so1.data.obj.constructor = 4; // if we override constructor we'll find it
142
so1.data.obj.hidden = 7;
143
AsSetPropFlags(so1.data.obj, 'hidden', 1); // hide from enumeration, should not end into the sol file
145
so1.data.ref = so1.data.obj;
147
so1.data.fun = function() {}; // functions in data
148
so1.data.mc = createEmptyMovieClip("mc2", 2); // movieclip values are skipped
150
//AsSetPropFlags(so1.data, '__proto__', 0, 1); // if we unhide __proto__ we'll find it in the SharedObject
151
AsSetPropFlags(so1.data, '__constructor__', 0, 1); // unhide __constructor__ (it's a function so will be skipped anyway)
152
AsSetPropFlags(so1.data, 'constructor', 0, 1); // unhide constructor (it's a function so will be skipped anyway)
158
loadMovie('fscommand:quit', '');
161
note(" - Will quit in 5 seconds, feel free to explicitly quit otherwise -");
164
setInterval(quit, 5000);