2 * Copyright (C) 2005, 2006, 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
20 * zou lunkai zoulunkai@gmail.com
22 * Test " Jumping backward to the middle of a DisplayObject's lifetime after removal and replacement(3)"
26 * Frame | 1 | 2 | 3 | 4 | 5 | 6 |
27 * --------+---+---+---+---+---+---+
28 * Event | |PPP| * | RR|PP | J |
30 * P = Place (by PlaceObject2)
31 * R = Remove (by RemoveObject)
38 * a static movieclip is placed at depth 3 (-16381) with ratio value 0.001 [ a red square ]
39 * a static movieclip is placed at depth 4 (-16380) with ratio value 0.001 [ a green square ]
40 * a static movieclip is placed at depth 5 (-16379) with ratio value 0.001 [ a blue square ]
43 * remove movieclip at depth 4;
44 * remove movieclip at depth 5;
46 * a static movieclip is placed at depth4 again with ratio value 0.001 [a yellow square]
47 * a static movieclip is placed at depth5 agian with ratio value 0.003 [a black square]
48 * frame6: gotoAndStop frame3
51 * movieclip in depth4 placed at frame5 kept alive;
52 * movieclip in depth5 placed at frame5 get destroyed;
62 #include "ming_utils.h"
64 #define OUTPUT_VERSION 6
65 #define OUTPUT_FILENAME "loop_test8.swf"
68 add_static_mc(SWFMovie mo
, const char* name
, const char* color
, int depth
, float ratio
);
71 add_static_mc(SWFMovie mo
, const char* name
, const char* color
, int depth
, float ratio
)
77 if( strcmp("red", color
) == 0 )
80 sh
= make_fill_square (300, 0, 60, 60, 255, 0, 0, 255, 0, 0);
82 else if( strcmp("green", color
) == 0 )
85 sh
= make_fill_square (300, 100, 60, 60, 0, 255, 0, 0, 255, 0);
87 else if( strcmp("blue", color
) == 0 )
90 sh
= make_fill_square (300, 200, 60, 60, 0, 0, 255, 0, 0, 255);
92 else if( strcmp("yellow", color
) == 0 )
95 sh
= make_fill_square (300, 300, 60, 60, 255, 255, 0, 255, 255, 0);
100 sh
= make_fill_square (300, 400, 60, 60, 0, 0, 0, 0, 0, 0);
103 mc
= newSWFMovieClip();
104 SWFMovieClip_add(mc
, (SWFBlock
)sh
);
105 SWFMovieClip_nextFrame(mc
);
107 it
= SWFMovie_add(mo
, (SWFBlock
)mc
);
108 SWFDisplayItem_setDepth(it
, depth
);
109 SWFDisplayItem_setName(it
, name
);
110 SWFDisplayItem_setRatio(it
, ratio
);
117 main(int argc
, char** argv
)
120 SWFMovieClip dejagnuclip
;
121 SWFDisplayItem it1
, it2
, it3
, it4
, it5
;
123 const char *srcdir
=".";
128 fprintf(stderr
, "Usage: %s <mediadir>\n", argv
[0]);
133 mo
= newSWFMovieWithVersion(OUTPUT_VERSION
);
134 SWFMovie_setDimension(mo
, 800, 600);
135 SWFMovie_setRate (mo
, 1.0);
137 dejagnuclip
= get_dejagnu_clip((SWFBlock
)get_default_font(srcdir
), 10, 0, 0, 800, 600);
138 SWFMovie_add(mo
, (SWFBlock
)dejagnuclip
);
139 // Frame1: initialize testing variables
140 add_actions(mo
, " mc1Constructed=0; mc2Constructed=0; mc3Constructed=0; "
141 " mc4Constructed=0; mc5Constructed=0; "
142 " mc1Unloaded=0; mc2Unloaded=0; mc3Unloaded=0; ");
143 SWFMovie_nextFrame(mo
); // 1st frame
146 // add a static movieclip at depth3 with ratio value 0.001
147 // add a static movieclip at depth4 with ratio value 0.001
148 // add a static movieclip at depth5 with ratio value 0.001
149 it1
= add_static_mc(mo
, "mc1", "red", 3, 0.001);
150 it2
= add_static_mc(mo
, "mc2", "green", 4, 0.001);
151 it3
= add_static_mc(mo
, "mc3", "blue", 5, 0.001);
153 SWFDisplayItem_addAction(it1
,
154 newSWFAction("_root.note(this+' constructed'); _root.mc1Constructed++;"),
155 SWFACTION_CONSTRUCT
);
156 SWFDisplayItem_addAction(it1
, newSWFAction(""), SWFACTION_ONLOAD
);
157 SWFDisplayItem_addAction(it1
,
158 newSWFAction("_root.note(this + ' unloaded'); _root.mc1Unloaded = 1;"),
161 SWFDisplayItem_addAction(it2
,
162 newSWFAction("_root.note(this+' constructed'); _root.mc2Constructed++;"),
163 SWFACTION_CONSTRUCT
);
164 SWFDisplayItem_addAction(it2
, newSWFAction(""), SWFACTION_ONLOAD
);
165 SWFDisplayItem_addAction(it2
,
166 newSWFAction("_root.note(this + ' unloaded'); _root.mc2Unloaded = 1;"),
169 SWFDisplayItem_addAction(it3
,
170 newSWFAction("_root.note(this+' constructed'); _root.mc3Constructed++;"),
171 SWFACTION_CONSTRUCT
);
172 SWFDisplayItem_addAction(it3
, newSWFAction(""), SWFACTION_ONLOAD
);
173 SWFDisplayItem_addAction(it3
,
174 newSWFAction("_root.note(this + ' unloaded'); _root.mc3Unloaded = 1;"),
176 SWFMovie_nextFrame(mo
); // 2nd frame
178 // Frame3: Do nothing
179 SWFMovie_nextFrame(mo
); // 3rd frame
181 // Frame4: Remove mc2(at depth4) and mc3(at depth5)
182 SWFDisplayItem_remove(it2
);
183 SWFDisplayItem_remove(it3
);
184 SWFMovie_nextFrame(mo
); // 4th frame
187 // add mc4 with the same depth and ratio as mc2
188 // add mc5 with the same depth but different ratio as mc3
189 it4
= add_static_mc(mo
, "mc4", "yellow", 4, 0.001);
190 it5
= add_static_mc(mo
, "mc5", "black", 5, 0.003);
192 SWFDisplayItem_addAction(it4
,
193 newSWFAction("_root.note(this+' constructed'); _root.mc4Constructed++;"),
194 SWFACTION_CONSTRUCT
);
195 SWFDisplayItem_addAction(it4
, newSWFAction(""), SWFACTION_ONLOAD
);
196 SWFDisplayItem_addAction(it4
, newSWFAction("_root.note(this+ 'unloaded');"), SWFACTION_UNLOAD
);
198 SWFDisplayItem_addAction(it5
,
199 newSWFAction("_root.note(this+' constructed'); _root.mc5Constructed++;"),
200 SWFACTION_CONSTRUCT
);
201 SWFDisplayItem_addAction(it5
, newSWFAction(""), SWFACTION_ONLOAD
);
202 SWFDisplayItem_addAction(it5
, newSWFAction("_root.note(this+ 'unloaded');"), SWFACTION_UNLOAD
);
203 SWFMovie_nextFrame(mo
); // 5th frame
205 // Frame6: Checks, goto frame3 and stop, checks
206 check_equals(mo
, "typeof(mc1)", "'movieclip'");
207 check_equals(mo
, "typeof(mc2)", "'undefined'");
208 check_equals(mo
, "typeof(mc3)", "'undefined'");
209 check_equals(mo
, "typeof(mc4)", "'movieclip'");
210 check_equals(mo
, "typeof(mc5)", "'movieclip'");
211 check_equals(mo
, "mc1Constructed", "1");
212 check_equals(mo
, "mc2Constructed", "1");
213 check_equals(mo
, "mc3Constructed", "1");
214 check_equals(mo
, "mc4Constructed", "1");
215 check_equals(mo
, "mc5Constructed", "1");
216 check_equals(mo
, "mc1Unloaded", "0");
217 check_equals(mo
, "mc2Unloaded", "1");
218 check_equals(mo
, "mc3Unloaded", "1");
220 add_actions(mo
, "gotoAndStop(3);");
222 check_equals(mo
, "typeof(mc1)", "'movieclip'");
223 check_equals(mo
, "typeof(mc2)", "'undefined'");
224 check_equals(mo
, "typeof(mc3)", "'movieclip'");
225 check_equals(mo
, "typeof(mc4)", "'movieclip'");
226 check_equals(mo
, "typeof(mc5)", "'movieclip'"); // Gnash fails because of action execution order
227 check_equals(mo
, "mc1Constructed", "1");
228 check_equals(mo
, "mc2Constructed", "1");
229 check_equals(mo
, "mc3Constructed", "2");
230 check_equals(mo
, "mc4Constructed", "1");
231 check_equals(mo
, "mc5Constructed", "1");
232 check_equals(mo
, "mc1Unloaded", "0");
233 check_equals(mo
, "mc2Unloaded", "1");
234 check_equals(mo
, "mc3Unloaded", "1");
236 add_actions(mo
, "totals();");
237 SWFMovie_nextFrame(mo
); // 6th frame
240 puts("Saving " OUTPUT_FILENAME
);
241 SWFMovie_save(mo
, OUTPUT_FILENAME
);