Add automated tests on function-type FSCommand parameter passing.
[gnash.git] / testsuite / misc-ming.all / register_class / registerClassTest.c
blobd220988fbb6c94a9ba6c3c8b2d9a01352a2c1da3
1 /*
2 * Copyright (C) 2005, 2006, 2009, 2010, 2011 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.
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
18 */
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
35 #include <stdlib.h>
36 #include <stdio.h>
37 #include <ming.h>
39 #include "ming_utils.h"
41 #define OUTPUT_VERSION 6
42 #define OUTPUT_FILENAME "registerClassTest.swf"
44 void addRedSquareExport(SWFMovie mo);
46 void
47 addRedSquareExport(SWFMovie mo)
49 SWFShape sh;
50 SWFMovieClip mc;
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);
65 int
66 main(int argc, char** argv)
68 SWFMovie mo;
69 const char *srcdir=".";
70 SWFMovieClip dejagnuclip;
73 /*********************************************
75 * Initialization
77 *********************************************/
79 if ( argc>1 ) srcdir=argv[1];
80 else
82 fprintf(stderr, "Usage: %s\n", argv[0]);
83 return 1;
86 puts("Setting things up");
88 Ming_init();
89 Ming_useSWFVersion (OUTPUT_VERSION);
90 Ming_setScale(20.0); /* let's talk pixels */
92 mo = newSWFMovie();
93 SWFMovie_setRate(mo, 12);
94 SWFMovie_setDimension(mo, 640, 400);
96 /*********************************************
98 * Body
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();");
111 add_actions(mo,
112 "var name1 = 'square'+counter;"
113 "attachMovie('redsquare', name1, 70+counter);"
114 "var clip1 = this[name1];"
115 "counter++;"
118 SWFMovie_nextFrame(mo); /* end of frame2 */
120 add_actions(mo,
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");
129 add_actions(mo,
130 "var name2 = 'square'+counter;"
131 "attachMovie('redsquare', name2, 70+counter);"
132 "var clip2 = this[name2];"
133 "counter++;"
137 SWFMovie_nextFrame(mo); /* end of frame3 */
139 add_actions(mo,
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");
150 add_actions(mo,
151 "var name3 = 'square'+counter;"
152 "attachMovie('redsquare', name3, 70+counter);"
153 "var clip3 = this[name3];"
154 "counter++;"
157 SWFMovie_nextFrame(mo); /* end of frame4 */
159 add_actions(mo,
160 "registerClassRet = Object.registerClass('redsquare');"
163 check_equals(mo, "typeof(registerClassRet)", "'boolean'");
164 check_equals(mo, "registerClassRet", "false");
166 add_actions(mo,
167 "var name4 = 'square'+counter;"
168 "attachMovie('redsquare', name4, 70+counter);"
169 "var clip4 = this[name4];"
170 "clip4._x = 240;"
171 "counter++;"
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");
229 add_actions(mo,
230 "totals(47);"
231 "stop();"
234 SWFMovie_nextFrame(mo); /* end of frame5 */
236 /*****************************************************
238 * Output movie
240 *****************************************************/
242 puts("Saving " OUTPUT_FILENAME );
244 SWFMovie_save(mo, OUTPUT_FILENAME);
246 return 0;