2 * Copyright (C) 2005, 2006, 2009, 2010, 2011 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.
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21 * Test Object.registerClass().
23 * 1) Exports a 'redsquare' symbol
24 * 2) attach it to main timeline
25 * 3) register a custom class to it
26 * 4) attach it again (expected to have the custom class interface)
27 * 5) register another custom class to it, this time deriving from MovieClip
28 * 6) attach it again (expected to be both instance of custom class and instance of MovieClip)
29 * 7) call registerClass again, this time with an *single* argument
30 * 8) attach it again (expected to be instance of of MovieClip)
32 * run as ./registerClass
39 #include "ming_utils.h"
41 #define OUTPUT_VERSION 6
42 #define OUTPUT_FILENAME "registerClassTest.swf"
44 void addRedSquareExport(SWFMovie mo
);
47 addRedSquareExport(SWFMovie mo
)
52 sh
= make_fill_square (0, 0, 60, 60, 255, 0, 0, 255, 0, 0);
53 mc
= newSWFMovieClip();
55 SWFMovieClip_add(mc
, (SWFBlock
)sh
);
56 /* This is here just to turn the clip into an active one */
57 add_clip_actions(mc
, "onRollOver = function() {};");
58 SWFMovieClip_nextFrame(mc
);
60 SWFMovie_addExport(mo
, (SWFBlock
)mc
, "redsquare");
62 SWFMovie_writeExports(mo
);
66 main(int argc
, char** argv
)
69 const char *srcdir
=".";
70 SWFMovieClip dejagnuclip
;
73 /*********************************************
77 *********************************************/
79 if ( argc
>1 ) srcdir
=argv
[1];
82 fprintf(stderr
, "Usage: %s\n", argv
[0]);
86 puts("Setting things up");
89 Ming_useSWFVersion (OUTPUT_VERSION
);
90 Ming_setScale(20.0); /* let's talk pixels */
93 SWFMovie_setRate(mo
, 12);
94 SWFMovie_setDimension(mo
, 640, 400);
96 /*********************************************
100 *********************************************/
102 dejagnuclip
= get_dejagnu_clip((SWFBlock
)get_default_font(srcdir
), 10, 0, 80, 800, 600);
103 SWFMovie_add(mo
, (SWFBlock
)dejagnuclip
);
104 addRedSquareExport(mo
);
105 /* it seems we need a SHOWFRAME for this to be effective */
106 /* (maybe it's related to loop-back handling ?) */
107 SWFMovie_nextFrame(mo
); /* end of frame1 */
109 add_actions(mo
, "counter = 1; onLoadCalled = new Array();");
112 "var name1 = 'square'+counter;"
113 "attachMovie('redsquare', name1, 70+counter);"
114 "var clip1 = this[name1];"
118 SWFMovie_nextFrame(mo
); /* end of frame2 */
121 "function CustomClass() { this._x = 80; }"
122 "CustomClass.prototype.onLoad = function() { note(this+'.onLoad called'); _root.onLoadCalled.push(this); };"
123 "registerClassRet = Object.registerClass('redsquare', CustomClass);"
126 check_equals(mo
, "typeof(registerClassRet)", "'boolean'");
127 check_equals(mo
, "registerClassRet", "true");
130 "var name2 = 'square'+counter;"
131 "attachMovie('redsquare', name2, 70+counter);"
132 "var clip2 = this[name2];"
137 SWFMovie_nextFrame(mo
); /* end of frame3 */
140 "function CustomClass2() { this._x = 160; check_equals(typeof(super.lineTo), 'function'); }"
141 "CustomClass2.prototype = new MovieClip;"
142 "registerClassRet = Object.registerClass('redsquare', CustomClass2);"
145 check_equals(mo
, "_root.onLoadCalled.length", "1");
146 check_equals(mo
, "_root.onLoadCalled[0]", "_level0.square2");
147 check_equals(mo
, "typeof(registerClassRet)", "'boolean'");
148 check_equals(mo
, "registerClassRet", "true");
151 "var name3 = 'square'+counter;"
152 "attachMovie('redsquare', name3, 70+counter);"
153 "var clip3 = this[name3];"
157 SWFMovie_nextFrame(mo
); /* end of frame4 */
160 "registerClassRet = Object.registerClass('redsquare');"
163 check_equals(mo
, "typeof(registerClassRet)", "'boolean'");
164 check_equals(mo
, "registerClassRet", "false");
167 "var name4 = 'square'+counter;"
168 "attachMovie('redsquare', name4, 70+counter);"
169 "var clip4 = this[name4];"
174 SWFMovie_nextFrame(mo
); /* end of frame5 */
176 check_equals(mo
, "typeof(clip1)", "'movieclip'");
177 check(mo
, "clip1 instanceOf MovieClip");
178 check_equals(mo
, "clip1._x", "0");
179 check(mo
, "! clip1 instanceOf CustomClass");
181 // Check that non-enumerable properties (unnamed instances,
182 // constructor, __constructor__) are not enumerated.
183 add_actions(mo
, "var s = ''; for (i in clip1) { s += i + ','; };");
184 check_equals(mo
, "s", "'onRollOver,'");
186 check_equals(mo
, "typeof(clip2)", "'movieclip'");
187 check(mo
, "clip2 instanceOf CustomClass");
188 check(mo
, "clip2.hasOwnProperty('__constructor__')");
189 check(mo
, "clip2.hasOwnProperty('constructor')");
190 check(mo
, "clip2.hasOwnProperty('__proto__')");
191 check_equals(mo
, "clip2.__proto__", "CustomClass.prototype");
192 check_equals(mo
, "clip2.__constructor__", "CustomClass");
193 check_equals(mo
, "clip2.constructor", "CustomClass");
194 check_equals(mo
, "clip2._x", "80");
195 check_equals(mo
, "typeof(clip2.lineTo)", "'undefined'");
196 check(mo
, "! clip2 instanceOf MovieClip");
198 // Check that non-enumerable properties (unnamed instances,
199 // constructor, __constructor__) are not enumerated.
200 add_actions(mo
, "var s = ''; for (i in clip2) { s += i + ','; };");
201 check_equals(mo
, "s", "'onLoad,onRollOver,'");
203 check(mo
, "clip3.hasOwnProperty('__constructor__')");
204 check(mo
, "clip3.hasOwnProperty('constructor')");
205 check(mo
, "clip3.hasOwnProperty('__proto__')");
206 check_equals(mo
, "clip3.__proto__", "CustomClass2.prototype");
207 check_equals(mo
, "clip3.__constructor__", "CustomClass2");
208 check_equals(mo
, "clip3.constructor", "CustomClass2");
209 check_equals(mo
, "typeof(clip3)", "'movieclip'");
210 check_equals(mo
, "clip3._x", "160");
211 check(mo
, "clip3 instanceOf CustomClass2");
212 check(mo
, "clip3 instanceOf MovieClip");
214 // Check that non-enumerable properties (unnamed instances,
215 // constructor, __constructor__) are not enumerated.
216 add_actions(mo
, "var s = ''; for (i in clip3) { s += i + ','; };");
217 check_equals(mo
, "s", "'onRollOver,'");
219 check(mo
, "clip4.hasOwnProperty('__constructor__')");
220 check(mo
, "clip4.hasOwnProperty('constructor')");
221 check(mo
, "clip4.hasOwnProperty('__proto__')");
222 check_equals(mo
, "clip4.__proto__", "CustomClass2.prototype");
223 check_equals(mo
, "clip4.__constructor__", "CustomClass2");
224 check_equals(mo
, "clip4.constructor", "CustomClass2");
225 check_equals(mo
, "typeof(clip4)", "'movieclip'");
226 check_equals(mo
, "clip4._x", "240");
227 check(mo
, "clip4 instanceOf MovieClip");
234 SWFMovie_nextFrame(mo
); /* end of frame5 */
236 /*****************************************************
240 *****************************************************/
242 puts("Saving " OUTPUT_FILENAME
);
244 SWFMovie_save(mo
, OUTPUT_FILENAME
);