Add automated tests on function-type FSCommand parameter passing.
[gnash.git] / testsuite / misc-ming.all / replace_shapes1test.c
blobc4c9e4c9eed7c29ce9a5ea39a38665f850973882
1 /*
2 * Copyright (C) 2007, 2009, 2010 , 2011Free 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
17 */
20 * Sandro Santilli, strk@keybit.net
22 * Test "Jump backward to start of lifetime after replacement with different shape"
24 * run as ./replace_shapes1test
26 * Timeline:
28 * Frame | 1 | 2 | 3 | 4 | 5 | 6 | 7 |
29 * --------+---+---+---+---+---+---+---+
30 * Event | |P* | X | J | | | |
32 * P = place (by PlaceObject2)
33 * X = replace (by PlaceObject2)
34 * J = jump
35 * * = jump target
37 * Description:
39 * frame2: shape 1 placed at depth -16381 and position 100,300
40 * frame3: instance at depth -16381 replaced by DisplayObject 2 at position 130,330
41 * frame4: jump back to frame 2 and stop
43 * Expected behaviour:
45 * In frame 2 we have a red square at (100,300), in frame 3 we have a green square at (130,330),
46 * after the jump-back we have a red square at (100,300) again.
47 * The name specified in the PlaceObject2 tag in frame 2 evaluates to the _root movie.
48 * The name specified in the PlaceObject2 tag in frame 3 (replace) evaluates to undefined.
51 #include "ming_utils.h"
53 #include <stdlib.h>
54 #include <stdio.h>
55 #include <ming.h>
57 #define OUTPUT_VERSION 6
58 #define OUTPUT_FILENAME "replace_shapes1test.swf"
60 SWFDisplayItem add_static_mc(SWFMovie mo, const char* name, int depth, int x, int y, int width, int height);
61 SWFMovieClip get_static_mc(int width, int height, int r, int g, int b);
62 SWFShape get_shape(int width, int height, int r, int g, int b);
64 SWFShape
65 get_shape(int width, int height, int r, int g, int b)
67 SWFShape sh;
69 /*sh = make_fill_square (-(width/2), -(height/2), width, height, r, g, b, r, g, b);*/
70 sh = make_fill_square (0, 0, width, height, r, g, b, r, g, b);
72 return sh;
75 SWFMovieClip
76 get_static_mc(int width, int height, int r, int g, int b)
78 SWFShape sh = get_shape(width, height, r, g, b);
79 SWFMovieClip mc = newSWFMovieClip();
81 SWFMovieClip_add(mc, (SWFBlock)sh);
83 SWFMovieClip_nextFrame(mc);
85 return mc;
89 SWFDisplayItem
90 add_static_mc(SWFMovie mo, const char* name, int depth, int x, int y, int width, int height)
92 SWFMovieClip mc;
93 SWFDisplayItem it;
95 mc = get_static_mc(width, height, 255, 0, 0);
97 it = SWFMovie_add(mo, (SWFBlock)mc);
98 SWFDisplayItem_setDepth(it, depth);
99 SWFDisplayItem_moveTo(it, x, y);
100 SWFDisplayItem_setName(it, name);
102 return it;
107 main(int argc, char** argv)
109 SWFMovie mo;
110 SWFMovieClip dejagnuclip;
111 SWFShape static1, static2;
112 SWFDisplayItem it1;
115 const char *srcdir=".";
116 if ( argc>1 )
117 srcdir=argv[1];
118 else
120 //fprintf(stderr, "Usage: %s <mediadir>\n", argv[0]);
121 //return 1;
124 Ming_init();
125 mo = newSWFMovieWithVersion(OUTPUT_VERSION);
126 SWFMovie_setDimension(mo, 800, 600);
127 SWFMovie_setRate (mo, 2);
129 static1 = get_shape(60, 60, 255, 0, 0);
130 static2 = get_shape(60, 60, 0, 255, 0);
132 dejagnuclip = get_dejagnu_clip((SWFBlock)get_default_font(srcdir), 10, 0, 0, 800, 600);
133 SWFMovie_add(mo, (SWFBlock)dejagnuclip);
134 SWFMovie_nextFrame(mo);
136 // Frame 2: place DisplayObject at depth 3 (-16381)
137 it1 = SWFMovie_add(mo, (SWFBlock)static1);
138 SWFDisplayItem_setDepth(it1, 3);
139 SWFDisplayItem_moveTo(it1, 100, 300);
140 SWFDisplayItem_setName(it1, "static1");
141 SWFDisplayItem_addAction(it1, newSWFAction(
142 "_root.note(this+' onClipConstruct');"
143 " _root.check_equals(typeof(_root), 'movieclip');"
144 " if ( isNaN(_root.depth3Constructed) ) {"
145 " _root.depth3Constructed=1; "
146 " } else {"
147 " _root.depth3Constructed++;"
148 " }"
149 " _root.note('_root.depth3Constructed set to '+_root.depth3Constructed);"
150 ), SWFACTION_CONSTRUCT);
151 add_actions(mo, "static1.name='static1';");
153 check_equals(mo, "typeof(static1)", "'movieclip'");
154 check_equals(mo, "static1", "_root");
155 check_equals(mo, "static1.name", "'static1'");
156 check_equals(mo, "_root.name", "'static1'");
158 // Gnash allows custom members to shape DisplayObjects...
159 // this is important to verify, see next check for it after REPLACE
160 check_equals(mo, "static1.name", "'static1'");
162 check_equals(mo, "static1._target", "'/'");
163 SWFMovie_nextFrame(mo);
165 // Frame 3: replace instance at depth -16381 with DisplayObject 2
166 if ( SWFMovie_replace(mo, it1, (SWFBlock)static2) )
168 abort(); // grace and beauty...
170 SWFDisplayItem_moveTo(it1, 130, 330);
171 SWFDisplayItem_setName(it1, "static2");
172 SWFDisplayItem_addAction(it1, newSWFAction(
173 "_root.note(this+' onClipConstruct');"
174 " _root.check_equals(typeof(_root), 'movieclip');"
175 " if ( isNaN(_root.depth3Constructed) ) {"
176 " _root.depth3Constructed=1; "
177 " } else {"
178 " _root.depth3Constructed++;"
179 " }"
180 " _root.note('_root.depth3Constructed set to '+_root.depth3Constructed);"
181 ), SWFACTION_CONSTRUCT);
184 // Can still reference the old DisplayObject and it's variables, after replace
185 xcheck_equals(mo, "typeof(static1)", "'movieclip'");
186 xcheck_equals(mo, "static1", "_root");
187 xcheck_equals(mo, "static1.name", "'static1'");
188 check_equals(mo, "_root.name", "'static1'");
190 // While the new name results undefined...
191 xcheck_equals(mo, "typeof(static2)", "'undefined'"); // the name wasn't changed
193 // Everything suggests that a new instance is NOT created on replace !!!
194 // Gnash here fails because it creates a NEW instance
196 // We can't check the color or the _x in a self-contained testcase unfortunately,
197 // we'll need a MovieTester-based runner for this.
198 // It is expected the color of the current instane is GREEN, and the boundaries
199 // are from 130 to 190 for X and 330 to 390 for Y.
200 // TODO: implement a MovieTester based runner !!
202 SWFMovie_nextFrame(mo);
204 // Frame 4: jump to frame 2, stop and check
206 add_actions(mo,
208 "gotoAndStop(2); "
210 // Shapes don't get their onConstruct event invoked !
211 "check_equals(typeof(_root.depth3Constructed), 'undefined');"
213 // Original DisplayObject name is still referenceable
214 "check_equals(typeof(static1), 'movieclip');"
216 // And it still has it's user-provided property
217 "check_equals(static1.name, 'static1');"
219 // We can't check the color or the _x in a self-contained testcase unfortunately,
220 // we'll need a MovieTester-based runner for this.
221 // It is expected the color of the current instance is RED, and the boundaries
222 // are from 100 to 120 for both X and Y.
223 // TODO: implement a MovieTester based runner !!
225 "totals();"
227 SWFMovie_nextFrame(mo);
229 //Output movie
230 puts("Saving " OUTPUT_FILENAME );
231 SWFMovie_save(mo, OUTPUT_FILENAME);
233 return 0;