2 * Copyright (C) 2007, 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 * zou lunkai, zoulunkai@gmail.com
23 * Testcases for Object.registerClass().
27 * (1) Export 'libItem1' and 'libItem2' symbols
29 * (2.1) Register 'theClass1' and 'theClass2' to the symbols above
30 * (2.2) Attach the symbols as instances 'clip1' and 'clip2'
31 * (3) Other DOACTION blocks
32 * (3.1) Verify that 'clip1' and 'clip2' are instances of 'theClass1' and 'theClass2' respectively
37 * (1) Export 'libItem3'
38 * (2) INITACTION block
39 * (2.1) Register 'theClass3' to 'libItem3'
40 * (2.2) Attach 'libItem3' as instance 'clip3'
41 * (2.3) Verify that 'clip3' is an instance of 'theClass3'
42 * (3) INITCLIP event for 'clip3'
43 * (3.1) Verify thet 'clip3' is an instance of 'theClass3'
44 * (4) CONSTRUCT event for 'clip3'
45 * (4.1) Verify thet 'clip3' is an instance of 'theClass3'
52 #include "ming_utils.h"
54 #define OUTPUT_VERSION 7
55 #define OUTPUT_FILENAME "registerClassTest2.swf"
57 void addExport(SWFMovie mo
, SWFMovieClip mc
, const char * name
);
60 addExport(SWFMovie mo
, SWFMovieClip mc
, const char * name
)
62 SWFMovie_addExport(mo
, (SWFBlock
)mc
, name
);
63 SWFMovie_writeExports(mo
);
67 main(int argc
, char** argv
)
70 SWFMovieClip mc1
, mc2
, mc3
, dejagnuclip
;
71 SWFShape sh1
, sh2
, sh3
;
72 SWFDisplayItem it3
, it4
;
73 const char *srcdir
=".";
75 if ( argc
>1 ) srcdir
=argv
[1];
78 fprintf(stderr
, "Usage: %s\n", argv
[0]);
83 Ming_useSWFVersion (OUTPUT_VERSION
);
84 Ming_setScale(20.0); /* let's talk pixels */
87 SWFMovie_setRate(mo
, 12);
88 SWFMovie_setDimension(mo
, 640, 400);
90 // add the dejagnuclip for testing
91 dejagnuclip
= get_dejagnu_clip((SWFBlock
)get_default_font(srcdir
), 10, 0, 80, 800, 600);
92 SWFMovie_add(mo
, (SWFBlock
)dejagnuclip
);
95 "_root.theClass1onLoadCalls = new Array();"
96 "_root.theClass2onLoadCalls = new Array();"
97 "_root.theClass3onLoadCalls = new Array();"
98 "_root.mc3frame0 = new Array();"
101 // define two movieClips
103 mc1
= newSWFMovieClip();
104 sh1
= make_fill_square (100, 100, 60, 60, 255, 0, 0, 255, 0, 0);
105 SWFMovieClip_add(mc1
, (SWFBlock
)sh1
);
106 SWFMovieClip_nextFrame(mc1
);
108 mc2
= newSWFMovieClip();
109 sh2
= make_fill_square (100, 100, 60, 60, 255, 255, 0, 255, 255, 0);
110 SWFMovieClip_add(mc2
, (SWFBlock
)sh2
);
111 SWFMovieClip_nextFrame(mc2
);
114 addExport(mo
, mc1
, "libItem1");
115 addExport(mo
, mc2
, "libItem2");
116 SWFMovie_nextFrame(mo
); /* end of frame1 */
120 "theClass1 = function() { this.x = 60; this._alpha=20; };"
121 "theClass1.prototype = new MovieClip();"
122 "theClass1.prototype.onLoad = function() { "
123 " trace('theClass1 proto onLoad ('+this+')');"
124 " _root.theClass1onLoadCalls.push(this);"
126 "theClass2 = function() { this.x = 600; this._x = 200; this._alpha=20;}; "
127 "Object.registerClass('libItem1', theClass1);"
128 "Object.registerClass('libItem2', theClass2);"
129 "_root.attachMovie('libItem1', 'clip1', 10);"
130 "_root.attachMovie('libItem2', 'clip2', 20);"
133 check_equals(mo
, "typeof(clip1)", "'movieclip'");
134 check_equals(mo
, "typeof(clip2)", "'movieclip'");
135 check_equals(mo
, "clip1.__proto__", "theClass1.prototype");
136 check_equals(mo
, "clip2.__proto__", "theClass2.prototype");
137 #if OUTPUT_VERSION > 6
138 // succeed in swf7 and swf8
139 check_equals(mo
, "clip1.constructor", "MovieClip");
140 #elif OUTPUT_VERSION == 6
141 check_equals(mo
, "clip1.constructor", "theClass1");
143 check_equals(mo
, "clip1.__constructor__", "theClass1");
144 check_equals(mo
, "clip2.constructor", "theClass2");
145 check_equals(mo
, "clip2.__constructor__", "theClass2");
146 check_equals(mo
, "clip1.x", "60");
147 check_equals(mo
, "clip2.x", "600");
148 check_equals(mo
, "clip1._x", "0");
149 check_equals(mo
, "clip2._x", "200");
150 check_equals(mo
, "typeof(MovieClip.prototype.getDepth)", "'function'");
151 check_equals(mo
, "clip1.getDepth()", "10");
152 // clip2 does not inherit MovieClip
153 check_equals(mo
, "clip2.getDepth()", "undefined");
155 SWFMovie_nextFrame(mo
); /* end of frame2 */
159 // Define movieclip mc3
160 mc3
= newSWFMovieClip();
161 sh3
= make_fill_square (0, 300, 100, 100, 255, 255, 0, 255, 255, 0);
162 SWFMovieClip_add(mc3
, (SWFBlock
)sh3
);
164 add_clip_actions(mc3
,
165 " _root.note(this+'.frame0 actions'); "
166 " _root.mc3frame0.push(this);"
168 SWFMovieClip_nextFrame(mc3
);
171 addExport(mo
, mc3
, "libItem3");
173 check_equals(mo
, "_root.theClass1onLoadCalls.length", "1");
174 check_equals(mo
, "_root.theClass1onLoadCalls[0]", "_level0.clip1");
176 // add init actions for mc3
177 add_clip_init_actions(mc3
, " _root.note('mc3.initactions'); "
178 " theClass3 = function () {}; "
179 " theClass3.prototype = new MovieClip(); "
180 " theClass3.prototype.onLoad = function() {"
181 " _root.note(this+'.onLoad (theClass3 proto)');"
182 " _root.theClass3onLoadCalls.push(this);"
184 " Object.registerClass('libItem3', theClass3); "
185 " _root.attachMovie('libItem3', 'clip3', 30); "
186 // clip3.__proto__ is initialized before executing onClipConstruct
187 "_root.check_equals(clip3.__proto__, _root.theClass3.prototype); ");
189 it3
= SWFMovie_add(mo
, mc3
);
190 SWFDisplayItem_setName(it3
, "clipevs");
191 SWFDisplayItem_addAction(it3
,
192 newSWFAction(" _root.note('mc3.onClipInitialize'); "
193 " _root.check_equals(typeof(_root.clip3), 'movieclip');"
194 " _root.check_equals(_root.clip3.__proto__, _root.theClass3.prototype);"
198 SWFDisplayItem_addAction(it3
,
199 newSWFAction(" _root.note('mc3.onClipConstruct'); "
200 " _root.check_equals(typeof(_root.clip3), 'movieclip'); "
201 " _root.check(_root.clip3.__proto__ != undefined); "
202 " _root.check_equals(_root.clip3.__proto__, _root.theClass3.prototype);"
204 SWFACTION_CONSTRUCT
);
206 /* Place it again, no clip events this time */
207 it4
= SWFMovie_add(mo
, mc3
);
208 SWFDisplayItem_setName(it4
, "noclipevs");
210 SWFMovie_nextFrame(mo
); /* end of frame3 */
212 check_equals(mo
, "_root.theClass3onLoadCalls.length", "3");
213 check_equals(mo
, "_root.theClass3onLoadCalls[0]", "_level0.clipevs");
214 // Gnash gets the onLoad events of 'clip3' and 'noclipevs' swapped !!
215 xcheck_equals(mo
, "_root.theClass3onLoadCalls[1]", "_level0.clip3");
216 xcheck_equals(mo
, "_root.theClass3onLoadCalls[2]", "_level0.noclipevs"); /* it4 ... */
218 check_equals(mo
, "_root.mc3frame0.length", "3");
219 check_equals(mo
, "_root.mc3frame0[0]", "_level0.clipevs");
220 check_equals(mo
, "_root.mc3frame0[1]", "_level0.noclipevs");
221 check_equals(mo
, "_root.mc3frame0[2]", "_level0.clip3");
223 add_actions(mo
, "totals(31); stop();");
225 SWFMovie_nextFrame(mo
); /* end of frame4 */
227 /*****************************************************
231 *****************************************************/
233 puts("Saving " OUTPUT_FILENAME
);
235 SWFMovie_save(mo
, OUTPUT_FILENAME
);